From d36fca277d9299e4dc9e2895fb1ae9cd5ca8c48a Mon Sep 17 00:00:00 2001 From: Aust1n46 Date: Mon, 12 Feb 2024 06:00:20 -0600 Subject: [PATCH] Model updates --- .../controllers/ProxyFlatFileController.java | 2 +- .../controllers/SpigotFlatFileController.java | 2 +- .../initiators/listeners/ChatListener.java | 6 +- .../Aust1n46/chat/model/ChatMessage.java | 19 +++--- .../Aust1n46/chat/model/JsonAttribute.java | 15 +++-- .../Aust1n46/chat/model/JsonFormat.java | 18 ++--- .../Aust1n46/chat/model/MuteContainer.java | 55 ++++----------- .../chat/model/TemporaryDataInstance.java | 47 +++++++------ .../chat/model/VentureChatPlayer.java | 67 +++++++++++-------- .../chat/model/VentureChatProxyServer.java | 10 ++- 10 files changed, 116 insertions(+), 125 deletions(-) diff --git a/src/main/java/venture/Aust1n46/chat/controllers/ProxyFlatFileController.java b/src/main/java/venture/Aust1n46/chat/controllers/ProxyFlatFileController.java index 233fb11..48c0deb 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/ProxyFlatFileController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/ProxyFlatFileController.java @@ -59,7 +59,7 @@ public class ProxyFlatFileController { while (m.hasMoreTokens()) { String[] parts = m.nextToken().split(":"); String channelName = parts[0]; - mutes.put(channelName, new MuteContainer(channelName, Long.parseLong(parts[1]))); + mutes.put(channelName, new MuteContainer(channelName, Long.parseLong(parts[1]), "")); } HashSet ignores = new HashSet(); StringTokenizer n = new StringTokenizer(playerData.getString(uuidString + ".ignores"), ","); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/SpigotFlatFileController.java b/src/main/java/venture/Aust1n46/chat/controllers/SpigotFlatFileController.java index fcaecf4..5b1c6fc 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/SpigotFlatFileController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/SpigotFlatFileController.java @@ -94,7 +94,7 @@ public class SpigotFlatFileController { continue; } String channelName = parts[0]; - mutes.put(channelName, new MuteContainer(channelName, Long.parseLong(parts[1]))); + mutes.put(channelName, new MuteContainer(channelName, Long.parseLong(parts[1]), "")); } } Set blockedCommands = new HashSet(); 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 0c78877..fa1f49d 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java @@ -190,7 +190,7 @@ public class ChatListener implements Listener { private void processMute(final VentureChatPlayer ventureChatPlayer, final ChatChannel channel) { MuteContainer muteContainer = ventureChatPlayer.getMute(channel.getName()); - if (muteContainer.hasDuration()) { + if (muteContainer.getDuration() > 0) { long dateTimeMillis = System.currentTimeMillis(); long muteTimeMillis = muteContainer.getDuration(); long remainingMuteTime = muteTimeMillis - dateTimeMillis; @@ -198,7 +198,7 @@ public class ChatListener implements Listener { remainingMuteTime = 1000; } String timeString = FormatUtils.parseTimeStringFromMillis(remainingMuteTime); - if (muteContainer.hasReason()) { + if (!muteContainer.getReason().isEmpty()) { ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.CHANNEL_MUTED_TIMED_REASON.toString().replace("{channel_color}", channel.getColor()) .replace("{channel_name}", channel.getName()).replace("{time}", timeString).replace("{reason}", muteContainer.getReason())); } else { @@ -206,7 +206,7 @@ public class ChatListener implements Listener { .replace("{channel_name}", channel.getName()).replace("{time}", timeString)); } } else { - if (muteContainer.hasReason()) { + if (!muteContainer.getReason().isEmpty()) { ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.CHANNEL_MUTED_REASON.toString().replace("{channel_color}", channel.getColor()) .replace("{channel_name}", channel.getName()).replace("{reason}", muteContainer.getReason())); } else { diff --git a/src/main/java/venture/Aust1n46/chat/model/ChatMessage.java b/src/main/java/venture/Aust1n46/chat/model/ChatMessage.java index 47bdc70..cdd4e71 100644 --- a/src/main/java/venture/Aust1n46/chat/model/ChatMessage.java +++ b/src/main/java/venture/Aust1n46/chat/model/ChatMessage.java @@ -2,19 +2,20 @@ package venture.Aust1n46.chat.model; import com.comphenix.protocol.wrappers.WrappedChatComponent; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; -@Data +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor public class ChatMessage { private WrappedChatComponent component; private String message; private String coloredMessage; private int hash; - - public ChatMessage(WrappedChatComponent component, String message, String coloredMessage, int hash) { - this.component = component; - this.message = message; - this.coloredMessage = coloredMessage; - this.hash = hash; - } } diff --git a/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java b/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java index b115d05..f7f87b5 100644 --- a/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java +++ b/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java @@ -2,19 +2,20 @@ package venture.Aust1n46.chat.model; import java.util.List; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; @Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor public class JsonAttribute { private String name; private List hoverText; private ClickAction clickAction; private String clickText; - - public JsonAttribute(String name, List hoverText, ClickAction clickAction, String clickText) { - this.name = name; - this.hoverText = hoverText; - this.clickAction = clickAction; - this.clickText = clickText; - } } diff --git a/src/main/java/venture/Aust1n46/chat/model/JsonFormat.java b/src/main/java/venture/Aust1n46/chat/model/JsonFormat.java index 0ba3ccf..cc59999 100644 --- a/src/main/java/venture/Aust1n46/chat/model/JsonFormat.java +++ b/src/main/java/venture/Aust1n46/chat/model/JsonFormat.java @@ -2,17 +2,19 @@ package venture.Aust1n46.chat.model; import java.util.List; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; @Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor public class JsonFormat { - 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; - } + private int priority; + private List jsonAttributes; } diff --git a/src/main/java/venture/Aust1n46/chat/model/MuteContainer.java b/src/main/java/venture/Aust1n46/chat/model/MuteContainer.java index d1711f8..93a065b 100644 --- a/src/main/java/venture/Aust1n46/chat/model/MuteContainer.java +++ b/src/main/java/venture/Aust1n46/chat/model/MuteContainer.java @@ -1,45 +1,18 @@ package venture.Aust1n46.chat.model; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor public class MuteContainer { - private String channel; - private String reason; - private long duration; - - public MuteContainer(String channel) { - this(channel, 0, ""); - } - - public MuteContainer(String channel, long duration) { - this(channel, duration, ""); - } - - public MuteContainer(String channel, String reason) { - this(channel, 0, reason); - } - - public MuteContainer(String channel, long duration, String reason) { - this.channel = channel; - this.reason = reason; - this.duration = duration; - } - - public String getChannel() { - return channel; - } - - public boolean hasReason() { - return !reason.equals(""); - } - - public String getReason() { - return reason; - } - - public boolean hasDuration() { - return duration > 0; - } - - public long getDuration() { - return duration; - } + private String channel; + private long duration; + private String reason; } diff --git a/src/main/java/venture/Aust1n46/chat/model/TemporaryDataInstance.java b/src/main/java/venture/Aust1n46/chat/model/TemporaryDataInstance.java index 0f89ee8..dd439fd 100644 --- a/src/main/java/venture/Aust1n46/chat/model/TemporaryDataInstance.java +++ b/src/main/java/venture/Aust1n46/chat/model/TemporaryDataInstance.java @@ -3,35 +3,34 @@ package venture.Aust1n46.chat.model; import java.util.HashMap; import java.util.UUID; +import lombok.Getter; + public class TemporaryDataInstance { - private int messagePackets; - private final UUID uuid; + @Getter + private int messagePackets; + private final UUID uuid; - private static final HashMap temporaryDataInstances = new HashMap(); + private static final HashMap temporaryDataInstances = new HashMap(); - private TemporaryDataInstance(UUID uuid) { - this.uuid = uuid; - } + private TemporaryDataInstance(UUID uuid) { + this.uuid = uuid; + } - public static UUID createTemporaryDataInstance() { - UUID uuid = UUID.randomUUID(); - temporaryDataInstances.put(uuid, new TemporaryDataInstance(uuid)); - return uuid; - } + public static UUID createTemporaryDataInstance() { + UUID uuid = UUID.randomUUID(); + temporaryDataInstances.put(uuid, new TemporaryDataInstance(uuid)); + return uuid; + } - public static TemporaryDataInstance getTemporaryDataInstance(UUID uuid) { - return temporaryDataInstances.get(uuid); - } + public static TemporaryDataInstance getTemporaryDataInstance(UUID uuid) { + return temporaryDataInstances.get(uuid); + } - public int getMessagePackets() { - return this.messagePackets; - } + public void incrementMessagePackets() { + this.messagePackets++; + } - public void incrementMessagePackets() { - this.messagePackets++; - } - - public void destroyInstance() { - temporaryDataInstances.remove(uuid); - } + public void destroyInstance() { + temporaryDataInstances.remove(uuid); + } } diff --git a/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java b/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java index c7e5ce4..01c9069 100644 --- a/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java +++ b/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java @@ -11,15 +11,22 @@ import java.util.UUID; import org.bukkit.entity.Player; import lombok.AccessLevel; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; /** * Wrapper for {@link Player} * * @author Aust1n46 */ -@Data +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor public class VentureChatPlayer { @Setter(value = AccessLevel.NONE) private UUID uuid; @@ -53,8 +60,10 @@ public class VentureChatPlayer { private boolean rangedSpy; private boolean messageToggle; private boolean 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) { + + 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; this.currentChannel = currentChannel; @@ -76,7 +85,7 @@ public class VentureChatPlayer { this.messageToggle = messageToggle; this.bungeeToggle = bungeeToggle; } - + public VentureChatPlayer(UUID uuid, String name, ChatChannel currentChannel) { this.uuid = uuid; this.name = name; @@ -95,10 +104,10 @@ public class VentureChatPlayer { this.messageToggle = true; this.bungeeToggle = true; } - + public boolean getRangedSpy() { - if(isOnline()) { - if(!getPlayer().hasPermission("venturechat.rangedspy")) { + if (isOnline()) { + if (!getPlayer().hasPermission("venturechat.rangedspy")) { setRangedSpy(false); return false; } @@ -107,7 +116,7 @@ public class VentureChatPlayer { } public boolean setCurrentChannel(ChatChannel channel) { - if(channel != null) { + if (channel != null) { this.currentChannel = channel; return true; } @@ -121,13 +130,13 @@ public class VentureChatPlayer { public void removeIgnore(UUID ignore) { this.ignores.remove(ignore); } - + public boolean isListening(String channel) { return listening.contains(channel); } public boolean addListening(String channel) { - if(channel != null) { + if (channel != null) { this.listening.add(channel); return true; } @@ -135,7 +144,7 @@ public class VentureChatPlayer { } public boolean removeListening(String channel) { - if(channel != null) { + if (channel != null) { this.listening.remove(channel); return true; } @@ -149,7 +158,7 @@ public class VentureChatPlayer { public Collection getMutes() { return this.mutes.values(); } - + public MuteContainer getMute(String channel) { return mutes.get(channel); } @@ -157,17 +166,17 @@ public class VentureChatPlayer { public boolean addMute(String channel) { return addMute(channel, 0, ""); } - + public boolean addMute(String channel, long time) { return addMute(channel, time, ""); } - + public boolean addMute(String channel, String reason) { return addMute(channel, 0, reason); } - + public boolean addMute(String channel, long time, String reason) { - if(channel != null && time >= 0) { + if (channel != null && time >= 0) { mutes.put(channel, new MuteContainer(channel, time, reason)); return true; } @@ -175,7 +184,7 @@ public class VentureChatPlayer { } public boolean removeMute(String channel) { - if(channel != null) { + if (channel != null) { mutes.remove(channel); return true; } @@ -211,8 +220,8 @@ public class VentureChatPlayer { } public boolean isSpy() { - if(this.isOnline()) { - if(!this.getPlayer().hasPermission("venturechat.spy")) { + if (this.isOnline()) { + if (!this.getPlayer().hasPermission("venturechat.spy")) { this.setSpy(false); return false; } @@ -221,8 +230,8 @@ public class VentureChatPlayer { } public boolean hasCommandSpy() { - if(this.isOnline()) { - if(!this.getPlayer().hasPermission("venturechat.commandspy")) { + if (this.isOnline()) { + if (!this.getPlayer().hasPermission("venturechat.commandspy")) { this.setCommandSpy(false); return false; } @@ -231,7 +240,7 @@ public class VentureChatPlayer { } public boolean setQuickChannel(ChatChannel channel) { - if(channel != null) { + if (channel != null) { this.quickChannel = channel; return true; } @@ -243,7 +252,7 @@ public class VentureChatPlayer { } public boolean addCooldown(ChatChannel channel, long time) { - if(channel != null && time > 0) { + if (channel != null && time > 0) { cooldowns.put(channel, time); return true; } @@ -251,7 +260,7 @@ public class VentureChatPlayer { } public boolean removeCooldown(ChatChannel channel) { - if(channel != null) { + if (channel != null) { cooldowns.remove(channel); return true; } @@ -261,13 +270,13 @@ public class VentureChatPlayer { public boolean hasCooldown(ChatChannel channel) { return channel != null && this.cooldowns != null ? this.cooldowns.containsKey(channel) : false; } - + public boolean hasSpam(ChatChannel channel) { return channel != null && this.spam != null ? this.spam.containsKey(channel) : false; } - + public boolean addSpam(ChatChannel channel) { - if(channel != null) { + if (channel != null) { spam.put(channel, new ArrayList()); return true; } @@ -275,7 +284,7 @@ public class VentureChatPlayer { } public void addMessage(ChatMessage message) { - if(this.messages.size() >= 100) { + if (this.messages.size() >= 100) { this.messages.remove(0); } this.messages.add(message); diff --git a/src/main/java/venture/Aust1n46/chat/model/VentureChatProxyServer.java b/src/main/java/venture/Aust1n46/chat/model/VentureChatProxyServer.java index e1b8138..d6d0658 100644 --- a/src/main/java/venture/Aust1n46/chat/model/VentureChatProxyServer.java +++ b/src/main/java/venture/Aust1n46/chat/model/VentureChatProxyServer.java @@ -1,9 +1,15 @@ package venture.Aust1n46.chat.model; import lombok.AllArgsConstructor; -import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; -@Data +@Getter +@Setter +@ToString +@NoArgsConstructor @AllArgsConstructor public class VentureChatProxyServer { private String name;