mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-03 06:28:57 +00:00
Fix events not being asynchronous.
This commit is contained in:
1 parent
dc4fef858e
commit
1a4ecba190
2 files changed
+29
-30
No files matched your search
@@ -1,17 +1,7 @@
|
|||||||
package com.palmergames.bukkit.TownyChat.channels;
|
package com.palmergames.bukkit.TownyChat.channels;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.TownyChat.Chat;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.dynmap.DynmapAPI;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
import com.palmergames.bukkit.TownyChat.Chat;
|
||||||
import com.palmergames.bukkit.TownyChat.CraftIRCHandler;
|
import com.palmergames.bukkit.TownyChat.CraftIRCHandler;
|
||||||
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
||||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||||
@@ -25,6 +15,15 @@ import com.palmergames.bukkit.towny.object.Resident;
|
|||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
import com.palmergames.bukkit.util.Colors;
|
import com.palmergames.bukkit.util.Colors;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.dynmap.DynmapAPI;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class StandardChannel extends Channel {
|
public class StandardChannel extends Channel {
|
||||||
|
|
||||||
@@ -75,7 +74,7 @@ public class StandardChannel extends Channel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Format = ChatSettings.getRelevantFormatGroup(player).getTOWN();
|
Format = ChatSettings.getRelevantFormatGroup(player).getTOWN();
|
||||||
recipients = new HashSet<Player>(findRecipients(player, TownyUniverse.getOnlinePlayers(town)));
|
recipients = new HashSet<>(findRecipients(player, TownyUniverse.getOnlinePlayers(town)));
|
||||||
recipients = checkSpying(recipients);
|
recipients = checkSpying(recipients);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -85,23 +84,23 @@ public class StandardChannel extends Channel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Format = ChatSettings.getRelevantFormatGroup(player).getNATION();
|
Format = ChatSettings.getRelevantFormatGroup(player).getNATION();
|
||||||
recipients = new HashSet<Player>(findRecipients(player, TownyUniverse.getOnlinePlayers(nation)));
|
recipients = new HashSet<>(findRecipients(player, TownyUniverse.getOnlinePlayers(nation)));
|
||||||
recipients = checkSpying(recipients);
|
recipients = checkSpying(recipients);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
Format = ChatSettings.getRelevantFormatGroup(player).getDEFAULT();
|
Format = ChatSettings.getRelevantFormatGroup(player).getDEFAULT();
|
||||||
recipients = new HashSet<Player>(findRecipients(player, new ArrayList<Player>(event.getRecipients())));
|
recipients = new HashSet<>(findRecipients(player, new ArrayList<>(event.getRecipients())));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLOBAL:
|
case GLOBAL:
|
||||||
Format = ChatSettings.getRelevantFormatGroup(player).getGLOBAL();
|
Format = ChatSettings.getRelevantFormatGroup(player).getGLOBAL();
|
||||||
recipients = new HashSet<Player>(findRecipients(player, new ArrayList<Player>(event.getRecipients())));
|
recipients = new HashSet<>(findRecipients(player, new ArrayList<>(event.getRecipients())));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRIVATE:
|
case PRIVATE:
|
||||||
Format = ChatSettings.getRelevantFormatGroup(player).getGLOBAL();
|
Format = ChatSettings.getRelevantFormatGroup(player).getGLOBAL();
|
||||||
recipients = new HashSet<Player>(findRecipients(player, new ArrayList<Player>(event.getRecipients())));
|
recipients = new HashSet<>(findRecipients(player, new ArrayList<>(event.getRecipients())));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +180,7 @@ public class StandardChannel extends Channel {
|
|||||||
* -1 = no limit
|
* -1 = no limit
|
||||||
* 0 = same world
|
* 0 = same world
|
||||||
* any positive value = distance in blocks
|
* any positive value = distance in blocks
|
||||||
*
|
*
|
||||||
* @param player1
|
* @param player1
|
||||||
* @param player2
|
* @param player2
|
||||||
* @param range
|
* @param range
|
||||||
@@ -206,15 +205,15 @@ public class StandardChannel extends Channel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile a list of valid recipients for this message.
|
* Compile a list of valid recipients for this message.
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* @param list
|
* @param list
|
||||||
* @return Set containing a list of players for this message.
|
* @return Set containing a list of players for this message.
|
||||||
*/
|
*/
|
||||||
private Set<Player> findRecipients(Player sender, List<Player> list) {
|
private Set<Player> findRecipients(Player sender, List<Player> list) {
|
||||||
|
|
||||||
Set<Player> recipients = new HashSet<Player>();
|
Set<Player> recipients = new HashSet<>();
|
||||||
Boolean bEssentials = plugin.getTowny().isEssentials();
|
boolean bEssentials = plugin.getTowny().isEssentials();
|
||||||
String sendersName = sender.getName();
|
String sendersName = sender.getName();
|
||||||
|
|
||||||
// Compile the list of recipients
|
// Compile the list of recipients
|
||||||
@@ -257,20 +256,20 @@ public class StandardChannel extends Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((recipients.size() <= 1) && (ChatSettings.isUsingAloneMessage()))
|
if ((recipients.size() <= 1) && (ChatSettings.isUsingAloneMessage()))
|
||||||
sender.sendMessage(ChatSettings.getUsingAloneMessageString());
|
sender.sendMessage(ChatSettings.getUsingAloneMessageString());
|
||||||
|
|
||||||
return recipients;
|
return recipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all spying players to the recipients list.
|
* Add all spying players to the recipients list.
|
||||||
*
|
*
|
||||||
* @param recipients
|
* @param recipients
|
||||||
* @return new recipients including spying.
|
* @return new recipients including spying.
|
||||||
*/
|
*/
|
||||||
private Set<Player> checkSpying(Set<Player> recipients) {
|
private Set<Player> checkSpying(Set<Player> recipients) {
|
||||||
|
|
||||||
|
|
||||||
// Compile the list of recipients with spy perms
|
// Compile the list of recipients with spy perms
|
||||||
for (Player test : plugin.getServer().getOnlinePlayers()) {
|
for (Player test : plugin.getServer().getOnlinePlayers()) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.palmergames.bukkit.TownyChat.events;
|
package com.palmergames.bukkit.TownyChat.events;
|
||||||
|
|
||||||
import java.util.Set;
|
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
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 org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
|
||||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
import java.util.Set;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allows other plugins to hook into a chat message being accepted into any of the channels
|
* Allows other plugins to hook into a chat message being accepted into any of the channels
|
||||||
@@ -29,11 +28,12 @@ import com.palmergames.bukkit.TownyChat.channels.Channel;
|
|||||||
*/
|
*/
|
||||||
public class AsyncChatHookEvent extends Event {
|
public class AsyncChatHookEvent extends Event {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
protected AsyncPlayerChatEvent event = null;
|
protected AsyncPlayerChatEvent event;
|
||||||
protected boolean changed = false;
|
protected boolean changed;
|
||||||
protected Channel channel=null;
|
protected Channel channel;
|
||||||
|
|
||||||
public AsyncChatHookEvent(AsyncPlayerChatEvent event, Channel channel) {
|
public AsyncChatHookEvent(AsyncPlayerChatEvent event, Channel channel) {
|
||||||
|
super(true);
|
||||||
this.event = event;
|
this.event = event;
|
||||||
this.changed = false;
|
this.changed = false;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
@@ -98,7 +98,7 @@ public class AsyncChatHookEvent extends Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
changed = (cancel == true);
|
changed = (cancel);
|
||||||
event.setCancelled(cancel);
|
event.setCancelled(cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user