Bridges fix being able to break mid chests before gamestart

Map parser Updates
This commit is contained in:
Mini-Chiss 2014-07-07 19:04:44 -07:00
parent ef86fe6948
commit cf25bdc44f
5 changed files with 468 additions and 374 deletions

View File

@ -175,7 +175,15 @@ public class MapUtil
public static void UnloadWorld(JavaPlugin plugin, World world) public static void UnloadWorld(JavaPlugin plugin, World world)
{ {
world.setAutoSave(false); UnloadWorld(plugin, world, false);
}
public static void UnloadWorld(JavaPlugin plugin, World world, boolean save)
{
if (save)
world.save();
world.setAutoSave(save);
for (Entity entity : world.getEntities()) for (Entity entity : world.getEntities())
{ {

View File

@ -117,7 +117,7 @@ public class MapParser extends JavaPlugin implements Listener
String worldName = "map_" + args[0]; String worldName = "map_" + args[0];
UtilPlayer.message(caller, F.main("Parser", "Creating World: " + F.elem(worldName))); Announce("Creating World: " + F.elem(worldName));
WorldCreator worldCreator = new WorldCreator(worldName); WorldCreator worldCreator = new WorldCreator(worldName);
worldCreator.environment(Environment.NORMAL); worldCreator.environment(Environment.NORMAL);
@ -140,7 +140,7 @@ public class MapParser extends JavaPlugin implements Listener
if (!DoesMapExist(worldName)) if (!DoesMapExist(worldName))
{ {
UtilPlayer.message(caller, F.main("Parser", "World does not exist: " + F.elem(worldName))); UtilPlayer.message(caller, F.main("Parser", "Map does not exist: " + F.elem(worldName)));
return; return;
} }
@ -159,7 +159,34 @@ public class MapParser extends JavaPlugin implements Listener
//Delete //Delete
FileUtils.deleteQuietly(new File(worldName)); FileUtils.deleteQuietly(new File(worldName));
Inform(caller, "Deleted World: " + F.elem(args[0])); Announce("Deleted World: " + F.elem(args[0]));
}
else if (event.getMessage().toLowerCase().startsWith("/save"))
{
event.setCancelled(true);
String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
String worldName = "map_" + args[0];
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, 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")) else if (event.getMessage().toLowerCase().startsWith("/hub"))
{ {
@ -175,19 +202,16 @@ public class MapParser extends JavaPlugin implements Listener
String worldName = "map_" + args[0]; String worldName = "map_" + args[0];
UtilPlayer.message(caller, F.main("Parser", "Loading Map: " + F.elem(worldName)));
World world = GetMapWorld(worldName); World world = GetMapWorld(worldName);
if (world == null) if (world == null)
{ {
if (DoesMapExist(worldName)) if (DoesMapExist(worldName))
{ {
UtilPlayer.message(caller, F.main("Parser", "Map Exists!")); world = Bukkit.createWorld(new WorldCreator(worldName));
world = Bukkit.getWorld(worldName);
} }
else else
{ {
UtilPlayer.message(caller, F.main("Parser", "Map Doesn't Exist!")); UtilPlayer.message(caller, F.main("Parser", "Map Not Found: " + F.elem(worldName)));
return; return;
} }
} }
@ -278,7 +302,7 @@ public class MapParser extends JavaPlugin implements Listener
World parseableWorld = Bukkit.getWorld(worldName); World parseableWorld = Bukkit.getWorld(worldName);
//Parse the World //Parse the World
Parse(event.getPlayer(), parseableWorld, msg.split(" "), parseLoc); Parse(parseableWorld, msg.split(" "), parseLoc);
//Finalize and Save to Zip //Finalize and Save to Zip
_worldManager.finalizeParsedWorld(gameType, parseableWorld); _worldManager.finalizeParsedWorld(gameType, parseableWorld);
@ -296,9 +320,9 @@ public class MapParser extends JavaPlugin implements Listener
} }
} }
public void Parse(Player caller, World world, String[] args, Location loc) public void Parse(World world, String[] args, Location loc)
{ {
_curParse = new Parse(this, world, args, caller, loc); _curParse = new Parse(this, world, args, loc);
} }
@EventHandler @EventHandler
@ -335,6 +359,22 @@ public class MapParser extends JavaPlugin implements Listener
event.getPlayer().setOp(true); event.getPlayer().setOp(true);
} }
@EventHandler
public void SaveUnloadWorlds(TickEvent event)
{
for (World world : getServer().getWorlds())
{
if (world.getName().equalsIgnoreCase("world"))
continue;
if (world.getPlayers().isEmpty())
{
Announce("Saving & Closing World: " + F.elem(world.getName()));
MapUtil.UnloadWorld(this, world, true);
}
}
}
public void Announce(String msg) public void Announce(String msg)
{ {
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
@ -345,13 +385,6 @@ public class MapParser extends JavaPlugin implements Listener
} }
} }
public void Inform(Player player, String message)
{
UtilPlayer.message(player, F.main("Parser", message));
System.out.println(message);
}
public boolean DoesMapExist(String name) public boolean DoesMapExist(String name)
{ {
File mapsFolder = new File("."); File mapsFolder = new File(".");

View File

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import org.bukkit.Location; import org.bukkit.Location;
@ -25,10 +26,12 @@ public class Parse
private MapParser Host; private MapParser Host;
private World _world; private World _world;
private String[] _args; private String[] _args;
private Player _caller;
private Location _callLoc; private Location _callLoc;
private int _size = 400; private int _size = 400;
private int y = 0;
private int _x = 0;
private int _y = 0;
private int _z = 0;
//World Data //World Data
private HashSet<Integer> _dataId = new HashSet<Integer>(); private HashSet<Integer> _dataId = new HashSet<Integer>();
@ -41,14 +44,13 @@ public class Parse
private int _processed = 0; private int _processed = 0;
public Parse(MapParser host, World world, String[] args, Player caller, Location loc) public Parse(MapParser host, World world, String[] args, Location loc)
{ {
Host = host; Host = host;
_world = world; _world = world;
_args = args; _args = args;
_callLoc = loc; _callLoc = new Location(world, loc.getX(), loc.getY(), loc.getZ());
Host.Announce("Parse Called: " + F.elem(caller.getName()));
Initialize(); Initialize();
} }
@ -69,22 +71,37 @@ public class Parse
} }
catch (Exception e) catch (Exception e)
{ {
_caller.sendMessage("Invalid Data ID: " + arg); Host.Announce("Invalid Data ID: " + F.elem(arg));
} }
} }
_x = -_size;
_z = -_size;
_y = 0;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean Update() public boolean Update()
{ {
for (int x=-_size ; x < _size ; x++) long startTime = System.currentTimeMillis();
for (int z=-_size ; z < _size ; z++)
{
_processed++;
if (_processed % 20000000 == 0)
Host.Announce("Processed: " + F.elem((int)(_processed/1000000) + "M of " + (int)(((_size*2)*(_size*2)*256)/1000000) + "M"));
Block block = _world.getBlockAt(_callLoc.getBlockX()+x, _callLoc.getBlockY()+y, _callLoc.getBlockZ()+z); for ( ; _x <= _size ; _x++)
{
for ( ; _z <= _size ; _z++)
{
for ( ; _y <= 256 ; _y++)
{
if (UtilTime.elapsed(startTime, 10))
return false;
_processed++;
if (_processed % 10000000 == 0)
Host.Announce("Scanning World: " + F.elem((int)(_processed/1000000) + "M of " + (int)(((_size*2)*(_size*2)*256)/1000000) + "M"));
Block block = _world.getBlockAt(_callLoc.getBlockX()+_x, _y, _callLoc.getBlockZ()+_z);
//if (block.getType() != Material.AIR)
// System.out.println(_world.getName() + " " + _x + " " + _y + " " + _z + " " + block.getType());
//ID DATA //ID DATA
if (_dataId.contains(block.getTypeId())) if (_dataId.contains(block.getTypeId()))
@ -133,19 +150,32 @@ public class Parse
{ {
Block wool = block.getRelative(BlockFace.DOWN); Block wool = block.getRelative(BlockFace.DOWN);
if (wool == null) if (wool == null)
{
continue; continue;
}
if (wool.getType() == Material.WOOL) if (wool.getType() == Material.WOOL)
{ {
if (wool.getData() == 0) if (wool.getData() == 0)
{ {
if (_cornerA == null) _cornerA = wool.getLocation(); if (_cornerA == null)
else if (_cornerB == null) _cornerB = wool.getLocation(); {
_cornerA = wool.getLocation();
Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA));
}
else if (_cornerB == null)
{
_cornerB = wool.getLocation();
Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerA));
}
else else
{ {
Host.Announce("More than 2 Corner Markers:"); Host.Announce("More than 2 Corner Markers:");
Host.Announce("Corner A: " + _cornerA); Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA));
Host.Announce("Corner B: " + _cornerB); Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB));
Host.Announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); Host.Announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation()));
} }
@ -360,15 +390,17 @@ public class Parse
wool.setTypeId(0); wool.setTypeId(0);
} }
y++; _y = 0;
}
_z = -_size;
}
//Finalize //Finalize
if (y > 255)
{
if (_cornerA == null || _cornerB == null) if (_cornerA == null || _cornerB == null)
{ {
Host.Announce("Missing Corner Locations!"); Host.Announce("Missing Corner Locations! Defaulted to -256 to +256.");
Host.Announce("Defaulted to -256 to +256");
_cornerA = new Location(_world, -256, 0, -256); _cornerA = new Location(_world, -256, 0, -256);
_cornerB = new Location(_world, 256, 0, 256); _cornerB = new Location(_world, 256, 0, 256);
@ -445,9 +477,8 @@ public class Parse
} }
Host.Announce("WorldConfig.dat Saved."); Host.Announce("WorldConfig.dat Saved.");
}
return false; return true;
} }
public String LocationsToString(ArrayList<Location> locs) public String LocationsToString(ArrayList<Location> locs)

