summaryrefslogtreecommitdiffstats
path: root/EssentialsSpawn/src/com/earth2me/essentials/spawn
diff options
context:
space:
mode:
authorZenexer <Zenexer@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-03-30 04:03:21 +0000
committerZenexer <Zenexer@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-03-30 04:03:21 +0000
commitcb21bc4d7a67f0974c2773fdd0f5376f177c068e (patch)
treef1584fe391f77c648a1d7d25385ef16229b756de /EssentialsSpawn/src/com/earth2me/essentials/spawn
downloadEssentials-cb21bc4d7a67f0974c2773fdd0f5376f177c068e.tar
Essentials-cb21bc4d7a67f0974c2773fdd0f5376f177c068e.tar.gz
Essentials-cb21bc4d7a67f0974c2773fdd0f5376f177c068e.tar.lz
Essentials-cb21bc4d7a67f0974c2773fdd0f5376f177c068e.tar.xz
Essentials-cb21bc4d7a67f0974c2773fdd0f5376f177c068e.zip
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
Diffstat (limited to 'EssentialsSpawn/src/com/earth2me/essentials/spawn')
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java24
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java23
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java65
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java51
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnWorker.java56
5 files changed, 219 insertions, 0 deletions
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java
new file mode 100644
index 000000000..e64985737
--- /dev/null
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java
@@ -0,0 +1,24 @@
+package com.earth2me.essentials.spawn;
+
+import org.bukkit.Server;
+import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.commands.EssentialsCommand;
+
+
+public class Commandsetspawn extends EssentialsCommand
+{
+ public Commandsetspawn()
+ {
+ super("setspawn");
+ }
+
+ @Override
+ public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
+ {
+ user.charge(this);
+ String group = args.length > 0 ? getFinalArg(args, 0) : "default";
+ parent.spawn.setSpawn(user.getLocation(), group);
+ user.sendMessage("§7Spawn location set for group \"" + group + "\".");
+ }
+}
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java
new file mode 100644
index 000000000..c26cc9e37
--- /dev/null
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java
@@ -0,0 +1,23 @@
+package com.earth2me.essentials.spawn;
+
+import org.bukkit.Server;
+import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.commands.EssentialsCommand;
+
+
+public class Commandspawn extends EssentialsCommand
+{
+ public Commandspawn()
+ {
+ super("spawn");
+ }
+
+ @Override
+ public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
+ {
+ user.canAfford(this);
+ user.teleportCooldown();
+ user.respawn(Essentials.getStatic().spawn, this.getName());
+ }
+}
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java
new file mode 100644
index 000000000..54e6bd198
--- /dev/null
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java
@@ -0,0 +1,65 @@
+package com.earth2me.essentials.spawn;
+
+import java.io.*;
+import java.util.logging.*;
+import com.earth2me.essentials.*;
+import org.bukkit.command.*;
+import org.bukkit.event.Event.Priority;
+import org.bukkit.event.Event.Type;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.*;
+
+
+public class EssentialsSpawn extends JavaPlugin
+{
+ public static final String AUTHORS = Essentials.AUTHORS;
+ private static final Logger logger = Logger.getLogger("Minecraft");
+
+ public EssentialsSpawn() throws IOException
+ {
+
+ }
+
+ @SuppressWarnings("LoggerStringConcat")
+ public void onEnable()
+ {
+ Plugin p = this.getServer().getPluginManager().getPlugin("Essentials");
+ if (p != null) {
+ if (!this.getServer().getPluginManager().isPluginEnabled(p)) {
+ this.getServer().getPluginManager().enablePlugin(p);
+ }
+ }
+ EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener();
+ getServer().getPluginManager().registerEvent(Type.PLAYER_RESPAWN, playerListener, Priority.Low, this);
+ getServer().getPluginManager().registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Low, 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() + " maintained by " + AUTHORS);
+ }
+
+ public void onDisable()
+ {
+ }
+
+ @SuppressWarnings(
+ {
+ "LoggerStringConcat", "CallToThreadDumpStack"
+ })
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
+ {
+ try
+ {
+ Essentials.loadClasses();
+ Essentials.previewCommand(sender, command, commandLabel, args);
+ return EssentialsSpawnWorker.onCommand(sender, command, commandLabel, args);
+ }
+ catch (Throwable ex)
+ {
+ ex.printStackTrace();
+ return true;
+ }
+ }
+}
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
new file mode 100644
index 000000000..697939daa
--- /dev/null
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
@@ -0,0 +1,51 @@
+package com.earth2me.essentials.spawn;
+
+import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.User;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerListener;
+import org.bukkit.event.player.PlayerRespawnEvent;
+
+
+public class EssentialsSpawnPlayerListener extends PlayerListener
+{
+ @Override
+ public void onPlayerRespawn(PlayerRespawnEvent event)
+ {
+ Essentials.loadClasses();
+ User user = User.get(event.getPlayer());
+
+ try
+ {
+ if (Essentials.getSettings().getRespawnAtHome())
+ {
+ event.setRespawnLocation(user.getHome());
+ return;
+ }
+ }
+ catch (Throwable ex)
+ {
+ }
+ event.setRespawnLocation(Essentials.getStatic().spawn.getSpawn(user.getGroup()));
+ }
+
+ @Override
+ public void onPlayerJoin(PlayerJoinEvent event)
+ {
+ Essentials.loadClasses();
+ User user = User.get(event.getPlayer());
+
+ if (!user.isNew()) return;
+ user.clearNewFlag();
+ try {
+ user.teleportToNow(Essentials.getStatic().spawn.getSpawn(Essentials.getSettings().getNewbieSpawn()));
+ } catch (Exception ex) {
+ Logger.getLogger("Minecraft").log(Level.WARNING, "Failed to teleport new player", ex);
+ }
+
+ if (Essentials.getSettings().getAnnounceNewPlayers())
+ Essentials.getStatic().getServer().broadcastMessage(Essentials.getSettings().getAnnounceNewPlayerFormat(user));
+ }
+}
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnWorker.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnWorker.java
new file mode 100644
index 000000000..d6e34db55
--- /dev/null
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnWorker.java
@@ -0,0 +1,56 @@
+package com.earth2me.essentials.spawn;
+
+import java.util.logging.*;
+import com.earth2me.essentials.*;
+import com.earth2me.essentials.commands.IEssentialsCommand;
+import org.bukkit.command.*;
+
+
+public class EssentialsSpawnWorker
+{
+ private static final Logger logger = Logger.getLogger("Minecraft");
+
+ @SuppressWarnings(
+ {
+ "LoggerStringConcat", "CallToThreadDumpStack"
+ })
+ public static boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
+ {
+ User user = User.get(sender);
+
+ IEssentialsCommand cmd;
+ try
+ {
+ cmd = (IEssentialsCommand)EssentialsSpawn.class.getClassLoader().loadClass("com.earth2me.essentials.spawn.Command" + command.getName()).newInstance();
+ }
+ catch (Exception ex)
+ {
+ sender.sendMessage("§cThat command is improperly loaded.");
+ ex.printStackTrace();
+ return true;
+ }
+
+ // Check authorization
+ if (user != null && !user.isAuthorized(cmd))
+ {
+ logger.warning(user.getName() + " was denied access to command.");
+ user.sendMessage("§cYou do not have access to that command.");
+ return true;
+ }
+
+ // Run the command
+ try
+ {
+ if (user == null)
+ cmd.run(Essentials.getStatic().getServer(), Essentials.getStatic(), sender, commandLabel, command, args);
+ else
+ cmd.run(Essentials.getStatic().getServer(), Essentials.getStatic(), user, commandLabel, command, args);
+ return true;
+ }
+ catch (Exception ex)
+ {
+ sender.sendMessage((user == null ? "" : "§c") + "Error: " + ex.getMessage());
+ return true;
+ }
+ }
+}