summaryrefslogtreecommitdiffstats
path: root/EssentialsChat/src/com/earth2me/essentials/chat
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsChat/src/com/earth2me/essentials/chat')
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java43
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java61
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatWorker.java122
3 files changed, 226 insertions, 0 deletions
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
new file mode 100644
index 000000000..266bd104e
--- /dev/null
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
@@ -0,0 +1,43 @@
+package com.earth2me.essentials.chat;
+
+import com.earth2me.essentials.Essentials;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.bukkit.event.Event.Priority;
+import org.bukkit.event.Event.Type;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
+
+
+public class EssentialsChat extends JavaPlugin
+{
+ private static final Logger logger = Logger.getLogger("Minecraft");
+
+ public EssentialsChat()
+ {
+ super();
+ }
+
+ public void onEnable()
+ {
+ Plugin p = this.getServer().getPluginManager().getPlugin("Essentials");
+ if (p != null) {
+ if (!this.getServer().getPluginManager().isPluginEnabled(p)) {
+ this.getServer().getPluginManager().enablePlugin(p);
+ }
+ }
+ PluginManager pm = getServer().getPluginManager();
+ EssentialsChatPlayerListener playerListener = new EssentialsChatPlayerListener(getServer());
+ pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
+ pm.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Highest, this);
+ if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
+ logger.log(Level.WARNING, "Version mismatch! Please update all Essentials jars to the same version.");
+ }
+ logger.info("Loaded " + this.getDescription().getName() + " build " + this.getDescription().getVersion() + " by " + Essentials.AUTHORS);
+ }
+
+ public void onDisable()
+ {
+ }
+}
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
new file mode 100644
index 000000000..e351cc865
--- /dev/null
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
@@ -0,0 +1,61 @@
+package com.earth2me.essentials.chat;
+
+import com.earth2me.essentials.Essentials;
+import org.bukkit.Server;
+import org.bukkit.event.player.*;
+
+
+public class EssentialsChatPlayerListener extends PlayerListener
+{
+ private final Server server;
+
+ public EssentialsChatPlayerListener(Server server)
+ {
+ this.server = server;
+ }
+
+ @Override
+ @SuppressWarnings("CallToThreadDumpStack")
+ public void onPlayerJoin(PlayerJoinEvent event)
+ {
+ try
+ {
+ Essentials.loadClasses();
+ EssentialsChatWorker.onPlayerJoin(server, event);
+ }
+ catch (Throwable ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Override
+ @SuppressWarnings("CallToThreadDumpStack")
+ public void onPlayerRespawn(PlayerRespawnEvent event)
+ {
+ try
+ {
+ Essentials.loadClasses();
+ EssentialsChatWorker.onPlayerRespawn(server, event);
+ }
+ catch (Throwable ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Override
+ @SuppressWarnings("CallToThreadDumpStack")
+ public void onPlayerChat(PlayerChatEvent event)
+ {
+ try
+ {
+ Essentials.loadClasses();
+ EssentialsChatWorker.onPlayerChat(server, event);
+ }
+ catch (Throwable ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatWorker.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatWorker.java
new file mode 100644
index 000000000..e11504259
--- /dev/null
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatWorker.java
@@ -0,0 +1,122 @@
+package com.earth2me.essentials.chat;
+
+import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.User;
+import com.nijikokun.bukkit.Permissions.Permissions;
+import java.util.logging.Logger;
+import org.bukkit.Location;
+import org.bukkit.Server;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerChatEvent;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+
+
+public class EssentialsChatWorker
+{
+ private static final Logger logger = Logger.getLogger("Minecraft");
+
+ public static void onPlayerRespawn(Server server, PlayerRespawnEvent event)
+ {
+ User user = User.get(event.getPlayer());
+ updateDisplayName(user);
+ }
+
+ public static void onPlayerJoin(Server server, PlayerEvent event)
+ {
+ User user = User.get(event.getPlayer());
+ updateDisplayName(user);
+ }
+
+ private static void updateDisplayName(User user)
+ {
+ try
+ {
+ String group = user.getGroup();
+ try
+ {
+ String prefix = Permissions.Security.getGroupPrefix(user.getWorld().getName(), group).replace('&', '§').replace("{WORLDNAME}", user.getWorld().getName());
+ String suffix = Permissions.Security.getGroupSuffix(user.getWorld().getName(), group).replace('&', '§').replace("{WORLDNAME}", user.getWorld().getName());
+ user.setDisplayName(prefix + user.getNick() + suffix + (suffix.endsWith("§f") ? "" : "§f"));
+ }
+ catch (Throwable ex)
+ {
+ logger.warning("Missing a prefix or suffix for " + group);
+ }
+ }
+ catch (Throwable ex)
+ {
+ logger.warning("Missing Permissions/GroupManager; chat prefixes/suffixes will be disabled.");
+ }
+ }
+
+ public static void onPlayerChat(Server server, PlayerChatEvent event)
+ {
+ User user = User.get(event.getPlayer());
+ updateDisplayName(user);
+
+ if (user.isAuthorized("essentials.chat.color"))
+ event.setMessage(event.getMessage().replaceAll("&([0-9a-f])", "§$1"));
+
+ event.setFormat(Essentials.getSettings().getChatFormat(user.getGroup())
+ .replace('&', '§')
+ .replace("§§", "&")
+ .replace("{DISPLAYNAME}", "%1$s")
+ .replace("{GROUP}", user.getGroup())
+ .replace("{MESSAGE}", "%2$s")
+ .replace("{WORLDNAME}", user.getWorld().getName()));
+
+ int radius = Essentials.getSettings().getChatRadius();
+ if (radius < 1) return;
+
+ if (event.getMessage().startsWith("!") && event.getMessage().length() > 1)
+ {
+ if (user.isAuthorized("essentials.chat.shout"))
+ {
+ event.setMessage(event.getMessage().substring(1));
+ event.setFormat("§7[Shout]§f " + event.getFormat());
+ return;
+ }
+ user.sendMessage("§cYou are not authorized to shout.");
+ event.setCancelled(true);
+ return;
+ }
+
+ if (event.getMessage().startsWith("?") && event.getMessage().length() > 1)
+ {
+ if (user.isAuthorized("essentials.chat.question"))
+ {
+ event.setMessage(event.getMessage().substring(1));
+ event.setFormat("§7[Question]§f " + event.getFormat());
+ return;
+ }
+ user.sendMessage("§cYou are not authorized to use question.");
+ event.setCancelled(true);
+ return;
+ }
+
+ event.setCancelled(true);
+ logger.info("Local: <" + user.getName() + "> " + event.getMessage());
+
+ Location loc = user.getLocation();
+ int x = loc.getBlockX();
+ int y = loc.getBlockY();
+ int z = loc.getBlockZ();
+
+ for (Player p : server.getOnlinePlayers())
+ {
+ User u = User.get(p);
+ if (u != user && !u.isAuthorized("essentials.chat.spy"))
+ {
+ Location l = u.getLocation();
+ int dx = Math.abs(x - l.getBlockX());
+ int dy = Math.abs(y - l.getBlockY());
+ int dz = Math.abs(z - l.getBlockZ());
+ int delta = dx + dy + dz;
+ if (delta > radius) continue;
+ }
+
+ u.sendMessage(String.format(event.getFormat(), user.getDisplayName(), event.getMessage()));
+ }
+ }
+}