Add player data support to Velocity impl.

This commit is contained in:
Aust1n46 2021-08-28 22:37:24 -04:00
parent 7a7fb1d885
commit 0e3a97b269
10 changed files with 164 additions and 87 deletions

View File

@ -108,3 +108,5 @@ Add clans channel from SimpleClans
Look into changing Bukkit chat event to not be cancelled. Look into changing Bukkit chat event to not be cancelled.
Expand on EssentialsDiscord integration to allow for custom MessageTypes for each channel Expand on EssentialsDiscord integration to allow for custom MessageTypes for each channel
Expand placeholder matching regex in convertToJson method

View File

@ -61,6 +61,7 @@
<artifactSet> <artifactSet>
<includes> <includes>
<include>com.zaxxer:HikariCP</include> <include>com.zaxxer:HikariCP</include>
<include>net.md-5:bungeecord-config</include>
</includes> </includes>
</artifactSet> </artifactSet>
</configuration> </configuration>
@ -185,7 +186,7 @@
<artifactId>bungeecord-api</artifactId> <artifactId>bungeecord-api</artifactId>
<version>1.13-SNAPSHOT</version> <version>1.13-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>

View File

@ -7,9 +7,11 @@ import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import mineverse.Aust1n46.chat.database.BungeePlayerData; import mineverse.Aust1n46.chat.database.ProxyPlayerData;
import mineverse.Aust1n46.chat.utilities.Format;
import mineverse.Aust1n46.chat.utilities.UUIDFetcher; import mineverse.Aust1n46.chat.utilities.UUIDFetcher;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PluginMessageEvent;
@ -29,13 +31,11 @@ import net.md_5.bungee.event.EventHandler;
* @author Aust1n46 * @author Aust1n46
*/ */
public class MineverseChatBungee extends Plugin implements Listener, VentureChatProxySource { public class MineverseChatBungee extends Plugin implements Listener, VentureChatProxySource {
private static MineverseChatBungee instance;
private static Configuration bungeeConfig; private static Configuration bungeeConfig;
private File BUNGEE_PLAYER_DATA_DIRECTORY_PATH;
@Override @Override
public void onEnable() { public void onEnable() {
instance = this;
if(!getDataFolder().exists()) { if(!getDataFolder().exists()) {
getDataFolder().mkdir(); getDataFolder().mkdir();
} }
@ -50,8 +50,9 @@ public class MineverseChatBungee extends Plugin implements Listener, VentureChat
e.printStackTrace(); e.printStackTrace();
} }
BungeePlayerData.loadLegacyBungeePlayerData(); BUNGEE_PLAYER_DATA_DIRECTORY_PATH = new File(getDataFolder().getAbsolutePath() + "/PlayerData");
BungeePlayerData.loadBungeePlayerData(); ProxyPlayerData.loadLegacyBungeePlayerData(BUNGEE_PLAYER_DATA_DIRECTORY_PATH, this);
ProxyPlayerData.loadProxyPlayerData(BUNGEE_PLAYER_DATA_DIRECTORY_PATH, this);
this.getProxy().registerChannel(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING); this.getProxy().registerChannel(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING);
this.getProxy().getPluginManager().registerListener(this, this); this.getProxy().getPluginManager().registerListener(this, this);
@ -59,15 +60,7 @@ public class MineverseChatBungee extends Plugin implements Listener, VentureChat
@Override @Override
public void onDisable() { public void onDisable() {
BungeePlayerData.saveBungeePlayerData(); ProxyPlayerData.saveProxyPlayerData(BUNGEE_PLAYER_DATA_DIRECTORY_PATH, this);
}
public static MineverseChatBungee getInstance() {
return instance;
}
public static Configuration getBungeeConfig() {
return bungeeConfig;
} }
@EventHandler @EventHandler
@ -82,7 +75,7 @@ public class MineverseChatBungee extends Plugin implements Listener, VentureChat
@EventHandler @EventHandler
public void onPlayerJoinNetwork(PostLoginEvent event) { public void onPlayerJoinNetwork(PostLoginEvent event) {
UUIDFetcher.checkOfflineUUIDWarningBungee(event.getPlayer().getUniqueId()); UUIDFetcher.checkOfflineUUIDWarningProxy(event.getPlayer().getUniqueId(), this);
} }
private void updatePlayerNames() { private void updatePlayerNames() {
@ -133,4 +126,14 @@ public class MineverseChatBungee extends Plugin implements Listener, VentureChat
ProxyServer server = (ProxyServer) getProxy().getServers().get(serverName); ProxyServer server = (ProxyServer) getProxy().getServers().get(serverName);
return new VentureChatProxyServer(serverName, server.getPlayers().isEmpty()); return new VentureChatProxyServer(serverName, server.getPlayers().isEmpty());
} }
@Override
public void sendConsoleMessage(String message) {
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll(message)));
}
@Override
public boolean isOfflineServerAcknowledgementSet() {
return bungeeConfig.getBoolean("offline_server_acknowledgement");
}
} }

