diff --git a/Plugins/BuildFiles/common.xml b/Plugins/BuildFiles/common.xml index c0e76de17..657cd1daf 100644 --- a/Plugins/BuildFiles/common.xml +++ b/Plugins/BuildFiles/common.xml @@ -64,9 +64,9 @@ - - - + + + @@ -74,7 +74,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/Plugins/Mineplex.MapParser/.classpath b/Plugins/Mineplex.MapParser/.classpath new file mode 100644 index 000000000..87e96b6e1 --- /dev/null +++ b/Plugins/Mineplex.MapParser/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Plugins/Mineplex.MapParser/.externalToolBuilders/MapParser Builder.launch b/Plugins/Mineplex.MapParser/.externalToolBuilders/MapParser Builder.launch new file mode 100644 index 000000000..a8d58ebe5 --- /dev/null +++ b/Plugins/Mineplex.MapParser/.externalToolBuilders/MapParser Builder.launch @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Plugins/Mineplex.MapParser/.project b/Plugins/Mineplex.MapParser/.project new file mode 100644 index 000000000..03de90b0d --- /dev/null +++ b/Plugins/Mineplex.MapParser/.project @@ -0,0 +1,26 @@ + + + Mineplex.MapParser + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + + + LaunchConfigHandle + <project>/.externalToolBuilders/MapParser Builder.launch + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Plugins/Mineplex.MapParser/.settings/org.eclipse.jdt.core.prefs b/Plugins/Mineplex.MapParser/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..7341ab168 --- /dev/null +++ b/Plugins/Mineplex.MapParser/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Plugins/Mineplex.MapParser/plugin.yml b/Plugins/Mineplex.MapParser/plugin.yml new file mode 100644 index 000000000..49dfd0c3d --- /dev/null +++ b/Plugins/Mineplex.MapParser/plugin.yml @@ -0,0 +1,3 @@ +name: MapParser +main: Mineplex.MapParser +version: 1 \ No newline at end of file diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java new file mode 100644 index 000000000..5a9b241b9 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -0,0 +1,464 @@ +package mineplex.mapparser; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +import mineplex.core.common.util.UtilWorld; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.material.Wool; +import org.bukkit.plugin.java.JavaPlugin; + +public class MapParser extends JavaPlugin implements Listener +{ + @Override + public void onEnable() + { + this.getServer().getPluginManager().registerEvents(this, this); + } + + @Override + public void onDisable() + { + + } + + @EventHandler + public void Command(PlayerCommandPreprocessEvent event) + { + if (!event.getMessage().startsWith("/parse")) + return; + + event.setCancelled(true); + + String msg = event.getMessage().toLowerCase(); + + Parse(event.getPlayer(), msg.split(" ")); + } + + public void Parse(Player caller, String[] args) + { + HashSet dataId = new HashSet(); + + for (String arg : args) + { + if (arg.equals("/parse")) + continue; + + try + { + dataId.add(Integer.parseInt(arg)); + } + catch (Exception e) + { + caller.sendMessage("Invalid Data ID: " + arg); + } + } + + HashMap> TeamLocs = new HashMap>(); + HashMap> DataLocs = new HashMap>(); + HashMap> CustomLocs = new HashMap>(); + + Location cornerA = null; + Location cornerB = null; + + int processed = 0; + + caller.sendMessage("Scanning for Blocks..."); + + for (int x=-600 ; x < 600 ; x++) + for (int z=-600 ; z < 600 ; z++) + for (int y=0 ; y < 256 ; y++) + { + processed++; + if (processed % 20000000 == 0) + caller.sendMessage("Processed: " + processed + " of " + (1200*1200*256)); + + Block block = caller.getWorld().getBlockAt(caller.getLocation().getBlockX()+x, caller.getLocation().getBlockY()+y, caller.getLocation().getBlockZ()+z); + + //ID DATA + if (dataId.contains(block.getTypeId())) + { + String key = ""+block.getTypeId(); + + if (!CustomLocs.containsKey(key)) + CustomLocs.put(key, new ArrayList()); + + CustomLocs.get(key).add(block.getLocation()); + continue; + } + + //Signs + if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) + { + if (block.getRelative(BlockFace.DOWN).getType() == Material.SPONGE) + { + Sign s = (Sign) block.getState(); + + String name = ""; + + try + { + name = s.getLine(0); + } + catch (Exception e) + { + caller.sendMessage("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); + } + + //Add + if (!CustomLocs.containsKey(name)) + CustomLocs.put(name, new ArrayList()); + + CustomLocs.get(name).add(block.getRelative(BlockFace.DOWN).getLocation()); + + //Remove Blocks + block.setTypeId(0); + block.getRelative(BlockFace.DOWN).setTypeId(0); + } + } + + //Spawns + Borders + if (block.getTypeId() == 147) + { + Block wool = block.getRelative(BlockFace.DOWN); + if (wool == null) + continue; + + if (wool.getType() == Material.WOOL) + { + if (wool.getData() == 0) + { + if (cornerA == null) cornerA = wool.getLocation(); + else if (cornerB == null) cornerB = wool.getLocation(); + else + { + caller.sendMessage("More than 2 Corner Markers:"); + caller.sendMessage("Corner A: " + cornerA); + caller.sendMessage("Corner B: " + cornerB); + caller.sendMessage("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); + } + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 1) + { + if (!TeamLocs.containsKey("Orange")) + TeamLocs.put("Orange", new ArrayList()); + + TeamLocs.get("Orange").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 2) + { + if (!TeamLocs.containsKey("Magenta")) + TeamLocs.put("Magenta", new ArrayList()); + + TeamLocs.get("Magenta").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 3) + { + if (!TeamLocs.containsKey("Sky")) + TeamLocs.put("Sky", new ArrayList()); + + TeamLocs.get("Sky").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 4) + { + if (!TeamLocs.containsKey("Yellow")) + TeamLocs.put("Yellow", new ArrayList()); + + TeamLocs.get("Yellow").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 5) + { + if (!TeamLocs.containsKey("Lime")) + TeamLocs.put("Lime", new ArrayList()); + + TeamLocs.get("Lime").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 6) + { + if (!TeamLocs.containsKey("Pink")) + TeamLocs.put("Pink", new ArrayList()); + + TeamLocs.get("Pink").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 7) + { + if (!TeamLocs.containsKey("Gray")) + TeamLocs.put("Gray", new ArrayList()); + + TeamLocs.get("Gray").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 8) + { + if (!TeamLocs.containsKey("LGray")) + TeamLocs.put("LGray", new ArrayList()); + + TeamLocs.get("LGray").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 9) + { + if (!TeamLocs.containsKey("Cyan")) + TeamLocs.put("Cyan", new ArrayList()); + + TeamLocs.get("Cyan").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 10) + { + if (!TeamLocs.containsKey("Purple")) + TeamLocs.put("Purple", new ArrayList()); + + TeamLocs.get("Purple").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 11) + { + if (!TeamLocs.containsKey("DBlue")) + TeamLocs.put("DBlue", new ArrayList()); + + TeamLocs.get("DBlue").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 12) + { + if (!TeamLocs.containsKey("Brown")) + TeamLocs.put("Brown", new ArrayList()); + + TeamLocs.get("Brown").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 13) + { + if (!TeamLocs.containsKey("Green")) + TeamLocs.put("Green", new ArrayList()); + + TeamLocs.get("Green").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 14) + { + if (!TeamLocs.containsKey("Red")) + TeamLocs.put("Red", new ArrayList()); + + TeamLocs.get("Red").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (wool.getData() == 15) + { + if (!TeamLocs.containsKey("Black")) + TeamLocs.put("Black", new ArrayList()); + + TeamLocs.get("Black").add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + } + } + + if (block.getTypeId() != 148) + continue; + + Block wool = block.getRelative(BlockFace.DOWN); + if (wool == null) + continue; + + if (wool.getType() != Material.WOOL) + continue; + + Wool woolData = new Wool(wool.getType(), wool.getData()); + + String dataType = woolData.getColor().name(); + + if (!DataLocs.containsKey(dataType)) + DataLocs.put(dataType, new ArrayList()); + + DataLocs.get(dataType).add(wool.getLocation()); + + //Remove Blocks + block.setTypeId(0); + wool.setTypeId(0); + } + + if (cornerA == null || cornerB == null) + { + caller.sendMessage("Missing Corner Locations!"); + return; + } + + //Save + try + { + FileWriter fstream = new FileWriter(caller.getWorld().getName() + File.separator + "WorldConfig.dat"); + BufferedWriter out = new BufferedWriter(fstream); + + out.write("MAP_NAME:"); + out.write("\n"); + out.write("MAP_AUTHOR:"); + out.write("\n"); + out.write("\n"); + out.write("MIN_X:"+Math.min(cornerA.getBlockX(), cornerB.getBlockX())); + out.write("\n"); + out.write("MAX_X:"+Math.max(cornerA.getBlockX(), cornerB.getBlockX())); + out.write("\n"); + out.write("MIN_Z:"+Math.min(cornerA.getBlockZ(), cornerB.getBlockZ())); + out.write("\n"); + out.write("MAX_Z:"+Math.max(cornerA.getBlockZ(), cornerB.getBlockZ())); + out.write("\n"); + out.write("\n"); + if (cornerA.getBlockY() == cornerB.getBlockY()) + { + out.write("MIN_Y:0"); + out.write("\n"); + out.write("MAX_Y:256"); + } + else + { + out.write("MIN_Y:"+Math.min(cornerA.getBlockY(), cornerB.getBlockY())); + out.write("\n"); + out.write("MAX_Y:"+Math.max(cornerA.getBlockY(), cornerB.getBlockY())); + } + + //Teams + for (String team : TeamLocs.keySet()) + { + out.write("\n"); + out.write("\n"); + out.write("TEAM_NAME:" + team); + out.write("\n"); + out.write("TEAM_SPAWNS:" + LocationsToString(TeamLocs.get(team))); + } + + //Data + for (String data : DataLocs.keySet()) + { + out.write("\n"); + out.write("\n"); + out.write("DATA_NAME:" + data); + out.write("\n"); + out.write("DATA_LOCS:" + LocationsToString(DataLocs.get(data))); + } + + //Custom + for (String data : CustomLocs.keySet()) + { + out.write("\n"); + out.write("\n"); + out.write("CUSTOM_NAME:" + data); + out.write("\n"); + out.write("CUSTOM_LOCS:" + LocationsToString(CustomLocs.get(data))); + } + + out.close(); + } + catch (Exception e) + { + caller.sendMessage("Error: File Write Error"); + } + + + caller.sendMessage("World Data Saved."); + } + + public String LocationsToString(ArrayList locs) + { + String out = ""; + + for (Location loc : locs) + out += loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":"; + + return out; + } + + public String LocationSignsToString(HashMap locs) + { + String out = ""; + + for (Location loc : locs.keySet()) + out += locs.get(loc) + "@" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":"; + + return out; + } +}