diff options
Diffstat (limited to 'EssentialsSpawn')
6 files changed, 112 insertions, 54 deletions
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java index c6c89a20d..d0383bd4a 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java @@ -1,20 +1,14 @@ package com.earth2me.essentials.spawn; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.commands.EssentialsCommand; -import org.bukkit.Server; public class Commandsetspawn extends EssentialsCommand { - public Commandsetspawn() - { - super("setspawn"); - } - @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { final String group = args.length > 0 ? getFinalArg(args, 0) : "default"; ((SpawnStorage)module).setSpawn(user.getLocation(), group); diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index 6335d6c69..07532653c 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -2,30 +2,24 @@ package com.earth2me.essentials.spawn; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; 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 { - public Commandspawn() - { - super("spawn"); - } - @Override - 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); + public void run(final IUser user, final String commandLabel, final String[] args) throws Exception + { + final Trade charge = new Trade(commandName, ess); charge.isAffordableFor(user); if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) { - final User otherUser = getPlayer(server, args, 0); + final IUser otherUser = getPlayer(args, 0); respawn(otherUser, null); if (!otherUser.equals(user)) { @@ -34,27 +28,28 @@ public class Commandspawn extends EssentialsCommand } } else - { + { respawn(user, null); } } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(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); + final IUser user = getPlayer(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 { + + private void respawn(final IUser 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); + 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 f0c5ee466..666bb1614 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -1,7 +1,9 @@ package com.earth2me.essentials.spawn; +import com.earth2me.essentials.EssentialsCommandHandler; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.ICommandHandler; +import com.earth2me.essentials.api.IEssentials; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Bukkit; @@ -22,11 +24,12 @@ public class EssentialsSpawn extends JavaPlugin private static final Logger LOGGER = Bukkit.getLogger(); private transient IEssentials ess; private transient SpawnStorage spawns; + private transient ICommandHandler commandHandler; public void onEnable() { final PluginManager pluginManager = getServer().getPluginManager(); - ess = (IEssentials)pluginManager.getPlugin("Essentials"); + ess = (IEssentials)pluginManager.getPlugin("Essentials3"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { LOGGER.log(Level.WARNING, _("versionMismatchAll")); @@ -40,8 +43,10 @@ public class EssentialsSpawn extends JavaPlugin spawns = new SpawnStorage(ess); ess.addReloadListener(spawns); + commandHandler = new EssentialsCommandHandler(EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials.", spawns, ess); + final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns); - pluginManager.registerEvent(PlayerRespawnEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor() + pluginManager.registerEvent(PlayerRespawnEvent.class, playerListener, spawns.getRespawnPriority(), new EventExecutor() { @Override public void execute(final Listener ll, final Event event) throws EventException @@ -49,7 +54,7 @@ public class EssentialsSpawn extends JavaPlugin ((EssentialsSpawnPlayerListener)ll).onPlayerRespawn((PlayerRespawnEvent)event); } }, this); - pluginManager.registerEvent(PlayerJoinEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor() + pluginManager.registerEvent(PlayerJoinEvent.class, playerListener, spawns.getRespawnPriority(), new EventExecutor() { @Override public void execute(final Listener ll, final Event event) throws EventException @@ -67,6 +72,6 @@ public class EssentialsSpawn extends JavaPlugin 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.", spawns); + return commandHandler.handleCommand(sender, command, commandLabel, args); } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index b68b4e350..248ac15b7 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -1,14 +1,13 @@ package com.earth2me.essentials.spawn; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.OfflinePlayer; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.ISettings; +import com.earth2me.essentials.api.IUser; import java.util.logging.Level; -import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerRespawnEvent; @@ -19,7 +18,6 @@ public class EssentialsSpawnPlayerListener implements Listener { private final transient IEssentials ess; private final transient SpawnStorage spawns; - private static final Logger LOGGER = Bukkit.getLogger(); public EssentialsSpawnPlayerListener(final IEssentials ess, final SpawnStorage spawns) { @@ -30,9 +28,20 @@ public class EssentialsSpawnPlayerListener implements Listener public void onPlayerRespawn(final PlayerRespawnEvent event) { - final User user = ess.getUser(event.getPlayer()); + final IUser user = ess.getUser(event.getPlayer()); - if (ess.getSettings().getRespawnAtHome()) + boolean respawnAtHome = false; + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + try + { + respawnAtHome = ess.getSettings().getData().getCommands().getHome().isRespawnAtHome(); + } + finally + { + settings.unlock(); + } + if (respawnAtHome) { Location home; final Location bed = user.getBedSpawnLocation(); @@ -59,32 +68,30 @@ public class EssentialsSpawnPlayerListener implements Listener public void onPlayerJoin(final PlayerJoinEvent event) { - final User user = ess.getUser(event.getPlayer()); + final IUser user = ess.getUser(event.getPlayer()); if (user.hasPlayedBefore()) { - LOGGER.log(Level.FINE, "Old player join"); return; } - if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn())) + + if (spawns.getNewbieSpawn() != null) { ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L); } - if (ess.getSettings().getAnnounceNewPlayers()) + if (spawns.getAnnounceNewPlayers()) { - ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user)); + ess.broadcastMessage(user, spawns.getAnnounceNewPlayerFormat(user)); } - - LOGGER.log(Level.FINE, "New player join"); } private class NewPlayerTeleport implements Runnable { - private final transient User user; + private final transient IUser user; - public NewPlayerTeleport(final User user) + public NewPlayerTeleport(final IUser user) { this.user = user; } @@ -96,10 +103,10 @@ public class EssentialsSpawnPlayerListener implements Listener { return; } - + try { - Location spawn = spawns.getSpawn(ess.getSettings().getNewbieSpawn()); + final Location spawn = spawns.getNewbieSpawn(); if (spawn != null) { user.getTeleport().now(spawn, false, TeleportCause.PLUGIN); diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java index 088ee9052..13eb1f7df 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.spawn; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.IEssentialsModule; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IEssentialsModule; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.settings.Spawns; import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import java.io.File; @@ -10,6 +11,8 @@ import java.util.Locale; import java.util.Map; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.event.Event.Priority; +import org.bukkit.event.EventPriority; public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule @@ -17,7 +20,7 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE public SpawnStorage(final IEssentials ess) { super(ess, Spawns.class); - reloadConfig(); + onReload(); } @Override @@ -87,4 +90,58 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE } return ess.getServer().getWorlds().get(0).getSpawnLocation(); } + + public EventPriority getRespawnPriority() + { + acquireReadLock(); + try + { + for (EventPriority priority : EventPriority.values()) + { + if (priority.toString().equalsIgnoreCase(getData().getRespawnPriority())) { + return priority; + } + } + return EventPriority.NORMAL; + } finally { + unlock(); + } + } + + public Location getNewbieSpawn() + { + acquireReadLock(); + try + { + if (getData().getNewbieSpawn() == null || getData().getNewbieSpawn().isEmpty() || + getData().getNewbieSpawn().equalsIgnoreCase("none")) { + return null; + } + return getSpawn(getData().getNewbieSpawn()); + } finally { + unlock(); + } + } + + public boolean getAnnounceNewPlayers() + { + acquireReadLock(); + try + { + return getData().getNewPlayerAnnouncement() != null && !getData().getNewPlayerAnnouncement().isEmpty(); + } finally { + unlock(); + } + } + + public String getAnnounceNewPlayerFormat(IUser user) + { + acquireReadLock(); + try + { + return getData().getNewPlayerAnnouncement().replace('&', '§').replace("§§", "&").replace("{PLAYER}", user.getDisplayName()).replace("{DISPLAYNAME}", user.getDisplayName()).replace("{GROUP}", user.getGroup()).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getAddress().toString()); + } finally { + unlock(); + } + } } diff --git a/EssentialsSpawn/src/plugin.yml b/EssentialsSpawn/src/plugin.yml index 2c9fca434..f2638aa2a 100644 --- a/EssentialsSpawn/src/plugin.yml +++ b/EssentialsSpawn/src/plugin.yml @@ -3,10 +3,10 @@ name: EssentialsSpawn main: com.earth2me.essentials.spawn.EssentialsSpawn # Note to developers: This next line cannot change, or the automatic versioning system will break. version: TeamCity -website: http://tiny.cc/EssentialsCommands +website: http://tiny.cc/EssentialsWiki description: Provides spawn control commands, utilizing Essentials. authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits] -depend: [Essentials] +depend: [Essentials3] commands: setspawn: description: Set the spawnpoint to your current position. |