Model updates

This commit is contained in:
Aust1n46 2024-02-12 06:00:20 -06:00
parent ba1bc62fb9
commit d36fca277d
10 changed files with 116 additions and 125 deletions

View File

@ -59,7 +59,7 @@ public class ProxyFlatFileController {
while (m.hasMoreTokens()) { while (m.hasMoreTokens()) {
String[] parts = m.nextToken().split(":"); String[] parts = m.nextToken().split(":");
String channelName = parts[0]; 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<UUID> ignores = new HashSet<UUID>(); HashSet<UUID> ignores = new HashSet<UUID>();
StringTokenizer n = new StringTokenizer(playerData.getString(uuidString + ".ignores"), ","); StringTokenizer n = new StringTokenizer(playerData.getString(uuidString + ".ignores"), ",");

View File

@ -94,7 +94,7 @@ public class SpigotFlatFileController {
continue; continue;
} }
String channelName = parts[0]; 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<String> blockedCommands = new HashSet<String>(); Set<String> blockedCommands = new HashSet<String>();

View File

@ -190,7 +190,7 @@ public class ChatListener implements Listener {
private void processMute(final VentureChatPlayer ventureChatPlayer, final ChatChannel channel) { private void processMute(final VentureChatPlayer ventureChatPlayer, final ChatChannel channel) {
MuteContainer muteContainer = ventureChatPlayer.getMute(channel.getName()); MuteContainer muteContainer = ventureChatPlayer.getMute(channel.getName());
if (muteContainer.hasDuration()) { if (muteContainer.getDuration() > 0) {
long dateTimeMillis = System.currentTimeMillis(); long dateTimeMillis = System.currentTimeMillis();
long muteTimeMillis = muteContainer.getDuration(); long muteTimeMillis = muteContainer.getDuration();
long remainingMuteTime = muteTimeMillis - dateTimeMillis; long remainingMuteTime = muteTimeMillis - dateTimeMillis;
@ -198,7 +198,7 @@ public class ChatListener implements Listener {
remainingMuteTime = 1000; remainingMuteTime = 1000;
} }
String timeString = FormatUtils.parseTimeStringFromMillis(remainingMuteTime); 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()) 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())); .replace("{channel_name}", channel.getName()).replace("{time}", timeString).replace("{reason}", muteContainer.getReason()));
} else { } else {
@ -206,7 +206,7 @@ public class ChatListener implements Listener {
.replace("{channel_name}", channel.getName()).replace("{time}", timeString)); .replace("{channel_name}", channel.getName()).replace("{time}", timeString));
} }
} else { } else {
if (muteContainer.hasReason()) { if (!muteContainer.getReason().isEmpty()) {
ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.CHANNEL_MUTED_REASON.toString().replace("{channel_color}", channel.getColor()) ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.CHANNEL_MUTED_REASON.toString().replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()).replace("{reason}", muteContainer.getReason())); .replace("{channel_name}", channel.getName()).replace("{reason}", muteContainer.getReason()));
} else { } else {

View File

@ -2,19 +2,20 @@ package venture.Aust1n46.chat.model;
import com.comphenix.protocol.wrappers.WrappedChatComponent; 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 { public class ChatMessage {
private WrappedChatComponent component; private WrappedChatComponent component;
private String message; private String message;
private String coloredMessage; private String coloredMessage;
private int hash; 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;
}
} }

View File

@ -2,19 +2,20 @@ package venture.Aust1n46.chat.model;
import java.util.List; import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter @Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class JsonAttribute { public class JsonAttribute {
private String name; private String name;
private List<String> hoverText; private List<String> hoverText;
private ClickAction clickAction; private ClickAction clickAction;
private String clickText; private String clickText;
public JsonAttribute(String name, List<String> hoverText, ClickAction clickAction, String clickText) {
this.name = name;
this.hoverText = hoverText;
this.clickAction = clickAction;
this.clickText = clickText;
}
} }

View File

