summaryrefslogtreecommitdiffstats
path: root/EssentialsSpawn/src
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsSpawn/src')
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java10
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java45
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java35
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java79
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java90
-rw-r--r--EssentialsSpawn/src/plugin.yml4
6 files changed, 208 insertions, 55 deletions
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..c4cd7c727 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, Priority.Low, 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..530a00faa 100644
--- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
@@ -1,23 +1,27 @@
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;
- public EssentialsSpawnPlayerListener(IEssentials ess)
+ public EssentialsSpawnPlayerListener(final IEssentials ess, final SpawnStorage spawns)
{
+ super();
this.ess = ess;
+ this.spawns = spawns;
}
@Override
@@ -25,28 +29,24 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
{
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)
+ final Location spawn = spawns.getSpawn(user.getGroup());
+ if (spawn != null)
{
+ event.setRespawnLocation(spawn);
}
- Location spawn = ess.getSpawn().getSpawn(user.getGroup());
- if (spawn == null)
- {
- return;
- }
- event.setRespawnLocation(spawn);
}
@Override
@@ -54,27 +54,14 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
{
final User user = ess.getUser(event.getPlayer());
- if (!user.isNew())
+ if (!user.isNew() || user.getBedSpawnLocation() != null)
{
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));
}
if (ess.getSettings().getAnnounceNewPlayers())
@@ -82,4 +69,32 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user));
}
}
+
+
+ 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