Lombok event.

This commit is contained in:
Aust1n46 2022-04-04 21:01:20 -05:00
parent a0c2501c3e
commit 862c673cd8
2 changed files with 29 additions and 71 deletions

View File

@ -6,34 +6,37 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import lombok.Getter;
import venture.Aust1n46.chat.model.ChatChannel; import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureChatPlayer;
/** /**
* Event called when a message has been sent to a channel. * Event called when a message has been sent to a channel. This event can not be
* This event can not be cancelled. * cancelled.
* *
* @author Aust1n46 * @author Aust1n46
*/ */
@Getter
public class VentureChatEvent extends Event { public class VentureChatEvent extends Event {
private static final boolean ASYNC = true; private static final boolean ASYNC = true;
private static final HandlerList HANDLERS = new HandlerList();
private static final HandlerList handlers = new HandlerList();
private final VentureChatPlayer mcp; private final VentureChatPlayer ventureChatPlayer;
private final String username; private final String username;
private final String playerPrimaryGroup; private final String playerPrimaryGroup;
private final ChatChannel channel; private final ChatChannel channel;
private final Set<Player> recipients; private final Set<Player> recipients;
private final int recipientCount; //For not counting vanished players private final int recipientCount; // For not counting vanished players
private final String format; private final String format;
private final String chat; private final String chat;
private final String globalJSON; private final String globalJSON;
private final int hash; private final int hash;
private final boolean bungee; private final boolean bungee;
public VentureChatEvent(VentureChatPlayer mcp, String username, String playerPrimaryGroup, ChatChannel channel, Set<Player> recipients, int recipientCount, String format, String chat, String globalJSON, int hash, boolean bungee) { public VentureChatEvent(final VentureChatPlayer ventureChatPlayer, final String username, final String playerPrimaryGroup, final ChatChannel channel,
final Set<Player> recipients, final int recipientCount, final String format, final String chat, final String globalJSON, final int hash, final boolean bungee) {
super(ASYNC); super(ASYNC);
this.mcp = mcp; this.ventureChatPlayer = ventureChatPlayer;
this.username = username; this.username = username;
this.playerPrimaryGroup = playerPrimaryGroup; this.playerPrimaryGroup = playerPrimaryGroup;
this.channel = channel; this.channel = channel;
@ -45,62 +48,17 @@ public class VentureChatEvent extends Event {
this.hash = hash; this.hash = hash;
this.bungee = bungee; this.bungee = bungee;
} }
public VentureChatPlayer getMineverseChatPlayer() {
return this.mcp;
}
public String getUsername() {
return this.username;
}
public String getPlayerPrimaryGroup() {
return this.playerPrimaryGroup;
}
public ChatChannel getChannel() {
return this.channel;
}
public Set<Player> getRecipients() {
return this.recipients;
}
//Could be lower than the total number of recipients because vanished players are not counted
public int getRecipientCount() {
return this.recipientCount;
}
public String getFormat() {
return this.format;
}
public String getChat() {
return this.chat;
}
public String getConsoleChat() { public String getConsoleChat() {
return this.format + this.chat; return format + chat;
} }
public String getGlobalJSON() {
return this.globalJSON;
}
public int getHash() {
return this.hash;
}
public boolean isBungee() {
return this.bungee;
}
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return HANDLERS;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return HANDLERS;
} }
} }

View File

@ -511,7 +511,7 @@ public class ChatListener implements Listener {
} }
public void handleVentureChatEvent(VentureChatEvent event) { public void handleVentureChatEvent(VentureChatEvent event) {
VentureChatPlayer mcp = event.getMineverseChatPlayer(); VentureChatPlayer ventureChatPlayer = event.getVentureChatPlayer();
ChatChannel channel = event.getChannel(); ChatChannel channel = event.getChannel();
Set<Player> recipients = event.getRecipients(); Set<Player> recipients = event.getRecipients();
int recipientCount = event.getRecipientCount(); int recipientCount = event.getRecipientCount();
@ -523,21 +523,21 @@ public class ChatListener implements Listener {
boolean bungee = event.isBungee(); boolean bungee = event.isBungee();
if (essentialsDiscordHook && channel.isDefaultchannel()) { if (essentialsDiscordHook && channel.isDefaultchannel()) {
Bukkit.getServicesManager().load(DiscordService.class).sendChatMessage(mcp.getPlayer(), chat); Bukkit.getServicesManager().load(DiscordService.class).sendChatMessage(ventureChatPlayer.getPlayer(), chat);
} }
if(!bungee) { if(!bungee) {
if(databaseService.isEnabled()) { if(databaseService.isEnabled()) {
databaseService.writeVentureChat(mcp.getUuid().toString(), mcp.getName(), "Local", channel.getName(), chat.replace("'", "''"), "Chat"); databaseService.writeVentureChat(ventureChatPlayer.getUuid().toString(), ventureChatPlayer.getName(), "Local", channel.getName(), chat.replace("'", "''"), "Chat");
} }
if(recipientCount == 1) { if(recipientCount == 1) {
if(!plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you.").equals("")) { if(!plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you.").equals("")) {
mcp.getPlayer().sendMessage(FormatUtils.FormatStringAll(plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you."))); ventureChatPlayer.getPlayer().sendMessage(FormatUtils.FormatStringAll(plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you.")));
} }
} }
for(Player p : recipients) { for(Player p : recipients) {
String json = formatService.formatModerationGUI(globalJSON, p, mcp.getName(), channel.getName(), hash); String json = formatService.formatModerationGUI(globalJSON, p, ventureChatPlayer.getName(), channel.getName(), hash);
PacketContainer packet = formatService.createPacketPlayOutChat(json); PacketContainer packet = formatService.createPacketPlayOutChat(json);
formatService.sendPacketPlayOutChat(p, packet); formatService.sendPacketPlayOutChat(p, packet);
} }
@ -550,9 +550,9 @@ public class ChatListener implements Listener {
try { try {
out.writeUTF("Chat"); out.writeUTF("Chat");
out.writeUTF(channel.getName()); out.writeUTF(channel.getName());
out.writeUTF(mcp.getName()); out.writeUTF(ventureChatPlayer.getName());
out.writeUTF(mcp.getUuid().toString()); out.writeUTF(ventureChatPlayer.getUuid().toString());
out.writeBoolean(mcp.isBungeeToggle()); out.writeBoolean(ventureChatPlayer.isBungeeToggle());
out.writeInt(hash); out.writeInt(hash);
out.writeUTF(format); out.writeUTF(format);
out.writeUTF(chat); out.writeUTF(chat);
@ -563,8 +563,8 @@ public class ChatListener implements Listener {
if(plugin.getConfig().getString("loglevel", "info").equals("debug")) { if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
System.out.println(out.size() + " bytes size with json"); System.out.println(out.size() + " bytes size with json");
} }
out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer())); // look into not sending this out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(ventureChatPlayer.getPlayer())); // look into not sending this
final String displayName = mcp.getPlayer().getDisplayName(); final String displayName = ventureChatPlayer.getPlayer().getDisplayName();
out.writeUTF(displayName); out.writeUTF(displayName);
pluginMessageController.sendPluginMessage(byteOutStream); pluginMessageController.sendPluginMessage(byteOutStream);
out.close(); out.close();