diff options
Diffstat (limited to 'EssentialsSpawn')
10 files changed, 236 insertions, 66 deletions
diff --git a/EssentialsSpawn/nbproject/build-impl.xml b/EssentialsSpawn/nbproject/build-impl.xml index 1f4e8e9fb..cf349590c 100644 --- a/EssentialsSpawn/nbproject/build-impl.xml +++ b/EssentialsSpawn/nbproject/build-impl.xml @@ -20,10 +20,10 @@ is divided into following sections: --> <project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="EssentialsSpawn-impl"> - <fail message="Please build using Ant 1.7.1 or higher."> + <fail message="Please build using Ant 1.8.0 or higher."> <condition> <not> - <antversion atleast="1.7.1"/> + <antversion atleast="1.8.0"/> </not> </condition> </fail> @@ -223,6 +223,7 @@ is divided into following sections: <property name="javac.fork" value="${jdkBug6558476}"/> <property name="jar.index" value="false"/> <property name="jar.index.metainf" value="${jar.index}"/> + <property name="copylibs.rebase" value="true"/> <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/> </target> <target name="-post-init"> @@ -409,6 +410,7 @@ is divided into following sections: <property environment="env"/> <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/> <java classname="@{classname}" dir="${profiler.info.dir}" fork="true" jvm="${profiler.info.jvm}"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> <jvmarg value="${profiler.info.jvmargs.agent}"/> <jvmarg line="${profiler.info.jvmargs}"/> <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/> @@ -539,7 +541,7 @@ is divided into following sections: </chainedmapper> </pathconvert> <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/> - <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" runtimeclasspath="${run.classpath.without.build.classes.dir}"> + <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}"> <fileset dir="${build.classes.dir}"/> <manifest> <attribute name="Class-Path" value="${jar.classpath}"/> @@ -871,6 +873,14 @@ is divided into following sections: --> <target depends="init" if="have.sources" name="-javadoc-build"> <mkdir dir="${dist.javadoc.dir}"/> + <condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}"> + <and> + <isset property="endorsed.classpath.cmd.line.arg"/> + <not> + <equals arg1="${endorsed.classpath.cmd.line.arg}" arg2=""/> + </not> + </and> + </condition> <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}"> <classpath> <path path="${javac.classpath}"/> @@ -882,6 +892,7 @@ is divided into following sections: <include name="**/*.java"/> <exclude name="*.java"/> </fileset> + <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/> </javadoc> <copy todir="${dist.javadoc.dir}"> <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}"> diff --git a/EssentialsSpawn/nbproject/genfiles.properties b/EssentialsSpawn/nbproject/genfiles.properties index bf3a6888d..15d04622b 100644 --- a/EssentialsSpawn/nbproject/genfiles.properties +++ b/EssentialsSpawn/nbproject/genfiles.properties @@ -4,5 +4,5 @@ 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=e7b96939 -nbproject/build-impl.xml.script.CRC32=fd1c94f8 -nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45 +nbproject/build-impl.xml.script.CRC32=f45f4172 +nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.1.46 diff --git a/EssentialsSpawn/nbproject/pmd.settings b/EssentialsSpawn/nbproject/pmd.settings new file mode 100644 index 000000000..6a34e356c --- /dev/null +++ b/EssentialsSpawn/nbproject/pmd.settings @@ -0,0 +1 @@ +DoNotUseThreads diff --git a/EssentialsSpawn/nbproject/project.properties b/EssentialsSpawn/nbproject/project.properties index 27fa91493..f78c2be3d 100644 --- a/EssentialsSpawn/nbproject/project.properties +++ b/EssentialsSpawn/nbproject/project.properties @@ -28,6 +28,7 @@ auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blank auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blankLinesBeforeClass=2 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement=NEW_LINE auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs=false +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.importGroupsOrder=* auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width=4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indentCasesFromSwitch=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement=NEW_LINE @@ -36,6 +37,7 @@ auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.place auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeElseOnNewLine=true auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeFinallyOnNewLine=true auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeWhileOnNewLine=true +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.separateImportGroups=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceAfterTypeCast=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaces-per-tab=4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.tab-size=4 @@ -61,12 +63,12 @@ dist.jar=${dist.dir}/EssentialsSpawn.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= -file.reference.bukkit-0.0.1-SNAPSHOT.jar=../lib/bukkit-0.0.1-SNAPSHOT.jar +file.reference.bukkit.jar=../lib/bukkit.jar includes=** jar.compress=true javac.classpath=\ ${reference.Essentials.jar}:\ - ${file.reference.bukkit-0.0.1-SNAPSHOT.jar} + ${file.reference.bukkit.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false @@ -77,8 +79,7 @@ javac.target=1.6 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir}:\ - ${libs.junit.classpath}:\ - ${libs.junit_4.classpath} + ${libs.junit_4.10.classpath} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java index 9ffc1c3f0..c6c89a20d 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.spawn; -import org.bukkit.Server; +import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; import com.earth2me.essentials.commands.EssentialsCommand; +import org.bukkit.Server; public class Commandsetspawn extends EssentialsCommand @@ -14,10 +14,10 @@ public class Commandsetspawn extends EssentialsCommand } @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception + public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final String group = args.length > 0 ? getFinalArg(args, 0) : "default"; - ess.getSpawn().setSpawn(user.getLocation(), group); - user.sendMessage(Util.format("spawnSet", group)); + ((SpawnStorage)module).setSpawn(user.getLocation(), group); + user.sendMessage(_("spawnSet", group)); } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index b3ade7634..6335d6c69 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -1,9 +1,14 @@ package com.earth2me.essentials.spawn; +import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.commands.EssentialsCommand; +import com.earth2me.essentials.commands.NotEnoughArgumentsException; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandspawn extends EssentialsCommand @@ -14,10 +19,42 @@ public class Commandspawn extends EssentialsCommand } @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception - { + public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + { final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); - user.getTeleport().respawn(ess.getSpawn(), charge); + if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) + { + final User otherUser = getPlayer(server, args, 0); + respawn(otherUser, null); + if (!otherUser.equals(user)) + { + otherUser.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn")); + user.sendMessage(_("teleporting")); + } + } + else + { + respawn(user, null); + } + } + + @Override + protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + { + if (args.length < 1) + { + throw new NotEnoughArgumentsException(); + } + final User user = getPlayer(server, args, 0); + respawn(user, null); + user.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn")); + sender.sendMessage(_("teleporting")); + } + + private void respawn (final User user, final Trade charge) throws Exception { + final SpawnStorage spawns = (SpawnStorage)this.module; + final Location spawn = spawns.getSpawn(user.getGroup()); + user.getTeleport().teleport(spawn, charge, TeleportCause.COMMAND); } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java index 1bae3fed3..813220a16 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -1,10 +1,11 @@ package com.earth2me.essentials.spawn; - +import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.IEssentialsModule; import java.util.logging.Level; import java.util.logging.Logger; +import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.event.Event.Priority; @@ -15,23 +16,32 @@ import org.bukkit.plugin.java.JavaPlugin; public class EssentialsSpawn extends JavaPlugin { - private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private static final Logger LOGGER = Bukkit.getLogger(); private transient IEssentials ess; + private transient SpawnStorage spawns; public void onEnable() { final PluginManager pluginManager = getServer().getPluginManager(); ess = (IEssentials)pluginManager.getPlugin("Essentials"); - final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess); - pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, Priority.Low, this); - pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Low, this); - - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { - LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll")); + LOGGER.log(Level.WARNING, _("versionMismatchAll")); + } + if (!ess.isEnabled()) + { + this.setEnabled(false); + return; } - LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); + + spawns = new SpawnStorage(ess); + ess.addReloadListener(spawns); + + final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns); + pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, ess.getSettings().getRespawnPriority(), this); + pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, ess.getSettings().getRespawnPriority(), this); + + LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); } public void onDisable() @@ -39,8 +49,9 @@ public class EssentialsSpawn extends JavaPlugin } @Override - public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) + public boolean onCommand(final CommandSender sender, final Command command, + final String commandLabel, final String[] args) { - return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials."); + return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials.", spawns); } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index 459eee60a..81e8f6e9e 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -1,52 +1,54 @@ package com.earth2me.essentials.spawn; +import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; import java.util.logging.Level; import java.util.logging.Logger; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class EssentialsSpawnPlayerListener extends PlayerListener { private final transient IEssentials ess; + private final transient SpawnStorage spawns; + private static final Logger LOGGER = Bukkit.getLogger(); - public EssentialsSpawnPlayerListener(IEssentials ess) + public EssentialsSpawnPlayerListener(final IEssentials ess, final SpawnStorage spawns) { + super(); this.ess = ess; + this.spawns = spawns; } @Override public void onPlayerRespawn(final PlayerRespawnEvent event) - { + { final User user = ess.getUser(event.getPlayer()); - try + if (ess.getSettings().getRespawnAtHome()) { - if (ess.getSettings().getRespawnAtHome()) + Location home = user.getHome(user.getLocation()); + if (home == null) + { + home = user.getBedSpawnLocation(); + } + if (home != null) { - Location home = user.getHome(user.getLocation()); - if (home == null) - { - throw new Exception(); - } event.setRespawnLocation(home); return; } } - catch (Throwable ex) - { - } - Location spawn = ess.getSpawn().getSpawn(user.getGroup()); - if (spawn == null) + final Location spawn = spawns.getSpawn(user.getGroup()); + if (spawn != null) { - return; + event.setRespawnLocation(spawn); } - event.setRespawnLocation(spawn); } @Override @@ -54,32 +56,49 @@ public class EssentialsSpawnPlayerListener extends PlayerListener { final User user = ess.getUser(event.getPlayer()); - if (!user.isNew()) + if (user.hasPlayedBefore()) { + LOGGER.log(Level.FINE, "Old player join"); return; - } - user.setNew(false); + } if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn())) { - ess.scheduleSyncDelayedTask(new Runnable() - { - public void run() - { - try - { - user.getTeleport().now(ess.getSpawn().getSpawn(ess.getSettings().getNewbieSpawn())); - } - catch (Exception ex) - { - Logger.getLogger("Minecraft").log(Level.WARNING, Util.i18n("teleportNewPlayerError"), ex); - } - } - }); + ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L); } if (ess.getSettings().getAnnounceNewPlayers()) { ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user)); } + + LOGGER.log(Level.FINE, "New player join"); + } + + + private class NewPlayerTeleport implements Runnable + { + private final transient User user; + + public NewPlayerTeleport(final User user) + { + this.user = user; + } + + @Override + public void run() + { + try + { + Location spawn = spawns.getSpawn(ess.getSettings().getNewbieSpawn()); + if (spawn != null) + { + user.getTeleport().now(spawn, false, TeleportCause.PLUGIN); + } + } + catch (Exception ex) + { + Bukkit.getLogger().log(Level.WARNING, _("teleportNewPlayerError"), ex); + } + } } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java new file mode 100644 index 000000000..088ee9052 --- /dev/null +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java @@ -0,0 +1,90 @@ +package com.earth2me.essentials.spawn; + +import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.IEssentialsModule; +import com.earth2me.essentials.settings.Spawns; +import com.earth2me.essentials.storage.AsyncStorageObjectHolder; +import java.io.File; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import org.bukkit.Location; +import org.bukkit.World; + + +public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule +{ + public SpawnStorage(final IEssentials ess) + { + super(ess, Spawns.class); + reloadConfig(); + } + + @Override + public File getStorageFile() + { + return new File(ess.getDataFolder(), "spawn.yml"); + } + + public void setSpawn(final Location loc, final String group) + { + acquireWriteLock(); + try + { + if (getData().getSpawns() == null) + { + getData().setSpawns(new HashMap<String, Location>()); + } + getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), loc); + } + finally + { + unlock(); + } + + if ("default".equalsIgnoreCase(group)) + { + loc.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + } + } + + public Location getSpawn(final String group) + { + acquireReadLock(); + try + { + if (getData().getSpawns() == null || group == null) + { + return getWorldSpawn(); + } + final Map<String, Location> spawnMap = getData().getSpawns(); + String groupName = group.toLowerCase(Locale.ENGLISH); + if (!spawnMap.containsKey(groupName)) + { + groupName = "default"; + } + if (!spawnMap.containsKey(groupName)) + { + return getWorldSpawn(); + } + return spawnMap.get(groupName); + } + finally + { + unlock(); + } + } + + private Location getWorldSpawn() + { + for (World world : ess.getServer().getWorlds()) + { + if (world.getEnvironment() != World.Environment.NORMAL) + { + continue; + } + return world.getSpawnLocation(); + } + return ess.getServer().getWorlds().get(0).getSpawnLocation(); + } +} diff --git a/EssentialsSpawn/src/plugin.yml b/EssentialsSpawn/src/plugin.yml index 1e01eebd9..a91031fbe 100644 --- a/EssentialsSpawn/src/plugin.yml +++ b/EssentialsSpawn/src/plugin.yml @@ -5,7 +5,7 @@ main: com.earth2me.essentials.spawn.EssentialsSpawn version: TeamCity website: http://www.earth2me.net:8001/ description: Provides spawn control commands, utilizing Essentials. -authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology] +authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits] depend: [Essentials] commands: setspawn: @@ -13,4 +13,4 @@ commands: usage: /<command> <group> spawn: description: Teleport to the spawnpoint. - usage: /<command>
\ No newline at end of file + usage: /<command> [player]
\ No newline at end of file |