Separate proxy architecture.

This commit is contained in:
Aust1n46 2022-01-15 03:13:12 -06:00
parent 4e9d70adfb
commit d7a55622be
18 changed files with 275 additions and 219 deletions

View File

@ -1,2 +0,0 @@
/org.eclipse.core.resources.prefs
/org.eclipse.m2e.core.prefs

View File

@ -1,8 +1,5 @@
eclipse.preferences.version=1 #Sat Jan 15 01:48:59 CST 2022
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.compliance=1.8

View File

@ -260,5 +260,11 @@
<version>4.2.0</version> <version>4.2.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,18 @@
package venture.Aust1n46.chat;
import com.google.inject.AbstractModule;
import venture.Aust1n46.chat.proxy.VentureChatBungee;
public class VentureChatBungeePluginModule extends AbstractModule {
private final VentureChatBungee plugin;
public VentureChatBungeePluginModule(final VentureChatBungee plugin) {
this.plugin = plugin;
}
@Override
protected void configure() {
this.bind(VentureChatBungee.class).toInstance(plugin);
}
}

View File

@ -19,8 +19,8 @@ import net.md_5.bungee.config.YamlConfiguration;
import venture.Aust1n46.chat.controllers.commands.MuteContainer; import venture.Aust1n46.chat.controllers.commands.MuteContainer;
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer; import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
import venture.Aust1n46.chat.proxy.VentureChatProxySource; import venture.Aust1n46.chat.proxy.VentureChatProxySource;
import venture.Aust1n46.chat.service.UUIDService; import venture.Aust1n46.chat.service.proxy.ProxyUuidService;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService; import venture.Aust1n46.chat.service.proxy.VentureChatProxyPlayerApiService;
/** /**
* Class for reading and writing proxy player data. * Class for reading and writing proxy player data.
@ -29,9 +29,9 @@ import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
*/ */
public class VentureChatProxyFlatFileController { public class VentureChatProxyFlatFileController {
@Inject @Inject
private UUIDService uuidService; private ProxyUuidService uuidService;
@Inject @Inject
private VentureChatPlayerApiService playerApiService; private VentureChatProxyPlayerApiService playerApiService;
public void loadLegacyBungeePlayerData(File dataFolder, VentureChatProxySource source) { public void loadLegacyBungeePlayerData(File dataFolder, VentureChatProxySource source) {
File sync = new File(dataFolder, "BungeePlayers.yml"); File sync = new File(dataFolder, "BungeePlayers.yml");

View File

@ -17,7 +17,8 @@ public class Me implements VentureCommand {
@Inject @Inject
private VentureChatPlayerApiService playerApiService; private VentureChatPlayerApiService playerApiService;
@Override @SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String command, String[] args) { public void execute(CommandSender sender, String command, String[] args) {
if (sender.hasPermission("venturechat.me")) { if (sender.hasPermission("venturechat.me")) {
if (args.length > 0) { if (args.length > 0) {

View File

@ -37,6 +37,7 @@ import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.utilities.FormatUtils;
//This class listens to chat through the chat event and handles the bulk of the chat channels and formatting. //This class listens to chat through the chat event and handles the bulk of the chat channels and formatting.
@SuppressWarnings("deprecation")
@Singleton @Singleton
public class ChatListener implements Listener { public class ChatListener implements Listener {
private final boolean essentialsDiscordHook = Bukkit.getPluginManager().isPluginEnabled("EssentialsDiscord"); private final boolean essentialsDiscordHook = Bukkit.getPluginManager().isPluginEnabled("EssentialsDiscord");
@ -54,8 +55,7 @@ public class ChatListener implements Listener {
private ConfigService configService; private ConfigService configService;
// this event isn't always asynchronous even though the event's name starts with "Async" // this event isn't always asynchronous even though the event's name starts with "Async"
// blame md_5 for that one @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) { public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
event.setCancelled(true); event.setCancelled(true);
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@ -564,7 +564,6 @@ public class ChatListener implements Listener {
System.out.println(out.size() + " bytes size with json"); System.out.println(out.size() + " bytes size with json");
} }
out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer())); // look into not sending this out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer())); // look into not sending this
@SuppressWarnings("deprecation") // Paper Deprecated
final String displayName = mcp.getPlayer().getDisplayName(); final String displayName = mcp.getPlayer().getDisplayName();
out.writeUTF(displayName); out.writeUTF(displayName);
pluginMessageController.sendPluginMessage(byteOutStream); pluginMessageController.sendPluginMessage(byteOutStream);

View File

@ -246,11 +246,14 @@ public class CommandListener implements CommandExecutor, Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void InventoryClick(InventoryClickEvent e) { public void InventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem(); if(!e.getView().getTitle().contains("VentureChat")) {
if(item == null || !e.getView().getTitle().contains("VentureChat")) {
return; return;
} }
e.setCancelled(true); e.setCancelled(true);
ItemStack item = e.getCurrentItem();
if (item == null) {
return;
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) e.getWhoClicked()); VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) e.getWhoClicked());
String playerName = e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", ""); String playerName = e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", "");
VentureChatPlayer target = playerApiService.getMineverseChatPlayer(playerName); VentureChatPlayer target = playerApiService.getMineverseChatPlayer(playerName);

View File

@ -18,6 +18,7 @@ public class SignListener implements Listener {
@Inject @Inject
private VentureChatPlayerApiService playerApiService; private VentureChatPlayerApiService playerApiService;
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onSignChange(SignChangeEvent event) { public void onSignChange(SignChangeEvent event) {
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer()); VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer());

View File

@ -7,7 +7,9 @@ import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.google.inject.Guice;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector;
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.chat.TextComponent;
@ -24,8 +26,9 @@ 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;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import venture.Aust1n46.chat.VentureChatBungeePluginModule;
import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController; import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController;
import venture.Aust1n46.chat.service.UUIDService; import venture.Aust1n46.chat.service.proxy.ProxyUuidService;
import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.utilities.FormatUtils;
/** /**
@ -38,7 +41,7 @@ public class VentureChatBungee extends Plugin implements Listener, VentureChatPr
private File bungeePlayerDataDirectory; private File bungeePlayerDataDirectory;
@Inject @Inject
private UUIDService uuidService; private ProxyUuidService uuidService;
@Inject @Inject
private VentureChatProxyFlatFileController proxyFlatFileController; private VentureChatProxyFlatFileController proxyFlatFileController;
@Inject @Inject
@ -46,17 +49,20 @@ public class VentureChatBungee extends Plugin implements Listener, VentureChatPr
@Override @Override
public void onEnable() { public void onEnable() {
if(!getDataFolder().exists()) { final VentureChatBungeePluginModule pluginModule = new VentureChatBungeePluginModule(this);
final Injector injector = Guice.createInjector(pluginModule);
injector.injectMembers(this);
if (!getDataFolder().exists()) {
getDataFolder().mkdir(); getDataFolder().mkdir();
} }
File config = new File(getDataFolder(), "bungeeconfig.yml"); File config = new File(getDataFolder(), "bungeeconfig.yml");
try { try {
if(!config.exists()) { if (!config.exists()) {
Files.copy(getResourceAsStream("bungeeconfig.yml"), config.toPath()); Files.copy(getResourceAsStream("bungeeconfig.yml"), config.toPath());
} }
bungeeConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "bungeeconfig.yml")); bungeeConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "bungeeconfig.yml"));
} } catch (Exception e) {
catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -94,27 +100,26 @@ public class VentureChatBungee extends Plugin implements Listener, VentureChatPr
DataOutputStream out = new DataOutputStream(outstream); DataOutputStream out = new DataOutputStream(outstream);
out.writeUTF("PlayerNames"); out.writeUTF("PlayerNames");
out.writeInt(getProxy().getPlayers().size()); out.writeInt(getProxy().getPlayers().size());
for(ProxiedPlayer pp : getProxy().getPlayers()) { for (ProxiedPlayer pp : getProxy().getPlayers()) {
out.writeUTF(pp.getName()); out.writeUTF(pp.getName());
} }
for(String send : getProxy().getServers().keySet()) { for (String send : getProxy().getServers().keySet()) {
if(getProxy().getServers().get(send).getPlayers().size() > 0) { if (getProxy().getServers().get(send).getPlayers().size() > 0) {
getProxy().getServers().get(send).sendData(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING, outstream.toByteArray()); getProxy().getServers().get(send).sendData(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING, outstream.toByteArray());
} }
} }
} } catch (Exception e) {
catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@EventHandler @EventHandler
public void onPluginMessage(PluginMessageEvent event) { public void onPluginMessage(PluginMessageEvent event) {
if(!event.getTag().equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !event.getTag().contains("viaversion:")) { if (!event.getTag().equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !event.getTag().contains("viaversion:")) {
return; return;
} }
if(!(event.getSender() instanceof Server)) { if (!(event.getSender() instanceof Server)) {
return; return;
} }
String serverName = ((Server) event.getSender()).getInfo().getName(); String serverName = ((Server) event.getSender()).getInfo().getName();
@ -128,7 +133,8 @@ public class VentureChatBungee extends Plugin implements Listener, VentureChatPr
@Override @Override
public List<VentureChatProxyServer> getServers() { public List<VentureChatProxyServer> getServers() {
return getProxy().getServers().values().stream().map(bungeeServer -> new VentureChatProxyServer(bungeeServer.getName(), bungeeServer.getPlayers().isEmpty())).collect(Collectors.toList()); return getProxy().getServers().values().stream().map(bungeeServer -> new VentureChatProxyServer(bungeeServer.getName(), bungeeServer.getPlayers().isEmpty()))
.collect(Collectors.toList());
} }
@Override @Override

View File

@ -12,7 +12,7 @@ import com.google.inject.Inject;
import venture.Aust1n46.chat.controllers.commands.MuteContainer; import venture.Aust1n46.chat.controllers.commands.MuteContainer;
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer; import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
import venture.Aust1n46.chat.model.TemporaryDataInstance; import venture.Aust1n46.chat.model.TemporaryDataInstance;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService; import venture.Aust1n46.chat.service.proxy.VentureChatProxyPlayerApiService;
public class VentureChatProxy { public class VentureChatProxy {
public static String PLUGIN_MESSAGING_CHANNEL_NAMESPACE = "venturechat"; public static String PLUGIN_MESSAGING_CHANNEL_NAMESPACE = "venturechat";
@ -20,7 +20,7 @@ public class VentureChatProxy {
public static String PLUGIN_MESSAGING_CHANNEL_STRING = "venturechat:data"; public static String PLUGIN_MESSAGING_CHANNEL_STRING = "venturechat:data";
@Inject @Inject
private VentureChatPlayerApiService playerApiService; private VentureChatProxyPlayerApiService playerApiService;
public void onPluginMessage(byte[] data, String serverName, VentureChatProxySource source) { public void onPluginMessage(byte[] data, String serverName, VentureChatProxySource source) {
ByteArrayInputStream instream = new ByteArrayInputStream(data); ByteArrayInputStream instream = new ByteArrayInputStream(data);

View File

@ -8,7 +8,6 @@ import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.proxy.VentureChatProxySource;
import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.utilities.FormatUtils;
@Singleton @Singleton
@ -16,47 +15,24 @@ public class UUIDService {
@Inject @Inject
private VentureChat plugin; private VentureChat plugin;
/** public boolean shouldSkipOfflineUUID(UUID uuid) {
* Returns whether the passed UUID is a v3 UUID. Offline UUIDs are v3, online are v4. return (FormatUtils.uuidIsOffline(uuid) && !plugin.getConfig().getBoolean("offline_server_acknowledgement", false));
* }
* @param uuid the UUID to check
* @return whether the UUID is a v3 UUID & thus is offline
*/
public boolean uuidIsOffline(UUID uuid) {
return uuid.version() == 3;
}
public boolean shouldSkipOfflineUUID(UUID uuid) { public void checkOfflineUUIDWarning(UUID uuid) {
return (uuidIsOffline(uuid) && !plugin.getConfig().getBoolean("offline_server_acknowledgement", false)); if (shouldSkipOfflineUUID(uuid)) {
} Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Detected Offline UUID!"));
Bukkit.getConsoleSender()
public boolean shouldSkipOfflineUUIDProxy(UUID uuid, VentureChatProxySource source) { .sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding."));
return (uuidIsOffline(uuid) && !source.isOfflineServerAcknowledgementSet()); Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/"));
} Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it."));
Bukkit.getConsoleSender().sendMessage(FormatUtils
public void checkOfflineUUIDWarning(UUID uuid) { .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."));
if(shouldSkipOfflineUUID(uuid)) { Bukkit.getConsoleSender().sendMessage(FormatUtils
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Detected Offline UUID!")); .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!"));
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding.")); Bukkit.getConsoleSender().sendMessage(FormatUtils
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/")); .FormatStringAll("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!"));
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it.")); return;
Bukkit.getConsoleSender().sendMessage(FormatUtils.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."));
Bukkit.getConsoleSender().sendMessage(FormatUtils.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!"));
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!"));
return;
} }
} }
public void checkOfflineUUIDWarningProxy(UUID uuid, VentureChatProxySource source) {
if(shouldSkipOfflineUUIDProxy(uuid, source)) {
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Detected Offline UUID!");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding.");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it.");
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.");
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!");
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;
}
}
} }

View File

@ -8,7 +8,8 @@ import java.util.UUID;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer; import com.google.inject.Singleton;
import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureChatPlayer;
/** /**
@ -17,152 +18,125 @@ import venture.Aust1n46.chat.model.VentureChatPlayer;
* *
* @author Aust1n46 * @author Aust1n46
*/ */
@Singleton
public class VentureChatPlayerApiService { public class VentureChatPlayerApiService {
private static HashMap<UUID, VentureChatPlayer> playerMap = new HashMap<UUID, VentureChatPlayer>(); private final HashMap<UUID, VentureChatPlayer> playerMap = new HashMap<>();
private static HashMap<String, UUID> namesMap = new HashMap<String, UUID>(); private final HashMap<String, UUID> namesMap = new HashMap<>();
private static HashMap<UUID, VentureChatPlayer> onlinePlayerMap = new HashMap<UUID, VentureChatPlayer>(); private final HashMap<UUID, VentureChatPlayer> onlinePlayerMap = new HashMap<>();
private final List<String> networkPlayerNames = new ArrayList<>();
private static List<String> networkPlayerNames = new ArrayList<String>(); public void addNameToMap(VentureChatPlayer mcp) {
private static HashMap<UUID, SynchronizedVentureChatPlayer> proxyPlayerMap = new HashMap<UUID, SynchronizedVentureChatPlayer>(); namesMap.put(mcp.getName(), mcp.getUuid());
}
public void addNameToMap(VentureChatPlayer mcp) { public void removeNameFromMap(String name) {
namesMap.put(mcp.getName(), mcp.getUuid()); namesMap.remove(name);
} }
public void removeNameFromMap(String name) { public void clearNameMap() {
namesMap.remove(name); namesMap.clear();
} }
public void clearNameMap() { public void addMineverseChatPlayerToMap(VentureChatPlayer mcp) {
namesMap.clear(); playerMap.put(mcp.getUuid(), mcp);
} }
public void addMineverseChatPlayerToMap(VentureChatPlayer mcp) { public void clearMineverseChatPlayerMap() {
playerMap.put(mcp.getUuid(), mcp); playerMap.clear();
} }
public void clearMineverseChatPlayerMap() { public Collection<VentureChatPlayer> getMineverseChatPlayers() {
playerMap.clear(); return playerMap.values();
} }
public Collection<VentureChatPlayer> getMineverseChatPlayers() { public void addMineverseChatOnlinePlayerToMap(VentureChatPlayer mcp) {
return playerMap.values(); onlinePlayerMap.put(mcp.getUuid(), mcp);
} }
public void addMineverseChatOnlinePlayerToMap(VentureChatPlayer mcp) { public void removeMineverseChatOnlinePlayerToMap(VentureChatPlayer mcp) {
onlinePlayerMap.put(mcp.getUuid(), mcp); onlinePlayerMap.remove(mcp.getUuid());
} }
public void removeMineverseChatOnlinePlayerToMap(VentureChatPlayer mcp) { public void clearOnlineMineverseChatPlayerMap() {
onlinePlayerMap.remove(mcp.getUuid()); onlinePlayerMap.clear();
} }
public void clearOnlineMineverseChatPlayerMap() { public Collection<VentureChatPlayer> getOnlineMineverseChatPlayers() {
onlinePlayerMap.clear(); return onlinePlayerMap.values();
} }
public Collection<VentureChatPlayer> getOnlineMineverseChatPlayers() { /**
return onlinePlayerMap.values(); * Get a MineverseChatPlayer wrapper from a Bukkit Player instance.
} *
* @param player {@link Player} object.
* @return {@link VentureChatPlayer}
*/
public VentureChatPlayer getMineverseChatPlayer(Player player) {
return getMineverseChatPlayer(player.getUniqueId());
}
/** /**
* Get a MineverseChatPlayer wrapper from a Bukkit Player instance. * Get a MineverseChatPlayer wrapper from a UUID.
* *
* @param player {@link Player} object. * @param uuid {@link UUID}.
* @return {@link VentureChatPlayer} * @return {@link VentureChatPlayer}
*/ */
public VentureChatPlayer getMineverseChatPlayer(Player player) { public VentureChatPlayer getMineverseChatPlayer(UUID uuid) {
return getMineverseChatPlayer(player.getUniqueId()); return playerMap.get(uuid);
} }
/** /**
* Get a MineverseChatPlayer wrapper from a UUID. * Get a MineverseChatPlayer wrapper from a user name.
* *
* @param uuid {@link UUID}. * @param name {@link String}.
* @return {@link VentureChatPlayer} * @return {@link VentureChatPlayer}
*/ */
public VentureChatPlayer getMineverseChatPlayer(UUID uuid) { public VentureChatPlayer getMineverseChatPlayer(String name) {
return playerMap.get(uuid); return getMineverseChatPlayer(namesMap.get(name));
} }
/** /**
* Get a MineverseChatPlayer wrapper from a user name. * Get a MineverseChatPlayer wrapper from a Bukkit Player instance. Only checks
* * current online players. Much more efficient!
* @param name {@link String}. *
* @return {@link VentureChatPlayer} * @param player {@link Player} object.
*/ * @return {@link VentureChatPlayer}
public VentureChatPlayer getMineverseChatPlayer(String name) { */
return getMineverseChatPlayer(namesMap.get(name)); public VentureChatPlayer getOnlineMineverseChatPlayer(final Player player) {
} return getOnlineMineverseChatPlayer(player.getUniqueId());
}
/** /**
* Get a MineverseChatPlayer wrapper from a Bukkit Player instance. Only checks * Get a MineverseChatPlayer wrapper from a UUID. Only checks current online
* current online players. Much more efficient! * players. Much more efficient!
* *
* @param player {@link Player} object. * @param uuid {@link UUID}.
* @return {@link VentureChatPlayer} * @return {@link VentureChatPlayer}
*/ */
public VentureChatPlayer getOnlineMineverseChatPlayer(final Player player) { public VentureChatPlayer getOnlineMineverseChatPlayer(UUID uuid) {
return getOnlineMineverseChatPlayer(player.getUniqueId()); return onlinePlayerMap.get(uuid);
} }
/** /**
* Get a MineverseChatPlayer wrapper from a UUID. Only checks current online * Get a MineverseChatPlayer wrapper from a user name. Only checks current
* players. Much more efficient! * online players. Much more efficient!
* *
* @param uuid {@link UUID}. * @param name {@link String}.
* @return {@link VentureChatPlayer} * @return {@link VentureChatPlayer}
*/ */
public VentureChatPlayer getOnlineMineverseChatPlayer(UUID uuid) { public VentureChatPlayer getOnlineMineverseChatPlayer(String name) {
return onlinePlayerMap.get(uuid); return getOnlineMineverseChatPlayer(namesMap.get(name));
} }
/** public List<String> getNetworkPlayerNames() {
* Get a MineverseChatPlayer wrapper from a user name. Only checks current return networkPlayerNames;
* online players. Much more efficient! }
*
* @param name {@link String}.
* @return {@link VentureChatPlayer}
*/
public VentureChatPlayer getOnlineMineverseChatPlayer(String name) {
return getOnlineMineverseChatPlayer(namesMap.get(name));
}
public void clearNetworkPlayerNames() {
networkPlayerNames.clear();
}
public void addNetworkPlayerName(String name) {
networkPlayerNames.add(name);
}
public List<String> getNetworkPlayerNames() {
return networkPlayerNames;
}
public void clearNetworkPlayerNames() {
networkPlayerNames.clear();
}
public void addNetworkPlayerName(String name) {
networkPlayerNames.add(name);
}
public void addSynchronizedMineverseChatPlayerToMap(SynchronizedVentureChatPlayer smcp) {
proxyPlayerMap.put(smcp.getUUID(), smcp);
}
public void clearProxyPlayerMap() {
proxyPlayerMap.clear();
}
public Collection<SynchronizedVentureChatPlayer> getSynchronizedMineverseChatPlayers() {
return proxyPlayerMap.values();
}
/**
* Get a SynchronizedMineverseChatPlayer from a UUID.
*
* @param uuid {@link UUID}
* @return {@link SynchronizedVentureChatPlayer}
*/
public SynchronizedVentureChatPlayer getSynchronizedMineverseChatPlayer(UUID uuid) {
return proxyPlayerMap.get(uuid);
}
} }

View File

@ -0,0 +1,29 @@
package venture.Aust1n46.chat.service.proxy;
import java.util.UUID;
import com.google.inject.Singleton;
import venture.Aust1n46.chat.proxy.VentureChatProxySource;
import venture.Aust1n46.chat.utilities.FormatUtils;
@Singleton
public class ProxyUuidService {
public boolean shouldSkipOfflineUUIDProxy(UUID uuid, VentureChatProxySource source) {
return (FormatUtils.uuidIsOffline(uuid) && !source.isOfflineServerAcknowledgementSet());
}
public void checkOfflineUUIDWarningProxy(UUID uuid, VentureChatProxySource source) {
if (shouldSkipOfflineUUIDProxy(uuid, source)) {
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Detected Offline UUID!");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding.");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it.");
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.");
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!");
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;
}
}
}

View File

@ -0,0 +1,36 @@
package venture.Aust1n46.chat.service.proxy;
import java.util.Collection;
import java.util.HashMap;
import java.util.UUID;
import com.google.inject.Singleton;
import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer;
@Singleton
public class VentureChatProxyPlayerApiService {
private final HashMap<UUID, SynchronizedVentureChatPlayer> proxyPlayerMap = new HashMap<>();
public void addSynchronizedMineverseChatPlayerToMap(SynchronizedVentureChatPlayer smcp) {
proxyPlayerMap.put(smcp.getUUID(), smcp);
}
public void clearProxyPlayerMap() {
proxyPlayerMap.clear();
}
public Collection<SynchronizedVentureChatPlayer> getSynchronizedMineverseChatPlayers() {
return proxyPlayerMap.values();
}
/**
* Get a SynchronizedMineverseChatPlayer from a UUID.
*
* @param uuid {@link UUID}
* @return {@link SynchronizedVentureChatPlayer}
*/
public SynchronizedVentureChatPlayer getSynchronizedMineverseChatPlayer(UUID uuid) {
return proxyPlayerMap.get(uuid);
}
}

View File

@ -1,5 +1,6 @@
package venture.Aust1n46.chat.utilities; package venture.Aust1n46.chat.utilities;
import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -300,4 +301,15 @@ public class FormatUtils {
public static String stripColor(String message) { public static String stripColor(String message) {
return message.replaceAll("(\u00A7([a-z0-9]))", ""); return message.replaceAll("(\u00A7([a-z0-9]))", "");
} }
/**
* Returns whether the passed UUID is a v3 UUID. Offline UUIDs are v3, online
* are v4.
*
* @param uuid the UUID to check
* @return whether the UUID is a v3 UUID & thus is offline
*/
public static boolean uuidIsOffline(UUID uuid) {
return uuid.version() == 3;
}
} }

View File

@ -1,4 +1,4 @@
name: VentureChat name: VentureChat
main: mineverse.Aust1n46.chat.proxy.VentureChatBungee main: venture.Aust1n46.chat.proxy.VentureChatBungee
version: ${project.version} version: ${project.version}
author: Aust1n46 author: Aust1n46

View File

@ -1,7 +1,7 @@
name: VentureChat name: VentureChat
version: ${project.version} version: ${project.version}
api-version: 1.13 api-version: 1.13
main: venture.Aust1n46.chat.VentureChat main: venture.Aust1n46.chat.initiators.application.VentureChat
depend: [Vault, ProtocolLib, PlaceholderAPI] depend: [Vault, ProtocolLib, PlaceholderAPI]
softdepend: [Towny, Factions, EssentialsDiscord] softdepend: [Towny, Factions, EssentialsDiscord]
author: Aust1n46 author: Aust1n46