Fix setup issue and remove region expansion
This commit consists of two components: - Restarts are no longer required after setting up the first arena - Regions no longer auto-expand The restart requirement is fixed by preventing the ArenaMaster from actually creating an Arena object and assigning it to the selected arena upon generating the default arena node in the config-file. The problem was that the selected arena was set to this initial Arena object, but another Arena object was created afterwards, which due to the equals() method of ArenaImpl overwrote the previously created Arena object in the arenas-list, but didn't change the reference in the selected arena. In other words; two identical Arena objects were created, but used in different places (arena list vs. selected arena). The auto-expansion is removed by simply never auto-expanding regions upon setting the arena warp or spawnpoints. Instead, setting these warps throws an error, if p1 and p2 have not yet been set, or if the location is outside the region.
This commit is contained in:
@@ -488,7 +488,7 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
|
|
||||||
// If no arenas were found, create a default node.
|
// If no arenas were found, create a default node.
|
||||||
if (arenanames == null || arenanames.isEmpty()) {
|
if (arenanames == null || arenanames.isEmpty()) {
|
||||||
createArenaNode("default", plugin.getServer().getWorlds().get(0));
|
createArenaNode("default", plugin.getServer().getWorlds().get(0), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
arenas = new LinkedList<Arena>();
|
arenas = new LinkedList<Arena>();
|
||||||
@@ -571,6 +571,10 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Arena createArenaNode(String arenaName, World world) {
|
public Arena createArenaNode(String arenaName, World world) {
|
||||||
|
return createArenaNode(arenaName, world, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Arena createArenaNode(String arenaName, World world, boolean load) {
|
||||||
String path = "arenas." + arenaName;
|
String path = "arenas." + arenaName;
|
||||||
if (config.getConfigSection(path) != null)
|
if (config.getConfigSection(path) != null)
|
||||||
throw new IllegalArgumentException("Arena already exists!");
|
throw new IllegalArgumentException("Arena already exists!");
|
||||||
@@ -589,7 +593,7 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
// Load the arena
|
// Load the arena
|
||||||
return loadArena(arenaName);
|
return (load ? loadArena(arenaName) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeArenaNode(Arena arena) {
|
public void removeArenaNode(Arena arena) {
|
||||||
|
|||||||
@@ -34,8 +34,18 @@ public class AddSpawnpointCommand implements Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
am.getSelectedArena().getRegion().addSpawn(arg1, p.getLocation());
|
// Make sure we're inside the region
|
||||||
Messenger.tellPlayer(sender, "Spawnpoint " + arg1 + " added for arena \"" + am.getSelectedArena().configName() + "\"");
|
if (am.getSelectedArena().getRegion().contains(p.getLocation())) {
|
||||||
|
am.getSelectedArena().getRegion().addSpawn(arg1, p.getLocation());
|
||||||
|
Messenger.tellPlayer(sender, "Spawnpoint " + arg1 + " added for arena \"" + am.getSelectedArena().configName() + "\"");
|
||||||
|
} else {
|
||||||
|
// If not, make sure the region is defined
|
||||||
|
if (am.getSelectedArena().getRegion().isDefined()) {
|
||||||
|
Messenger.tellPlayer(sender, "You must be inside the arena region!");
|
||||||
|
} else {
|
||||||
|
Messenger.tellPlayer(sender, "You must first set the region points p1 and p2");
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class RemoveContainerCommand implements Command
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (am.getSelectedArena().getRegion().removeSpawn(arg1))
|
if (am.getSelectedArena().getRegion().removeChest(arg1))
|
||||||
Messenger.tellPlayer(sender, "Container " + arg1 + " removed for arena '" + am.getSelectedArena().configName() + "'");
|
Messenger.tellPlayer(sender, "Container " + arg1 + " removed for arena '" + am.getSelectedArena().configName() + "'");
|
||||||
else
|
else
|
||||||
Messenger.tellPlayer(sender, "Could not find the container " + arg1 + "for the arena '" + am.getSelectedArena().configName() + "'");
|
Messenger.tellPlayer(sender, "Could not find the container " + arg1 + "for the arena '" + am.getSelectedArena().configName() + "'");
|
||||||
|
|||||||
@@ -34,9 +34,18 @@ public class SetWarpCommand implements Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
am.getSelectedArena().getRegion().set(arg1, p.getLocation());
|
// Make sure the arena warp is inside the region
|
||||||
Messenger.tellPlayer(sender, "Warp point " + arg1 + " was set for arena '" + am.getSelectedArena().configName() + "'");
|
if (arg1.equals("arena") && !am.getSelectedArena().getRegion().contains(p.getLocation())) {
|
||||||
Messenger.tellPlayer(sender, "Type /ma checkdata to see if you're missing anything...");
|
if (am.getSelectedArena().getRegion().isDefined()) {
|
||||||
|
Messenger.tellPlayer(sender, "You must be inside the arena region!");
|
||||||
|
} else {
|
||||||
|
Messenger.tellPlayer(sender, "You must first set the region points p1 and p2");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
am.getSelectedArena().getRegion().set(arg1, p.getLocation());
|
||||||
|
Messenger.tellPlayer(sender, "Warp point " + arg1 + " was set for arena '" + am.getSelectedArena().configName() + "'");
|
||||||
|
Messenger.tellPlayer(sender, "Type /ma checkdata to see if you're missing anything...");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ public class ArenaRegion
|
|||||||
this.chests = coords.getConfigSection("containers");
|
this.chests = coords.getConfigSection("containers");
|
||||||
|
|
||||||
reloadAll();
|
reloadAll();
|
||||||
adjustRegion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadAll() {
|
public void reloadAll() {
|
||||||
@@ -60,9 +59,11 @@ public class ArenaRegion
|
|||||||
public void reloadRegion() {
|
public void reloadRegion() {
|
||||||
p1 = coords.getLocation("p1", world);
|
p1 = coords.getLocation("p1", world);
|
||||||
p2 = coords.getLocation("p2", world);
|
p2 = coords.getLocation("p2", world);
|
||||||
|
fixRegion();
|
||||||
|
|
||||||
l1 = coords.getLocation("l1", world);
|
l1 = coords.getLocation("l1", world);
|
||||||
l2 = coords.getLocation("l2", world);
|
l2 = coords.getLocation("l2", world);
|
||||||
|
fixLobbyRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadWarps() {
|
public void reloadWarps() {
|
||||||
@@ -149,7 +150,7 @@ public class ArenaRegion
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(Location l) {
|
public boolean contains(Location l) {
|
||||||
if (!l.getWorld().getName().equals(world.getName()) || !setup) {
|
if (!l.getWorld().getName().equals(world.getName()) || !isDefined()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ public class ArenaRegion
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(Location l, int radius) {
|
public boolean contains(Location l, int radius) {
|
||||||
if (!l.getWorld().getName().equals(world.getName()) || !setup) {
|
if (!l.getWorld().getName().equals(world.getName()) || !isDefined()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,88 +265,42 @@ public class ArenaRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean modified = false;
|
||||||
|
|
||||||
if (loc1.getX() > loc2.getX()) {
|
if (loc1.getX() > loc2.getX()) {
|
||||||
double tmp = loc1.getX();
|
double tmp = loc1.getX();
|
||||||
loc1.setX(loc2.getX());
|
loc1.setX(loc2.getX());
|
||||||
loc2.setX(tmp);
|
loc2.setX(tmp);
|
||||||
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loc1.getZ() > loc2.getZ()) {
|
if (loc1.getZ() > loc2.getZ()) {
|
||||||
double tmp = loc1.getZ();
|
double tmp = loc1.getZ();
|
||||||
loc1.setZ(loc2.getZ());
|
loc1.setZ(loc2.getZ());
|
||||||
loc2.setZ(tmp);
|
loc2.setZ(tmp);
|
||||||
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loc1.getY() > loc2.getY()) {
|
if (loc1.getY() > loc2.getY()) {
|
||||||
double tmp = loc1.getY();
|
double tmp = loc1.getY();
|
||||||
loc1.setY(loc2.getY());
|
loc1.setY(loc2.getY());
|
||||||
loc2.setY(tmp);
|
loc2.setY(tmp);
|
||||||
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!arena.getWorld().getName().equals(world.getName()))
|
if (!arena.getWorld().getName().equals(world.getName())) {
|
||||||
arena.setWorld(world);
|
arena.setWorld(world);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!modified) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
coords.set(location1, loc1);
|
coords.set(location1, loc1);
|
||||||
coords.set(location2, loc2);
|
coords.set(location2, loc2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void adjustRegion() {
|
|
||||||
if (!setup) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the arena warp is inside the region.
|
|
||||||
readjustRegion(arenaWarp);
|
|
||||||
|
|
||||||
// Re-adjust for all spawnpoints and containers.
|
|
||||||
for (Location spawnpoint : spawnpoints.values()) {
|
|
||||||
readjustRegion(spawnpoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Location chest : containers.values()) {
|
|
||||||
readjustRegion(chest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void readjustRegion(Location l) {
|
|
||||||
if (p1 == null || p2 == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x = l.getBlockX();
|
|
||||||
int y = l.getBlockY();
|
|
||||||
int z = l.getBlockZ();
|
|
||||||
|
|
||||||
int p1x = p1.getBlockX();
|
|
||||||
int p1y = p1.getBlockY();
|
|
||||||
int p1z = p1.getBlockZ();
|
|
||||||
|
|
||||||
int p2x = p2.getBlockX();
|
|
||||||
int p2y = p2.getBlockY();
|
|
||||||
int p2z = p2.getBlockZ();
|
|
||||||
|
|
||||||
if (x <= p1x) {
|
|
||||||
expandP1(p1x - x + 2, 0);
|
|
||||||
}
|
|
||||||
else if (x >= p2x) {
|
|
||||||
expandP2(x - p2x + 2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y <= p1y) {
|
|
||||||
expandDown((int) (p1y - y + 2));
|
|
||||||
}
|
|
||||||
else if (y >= p2y) {
|
|
||||||
expandUp((int) (y - p2y + 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (z <= p1z) {
|
|
||||||
expandP1(0, p1z - z + 2);
|
|
||||||
}
|
|
||||||
else if (z >= p2z) {
|
|
||||||
expandP2(0, z - p2z + 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Chunk> getChunks() {
|
public List<Chunk> getChunks() {
|
||||||
List<Chunk> result = new ArrayList<Chunk>();
|
List<Chunk> result = new ArrayList<Chunk>();
|
||||||
|
|
||||||
@@ -398,56 +353,64 @@ public class ArenaRegion
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void set(String point, Location loc) {
|
public void set(String point, Location loc) {
|
||||||
|
// Set the point and save
|
||||||
coords.set(point, loc);
|
coords.set(point, loc);
|
||||||
|
save();
|
||||||
|
|
||||||
// Adjust the region to accomodate any bounding box breaking.
|
// Reload region, warps and leaderboards
|
||||||
if (point.equals("arena") || point.equals("lobby") || point.equals("spectator")) {
|
|
||||||
readjustRegion(loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
fixRegion();
|
|
||||||
fixLobbyRegion();
|
|
||||||
reloadRegion();
|
reloadRegion();
|
||||||
reloadWarps();
|
reloadWarps();
|
||||||
reloadLeaderboards();
|
reloadLeaderboards();
|
||||||
verifyData();
|
verifyData();
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSpawn(String name, Location loc) {
|
public void addSpawn(String name, Location loc) {
|
||||||
|
// Add the spawn and save
|
||||||
spawns.set(name, loc);
|
spawns.set(name, loc);
|
||||||
readjustRegion(loc);
|
save();
|
||||||
|
|
||||||
|
// Reload spawnpoints and verify data
|
||||||
reloadSpawnpoints();
|
reloadSpawnpoints();
|
||||||
verifyData();
|
verifyData();
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeSpawn(String name) {
|
public boolean removeSpawn(String name) {
|
||||||
|
// Check if the spawnpoint exists
|
||||||
if (spawns.getString(name) == null) {
|
if (spawns.getString(name) == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Null the spawnpoint and save
|
||||||
spawns.set(name, null);
|
spawns.set(name, null);
|
||||||
|
save();
|
||||||
|
|
||||||
|
// Reload spawnpoints and verify data
|
||||||
reloadSpawnpoints();
|
reloadSpawnpoints();
|
||||||
verifyData();
|
verifyData();
|
||||||
save();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChest(String name, Location loc) {
|
public void addChest(String name, Location loc) {
|
||||||
|
// Add the chest location and save
|
||||||
chests.set(name, loc);
|
chests.set(name, loc);
|
||||||
reloadChests();
|
|
||||||
save();
|
save();
|
||||||
|
|
||||||
|
// Reload the chests
|
||||||
|
reloadChests();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeChest(String name) {
|
public boolean removeChest(String name) {
|
||||||
|
// Check if the chest exists
|
||||||
if (chests.getString(name) == null) {
|
if (chests.getString(name) == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Null the chest and save
|
||||||
chests.set(name, null);
|
chests.set(name, null);
|
||||||
reloadChests();
|
|
||||||
save();
|
save();
|
||||||
|
|
||||||
|
// Reload the chests
|
||||||
|
reloadChests();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user