View File

@ -26,7 +26,7 @@ public class WorldManager
public String prepMapParse(World world) public String prepMapParse(World world)
{ {
//Unload World //Unload World
MapUtil.UnloadWorld(_plugin, world); MapUtil.UnloadWorld(_plugin, world, true);
//Delete Non-Map Files //Delete Non-Map Files
String[] folders = new File(world.getName()).list(); String[] folders = new File(world.getName()).list();
@ -94,5 +94,8 @@ public class WorldManager
{ {
e.printStackTrace(); e.printStackTrace();
} }
//Delete Parse Map
FileUtils.deleteQuietly(new File(world.getName()));
} }
} }

View File

@ -337,6 +337,25 @@ public class Bridge extends TeamGame implements OreObsfucation
} }
} }
@EventHandler
public void ChestDeny(BlockBreakEvent event)
{
if (_bridgesDown)
return;
if (event.getBlock().getType() != Material.CHEST)
return;
for (Location loc : WorldData.GetCustomLocs("54"))
{
if (loc.getBlock().equals(event.getBlock()))
{
event.setCancelled(true);
return;
}
}
}
private void ParseOre(ArrayList<Location> teamOre) private void ParseOre(ArrayList<Location> teamOre)
{ {
int coal = (int) ((teamOre.size() / 32d) * _oreDensity); int coal = (int) ((teamOre.size() / 32d) * _oreDensity);