From d6350e6feb80e41aa411f48cf5d00584f2fa26d4 Mon Sep 17 00:00:00 2001 From: Aust1n46 Date: Sat, 25 Dec 2021 19:41:17 -0600 Subject: [PATCH] More renaming and DI framework. --- .settings/org.eclipse.jdt.core.prefs | 9 +- pom.xml | 22 +- .../java/venture/Aust1n46/chat/Logger.java | 4 + .../chat/VentureChatPlaceholders.java | 1 + .../chat/VentureChatPluginModule.java | 8 +- .../chat/api/events/ChannelJoinEvent.java | 2 +- .../chat/api/events/MutePlayerEvent.java | 2 +- .../chat/api/events/VentureChatEvent.java | 7 +- .../controllers/PluginMessageController.java | 98 ++++---- .../VentureChatProxyFlatFileController.java | 2 +- .../VentureChatSpigotFlatFileController.java | 23 +- .../chat/controllers/commands/Broadcast.java | 6 +- .../controllers/commands/BungeeToggle.java | 2 +- .../chat/controllers/commands/Channel.java | 11 +- .../controllers/commands/Channelinfo.java | 9 +- .../chat/controllers/commands/Chatinfo.java | 11 +- .../chat/controllers/commands/Chatreload.java | 25 +- .../chat/controllers/commands/Chlist.java | 9 +- .../chat/controllers/commands/Chwho.java | 11 +- .../chat/controllers/commands/Clearchat.java | 4 +- .../controllers/commands/Commandblock.java | 4 +- .../chat/controllers/commands/Commandspy.java | 2 +- .../chat/controllers/commands/Edit.java | 6 +- .../chat/controllers/commands/Filter.java | 2 +- .../chat/controllers/commands/Force.java | 2 +- .../chat/controllers/commands/Forceall.java | 2 +- .../commands/IgnoreCommandExecutor.java | 4 +- .../controllers/commands/Kickchannel.java | 17 +- .../controllers/commands/Kickchannelall.java | 19 +- .../chat/controllers/commands/Leave.java | 17 +- .../chat/controllers/commands/Listen.java | 7 +- .../chat/controllers/commands/Me.java | 4 +- .../commands/MessageCommandExecutor.java | 8 +- .../controllers/commands/MessageToggle.java | 2 +- .../chat/controllers/commands/Mute.java | 17 +- .../chat/controllers/commands/Muteall.java | 11 +- .../controllers/commands/Notifications.java | 4 +- .../chat/controllers/commands/Party.java | 8 +- .../chat/controllers/commands/RangedSpy.java | 2 +- .../controllers/commands/Removemessage.java | 14 +- .../chat/controllers/commands/Reply.java | 8 +- .../chat/controllers/commands/Setchannel.java | 7 +- .../controllers/commands/Setchannelall.java | 7 +- .../chat/controllers/commands/Spy.java | 2 +- .../chat/controllers/commands/Unmute.java | 15 +- .../chat/controllers/commands/Unmuteall.java | 7 +- .../controllers/commands/VentureChatGui.java | 19 +- .../controllers/commands/Venturechat.java | 4 +- .../application}/VentureChat.java | 125 ++++------ .../initiators/listeners/ChatListener.java | 24 +- .../initiators/listeners/CommandListener.java | 23 +- .../initiators/listeners/LoginListener.java | 61 ++--- .../initiators/listeners/PacketListener.java | 4 +- .../initiators/listeners/SignListener.java | 2 +- .../listeners/VentureCommandExecutor.java | 60 ++--- .../schedulers/UnmuteScheduler.java | 13 +- .../chat/localization/InternalMessage.java | 4 +- .../chat/localization/Localization.java | 6 +- .../chat/localization/LocalizedMessage.java | 4 +- .../venture/Aust1n46/chat/model/Alias.java | 66 ++--- .../Aust1n46/chat/model/ChatChannel.java | 127 +--------- .../Aust1n46/chat/model/ChatMessage.java | 31 +-- .../venture/Aust1n46/chat/model/GuiSlot.java | 94 ++----- .../Aust1n46/chat/model/JsonAttribute.java | 21 +- .../Aust1n46/chat/model/JsonFormat.java | 65 +---- .../chat/model/VentureChatPlayer.java | 132 +--------- .../chat/proxy/VentureChatBungee.java | 4 +- .../Aust1n46/chat/proxy/VentureChatProxy.java | 2 +- .../chat/proxy/VentureChatProxyServer.java | 2 +- .../chat/proxy/VentureChatProxySource.java | 2 +- .../chat/proxy/VentureChatVelocity.java | 4 +- .../Aust1n46/chat/service/ConfigService.java | 225 +++++++++++++++++ .../Aust1n46/chat/service/UUIDService.java | 6 +- .../service/VentureChatDatabaseService.java | 4 +- .../service/VentureChatFormatService.java | 236 ++++++++++-------- .../service/VentureChatPlayerApiService.java | 12 +- .../Aust1n46/chat/utilities/FormatUtils.java | 6 +- .../chat/utilities}/VersionHandler.java | 2 +- .../listeners/LoginListenerTest.java | 51 +++- 79 files changed, 920 insertions(+), 985 deletions(-) rename src/main/java/{mineverse => venture}/Aust1n46/chat/api/events/ChannelJoinEvent.java (97%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/api/events/MutePlayerEvent.java (96%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/api/events/VentureChatEvent.java (95%) rename src/main/java/venture/Aust1n46/chat/{ => initiators/application}/VentureChat.java (71%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/localization/InternalMessage.java (81%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/localization/Localization.java (88%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/localization/LocalizedMessage.java (98%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/proxy/VentureChatBungee.java (98%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/proxy/VentureChatProxy.java (99%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/proxy/VentureChatProxyServer.java (88%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/proxy/VentureChatProxySource.java (90%) rename src/main/java/{mineverse => venture}/Aust1n46/chat/proxy/VentureChatVelocity.java (98%) create mode 100644 src/main/java/venture/Aust1n46/chat/service/ConfigService.java rename src/main/java/{mineverse => venture}/Aust1n46/chat/utilities/FormatUtils.java (98%) rename src/main/java/{mineverse/Aust1n46/chat/versions => venture/Aust1n46/chat/utilities}/VersionHandler.java (96%) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index b9ca028..2f5cc74 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,8 @@ -#Sun Nov 28 17:16:27 CST 2021 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.source=1.8 eclipse.preferences.version=1 +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 diff --git a/pom.xml b/pom.xml index d4d5059..8e05ebb 100644 --- a/pom.xml +++ b/pom.xml @@ -248,17 +248,17 @@ 1.18.22 provided - - junit - junit - 4.12 - test - - - org.mockito - mockito-inline - 3.12.4 - test + + org.junit.jupiter + junit-jupiter-engine + 5.8.2 + test + + + org.mockito + mockito-inline + 4.2.0 + test diff --git a/src/main/java/venture/Aust1n46/chat/Logger.java b/src/main/java/venture/Aust1n46/chat/Logger.java index f8adf7e..a8e18b3 100644 --- a/src/main/java/venture/Aust1n46/chat/Logger.java +++ b/src/main/java/venture/Aust1n46/chat/Logger.java @@ -3,7 +3,11 @@ package venture.Aust1n46.chat; import org.slf4j.LoggerFactory; import com.google.inject.Inject; +import com.google.inject.Singleton; +import venture.Aust1n46.chat.initiators.application.VentureChat; + +@Singleton public class Logger { private static final String LOG_PREFIX = "[VentureChat] "; diff --git a/src/main/java/venture/Aust1n46/chat/VentureChatPlaceholders.java b/src/main/java/venture/Aust1n46/chat/VentureChatPlaceholders.java index 6cdeeb1..85e5e54 100644 --- a/src/main/java/venture/Aust1n46/chat/VentureChatPlaceholders.java +++ b/src/main/java/venture/Aust1n46/chat/VentureChatPlaceholders.java @@ -6,6 +6,7 @@ import com.google.inject.Inject; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/VentureChatPluginModule.java b/src/main/java/venture/Aust1n46/chat/VentureChatPluginModule.java index 0b648ae..b24472a 100644 --- a/src/main/java/venture/Aust1n46/chat/VentureChatPluginModule.java +++ b/src/main/java/venture/Aust1n46/chat/VentureChatPluginModule.java @@ -1,8 +1,8 @@ package venture.Aust1n46.chat; import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; + +import venture.Aust1n46.chat.initiators.application.VentureChat; public class VentureChatPluginModule extends AbstractModule { private final VentureChat plugin; @@ -11,10 +11,6 @@ public class VentureChatPluginModule extends AbstractModule { this.plugin = plugin; } - public Injector createInjector() { - return Guice.createInjector(this); - } - @Override protected void configure() { this.bind(VentureChat.class).toInstance(plugin); diff --git a/src/main/java/mineverse/Aust1n46/chat/api/events/ChannelJoinEvent.java b/src/main/java/venture/Aust1n46/chat/api/events/ChannelJoinEvent.java similarity index 97% rename from src/main/java/mineverse/Aust1n46/chat/api/events/ChannelJoinEvent.java rename to src/main/java/venture/Aust1n46/chat/api/events/ChannelJoinEvent.java index 683ca08..7c4c192 100644 --- a/src/main/java/mineverse/Aust1n46/chat/api/events/ChannelJoinEvent.java +++ b/src/main/java/venture/Aust1n46/chat/api/events/ChannelJoinEvent.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.api.events; +package venture.Aust1n46.chat.api.events; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; diff --git a/src/main/java/mineverse/Aust1n46/chat/api/events/MutePlayerEvent.java b/src/main/java/venture/Aust1n46/chat/api/events/MutePlayerEvent.java similarity index 96% rename from src/main/java/mineverse/Aust1n46/chat/api/events/MutePlayerEvent.java rename to src/main/java/venture/Aust1n46/chat/api/events/MutePlayerEvent.java index bbada11..6f8ba97 100644 --- a/src/main/java/mineverse/Aust1n46/chat/api/events/MutePlayerEvent.java +++ b/src/main/java/venture/Aust1n46/chat/api/events/MutePlayerEvent.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.api.events; +package venture.Aust1n46.chat.api.events; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; diff --git a/src/main/java/mineverse/Aust1n46/chat/api/events/VentureChatEvent.java b/src/main/java/venture/Aust1n46/chat/api/events/VentureChatEvent.java similarity index 95% rename from src/main/java/mineverse/Aust1n46/chat/api/events/VentureChatEvent.java rename to src/main/java/venture/Aust1n46/chat/api/events/VentureChatEvent.java index 9515fc0..64f93ce 100644 --- a/src/main/java/mineverse/Aust1n46/chat/api/events/VentureChatEvent.java +++ b/src/main/java/venture/Aust1n46/chat/api/events/VentureChatEvent.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.api.events; +package venture.Aust1n46.chat.api.events; import java.util.Set; @@ -6,7 +6,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; @@ -17,6 +16,8 @@ import venture.Aust1n46.chat.model.VentureChatPlayer; * @author Aust1n46 */ public class VentureChatEvent extends Event { + private static final boolean ASYNC = true; + private static final HandlerList handlers = new HandlerList(); private final VentureChatPlayer mcp; private final String username; @@ -31,7 +32,7 @@ public class VentureChatEvent extends Event { private final boolean bungee; public VentureChatEvent(VentureChatPlayer mcp, String username, String playerPrimaryGroup, ChatChannel channel, Set recipients, int recipientCount, String format, String chat, String globalJSON, int hash, boolean bungee) { - super(VentureChat.ASYNC); + super(ASYNC); this.mcp = mcp; this.username = username; this.playerPrimaryGroup = playerPrimaryGroup; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java b/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java index e0fbff9..951ee8e 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java @@ -20,16 +20,17 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import me.clip.placeholderapi.PlaceholderAPI; -import mineverse.Aust1n46.chat.api.events.VentureChatEvent; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.api.events.VentureChatEvent; import venture.Aust1n46.chat.controllers.commands.MuteContainer; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatDatabaseService; import venture.Aust1n46.chat.service.VentureChatFormatService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; @Singleton public class PluginMessageController { @@ -43,6 +44,8 @@ public class PluginMessageController { private VentureChatFormatService formatService; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; public void sendPluginMessage(ByteArrayOutputStream byteOutStream) { if(playerApiService.getOnlineMineverseChatPlayers().size() > 0) { @@ -68,6 +71,15 @@ public class PluginMessageController { } } + public void synchronizeWithDelay(final VentureChatPlayer vcp, final boolean changes) { + final long delayInTicks = 20L; + plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { + public void run() { + synchronize(vcp, false); + } + }, delayInTicks); + } + public void synchronize(VentureChatPlayer mcp, boolean changes) { // System.out.println("Sync started..."); ByteArrayOutputStream outstream = new ByteArrayOutputStream(); @@ -82,7 +94,7 @@ public class PluginMessageController { Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { @Override public void run() { - if(!mcp.isOnline() || mcp.hasPlayed()) { + if(!mcp.isOnline() || mcp.isHasPlayed()) { return; } synchronize(mcp, false); @@ -95,14 +107,14 @@ public class PluginMessageController { // out.writeUTF("Channels"); int channelCount = 0; for(String c : mcp.getListening()) { - ChatChannel channel = ChatChannel.getChannel(c); + ChatChannel channel = configService.getChannel(c); if(channel.getBungee()) { channelCount++; } } out.write(channelCount); for(String c : mcp.getListening()) { - ChatChannel channel = ChatChannel.getChannel(c); + ChatChannel channel = configService.getChannel(c); if(channel.getBungee()) { out.writeUTF(channel.getName()); } @@ -110,7 +122,7 @@ public class PluginMessageController { // out.writeUTF("Mutes"); int muteCount = 0; for(MuteContainer mute : mcp.getMutes()) { - ChatChannel channel = ChatChannel.getChannel(mute.getChannel()); + ChatChannel channel = configService.getChannel(mute.getChannel()); if(channel.getBungee()) { muteCount++; } @@ -118,7 +130,7 @@ public class PluginMessageController { // System.out.println(muteCount + " mutes"); out.write(muteCount); for(MuteContainer mute : mcp.getMutes()) { - ChatChannel channel = ChatChannel.getChannel(mute.getChannel()); + ChatChannel channel = configService.getChannel(mute.getChannel()); if(channel.getBungee()) { out.writeUTF(channel.getName()); out.writeLong(mute.getDuration()); @@ -170,10 +182,10 @@ public class PluginMessageController { String globalJSON = msgin.readUTF(); String primaryGroup = msgin.readUTF(); - if(!ChatChannel.isChannel(chatchannel)) { + if(!configService.isChannel(chatchannel)) { return; } - ChatChannel chatChannelObject = ChatChannel.getChannel(chatchannel); + ChatChannel chatChannelObject = configService.getChannel(chatchannel); if(!chatChannelObject.getBungee()) { return; @@ -181,7 +193,7 @@ public class PluginMessageController { Set recipients = new HashSet(); for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { - if(p.isListening(chatChannelObject.getName())) { + if(configService.isListening(p, chatChannelObject.getName())) { recipients.add(p.getPlayer()); } } @@ -203,7 +215,7 @@ public class PluginMessageController { } for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { - if(p.isListening(chatChannelObject.getName())) { + if(configService.isListening(p, chatChannelObject.getName())) { if(!p.isBungeeToggle() && playerApiService.getOnlineMineverseChatPlayer(senderName) == null) { continue; } @@ -225,10 +237,10 @@ public class PluginMessageController { if(subchannel.equals("DiscordSRV")) { String chatChannel = msgin.readUTF(); String message = msgin.readUTF(); - if(!ChatChannel.isChannel(chatChannel)) { + if(!configService.isChannel(chatChannel)) { return; } - ChatChannel chatChannelObj = ChatChannel.getChannel(chatChannel); + ChatChannel chatChannelObj = configService.getChannel(chatChannel); if(!chatChannelObj.getBungee()) { return; } @@ -237,7 +249,7 @@ public class PluginMessageController { int hash = (message.replaceAll("([�]([a-z0-9]))", "")).hashCode(); for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { - if(p.isListening(chatChannelObj.getName())) { + if(configService.isListening(p, chatChannelObj.getName())) { String finalJSON = formatService.formatModerationGUI(json, p.getPlayer(), "Discord", chatChannelObj.getName(), hash); PacketContainer packet = formatService.createPacketPlayOutChat(finalJSON); formatService.sendPacketPlayOutChat(p.getPlayer(), packet); @@ -258,9 +270,9 @@ public class PluginMessageController { String sender = msgin.readUTF(); String chatchannel = msgin.readUTF(); List listening = new ArrayList(); - if(ChatChannel.isChannel(chatchannel)) { + if(configService.isChannel(chatchannel)) { for(VentureChatPlayer mcp : playerApiService.getOnlineMineverseChatPlayers()) { - if(mcp.isListening(chatchannel)) { + if(configService.isListening(mcp, chatchannel)) { String entry = "&f" + mcp.getName(); if(mcp.isMuted(chatchannel)) { entry = "&c" + mcp.getName(); @@ -284,7 +296,7 @@ public class PluginMessageController { String sender = msgin.readUTF(); String stringchannel = msgin.readUTF(); VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(UUID.fromString(sender)); - ChatChannel chatchannel = ChatChannel.getChannel(stringchannel); + ChatChannel chatchannel = configService.getChannel(stringchannel); String playerList = ""; int size = msgin.readInt(); for(int a = 0; a < size; a++) { @@ -309,12 +321,12 @@ public class PluginMessageController { } String uuid = msgin.readUTF(); VentureChatPlayer p = playerApiService.getOnlineMineverseChatPlayer(UUID.fromString(uuid)); - if(p == null || p.hasPlayed()) { + if(p == null || p.isHasPlayed()) { return; } for(Object ch : p.getListening().toArray()) { String c = ch.toString(); - ChatChannel cha = ChatChannel.getChannel(c); + ChatChannel cha = configService.getChannel(c); if(cha.getBungee()) { p.removeListening(c); } @@ -322,14 +334,14 @@ public class PluginMessageController { int size = msgin.read(); for(int a = 0; a < size; a++) { String ch = msgin.readUTF(); - if(ChatChannel.isChannel(ch)) { - ChatChannel cha = ChatChannel.getChannel(ch); + if(configService.isChannel(ch)) { + ChatChannel cha = configService.getChannel(ch); if(!cha.hasPermission() || p.getPlayer().hasPermission(cha.getPermission())) { p.addListening(ch); } } } - p.getMutes().removeIf(mute -> ChatChannel.getChannel(mute.getChannel()).getBungee()); + p.getMutes().removeIf(mute -> configService.getChannel(mute.getChannel()).getBungee()); int sizeB = msgin.read(); // System.out.println(sizeB + " mute size"); for(int b = 0; b < sizeB; b++) { @@ -337,7 +349,7 @@ public class PluginMessageController { long muteTime = msgin.readLong(); String muteReason = msgin.readUTF(); // System.out.println(ch); - if(ChatChannel.isChannel(ch)) { + if(configService.isChannel(ch)) { p.addMute(ch, muteTime, muteReason); } } @@ -355,10 +367,10 @@ public class PluginMessageController { // System.out.println(i); p.addIgnore(UUID.fromString(i)); } - if(!p.hasPlayed()) { + if(!p.isHasPlayed()) { boolean isThereABungeeChannel = false; - for(ChatChannel ch : ChatChannel.getAutojoinList()) { - if((!ch.hasPermission() || p.getPlayer().hasPermission(ch.getPermission())) && !p.isListening(ch.getName())) { + for(ChatChannel ch : configService.getAutojoinList()) { + if((!ch.hasPermission() || p.getPlayer().hasPermission(ch.getPermission())) && !configService.isListening(p, ch.getName())) { p.addListening(ch.getName()); if(ch.getBungee()) { isThereABungeeChannel = true; @@ -445,10 +457,10 @@ public class PluginMessageController { sendPluginMessage(stream); return; } - if(!ChatChannel.isChannel(channelName)) { + if(!configService.isChannel(channelName)) { return; } - ChatChannel chatChannelObj = ChatChannel.getChannel(channelName); + ChatChannel chatChannelObj = configService.getChannel(channelName); if (playerToMuteMCP.isMuted(chatChannelObj.getName())) { out.writeUTF("Mute"); out.writeUTF("AlreadyMuted"); @@ -516,10 +528,10 @@ public class PluginMessageController { String channelName = msgin.readUTF(); long time = msgin.readLong(); String reason = msgin.readUTF(); - if(!ChatChannel.isChannel(channelName)) { + if(!configService.isChannel(channelName)) { return; } - ChatChannel chatChannelObj = ChatChannel.getChannel(channelName); + ChatChannel chatChannelObj = configService.getChannel(channelName); if(time > 0) { String timeString = FormatUtils.parseTimeStringFromMillis(time); if(reason.isEmpty()) { @@ -617,10 +629,10 @@ public class PluginMessageController { String senderIdentifier = msgin.readUTF(); String playerToMute = msgin.readUTF(); String channelName = msgin.readUTF(); - if(!ChatChannel.isChannel(channelName)) { + if(!configService.isChannel(channelName)) { return; } - ChatChannel chatChannelObj = ChatChannel.getChannel(channelName); + ChatChannel chatChannelObj = configService.getChannel(channelName); if(senderIdentifier.equals("VentureChat:Console")) { Bukkit.getConsoleSender().sendMessage(LocalizedMessage.PLAYER_ALREADY_MUTED.toString() .replace("{player}", playerToMute).replace("{channel_color}", chatChannelObj.getColor()) @@ -654,10 +666,10 @@ public class PluginMessageController { sendPluginMessage(stream); return; } - if(!ChatChannel.isChannel(channelName)) { + if(!configService.isChannel(channelName)) { return; } - ChatChannel chatChannelObj = ChatChannel.getChannel(channelName); + ChatChannel chatChannelObj = configService.getChannel(channelName); if (!playerToUnmuteMCP.isMuted(chatChannelObj.getName())) { out.writeUTF("Unmute"); out.writeUTF("NotMuted"); @@ -686,10 +698,10 @@ public class PluginMessageController { String senderIdentifier = msgin.readUTF(); String playerToUnmute = msgin.readUTF(); String channelName = msgin.readUTF(); - if(!ChatChannel.isChannel(channelName)) { + if(!configService.isChannel(channelName)) { return; } - ChatChannel chatChannelObj = ChatChannel.getChannel(channelName); + ChatChannel chatChannelObj = configService.getChannel(channelName); if(senderIdentifier.equals("VentureChat:Console")) { Bukkit.getConsoleSender().sendMessage(LocalizedMessage.UNMUTE_PLAYER_SENDER.toString() .replace("{player}", playerToUnmute) @@ -724,10 +736,10 @@ public class PluginMessageController { String senderIdentifier = msgin.readUTF(); String playerToUnmute = msgin.readUTF(); String channelName = msgin.readUTF(); - if(!ChatChannel.isChannel(channelName)) { + if(!configService.isChannel(channelName)) { return; } - ChatChannel chatChannelObj = ChatChannel.getChannel(channelName); + ChatChannel chatChannelObj = configService.getChannel(channelName); if(senderIdentifier.equals("VentureChat:Console")) { Bukkit.getConsoleSender().sendMessage(LocalizedMessage.PLAYER_NOT_MUTED.toString() .replace("{player}", playerToUnmute).replace("{channel_color}", chatChannelObj.getColor()) @@ -782,11 +794,11 @@ public class PluginMessageController { return; } p.getPlayer().sendMessage(FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(p.getPlayer(), send.replaceAll("receiver_", ""))) + msg); - if(p.hasNotifications()) { + if(p.isNotifications()) { formatService.playMessageSound(p); } if(playerApiService.getMineverseChatPlayer(sender) == null) { - VentureChatPlayer senderMCP = new VentureChatPlayer(sender, sName); + VentureChatPlayer senderMCP = new VentureChatPlayer(sender, sName, configService.getDefaultChannel()); playerApiService.addMineverseChatPlayerToMap(senderMCP); playerApiService.addNameToMap(senderMCP); } @@ -832,7 +844,7 @@ public class PluginMessageController { VentureChatPlayer senderMCP = playerApiService.getOnlineMineverseChatPlayer(senderUUID); String echo = msgin.readUTF(); if(playerApiService.getMineverseChatPlayer(receiverUUID) == null) { - VentureChatPlayer receiverMCP = new VentureChatPlayer(receiverUUID, receiverName); + VentureChatPlayer receiverMCP = new VentureChatPlayer(receiverUUID, receiverName, configService.getDefaultChannel()); playerApiService.addMineverseChatPlayerToMap(receiverMCP); playerApiService.addNameToMap(receiverMCP); } diff --git a/src/main/java/venture/Aust1n46/chat/controllers/VentureChatProxyFlatFileController.java b/src/main/java/venture/Aust1n46/chat/controllers/VentureChatProxyFlatFileController.java index 3f22e56..a524f9b 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/VentureChatProxyFlatFileController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/VentureChatProxyFlatFileController.java @@ -13,12 +13,12 @@ import java.util.UUID; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.proxy.VentureChatProxySource; 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.commands.MuteContainer; import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer; +import venture.Aust1n46.chat.proxy.VentureChatProxySource; import venture.Aust1n46.chat.service.UUIDService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/VentureChatSpigotFlatFileController.java b/src/main/java/venture/Aust1n46/chat/controllers/VentureChatSpigotFlatFileController.java index 1201503..3299c80 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/VentureChatSpigotFlatFileController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/VentureChatSpigotFlatFileController.java @@ -21,13 +21,14 @@ import org.bukkit.configuration.file.YamlConfiguration; import com.google.inject.Inject; import com.google.inject.Singleton; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.commands.MuteContainer; +import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.UUIDService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; /** * Class for reading and writing player data. @@ -42,6 +43,8 @@ public class VentureChatSpigotFlatFileController { private UUIDService uuidService; @Inject private VentureChatPlayerApiService ventureChatApi; + @Inject + private ConfigService configService; private String playerDataDirectoryPath; @@ -67,7 +70,7 @@ public class VentureChatSpigotFlatFileController { } String name = playerData.getConfigurationSection("players." + uuid).getString("name"); String currentChannelName = playerData.getConfigurationSection("players." + uuid).getString("current"); - ChatChannel currentChannel = ChatChannel.isChannel(currentChannelName) ? ChatChannel.getChannel(currentChannelName) : ChatChannel.getDefaultChannel(); + ChatChannel currentChannel = configService.isChannel(currentChannelName) ? configService.getChannel(currentChannelName) : configService.getDefaultChannel(); Set ignores = new HashSet(); StringTokenizer i = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("ignores"), ","); while (i.hasMoreTokens()) { @@ -77,7 +80,7 @@ public class VentureChatSpigotFlatFileController { StringTokenizer l = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("listen"), ","); while (l.hasMoreTokens()) { String channel = l.nextToken(); - if (ChatChannel.isChannel(channel)) { + if (configService.isChannel(channel)) { listening.add(channel); } } @@ -85,7 +88,7 @@ public class VentureChatSpigotFlatFileController { StringTokenizer m = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("mutes"), ","); while (m.hasMoreTokens()) { String[] parts = m.nextToken().split(":"); - if (ChatChannel.isChannel(parts[0])) { + if (configService.isChannel(parts[0])) { if (parts[1].equals("null")) { Bukkit.getConsoleSender().sendMessage("[VentureChat] Null Mute Time: " + parts[0] + " " + name); continue; @@ -161,7 +164,7 @@ public class VentureChatSpigotFlatFileController { } String name = playerDataFileYamlConfiguration.getString("name"); String currentChannelName = playerDataFileYamlConfiguration.getString("current"); - ChatChannel currentChannel = ChatChannel.isChannel(currentChannelName) ? ChatChannel.getChannel(currentChannelName) : ChatChannel.getDefaultChannel(); + ChatChannel currentChannel = configService.isChannel(currentChannelName) ? configService.getChannel(currentChannelName) : configService.getDefaultChannel(); Set ignores = new HashSet(); StringTokenizer i = new StringTokenizer(playerDataFileYamlConfiguration.getString("ignores"), ","); while (i.hasMoreTokens()) { @@ -171,7 +174,7 @@ public class VentureChatSpigotFlatFileController { StringTokenizer l = new StringTokenizer(playerDataFileYamlConfiguration.getString("listen"), ","); while (l.hasMoreTokens()) { String channel = l.nextToken(); - if (ChatChannel.isChannel(channel)) { + if (configService.isChannel(channel)) { listening.add(channel); } } @@ -211,7 +214,7 @@ public class VentureChatSpigotFlatFileController { } public void savePlayerData(VentureChatPlayer mcp) { - if (mcp == null || uuidService.shouldSkipOfflineUUID(mcp.getUuid()) || (!mcp.isOnline() && !mcp.wasModified())) { + if (mcp == null || uuidService.shouldSkipOfflineUUID(mcp.getUuid()) || (!mcp.isOnline() && !mcp.isModified())) { return; } try { @@ -230,7 +233,7 @@ public class VentureChatSpigotFlatFileController { playerDataFileYamlConfiguration.set("ignores", ignores); String listening = ""; for (String channel : mcp.getListening()) { - ChatChannel c = ChatChannel.getChannel(channel); + ChatChannel c = configService.getChannel(channel); listening += c.getName() + ","; } String blockedCommands = ""; @@ -253,7 +256,7 @@ public class VentureChatSpigotFlatFileController { playerDataFileYamlConfiguration.set("host", mcp.isHost()); playerDataFileYamlConfiguration.set("party", mcp.hasParty() ? mcp.getParty().toString() : ""); playerDataFileYamlConfiguration.set("filter", mcp.isFilter()); - playerDataFileYamlConfiguration.set("notifications", mcp.hasNotifications()); + playerDataFileYamlConfiguration.set("notifications", mcp.isNotifications()); playerDataFileYamlConfiguration.set("spy", mcp.isSpy()); playerDataFileYamlConfiguration.set("commandspy", mcp.hasCommandSpy()); playerDataFileYamlConfiguration.set("rangedspy", mcp.getRangedSpy()); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Broadcast.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Broadcast.java index 3bddc11..3301d8a 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Broadcast.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Broadcast.java @@ -6,11 +6,11 @@ import org.bukkit.configuration.ConfigurationSection; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatFormatService; +import venture.Aust1n46.chat.utilities.FormatUtils; public class Broadcast implements VentureCommand { @Inject diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/BungeeToggle.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/BungeeToggle.java index f19e819..5586681 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/BungeeToggle.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/BungeeToggle.java @@ -6,8 +6,8 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Channel.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Channel.java index 48cac20..c0a69e2 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Channel.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Channel.java @@ -7,12 +7,13 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; import com.google.inject.Singleton; -import mineverse.Aust1n46.chat.api.events.ChannelJoinEvent; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.api.events.ChannelJoinEvent; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; @Singleton @@ -21,6 +22,8 @@ public class Channel implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -30,12 +33,12 @@ public class Channel implements VentureCommand { } VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender); if (args.length > 0) { - if (!ChatChannel.isChannel(args[0])) { + if (!configService.isChannel(args[0])) { mcp.getPlayer().sendMessage(LocalizedMessage.INVALID_CHANNEL.toString() .replace("{args}", args[0])); return; } - ChatChannel channel = ChatChannel.getChannel(args[0]); + ChatChannel channel = configService.getChannel(args[0]); ChannelJoinEvent channelJoinEvent = new ChannelJoinEvent(mcp.getPlayer(), channel, LocalizedMessage.SET_CHANNEL.toString() .replace("{channel_color}", channel.getColor() + "") .replace("{channel_name}", channel.getName())); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Channelinfo.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Channelinfo.java index 70183c1..a3566a7 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Channelinfo.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Channelinfo.java @@ -3,11 +3,16 @@ package venture.Aust1n46.chat.controllers.commands; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import mineverse.Aust1n46.chat.utilities.FormatUtils; +import com.google.inject.Inject; + import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; +import venture.Aust1n46.chat.utilities.FormatUtils; public class Channelinfo implements VentureCommand { + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -16,7 +21,7 @@ public class Channelinfo implements VentureCommand { sender.sendMessage(ChatColor.RED + "Invalid command: /channelinfo [channel]"); return; } - ChatChannel chname = ChatChannel.getChannel(args[0]); + ChatChannel chname = configService.getChannel(args[0]); if (chname == null) { sender.sendMessage(ChatColor.RED + "Invalid channel: " + args[0]); return; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Chatinfo.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Chatinfo.java index 8c618bd..ea4ef06 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Chatinfo.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Chatinfo.java @@ -10,11 +10,14 @@ import com.google.inject.Inject; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Chatinfo implements VentureCommand { @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -31,11 +34,11 @@ public class Chatinfo implements VentureCommand { if (args.length < 1) { mcp.getPlayer().sendMessage(ChatColor.GOLD + "Player: " + ChatColor.GREEN + mcp.getName()); for (String c : mcp.getListening()) { - ChatChannel channel = ChatChannel.getChannel(c); + ChatChannel channel = configService.getChannel(c); listen += channel.getColor() + channel.getName() + " "; } for (MuteContainer muteContainer : mcp.getMutes()) { - ChatChannel channel = ChatChannel.getChannel(muteContainer.getChannel()); + ChatChannel channel = configService.getChannel(muteContainer.getChannel()); mute += channel.getColor() + channel.getName() + " "; } for (String bc : mcp.getBlockedCommands()) { @@ -86,11 +89,11 @@ public class Chatinfo implements VentureCommand { } sender.sendMessage(ChatColor.GOLD + "Player: " + ChatColor.GREEN + p.getName()); for (String c : p.getListening()) { - ChatChannel channel = ChatChannel.getChannel(c); + ChatChannel channel = configService.getChannel(c); listen += channel.getColor() + channel.getName() + " "; } for (MuteContainer muteContainer : p.getMutes()) { - ChatChannel channel = ChatChannel.getChannel(muteContainer.getChannel()); + ChatChannel channel = configService.getChannel(muteContainer.getChannel()); mute += channel.getColor() + channel.getName() + " "; } for (String bc : p.getBlockedCommands()) { diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Chatreload.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Chatreload.java index 52735e8..d0f959b 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Chatreload.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Chatreload.java @@ -8,13 +8,15 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.model.JsonFormat; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; public class Chatreload implements VentureCommand { @Inject @@ -23,6 +25,8 @@ public class Chatreload implements VentureCommand { private VentureChatSpigotFlatFileController spigotFlatFileController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -33,7 +37,7 @@ public class Chatreload implements VentureCommand { playerApiService.clearOnlineMineverseChatPlayerMap(); plugin.reloadConfig(); - plugin.initializeConfigReaders(); + configService.postConstruct(); spigotFlatFileController.loadLegacyPlayerData(); spigotFlatFileController.loadPlayerData(); @@ -44,11 +48,20 @@ public class Chatreload implements VentureCommand { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - There could be an issue with your player data saving.")); String name = p.getName(); UUID uuid = p.getUniqueId(); - mcp = new VentureChatPlayer(uuid, name); + mcp = new VentureChatPlayer(uuid, name, configService.getDefaultChannel()); } mcp.setOnline(true); + mcp.setPlayer(plugin.getServer().getPlayer(mcp.getUuid())); mcp.setHasPlayed(false); - mcp.setJsonFormat(); + String jsonFormat = mcp.getJsonFormat(); + for(JsonFormat j : configService.getJsonFormats()) { + if(mcp.getPlayer().hasPermission("venturechat.json." + j.getName())) { + if(configService.getJsonFormat(mcp.getJsonFormat()).getPriority() > j.getPriority()) { + jsonFormat = j.getName(); + } + } + } + mcp.setJsonFormat(jsonFormat); playerApiService.addMineverseChatOnlinePlayerToMap(mcp); playerApiService.addNameToMap(mcp); } diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Chlist.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Chlist.java index b4055a5..5b7cc45 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Chlist.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Chlist.java @@ -2,16 +2,21 @@ package venture.Aust1n46.chat.controllers.commands; import org.bukkit.command.CommandSender; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import com.google.inject.Inject; + +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; public class Chlist implements VentureCommand { + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { sender.sendMessage(LocalizedMessage.CHANNEL_LIST_HEADER.toString()); - for (ChatChannel chname : ChatChannel.getChatChannels()) { + for (ChatChannel chname : configService.getChatChannels()) { if (chname.hasPermission()) { if (sender.hasPermission(chname.getPermission())) { sender.sendMessage(LocalizedMessage.CHANNEL_LIST_WITH_PERMISSIONS.toString() diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Chwho.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Chwho.java index 87c9e23..541b742 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Chwho.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Chwho.java @@ -1,6 +1,6 @@ package venture.Aust1n46.chat.controllers.commands; -import static venture.Aust1n46.chat.VentureChat.LINE_LENGTH; +import static venture.Aust1n46.chat.utilities.FormatUtils.LINE_LENGTH; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -16,12 +16,13 @@ import com.massivecraft.factions.entity.MPlayer; import com.palmergames.bukkit.towny.TownyUniverse; import com.palmergames.bukkit.towny.object.Resident; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Chwho implements VentureCommand { @@ -31,13 +32,15 @@ public class Chwho implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { String playerlist = ""; if (sender.hasPermission("venturechat.chwho")) { if (args.length > 0) { - ChatChannel channel = ChatChannel.getChannel(args[0]); + ChatChannel channel = configService.getChannel(args[0]); if (channel != null) { if (channel.hasPermission()) { if (!sender.hasPermission(channel.getPermission())) { diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Clearchat.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Clearchat.java index f948cac..eab9050 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Clearchat.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Clearchat.java @@ -4,8 +4,8 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.InternalMessage; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.localization.InternalMessage; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Commandblock.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Commandblock.java index 359fb7e..1f8b688 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Commandblock.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Commandblock.java @@ -6,8 +6,8 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Commandspy.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Commandspy.java index 6994e88..0f6dc3c 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Commandspy.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Commandspy.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Edit.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Edit.java index 9ab05cd..9d9e305 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Edit.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Edit.java @@ -13,13 +13,13 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.service.VentureChatFormatService; public class Edit implements VentureCommand { diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Filter.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Filter.java index f375464..020c907 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Filter.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Filter.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Force.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Force.java index 5c5f46b..39d3e14 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Force.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Force.java @@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Forceall.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Forceall.java index 88ef6ea..0cfa329 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Forceall.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Forceall.java @@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/IgnoreCommandExecutor.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/IgnoreCommandExecutor.java index 6f56172..467f85e 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/IgnoreCommandExecutor.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/IgnoreCommandExecutor.java @@ -16,9 +16,9 @@ import org.bukkit.util.StringUtil; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Kickchannel.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Kickchannel.java index f063e9b..ea5d889 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Kickchannel.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Kickchannel.java @@ -5,11 +5,12 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Kickchannel implements VentureCommand { @@ -17,6 +18,8 @@ public class Kickchannel implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -33,7 +36,7 @@ public class Kickchannel implements VentureCommand { .replace("{args}", args[0])); return; } - ChatChannel channel = ChatChannel.getChannel(args[1]); + ChatChannel channel = configService.getChannel(args[1]); if (channel == null) { sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString() .replace("{args}", args[1])); @@ -53,16 +56,16 @@ public class Kickchannel implements VentureCommand { } boolean isThereABungeeChannel = channel.getBungee(); if (player.getListening().size() == 0) { - player.addListening(ChatChannel.getDefaultChannel().getName()); - player.setCurrentChannel(ChatChannel.getDefaultChannel()); - if (ChatChannel.getDefaultChannel().getBungee()) { + player.addListening(configService.getDefaultChannel().getName()); + player.setCurrentChannel(configService.getDefaultChannel()); + if (configService.getDefaultChannel().getBungee()) { isThereABungeeChannel = true; } if (player.isOnline()) { player.getPlayer().sendMessage(LocalizedMessage.MUST_LISTEN_ONE_CHANNEL.toString()); player.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString() - .replace("{channel_color}", ChatColor.valueOf(ChatChannel.getDefaultColor().toUpperCase()) + "") - .replace("{channel_name}", ChatChannel.getDefaultChannel().getName())); + .replace("{channel_color}", ChatColor.valueOf(configService.getDefaultColor().toUpperCase()) + "") + .replace("{channel_name}", configService.getDefaultChannel().getName())); } else player.setModified(true); } diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Kickchannelall.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Kickchannelall.java index ad1653d..c6b9635 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Kickchannelall.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Kickchannelall.java @@ -5,11 +5,12 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Kickchannelall implements VentureCommand { @@ -17,6 +18,8 @@ public class Kickchannelall implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -35,8 +38,8 @@ public class Kickchannelall implements VentureCommand { } boolean isThereABungeeChannel = false; for (String channel : player.getListening()) { - if (ChatChannel.isChannel(channel)) { - ChatChannel chatChannelObj = ChatChannel.getChannel(channel); + if (configService.isChannel(channel)) { + ChatChannel chatChannelObj = configService.getChannel(channel); if (chatChannelObj.getBungee()) { isThereABungeeChannel = true; } @@ -45,9 +48,9 @@ public class Kickchannelall implements VentureCommand { player.clearListening(); sender.sendMessage(LocalizedMessage.KICK_CHANNEL_ALL_SENDER.toString() .replace("{player}", player.getName())); - player.addListening(ChatChannel.getDefaultChannel().getName()); - player.setCurrentChannel(ChatChannel.getDefaultChannel()); - if (ChatChannel.getDefaultChannel().getBungee()) { + player.addListening(configService.getDefaultChannel().getName()); + player.setCurrentChannel(configService.getDefaultChannel()); + if (configService.getDefaultChannel().getBungee()) { isThereABungeeChannel = true; } if (isThereABungeeChannel) { @@ -57,8 +60,8 @@ public class Kickchannelall implements VentureCommand { player.getPlayer().sendMessage(LocalizedMessage.KICK_CHANNEL_ALL_PLAYER.toString()); player.getPlayer().sendMessage(LocalizedMessage.MUST_LISTEN_ONE_CHANNEL.toString()); player.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString() - .replace("{channel_color}", ChatColor.valueOf(ChatChannel.getDefaultColor().toUpperCase()) + "") - .replace("{channel_name}", ChatChannel.getDefaultChannel().getName())); + .replace("{channel_color}", ChatColor.valueOf(configService.getDefaultColor().toUpperCase()) + "") + .replace("{channel_name}", configService.getDefaultChannel().getName())); } else { player.setModified(true); } diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Leave.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Leave.java index a5d58a7..19656d3 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Leave.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Leave.java @@ -7,11 +7,12 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Leave implements VentureCommand { @@ -19,6 +20,8 @@ public class Leave implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -28,7 +31,7 @@ public class Leave implements VentureCommand { } VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender); if (args.length > 0) { - ChatChannel channel = ChatChannel.getChannel(args[0]); + ChatChannel channel = configService.getChannel(args[0]); if (channel == null) { mcp.getPlayer().sendMessage(LocalizedMessage.INVALID_CHANNEL.toString() .replace("{args}", args[0])); @@ -40,15 +43,15 @@ public class Leave implements VentureCommand { .replace("{channel_name}", channel.getName())); boolean isThereABungeeChannel = channel.getBungee(); if (mcp.getListening().size() == 0) { - mcp.addListening(ChatChannel.getDefaultChannel().getName()); - mcp.setCurrentChannel(ChatChannel.getDefaultChannel()); - if (ChatChannel.getDefaultChannel().getBungee()) { + mcp.addListening(configService.getDefaultChannel().getName()); + mcp.setCurrentChannel(configService.getDefaultChannel()); + if (configService.getDefaultChannel().getBungee()) { isThereABungeeChannel = true; } mcp.getPlayer().sendMessage(LocalizedMessage.MUST_LISTEN_ONE_CHANNEL.toString()); mcp.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString() - .replace("{channel_color}", ChatColor.valueOf(ChatChannel.getDefaultColor().toUpperCase()) + "") - .replace("{channel_name}", ChatChannel.getDefaultChannel().getName())); + .replace("{channel_color}", ChatColor.valueOf(configService.getDefaultColor().toUpperCase()) + "") + .replace("{channel_name}", configService.getDefaultChannel().getName())); } if (isThereABungeeChannel) { pluginMessageController.synchronize(mcp, true); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Listen.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Listen.java index 456c281..5c71197 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Listen.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Listen.java @@ -6,11 +6,12 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Listen implements VentureCommand { @@ -18,6 +19,8 @@ public class Listen implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -27,7 +30,7 @@ public class Listen implements VentureCommand { } VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender); if (args.length > 0) { - ChatChannel channel = ChatChannel.getChannel(args[0]); + ChatChannel channel = configService.getChannel(args[0]); if (channel == null) { mcp.getPlayer().sendMessage(LocalizedMessage.INVALID_CHANNEL.toString() .replace("{args}", args[0])); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Me.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Me.java index db8cc73..243b57c 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Me.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Me.java @@ -5,10 +5,10 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.service.VentureChatFormatService; public class Me implements VentureCommand { diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/MessageCommandExecutor.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/MessageCommandExecutor.java index 814af3a..a536039 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/MessageCommandExecutor.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/MessageCommandExecutor.java @@ -15,12 +15,12 @@ import org.bukkit.util.StringUtil; import com.google.inject.Inject; import me.clip.placeholderapi.PlaceholderAPI; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.service.VentureChatFormatService; public class MessageCommandExecutor implements TabExecutor { @@ -109,7 +109,7 @@ public class MessageCommandExecutor implements TabExecutor { mcp.setReplyPlayer(player.getUuid()); player.getPlayer().sendMessage(send); mcp.getPlayer().sendMessage(echo); - if (player.hasNotifications()) { + if (player.isNotifications()) { formatService.playMessageSound(player); } if (!mcp.getPlayer().hasPermission("venturechat.spy.override")) { diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/MessageToggle.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/MessageToggle.java index 6e61c4f..bba6329 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/MessageToggle.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/MessageToggle.java @@ -6,8 +6,8 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Mute.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Mute.java index d246bdc..d91870b 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Mute.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Mute.java @@ -15,13 +15,14 @@ import org.bukkit.util.StringUtil; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; public class Mute implements VentureCommand { private static final List COMMON_MUTE_TIMES = Collections.unmodifiableList(Arrays.asList(new String[]{"12h", "15m", "1d", "1h", "1m", "30s"})); @@ -30,6 +31,8 @@ public class Mute implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -39,8 +42,8 @@ public class Mute implements VentureCommand { .replace("{args}", "[channel] [player] {time} {reason}")); return; } - if (ChatChannel.isChannel(args[0])) { - ChatChannel channel = ChatChannel.getChannel(args[0]); + if (configService.isChannel(args[0])) { + ChatChannel channel = configService.getChannel(args[0]); if (channel.isMutable()) { long datetime = System.currentTimeMillis(); long time = 0; @@ -167,13 +170,13 @@ public class Mute implements VentureCommand { public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { List completions = new ArrayList<>(); if (args.length == 1) { - StringUtil.copyPartialMatches(args[0], ChatChannel.getChatChannels().stream().map(ChatChannel::getName).collect(Collectors.toList()), completions); + StringUtil.copyPartialMatches(args[0], configService.getChatChannels().stream().map(ChatChannel::getName).collect(Collectors.toList()), completions); Collections.sort(completions); return completions; } if (args.length == 2) { - if (ChatChannel.isChannel(args[0])) { - ChatChannel chatChannelObj = ChatChannel.getChannel(args[0]); + if (configService.isChannel(args[0])) { + ChatChannel chatChannelObj = configService.getChannel(args[0]); if (chatChannelObj.getBungee()) { StringUtil.copyPartialMatches(args[1], playerApiService.getNetworkPlayerNames(), completions); Collections.sort(completions); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Muteall.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Muteall.java index fa9021b..907bc98 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Muteall.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Muteall.java @@ -4,19 +4,22 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; public class Muteall implements VentureCommand { @Inject private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -43,7 +46,7 @@ public class Muteall implements VentureCommand { } if (reason.isEmpty()) { boolean bungee = false; - for (ChatChannel channel : ChatChannel.getChatChannels()) { + for (ChatChannel channel : configService.getChatChannels()) { if (channel.isMutable()) { player.addMute(channel.getName()); if (channel.getBungee()) { @@ -63,7 +66,7 @@ public class Muteall implements VentureCommand { return; } else { boolean bungee = false; - for (ChatChannel channel : ChatChannel.getChatChannels()) { + for (ChatChannel channel : configService.getChatChannels()) { if (channel.isMutable()) { player.addMute(channel.getName(), reason); if (channel.getBungee()) { diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Notifications.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Notifications.java index 71dfc4f..fc2beae 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Notifications.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Notifications.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; @@ -23,7 +23,7 @@ public class Notifications implements VentureCommand { } VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender); - if (!mcp.hasNotifications()) { + if (!mcp.isNotifications()) { mcp.setNotifications(true); mcp.getPlayer().sendMessage(LocalizedMessage.NOTIFICATIONS_ON.toString()); return; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Party.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Party.java index d5cfb52..22a42fc 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Party.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Party.java @@ -1,6 +1,6 @@ package venture.Aust1n46.chat.controllers.commands; -import static venture.Aust1n46.chat.VentureChat.LINE_LENGTH; +import static venture.Aust1n46.chat.utilities.FormatUtils.LINE_LENGTH; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -8,12 +8,12 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; -import venture.Aust1n46.chat.service.VentureChatPlayerApiService; import venture.Aust1n46.chat.service.VentureChatFormatService; +import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; public class Party implements VentureCommand { @Inject diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/RangedSpy.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/RangedSpy.java index ea3a6dd..a184473 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/RangedSpy.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/RangedSpy.java @@ -1,6 +1,6 @@ package venture.Aust1n46.chat.controllers.commands; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Removemessage.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Removemessage.java index d6fef21..601271c 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Removemessage.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Removemessage.java @@ -16,16 +16,16 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.PluginMessageController; -import venture.Aust1n46.chat.model.ChatChannel; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; -import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatFormatService; +import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; public class Removemessage implements VentureCommand { @Inject @@ -36,6 +36,8 @@ public class Removemessage implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; private PacketContainer emptyLinePacketContainer; private WrappedChatComponent messageDeletedComponentPlayer; @@ -62,7 +64,7 @@ public class Removemessage implements VentureCommand { sender.sendMessage(LocalizedMessage.INVALID_HASH.toString()); return; } - if (args.length > 1 && ChatChannel.isChannel(args[1]) && ChatChannel.getChannel(args[1]).getBungee()) { + if (args.length > 1 && configService.isChannel(args[1]) && configService.getChannel(args[1]).getBungee()) { ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(byteOutStream); try { diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Reply.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Reply.java index 3e85536..5bf5c47 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Reply.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Reply.java @@ -9,13 +9,13 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; import me.clip.placeholderapi.PlaceholderAPI; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.service.VentureChatFormatService; public class Reply implements VentureCommand { @@ -101,7 +101,7 @@ public class Reply implements VentureCommand { } player.getPlayer().sendMessage(send); mcp.getPlayer().sendMessage(echo); - if (player.hasNotifications()) { + if (player.isNotifications()) { formatService.playMessageSound(player); } player.setReplyPlayer(mcp.getUuid()); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Setchannel.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Setchannel.java index b70044d..2a2a152 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Setchannel.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Setchannel.java @@ -4,11 +4,12 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Setchannel implements VentureCommand { @@ -16,6 +17,8 @@ public class Setchannel implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -32,7 +35,7 @@ public class Setchannel implements VentureCommand { .replace("{args}", args[0])); return; } - ChatChannel channel = ChatChannel.getChannel(args[1]); + ChatChannel channel = configService.getChannel(args[1]); if (channel == null) { sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString() .replace("{args}", args[1])); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Setchannelall.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Setchannelall.java index 6a9e93f..4c58628 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Setchannelall.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Setchannelall.java @@ -4,11 +4,12 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Setchannelall implements VentureCommand { @@ -16,6 +17,8 @@ public class Setchannelall implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -33,7 +36,7 @@ public class Setchannelall implements VentureCommand { return; } boolean isThereABungeeChannel = false; - for (ChatChannel channel : ChatChannel.getChatChannels()) { + for (ChatChannel channel : configService.getChatChannels()) { if (channel.hasPermission()) { if (!player.isOnline()) { sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE_NO_PERMISSIONS_CHECK.toString()); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Spy.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Spy.java index dffc044..3e3d98d 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Spy.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Spy.java @@ -6,8 +6,8 @@ import org.bukkit.entity.Player; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Unmute.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Unmute.java index 6583ac8..4901ad5 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Unmute.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Unmute.java @@ -14,11 +14,12 @@ import org.bukkit.util.StringUtil; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Unmute implements VentureCommand { @@ -26,6 +27,8 @@ public class Unmute implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -35,8 +38,8 @@ public class Unmute implements VentureCommand { .replace("{args}", "[channel] [player]")); return; } - if (ChatChannel.isChannel(args[0])) { - ChatChannel channel = ChatChannel.getChannel(args[0]); + if (configService.isChannel(args[0])) { + ChatChannel channel = configService.getChannel(args[0]); if (channel.getBungee()) { sendBungeeCordUnmute(sender, args[1], channel); return; @@ -77,13 +80,13 @@ public class Unmute implements VentureCommand { public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { List completions = new ArrayList<>(); if (args.length == 1) { - StringUtil.copyPartialMatches(args[0], ChatChannel.getChatChannels().stream().map(ChatChannel::getName).collect(Collectors.toList()), completions); + StringUtil.copyPartialMatches(args[0], configService.getChatChannels().stream().map(ChatChannel::getName).collect(Collectors.toList()), completions); Collections.sort(completions); return completions; } if (args.length == 2) { - if (ChatChannel.isChannel(args[0])) { - ChatChannel chatChannelObj = ChatChannel.getChannel(args[0]); + if (configService.isChannel(args[0])) { + ChatChannel chatChannelObj = configService.getChannel(args[0]); if (chatChannelObj.getBungee()) { StringUtil.copyPartialMatches(args[1], playerApiService.getNetworkPlayerNames(), completions); Collections.sort(completions); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Unmuteall.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Unmuteall.java index 7f5b67c..fa2eb45 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Unmuteall.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Unmuteall.java @@ -4,11 +4,12 @@ import org.bukkit.command.CommandSender; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; public class Unmuteall implements VentureCommand { @@ -16,6 +17,8 @@ public class Unmuteall implements VentureCommand { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -33,7 +36,7 @@ public class Unmuteall implements VentureCommand { return; } boolean bungee = false; - for (ChatChannel channel : ChatChannel.getChatChannels()) { + for (ChatChannel channel : configService.getChatChannels()) { player.removeMute(channel.getName()); if (channel.getBungee()) { bungee = true; diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/VentureChatGui.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/VentureChatGui.java index edf673d..f9792ec 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/VentureChatGui.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/VentureChatGui.java @@ -16,21 +16,24 @@ import org.bukkit.inventory.meta.SkullMeta; import com.google.inject.Inject; import me.clip.placeholderapi.PlaceholderAPI; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import mineverse.Aust1n46.chat.versions.VersionHandler; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.GuiSlot; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureCommand; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; +import venture.Aust1n46.chat.utilities.VersionHandler; public class VentureChatGui implements VentureCommand { @Inject private VentureChat plugin; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Override public void execute(CommandSender sender, String command, String[] args) { @@ -52,8 +55,8 @@ public class VentureChatGui implements VentureCommand { .replace("{args}", args[0])); return; } - if (ChatChannel.isChannel(args[1])) { - ChatChannel channel = ChatChannel.getChannel(args[1]); + if (configService.isChannel(args[1])) { + ChatChannel channel = configService.getChannel(args[1]); final int hash; try { hash = Integer.parseInt(args[2]); @@ -108,7 +111,7 @@ public class VentureChatGui implements VentureCommand { skull.setDurability((short) 3); inv.setItem(0, skull); - for (GuiSlot g : GuiSlot.getGuiSlots()) { + for (GuiSlot g : configService.getGuiSlots()) { if (!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) { if (this.checkSlot(g.getSlot())) { plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!")); @@ -165,7 +168,7 @@ public class VentureChatGui implements VentureCommand { skull.setDurability((short) 3); inv.setItem(0, skull); - for (GuiSlot g : GuiSlot.getGuiSlots()) { + for (GuiSlot g : configService.getGuiSlots()) { if (!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) { if (this.checkSlot(g.getSlot())) { plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!")); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/commands/Venturechat.java b/src/main/java/venture/Aust1n46/chat/controllers/commands/Venturechat.java index d112d41..9ff8995 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/commands/Venturechat.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/commands/Venturechat.java @@ -1,7 +1,7 @@ package venture.Aust1n46.chat.controllers.commands; -import mineverse.Aust1n46.chat.localization.InternalMessage; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.InternalMessage; //import net.md_5.bungee.api.chat.ClickEvent; //import net.md_5.bungee.api.chat.ComponentBuilder; //import net.md_5.bungee.api.chat.HoverEvent; diff --git a/src/main/java/venture/Aust1n46/chat/VentureChat.java b/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChat.java similarity index 71% rename from src/main/java/venture/Aust1n46/chat/VentureChat.java rename to src/main/java/venture/Aust1n46/chat/initiators/application/VentureChat.java index e6371ad..8a2905c 100644 --- a/src/main/java/venture/Aust1n46/chat/VentureChat.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChat.java @@ -1,4 +1,4 @@ -package venture.Aust1n46.chat; +package venture.Aust1n46.chat.initiators.application; import java.io.File; @@ -11,13 +11,14 @@ import org.bukkit.plugin.messaging.PluginMessageListener; import org.bukkit.scheduler.BukkitScheduler; import com.comphenix.protocol.ProtocolLibrary; +import com.google.inject.Guice; import com.google.inject.Inject; +import com.google.inject.Injector; import com.google.inject.Singleton; -import mineverse.Aust1n46.chat.localization.Localization; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; +import venture.Aust1n46.chat.VentureChatPlaceholders; +import venture.Aust1n46.chat.VentureChatPluginModule; import venture.Aust1n46.chat.controllers.PluginMessageController; import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController; import venture.Aust1n46.chat.initiators.listeners.ChatListener; @@ -27,13 +28,9 @@ import venture.Aust1n46.chat.initiators.listeners.PacketListener; import venture.Aust1n46.chat.initiators.listeners.SignListener; import venture.Aust1n46.chat.initiators.listeners.VentureCommandExecutor; import venture.Aust1n46.chat.initiators.schedulers.UnmuteScheduler; -import venture.Aust1n46.chat.model.Alias; -import venture.Aust1n46.chat.model.ChatChannel; -import venture.Aust1n46.chat.model.GuiSlot; -import venture.Aust1n46.chat.model.JsonFormat; -import venture.Aust1n46.chat.service.VentureChatDatabaseService; -import venture.Aust1n46.chat.service.VentureChatFormatService; +import venture.Aust1n46.chat.localization.Localization; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; /** * VentureChat Minecraft plugin for servers running Spigot or Paper software. @@ -42,10 +39,6 @@ import venture.Aust1n46.chat.service.VentureChatPlayerApiService; */ @Singleton public class VentureChat extends JavaPlugin implements PluginMessageListener { - public static final boolean ASYNC = true; - public static final boolean SYNC = false; - public static final int LINE_LENGTH = 40; - @Inject private LoginListener loginListener; @Inject @@ -55,99 +48,86 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener { @Inject private CommandListener commandListener; @Inject - private VentureCommandExecutor commandExecutor; - @Inject private PacketListener packetListener; @Inject private VentureChatPlaceholders ventureChatPlaceholders; @Inject - private VentureChatFormatService formatter; - @Inject - private VentureChatDatabaseService databaseService; - @Inject private VentureChatSpigotFlatFileController spigotFlatFileService; @Inject private VentureChatPlayerApiService playerApiService; @Inject - private UnmuteScheduler unmuteScheduler; - @Inject private PluginMessageController pluginMessageController; - + private Permission permission = null; - + @Override public void onEnable() { - VentureChatPluginModule pluginModule = new VentureChatPluginModule(this); - pluginModule.createInjector().injectMembers(this); - + final VentureChatPluginModule pluginModule = new VentureChatPluginModule(this); + final Injector injector = Guice.createInjector(pluginModule); + injector.injectMembers(this); + injector.injectMembers(new VentureCommandExecutor()); + injector.injectMembers(new UnmuteScheduler()); + try { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Initializing...")); - if(!getDataFolder().exists()) { + if (!getDataFolder().exists()) { getDataFolder().mkdirs(); } File file = new File(getDataFolder(), "config.yml"); - if(!file.exists()) { + if (!file.exists()) { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Config not found! Generating file.")); saveDefaultConfig(); - } - else { + } else { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Config found! Loading file.")); } saveResource("example_config_always_up_to_date!.yml", true); - } - catch(Exception ex) { + } catch (Exception ex) { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cCould not load configuration! Something unexpected went wrong!")); } - + Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Checking for Vault...")); - - if(!setupPermissions() || !setupChat()) { + + if (!setupPermissions()) { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cCould not find Vault and/or a Vault compatible permissions plugin!")); Bukkit.getPluginManager().disablePlugin(this); } - initializeConfigReaders(); - + Localization.initialize(this); + Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data")); spigotFlatFileService.loadLegacyPlayerData(); spigotFlatFileService.loadPlayerData(); registerListeners(); Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Registering Listeners")); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Attaching to Executors")); - - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Establishing BungeeCord")); + + Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Registering BungeeCord channels")); Bukkit.getMessenger().registerOutgoingPluginChannel(this, PluginMessageController.PLUGIN_MESSAGING_CHANNEL); Bukkit.getMessenger().registerIncomingPluginChannel(this, PluginMessageController.PLUGIN_MESSAGING_CHANNEL, this); - + PluginManager pluginManager = getServer().getPluginManager(); - if(pluginManager.isPluginEnabled("Towny")) { + if (pluginManager.isPluginEnabled("Towny")) { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabling Towny Formatting")); } - if(pluginManager.isPluginEnabled("Jobs")) { + if (pluginManager.isPluginEnabled("Jobs")) { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabling Jobs Formatting")); } - if(pluginManager.isPluginEnabled("Factions")) { - String version = pluginManager.getPlugin("Factions").getDescription().getVersion(); + if (pluginManager.isPluginEnabled("Factions")) { + final String version = pluginManager.getPlugin("Factions").getDescription().getVersion(); Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabling Factions Formatting version " + version)); } - if(pluginManager.isPluginEnabled("PlaceholderAPI")) { + if (pluginManager.isPluginEnabled("PlaceholderAPI")) { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabling PlaceholderAPI Hook")); } - + ventureChatPlaceholders.register(); - + startRepeatingTasks(); - - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabled Successfully")); + + Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Enabled Successfully")); } - - @Override - public void onLoad() { - //new DebugLoggingProvider().enableDebugLogging(); - } - + @Override public void onDisable() { spigotFlatFileService.savePlayerData(); @@ -157,20 +137,20 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Disabling...")); Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Disabled Successfully")); } - + private void startRepeatingTasks() { BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); scheduler.runTaskTimerAsynchronously(this, new Runnable() { @Override public void run() { spigotFlatFileService.savePlayerData(); - if(getConfig().getString("loglevel", "info").equals("debug")) { + if (getConfig().getString("loglevel", "info").equals("debug")) { Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Saving Player Data")); } } - }, 0L, getConfig().getInt("saveinterval") * 1200); //one minute * save interval + }, 0L, getConfig().getInt("saveinterval") * 1200); // one minute * save interval } - + private void registerListeners() { PluginManager pluginManager = getServer().getPluginManager(); pluginManager.registerEvents(chatListener, this); @@ -179,32 +159,15 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener { pluginManager.registerEvents(loginListener, this); ProtocolLibrary.getProtocolManager().addPacketListener(packetListener); } - + private boolean setupPermissions() { RegisteredServiceProvider permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); - if(permissionProvider != null) { + if (permissionProvider != null) { permission = permissionProvider.getProvider(); } - return(permission != null); + return (permission != null); } - private boolean setupChat() { - RegisteredServiceProvider chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class); - Chat chat = null; - if(chatProvider != null) { - chat = chatProvider.getProvider(); - } - return(chat != null); - } - - public void initializeConfigReaders() { - Localization.initialize(this); - Alias.initialize(this); - JsonFormat.initialize(this); - GuiSlot.initialize(this); - ChatChannel.initialize(this, formatter, false); - } - public Permission getVaultPermission() { return permission; } diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java index b08dd4d..707c2a1 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java @@ -22,18 +22,19 @@ import com.palmergames.bukkit.towny.TownyUniverse; import com.palmergames.bukkit.towny.object.Resident; import me.clip.placeholderapi.PlaceholderAPI; -import mineverse.Aust1n46.chat.api.events.VentureChatEvent; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; import net.essentialsx.api.v2.services.discord.DiscordService; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.api.events.VentureChatEvent; import venture.Aust1n46.chat.controllers.PluginMessageController; import venture.Aust1n46.chat.controllers.commands.MuteContainer; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatDatabaseService; import venture.Aust1n46.chat.service.VentureChatFormatService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +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. @Singleton @@ -49,6 +50,8 @@ public class ChatListener implements Listener { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; // this event isn't always asynchronous even though the event's name starts with "Async" // blame md_5 for that one @@ -151,7 +154,7 @@ public class ChatListener implements Listener { } tp.getPlayer().sendMessage(send); mcp.getPlayer().sendMessage(echo); - if(tp.hasNotifications()) { + if(tp.isNotifications()) { formatService.playMessageSound(tp); } mcp.setReplyPlayer(tp.getUuid()); @@ -256,7 +259,7 @@ public class ChatListener implements Listener { mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString()); mcp.setQuickChat(false); mcp.removeListening(eventChannel.getName()); - mcp.setCurrentChannel(ChatChannel.getDefaultChannel()); + mcp.setCurrentChannel(configService.getDefaultChannel()); return; } if(eventChannel.hasSpeakPermission() && !mcp.getPlayer().hasPermission(eventChannel.getSpeakPermission())) { @@ -364,7 +367,7 @@ public class ChatListener implements Listener { PluginManager pluginManager = plugin.getServer().getPluginManager(); for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { if(p.getPlayer() != mcp.getPlayer()) { - if(!p.isListening(eventChannel.getName())) { + if(!configService.isListening(p, eventChannel.getName())) { recipients.remove(p.getPlayer()); recipientCount--; continue; @@ -560,9 +563,10 @@ public class ChatListener implements Listener { if(plugin.getConfig().getString("loglevel", "info").equals("debug")) { System.out.println(out.size() + " bytes size with json"); } - out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer())); - // look into not sending this - out.writeUTF(mcp.getPlayer().getDisplayName()); + out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer())); // look into not sending this + @SuppressWarnings("deprecation") // Paper Deprecated + final String displayName = mcp.getPlayer().getDisplayName(); + out.writeUTF(displayName); pluginMessageController.sendPluginMessage(byteOutStream); out.close(); } diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/CommandListener.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/CommandListener.java index cbbbc7b..c2c5fee 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/CommandListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/CommandListener.java @@ -23,16 +23,17 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import me.clip.placeholderapi.PlaceholderAPI; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import mineverse.Aust1n46.chat.versions.VersionHandler; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.PluginMessageController; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.Alias; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.GuiSlot; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; +import venture.Aust1n46.chat.utilities.VersionHandler; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatDatabaseService; import venture.Aust1n46.chat.service.VentureChatFormatService; @@ -50,6 +51,8 @@ public class CommandListener implements CommandExecutor, Listener { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @EventHandler public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) throws FileNotFoundException { @@ -94,7 +97,7 @@ public class CommandListener implements CommandExecutor, Listener { databaseService.writeVentureChat(mcp.getUuid().toString(), mcp.getName(), "Local", "Command_Component", event.getMessage().replace("'", "''"), "Command"); } - for(Alias a : Alias.getAliases()) { + for(Alias a : configService.getAliases()) { if(message.toLowerCase().substring(1).split(" ")[0].equals(a.getName().toLowerCase())) { for(String s : a.getComponents()) { if(!mcp.getPlayer().hasPermission(a.getPermission()) && a.hasPermission()) { @@ -145,8 +148,8 @@ public class CommandListener implements CommandExecutor, Listener { } } - if(!ChatChannel.areAliasesRegisteredAsCommands()) { - for(ChatChannel channel : ChatChannel.getChatChannels()) { + if(!configService.areAliasesRegisteredAsCommands()) { + for(ChatChannel channel : configService.getChatChannels()) { if(!channel.hasPermission() || mcp.getPlayer().hasPermission(channel.getPermission())) { if(message.equals("/" + channel.getAlias())) { mcp.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString() @@ -217,7 +220,7 @@ public class CommandListener implements CommandExecutor, Listener { return true; } VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender); - for(ChatChannel channel : ChatChannel.getChatChannels()) { + for(ChatChannel channel : configService.getChatChannels()) { if(command.getName().toLowerCase().equals(channel.getAlias())) { if(args.length == 0) { mcp.getPlayer().sendMessage(ChatColor.RED + "Invalid command: /" + channel.getAlias() + " message"); @@ -253,7 +256,7 @@ public class CommandListener implements CommandExecutor, Listener { VentureChatPlayer target = playerApiService.getMineverseChatPlayer(playerName); ItemStack skull = e.getInventory().getItem(0); SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); - ChatChannel channel = ChatChannel.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", "")); + ChatChannel channel = configService.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", "")); int hash = Integer.parseInt(ChatColor.stripColor(skullMeta.getLore().get(1).replace("Hash: ", ""))); if(VersionHandler.is1_7()) { if(item.getType() == Material.BEDROCK) { @@ -265,7 +268,7 @@ public class CommandListener implements CommandExecutor, Listener { mcp.getPlayer().closeInventory(); } } - for(GuiSlot g : GuiSlot.getGuiSlots()) { + for(GuiSlot g : configService.getGuiSlots()) { if(g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == e.getSlot()) { String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + ""); if(target != null) { diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/LoginListener.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/LoginListener.java index 716e35a..55b39af 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/LoginListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/LoginListener.java @@ -12,15 +12,17 @@ import org.bukkit.event.player.PlayerQuitEvent; import com.google.inject.Inject; import com.google.inject.Singleton; -import mineverse.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.Logger; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.PluginMessageController; import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController; +import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.model.ChatChannel; +import venture.Aust1n46.chat.model.JsonFormat; import venture.Aust1n46.chat.model.VentureChatPlayer; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.UUIDService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; /** * Manages player login and logout events. @@ -40,6 +42,8 @@ public class LoginListener implements Listener { @Inject private VentureChatPlayerApiService playerApiService; @Inject + private ConfigService configService; + @Inject private Logger log; @EventHandler(priority = EventPriority.LOW) @@ -55,58 +59,55 @@ public class LoginListener implements Listener { log.debug("onPlayerQuit() ventureChatPlayer:{} quit", ventureChatPlayer); } } - - void handleNameChange(VentureChatPlayer mcp, Player eventPlayerInstance) { - plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Detected Name Change. Old Name:&c " + mcp.getName() + " &eNew Name:&c " + eventPlayerInstance.getName())); + + private void handleNameChange(VentureChatPlayer mcp, Player eventPlayerInstance) { + plugin.getServer().getConsoleSender().sendMessage( + FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Detected Name Change. Old Name:&c " + mcp.getName() + " &eNew Name:&c " + eventPlayerInstance.getName())); playerApiService.removeNameFromMap(mcp.getName()); mcp.setName(eventPlayerInstance.getName()); playerApiService.addNameToMap(mcp); } @EventHandler(priority = EventPriority.LOW) - public void onPlayerJoin(PlayerJoinEvent event) throws Exception { + public void onPlayerJoin(PlayerJoinEvent event) { VentureChatPlayer mcp = playerApiService.getMineverseChatPlayer(event.getPlayer()); Player player = event.getPlayer(); String name = player.getName(); - if(mcp == null) { + if (mcp == null) { UUID uuid = player.getUniqueId(); - mcp = new VentureChatPlayer(uuid, name); + mcp = new VentureChatPlayer(uuid, name, configService.getDefaultChannel()); playerApiService.addMineverseChatPlayerToMap(mcp); playerApiService.addNameToMap(mcp); } uuidService.checkOfflineUUIDWarning(mcp.getUuid()); - //check for name change - if(!mcp.getName().equals(name)) { + // check for name change + if (!mcp.getName().equals(name)) { handleNameChange(mcp, event.getPlayer()); } mcp.setOnline(true); + mcp.setPlayer(player); mcp.setHasPlayed(false); playerApiService.addMineverseChatOnlinePlayerToMap(mcp); - mcp.setJsonFormat(); - for(ChatChannel ch : ChatChannel.getAutojoinList()) { - if(ch.hasPermission()) { - if(mcp.getPlayer().hasPermission(ch.getPermission())) { - mcp.addListening(ch.getName()); + String jsonFormat = mcp.getJsonFormat(); + for (JsonFormat j : configService.getJsonFormats()) { + if (mcp.getPlayer().hasPermission("venturechat.json." + j.getName())) { + if (configService.getJsonFormat(mcp.getJsonFormat()).getPriority() > j.getPriority()) { + jsonFormat = j.getName(); } } - else { + } + mcp.setJsonFormat(jsonFormat); + for (ChatChannel ch : configService.getAutojoinList()) { + if (ch.hasPermission()) { + if (mcp.getPlayer().hasPermission(ch.getPermission())) { + mcp.addListening(ch.getName()); + } + } else { mcp.addListening(ch.getName()); } } - - try { - if(plugin.getServer().spigot().getConfig().getBoolean("settings.bungeecord") || plugin.getServer().spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled")) { - long delayInTicks = 20L; - final VentureChatPlayer sync = mcp; - plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { - public void run() { - pluginMessageController.synchronize(sync, false); - } - }, delayInTicks); - } - } - catch(NoSuchMethodError exception) { // Thrown if server isn't Paper. - // Do nothing + if (configService.isProxyEnabled()) { + pluginMessageController.synchronizeWithDelay(mcp, false); } } } diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListener.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListener.java index 83a4bd3..dc8daef 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListener.java @@ -9,11 +9,11 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.google.inject.Inject; import com.google.inject.Singleton; -import mineverse.Aust1n46.chat.versions.VersionHandler; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.model.ChatMessage; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.VersionHandler; import venture.Aust1n46.chat.service.VentureChatFormatService; //This class listens for chat packets and intercepts them before they are sent to the Player. diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/SignListener.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/SignListener.java index 37f8827..1a52160 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/SignListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/SignListener.java @@ -8,9 +8,9 @@ import org.bukkit.event.block.SignChangeEvent; import com.google.inject.Inject; import com.google.inject.Singleton; -import mineverse.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; //This class listens for text being added to signs, and it formats them to allow colors and formatting. @Singleton diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/VentureCommandExecutor.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/VentureCommandExecutor.java index 95ee358..f5aaa29 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/VentureCommandExecutor.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/VentureCommandExecutor.java @@ -12,7 +12,6 @@ import org.bukkit.command.TabExecutor; import com.google.inject.Inject; import com.google.inject.Singleton; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.commands.Broadcast; import venture.Aust1n46.chat.controllers.commands.BungeeToggle; import venture.Aust1n46.chat.controllers.commands.Channel; @@ -50,6 +49,7 @@ import venture.Aust1n46.chat.controllers.commands.Unmute; import venture.Aust1n46.chat.controllers.commands.Unmuteall; import venture.Aust1n46.chat.controllers.commands.VentureChatGui; import venture.Aust1n46.chat.controllers.commands.Venturechat; +import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.model.VentureCommand; /** @@ -58,21 +58,21 @@ import venture.Aust1n46.chat.model.VentureCommand; @Singleton public class VentureCommandExecutor implements TabExecutor { private Map commands = new HashMap(); - + @Inject private VentureChat plugin; @Inject private MessageCommandExecutor messageCommandExecutor; @Inject private IgnoreCommandExecutor ignoreCommandExecutor; - + @Inject private Broadcast broadcast; @Inject private Channel channel; @Inject private Channelinfo channelinfo; - @Inject + @Inject private Chatinfo chatinfo; @Inject private Chatreload chatreload; @@ -147,7 +147,7 @@ public class VentureCommandExecutor implements TabExecutor { public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { return commands.get(command.getName()).onTabComplete(sender, command, label, args); } - + @Inject public void postConstruct() { commands.put("broadcast", broadcast); @@ -181,36 +181,38 @@ public class VentureCommandExecutor implements TabExecutor { commands.put("venturechatgui", ventureChatGui); commands.put("messagetoggle", messageToggle); commands.put("bungeetoggle", bungeeToggle); - for(String command : commands.keySet()) { + for (String command : commands.keySet()) { registerCommand(command, this); } - + plugin.getServer().getScheduler().runTaskLater(plugin, () -> { - commands.put("reply", reply); - commands.put("r", reply); - registerCommand("reply", this); - registerCommand("r", this); - - commands.put("mute", mute); - commands.put("muteall", muteall); - commands.put("unmute", unmute); - commands.put("unmuteall", unmuteall); - registerCommand("mute", this); - registerCommand("muteall", this); - registerCommand("unmute", this); - registerCommand("unmuteall", this); - - registerCommand("message", messageCommandExecutor); - registerCommand("msg", messageCommandExecutor); - registerCommand("tell", messageCommandExecutor); - registerCommand("whisper", messageCommandExecutor); - - registerCommand("ignore", ignoreCommandExecutor); + if (plugin.isEnabled()) { + commands.put("reply", reply); + commands.put("r", reply); + registerCommand("reply", this); + registerCommand("r", this); + + commands.put("mute", mute); + commands.put("muteall", muteall); + commands.put("unmute", unmute); + commands.put("unmuteall", unmuteall); + registerCommand("mute", this); + registerCommand("muteall", this); + registerCommand("unmute", this); + registerCommand("unmuteall", this); + + registerCommand("message", messageCommandExecutor); + registerCommand("msg", messageCommandExecutor); + registerCommand("tell", messageCommandExecutor); + registerCommand("whisper", messageCommandExecutor); + + registerCommand("ignore", ignoreCommandExecutor); + } }, 0); } - + private void registerCommand(String command, CommandExecutor commandExecutor) { - if(plugin.getCommand(command) != null) { + if (plugin.getCommand(command) != null) { plugin.getCommand(command).setExecutor(commandExecutor); } } diff --git a/src/main/java/venture/Aust1n46/chat/initiators/schedulers/UnmuteScheduler.java b/src/main/java/venture/Aust1n46/chat/initiators/schedulers/UnmuteScheduler.java index c25fcab..661e864 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/schedulers/UnmuteScheduler.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/schedulers/UnmuteScheduler.java @@ -7,14 +7,15 @@ import org.bukkit.scheduler.BukkitScheduler; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.controllers.PluginMessageController; import venture.Aust1n46.chat.controllers.commands.MuteContainer; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.localization.LocalizedMessage; import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.VentureChatPlayer; +import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; +import venture.Aust1n46.chat.utilities.FormatUtils; public class UnmuteScheduler { @Inject @@ -23,6 +24,8 @@ public class UnmuteScheduler { private PluginMessageController pluginMessageController; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; @Inject public void postConstruct() { @@ -35,8 +38,8 @@ public class UnmuteScheduler { Iterator iterator = p.getMutes().iterator(); while (iterator.hasNext()) { MuteContainer mute = iterator.next(); - if(ChatChannel.isChannel(mute.getChannel())) { - ChatChannel channel = ChatChannel.getChannel(mute.getChannel()); + if(configService.isChannel(mute.getChannel())) { + ChatChannel channel = configService.getChannel(mute.getChannel()); long timemark = mute.getDuration(); if (timemark == 0) { continue; diff --git a/src/main/java/mineverse/Aust1n46/chat/localization/InternalMessage.java b/src/main/java/venture/Aust1n46/chat/localization/InternalMessage.java similarity index 81% rename from src/main/java/mineverse/Aust1n46/chat/localization/InternalMessage.java rename to src/main/java/venture/Aust1n46/chat/localization/InternalMessage.java index 7ed218c..bd06c01 100644 --- a/src/main/java/mineverse/Aust1n46/chat/localization/InternalMessage.java +++ b/src/main/java/venture/Aust1n46/chat/localization/InternalMessage.java @@ -1,6 +1,6 @@ -package mineverse.Aust1n46.chat.localization; +package venture.Aust1n46.chat.localization; -import mineverse.Aust1n46.chat.utilities.FormatUtils; +import venture.Aust1n46.chat.utilities.FormatUtils; /** * Messages internal to the plugin diff --git a/src/main/java/mineverse/Aust1n46/chat/localization/Localization.java b/src/main/java/venture/Aust1n46/chat/localization/Localization.java similarity index 88% rename from src/main/java/mineverse/Aust1n46/chat/localization/Localization.java rename to src/main/java/venture/Aust1n46/chat/localization/Localization.java index 63d61e6..91c7a58 100644 --- a/src/main/java/mineverse/Aust1n46/chat/localization/Localization.java +++ b/src/main/java/venture/Aust1n46/chat/localization/Localization.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.localization; +package venture.Aust1n46.chat.localization; import java.io.File; @@ -6,8 +6,8 @@ import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.utilities.FormatUtils; //This class is used to create objects of localization for different languages. public class Localization { diff --git a/src/main/java/mineverse/Aust1n46/chat/localization/LocalizedMessage.java b/src/main/java/venture/Aust1n46/chat/localization/LocalizedMessage.java similarity index 98% rename from src/main/java/mineverse/Aust1n46/chat/localization/LocalizedMessage.java rename to src/main/java/venture/Aust1n46/chat/localization/LocalizedMessage.java index 71e8862..563f9dc 100644 --- a/src/main/java/mineverse/Aust1n46/chat/localization/LocalizedMessage.java +++ b/src/main/java/venture/Aust1n46/chat/localization/LocalizedMessage.java @@ -1,6 +1,6 @@ -package mineverse.Aust1n46.chat.localization; +package venture.Aust1n46.chat.localization; -import mineverse.Aust1n46.chat.utilities.FormatUtils; +import venture.Aust1n46.chat.utilities.FormatUtils; /** * Messages configurable in Messages.yml file. diff --git a/src/main/java/venture/Aust1n46/chat/model/Alias.java b/src/main/java/venture/Aust1n46/chat/model/Alias.java index 4714381..098b821 100644 --- a/src/main/java/venture/Aust1n46/chat/model/Alias.java +++ b/src/main/java/venture/Aust1n46/chat/model/Alias.java @@ -1,60 +1,24 @@ package venture.Aust1n46.chat.model; -import java.util.ArrayList; import java.util.List; -import org.bukkit.configuration.ConfigurationSection; - -import venture.Aust1n46.chat.VentureChat; +import lombok.Getter; +@Getter public class Alias { - private static List aliases; + private String name; + private int arguments; + private List components; + private String permission; - private String name; - private int arguments; - private List components; - private String permission; + public Alias(String name, int arguments, List components, String permission) { + this.name = name; + this.arguments = arguments; + this.components = components; + this.permission = "venturechat." + permission; + } - public Alias(String name, int arguments, List components, String permission) { - this.name = name; - this.arguments = arguments; - this.components = components; - this.permission = "venturechat." + permission; - } - - public static void initialize(VentureChat plugin) { - aliases = new ArrayList(); - ConfigurationSection cs = plugin.getConfig().getConfigurationSection("alias"); - for (String key : cs.getKeys(false)) { - String name = key; - int arguments = cs.getInt(key + ".arguments", 0); - List components = cs.getStringList(key + ".components"); - String permissions = cs.getString(key + ".permissions", "None"); - aliases.add(new Alias(name, arguments, components, permissions)); - } - } - - public static List getAliases() { - return aliases; - } - - public String getName() { - return name; - } - - public int getArguments() { - return arguments; - } - - public List getComponents() { - return components; - } - - public String getPermission() { - return permission; - } - - public boolean hasPermission() { - return !permission.equalsIgnoreCase("venturechat.none"); - } + public boolean hasPermission() { + return !permission.equalsIgnoreCase("venturechat.none"); + } } diff --git a/src/main/java/venture/Aust1n46/chat/model/ChatChannel.java b/src/main/java/venture/Aust1n46/chat/model/ChatChannel.java index e2633fa..da8b341 100644 --- a/src/main/java/venture/Aust1n46/chat/model/ChatChannel.java +++ b/src/main/java/venture/Aust1n46/chat/model/ChatChannel.java @@ -1,18 +1,9 @@ package venture.Aust1n46.chat.model; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - -import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.configuration.ConfigurationSection; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; import venture.Aust1n46.chat.service.VentureChatFormatService; +import venture.Aust1n46.chat.utilities.FormatUtils; /** * Chat channel object pojo. Class also contains static initialization methods @@ -24,11 +15,6 @@ public class ChatChannel { private static final String PERMISSION_PREFIX = "venturechat."; private static final String NO_PERMISSIONS = "venturechat.none"; - private static boolean aliasesRegisteredAsCommands; - private static ChatChannel defaultChatChannel; - private static String defaultColor; - private static HashMap chatChannels; - private String name; private String permission; private String speakPermission; @@ -45,117 +31,6 @@ public class ChatChannel { private int cooldown; private String prefix; - /** - * Read chat channels from config file and initialize channel array. - */ - public static void initialize(final VentureChat plugin, final VentureChatFormatService formatter, final boolean aliasesRegisteredAsCommands) { - chatChannels = new HashMap(); - ChatChannel.aliasesRegisteredAsCommands = aliasesRegisteredAsCommands; - ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels"); - for (String key : cs.getKeys(false)) { - String color = cs.getString(key + ".color", "white"); - String chatColor = cs.getString(key + ".chatcolor", "white"); - String name = key; - String permission = cs.getString(key + ".permissions", "None"); - String speakPermission = cs.getString(key + ".speak_permissions", "None"); - boolean mutable = cs.getBoolean(key + ".mutable", false); - boolean filter = cs.getBoolean(key + ".filter", true); - boolean bungee = cs.getBoolean(key + ".bungeecord", false); - String format = cs.getString(key + ".format", "Default"); - boolean defaultChannel = cs.getBoolean(key + ".default", false); - String alias = cs.getString(key + ".alias", "None"); - double distance = cs.getDouble(key + ".distance", (double) 0); - int cooldown = cs.getInt(key + ".cooldown", 0); - boolean autojoin = cs.getBoolean(key + ".autojoin", false); - String prefix = cs.getString(key + ".channel_prefix"); - ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable, - filter, defaultChannel, alias, distance, autojoin, bungee, cooldown, prefix, format); - chatChannels.put(name.toLowerCase(), chatChannel); - chatChannels.put(alias.toLowerCase(), chatChannel); - if (defaultChannel) { - defaultChatChannel = chatChannel; - defaultColor = color; - } - } - // Error handling for missing default channel in the config. - if(defaultChatChannel == null) { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cNo default channel found!")); - defaultChatChannel = new ChatChannel("MissingDefault", "red", "red", "None", "None", false, - true, true, "md", 0, true, false, 0, "&f[&cMissingDefault&f]", "{venturechat_channel_prefix} {vault_prefix}{player_displayname}&c:"); - defaultColor = defaultChatChannel.getColor(); - chatChannels.put("missingdefault", defaultChatChannel); - chatChannels.put("md", defaultChatChannel); - } - } - - public static boolean areAliasesRegisteredAsCommands() { - return aliasesRegisteredAsCommands; - } - - /** - * Get list of chat channels. - * - * @return {@link Collection}<{@link ChatChannel}> - */ - public static Collection getChatChannels() { - return new HashSet(chatChannels.values()); - } - - /** - * Get a chat channel by name. - * - * @param channelName - * name of channel to get. - * @return {@link ChatChannel} - */ - public static ChatChannel getChannel(String channelName) { - return chatChannels.get(channelName.toLowerCase()); - } - - /** - * Checks if the chat channel exists. - * - * @param channelName - * name of channel to check. - * @return true if channel exists, false otherwise. - */ - public static boolean isChannel(String channelName) { - return getChannel(channelName) != null; - } - - /** - * Get default chat channel color. - * - * @return {@link String} - */ - public static String getDefaultColor() { - return defaultColor; - } - - /** - * Get default chat channel. - * - * @return {@link ChatChannel} - */ - public static ChatChannel getDefaultChannel() { - return defaultChatChannel; - } - - /** - * Get list of chat channels with autojoin set to true. - * - * @return {@link List}<{@link ChatChannel}> - */ - public static List getAutojoinList() { - List joinlist = new ArrayList(); - for (ChatChannel c : chatChannels.values()) { - if (c.getAutojoin()) { - joinlist.add(c); - } - } - return joinlist; - } - /** * Parameterized constructor a {@link ChatChannel}. * diff --git a/src/main/java/venture/Aust1n46/chat/model/ChatMessage.java b/src/main/java/venture/Aust1n46/chat/model/ChatMessage.java index b53db90..47bdc70 100644 --- a/src/main/java/venture/Aust1n46/chat/model/ChatMessage.java +++ b/src/main/java/venture/Aust1n46/chat/model/ChatMessage.java @@ -2,8 +2,9 @@ package venture.Aust1n46.chat.model; import com.comphenix.protocol.wrappers.WrappedChatComponent; -//This class is used to create ChatMessage objects, which are used to store information about previous text components -//that were sent to the player. This is a main component in making the message remover work. +import lombok.Data; + +@Data public class ChatMessage { private WrappedChatComponent component; private String message; @@ -16,28 +17,4 @@ public class ChatMessage { this.coloredMessage = coloredMessage; this.hash = hash; } - - public WrappedChatComponent getComponent() { - return this.component; - } - - public void setComponent(WrappedChatComponent component) { - this.component = component; - } - - public String getMessage() { - return this.message; - } - - public String getColoredMessage() { - return this.coloredMessage; - } - - public int getHash() { - return this.hash; - } - - public void setHash(int hash) { - this.hash = hash; - } -} \ No newline at end of file +} diff --git a/src/main/java/venture/Aust1n46/chat/model/GuiSlot.java b/src/main/java/venture/Aust1n46/chat/model/GuiSlot.java index cbf51fe..e870909 100644 --- a/src/main/java/venture/Aust1n46/chat/model/GuiSlot.java +++ b/src/main/java/venture/Aust1n46/chat/model/GuiSlot.java @@ -1,82 +1,30 @@ package venture.Aust1n46.chat.model; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import venture.Aust1n46.chat.VentureChat; +import lombok.Getter; +@Getter public class GuiSlot { - private static List guiSlots; + private String text; + private String command; + private String permission; + private Material icon; + private String name; + private int durability; + private int slot; - private String text; - private String command; - private String permission; - private Material icon; - private String name; - private int durability; - private int slot; + public GuiSlot(String name, String icon, int durability, String text, String permission, String command, int slot) { + this.name = name; + this.text = text; + this.command = command; + this.permission = "venturechat." + permission; + this.icon = Material.valueOf(icon.toUpperCase()); + this.durability = durability; + this.slot = slot; + } - public GuiSlot(String name, String icon, int durability, String text, String permission, String command, int slot) { - this.name = name; - this.text = text; - this.command = command; - this.permission = "venturechat." + permission; - this.icon = Material.valueOf(icon.toUpperCase()); - this.durability = durability; - this.slot = slot; - } - - public static void initialize(final VentureChat plugin) { - guiSlots = new ArrayList(); - ConfigurationSection cs = plugin.getConfig().getConfigurationSection("venturegui"); - for (String key : cs.getKeys(false)) { - String name = key; - String icon = cs.getString(key + ".icon"); - int durability = cs.getInt(key + ".durability"); - String text = cs.getString(key + ".text"); - String permission = cs.getString(key + ".permission"); - String command = cs.getString(key + ".command"); - int slot = cs.getInt(key + ".slot"); - guiSlots.add(new GuiSlot(name, icon, durability, text, permission, command, slot)); - } - } - - public static List getGuiSlots() { - return guiSlots; - } - - public String getText() { - return text; - } - - public String getCommand() { - return command; - } - - public String getPermission() { - return permission; - } - - public Material getIcon() { - return icon; - } - - public int getDurability() { - return durability; - } - - public String getName() { - return name; - } - - public int getSlot() { - return slot; - } - - public boolean hasPermission() { - return !permission.equalsIgnoreCase("venturechat.none"); - } + public boolean hasPermission() { + return !permission.equalsIgnoreCase("venturechat.none"); + } } diff --git a/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java b/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java index 97efb1a..447c779 100644 --- a/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java +++ b/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java @@ -2,32 +2,19 @@ package venture.Aust1n46.chat.model; import java.util.List; +import lombok.Getter; + +@Getter public class JsonAttribute { private String name; private List hoverText; private String clickAction; private String clickText; - + public JsonAttribute(String name, List hoverText, String clickAction, String clickText) { this.name = name; this.hoverText = hoverText; this.clickAction = clickAction; this.clickText = clickText; } - - public String getName() { - return name; - } - - public List getHoverText() { - return hoverText; - } - - public String getClickAction() { - return clickAction; - } - - public String getClickText() { - return clickText; - } } diff --git a/src/main/java/venture/Aust1n46/chat/model/JsonFormat.java b/src/main/java/venture/Aust1n46/chat/model/JsonFormat.java index 4948123..0ba3ccf 100644 --- a/src/main/java/venture/Aust1n46/chat/model/JsonFormat.java +++ b/src/main/java/venture/Aust1n46/chat/model/JsonFormat.java @@ -1,63 +1,18 @@ package venture.Aust1n46.chat.model; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.List; -import org.bukkit.configuration.ConfigurationSection; - -import venture.Aust1n46.chat.VentureChat; +import lombok.Getter; +@Getter public class JsonFormat { - private static HashMap jsonFormats; + private List jsonAttributes; + private int priority; + private String name; - private List jsonAttributes; - private int priority; - private String name; - - public JsonFormat(String name, int priority, List jsonAttributes) { - this.name = name; - this.priority = priority; - this.jsonAttributes = jsonAttributes; - } - - public static void initialize(final VentureChat plugin) { - jsonFormats = new HashMap(); - ConfigurationSection jsonFormatSection = plugin.getConfig().getConfigurationSection("jsonformatting"); - for (String jsonFormat : jsonFormatSection.getKeys(false)) { - int priority = jsonFormatSection.getInt(jsonFormat + ".priority", 0); - List jsonAttributes = new ArrayList<>(); - ConfigurationSection jsonAttributeSection = jsonFormatSection.getConfigurationSection(jsonFormat + ".json_attributes"); - if (jsonAttributeSection != null) { - for (String attribute : jsonAttributeSection.getKeys(false)) { - List hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text"); - String clickAction = jsonAttributeSection.getString(attribute + ".click_action", ""); - String clickText = jsonAttributeSection.getString(attribute + ".click_text", ""); - jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText)); - } - } - jsonFormats.put(jsonFormat.toLowerCase(), new JsonFormat(jsonFormat, priority, jsonAttributes)); - } - } - - public static Collection getJsonFormats() { - return jsonFormats.values(); - } - - public static JsonFormat getJsonFormat(String name) { - return jsonFormats.get(name.toLowerCase()); - } - - public String getName() { - return name; - } - - public int getPriority() { - return priority; - } - - public List getJsonAttributes() { - return jsonAttributes; - } + public JsonFormat(String name, int priority, List jsonAttributes) { + this.name = name; + this.priority = priority; + this.jsonAttributes = jsonAttributes; + } } diff --git a/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java b/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java index d6991be..d3f485b 100644 --- a/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java +++ b/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Set; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import lombok.AccessLevel; @@ -56,11 +55,6 @@ public class VentureChatPlayer { private boolean messageToggle; private boolean bungeeToggle; - @Deprecated - public VentureChatPlayer(UUID uuid, String name, ChatChannel currentChannel, Set ignores, Set listening, HashMap mutes, Set blockedCommands, boolean host, UUID party, boolean filter, boolean notifications, String nickname, String jsonFormat, boolean spy, boolean commandSpy, boolean rangedSpy, boolean messageToggle, boolean bungeeToggle) { - this(uuid, name, currentChannel, ignores, listening, mutes, blockedCommands, host, party, filter, notifications, jsonFormat, spy, commandSpy, rangedSpy, messageToggle, bungeeToggle); - } - public VentureChatPlayer(UUID uuid, String name, ChatChannel currentChannel, Set ignores, Set listening, HashMap mutes, Set blockedCommands, boolean host, UUID party, boolean filter, boolean notifications, String jsonFormat, boolean spy, boolean commandSpy, boolean rangedSpy, boolean messageToggle, boolean bungeeToggle) { this.uuid = uuid; this.name = name; @@ -93,10 +87,10 @@ public class VentureChatPlayer { this.bungeeToggle = bungeeToggle; } - public VentureChatPlayer(UUID uuid, String name) { + public VentureChatPlayer(UUID uuid, String name, ChatChannel currentChannel) { this.uuid = uuid; this.name = name; - this.currentChannel = ChatChannel.getDefaultChannel(); + this.currentChannel = currentChannel; this.ignores = new HashSet(); this.listening = new HashSet(); listening.add(currentChannel.getName()); @@ -151,27 +145,9 @@ public class VentureChatPlayer { public void removeIgnore(UUID ignore) { this.ignores.remove(ignore); } - - public Set getListening() { - return this.listening; - } public boolean isListening(String channel) { - if(this.isOnline()) { - if(ChatChannel.isChannel(channel)) { - ChatChannel chatChannel = ChatChannel.getChannel(channel); - if(chatChannel.hasPermission()) { - if(!this.getPlayer().hasPermission(chatChannel.getPermission())) { - if(this.getCurrentChannel().equals(chatChannel)) { - this.setCurrentChannel(ChatChannel.getDefaultChannel()); - } - this.removeListening(channel); - return false; - } - } - } - } - return this.listening.contains(channel); + return listening.contains(channel); } public boolean addListening(String channel) { @@ -234,10 +210,6 @@ public class VentureChatPlayer { return channel != null ? this.mutes.containsKey(channel) : false; } - public Set getBlockedCommands() { - return this.blockedCommands; - } - public void addBlockedCommand(String command) { this.blockedCommands.add(command); } @@ -254,28 +226,10 @@ public class VentureChatPlayer { return this.party != null; } - public void setOnline(boolean online) { - this.online = online; - if(this.online) { - this.player = Bukkit.getPlayer(name); - } - else { - this.player = null; - } - } - public Player getPlayer() { return this.online ? this.player : null; } - public UUID getConversation() { - return this.conversation; - } - - public void setConversation(UUID conversation) { - this.conversation = conversation; - } - public boolean hasConversation() { return this.conversation != null; } @@ -290,10 +244,6 @@ public class VentureChatPlayer { return this.spy; } - public void setSpy(boolean spy) { - this.spy = spy; - } - public boolean hasCommandSpy() { if(this.isOnline()) { if(!this.getPlayer().hasPermission("venturechat.commandspy")) { @@ -304,22 +254,6 @@ public class VentureChatPlayer { return this.commandSpy; } - public void setCommandSpy(boolean commandSpy) { - this.commandSpy = commandSpy; - } - - public boolean isQuickChat() { - return this.quickChat; - } - - public void setQuickChat(boolean quickChat) { - this.quickChat = quickChat; - } - - public ChatChannel getQuickChannel() { - return this.quickChannel; - } - public boolean setQuickChannel(ChatChannel channel) { if(channel != null) { this.quickChannel = channel; @@ -328,39 +262,10 @@ public class VentureChatPlayer { return false; } - @Deprecated - /** - * Not needed and never resets to it's original null value after being set once. - * @return - */ - public boolean hasQuickChannel() { - return this.quickChannel != null; - } - - public UUID getReplyPlayer() { - return this.replyPlayer; - } - - public void setReplyPlayer(UUID replyPlayer) { - this.replyPlayer = replyPlayer; - } - public boolean hasReplyPlayer() { return this.replyPlayer != null; } - public boolean isPartyChat() { - return this.partyChat; - } - - public void setPartyChat(boolean partyChat) { - this.partyChat = partyChat; - } - - public HashMap getCooldowns() { - return this.cooldowns; - } - public boolean addCooldown(ChatChannel channel, long time) { if(channel != null && time > 0) { cooldowns.put(channel, time); @@ -381,10 +286,6 @@ public class VentureChatPlayer { return channel != null && this.cooldowns != null ? this.cooldowns.containsKey(channel) : false; } - public HashMap> getSpam() { - return this.spam; - } - public boolean hasSpam(ChatChannel channel) { return channel != null && this.spam != null ? this.spam.containsKey(channel) : false; } @@ -397,18 +298,6 @@ public class VentureChatPlayer { return false; } - public void setModified(boolean modified) { - this.modified = modified; - } - - public boolean wasModified() { - return this.modified; - } - - public List getMessages() { - return this.messages; - } - public void addMessage(ChatMessage message) { if(this.messages.size() >= 100) { this.messages.remove(0); @@ -419,19 +308,4 @@ public class VentureChatPlayer { public void clearMessages() { this.messages.clear(); } - - public String getJsonFormat() { - return this.jsonFormat; - } - - public void setJsonFormat() { - this.jsonFormat = "Default"; - for(JsonFormat j : JsonFormat.getJsonFormats()) { - if(this.getPlayer().hasPermission("venturechat.json." + j.getName())) { - if(JsonFormat.getJsonFormat(this.getJsonFormat()).getPriority() > j.getPriority()) { - this.jsonFormat = j.getName(); - } - } - } - } } diff --git a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatBungee.java b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatBungee.java similarity index 98% rename from src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatBungee.java rename to src/main/java/venture/Aust1n46/chat/proxy/VentureChatBungee.java index feffe07..7192d34 100644 --- a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatBungee.java +++ b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatBungee.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.proxy; +package venture.Aust1n46.chat.proxy; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -9,7 +9,6 @@ import java.util.stream.Collectors; import com.google.inject.Inject; -import mineverse.Aust1n46.chat.utilities.FormatUtils; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.config.ServerInfo; @@ -27,6 +26,7 @@ import net.md_5.bungee.config.YamlConfiguration; import net.md_5.bungee.event.EventHandler; import venture.Aust1n46.chat.controllers.VentureChatProxyFlatFileController; import venture.Aust1n46.chat.service.UUIDService; +import venture.Aust1n46.chat.utilities.FormatUtils; /** * VentureChat Minecraft plugin for BungeeCord. diff --git a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxy.java b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxy.java similarity index 99% rename from src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxy.java rename to src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxy.java index 35366bf..ceb83d6 100644 --- a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxy.java +++ b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxy.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.proxy; +package venture.Aust1n46.chat.proxy; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxyServer.java b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxyServer.java similarity index 88% rename from src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxyServer.java rename to src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxyServer.java index a16867a..1971b72 100644 --- a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxyServer.java +++ b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxyServer.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.proxy; +package venture.Aust1n46.chat.proxy; public class VentureChatProxyServer { private String name; diff --git a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxySource.java b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxySource.java similarity index 90% rename from src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxySource.java rename to src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxySource.java index 84edbf2..441235e 100644 --- a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatProxySource.java +++ b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatProxySource.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.proxy; +package venture.Aust1n46.chat.proxy; import java.util.List; diff --git a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatVelocity.java b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatVelocity.java similarity index 98% rename from src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatVelocity.java rename to src/main/java/venture/Aust1n46/chat/proxy/VentureChatVelocity.java index f6fdf35..ab5762a 100644 --- a/src/main/java/mineverse/Aust1n46/chat/proxy/VentureChatVelocity.java +++ b/src/main/java/venture/Aust1n46/chat/proxy/VentureChatVelocity.java @@ -1,4 +1,4 @@ -package mineverse.Aust1n46.chat.proxy; +package venture.Aust1n46.chat.proxy; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -29,11 +29,11 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.server.RegisteredServer; -import mineverse.Aust1n46.chat.utilities.FormatUtils; 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.utilities.FormatUtils; /** * VentureChat Minecraft plugin for Velocity. diff --git a/src/main/java/venture/Aust1n46/chat/service/ConfigService.java b/src/main/java/venture/Aust1n46/chat/service/ConfigService.java new file mode 100644 index 0000000..7175045 --- /dev/null +++ b/src/main/java/venture/Aust1n46/chat/service/ConfigService.java @@ -0,0 +1,225 @@ +package venture.Aust1n46.chat.service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.model.Alias; +import venture.Aust1n46.chat.model.ChatChannel; +import venture.Aust1n46.chat.model.GuiSlot; +import venture.Aust1n46.chat.model.JsonAttribute; +import venture.Aust1n46.chat.model.JsonFormat; +import venture.Aust1n46.chat.model.VentureChatPlayer; +import venture.Aust1n46.chat.utilities.FormatUtils; + +@Singleton +public class ConfigService { + @Inject + private VentureChat plugin; + + private final HashMap chatChannels = new HashMap(); + private final HashMap jsonFormats = new HashMap(); + private final List aliases = new ArrayList<>(); + private final List guiSlots = new ArrayList<>(); + private boolean aliasesRegisteredAsCommands; + private ChatChannel defaultChatChannel; + private String defaultColor; + + @Inject + public void postConstruct() { + aliasesRegisteredAsCommands = true; + ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels"); + for (String key : cs.getKeys(false)) { + String color = cs.getString(key + ".color", "white"); + String chatColor = cs.getString(key + ".chatcolor", "white"); + String name = key; + String permission = cs.getString(key + ".permissions", "None"); + String speakPermission = cs.getString(key + ".speak_permissions", "None"); + boolean mutable = cs.getBoolean(key + ".mutable", false); + boolean filter = cs.getBoolean(key + ".filter", true); + boolean bungee = cs.getBoolean(key + ".bungeecord", false); + String format = cs.getString(key + ".format", "Default"); + boolean defaultChannel = cs.getBoolean(key + ".default", false); + String alias = cs.getString(key + ".alias", "None"); + double distance = cs.getDouble(key + ".distance", (double) 0); + int cooldown = cs.getInt(key + ".cooldown", 0); + boolean autojoin = cs.getBoolean(key + ".autojoin", false); + String prefix = cs.getString(key + ".channel_prefix"); + ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable, filter, defaultChannel, alias, distance, autojoin, bungee, + cooldown, prefix, format); + chatChannels.put(name.toLowerCase(), chatChannel); + chatChannels.put(alias.toLowerCase(), chatChannel); + if (defaultChannel) { + defaultChatChannel = chatChannel; + defaultColor = color; + } + } + // Error handling for missing default channel in the config. + if (defaultChatChannel == null) { + Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cNo default channel found!")); + defaultChatChannel = new ChatChannel("MissingDefault", "red", "red", "None", "None", false, true, true, "md", 0, true, false, 0, "&f[&cMissingDefault&f]", + "{venturechat_channel_prefix} {vault_prefix}{player_displayname}&c:"); + defaultColor = defaultChatChannel.getColor(); + chatChannels.put("missingdefault", defaultChatChannel); + chatChannels.put("md", defaultChatChannel); + } + + jsonFormats.clear(); + ConfigurationSection jsonFormatSection = plugin.getConfig().getConfigurationSection("jsonformatting"); + for (String jsonFormat : jsonFormatSection.getKeys(false)) { + int priority = jsonFormatSection.getInt(jsonFormat + ".priority", 0); + List jsonAttributes = new ArrayList<>(); + ConfigurationSection jsonAttributeSection = jsonFormatSection.getConfigurationSection(jsonFormat + ".json_attributes"); + if (jsonAttributeSection != null) { + for (String attribute : jsonAttributeSection.getKeys(false)) { + List hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text"); + String clickAction = jsonAttributeSection.getString(attribute + ".click_action", ""); + String clickText = jsonAttributeSection.getString(attribute + ".click_text", ""); + jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText)); + } + } + jsonFormats.put(jsonFormat.toLowerCase(), new JsonFormat(jsonFormat, priority, jsonAttributes)); + } + + aliases.clear(); + ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("alias"); + for (String key : configurationSection.getKeys(false)) { + String name = key; + int arguments = configurationSection.getInt(key + ".arguments", 0); + List components = configurationSection.getStringList(key + ".components"); + String permissions = configurationSection.getString(key + ".permissions", "None"); + aliases.add(new Alias(name, arguments, components, permissions)); + } + + guiSlots.clear(); + cs = plugin.getConfig().getConfigurationSection("venturegui"); + for (String key : cs.getKeys(false)) { + String name = key; + String icon = cs.getString(key + ".icon"); + int durability = cs.getInt(key + ".durability"); + String text = cs.getString(key + ".text"); + String permission = cs.getString(key + ".permission"); + String command = cs.getString(key + ".command"); + int slot = cs.getInt(key + ".slot"); + guiSlots.add(new GuiSlot(name, icon, durability, text, permission, command, slot)); + } + } + + public boolean areAliasesRegisteredAsCommands() { + return aliasesRegisteredAsCommands; + } + + /** + * Get list of chat channels. + * + * @return {@link Collection}<{@link ChatChannel}> + */ + public Collection getChatChannels() { + return new HashSet(chatChannels.values()); + } + + /** + * Get a chat channel by name. + * + * @param channelName name of channel to get. + * @return {@link ChatChannel} + */ + public ChatChannel getChannel(String channelName) { + return chatChannels.get(channelName.toLowerCase()); + } + + /** + * Checks if the chat channel exists. + * + * @param channelName name of channel to check. + * @return true if channel exists, false otherwise. + */ + public boolean isChannel(String channelName) { + return getChannel(channelName) != null; + } + + public boolean isListening(VentureChatPlayer ventureChatPlayer, String channel) { + if (ventureChatPlayer.isOnline()) { + if (isChannel(channel)) { + ChatChannel chatChannel = getChannel(channel); + if (chatChannel.hasPermission()) { + if (!ventureChatPlayer.getPlayer().hasPermission(chatChannel.getPermission())) { + if (ventureChatPlayer.getCurrentChannel().equals(chatChannel)) { + ventureChatPlayer.setCurrentChannel(getDefaultChannel()); + } + ventureChatPlayer.removeListening(channel); + return false; + } + } + } + } + return ventureChatPlayer.isListening(channel); + } + + /** + * Get default chat channel color. + * + * @return {@link String} + */ + public String getDefaultColor() { + return defaultColor; + } + + /** + * Get default chat channel. + * + * @return {@link ChatChannel} + */ + public ChatChannel getDefaultChannel() { + return defaultChatChannel; + } + + /** + * Get list of chat channels with autojoin set to true. + * + * @return {@link List}<{@link ChatChannel}> + */ + public List getAutojoinList() { + List joinlist = new ArrayList(); + for (ChatChannel c : chatChannels.values()) { + if (c.getAutojoin()) { + joinlist.add(c); + } + } + return joinlist; + } + + public Collection getJsonFormats() { + return jsonFormats.values(); + } + + public JsonFormat getJsonFormat(String name) { + return jsonFormats.get(name.toLowerCase()); + } + + public List getAliases() { + return aliases; + } + + public List getGuiSlots() { + return guiSlots; + } + + public boolean isProxyEnabled() { + try { + return plugin.getServer().spigot().getConfig().getBoolean("settings.bungeecord") + || plugin.getServer().spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled"); + } catch (NoSuchMethodError exception) { // Thrown if server isn't Paper. + return false; + } + } +} diff --git a/src/main/java/venture/Aust1n46/chat/service/UUIDService.java b/src/main/java/venture/Aust1n46/chat/service/UUIDService.java index 43e107d..aa2417f 100644 --- a/src/main/java/venture/Aust1n46/chat/service/UUIDService.java +++ b/src/main/java/venture/Aust1n46/chat/service/UUIDService.java @@ -7,9 +7,9 @@ import org.bukkit.Bukkit; import com.google.inject.Inject; import com.google.inject.Singleton; -import mineverse.Aust1n46.chat.proxy.VentureChatProxySource; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.proxy.VentureChatProxySource; +import venture.Aust1n46.chat.utilities.FormatUtils; @Singleton public class UUIDService { diff --git a/src/main/java/venture/Aust1n46/chat/service/VentureChatDatabaseService.java b/src/main/java/venture/Aust1n46/chat/service/VentureChatDatabaseService.java index 779bc33..00e5a63 100644 --- a/src/main/java/venture/Aust1n46/chat/service/VentureChatDatabaseService.java +++ b/src/main/java/venture/Aust1n46/chat/service/VentureChatDatabaseService.java @@ -14,8 +14,8 @@ import com.google.inject.Singleton; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.utilities.FormatUtils; /** * Initializes and handles writing to the chat logging database. diff --git a/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java b/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java index a8c7b2a..bbb3ed5 100644 --- a/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java +++ b/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java @@ -1,10 +1,10 @@ package venture.Aust1n46.chat.service; -import static mineverse.Aust1n46.chat.utilities.FormatUtils.BUKKIT_COLOR_CODE_PREFIX; -import static mineverse.Aust1n46.chat.utilities.FormatUtils.BUKKIT_COLOR_CODE_PREFIX_CHAR; -import static mineverse.Aust1n46.chat.utilities.FormatUtils.BUKKIT_HEX_COLOR_CODE_PREFIX; -import static mineverse.Aust1n46.chat.utilities.FormatUtils.DEFAULT_COLOR_CODE; -import static mineverse.Aust1n46.chat.utilities.FormatUtils.HEX_COLOR_CODE_PREFIX; +import static venture.Aust1n46.chat.utilities.FormatUtils.BUKKIT_COLOR_CODE_PREFIX; +import static venture.Aust1n46.chat.utilities.FormatUtils.BUKKIT_COLOR_CODE_PREFIX_CHAR; +import static venture.Aust1n46.chat.utilities.FormatUtils.BUKKIT_HEX_COLOR_CODE_PREFIX; +import static venture.Aust1n46.chat.utilities.FormatUtils.DEFAULT_COLOR_CODE; +import static venture.Aust1n46.chat.utilities.FormatUtils.HEX_COLOR_CODE_PREFIX; import java.util.ArrayList; import java.util.Arrays; @@ -28,12 +28,12 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import me.clip.placeholderapi.PlaceholderAPI; -import mineverse.Aust1n46.chat.utilities.FormatUtils; -import mineverse.Aust1n46.chat.versions.VersionHandler; -import venture.Aust1n46.chat.VentureChat; +import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.model.JsonAttribute; import venture.Aust1n46.chat.model.JsonFormat; import venture.Aust1n46.chat.model.VentureChatPlayer; +import venture.Aust1n46.chat.utilities.FormatUtils; +import venture.Aust1n46.chat.utilities.VersionHandler; /** * Class containing chat formatting methods. @@ -45,23 +45,25 @@ public class VentureChatFormatService { private static final Pattern PLACEHOLDERAPI_PLACEHOLDER_PATTERN = Pattern.compile("\\{([^\\{\\}]+)\\}"); public static final String DEFAULT_MESSAGE_SOUND = "ENTITY_PLAYER_LEVELUP"; public static final String DEFAULT_LEGACY_MESSAGE_SOUND = "LEVEL_UP"; - + @Inject private VentureChat plugin; @Inject private VentureChatPlayerApiService playerApiService; + @Inject + private ConfigService configService; /** - * Converts a message to Minecraft JSON formatting while applying the - * {@link JsonFormat} from the config. - * - * @param sender {@link VentureChatPlayer} wrapper of the message sender. - * @param format The format section of the message. - * @param chat The chat section of the message. - * @return {@link String} - */ + * Converts a message to Minecraft JSON formatting while applying the + * {@link JsonFormat} from the config. + * + * @param sender {@link VentureChatPlayer} wrapper of the message sender. + * @param format The format section of the message. + * @param chat The chat section of the message. + * @return {@link String} + */ public String convertToJson(VentureChatPlayer sender, String format, String chat) { - JsonFormat JSONformat = JsonFormat.getJsonFormat(sender.getJsonFormat()); + JsonFormat JSONformat = configService.getJsonFormat(sender.getJsonFormat()); String f = escapeJsonChars(format); String c = escapeJsonChars(chat); String json = "[\"\",{\"text\":\"\",\"extra\":["; @@ -81,16 +83,16 @@ public class VentureChatFormatService { } /** - * Converts the format section of a message to JSON using PlaceholderAPI. - * - * @param s - * @param format - * @param prefix - * @param nickname - * @param suffix - * @param icp - * @return {@link String} - */ + * Converts the format section of a message to JSON using PlaceholderAPI. + * + * @param s + * @param format + * @param prefix + * @param nickname + * @param suffix + * @param icp + * @return {@link String} + */ private String convertPlaceholders(String s, JsonFormat format, VentureChatPlayer icp) { String remaining = s; String temp = ""; @@ -105,7 +107,8 @@ public class VentureChatFormatService { indexStart = matcher.start(); indexEnd = matcher.end(); placeholder = remaining.substring(indexStart, indexEnd); - formattedPlaceholder = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder)); + formattedPlaceholder = FormatUtils + .FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder)); temp += convertToJsonColors(lastCode + remaining.substring(0, indexStart)) + ","; lastCode = getLastCode(lastCode + remaining.substring(0, indexStart)); String action = ""; @@ -121,9 +124,9 @@ public class VentureChatFormatService { } } } - if(!hover.isEmpty()) { - hover = FormatUtils.FormatStringAll( - PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1))); + if (!hover.isEmpty()) { + hover = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), + hover.substring(0, hover.length() - 1))); } temp += convertToJsonColors(lastCode + formattedPlaceholder, ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text @@ -141,11 +144,11 @@ public class VentureChatFormatService { } /** - * Converts URL's to JSON. - * - * @param s - * @return {@link String} - */ + * Converts URL's to JSON. + * + * @param s + * @return {@link String} + */ private String convertLinks(String s) { String remaining = s; String temp = ""; @@ -219,22 +222,22 @@ public class VentureChatFormatService { } /** - * Converts a message to JSON colors with no additional JSON extensions. - * - * @param s - * @return {@link String} - */ + * Converts a message to JSON colors with no additional JSON extensions. + * + * @param s + * @return {@link String} + */ public String convertToJsonColors(String s) { return convertToJsonColors(s, ""); } /** - * Converts a message to JSON colors with additional JSON extensions. - * - * @param s - * @param extensions - * @return {@link String} - */ + * Converts a message to JSON colors with additional JSON extensions. + * + * @param s + * @param extensions + * @return {@link String} + */ private String convertToJsonColors(String s, String extensions) { String remaining = s; String temp = ""; @@ -404,7 +407,7 @@ public class VentureChatFormatService { return "[" + convertToJsonColors(DEFAULT_COLOR_CODE + s) + "]"; } } - + private String escapeJsonChars(String s) { return s.replace("\\", "\\\\").replace("\"", "\\\""); } @@ -416,8 +419,7 @@ public class VentureChatFormatService { ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/vchatgui " + sender + " " + channelName + " " + hash + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" - + convertToJsonColors( - FormatUtils.FormatStringAll(plugin.getConfig().getString("guitext"))) + + convertToJsonColors(FormatUtils.FormatStringAll(plugin.getConfig().getString("guitext"))) + "]}}") + "]"; } @@ -446,38 +448,71 @@ public class VentureChatFormatService { e.printStackTrace(); } } - + @SuppressWarnings("unchecked") public String toColoredText(Object o, Class c) { if (VersionHandler.is1_7()) { return "\"extra\":[{\"text\":\"Hover to see original message is not currently supported in 1.7\",\"color\":\"red\"}]"; - } + } List finalList = new ArrayList<>(); StringBuilder stringbuilder = new StringBuilder(); stringbuilder.append("\"extra\":["); try { splitComponents(finalList, o, c); - for (Object component : finalList) { + for (Object component : finalList) { try { - String text = (String) component.getClass().getMethod("getText").invoke(component); - Object chatModifier = component.getClass().getMethod("getChatModifier").invoke(component); - String color = chatModifier.getClass().getMethod("getColor").invoke(chatModifier).toString(); - boolean bold = (boolean) chatModifier.getClass().getMethod("isBold").invoke(chatModifier); - boolean strikethrough = (boolean) chatModifier.getClass().getMethod("isStrikethrough").invoke(chatModifier); - boolean italic = (boolean) chatModifier.getClass().getMethod("isItalic").invoke(chatModifier); - boolean underlined = (boolean) chatModifier.getClass().getMethod("isUnderlined").invoke(chatModifier); - boolean obfuscated = (boolean) chatModifier.getClass().getMethod("isRandom").invoke(chatModifier); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("text", text); - jsonObject.put("color", color); - jsonObject.put("bold", bold); - jsonObject.put("strikethrough", strikethrough); - jsonObject.put("italic", italic); - jsonObject.put("underlined", underlined); - jsonObject.put("obfuscated", obfuscated); - stringbuilder.append(jsonObject.toJSONString() + ","); - } - catch(Exception e) { + if (VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10() + || VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13() + || VersionHandler.is1_14() || VersionHandler.is1_15() || VersionHandler.is1_16() + || VersionHandler.is1_17()) { + String text = (String) component.getClass().getMethod("getText").invoke(component); + Object chatModifier = component.getClass().getMethod("getChatModifier").invoke(component); + Object color = chatModifier.getClass().getMethod("getColor").invoke(chatModifier); + String colorString = "white"; + if (color != null) { + colorString = color.getClass().getMethod("b").invoke(color).toString(); + } + boolean bold = (boolean) chatModifier.getClass().getMethod("isBold").invoke(chatModifier); + boolean strikethrough = (boolean) chatModifier.getClass().getMethod("isStrikethrough") + .invoke(chatModifier); + boolean italic = (boolean) chatModifier.getClass().getMethod("isItalic").invoke(chatModifier); + boolean underlined = (boolean) chatModifier.getClass().getMethod("isUnderlined") + .invoke(chatModifier); + boolean obfuscated = (boolean) chatModifier.getClass().getMethod("isRandom") + .invoke(chatModifier); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("text", text); + jsonObject.put("color", colorString); + jsonObject.put("bold", bold); + jsonObject.put("strikethrough", strikethrough); + jsonObject.put("italic", italic); + jsonObject.put("underlined", underlined); + jsonObject.put("obfuscated", obfuscated); + stringbuilder.append(jsonObject.toJSONString() + ","); + } else { + String text = (String) component.getClass().getMethod("getString").invoke(component); + Object chatModifier = component.getClass().getMethod("c").invoke(component); + Object color = chatModifier.getClass().getMethod("a").invoke(chatModifier); + String colorString = "white"; + if (color != null) { + colorString = color.getClass().getMethod("b").invoke(color).toString(); + } + boolean bold = (boolean) chatModifier.getClass().getMethod("b").invoke(chatModifier); + boolean italic = (boolean) chatModifier.getClass().getMethod("c").invoke(chatModifier); + boolean strikethrough = (boolean) chatModifier.getClass().getMethod("d").invoke(chatModifier); + boolean underlined = (boolean) chatModifier.getClass().getMethod("e").invoke(chatModifier); + boolean obfuscated = (boolean) chatModifier.getClass().getMethod("f").invoke(chatModifier); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("text", text); + jsonObject.put("color", colorString); + jsonObject.put("bold", bold); + jsonObject.put("strikethrough", strikethrough); + jsonObject.put("italic", italic); + jsonObject.put("underlined", underlined); + jsonObject.put("obfuscated", obfuscated); + stringbuilder.append(jsonObject.toJSONString() + ","); + } + } catch (Exception e) { return "\"extra\":[{\"text\":\"Something went wrong. Could not access color.\",\"color\":\"red\"}]"; } } @@ -485,7 +520,7 @@ public class VentureChatFormatService { e.printStackTrace(); } String coloredText = stringbuilder.toString(); - if(coloredText.endsWith(",")) { + if (coloredText.endsWith(",")) { coloredText = coloredText.substring(0, coloredText.length() - 1); } coloredText += "]"; @@ -500,29 +535,22 @@ public class VentureChatFormatService { for (Object component : finalList) { if (VersionHandler.is1_7()) { stringbuilder.append((String) component.getClass().getMethod("e").invoke(component)); - } else { + } else if (VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10() + || VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13() + || VersionHandler.is1_14() || VersionHandler.is1_15() || VersionHandler.is1_16() + || VersionHandler.is1_17()) { stringbuilder.append((String) component.getClass().getMethod("getText").invoke(component)); + } else { + stringbuilder.append((String) component.getClass().getMethod("getString").invoke(component)); } } } catch (Exception e) { e.printStackTrace(); } - // if(plugin.getConfig().getString("loglevel", "info").equals("debug")) { - // System.out.println("my string"); - // System.out.println("my string"); - // System.out.println("my string"); - // System.out.println("my string"); - // System.out.println("my string"); - // System.out.println(stringbuilder.toString()); - // } return stringbuilder.toString(); } private void splitComponents(List finalList, Object o, Class c) throws Exception { -// for(Method m : c.getMethods()) { -// System.out.println(m.getName()); -// } - if (VersionHandler.is1_7() || VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10() || VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13() || (VersionHandler.is1_14() && !VersionHandler.is1_14_4())) { @@ -535,7 +563,8 @@ public class VentureChatFormatService { finalList.add(component); } } - } else { + } else if (VersionHandler.is1_14_4() || VersionHandler.is1_15() || VersionHandler.is1_16() + || VersionHandler.is1_17()) { ArrayList list = (ArrayList) c.getMethod("getSiblings").invoke(o, new Object[0]); for (Object component : list) { ArrayList innerList = (ArrayList) c.getMethod("getSiblings").invoke(component, new Object[0]); @@ -545,6 +574,16 @@ public class VentureChatFormatService { finalList.add(component); } } + } else { + ArrayList list = (ArrayList) c.getMethod("b").invoke(o, new Object[0]); + for (Object component : list) { + ArrayList innerList = (ArrayList) c.getMethod("b").invoke(component, new Object[0]); + if (innerList.size() > 0) { + splitComponents(finalList, component, c); + } else { + finalList.add(component); + } + } } } @@ -573,33 +612,34 @@ public class VentureChatFormatService { } public void broadcastToServer(String message) { - for(VentureChatPlayer mcp : playerApiService.getOnlineMineverseChatPlayers()) { + for (VentureChatPlayer mcp : playerApiService.getOnlineMineverseChatPlayers()) { mcp.getPlayer().sendMessage(message); } } - + public void playMessageSound(VentureChatPlayer mcp) { Player player = mcp.getPlayer(); String soundName = plugin.getConfig().getString("message_sound", DEFAULT_MESSAGE_SOUND); - if(!soundName.equalsIgnoreCase("None")) { + if (!soundName.equalsIgnoreCase("None")) { Sound messageSound = getSound(soundName); player.playSound(player.getLocation(), messageSound, 1, 0); } } - + private Sound getSound(String soundName) { - if(Arrays.asList(Sound.values()).stream().map(Sound::toString).collect(Collectors.toList()).contains(soundName)) { + if (Arrays.asList(Sound.values()).stream().map(Sound::toString).collect(Collectors.toList()) + .contains(soundName)) { return Sound.valueOf(soundName); } - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Message sound invalid!")); + Bukkit.getConsoleSender() + .sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Message sound invalid!")); return getDefaultMessageSound(); } - + private Sound getDefaultMessageSound() { - if(VersionHandler.is1_7() || VersionHandler.is1_8()) { + if (VersionHandler.is1_7() || VersionHandler.is1_8()) { return Sound.valueOf(DEFAULT_LEGACY_MESSAGE_SOUND); - } - else { + } else { return Sound.valueOf(DEFAULT_MESSAGE_SOUND); } } diff --git a/src/main/java/venture/Aust1n46/chat/service/VentureChatPlayerApiService.java b/src/main/java/venture/Aust1n46/chat/service/VentureChatPlayerApiService.java index a5f7aae..69a8d8d 100644 --- a/src/main/java/venture/Aust1n46/chat/service/VentureChatPlayerApiService.java +++ b/src/main/java/venture/Aust1n46/chat/service/VentureChatPlayerApiService.java @@ -8,8 +8,8 @@ import java.util.UUID; import org.bukkit.entity.Player; -import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer; +import venture.Aust1n46.chat.model.VentureChatPlayer; /** * API class for looking up wrapped {@link VentureChatPlayer} objects from @@ -17,7 +17,7 @@ import venture.Aust1n46.chat.model.SynchronizedVentureChatPlayer; * * @author Aust1n46 */ -public final class VentureChatPlayerApiService { +public class VentureChatPlayerApiService { private static HashMap playerMap = new HashMap(); private static HashMap namesMap = new HashMap(); private static HashMap onlinePlayerMap = new HashMap(); @@ -102,7 +102,7 @@ public final class VentureChatPlayerApiService { * @param player {@link Player} object. * @return {@link VentureChatPlayer} */ - public VentureChatPlayer getOnlineMineverseChatPlayer(Player player) { + public VentureChatPlayer getOnlineMineverseChatPlayer(final Player player) { return getOnlineMineverseChatPlayer(player.getUniqueId()); } @@ -131,7 +131,6 @@ public final class VentureChatPlayerApiService { - public List getNetworkPlayerNames() { return networkPlayerNames; @@ -148,11 +147,6 @@ public final class VentureChatPlayerApiService { public void addSynchronizedMineverseChatPlayerToMap(SynchronizedVentureChatPlayer smcp) { proxyPlayerMap.put(smcp.getUUID(), smcp); } - -// @Deprecated -// public static void clearBungeePlayerMap() { -// clearProxyPlayerMap(); -// } public void clearProxyPlayerMap() { proxyPlayerMap.clear(); diff --git a/src/main/java/mineverse/Aust1n46/chat/utilities/FormatUtils.java b/src/main/java/venture/Aust1n46/chat/utilities/FormatUtils.java similarity index 98% rename from src/main/java/mineverse/Aust1n46/chat/utilities/FormatUtils.java rename to src/main/java/venture/Aust1n46/chat/utilities/FormatUtils.java index 624c470..048afb2 100644 --- a/src/main/java/mineverse/Aust1n46/chat/utilities/FormatUtils.java +++ b/src/main/java/venture/Aust1n46/chat/utilities/FormatUtils.java @@ -1,11 +1,11 @@ -package mineverse.Aust1n46.chat.utilities; +package venture.Aust1n46.chat.utilities; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.bukkit.ChatColor; -import mineverse.Aust1n46.chat.localization.LocalizedMessage; +import venture.Aust1n46.chat.localization.LocalizedMessage; public class FormatUtils { public static final char BUKKIT_COLOR_CODE_PREFIX_CHAR = '\u00A7'; @@ -19,6 +19,8 @@ public class FormatUtils { public static final long MILLISECONDS_PER_MINUTE = 60000; public static final long MILLISECONDS_PER_SECOND = 1000; + public static final int LINE_LENGTH = 40; + private static final Pattern LEGACY_CHAT_COLOR_DIGITS_PATTERN = Pattern.compile("&([0-9])"); private static final Pattern LEGACY_CHAT_COLOR_PATTERN = Pattern.compile( "(? loginListener.onPlayerQuit(mockPlayerQuitEvent)); + } + + @Test + public void testPlayerJoin_existingPlayer_NoProxy() { + when(mockPlayerJoinEvent.getPlayer()).thenReturn(mockPlayer); + when(configService.getDefaultChannel()).thenReturn(mockDefaultChannel); + when(mockPlayer.getName()).thenReturn("Aust1n46"); + when(configService.isProxyEnabled()).thenReturn(false); + loginListener.onPlayerJoin(mockPlayerJoinEvent); + } + + @Test + public void testPlayerJoin_existingPlayer_Proxy() { + when(mockPlayerJoinEvent.getPlayer()).thenReturn(mockPlayer); + when(configService.getDefaultChannel()).thenReturn(mockDefaultChannel); + when(mockPlayer.getName()).thenReturn("Aust1n46"); + when(configService.isProxyEnabled()).thenReturn(true); + loginListener.onPlayerJoin(mockPlayerJoinEvent); } }