@ -2,17 +2,19 @@ package venture.Aust1n46.chat.model;
import java.util.List; import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter @Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class JsonFormat { public class JsonFormat {
private List<JsonAttribute> jsonAttributes;
private int priority;
private String name; private String name;
private int priority;
public JsonFormat(String name, int priority, List<JsonAttribute> jsonAttributes) { private List<JsonAttribute> jsonAttributes;
this.name = name;
this.priority = priority;
this.jsonAttributes = jsonAttributes;
}
} }

View File

@ -1,45 +1,18 @@
package venture.Aust1n46.chat.model; 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 { public class MuteContainer {
private String channel; private String channel;
private String reason; private long duration;
private long duration; private String reason;
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;
}
} }

View File

@ -3,35 +3,34 @@ package venture.Aust1n46.chat.model;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import lombok.Getter;
public class TemporaryDataInstance { public class TemporaryDataInstance {
private int messagePackets; @Getter
private final UUID uuid; private int messagePackets;
private final UUID uuid;
private static final HashMap<UUID, TemporaryDataInstance> temporaryDataInstances = new HashMap<UUID, TemporaryDataInstance>(); private static final HashMap<UUID, TemporaryDataInstance> temporaryDataInstances = new HashMap<UUID, TemporaryDataInstance>();
private TemporaryDataInstance(UUID uuid) { private TemporaryDataInstance(UUID uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
public static UUID createTemporaryDataInstance() { public static UUID createTemporaryDataInstance() {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
temporaryDataInstances.put(uuid, new TemporaryDataInstance(uuid)); temporaryDataInstances.put(uuid, new TemporaryDataInstance(uuid));
return uuid; return uuid;
} }
public static TemporaryDataInstance getTemporaryDataInstance(UUID uuid) { public static TemporaryDataInstance getTemporaryDataInstance(UUID uuid) {
return temporaryDataInstances.get(uuid); return temporaryDataInstances.get(uuid);
} }
public int getMessagePackets() { public void incrementMessagePackets() {
return this.messagePackets; this.messagePackets++;
} }
public void incrementMessagePackets() { public void destroyInstance() {
this.messagePackets++; temporaryDataInstances.remove(uuid);
} }
public void destroyInstance() {
temporaryDataInstances.remove(uuid);
}
} }

View File

@ -11,15 +11,22 @@ import java.util.UUID;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Data; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
/** /**
* Wrapper for {@link Player} * Wrapper for {@link Player}
* *
* @author Aust1n46 * @author Aust1n46
*/ */
@Data @Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class VentureChatPlayer { public class VentureChatPlayer {
@Setter(value = AccessLevel.NONE) @Setter(value = AccessLevel.NONE)
private UUID uuid; private UUID uuid;
@ -54,7 +61,9 @@ public class VentureChatPlayer {
private boolean messageToggle; private boolean messageToggle;
private boolean bungeeToggle; private boolean bungeeToggle;
public VentureChatPlayer(UUID uuid, String name, ChatChannel currentChannel, Set<UUID> ignores, Set<String> listening, HashMap<String, MuteContainer> mutes, Set<String> 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<UUID> ignores, Set<String> listening, HashMap<String, MuteContainer> mutes,
Set<String> 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.uuid = uuid;
this.name = name; this.name = name;
this.currentChannel = currentChannel; this.currentChannel = currentChannel;
@ -97,8 +106,8 @@ public class VentureChatPlayer {
} }
public boolean getRangedSpy() { public boolean getRangedSpy() {
if(isOnline()) { if (isOnline()) {
if(!getPlayer().hasPermission("venturechat.rangedspy")) { if (!getPlayer().hasPermission("venturechat.rangedspy")) {
setRangedSpy(false); setRangedSpy(false);
return false; return false;
} }
@ -107,7 +116,7 @@ public class VentureChatPlayer {
} }
public boolean setCurrentChannel(ChatChannel channel) { public boolean setCurrentChannel(ChatChannel channel) {
if(channel != null) { if (channel != null) {
this.currentChannel = channel; this.currentChannel = channel;
return true; return true;
} }
@ -127,7 +136,7 @@ public class VentureChatPlayer {
} }
public boolean addListening(String channel) { public boolean addListening(String channel) {
if(channel != null) { if (channel != null) {
this.listening.add(channel); this.listening.add(channel);
return true; return true;
} }
@ -135,7 +144,7 @@ public class VentureChatPlayer {
} }
public boolean removeListening(String channel) { public boolean removeListening(String channel) {
if(channel != null) { if (channel != null) {
this.listening.remove(channel); this.listening.remove(channel);
return true; return true;
} }
@ -167,7 +176,7 @@ public class VentureChatPlayer {
} }
public boolean addMute(String channel, long time, String 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)); mutes.put(channel, new MuteContainer(channel, time, reason));
return true; return true;
} }
@ -175,7 +184,7 @@ public class VentureChatPlayer {
} }
public boolean removeMute(String channel) { public boolean removeMute(String channel) {
if(channel != null) { if (channel != null) {
mutes.remove(channel); mutes.remove(channel);
return true; return true;
} }
@ -211,8 +220,8 @@ public class VentureChatPlayer {
} }
public boolean isSpy() { public boolean isSpy() {
if(this.isOnline()) { if (this.isOnline()) {
if(!this.getPlayer().hasPermission("venturechat.spy")) { if (!this.getPlayer().hasPermission("venturechat.spy")) {
this.setSpy(false); this.setSpy(false);
return false; return false;
} }
@ -221,8 +230,8 @@ public class VentureChatPlayer {
} }
public boolean hasCommandSpy() { public boolean hasCommandSpy() {
if(this.isOnline()) { if (this.isOnline()) {
if(!this.getPlayer().hasPermission("venturechat.commandspy")) { if (!this.getPlayer().hasPermission("venturechat.commandspy")) {
this.setCommandSpy(false); this.setCommandSpy(false);
return false; return false;
} }
@ -231,7 +240,7 @@ public class VentureChatPlayer {
} }
public boolean setQuickChannel(ChatChannel channel) { public boolean setQuickChannel(ChatChannel channel) {
if(channel != null) { if (channel != null) {
this.quickChannel = channel; this.quickChannel = channel;
return true; return true;
} }
@ -243,7 +252,7 @@ public class VentureChatPlayer {
} }
public boolean addCooldown(ChatChannel channel, long time) { public boolean addCooldown(ChatChannel channel, long time) {
if(channel != null && time > 0) { if (channel != null && time > 0) {
cooldowns.put(channel, time); cooldowns.put(channel, time);
return true; return true;
} }
@ -251,7 +260,7 @@ public class VentureChatPlayer {
} }
public boolean removeCooldown(ChatChannel channel) { public boolean removeCooldown(ChatChannel channel) {
if(channel != null) { if (channel != null) {
cooldowns.remove(channel); cooldowns.remove(channel);
return true; return true;
} }
@ -267,7 +276,7 @@ public class VentureChatPlayer {
} }
public boolean addSpam(ChatChannel channel) { public boolean addSpam(ChatChannel channel) {
if(channel != null) { if (channel != null) {
spam.put(channel, new ArrayList<Long>()); spam.put(channel, new ArrayList<Long>());
return true; return true;
} }
@ -275,7 +284,7 @@ public class VentureChatPlayer {
} }
public void addMessage(ChatMessage message) { public void addMessage(ChatMessage message) {
if(this.messages.size() >= 100) { if (this.messages.size() >= 100) {
this.messages.remove(0); this.messages.remove(0);
} }
this.messages.add(message); this.messages.add(message);

View File

@ -1,9 +1,15 @@
package venture.Aust1n46.chat.model; package venture.Aust1n46.chat.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Data @Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class VentureChatProxyServer { public class VentureChatProxyServer {
private String name; private String name;