View File

@ -8,4 +8,8 @@ public interface VentureChatProxySource {
public List<VentureChatProxyServer> getServers(); public List<VentureChatProxyServer> getServers();
public VentureChatProxyServer getServer(String serverName); public VentureChatProxyServer getServer(String serverName);
public void sendConsoleMessage(String message);
public boolean isOfflineServerAcknowledgementSet();
} }

View File

@ -2,6 +2,10 @@ package mineverse.Aust1n46.chat.bungee;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -15,7 +19,9 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.event.connection.PluginMessageEvent.ForwardResult; import com.velocitypowered.api.event.connection.PluginMessageEvent.ForwardResult;
import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.event.player.ServerPostConnectEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.ServerConnection;
@ -23,20 +29,62 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import mineverse.Aust1n46.chat.database.ProxyPlayerData;
import mineverse.Aust1n46.chat.utilities.Format;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
@Plugin(id = "venturechat", name = "VentureChat", version = "3.1.0", @Plugin(id = "venturechat", name = "VentureChat", version = "3.1.0",
description = "#1 Channels Chat plugin! Spigot + Bungee. Supports PlaceholderAPI + JSON formatting. Moderation GUI!", authors = {"Aust1n46"}) description = "#1 Channels Chat plugin! Spigot + Bungee. Supports PlaceholderAPI + JSON formatting. Moderation GUI!", authors = {"Aust1n46"})
public class VentureChatVelocity implements VentureChatProxySource { public class VentureChatVelocity implements VentureChatProxySource {
private final ProxyServer proxyServer; private final ProxyServer proxyServer;
private final ChannelIdentifier channelIdentifier = MinecraftChannelIdentifier.create(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_NAMESPACE, VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_NAME); private final ChannelIdentifier channelIdentifier = MinecraftChannelIdentifier.create(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_NAMESPACE, VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_NAME);
private final Logger logger;
@Inject
@DataDirectory
private Path dataPath;
private File velocityPlayerDataDirectory;
private static Configuration velocityConfig;
@Inject @Inject
public VentureChatVelocity(ProxyServer server, Logger logger) { public VentureChatVelocity(ProxyServer server, Logger logger) {
this.proxyServer = server; this.proxyServer = server;
this.logger = logger;
}
public static Configuration getVelocityConfig() {
return velocityConfig;
} }
@Subscribe @Subscribe
public void onInitialize(ProxyInitializeEvent event) { public void onInitialize(ProxyInitializeEvent event) {
proxyServer.getChannelRegistrar().register(channelIdentifier); proxyServer.getChannelRegistrar().register(channelIdentifier);
File dataFolder = dataPath.toFile();
if(!dataFolder.exists()) {
dataFolder.mkdir();
}
File config = new File(dataFolder, "velocityconfig.yml");
try {
if(!config.exists()) {
Files.copy(getClass().getClassLoader().getResourceAsStream("velocityconfig.yml"), config.toPath());
}
velocityConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(dataFolder, "velocityconfig.yml"));
}
catch(Exception e) {
e.printStackTrace();
}
velocityPlayerDataDirectory = new File(dataPath.toAbsolutePath().toString() + "/PlayerData");
ProxyPlayerData.loadProxyPlayerData(velocityPlayerDataDirectory, this);
}
@Subscribe
public void onShutdown(ProxyShutdownEvent event) {
ProxyPlayerData.saveProxyPlayerData(velocityPlayerDataDirectory, this);
} }
@Subscribe @Subscribe
@ -64,7 +112,10 @@ public class VentureChatVelocity implements VentureChatProxySource {
} }
}); });
} }
catch(Exception e) { catch(IllegalStateException e) {
sendConsoleMessage("Velocity being finicky");
}
catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -101,4 +152,14 @@ public class VentureChatVelocity implements VentureChatProxySource {
RegisteredServer server = proxyServer.getServer(serverName).get(); RegisteredServer server = proxyServer.getServer(serverName).get();
return new VentureChatProxyServer(serverName, server.getPlayersConnected().isEmpty()); return new VentureChatProxyServer(serverName, server.getPlayersConnected().isEmpty());
} }
@Override
public void sendConsoleMessage(String message) {
logger.info(Format.stripColor(message));
}
@Override
public boolean isOfflineServerAcknowledgementSet() {
return velocityConfig.getBoolean("offline_server_acknowledgement");
}
} }

