diff --git a/Plugins/Mineplex.MapParser/Mineplex.MapParser.iml b/Plugins/Mineplex.MapParser/Mineplex.MapParser.iml
index d4443f18f..c63507327 100644
--- a/Plugins/Mineplex.MapParser/Mineplex.MapParser.iml
+++ b/Plugins/Mineplex.MapParser/Mineplex.MapParser.iml
@@ -9,6 +9,7 @@
+
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java
index 7c4d836f7..2f9daf2f4 100644
--- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java
@@ -47,7 +47,8 @@ public enum GameType
Tug("Tug of Wool"),
TurfWars("Turf Wars"),
UHC("Ultra Hardcore"),
- ZombieSurvival("Zombie Survival");
+ ZombieSurvival("Zombie Survival"),
+ None("None");
String _name;
String _lobbyName;
@@ -73,4 +74,18 @@ public enum GameType
{
return _lobbyName;
}
+
+ public static GameType match(String string)
+ {
+ GameType gameType = null;
+ string = string.toLowerCase();
+ for (GameType type : values())
+ {
+ if (type.name().toLowerCase().startsWith(string) || type.GetName().toLowerCase().startsWith(string))
+ {
+ gameType = type;
+ }
+ }
+ return gameType;
+ }
}
\ No newline at end of file
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java
index 5adea1189..1217b9f39 100644
--- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java
@@ -15,7 +15,7 @@ public class MapData
{
public String MapFolder;
- public String GameType = "null";
+ public GameType GameType = null;
public String MapName = "null";
public String MapCreator = "null";
@@ -66,7 +66,7 @@ public class MapData
}
else if (tokens[0].equalsIgnoreCase("GAME_TYPE"))
{
- GameType = tokens[1];
+ GameType = GameType.valueOf(tokens[1] == null ? "Null" : tokens[1]);
}
else if (tokens[0].equalsIgnoreCase("WHITE_LIST"))
{
@@ -134,4 +134,9 @@ public class MapData
{
return BuildList.contains(player.getName()) || WhiteList.contains(player.getName()) || player.isOp();
}
+
+ public boolean CanRename(Player player)
+ {
+ return true;
+ }
}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java
index bfb81c67e..46624d118 100644
--- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java
@@ -2,7 +2,11 @@ package mineplex.mapparser;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
@@ -10,17 +14,13 @@ import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
-import net.minecraft.util.org.apache.commons.io.FileUtils;
+import mineplex.mapparser.command.*;
-import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
-import org.bukkit.World.Environment;
-import org.bukkit.WorldCreator;
-import org.bukkit.WorldType;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@@ -45,8 +45,8 @@ public class MapParser extends JavaPlugin implements Listener
private WorldManager _worldManager;
private Parse _curParse = null;
-
private HashMap _mapData = new HashMap();
+ private List _commands = new ArrayList();
@Override
public void onEnable()
@@ -59,6 +59,22 @@ public class MapParser extends JavaPlugin implements Listener
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Ticker(this), 1, 1);
+
+ _commands.add(new AuthorCommand(this));
+ _commands.add(new BuildCommand(this));
+ _commands.add(new CopySchematicsCommand(this));
+ _commands.add(new CreateCommand(this));
+ _commands.add(new DeleteCommand(this));
+ _commands.add(new GameTypeCommand(this));
+ _commands.add(new HubCommand(this));
+ _commands.add(new JoinCommand(this));
+ _commands.add(new ListCommand(this));
+ _commands.add(new MapCommand(this));
+ _commands.add(new NameCommand(this));
+ _commands.add(new ParseCommand(this));
+ _commands.add(new RenameCommand(this));
+ _commands.add(new SaveCommand(this));
+ _commands.add(new WorldsCommand(this));
}
@Override
@@ -82,11 +98,12 @@ public class MapParser extends JavaPlugin implements Listener
public void DisplayHelp(Player player)
{
UtilPlayer.message(player, F.main("Parser", "Listing Commands;"));
+ UtilPlayer.message(player, F.value("Parameters", "Parameters: > = Required, [?] = Optional"));
UtilPlayer.message(player, F.value("/hub", "Return to hub world"));
UtilPlayer.message(player, " ");
- UtilPlayer.message(player, F.value("/create ", "Creates a new map"));
- UtilPlayer.message(player, F.value("/delete ", "Deletes an existing map"));
- UtilPlayer.message(player, F.value("/map ", "Teleport to a map"));
+ UtilPlayer.message(player, F.value("/create [gametype]", "Creates a new map"));
+ UtilPlayer.message(player, F.value("/delete [gametype]", "Deletes an existing map"));
+ UtilPlayer.message(player, F.value("/map [gametype]", "Teleport to a map"));
UtilPlayer.message(player, F.value("/list", "List maps"));
UtilPlayer.message(player, F.value("/parse", "Parse your current map!"));
UtilPlayer.message(player, " ");
@@ -95,7 +112,7 @@ public class MapParser extends JavaPlugin implements Listener
UtilPlayer.message(player, " ");
UtilPlayer.message(player, F.value("/name ", "Set name for current map"));
UtilPlayer.message(player, F.value("/author ", "Set author for current map"));
- UtilPlayer.message(player, F.value("/gametype ", "Set gametype for current map"));
UtilPlayer.message(player, " ");
UtilPlayer.message(player, C.cYellow + "Documentation: " + C.cGreen + "http://tinyurl.com/mpxmaps");
@@ -104,508 +121,57 @@ public class MapParser extends JavaPlugin implements Listener
@EventHandler
public void Command(PlayerCommandPreprocessEvent event)
{
- Player caller = event.getPlayer();
-
+ Player player = event.getPlayer();
+
+ String[] parts = event.getMessage().split(" ");
+ String commandLabel = parts[0].substring(1);
+ String[] args = new String[parts.length - 1];
+ System.arraycopy(parts, 1, args, 0, parts.length - 1);
+
if (_curParse != null)
{
- UtilPlayer.message(caller, F.main("Parse", "Cannot use commands during Map Parse!"));
+ UtilPlayer.message(player, F.main("Parser", "Cannot use commands during Map Parse!"));
return;
}
-
if (event.getMessage().toLowerCase().startsWith("/help"))
{
event.setCancelled(true);
- DisplayHelp(caller);
+ DisplayHelp(player);
}
- else if (event.getMessage().toLowerCase().startsWith("/copyschematics"))
- {
- event.setCancelled(true);
-
- try
- {
- FileUtils.copyDirectory(new File(".." + File.separator + "Build-1" + File.separator + "plugins" + File.separator + "WorldEdit" + File.separator + "schematics"),
- new File("plugins" + File.separator + "WorldEdit" + File.separator + "schematics"));
-
- UtilPlayer.message(caller, F.main("Parser", "Schematics Copied."));
- }
- catch (IOException e)
- {
- e.printStackTrace();
-
- UtilPlayer.message(caller, F.main("Parser", "Schematics Copy Failed! Contact Jonalon."));
- }
- }
- else if (event.getMessage().toLowerCase().startsWith("/create"))
- {
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/create ")));
- return;
- }
-
- String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
- String worldName = "map_" + args[0];
-
- if (DoesMapExist(worldName))
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Map name is already in use!"));
- return;
- }
-
- Announce("Creating World: " + F.elem(worldName));
-
- WorldCreator worldCreator = new WorldCreator(worldName);
- worldCreator.environment(Environment.NORMAL);
- worldCreator.type(WorldType.FLAT);
- worldCreator.generateStructures(false);
-
- World world = Bukkit.getServer().createWorld(worldCreator);
-
- UtilPlayer.message(caller, F.main("Parser", "Teleporting to World: " + F.elem(worldName)));
-
- event.getPlayer().teleport(new Location(world, 0, 100, 0));
-
- //Give Access
- GetData(world.getName()).WhiteList.add(event.getPlayer().getName());
- GetData(world.getName()).BuildList.add(event.getPlayer().getName());
- GetData(world.getName()).Write();
- }
- else if (event.getMessage().toLowerCase().startsWith("/delete"))
+ for (BaseCommand command : _commands)
{
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
+ for (String alias : command.getAliases())
{
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/delete ")));
- return;
- }
-
- String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
-
- String worldName = "map_" + args[0];
-
- if (!DoesMapExist(worldName))
- {
- UtilPlayer.message(caller, F.main("Parser", "Map does not exist: " + F.elem(worldName)));
- return;
- }
-
- if (!GetData(worldName).CanBuild(event.getPlayer()))
- {
- UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map."));
- return;
- }
-
- if (GetMapWorld(worldName) != null)
- {
- World world = GetMapWorld(worldName);
-
- //Teleport Out
- for (Player other : world.getPlayers())
- other.teleport(new Location(getServer().getWorlds().get(0), 0, 106, 0));
-
- //Unload World
- MapUtil.UnloadWorld(this, world);
- }
-
- //Delete
- FileUtils.deleteQuietly(new File(worldName));
-
- Announce("Deleted World: " + F.elem(args[0]));
- }
- else if (event.getMessage().toLowerCase().startsWith("/save"))
- {
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/save ")));
- return;
- }
-
- String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
-
- String worldName = "map_" + args[0];
-
- if (GetMapWorld(worldName) != null)
- {
- World world = GetMapWorld(worldName);
-
- if (!GetData(worldName).CanBuild(event.getPlayer()))
+ if (alias.equalsIgnoreCase(commandLabel))
{
- UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map."));
+ if (!command.execute(player, commandLabel, args))
+ {
+ UtilPlayer.message(player, F.main("Parser", "Invalid Input. " + command.getUsage()));
+ }
+
+ event.setCancelled(true);
return;
}
-
- //Teleport Out
- for (Player other : world.getPlayers())
- other.teleport(new Location(getServer().getWorlds().get(0), 0, 106, 0));
-
- //Unload World
- MapUtil.UnloadWorld(this, world, true);
- }
- else
- {
- UtilPlayer.message(caller, F.main("Parser", "World is not loaded: " + F.elem(worldName)));
- return;
- }
-
- Announce("Saved World: " + F.elem(args[0]));
- }
- else if (event.getMessage().toLowerCase().startsWith("/hub"))
- {
- event.setCancelled(true);
-
- event.getPlayer().teleport(new Location(getServer().getWorlds().get(0), 0, 106, 0));
- }
- else if (event.getMessage().toLowerCase().startsWith("/map"))
- {
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/map ")));
- return;
- }
-
- String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
-
- String worldName = "map_" + args[0];
-
- World world = GetMapWorld(worldName);
- if (world == null)
- {
- if (DoesMapExist(worldName))
- {
- world = Bukkit.createWorld(new WorldCreator(worldName));
- }
- else
- {
- UtilPlayer.message(caller, F.main("Parser", "Map Not Found: " + F.elem(worldName)));
- return;
- }
- }
-
- //Error (This should not occur!)
- if (world == null)
- {
- UtilPlayer.message(caller, F.main("Parser", "Null World Error: " + F.elem(worldName)));
- return;
- }
-
- //Permission
- if (!GetData(world.getName()).CanJoin(event.getPlayer()))
- {
- UtilPlayer.message(caller, F.main("Parser", "You do not have Join-Access on this Map."));
- return;
- }
-
- //Teleport
- UtilPlayer.message(caller, F.main("Parser", "Teleporting to World: " + F.elem(worldName)));
-
- event.getPlayer().teleport(new Location(world, 0, 100, 0));
-
- MapData data = GetData(worldName);
-
- UtilPlayer.message(event.getPlayer(), F.value("Map Name", data.MapName));
- UtilPlayer.message(event.getPlayer(), F.value("Author", data.MapCreator));
- UtilPlayer.message(event.getPlayer(), F.value("Game Type", data.GameType));
- }
- else if (event.getMessage().toLowerCase().startsWith("/list"))
- {
- event.setCancelled(true);
-
- UtilPlayer.message(caller, F.main("Parser", "Listing Maps;"));
-
- String maps = "";
- ChatColor color = ChatColor.YELLOW;
-
- File mapsFolder = new File(".");
- for (File file : mapsFolder.listFiles())
- {
- if (!file.isDirectory())
- continue;
-
- if (!file.getName().toLowerCase().startsWith("map_"))
- continue;
-
- maps += color + file.getName().substring(4) + " ";
-
- if (color == ChatColor.YELLOW)
- color = ChatColor.GOLD;
- else
- color = ChatColor.YELLOW;
- }
-
- event.getPlayer().sendMessage(maps);
- }
- else if (event.getMessage().toLowerCase().startsWith("/parse"))
- {
- event.setCancelled(true);
-
- Location parseLoc = event.getPlayer().getLocation();
-
- World world = caller.getWorld();
-
- MapData data = GetData(caller.getWorld().getName());
-
- if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.GameType.equals("null"))
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Map Name/Author/GameType are not set!"));
- return;
- }
-
- //Teleport Players Out
- for (Player worldPlayer : world.getPlayers())
- {
- worldPlayer.teleport(new Location(Bukkit.getWorlds().get(0), 0, 100, 0));
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "World " + F.elem(world.getName()) + " is preparing to be parsed."));
- }
-
- //Unload World > Copy
- World parseableWorld = _worldManager.prepMapParse(world);
-
- if (parseableWorld == null)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Could not prepare world for parsing!"));
- return;
- }
-
- //Parse the World
- _curParse = new Parse(this, parseableWorld, event.getMessage().split(" "), parseLoc, GetData(parseLoc.getWorld().getName()));
- }
- else if (event.getMessage().toLowerCase().startsWith("/worlds"))
- {
- event.setCancelled(true);
-
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Listing Active Worlds;"));
-
- for (World world : this.getServer().getWorlds())
- {
- event.getPlayer().sendMessage(world.getName());
- }
- }
-
- //XXX Set Map Data
- else if (event.getMessage().toLowerCase().startsWith("/name"))
- {
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/name ")));
- return;
- }
-
- String input = event.getMessage().substring(event.getMessage().indexOf(' ') + 1);
-
- if (event.getPlayer().getWorld().getName().equals("world"))
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot set name for Lobby."));
- return;
- }
-
- //Permission
- if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer()))
- {
- UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map."));
- return;
- }
-
- MapData data = GetData(event.getPlayer().getWorld().getName());
-
- data.MapName = input;
- data.Write();
-
- Announce("Map Name for " + F.elem(event.getPlayer().getWorld().getName()) + " set to " + F.elem(input) + ".");
- }
- else if (event.getMessage().toLowerCase().startsWith("/author"))
- {
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/author ")));
- return;
- }
-
- String input = event.getMessage().substring(event.getMessage().indexOf(' ') + 1);
-
- if (event.getPlayer().getWorld().getName().equals("world"))
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot set author for Lobby."));
- return;
- }
-
- //Permission
- if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer()))
- {
- UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map."));
- return;
- }
-
- MapData data = GetData(event.getPlayer().getWorld().getName());
-
- data.MapCreator = input;
- data.Write();
-
- Announce("Map Author for " + F.elem(event.getPlayer().getWorld().getName()) + " set to " + F.elem(input) + ".");
- }
- else if (event.getMessage().toLowerCase().startsWith("/gametype"))
- {
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/gametype ")));
- return;
- }
-
- String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
-
- if (event.getPlayer().getWorld().getName().equals("world"))
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot set GameType for Lobby."));
- return;
- }
-
- //Permission
- if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer()))
- {
- UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map."));
- return;
- }
-
- //Check Gametype
- try
- {
- GameType.valueOf(args[0]);
- }
- catch (Exception ex)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Valid Game Types;"));
-
- String gameTypes = "";
-
- for (GameType game : GameType.values())
- {
- gameTypes += game.toString() + " ";
- }
-
- event.getPlayer().sendMessage(gameTypes);
-
- return;
- }
-
- MapData data = GetData(event.getPlayer().getWorld().getName());
-
- data.GameType = args[0];
- data.Write();
-
- Announce("GameType for " + F.elem(event.getPlayer().getWorld().getName()) + " set to " + F.elem(args[0]) + ".");
- }
-
- else if (event.getMessage().toLowerCase().startsWith("/join"))
- {
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/join ")));
- return;
- }
-
- String input = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ")[0];
-
- if (event.getPlayer().getWorld().getName().equals("world"))
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot change Join-List for Lobby."));
- return;
- }
-
- //Permission
- if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer()))
- {
- UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map."));
- return;
- }
-
- Player player = UtilPlayer.searchOnline(event.getPlayer(), input, true);
-
- if (player != null)
- {
- MapData data = GetData(event.getPlayer().getWorld().getName());
-
- if (data.WhiteList.contains(player.getName()))
- {
- data.WhiteList.remove(player.getName());
- data.Write();
-
- Announce("Join-List for " + F.elem(event.getPlayer().getWorld().getName()) + " (" + player.getName() + " = " + F.tf(false) + ")");
- }
- else
- {
- data.WhiteList.add(player.getName());
- data.Write();
-
- Announce("Join-List for " + F.elem(event.getPlayer().getWorld().getName()) + " (" + player.getName() + " = " + F.tf(true) + ")");
- }
- }
- }
-
- else if (event.getMessage().toLowerCase().startsWith("/build"))
- {
- event.setCancelled(true);
-
- if (event.getMessage().split(" ").length < 2)
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/build ")));
- return;
- }
-
- String input = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ")[0];
-
- if (event.getPlayer().getWorld().getName().equals("world"))
- {
- UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot change Build-List for Lobby."));
- return;
- }
-
- //Permission
- if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer()))
- {
- UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map."));
- return;
- }
-
- Player player = UtilPlayer.searchOnline(event.getPlayer(), input, true);
-
- if (player != null)
- {
- MapData data = GetData(event.getPlayer().getWorld().getName());
-
- if (data.BuildList.contains(player.getName()))
- {
- data.BuildList.remove(player.getName());
- data.Write();
-
- Announce("Build-List for " + F.elem(event.getPlayer().getWorld().getName()) + " (" + player.getName() + " = " + F.tf(false) + ")");
- }
- else
- {
- data.BuildList.add(player.getName());
- data.Write();
-
- Announce("Build-List for " + F.elem(event.getPlayer().getWorld().getName()) + " (" + player.getName() + " = " + F.tf(true) + ")");
- }
}
}
}
-
+
+ public void sendValidGameTypes(Player player)
+ {
+ UtilPlayer.message(player, F.main("Parser", "Valid Game Types;"));
+
+ String gameTypes = "";
+
+ for (GameType game : GameType.values())
+ {
+ gameTypes += game.toString() + " ";
+ }
+
+ player.sendMessage(gameTypes);
+ }
+
@EventHandler
public void ParseUpdate(TickEvent event)
{
@@ -688,7 +254,7 @@ public class MapParser extends JavaPlugin implements Listener
if (world.getName().startsWith("parse_"))
continue;
- if (!world.getName().startsWith("map_"))
+ if (!world.getName().startsWith("map"))
continue;
if (world.getPlayers().isEmpty())
@@ -709,31 +275,98 @@ public class MapParser extends JavaPlugin implements Listener
}
}
- public boolean DoesMapExist(String name)
+ public boolean DoesMapExist(String mapName, GameType gameType)
{
- File mapsFolder = new File(".");
- for (File file : mapsFolder.listFiles())
- {
- if (!file.isDirectory())
- continue;
-
- if (file.getName().equals(name))
- return true;
- }
-
+ return DoesMapExist(getWorldString(mapName, gameType));
+ }
+
+ public boolean DoesMapExist(String worldName)
+ {
+ File file = new File(worldName);
+
+ if (file.exists() && file.isDirectory())
+ return true;
+
return false;
}
-
- public World GetMapWorld(String name)
+
+ public String getShortWorldName(String worldName)
+ {
+ int lastIndexOfSeperator = worldName.lastIndexOf('/');
+
+ if (lastIndexOfSeperator != -1)
+ return worldName.substring(lastIndexOfSeperator + 1);
+
+ return worldName;
+ }
+
+ public World GetMapWorld(String mapName, GameType gameType)
+ {
+ return GetMapWorld(getWorldString(mapName, gameType));
+ }
+
+ public World GetMapWorld(String worldName)
{
for (World world : this.getServer().getWorlds())
{
- if (world.getName().equals(name))
+ if (world.getName().equals(worldName))
return world;
}
-
+
return null;
}
+
+ public String getWorldString(String worldName, GameType type)
+ {
+ return "map" + "/" + type.GetName() + "/" + worldName;
+ }
+
+ public List getMapsByName(String name)
+ {
+ name = name.toLowerCase();
+
+ List maps = new LinkedList();
+ boolean matchesExact = false;
+
+ for (GameType type : GameType.values())
+ {
+ ChatColor color = ChatColor.YELLOW;
+
+ File mapsFolder = new File("map" + File.separator + type.GetName());
+ if (!mapsFolder.exists())
+ continue;
+
+ for (File file : mapsFolder.listFiles())
+ {
+ if (!file.isDirectory())
+ continue;
+
+ if (!file.getName().toLowerCase().contains(name))
+ continue;
+
+ if (file.getName().equalsIgnoreCase(name))
+ matchesExact = true;
+
+ maps.add(getWorldString(file.getName(), type));
+ }
+ }
+
+ if (matchesExact)
+ {
+ Iterator it = maps.iterator();
+ while (it.hasNext())
+ {
+ String mapString = it.next();
+
+ if (!mapString.toLowerCase().endsWith(name))
+ {
+ it.remove();
+ }
+ }
+ }
+
+ return maps;
+ }
public MapData GetData(String mapName)
{
@@ -756,13 +389,25 @@ public class MapParser extends JavaPlugin implements Listener
player.getInventory().addItem(new ItemStack(Material.STONE_PICKAXE));
player.getInventory().addItem(new ItemStack(Material.STONE_AXE));
}
+
+ public WorldManager getWorldManager()
+ {
+ return _worldManager;
+ }
+
+ public void setCurrentParse(Parse parse)
+ {
+ _curParse = parse;
+ }
@EventHandler
public void Chat(AsyncPlayerChatEvent event)
{
event.setCancelled(true);
-
- String world = C.cDGreen + C.Bold + event.getPlayer().getWorld().getName();
+
+ String world = C.cDGreen + C.Bold + getShortWorldName(event.getPlayer().getWorld().getName());
+
+
String name = C.cYellow + event.getPlayer().getName();
if (GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer()))
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java
index ed6b13e64..018fbecd9 100644
--- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java
@@ -71,9 +71,6 @@ public class Parse
//Take BlockID Arguments
for (String arg : _args)
{
- if (arg.equals("/parse"))
- continue;
-
try
{
_dataId.add(Integer.parseInt(arg));
@@ -509,7 +506,7 @@ public class Parse
return out;
}
- public String getGameType()
+ public GameType getGameType()
{
return _mapData.GameType;
}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java
index c9cad10ac..6d2dadae9 100644
--- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java
@@ -102,7 +102,7 @@ public class WorldManager
MapData data = Host.GetData(world.getName().substring(6));
String fileName = data.GameType + "_" + data.MapName + ".zip";
- GameType gameType = GameType.valueOf(data.GameType);
+ GameType gameType = data.GameType;
ZipUtil.ZipFolders(Paths.get(world.getName()).toAbsolutePath().toString(), fileName, dirList, fileList);
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java
new file mode 100644
index 000000000..89861f4da
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java
@@ -0,0 +1,59 @@
+package mineplex.mapparser.command;
+
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/15/2014.
+ */
+public class AuthorCommand extends BaseCommand
+{
+ public AuthorCommand(MapParser plugin)
+ {
+ super(plugin, "author");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ World world = player.getWorld();
+
+ if (args.length < 1)
+ {
+ message(player, "Invalid Input. " + F.elem("/author "));
+ return true;
+ }
+
+ String authorName = "";
+ for (String arg : args)
+ authorName += arg + " ";
+ authorName = authorName.trim();
+
+ if (world.getName().equals("world"))
+ {
+ message(player, "Cannot set author for Lobby.");
+ return true;
+ }
+
+ //Permission
+ if (!getPlugin().GetData(world.getName()).CanBuild(player))
+ {
+ message(player, "You do not have Build-Access on this Map.");
+ return true;
+ }
+
+ MapData data = getPlugin().GetData(world.getName());
+
+ data.MapCreator = authorName;
+ data.Write();
+
+ getPlugin().Announce("Map Author for " + F.elem(world.getName()) + " set to " + F.elem(authorName) + ".");
+
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/BaseCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/BaseCommand.java
new file mode 100644
index 000000000..16552b9b0
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/BaseCommand.java
@@ -0,0 +1,64 @@
+package mineplex.mapparser.command;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/15/2014.
+ */
+public abstract class BaseCommand
+{
+ private MapParser _plugin;
+ private List _aliases;
+ private String _description = "Null";
+ private String _usage = "Undefined";
+
+ public BaseCommand(MapParser plugin, String... aliases)
+ {
+ _plugin = plugin;
+ _aliases = Arrays.asList(aliases);
+ }
+
+ public abstract boolean execute(Player player, String alias, String[] args);
+
+ public String getDescription()
+ {
+ return _description;
+ }
+
+ protected void setDescription(String description)
+ {
+ _description = description;
+ }
+
+ public String getUsage()
+ {
+ return _usage;
+ }
+
+ protected void setUsage(String usage)
+ {
+ _usage = usage;
+ }
+
+ public List getAliases()
+ {
+ return _aliases;
+ }
+
+ protected MapParser getPlugin()
+ {
+ return _plugin;
+ }
+
+ protected void message(Player player, String message)
+ {
+ UtilPlayer.message(player, F.main("Parser", message));
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/BuildCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/BuildCommand.java
new file mode 100644
index 000000000..b58a5086f
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/BuildCommand.java
@@ -0,0 +1,68 @@
+package mineplex.mapparser.command;
+
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/16/2014.
+ */
+public class BuildCommand extends BaseCommand
+{
+ public BuildCommand(MapParser plugin)
+ {
+ super(plugin, "build");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ if (args.length != 1)
+ {
+ message(player, "Invalid Input. " + F.elem("/build "));
+ return true;
+ }
+
+ World world = player.getWorld();
+
+ if (world.getName().equals("world"))
+ {
+ message(player, "Cannot change Build-List for Lobby.");
+ return true;
+ }
+
+ //Permission
+ if (!getPlugin().GetData(world.getName()).CanBuild(player))
+ {
+ message(player, "You do not have Build-Access on this Map.");
+ return true;
+ }
+
+ Player other = UtilPlayer.searchOnline(player, args[0], true);
+
+ if (player != null)
+ {
+ MapData data = getPlugin().GetData(world.getName());
+
+ if (data.BuildList.contains(other.getName()))
+ {
+ data.BuildList.remove(other.getName());
+ data.Write();
+
+ getPlugin().Announce("Build-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(false) + ")");
+ }
+ else
+ {
+ data.BuildList.add(other.getName());
+ data.Write();
+
+ getPlugin().Announce("Build-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(true) + ")");
+ }
+ }
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopySchematicsCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopySchematicsCommand.java
new file mode 100644
index 000000000..2b59d916c
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopySchematicsCommand.java
@@ -0,0 +1,40 @@
+package mineplex.mapparser.command;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.bukkit.entity.Player;
+
+import mineplex.mapparser.MapParser;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Created by Shaun on 8/16/2014.
+ */
+public class CopySchematicsCommand extends BaseCommand
+{
+ public CopySchematicsCommand(MapParser plugin)
+ {
+ super(plugin, "copyschematics");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ try
+ {
+ FileUtils.copyDirectory(new File(".." + File.separator + "Build-1" + File.separator + "plugins" + File.separator + "WorldEdit" + File.separator + "schematics"),
+ new File("plugins" + File.separator + "WorldEdit" + File.separator + "schematics"));
+
+ message(player, "Schematics Copied.");
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+
+ message(player, "Schematics Copy Failed! Contact Jonalon.");
+ }
+
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java
new file mode 100644
index 000000000..fb6174434
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java
@@ -0,0 +1,76 @@
+package mineplex.mapparser.command;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.WorldCreator;
+import org.bukkit.WorldType;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.GameType;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/16/2014.
+ */
+public class CreateCommand extends BaseCommand
+{
+ public CreateCommand(MapParser plugin)
+ {
+ super(plugin, "create");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ if (args.length < 2)
+ {
+ message(player, "Invalid Input. " + F.elem("/create "));
+ return true;
+ }
+
+ GameType gameType = null;
+
+ try
+ {
+ gameType = GameType.valueOf(args[1]);
+ }
+ catch (Exception e)
+ {
+ getPlugin().sendValidGameTypes(player);
+ }
+
+ String worldName = "map/" + gameType.GetName() + "/" + args[0];
+
+ if (getPlugin().DoesMapExist(worldName))
+ {
+ message(player, "Map name is already in use!");
+ return true;
+ }
+
+ getPlugin().Announce("Creating World: " + F.elem(worldName));
+
+ WorldCreator worldCreator = new WorldCreator(worldName);
+ worldCreator.environment(World.Environment.NORMAL);
+ worldCreator.type(WorldType.FLAT);
+ worldCreator.generateStructures(false);
+
+ World world = Bukkit.getServer().createWorld(worldCreator);
+
+ message(player, "Teleporting to World: " + F.elem(worldName));
+
+ player.teleport(new Location(world, 0, 100, 0));
+
+ //Give Access
+ MapData mapData = getPlugin().GetData(worldName);
+ mapData.WhiteList.add(player.getName());
+ mapData.BuildList.add(player.getName());
+ mapData.GameType = gameType;
+ mapData.Write();
+
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java
new file mode 100644
index 000000000..20837b8df
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java
@@ -0,0 +1,84 @@
+package mineplex.mapparser.command;
+
+import java.io.File;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.MapUtil;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.GameType;
+import mineplex.mapparser.MapParser;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Created by Shaun on 8/16/2014.
+ */
+public class DeleteCommand extends BaseCommand
+{
+ public DeleteCommand(MapParser plugin)
+ {
+ super(plugin, "delete");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ if (args.length < 2)
+ {
+ message(player, "Invalid Input. " + F.elem("/delete [GameType]"));
+ return true;
+ }
+
+ String mapName = args[0];
+ GameType gameType = null;
+
+ try
+ {
+ gameType = GameType.valueOf(args[1]);
+ }
+ catch (Exception e)
+ {
+ getPlugin().sendValidGameTypes(player);
+ }
+
+ final String worldName = getPlugin().getWorldString(mapName, gameType);
+
+ if (!getPlugin().DoesMapExist(worldName))
+ {
+ message(player, "Map does not exist: " + F.elem(worldName));
+ return true;
+ }
+
+ if (!getPlugin().GetData(worldName).CanBuild(player))
+ {
+ message(player, "You do not have Build-Access on this Map.");
+ return true;
+ }
+
+ if (getPlugin().GetMapWorld(worldName) != null)
+ {
+ World world = getPlugin().GetMapWorld(worldName);
+
+ //Teleport Out
+ for (Player other : world.getPlayers())
+ other.teleport(new Location(getPlugin().getServer().getWorlds().get(0), 0, 106, 0));
+
+ //Unload World
+ //Things break if this isn't set to true for saving the world
+ MapUtil.UnloadWorld(getPlugin(), world, true);
+ }
+
+ //Delete
+ boolean deleted = FileUtils.deleteQuietly(new File(worldName));
+
+ if (deleted)
+ getPlugin().Announce("Deleted World: " + F.elem(worldName));
+ else
+ getPlugin().Announce("Failed to delete World: " + F.elem(worldName));
+
+ return false;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java
new file mode 100644
index 000000000..60062df24
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java
@@ -0,0 +1,96 @@
+package mineplex.mapparser.command;
+
+import java.io.File;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.MapUtil;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.GameType;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/16/2014.
+ */
+public class GameTypeCommand extends BaseCommand
+{
+ public GameTypeCommand(MapParser plugin)
+ {
+ super(plugin, "gametype");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ World world = player.getWorld();
+
+ if (args.length != 1)
+ {
+ message(player, "Invalid Input. " + F.elem("/gametype "));
+ return true;
+ }
+
+ if (world.getName().equals("world"))
+ {
+ message(player, "Cannot set GameType for Lobby.");
+ return true;
+ }
+
+ //Permission
+ if (!getPlugin().GetData(world.getName()).CanBuild(player))
+ {
+ message(player, "You do not have Build-Access on this Map.");
+ return true;
+ }
+
+ //Check Gametype
+ GameType type = null;
+ try
+ {
+ type = GameType.valueOf(args[0]);
+ }
+ catch (Exception ex)
+ {
+ getPlugin().sendValidGameTypes(player);
+ return true;
+ }
+
+ if (getPlugin().DoesMapExist(getPlugin().getShortWorldName(world.getName()), type))
+ {
+ message(player, "A world with the same name already exists for the new gametype: " + type.GetName());
+ return true;
+ }
+
+ // Rename world
+ for (Player other : world.getPlayers())
+ {
+ other.teleport(new Location(getPlugin().getServer().getWorlds().get(0), 0, 106, 0));
+ message(player, "Unloading world for rename...");
+ }
+ MapUtil.UnloadWorld(getPlugin(), world, true);
+
+ File typeFolder = new File("map/" + type.GetName());
+ if (!typeFolder.exists())
+ typeFolder.mkdir();
+
+ File mapFolder = new File(world.getName());
+ String newName = "map/" + type.GetName() + "/" + getPlugin().getShortWorldName(world.getName());
+ File newFolder = new File(newName);
+ mapFolder.renameTo(newFolder);
+
+ message(player, "Map " + world.getName() + " renamed to " + newName);
+
+
+ MapData data = getPlugin().GetData(newName);
+ data.GameType = type;
+ data.Write();
+
+ getPlugin().Announce("GameType for " + F.elem(newName) + " set to " + F.elem(args[0]) + ".");
+
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/HubCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/HubCommand.java
new file mode 100644
index 000000000..da6a98aef
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/HubCommand.java
@@ -0,0 +1,24 @@
+package mineplex.mapparser.command;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/15/2014.
+ */
+public class HubCommand extends BaseCommand
+{
+ public HubCommand(MapParser plugin)
+ {
+ super(plugin, "hub");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ player.teleport(new Location(getPlugin().getServer().getWorlds().get(0), 0, 106, 0));
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/JoinCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/JoinCommand.java
new file mode 100644
index 000000000..bd5bf383f
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/JoinCommand.java
@@ -0,0 +1,66 @@
+package mineplex.mapparser.command;
+
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/16/2014.
+ */
+public class JoinCommand extends BaseCommand
+{
+ public JoinCommand(MapParser plugin)
+ {
+ super(plugin, "join");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ if (args.length != 1)
+ {
+ message(player, "Invalid Input. " + F.elem("/join "));
+ return true;
+ }
+
+ if (player.getWorld().getName().equals("world"))
+ {
+ message(player, "Cannot change Join-List for Lobby.");
+ return true;
+ }
+
+ //Permission
+ if (!getPlugin().GetData(player.getWorld().getName()).CanBuild(player))
+ {
+ message(player, "You do not have Build-Access on this Map.");
+ return true;
+ }
+
+ Player other = UtilPlayer.searchOnline(player, args[0], true);
+
+ if (other != null)
+ {
+ MapData data = getPlugin().GetData(player.getWorld().getName());
+
+ if (data.WhiteList.contains(other.getName()))
+ {
+ data.WhiteList.remove(other.getName());
+ data.Write();
+
+ getPlugin().Announce("Join-List for " + F.elem(player.getWorld().getName()) + " (" + other.getName() + " = " + F.tf(false) + ")");
+ }
+ else
+ {
+ data.WhiteList.add(player.getName());
+ data.Write();
+
+ getPlugin().Announce("Join-List for " + F.elem(player.getWorld().getName()) + " (" + other.getName() + " = " + F.tf(true) + ")");
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ListCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ListCommand.java
new file mode 100644
index 000000000..7cd543d11
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ListCommand.java
@@ -0,0 +1,84 @@
+package mineplex.mapparser.command;
+
+import java.io.File;
+
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.GameType;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/15/2014.
+ */
+public class ListCommand extends BaseCommand
+{
+ public ListCommand(MapParser plugin)
+ {
+ super(plugin, "list");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ if (args.length == 0)
+ {
+ UtilPlayer.message(player, F.main("Parser", "Listing Maps;"));
+
+ for (GameType gameType : GameType.values())
+ {
+ listMaps(player, gameType);
+ }
+ }
+ else if (args.length == 1)
+ {
+ GameType gameType = null;
+ try
+ {
+ gameType = GameType.valueOf(args[0]);
+ }
+ catch (Exception e)
+ {
+ getPlugin().sendValidGameTypes(player);
+ }
+
+
+ UtilPlayer.message(player, F.main("Parser", "Listing Maps for gametype " + F.elem(gameType.GetName())));
+ listMaps(player, gameType);
+ }
+
+ return true;
+ }
+
+ private void listMaps(Player player, GameType gameType)
+ {
+ String maps = "";
+ ChatColor color = ChatColor.YELLOW;
+
+ File mapsFolder = new File("map" + File.separator + gameType.GetName());
+ if (!mapsFolder.exists())
+ return;
+
+ for (File file : mapsFolder.listFiles())
+ {
+ if (!file.isDirectory())
+ continue;
+
+ maps += color + file.getName() + " ";
+
+ if (color == ChatColor.YELLOW)
+ color = ChatColor.GOLD;
+ else
+ color = ChatColor.YELLOW;
+ }
+
+ // Print line of maps for specific gametype
+ if (maps.length() > 0)
+ {
+ maps = F.elem(gameType.name()) + "> " + maps;
+ player.sendMessage(maps);
+ }
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java
new file mode 100644
index 000000000..d8cba4c18
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java
@@ -0,0 +1,115 @@
+package mineplex.mapparser.command;
+
+import java.util.List;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.WorldCreator;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.GameType;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/15/2014.
+ */
+public class MapCommand extends BaseCommand
+{
+ public MapCommand(MapParser plugin)
+ {
+ super(plugin, "map");
+
+ setDescription("Teleport to a map");
+ setUsage("/map [gametype]");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ if (args.length < 1)
+ {
+ //UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/map [GameType]")));
+ return false;
+ }
+
+ String worldName = null;
+ // Look up maps without a specific game type
+ if (args.length == 1)
+ {
+ List possibleMaps = getPlugin().getMapsByName(args[0]);
+ if (possibleMaps.size() == 0)
+ {
+ message(player, "No maps found with the name: " + F.elem(args[0]));
+ }
+ else if (possibleMaps.size() > 1)
+ {
+ message(player, "Found more than one possible match:");
+ for (String s : possibleMaps)
+ UtilPlayer.message(player, s);
+
+ return true;
+ }
+
+ worldName = possibleMaps.get(0);
+ }
+ else // Get map with specified name and gametype
+ {
+ GameType gameType = null;
+ try
+ {
+ gameType = GameType.valueOf(args[1]);
+ }
+ catch (Exception e)
+ {
+ getPlugin().sendValidGameTypes(player);
+ return true;
+ }
+
+ worldName = getPlugin().getWorldString(args[0], gameType);
+ }
+
+ World world = getPlugin().GetMapWorld(worldName);
+ if (world == null)
+ {
+ if (getPlugin().DoesMapExist(worldName))
+ {
+ world = Bukkit.createWorld(new WorldCreator(worldName));
+ }
+ else
+ {
+ message(player, "Map Not Found: " + F.elem(worldName));
+ return true;
+ }
+ }
+
+ //Error (This should not occur!)
+ if (world == null)
+ {
+ message(player, "Null World Error: " + F.elem(worldName));
+ return true;
+ }
+
+ //Permission
+ if (!getPlugin().GetData(world.getName()).CanJoin(player))
+ {
+ message(player, "You do not have Join-Access on this Map.");
+ return true;
+ }
+
+ //Teleport
+ message(player, "Teleporting to World: " + F.elem(worldName));
+
+ player.teleport(new Location(world, 0, 100, 0));
+
+ MapData data = getPlugin().GetData(worldName);
+
+ UtilPlayer.message(player, F.value("Map Name", data.MapName));
+ UtilPlayer.message(player, F.value("Author", data.MapCreator));
+ UtilPlayer.message(player, F.value("Game Type", data.GameType.GetName()));
+ return false;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java
new file mode 100644
index 000000000..e7741ddf5
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java
@@ -0,0 +1,61 @@
+package mineplex.mapparser.command;
+
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/15/2014.
+ */
+public class NameCommand extends BaseCommand
+{
+
+ public NameCommand(MapParser plugin)
+ {
+ super(plugin, "name");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ World world = player.getWorld();
+
+ if (args.length < 1)
+ {
+ message(player, "Invalid Input. " + F.elem("/name "));
+ return true;
+ }
+
+ if (world.equals("world"))
+ {
+ message(player, "Cannot set name for Lobby.");
+ return true;
+ }
+
+ String mapName = "";
+ for(String arg : args)
+ mapName += arg + " ";
+
+ mapName = mapName.trim();
+
+ //Permission
+ if (!getPlugin().GetData(world.getName()).CanBuild(player))
+ {
+ message(player, "You do not have Build-Access on this Map.");
+ return true;
+ }
+
+ MapData data = getPlugin().GetData(world.getName());
+
+ data.MapName = mapName;
+ data.Write();
+
+ getPlugin().Announce("Map Name for " + F.elem(world.getName()) + " set to " + F.elem(mapName) + ".");
+
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand.java
new file mode 100644
index 000000000..cd73dbebc
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand.java
@@ -0,0 +1,60 @@
+package mineplex.mapparser.command;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+import mineplex.mapparser.Parse;
+
+/**
+ * Created by Shaun on 8/15/2014.
+ */
+public class ParseCommand extends BaseCommand
+{
+ public ParseCommand(MapParser plugin)
+ {
+ super(plugin, "parse");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ Location parseLoc = player.getLocation();
+
+ World world = parseLoc.getWorld();
+
+ MapData data = getPlugin().GetData(world.getName());
+
+ if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.GameType.equals("null"))
+ {
+ message(player, "Map Name/Author/GameType are not set!");
+ return true;
+ }
+
+ //Teleport Players Out
+ for (Player worldPlayer : world.getPlayers())
+ {
+ worldPlayer.teleport(new Location(Bukkit.getWorlds().get(0), 0, 100, 0));
+ message(player, "World " + F.elem(world.getName()) + " is preparing to be parsed.");
+ }
+
+ //Unload World > Copy
+ World parseableWorld = getPlugin().getWorldManager().prepMapParse(world);
+
+ if (parseableWorld == null)
+ {
+ message(player, "Could not prepare world for parsing!");
+ return true;
+ }
+
+ //Parse the World
+ getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName())));
+
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java
new file mode 100644
index 000000000..5d9e9b412
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java
@@ -0,0 +1,65 @@
+package mineplex.mapparser.command;
+
+import java.io.File;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.MapUtil;
+import mineplex.mapparser.MapData;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/16/2014.
+ */
+public class RenameCommand extends BaseCommand
+{
+ public RenameCommand(MapParser plugin)
+ {
+ super(plugin, "rename");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ World world = player.getWorld();
+ MapData data = getPlugin().GetData(world.getName());
+
+ if (data == null)
+ {
+ message(player, "Map not found: " + F.elem(args[0]));
+ return true;
+ }
+ else if (!data.CanRename(player))
+ {
+ message(player, "You do not have access to rename this map");
+ return true;
+ }
+ else if (args.length != 1)
+ {
+ message(player, "Usage: /rename ");
+ return true;
+ }
+
+ String newName = args[0];
+
+ for (Player other : world.getPlayers())
+ {
+ other.teleport(new Location(getPlugin().getServer().getWorlds().get(0), 0, 106, 0));
+ message(other, "Unloading world for rename...");
+ }
+ MapUtil.UnloadWorld(getPlugin(), world, true);
+ message(player, "World unloaded!");
+
+
+ File mapFolder = new File(world.getName());
+ File newFolder = new File("map" + File.separator + data.GameType.GetName() + File.separator + newName);
+ mapFolder.renameTo(newFolder);
+
+ message(player, "Map " + world.getName() + " renamed to " + newFolder.getName());
+
+ return true;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java
new file mode 100644
index 000000000..c618be90b
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java
@@ -0,0 +1,79 @@
+package mineplex.mapparser.command;
+
+import java.util.List;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.MapUtil;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/16/2014.
+ */
+public class SaveCommand extends BaseCommand
+{
+ public SaveCommand(MapParser plugin)
+ {
+ super(plugin, "save");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ if (args.length < 1)
+ {
+ message(player, "Invalid Input. " + F.elem("/save "));
+ return true;
+ }
+
+ String name = args[0];
+
+ List possibleMaps = getPlugin().getMapsByName(name);
+
+ if (possibleMaps.size() > 1)
+ {
+ message(player, "More than one map found:");
+ for (String s : possibleMaps)
+ UtilPlayer.message(player, s);
+
+ return true;
+ }
+ else if (possibleMaps.size() == 0)
+ {
+ message(player, "No maps found with the name: " + F.elem(name));
+ return true;
+ }
+
+ String worldName = possibleMaps.get(0);
+ World world = getPlugin().GetMapWorld(worldName);
+
+ if (world != null)
+ {
+ if (!getPlugin().GetData(worldName).CanBuild(player))
+ {
+ message(player, "You do not have Build-Access on this Map.");
+ return true;
+ }
+
+ //Teleport Out
+ for (Player other : world.getPlayers())
+ other.teleport(new Location(getPlugin().getServer().getWorlds().get(0), 0, 106, 0));
+
+ //Unload World
+ MapUtil.UnloadWorld(getPlugin(), world, true);
+ }
+ else
+ {
+ message(player, "World is not loaded: " + F.elem(worldName));
+ return true;
+ }
+
+ getPlugin().Announce("Saved World: " + F.elem(args[0]));
+
+ return false;
+ }
+}
diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WorldsCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WorldsCommand.java
new file mode 100644
index 000000000..2b9d6331c
--- /dev/null
+++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WorldsCommand.java
@@ -0,0 +1,31 @@
+package mineplex.mapparser.command;
+
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import mineplex.core.common.util.F;
+import mineplex.core.common.util.UtilPlayer;
+import mineplex.mapparser.MapParser;
+
+/**
+ * Created by Shaun on 8/15/2014.
+ */
+public class WorldsCommand extends BaseCommand
+{
+ public WorldsCommand(MapParser plugin)
+ {
+ super(plugin, "worlds");
+ }
+
+ @Override
+ public boolean execute(Player player, String alias, String[] args)
+ {
+ message(player, "Listing Active Worlds;");
+
+ for (World world : getPlugin().getServer().getWorlds())
+ {
+ player.sendMessage(world.getName());
+ }
+ return true;
+ }
+}