mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-21 14:03:54 +02:00
EssentialsChat cleaning.
This commit is contained in:
@@ -2,9 +2,11 @@ package com.earth2me.essentials.chat;
|
|||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.chat.listenerlevel.EssentialsChatPlayerListenerHighest;
|
||||||
|
import com.earth2me.essentials.chat.listenerlevel.EssentialsChatPlayerListenerLowest;
|
||||||
|
import com.earth2me.essentials.chat.listenerlevel.EssentialsChatPlayerListenerNormal;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
@@ -17,8 +19,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
public class EssentialsChat extends JavaPlugin
|
public class EssentialsChat extends JavaPlugin
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||||
private transient Map<String, IEssentialsChatListener> chatListener;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
@@ -35,16 +35,17 @@ public class EssentialsChat extends JavaPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chatListener = new ConcurrentSkipListMap<String, IEssentialsChatListener>();
|
|
||||||
final Map<PlayerChatEvent, String> charges = new HashMap<PlayerChatEvent, String>();
|
final Map<PlayerChatEvent, String> charges = new HashMap<PlayerChatEvent, String>();
|
||||||
|
|
||||||
|
|
||||||
final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatListener);
|
final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess);
|
||||||
final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatListener, charges);
|
final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, charges);
|
||||||
final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatListener, charges);
|
final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, charges);
|
||||||
|
final EssentialsLocalChatEventListener localChatListener = new EssentialsLocalChatEventListener(getServer(), ess);
|
||||||
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerLowest, Priority.Lowest, this);
|
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerLowest, Priority.Lowest, this);
|
||||||
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerNormal, Priority.Normal, this);
|
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerNormal, Priority.Normal, this);
|
||||||
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerHighest, Priority.Highest, this);
|
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerHighest, Priority.Highest, this);
|
||||||
|
pluginManager.registerEvent(Type.CUSTOM_EVENT, localChatListener, Priority.Highest, this);
|
||||||
|
|
||||||
LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
|
LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
|
||||||
}
|
}
|
||||||
@@ -52,19 +53,5 @@ public class EssentialsChat extends JavaPlugin
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
if (chatListener != null)
|
|
||||||
{
|
|
||||||
chatListener.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEssentialsChatListener(final String plugin, final IEssentialsChatListener listener)
|
|
||||||
{
|
|
||||||
chatListener.put(plugin, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEssentialsChatListener removeEssentialsChatListener(final String plugin)
|
|
||||||
{
|
|
||||||
return chatListener.remove(plugin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,11 +5,10 @@ import static com.earth2me.essentials.I18n._;
|
|||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
@@ -20,16 +19,15 @@ public abstract class EssentialsChatPlayer extends PlayerListener
|
|||||||
{
|
{
|
||||||
protected transient IEssentials ess;
|
protected transient IEssentials ess;
|
||||||
protected final static Logger logger = Logger.getLogger("Minecraft");
|
protected final static Logger logger = Logger.getLogger("Minecraft");
|
||||||
protected final transient Map<String, IEssentialsChatListener> listeners;
|
|
||||||
protected final transient Server server;
|
protected final transient Server server;
|
||||||
|
|
||||||
public EssentialsChatPlayer(Server server, IEssentials ess, Map<String, IEssentialsChatListener> listeners)
|
public EssentialsChatPlayer(final Server server, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
this.listeners = listeners;
|
|
||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onPlayerChat(final PlayerChatEvent event)
|
public void onPlayerChat(final PlayerChatEvent event)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -45,13 +43,6 @@ public abstract class EssentialsChatPlayer extends PlayerListener
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (IEssentialsChatListener listener : listeners.values())
|
|
||||||
{
|
|
||||||
if (listener.shouldHandleThisChat(event))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final IUser user = ess.getUser(event.getPlayer());
|
final IUser user = ess.getUser(event.getPlayer());
|
||||||
if (!isAffordableFor(user, command))
|
if (!isAffordableFor(user, command))
|
||||||
@@ -62,16 +53,24 @@ public abstract class EssentialsChatPlayer extends PlayerListener
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChatType(final String message)
|
protected void chargeChat (final PlayerChatEvent event, final Map<PlayerChatEvent, String> charges) {
|
||||||
|
|
||||||
|
final IUser user = ess.getUser(event.getPlayer());
|
||||||
|
|
||||||
|
String charge = charges.remove(event);
|
||||||
|
if (charge == null)
|
||||||
{
|
{
|
||||||
switch (message.charAt(0))
|
charge = "chat";
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
case '!':
|
charge(user, charge);
|
||||||
return "shout";
|
}
|
||||||
case '?':
|
catch (ChargeException e)
|
||||||
return "question";
|
{
|
||||||
default:
|
ess.getCommandHandler().showCommandError(user, charge, e);
|
||||||
return "";
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,47 +105,69 @@ public abstract class EssentialsChatPlayer extends PlayerListener
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendLocalChat(final IUser sender, final long radius, final PlayerChatEvent event)
|
protected void formatChat(final PlayerChatEvent event)
|
||||||
{
|
{
|
||||||
|
final IUser user = ess.getUser(event.getPlayer());
|
||||||
|
if (user.isAuthorized("essentials.chat.color"))
|
||||||
|
{
|
||||||
|
event.setMessage(event.getMessage().replaceAll("&([0-9a-f])", "\u00a7$1"));
|
||||||
|
}
|
||||||
|
event.setFormat(ess.getSettings().getChatFormat(user.getGroup()).replace('&', '\u00a7').replace("\u00a7\u00a7", "&").replace("{DISPLAYNAME}", "%1$s").replace("{GROUP}", user.getGroup()).replace("{MESSAGE}", "%2$s").replace("{WORLDNAME}", user.getWorld().getName()).replace("{SHORTWORLDNAME}", user.getWorld().getName().substring(0, 1).toUpperCase(Locale.ENGLISH)));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getChatType(final String message)
|
||||||
|
{
|
||||||
|
switch (message.charAt(0))
|
||||||
|
{
|
||||||
|
case '!':
|
||||||
|
return "shout";
|
||||||
|
case '?':
|
||||||
|
return "question";
|
||||||
|
//case '@':
|
||||||
|
// return "admin";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handleLocalChat(final Map<PlayerChatEvent, String> charges, final PlayerChatEvent event)
|
||||||
|
{
|
||||||
|
|
||||||
|
long radius = ess.getSettings().getChatRadius();
|
||||||
|
radius *= radius;
|
||||||
|
|
||||||
|
final IUser user = ess.getUser(event.getPlayer());
|
||||||
|
final String chatType = getChatType(event.getMessage());
|
||||||
|
final StringBuilder command = new StringBuilder();
|
||||||
|
command.append("chat");
|
||||||
|
|
||||||
|
if (event.getMessage().length() > 0 && chatType.length() > 0)
|
||||||
|
{
|
||||||
|
command.append("-").append(chatType);
|
||||||
|
final StringBuilder permission = new StringBuilder();
|
||||||
|
permission.append("essentials.chat.").append(chatType);
|
||||||
|
|
||||||
|
final StringBuilder format = new StringBuilder();
|
||||||
|
format.append(chatType).append("Format");
|
||||||
|
|
||||||
|
final StringBuilder errorMsg = new StringBuilder();
|
||||||
|
errorMsg.append("notAllowedTo").append(chatType.substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatType.substring(1));
|
||||||
|
|
||||||
|
if (user.isAuthorized(permission.toString()))
|
||||||
|
{
|
||||||
|
event.setMessage(event.getMessage().substring(1));
|
||||||
|
event.setFormat(_(format.toString(), event.getFormat()));
|
||||||
|
charges.put(event, command.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.sendMessage(_(errorMsg.toString()));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
logger.info(_("localFormat", sender.getName(), event.getMessage()));
|
return;
|
||||||
final Location loc = sender.getLocation();
|
|
||||||
final World world = loc.getWorld();
|
|
||||||
|
|
||||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
String type = "[L]";
|
|
||||||
final IUser user = ess.getUser(onlinePlayer);
|
|
||||||
//TODO: remove reference to op
|
|
||||||
if (user.isIgnoringPlayer(sender.getName()) && !sender.isOp())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!user.equals(sender))
|
|
||||||
{
|
|
||||||
final Location playerLoc = user.getLocation();
|
|
||||||
if (playerLoc.getWorld() != world) { continue; }
|
|
||||||
final double delta = playerLoc.distanceSquared(loc);
|
|
||||||
|
|
||||||
if (delta > radius)
|
|
||||||
{
|
|
||||||
if (user.isAuthorized("essentials.chat.spy"))
|
|
||||||
{
|
|
||||||
type = type.concat("[Spy]");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = String.format(event.getFormat(), type.concat(sender.getDisplayName()), event.getMessage());
|
event.setCancelled(true);
|
||||||
for (IEssentialsChatListener listener : listeners.values())
|
final EssentialsLocalChatEvent localChat = new EssentialsLocalChatEvent(event, radius);
|
||||||
{
|
ess.getServer().getPluginManager().callEvent(localChat);
|
||||||
message = listener.modifyMessage(event, onlinePlayer, message);
|
|
||||||
}
|
|
||||||
user.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,53 +0,0 @@
|
|||||||
package com.earth2me.essentials.chat;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.ChargeException;
|
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
|
||||||
import com.earth2me.essentials.api.IUser;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer
|
|
||||||
{
|
|
||||||
private final transient Map<PlayerChatEvent, String> charges;
|
|
||||||
|
|
||||||
public EssentialsChatPlayerListenerHighest(final Server server,
|
|
||||||
final IEssentials ess,
|
|
||||||
final Map<String, IEssentialsChatListener> listeners,
|
|
||||||
final Map<PlayerChatEvent, String> charges)
|
|
||||||
{
|
|
||||||
super(server, ess, listeners);
|
|
||||||
this.charges = charges;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayerChat(final PlayerChatEvent event)
|
|
||||||
{
|
|
||||||
String charge = charges.remove(event);
|
|
||||||
if (charge == null)
|
|
||||||
{
|
|
||||||
charge = "chat";
|
|
||||||
}
|
|
||||||
if (isAborted(event))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This file should handle charging the user for the action before returning control back
|
|
||||||
*/
|
|
||||||
final IUser user = ess.getUser(event.getPlayer());
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
charge(user, charge);
|
|
||||||
}
|
|
||||||
catch (ChargeException e)
|
|
||||||
{
|
|
||||||
ess.getCommandHandler().showCommandError(user, charge, e);
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,38 +0,0 @@
|
|||||||
package com.earth2me.essentials.chat;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
|
||||||
import com.earth2me.essentials.api.IUser;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer
|
|
||||||
{
|
|
||||||
public EssentialsChatPlayerListenerLowest(final Server server,
|
|
||||||
final IEssentials ess,
|
|
||||||
final Map<String, IEssentialsChatListener> listeners)
|
|
||||||
{
|
|
||||||
super(server, ess, listeners);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayerChat(final PlayerChatEvent event)
|
|
||||||
{
|
|
||||||
if (isAborted(event))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener should apply the general chat formatting only...then return control back the event handler
|
|
||||||
*/
|
|
||||||
final IUser user = ess.getUser(event.getPlayer());
|
|
||||||
if (user.isAuthorized("essentials.chat.color"))
|
|
||||||
{
|
|
||||||
event.setMessage(event.getMessage().replaceAll("&([0-9a-f])", "\u00a7$1"));
|
|
||||||
}
|
|
||||||
event.setFormat(ess.getSettings().getChatFormat(user.getGroup()).replace('&', '\u00a7').replace("\u00a7\u00a7", "&").replace("{DISPLAYNAME}", "%1$s").replace("{GROUP}", user.getGroup()).replace("{MESSAGE}", "%2$s").replace("{WORLDNAME}", user.getWorld().getName()).replace("{SHORTWORLDNAME}", user.getWorld().getName().substring(0, 1).toUpperCase(Locale.ENGLISH)));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
package com.earth2me.essentials.chat;
|
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
|
||||||
import com.earth2me.essentials.api.IUser;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer
|
|
||||||
{
|
|
||||||
private final transient Map<PlayerChatEvent, String> charges;
|
|
||||||
|
|
||||||
public EssentialsChatPlayerListenerNormal(final Server server,
|
|
||||||
final IEssentials ess,
|
|
||||||
final Map<String, IEssentialsChatListener> listeners,
|
|
||||||
final Map<PlayerChatEvent, String> charges)
|
|
||||||
{
|
|
||||||
super(server, ess, listeners);
|
|
||||||
this.charges = charges;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayerChat(final PlayerChatEvent event)
|
|
||||||
{
|
|
||||||
if (isAborted(event))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This file should handle detection of the local chat features... if local chat is enabled, we need to handle
|
|
||||||
* it here
|
|
||||||
*/
|
|
||||||
final String chatType = getChatType(event.getMessage());
|
|
||||||
final StringBuilder command = new StringBuilder();
|
|
||||||
command.append("chat");
|
|
||||||
|
|
||||||
if (chatType.length() > 0)
|
|
||||||
{
|
|
||||||
command.append("-").append(chatType);
|
|
||||||
}
|
|
||||||
long radius = ess.getSettings().getChatRadius();
|
|
||||||
if (radius < 1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
radius *= radius;
|
|
||||||
final IUser user = ess.getUser(event.getPlayer());
|
|
||||||
|
|
||||||
if (event.getMessage().length() > 0 && chatType.length() > 0)
|
|
||||||
{
|
|
||||||
final StringBuilder permission = new StringBuilder();
|
|
||||||
permission.append("essentials.chat.").append(chatType);
|
|
||||||
|
|
||||||
final StringBuilder format = new StringBuilder();
|
|
||||||
format.append(chatType).append("Format");
|
|
||||||
|
|
||||||
final StringBuilder errorMsg = new StringBuilder();
|
|
||||||
errorMsg.append("notAllowedTo").append(chatType.substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatType.substring(1));
|
|
||||||
|
|
||||||
if (user.isAuthorized(permission.toString()))
|
|
||||||
{
|
|
||||||
event.setMessage(event.getMessage().substring(1));
|
|
||||||
event.setFormat(_(format.toString(), event.getFormat()));
|
|
||||||
charges.put(event, command.toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.sendMessage(_(errorMsg.toString()));
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendLocalChat(user, radius, event);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,100 @@
|
|||||||
|
package com.earth2me.essentials.chat;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class EssentialsLocalChatEvent extends Event implements Cancellable
|
||||||
|
{
|
||||||
|
private Player player;
|
||||||
|
private String message;
|
||||||
|
private String format = "<%1$s> %2$s";
|
||||||
|
private long radius;
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private PlayerChatEvent parentEvent = null;
|
||||||
|
|
||||||
|
public EssentialsLocalChatEvent(final Player player, final String message, final String format, final long radius)
|
||||||
|
{
|
||||||
|
super("LocalChat");
|
||||||
|
this.player = player;
|
||||||
|
this.message = message;
|
||||||
|
this.format = format;
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EssentialsLocalChatEvent(final PlayerChatEvent event, final long radius)
|
||||||
|
{
|
||||||
|
this(event.getPlayer(), event.getMessage(), event.getFormat(), radius);
|
||||||
|
this.parentEvent = event;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled()
|
||||||
|
{
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(final boolean cancel)
|
||||||
|
{
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(final String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayer(final Player player)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer()
|
||||||
|
{
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat()
|
||||||
|
{
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormat(final String format)
|
||||||
|
{
|
||||||
|
// Oh for a better way to do this!
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String.format(format, player, message);
|
||||||
|
}
|
||||||
|
catch (RuntimeException ex)
|
||||||
|
{
|
||||||
|
ex.fillInStackTrace();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getRadius()
|
||||||
|
{
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadius(final long radius)
|
||||||
|
{
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerChatEvent getParentEvent()
|
||||||
|
{
|
||||||
|
return parentEvent;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,78 @@
|
|||||||
|
package com.earth2me.essentials.chat;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import com.earth2me.essentials.chat.EssentialsLocalChatEvent;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.CustomEventListener;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class EssentialsLocalChatEventListener extends CustomEventListener implements Listener {
|
||||||
|
|
||||||
|
|
||||||
|
protected transient IEssentials ess;
|
||||||
|
protected final transient Server server;
|
||||||
|
|
||||||
|
public EssentialsLocalChatEventListener(final Server server, final IEssentials ess)
|
||||||
|
{
|
||||||
|
this.ess = ess;
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onLocalChat(final EssentialsLocalChatEvent event) {
|
||||||
|
final Player sender = event.getPlayer();
|
||||||
|
if (event.getRadius() < 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
final Location loc = sender.getLocation();
|
||||||
|
final World world = loc.getWorld();
|
||||||
|
|
||||||
|
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
String type = "[L]";
|
||||||
|
final IUser user = ess.getUser(onlinePlayer);
|
||||||
|
//TODO: remove reference to op
|
||||||
|
if (user.isIgnoringPlayer(sender.getName()) && !sender.isOp())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!user.equals(sender))
|
||||||
|
{
|
||||||
|
final Location playerLoc = user.getLocation();
|
||||||
|
if (playerLoc.getWorld() != world)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final double delta = playerLoc.distanceSquared(loc);
|
||||||
|
|
||||||
|
if (delta > event.getRadius())
|
||||||
|
{
|
||||||
|
if (user.isAuthorized("essentials.chat.spy"))
|
||||||
|
{
|
||||||
|
type = type.concat("[Spy]");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final String message = String.format(event.getFormat(), type.concat(sender.getDisplayName()), event.getMessage());
|
||||||
|
user.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCustomEvent(final Event event) {
|
||||||
|
if (event instanceof EssentialsLocalChatEvent) {
|
||||||
|
onLocalChat((EssentialsLocalChatEvent) event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,12 +0,0 @@
|
|||||||
package com.earth2me.essentials.chat;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
|
||||||
|
|
||||||
|
|
||||||
public interface IEssentialsChatListener
|
|
||||||
{
|
|
||||||
boolean shouldHandleThisChat(PlayerChatEvent event);
|
|
||||||
|
|
||||||
String modifyMessage(PlayerChatEvent event, Player target, String message);
|
|
||||||
}
|
|
@@ -0,0 +1,32 @@
|
|||||||
|
package com.earth2me.essentials.chat.listenerlevel;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.chat.EssentialsChatPlayer;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer
|
||||||
|
{
|
||||||
|
private final transient Map<PlayerChatEvent, String> charges;
|
||||||
|
|
||||||
|
public EssentialsChatPlayerListenerHighest(final Server server,
|
||||||
|
final IEssentials ess,
|
||||||
|
final Map<PlayerChatEvent, String> charges)
|
||||||
|
{
|
||||||
|
super(server, ess);
|
||||||
|
this.charges = charges;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerChat(final PlayerChatEvent event)
|
||||||
|
{
|
||||||
|
if (isAborted(event))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chargeChat(event, charges);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
package com.earth2me.essentials.chat.listenerlevel;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.chat.EssentialsChatPlayer;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer
|
||||||
|
{
|
||||||
|
public EssentialsChatPlayerListenerLowest(final Server server, final IEssentials ess)
|
||||||
|
{
|
||||||
|
super(server, ess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerChat(final PlayerChatEvent event)
|
||||||
|
{
|
||||||
|
if (isAborted(event))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
formatChat(event);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,32 @@
|
|||||||
|
package com.earth2me.essentials.chat.listenerlevel;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.chat.EssentialsChatPlayer;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer
|
||||||
|
{
|
||||||
|
private final transient Map<PlayerChatEvent, String> charges;
|
||||||
|
|
||||||
|
public EssentialsChatPlayerListenerNormal(final Server server,
|
||||||
|
final IEssentials ess,
|
||||||
|
final Map<PlayerChatEvent, String> charges)
|
||||||
|
{
|
||||||
|
super(server, ess);
|
||||||
|
this.charges = charges;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerChat(final PlayerChatEvent event)
|
||||||
|
{
|
||||||
|
if (isAborted(event))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleLocalChat(charges, event);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user