From 096da4db4dda4260c985830dea3f8cdf288f652f Mon Sep 17 00:00:00 2001 From: Aust1n46 Date: Sat, 15 Jan 2022 03:24:56 -0600 Subject: [PATCH] Move main classes for proxies. --- .../chat/VentureChatBungeePluginModule.java | 2 +- .../application}/VentureChatBungee.java | 5 +- .../application}/VentureChatVelocity.java | 72 ++++++++++--------- src/main/resources/bungee.yml | 2 +- src/main/resources/velocity-plugin.json | 2 +- 5 files changed, 44 insertions(+), 39 deletions(-) rename src/main/java/venture/Aust1n46/chat/{proxy => initiators/application}/VentureChatBungee.java (95%) rename src/main/java/venture/Aust1n46/chat/{proxy => initiators/application}/VentureChatVelocity.java (82%) diff --git a/src/main/java/venture/Aust1n46/chat/VentureChatBungeePluginModule.java b/src/main/java/venture/Aust1n46/chat/VentureChatBungeePluginModule.java index 35035a9..0a89d77 100644 --- a/src/main/java/venture/Aust1n46/chat/VentureChatBungeePluginModule.java +++ b/src/main/java/venture/Aust1n46/chat/VentureChatBungeePluginModule.java @@ -2,7 +2,7 @@ package venture.Aust1n46.chat; import com.google.inject.AbstractModule; -import venture.Aust1n46.chat.proxy.VentureChatBungee; +import venture.Aust1n46.chat.initiators.application.VentureChatBungee; public class VentureChatBungeePluginModule extends AbstractModule { private final VentureChatBungee plugin; diff --git a/src/main/java/venture/Aust1n46/chat/proxy/VentureChatBungee.java b/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChatBungee.java similarity index 95% rename from src/main/java/venture/Aust1n46/chat/proxy/VentureChatBungee.java rename to src/main/java/venture/Aust1n46/chat/initiators/application/VentureChatBungee.java index b79c739..b333935 100644 --- a/src/main/java/venture/Aust1n46/chat/proxy/VentureChatBungee.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChatBungee.java @@ -1,4 +1,4 @@ -package venture.Aust1n46.chat.proxy; +package venture.Aust1n46.chat.initiators.application; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -28,6 +28,9 @@ import net.md_5.bungee.config.YamlConfiguration; import net.md_5.bungee.event.EventHandler; import venture.Aust1n46.chat.VentureChatBungeePluginModule; import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController; +import venture.Aust1n46.chat.proxy.VentureChatProxy; +import venture.Aust1n46.chat.proxy.VentureChatProxyServer; +import venture.Aust1n46.chat.proxy.VentureChatProxySource; import venture.Aust1n46.chat.service.proxy.ProxyUuidService; import venture.Aust1n46.chat.utilities.FormatUtils; diff --git a/src/main/java/venture/Aust1n46/chat/proxy/VentureChatVelocity.java b/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChatVelocity.java similarity index 82% rename from src/main/java/venture/Aust1n46/chat/proxy/VentureChatVelocity.java rename to src/main/java/venture/Aust1n46/chat/initiators/application/VentureChatVelocity.java index ab5762a..e08835f 100644 --- a/src/main/java/venture/Aust1n46/chat/proxy/VentureChatVelocity.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChatVelocity.java @@ -1,4 +1,4 @@ -package venture.Aust1n46.chat.proxy; +package venture.Aust1n46.chat.initiators.application; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -33,6 +33,9 @@ import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.YamlConfiguration; import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController; +import venture.Aust1n46.chat.proxy.VentureChatProxy; +import venture.Aust1n46.chat.proxy.VentureChatProxyServer; +import venture.Aust1n46.chat.proxy.VentureChatProxySource; import venture.Aust1n46.chat.utilities.FormatUtils; /** @@ -42,104 +45,101 @@ import venture.Aust1n46.chat.utilities.FormatUtils; */ public class VentureChatVelocity implements VentureChatProxySource { 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 + + @Inject private VentureChatProxyFlatFileController proxyFlatFileController; @Inject private VentureChatProxy proxy; - + @Inject @DataDirectory private Path dataPath; private File velocityPlayerDataDirectory; - + private static Configuration velocityConfig; - + @Inject public VentureChatVelocity(ProxyServer server, Logger logger) { this.proxyServer = server; this.logger = logger; } - + public static Configuration getVelocityConfig() { return velocityConfig; } - + @Subscribe public void onInitialize(ProxyInitializeEvent event) { proxyServer.getChannelRegistrar().register(channelIdentifier); - + File dataFolder = dataPath.toFile(); - if(!dataFolder.exists()) { + if (!dataFolder.exists()) { dataFolder.mkdir(); } File config = new File(dataFolder, "velocityconfig.yml"); try { - if(!config.exists()) { + 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) { + } catch (Exception e) { e.printStackTrace(); } - + velocityPlayerDataDirectory = new File(dataPath.toAbsolutePath().toString() + "/PlayerData"); proxyFlatFileController.loadProxyPlayerData(velocityPlayerDataDirectory, this); } - + @Subscribe public void onShutdown(ProxyShutdownEvent event) { proxyFlatFileController.saveProxyPlayerData(velocityPlayerDataDirectory, this); } - + @Subscribe public void onPlayerJoin(ServerPostConnectEvent event) { updatePlayerNames(); } - + @Subscribe public void onPlayerQuit(DisconnectEvent event) { - // Delay sending plugin message to make sure disconnecting player is truly disconnected. + // Delay sending plugin message to make sure disconnecting player is truly + // disconnected. proxyServer.getScheduler().buildTask(this, () -> { updatePlayerNames(); - }) - .delay(1, TimeUnit.SECONDS) - .schedule(); + }).delay(1, TimeUnit.SECONDS).schedule(); } - + private void updatePlayerNames() { try { ByteArrayOutputStream outstream = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(outstream); out.writeUTF("PlayerNames"); out.writeInt(proxyServer.getPlayerCount()); - for(Player player : proxyServer.getAllPlayers()) { + for (Player player : proxyServer.getAllPlayers()) { out.writeUTF(player.getUsername()); } getServers().forEach(send -> { - if(!send.isEmpty()) { + if (!send.isEmpty()) { sendPluginMessage(send.getName(), outstream.toByteArray()); } - }); - } - catch(IllegalStateException e) { + }); + } catch (IllegalStateException e) { sendConsoleMessage("Velocity being finicky with DisconnectEvent."); - } - catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); } } - + @Subscribe public void onPluginMessage(PluginMessageEvent event) { String channelIdentifierId = event.getIdentifier().getId(); - if(!channelIdentifierId.equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !channelIdentifierId.contains("viaversion:")) { + if (!channelIdentifierId.equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !channelIdentifierId.contains("viaversion:")) { return; } - if(!(event.getSource() instanceof ServerConnection)) { + if (!(event.getSource() instanceof ServerConnection)) { return; } String serverName = ((ServerConnection) event.getSource()).getServerInfo().getName(); @@ -150,14 +150,16 @@ public class VentureChatVelocity implements VentureChatProxySource { @Override public void sendPluginMessage(String serverName, byte[] data) { Optional server = proxyServer.getServer(serverName); - if(server.isPresent()) { + if (server.isPresent()) { server.get().sendPluginMessage(channelIdentifier, data); } } @Override public List getServers() { - return proxyServer.getAllServers().stream().map(velocityServer -> new VentureChatProxyServer(velocityServer.getServerInfo().getName(), velocityServer.getPlayersConnected().isEmpty())).collect(Collectors.toList()); + return proxyServer.getAllServers().stream() + .map(velocityServer -> new VentureChatProxyServer(velocityServer.getServerInfo().getName(), velocityServer.getPlayersConnected().isEmpty())) + .collect(Collectors.toList()); } @Override diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml index 842149e..ea2ee42 100644 --- a/src/main/resources/bungee.yml +++ b/src/main/resources/bungee.yml @@ -1,4 +1,4 @@ name: VentureChat -main: venture.Aust1n46.chat.proxy.VentureChatBungee +main: venture.Aust1n46.chat.initiators.application.VentureChatBungee version: ${project.version} author: Aust1n46 diff --git a/src/main/resources/velocity-plugin.json b/src/main/resources/velocity-plugin.json index c3068aa..dd2075d 100644 --- a/src/main/resources/velocity-plugin.json +++ b/src/main/resources/velocity-plugin.json @@ -1 +1 @@ -{"id":"venturechat","name":"VentureChat","version":"${project.version}","description":"#1 Channels Chat plugin! Spigot + Bungee. Supports PlaceholderAPI + JSON formatting. Moderation GUI!","authors":["Aust1n46"],"dependencies":[],"main":"mineverse.Aust1n46.chat.proxy.VentureChatVelocity"} \ No newline at end of file +{"id":"venturechat","name":"VentureChat","version":"${project.version}","description":"#1 Channels Chat plugin! Spigot + Bungee. Supports PlaceholderAPI + JSON formatting. Moderation GUI!","authors":["Aust1n46"],"dependencies":[],"main":"venture.Aust1n46.chat.initiators.application.VentureChatVelocity"} \ No newline at end of file