Map Parser

This commit is contained in:
Chiss 2014-06-15 10:12:08 +10:00
parent 2170f743dd
commit bac071e084
7 changed files with 535 additions and 5 deletions

View File

@ -64,9 +64,9 @@
</jar>
<copy file="../bin/Hub.jar" todir="../../Testing/Hub/plugins"/>
</target>
<target name ="MagicMC" description="MagicMC">
<jar jarfile="../bin/MagicMC.jar">
<fileset dir="../MagicMC/bin">
<target name ="MapParser" description="MapParser">
<jar jarfile="../bin/MapParser.jar">
<fileset dir="../Mineplex.MapParser/bin">
<include name="**/*.class"/>
</fileset>
@ -74,7 +74,7 @@
<include name="**/*.class"/>
</fileset>
<fileset dir="../MagicMC">
<fileset dir="../Mineplex.MapParser">
<include name="*.yml"/>
</fileset>
@ -86,7 +86,7 @@
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
</jar>
<copy file="../bin/MagicMC.jar" todir="../../Testing/MagicMC/plugins"/>
<copy file="../bin/MapParser.jar" todir="../../Testing/Build/plugins"/>
</target>
<target name="NautilusCraftBukkit2" description="NautilusCraftBukkit2">
<mkdir dir="../bin/craftbukkit_temp" />

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="MapParser,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="MapParser,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_CLEAN_TARGETS" value="MapParser,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="MapParser,"/>
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}\common.xml"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,clean"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.MapParser}"/>
</launchConfiguration>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Mineplex.MapParser</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/MapParser Builder.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -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

View File

@ -0,0 +1,3 @@
name: MapParser
main: Mineplex.MapParser
version: 1

View File

@ -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<Integer> dataId = new HashSet<Integer>();
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<String, ArrayList<Location>> TeamLocs = new HashMap<String, ArrayList<Location>>();
HashMap<String, ArrayList<Location>> DataLocs = new HashMap<String, ArrayList<Location>>();
HashMap<String, ArrayList<Location>> CustomLocs = new HashMap<String, ArrayList<Location>>();
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location>());
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<Location> locs)
{
String out = "";
for (Location loc : locs)
out += loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":";
return out;
}
public String LocationSignsToString(HashMap<Location, String> locs)
{
String out = "";
for (Location loc : locs.keySet())
out += locs.get(loc) + "@" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":";
return out;
}
}