Skip to content

Commit

Permalink
Added option to not launch AsyncChat for specific channels
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioZumbi12 committed Aug 6, 2024
1 parent 9fcfe6a commit 15ae2cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class UCChannel {
private List<String> members = new ArrayList<>();

@Deprecated()
public UCChannel(String name, String alias, boolean worlds, int dist, String color, String builder, boolean focus, boolean receiversMsg, double cost, boolean isbungee, boolean hand, boolean ownBuilder, boolean isAlias, String aliasSender, String aliasCmd, List<String> availableWorlds, String ddchannel, String ddmode, String ddmcformat, String mcddformat, String ddhover, boolean ddallowcmds, boolean lock, boolean dynenable, String mcdynformat, String dynmcformat) {
public UCChannel(String name, String alias, boolean worlds, int dist, String color, String builder, boolean focus, boolean receiversMsg, double cost, boolean isbungee, boolean hand, boolean ownBuilder, boolean isAlias, String aliasSender, String aliasCmd, List<String> availableWorlds, String ddchannel, String ddmode, String ddmcformat, String mcddformat, String ddhover, boolean ddallowcmds, boolean lock, boolean dynenable, String mcdynformat, String dynmcformat, boolean chatEvent) {
addDefaults();
properties.put("name", name);
properties.put("alias", alias);
Expand Down Expand Up @@ -82,6 +82,8 @@ public UCChannel(String name, String alias, boolean worlds, int dist, String col
properties.put("dynmap.enable", dynenable);
properties.put("dynmap.ingame-to-web", mcdynformat);
properties.put("dynmap.web-to-ingame", dynmcformat);

properties.put("compat.cancel-chat-event", chatEvent);
}

public UCChannel(String name, String alias, String color) {
Expand Down Expand Up @@ -133,6 +135,7 @@ private void addDefaults() {
properties.put("discord.format-to-dd", ":regional_indicator_g: **{sender}**: {message}");

properties.put("dynmap.enable", false);
properties.put("compat.cancel-chat-event", false);
}

public Properties getProperties() {
Expand All @@ -157,6 +160,10 @@ public void setProperty(String key, String value) {
}
}

public boolean compatCancelChatEvent(){
return (boolean) properties.get("compat.cancel-chat-event");
}

public boolean useDynmap() {
return (boolean) properties.get("dynmap.enable");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,15 +865,15 @@ public void onChat(AsyncPlayerChatEvent e) {
if (ch.getCharAlias().length() == rawMsg.length() && rawMsg.equalsIgnoreCase(ch.getCharAlias())) {
addPlayerToChannel(ch, p);
e.setCancelled(true);
AsyncPlayerChatEvent newEvent = new AsyncPlayerChatEvent(true, e.getPlayer(), e.getMessage(), new HashSet<>());
Bukkit.getPluginManager().callEvent(newEvent);
}
if (rawMsg.startsWith(ch.getCharAlias())) {
String msg = rawMsg.substring(ch.getCharAlias().length());
sendMessageToPlayer(ch, p, e.getMessage().split(" "), msg);
e.setCancelled(true);
AsyncPlayerChatEvent newEvent = new AsyncPlayerChatEvent(true, e.getPlayer(), e.getMessage(), new HashSet<>());
Bukkit.getPluginManager().callEvent(newEvent);
if (!ch.compatCancelChatEvent()){
AsyncPlayerChatEvent newEvent = new AsyncPlayerChatEvent(true, e.getPlayer(), e.getMessage(), new HashSet<>());
Bukkit.getPluginManager().callEvent(newEvent);
}
}
}
if (e.isCancelled()) return;
Expand All @@ -882,8 +882,6 @@ public void onChat(AsyncPlayerChatEvent e) {
Player tellReceiver = UChat.get().getServer().getPlayer(UChat.get().tellPlayers.get(p.getName()));
sendTell(p, tellReceiver, e.getMessage());
e.setCancelled(true);
AsyncPlayerChatEvent newEvent = new AsyncPlayerChatEvent(true, e.getPlayer(), e.getMessage(), new HashSet<>());
Bukkit.getPluginManager().callEvent(newEvent);
} else if (UChat.get().command.contains(p.getName()) || UChat.get().command.contains("CONSOLE")) {
if (UChat.get().tempTellPlayers.containsKey("CONSOLE")) {
String recStr = UChat.get().tempTellPlayers.get("CONSOLE");
Expand Down Expand Up @@ -912,8 +910,6 @@ public void onChat(AsyncPlayerChatEvent e) {
UChat.get().command.remove(p.getName());
}
e.setCancelled(true);
AsyncPlayerChatEvent newEvent = new AsyncPlayerChatEvent(true, e.getPlayer(), e.getMessage(), new HashSet<>());
Bukkit.getPluginManager().callEvent(newEvent);
} else {
UCChannel ch = UChat.get().getPlayerChannel(p);
if (UChat.get().tempChannels.containsKey(p.getName()) && !UChat.get().tempChannels.get(p.getName()).equals(ch.getAlias())) {
Expand All @@ -929,8 +925,6 @@ public void onChat(AsyncPlayerChatEvent e) {
UChat.get().getLang().sendMessage(p, "channel.muted");
}
e.setCancelled(true);
AsyncPlayerChatEvent newEvent = new AsyncPlayerChatEvent(true, e.getPlayer(), e.getMessage(), new HashSet<>());
Bukkit.getPluginManager().callEvent(newEvent);
}

if (ch.isCmdAlias()) {
Expand All @@ -947,8 +941,10 @@ public void onChat(AsyncPlayerChatEvent e) {
UCMessages.sendFancyMessage(e.getFormat().split(","), e.getMessage(), ch, p, null);
}
e.setCancelled(true);
AsyncPlayerChatEvent newEvent = new AsyncPlayerChatEvent(true, e.getPlayer(), e.getMessage(), new HashSet<>());
Bukkit.getPluginManager().callEvent(newEvent);
if (!ch.compatCancelChatEvent()){
AsyncPlayerChatEvent newEvent = new AsyncPlayerChatEvent(true, e.getPlayer(), e.getMessage(), new HashSet<>());
Bukkit.getPluginManager().callEvent(newEvent);
}
}
}

Expand Down

0 comments on commit 15ae2cc

Please sign in to comment.