From 71c5e8c54eb51e8eb8176f807a6205abdd02f5ae Mon Sep 17 00:00:00 2001 From: Zenexer Date: Wed, 30 Mar 2011 04:03:21 +0000 Subject: 2.1 prerelease, part 2 of 3 git-svn-id: https://svn.java.net/svn/essentials~svn/trunk2.1@1015 e251c2fe-e539-e718-e476-b85c1f46cddb --- EssentialsChat/build.xml | 76 ++ EssentialsChat/nbproject/build-impl.xml | 1072 ++++++++++++++++++++ EssentialsChat/nbproject/genfiles.properties | 8 + .../nbproject/private/private.properties | 1 + EssentialsChat/nbproject/project.properties | 79 ++ EssentialsChat/nbproject/project.xml | 28 + .../earth2me/essentials/chat/EssentialsChat.java | 43 + .../chat/EssentialsChatPlayerListener.java | 61 ++ .../essentials/chat/EssentialsChatWorker.java | 122 +++ EssentialsChat/src/plugin.yml | 8 + 10 files changed, 1498 insertions(+) create mode 100644 EssentialsChat/build.xml create mode 100644 EssentialsChat/nbproject/build-impl.xml create mode 100644 EssentialsChat/nbproject/genfiles.properties create mode 100644 EssentialsChat/nbproject/private/private.properties create mode 100644 EssentialsChat/nbproject/project.properties create mode 100644 EssentialsChat/nbproject/project.xml create mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java create mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java create mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatWorker.java create mode 100644 EssentialsChat/src/plugin.yml (limited to 'EssentialsChat') diff --git a/EssentialsChat/build.xml b/EssentialsChat/build.xml new file mode 100644 index 000000000..ed22cfe0c --- /dev/null +++ b/EssentialsChat/build.xml @@ -0,0 +1,76 @@ + + ]> + + + + + + + + + + Builds, tests, and runs the project EssentialsChat. + + &buildinc; + + diff --git a/EssentialsChat/nbproject/build-impl.xml b/EssentialsChat/nbproject/build-impl.xml new file mode 100644 index 000000000..e0b698395 --- /dev/null +++ b/EssentialsChat/nbproject/build-impl.xml @@ -0,0 +1,1072 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EssentialsChat/nbproject/genfiles.properties b/EssentialsChat/nbproject/genfiles.properties new file mode 100644 index 000000000..e53628d44 --- /dev/null +++ b/EssentialsChat/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7c7f517b +build.xml.script.CRC32=71afd555 +build.xml.stylesheet.CRC32=28e38971@1.38.2.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7c7f517b +nbproject/build-impl.xml.script.CRC32=c24d2db5 +nbproject/build-impl.xml.stylesheet.CRC32=19debb58@1.42.1.45 diff --git a/EssentialsChat/nbproject/private/private.properties b/EssentialsChat/nbproject/private/private.properties new file mode 100644 index 000000000..94183418a --- /dev/null +++ b/EssentialsChat/nbproject/private/private.properties @@ -0,0 +1 @@ +user.properties.file=C:\\Users\\Paul\\.netbeans\\7.0beta2\\build.properties diff --git a/EssentialsChat/nbproject/project.properties b/EssentialsChat/nbproject/project.properties new file mode 100644 index 000000000..315a26576 --- /dev/null +++ b/EssentialsChat/nbproject/project.properties @@ -0,0 +1,79 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=EssentialsChat +application.vendor=Paul +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/EssentialsChat.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=../lib/craftbukkit-0.0.1-SNAPSHOT.jar +file.reference.Permissions.jar=..\\lib\\Permissions.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\ + ${file.reference.Permissions.jar}:\ + ${reference.Essentials.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +project.Essentials=../Essentials +reference.Essentials.jar=${project.Essentials}/dist/Essentials.jar +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/EssentialsChat/nbproject/project.xml b/EssentialsChat/nbproject/project.xml new file mode 100644 index 000000000..da40bbe42 --- /dev/null +++ b/EssentialsChat/nbproject/project.xml @@ -0,0 +1,28 @@ + + + org.netbeans.modules.java.j2seproject + + + EssentialsChat + + + + + + + + + ..\lib\nblibraries.properties + + + + Essentials + jar + + jar + clean + jar + + + + 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())); + } + } +} diff --git a/EssentialsChat/src/plugin.yml b/EssentialsChat/src/plugin.yml new file mode 100644 index 000000000..b4f7bb9c9 --- /dev/null +++ b/EssentialsChat/src/plugin.yml @@ -0,0 +1,8 @@ +# This determines the command prefix when there are conflicts (/name:home, /name:help, etc.) +name: EssentialsChat +main: com.earth2me.essentials.chat.EssentialsChat +# Note to developers: This next line cannot change, or the automatic versioning system will break. +version: TeamCity +website: http://www.earth2me.net:8001/ +description: Provides chat control features for Essentials. Requires Permissions. +authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo] \ No newline at end of file -- cgit v1.2.3