From 9802c00ec57ac97f5601776d76e4a906eeff8718 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 26 Feb 2015 21:40:09 +1300 Subject: [PATCH] Add /spawn and /setspawn commands to MapParser --- .../src/mineplex/mapparser/MapParser.java | 33 +++---------------- .../mapparser/command/SetSpawnCommand.java | 31 +++++++++++++++++ .../mapparser/command/SpawnCommand.java | 23 +++++++++++++ 3 files changed, 59 insertions(+), 28 deletions(-) create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SetSpawnCommand.java create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SpawnCommand.java diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index bca8b0264..08915a045 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -15,11 +15,9 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.entity.Sheep; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -28,21 +26,16 @@ import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.LeavesDecayEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; @@ -51,27 +44,9 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilGear; -import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.mapparser.command.AdminCommand; -import mineplex.mapparser.command.AuthorCommand; -import mineplex.mapparser.command.BaseCommand; -import mineplex.mapparser.command.CopyCommand; -import mineplex.mapparser.command.CopySchematicsCommand; -import mineplex.mapparser.command.CreateCommand; -import mineplex.mapparser.command.DeleteCommand; -import mineplex.mapparser.command.GameTypeCommand; -import mineplex.mapparser.command.HubCommand; -import mineplex.mapparser.command.ListCommand; -import mineplex.mapparser.command.MapCommand; -import mineplex.mapparser.command.NameCommand; -import mineplex.mapparser.command.ParseCommand200; -import mineplex.mapparser.command.ParseCommand400; -import mineplex.mapparser.command.ParseCommand600; -import mineplex.mapparser.command.RenameCommand; -import mineplex.mapparser.command.SaveCommand; -import mineplex.mapparser.command.WorldsCommand; +import mineplex.mapparser.command.*; public class MapParser extends JavaPlugin implements Listener { @@ -115,6 +90,8 @@ public class MapParser extends JavaPlugin implements Listener _commands.add(new SaveCommand(this)); _commands.add(new WorldsCommand(this)); _commands.add(new CopyCommand(this)); + _commands.add(new SpawnCommand(this)); + _commands.add(new SetSpawnCommand(this)); } @Override @@ -215,13 +192,14 @@ public class MapParser extends JavaPlugin implements Listener { if (alias.equalsIgnoreCase(commandLabel)) { + event.setCancelled(true); + if (!command.execute(player, commandLabel, args)) { UtilPlayer.message(player, F.main("Parser", "Invalid Input.")); UtilPlayer.message(player, F.elem(command.getUsage())); } - event.setCancelled(true); return; } } @@ -415,7 +393,6 @@ public class MapParser extends JavaPlugin implements Listener for (GameType type : GameType.values()) { - ChatColor color = ChatColor.YELLOW; File mapsFolder = new File("map" + File.separator + type.GetName()); if (!mapsFolder.exists()) diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SetSpawnCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SetSpawnCommand.java new file mode 100644 index 000000000..87002634f --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SetSpawnCommand.java @@ -0,0 +1,31 @@ +package mineplex.mapparser.command; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import mineplex.mapparser.MapParser; + +public class SetSpawnCommand extends BaseCommand +{ + + public SetSpawnCommand(MapParser plugin) + { + super(plugin, "setspawn"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + Location loc = player.getLocation(); + + player.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + + player.sendMessage(ChatColor.YELLOW + "Spawn saved for world '" + ChatColor.GOLD + loc.getWorld().getName() + + ChatColor.YELLOW + "' to X: " + ChatColor.GOLD + loc.getBlockX() + ChatColor.YELLOW + ", Y: " + + ChatColor.GOLD + loc.getBlockY() + ChatColor.YELLOW + ", Z: " + ChatColor.GOLD + loc.getBlockZ()); + + return true; + } + +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SpawnCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SpawnCommand.java new file mode 100644 index 000000000..e43f7515d --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SpawnCommand.java @@ -0,0 +1,23 @@ +package mineplex.mapparser.command; + +import org.bukkit.entity.Player; + +import mineplex.mapparser.MapParser; + +public class SpawnCommand extends BaseCommand +{ + + public SpawnCommand(MapParser plugin) + { + super(plugin, "spawn"); + } + + @Override + public boolean execute(Player player, String alias, String[] args) + { + player.teleport(player.getWorld().getSpawnLocation()); + + return true; + } + +}