View File

@ -13,38 +13,32 @@ import java.util.UUID;
import mineverse.Aust1n46.chat.api.MineverseChatAPI; import mineverse.Aust1n46.chat.api.MineverseChatAPI;
import mineverse.Aust1n46.chat.api.SynchronizedMineverseChatPlayer; import mineverse.Aust1n46.chat.api.SynchronizedMineverseChatPlayer;
import mineverse.Aust1n46.chat.bungee.MineverseChatBungee; import mineverse.Aust1n46.chat.bungee.VentureChatProxySource;
import mineverse.Aust1n46.chat.command.mute.MuteContainer; import mineverse.Aust1n46.chat.command.mute.MuteContainer;
import mineverse.Aust1n46.chat.utilities.Format;
import mineverse.Aust1n46.chat.utilities.UUIDFetcher; import mineverse.Aust1n46.chat.utilities.UUIDFetcher;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration; import net.md_5.bungee.config.YamlConfiguration;
/** /**
* Class for reading and writing bungee player data. * Class for reading and writing proxy player data.
* *
* @author Aust1n46 * @author Aust1n46
*/ */
public class BungeePlayerData { public class ProxyPlayerData {
private static MineverseChatBungee bungee = MineverseChatBungee.getInstance(); public static void loadLegacyBungeePlayerData(File dataFolder, VentureChatProxySource source) {
private static final String BUNGEE_PLAYER_DATA_DIRECTORY_PATH = bungee.getDataFolder().getAbsolutePath() + "/PlayerData"; File sync = new File(dataFolder, "BungeePlayers.yml");
public static void loadLegacyBungeePlayerData() {
File sync = new File(bungee.getDataFolder(), "BungeePlayers.yml");
if (!sync.exists()) { if (!sync.exists()) {
return; return;
} }
try { try {
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - Detected Legacy Player Data!"))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - Detected Legacy Player Data!");
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - Converting to new structure and deleting old BungeePlayers.yml file!"))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - Converting to new structure and deleting old BungeePlayers.yml file!");
Configuration playerData = ConfigurationProvider.getProvider(YamlConfiguration.class).load(sync); Configuration playerData = ConfigurationProvider.getProvider(YamlConfiguration.class).load(sync);
for (String uuidString : playerData.getKeys()) { for (String uuidString : playerData.getKeys()) {
UUID uuid = UUID.fromString(uuidString); UUID uuid = UUID.fromString(uuidString);
if (UUIDFetcher.shouldSkipOfflineUUIDBungee(uuid)) { if (UUIDFetcher.shouldSkipOfflineUUIDProxy(uuid, source)) {
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid);
continue; continue;
} }
Set<String> listening = new HashSet<String>(); Set<String> listening = new HashSet<String>();
@ -72,68 +66,68 @@ public class BungeePlayerData {
} }
} catch (Exception e) { } catch (Exception e) {
MineverseChatAPI.clearBungeePlayerMap(); MineverseChatAPI.clearBungeePlayerMap();
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - Error Loading Legacy Player Data!"))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - Error Loading Legacy Player Data!");
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - Deleted BungeePlayers.yml file!"))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - Deleted BungeePlayers.yml file!");
} finally { } finally {
sync.delete(); sync.delete();
} }
} }
public static void loadBungeePlayerData() { public static void loadProxyPlayerData(File dataFolder, VentureChatProxySource source) {
try { try {
File playerDataDirectory = new File(BUNGEE_PLAYER_DATA_DIRECTORY_PATH); File playerDataDirectory = dataFolder;
if (!playerDataDirectory.exists()) { if (!playerDataDirectory.exists()) {
playerDataDirectory.mkdirs(); playerDataDirectory.mkdirs();
} }
Files.walk(Paths.get(BUNGEE_PLAYER_DATA_DIRECTORY_PATH)) Files.walk(Paths.get(dataFolder.getAbsolutePath()))
.filter(Files::isRegularFile) .filter(Files::isRegularFile)
.forEach((path) -> readBungeePlayerDataFile(path)); .forEach((path) -> readProxyPlayerDataFile(path, source));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private static void readBungeePlayerDataFile(Path path) { private static void readProxyPlayerDataFile(Path path, VentureChatProxySource source) {
SynchronizedMineverseChatPlayer smcp; SynchronizedMineverseChatPlayer smcp;
File bungeePlayerDataFile = path.toFile(); File proxyPlayerDataFile = path.toFile();
if (!bungeePlayerDataFile.exists()) { if (!proxyPlayerDataFile.exists()) {
return; return;
} }
try { try {
Configuration bungeePlayerDataFileConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(bungeePlayerDataFile); Configuration proxyPlayerDataFileConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(proxyPlayerDataFile);
String uuidString = bungeePlayerDataFile.getName().replace(".yml", ""); String uuidString = proxyPlayerDataFile.getName().replace(".yml", "");
UUID uuid = UUID.fromString(uuidString); UUID uuid = UUID.fromString(uuidString);
if (UUIDFetcher.shouldSkipOfflineUUIDBungee(uuid)) { if (UUIDFetcher.shouldSkipOfflineUUIDProxy(uuid, source)) {
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid);
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - File will be skipped and deleted."))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - File will be skipped and deleted.");
bungeePlayerDataFile.delete(); proxyPlayerDataFile.delete();
return; return;
} }
Set<String> listening = new HashSet<String>(); Set<String> listening = new HashSet<String>();
StringTokenizer l = new StringTokenizer(bungeePlayerDataFileConfiguration.getString("channels"), ","); StringTokenizer l = new StringTokenizer(proxyPlayerDataFileConfiguration.getString("channels"), ",");
while (l.hasMoreTokens()) { while (l.hasMoreTokens()) {
String channel = l.nextToken(); String channel = l.nextToken();
listening.add(channel); listening.add(channel);
} }
HashMap<String, MuteContainer> mutes = new HashMap<String, MuteContainer>(); HashMap<String, MuteContainer> mutes = new HashMap<String, MuteContainer>();
Configuration muteSection = bungeePlayerDataFileConfiguration.getSection("mutes"); Configuration muteSection = proxyPlayerDataFileConfiguration.getSection("mutes");
for (String channelName : muteSection.getKeys()) { for (String channelName : muteSection.getKeys()) {
Configuration channelSection = muteSection.getSection(channelName); Configuration channelSection = muteSection.getSection(channelName);
mutes.put(channelName, new MuteContainer(channelName, channelSection.getLong("time"), channelSection.getString("reason"))); mutes.put(channelName, new MuteContainer(channelName, channelSection.getLong("time"), channelSection.getString("reason")));
} }
HashSet<UUID> ignores = new HashSet<UUID>(); HashSet<UUID> ignores = new HashSet<UUID>();
StringTokenizer n = new StringTokenizer(bungeePlayerDataFileConfiguration.getString("ignores"), ","); StringTokenizer n = new StringTokenizer(proxyPlayerDataFileConfiguration.getString("ignores"), ",");
while (n.hasMoreTokens()) { while (n.hasMoreTokens()) {
String ignore = n.nextToken(); String ignore = n.nextToken();
ignores.add(UUID.fromString(ignore)); ignores.add(UUID.fromString(ignore));
} }
boolean spy = bungeePlayerDataFileConfiguration.getBoolean("spy"); boolean spy = proxyPlayerDataFileConfiguration.getBoolean("spy");
boolean messageToggle = bungeePlayerDataFileConfiguration.getBoolean("messagetoggle"); boolean messageToggle = proxyPlayerDataFileConfiguration.getBoolean("messagetoggle");
smcp = new SynchronizedMineverseChatPlayer(uuid, listening, mutes, ignores, spy, messageToggle); smcp = new SynchronizedMineverseChatPlayer(uuid, listening, mutes, ignores, spy, messageToggle);
} catch (Exception e) { } catch (Exception e) {
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - Error Loading Data File: " + bungeePlayerDataFile.getName()))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - Error Loading Data File: " + proxyPlayerDataFile.getName());
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - File will be skipped and deleted."))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - File will be skipped and deleted.");
bungeePlayerDataFile.delete(); proxyPlayerDataFile.delete();
return; return;
} }
if (smcp != null) { if (smcp != null) {
@ -141,17 +135,17 @@ public class BungeePlayerData {
} }
} }
public static void saveBungeePlayerData() { public static void saveProxyPlayerData(File dataFolder, VentureChatProxySource source) {
try { try {
for (SynchronizedMineverseChatPlayer p : MineverseChatAPI.getSynchronizedMineverseChatPlayers()) { for (SynchronizedMineverseChatPlayer p : MineverseChatAPI.getSynchronizedMineverseChatPlayers()) {
if (UUIDFetcher.shouldSkipOfflineUUIDBungee(p.getUUID())) { if (UUIDFetcher.shouldSkipOfflineUUIDProxy(p.getUUID(), source)) {
return; return;
} }
File bungeePlayerDataFile = new File(BUNGEE_PLAYER_DATA_DIRECTORY_PATH, p.getUUID() + ".yml"); File proxyPlayerDataFile = new File(dataFolder.getAbsolutePath(), p.getUUID() + ".yml");
if (!bungeePlayerDataFile.exists()) { if (!proxyPlayerDataFile.exists()) {
bungeePlayerDataFile.createNewFile(); proxyPlayerDataFile.createNewFile();
} }
Configuration bungeePlayerDataFileConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(bungeePlayerDataFile); Configuration proxyPlayerDataFileConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(proxyPlayerDataFile);
String listen = ""; String listen = "";
for (String s : p.getListening()) for (String s : p.getListening())
@ -163,18 +157,18 @@ public class BungeePlayerData {
listen = listen.substring(0, listen.length() - 1); listen = listen.substring(0, listen.length() - 1);
if (ignore.length() > 0) if (ignore.length() > 0)
ignore = ignore.substring(0, ignore.length() - 1); ignore = ignore.substring(0, ignore.length() - 1);
bungeePlayerDataFileConfiguration.set("channels", listen); proxyPlayerDataFileConfiguration.set("channels", listen);
Configuration muteSection = createSection(bungeePlayerDataFileConfiguration, "mutes"); Configuration muteSection = createSection(proxyPlayerDataFileConfiguration, "mutes");
for (MuteContainer mute : p.getMutes()) { for (MuteContainer mute : p.getMutes()) {
Configuration channelSection = createSection(muteSection, mute.getChannel()); Configuration channelSection = createSection(muteSection, mute.getChannel());
channelSection.set("time", mute.getDuration()); channelSection.set("time", mute.getDuration());
channelSection.set("reason", mute.getReason()); channelSection.set("reason", mute.getReason());
} }
bungeePlayerDataFileConfiguration.set("ignores", ignore); proxyPlayerDataFileConfiguration.set("ignores", ignore);
bungeePlayerDataFileConfiguration.set("spy", p.isSpy()); proxyPlayerDataFileConfiguration.set("spy", p.isSpy());
bungeePlayerDataFileConfiguration.set("messagetoggle", p.getMessageToggle()); proxyPlayerDataFileConfiguration.set("messagetoggle", p.getMessageToggle());
ConfigurationProvider.getProvider(YamlConfiguration.class).save(bungeePlayerDataFileConfiguration, bungeePlayerDataFile); ConfigurationProvider.getProvider(YamlConfiguration.class).save(proxyPlayerDataFileConfiguration, proxyPlayerDataFile);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -486,7 +486,7 @@ public class ChatListener implements Listener {
String globalJSON = Format.convertToJson(mcp, format, chat); String globalJSON = Format.convertToJson(mcp, format, chat);
format = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), Format.FormatStringAll(format))); format = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), Format.FormatStringAll(format)));
String message = (format + chat).replaceAll("(\u00A7([a-z0-9]))", ""); // UTF-8 encoding issues. String message = Format.stripColor(format + chat); // UTF-8 encoding issues.
int hash = message.hashCode(); int hash = message.hashCode();
//Create VentureChatEvent //Create VentureChatEvent

View File

@ -878,4 +878,8 @@ public class Format {
return Sound.valueOf(DEFAULT_MESSAGE_SOUND); return Sound.valueOf(DEFAULT_MESSAGE_SOUND);
} }
} }
public static String stripColor(String message) {
return message.replaceAll("(\u00A7([a-z0-9]))", "");
}
} }

