2014-06-15 02:12:08 +02:00
|
|
|
package mineplex.mapparser;
|
|
|
|
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileWriter;
|
2014-06-26 21:09:29 +02:00
|
|
|
import java.io.IOException;
|
2014-06-15 02:12:08 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
import mineplex.core.common.util.F;
|
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
2014-06-15 02:12:08 +02:00
|
|
|
import mineplex.core.common.util.UtilWorld;
|
2014-06-26 21:09:29 +02:00
|
|
|
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
2014-06-15 02:12:08 +02:00
|
|
|
|
2014-06-26 05:53:28 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2014-06-26 21:09:29 +02:00
|
|
|
import org.bukkit.ChatColor;
|
2014-07-05 08:04:46 +02:00
|
|
|
import org.bukkit.GameMode;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2014-06-26 05:53:28 +02:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.World.Environment;
|
|
|
|
import org.bukkit.WorldCreator;
|
|
|
|
import org.bukkit.WorldType;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
import org.bukkit.block.Sign;
|
2014-07-05 08:04:46 +02:00
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
2014-07-05 08:04:46 +02:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
|
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
2014-07-05 08:04:46 +02:00
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.material.Wool;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2014-06-26 21:09:29 +02:00
|
|
|
import org.fusesource.jansi.Ansi.Color;
|
2014-06-15 02:12:08 +02:00
|
|
|
|
|
|
|
public class MapParser extends JavaPlugin implements Listener
|
|
|
|
{
|
2014-06-26 05:53:28 +02:00
|
|
|
private WorldManager _worldManager;
|
|
|
|
|
2014-06-15 02:12:08 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2014-06-26 05:53:28 +02:00
|
|
|
_worldManager = new WorldManager(this);
|
|
|
|
|
|
|
|
getServer().getPluginManager().registerEvents(this, this);
|
2014-06-15 02:12:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Command(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
2014-07-05 08:04:46 +02:00
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if (event.getMessage().toLowerCase().startsWith("/copyschematics"))
|
2014-06-26 21:09:29 +02:00
|
|
|
{
|
|
|
|
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"));
|
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
UtilPlayer.message(player, F.main("Parser", "Schematics Copied."));
|
2014-06-26 21:09:29 +02:00
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
UtilPlayer.message(player, F.main("Parser", "Schematics Copy Failed! Contact Jonalon."));
|
2014-06-26 21:09:29 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-05 08:04:46 +02:00
|
|
|
else if (event.getMessage().toLowerCase().startsWith("/createmap"))
|
2014-06-26 05:53:28 +02:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
|
|
|
String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
|
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
UtilPlayer.message(player, F.main("Parser", "Creating World: " + F.elem(args[0])));
|
|
|
|
|
2014-06-26 05:53:28 +02:00
|
|
|
WorldCreator worldCreator = new WorldCreator(args[0]);
|
|
|
|
worldCreator.environment(Environment.NORMAL);
|
|
|
|
worldCreator.type(WorldType.FLAT);
|
|
|
|
worldCreator.generateStructures(false);
|
|
|
|
|
|
|
|
World world = Bukkit.getServer().createWorld(worldCreator);
|
2014-07-05 08:04:46 +02:00
|
|
|
|
|
|
|
UtilPlayer.message(player, F.main("Parser", "Teleporting to World: " + F.elem(args[0])));
|
2014-06-15 02:12:08 +02:00
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
event.getPlayer().teleport(new Location(world, 0, 100, 0));
|
2014-06-26 05:53:28 +02:00
|
|
|
}
|
2014-07-05 08:04:46 +02:00
|
|
|
else if (event.getMessage().toLowerCase().startsWith("/loadmap"))
|
2014-06-26 05:53:28 +02:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
|
|
|
String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
|
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
UtilPlayer.message(player, F.main("Parser", "Loading World: " + F.elem(args[0])));
|
|
|
|
|
2014-06-26 05:53:28 +02:00
|
|
|
World world = _worldManager.loadPendingParse(event.getPlayer(), args[0]);
|
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
UtilPlayer.message(player, F.main("Parser", "Teleporting to World: " + F.elem(args[0])));
|
|
|
|
|
|
|
|
event.getPlayer().teleport(new Location(world, 0, 100, 0));
|
2014-06-26 05:53:28 +02:00
|
|
|
}
|
2014-07-05 08:04:46 +02:00
|
|
|
else if (event.getMessage().toLowerCase().startsWith("/listmaps"))
|
2014-06-26 05:53:28 +02:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
UtilPlayer.message(player, F.main("Parser", "Listing Worlds;"));
|
|
|
|
|
2014-06-26 05:53:28 +02:00
|
|
|
_worldManager.listPendingParses(event.getPlayer());
|
|
|
|
}
|
2014-07-05 08:04:46 +02:00
|
|
|
else if (event.getMessage().toLowerCase().startsWith("/parse"))
|
2014-06-26 21:09:29 +02:00
|
|
|
{
|
2014-06-26 05:53:28 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
|
|
|
|
String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
|
|
|
|
|
|
|
|
String gameType = args[0];
|
2014-06-26 21:09:29 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
GameType type = GameType.valueOf(gameType);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
event.getPlayer().sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Invalid gametype!");
|
|
|
|
event.getPlayer().sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Available games:");
|
|
|
|
|
|
|
|
for (GameType game : GameType.values())
|
|
|
|
{
|
|
|
|
event.getPlayer().sendMessage(game.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-26 05:53:28 +02:00
|
|
|
String msg = event.getMessage().replace(gameType, "").toLowerCase();
|
|
|
|
|
|
|
|
World world = player.getWorld();
|
|
|
|
|
|
|
|
// TODO teleport player to main world
|
|
|
|
player.teleport(new Location(Bukkit.getWorlds().get(0), 0, 100, 0));
|
|
|
|
|
|
|
|
String worldName = _worldManager.prepMapParse(world);
|
|
|
|
|
|
|
|
World parseableWorld = Bukkit.getWorld(worldName);
|
|
|
|
|
|
|
|
Parse(event.getPlayer(), parseableWorld, msg.split(" "));
|
|
|
|
|
|
|
|
_worldManager.finalizeParsedWorld(gameType, parseableWorld);
|
|
|
|
}
|
2014-06-15 02:12:08 +02:00
|
|
|
}
|
|
|
|
|
2014-06-26 05:53:28 +02:00
|
|
|
public void Parse(Player caller, World world, String[] args)
|
2014-06-15 02:12:08 +02:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2014-06-26 05:53:28 +02:00
|
|
|
Block block = world.getBlockAt(caller.getLocation().getBlockX()+x, caller.getLocation().getBlockY()+y, caller.getLocation().getBlockZ()+z);
|
2014-06-15 02:12:08 +02:00
|
|
|
|
|
|
|
//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
|
|
|
|
{
|
2014-06-26 05:53:28 +02:00
|
|
|
FileWriter fstream = new FileWriter(world.getName() + File.separator + "WorldConfig.dat");
|
2014-06-15 02:12:08 +02:00
|
|
|
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;
|
|
|
|
}
|
2014-07-05 08:04:46 +02:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void DisableCreatures(EntitySpawnEvent event)
|
|
|
|
{
|
|
|
|
if (event.getEntityType() == EntityType.DROPPED_ITEM || event.getEntity() instanceof LivingEntity)
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Updates(PlayerMoveEvent event)
|
|
|
|
{
|
|
|
|
for (World world : this.getServer().getWorlds())
|
|
|
|
world.setTime(8000);
|
|
|
|
|
|
|
|
if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
|
|
|
event.getPlayer().setGameMode(GameMode.CREATIVE);
|
|
|
|
|
|
|
|
if (!event.getPlayer().isOp())
|
|
|
|
event.getPlayer().setOp(true);
|
|
|
|
}
|
2014-06-15 02:12:08 +02:00
|
|
|
}
|