diff options
Diffstat (limited to 'EssentialsSpawn/src/com')
5 files changed, 108 insertions, 52 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 813220a16..2e4b5eaa6 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -1,14 +1,14 @@ 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.IEssentialsModule; +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; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -19,6 +19,7 @@ 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() { @@ -37,9 +38,11 @@ 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(Type.PLAYER_RESPAWN, playerListener, ess.getSettings().getRespawnPriority(), this); - pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, ess.getSettings().getRespawnPriority(), this); + pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, spawns.getRespawnPriority(), this); + pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, spawns.getRespawnPriority(), this); LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); } @@ -52,6 +55,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 81e8f6e9e..08bb4d739 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -1,10 +1,10 @@ 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.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.event.player.PlayerJoinEvent; @@ -17,7 +17,6 @@ public class EssentialsSpawnPlayerListener extends PlayerListener { 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) { @@ -28,10 +27,21 @@ public class EssentialsSpawnPlayerListener extends PlayerListener @Override 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 = user.getHome(user.getLocation()); if (home == null) @@ -54,32 +64,30 @@ public class EssentialsSpawnPlayerListener extends PlayerListener @Override 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; } @@ -89,7 +97,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener { 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..0c351c753 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,7 @@ import java.util.Locale; import java.util.Map; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.event.Event.Priority; public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule @@ -17,7 +19,7 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE public SpawnStorage(final IEssentials ess) { super(ess, Spawns.class); - reloadConfig(); + onReload(); } @Override @@ -87,4 +89,58 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE } return ess.getServer().getWorlds().get(0).getSpawnLocation(); } + + public Priority getRespawnPriority() + { + acquireReadLock(); + try + { + for (Priority priority : Priority.values()) + { + if (priority.toString().equalsIgnoreCase(getData().getRespawnPriority())) { + return priority; + } + } + return Priority.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(); + } + } } |