View File

@ -20,12 +20,9 @@ import org.json.simple.parser.JSONParser;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import mineverse.Aust1n46.chat.MineverseChat; import mineverse.Aust1n46.chat.MineverseChat;
import mineverse.Aust1n46.chat.bungee.MineverseChatBungee; import mineverse.Aust1n46.chat.bungee.VentureChatProxySource;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
//This class is used to query the Mojang servers to verify UUID's. public class UUIDFetcher implements Callable<Map<String, UUID>> {
public class UUIDFetcher implements Callable<Map<String, UUID>> { //unimplemented
private static final double PROFILES_PER_REQUEST = 100; private static final double PROFILES_PER_REQUEST = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser jsonParser = new JSONParser(); private final JSONParser jsonParser = new JSONParser();
@ -120,8 +117,8 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> { //unimplemente
return (uuidIsOffline(uuid) && !MineverseChat.getInstance().getConfig().getBoolean("offline_server_acknowledgement", false)); return (uuidIsOffline(uuid) && !MineverseChat.getInstance().getConfig().getBoolean("offline_server_acknowledgement", false));
} }
public static boolean shouldSkipOfflineUUIDBungee(UUID uuid) { public static boolean shouldSkipOfflineUUIDProxy(UUID uuid, VentureChatProxySource source) {
return (uuidIsOffline(uuid) && !MineverseChatBungee.getBungeeConfig().getBoolean("offline_server_acknowledgement", false)); return (uuidIsOffline(uuid) && !source.isOfflineServerAcknowledgementSet());
} }
public static void checkOfflineUUIDWarning(UUID uuid) { public static void checkOfflineUUIDWarning(UUID uuid) {
@ -137,15 +134,15 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> { //unimplemente
} }
} }
public static void checkOfflineUUIDWarningBungee(UUID uuid) { public static void checkOfflineUUIDWarningProxy(UUID uuid, VentureChatProxySource source) {
if(shouldSkipOfflineUUIDBungee(uuid)) { if(shouldSkipOfflineUUIDProxy(uuid, source)) {
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - Detected Offline UUID!"))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - Detected Offline UUID!");
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding."))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding.");
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/"))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/");
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it."))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it.");
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - If you're running a \"cracked\" server, player data might not be stored properly, and thus, you are on your own."))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you're running a \"cracked\" server, player data might not be stored properly, and thus, you are on your own.");
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - If you run your server in offline mode, you will probably lose your player data when switching to online mode!"))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you run your server in offline mode, you will probably lose your player data when switching to online mode!");
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Format.FormatStringAll("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!"))); source.sendConsoleMessage("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!");
return; return;
} }
} }

View File

@ -0,0 +1,11 @@
#===============================================================
# MineverseChat Velocity Config =
# Author: Aust1n46 =
#===============================================================
# If you're running a "cracked" server, player data might not be stored properly, and thus, you are on your own.
# If you run your server in offline mode, you might have to reset your player data when switching to online mode!
# If you see this warning by accident and you are using Velocity, make sure you have properly setup IP Forwarding.
# https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/
# No player data will be saved in offline mode unless you set this acknowledgement to 'true'
offline_server_acknowledgement: false