Fix the region setup bug.
Previously, the set() method would overwrite coordinates completely without min/max'ing the values to preserve the invariant that p1 is the lowest point and p2 the highest.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
name: MobArena
|
name: MobArena
|
||||||
author: garbagemule
|
author: garbagemule
|
||||||
main: com.garbagemule.MobArena.MobArena
|
main: com.garbagemule.MobArena.MobArena
|
||||||
version: 0.95.2
|
version: 0.95.1.1
|
||||||
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
|
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
|
||||||
commands:
|
commands:
|
||||||
ma:
|
ma:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.util.Enums;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -111,6 +112,8 @@ public class ArenaRegion
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkData(MobArena plugin, CommandSender s) {
|
public void checkData(MobArena plugin, CommandSender s) {
|
||||||
|
verifyData();
|
||||||
|
|
||||||
if (arenaWarp == null)
|
if (arenaWarp == null)
|
||||||
Messenger.tellPlayer(s, "Missing warp: arena");
|
Messenger.tellPlayer(s, "Missing warp: arena");
|
||||||
if (lobbyWarp == null)
|
if (lobbyWarp == null)
|
||||||
@@ -299,6 +302,7 @@ public class ArenaRegion
|
|||||||
|
|
||||||
coords.set(location1, loc1);
|
coords.set(location1, loc1);
|
||||||
coords.set(location2, loc2);
|
coords.set(location2, loc2);
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Chunk> getChunks() {
|
public List<Chunk> getChunks() {
|
||||||
@@ -352,17 +356,124 @@ public class ArenaRegion
|
|||||||
return leaderboard;
|
return leaderboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void set(RegionPoint point, Location loc) {
|
||||||
|
// Act based on the point
|
||||||
|
switch (point) {
|
||||||
|
case P1: setP1(loc); return;
|
||||||
|
case P2: setP2(loc); return;
|
||||||
|
case ARENA:
|
||||||
|
case LOBBY:
|
||||||
|
case SPECTATOR: setWarp(point, loc); return;
|
||||||
|
case LEADERBOARD: setLeaderboard(loc); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Invalid region point!");
|
||||||
|
}
|
||||||
|
|
||||||
public void set(String point, Location loc) {
|
public void set(String point, Location loc) {
|
||||||
// Set the point and save
|
// Get the region point enum
|
||||||
coords.set(point, loc);
|
RegionPoint rp = Enums.getEnumFromString(RegionPoint.class, point);
|
||||||
|
if (rp == null) throw new IllegalArgumentException("Invalid region point '" + point + "'");
|
||||||
|
|
||||||
|
// Then delegate
|
||||||
|
set(rp, loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setP1(Location l) {
|
||||||
|
if (p2 != null) {
|
||||||
|
boolean modified = false;
|
||||||
|
|
||||||
|
if (p2.getX() < l.getX()) {
|
||||||
|
double tmp = p2.getX();
|
||||||
|
p2.setX(l.getX());
|
||||||
|
l.setX(tmp);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (p2.getZ() < l.getZ()) {
|
||||||
|
double tmp = p2.getZ();
|
||||||
|
p2.setZ(l.getZ());
|
||||||
|
l.setZ(tmp);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (p2.getY() < l.getY()) {
|
||||||
|
double tmp = p2.getY();
|
||||||
|
p2.setY(l.getY());
|
||||||
|
l.setY(tmp);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we made modifications, re-save P2
|
||||||
|
if (modified) {
|
||||||
|
coords.set("p2", p2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set P1 and save
|
||||||
|
coords.set("p1", l);
|
||||||
save();
|
save();
|
||||||
|
|
||||||
// Reload region, warps and leaderboards
|
// Then reload the region
|
||||||
reloadRegion();
|
reloadRegion();
|
||||||
reloadWarps();
|
|
||||||
reloadLeaderboards();
|
|
||||||
verifyData();
|
verifyData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setP2(Location l) {
|
||||||
|
if (p1 != null) {
|
||||||
|
boolean modified = false;
|
||||||
|
|
||||||
|
if (l.getX() < p1.getX()) {
|
||||||
|
double tmp = p1.getX();
|
||||||
|
p1.setX(l.getX());
|
||||||
|
l.setX(tmp);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l.getZ() < p1.getZ()) {
|
||||||
|
double tmp = p1.getZ();
|
||||||
|
p1.setZ(l.getZ());
|
||||||
|
l.setZ(tmp);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l.getY() < p1.getY()) {
|
||||||
|
double tmp = p1.getY();
|
||||||
|
p1.setY(l.getY());
|
||||||
|
l.setY(tmp);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we made modifications, re-save P1
|
||||||
|
if (modified) {
|
||||||
|
coords.set("p1", p1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set P2 and save
|
||||||
|
coords.set("p2", l);
|
||||||
|
save();
|
||||||
|
|
||||||
|
// Then reload the region
|
||||||
|
reloadRegion();
|
||||||
|
verifyData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWarp(RegionPoint point, Location l) {
|
||||||
|
// Set the point and save
|
||||||
|
coords.set(point.toString(), l);
|
||||||
|
save();
|
||||||
|
|
||||||
|
// Then reload warps
|
||||||
|
reloadWarps();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLeaderboard(Location l) {
|
||||||
|
// Set the point and save
|
||||||
|
coords.set("leaderboard", l);
|
||||||
|
save();
|
||||||
|
|
||||||
|
// Then reload the leaderboards
|
||||||
|
reloadLeaderboards();
|
||||||
|
}
|
||||||
|
|
||||||
public void addSpawn(String name, Location loc) {
|
public void addSpawn(String name, Location loc) {
|
||||||
// Add the spawn and save
|
// Add the spawn and save
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
package com.garbagemule.MobArena.region;
|
package com.garbagemule.MobArena.region;
|
||||||
|
|
||||||
public class RegionPoint
|
public enum RegionPoint {
|
||||||
{
|
P1,
|
||||||
public static final String P1 = "p1";
|
P2,
|
||||||
public static final String P2 = "p2";
|
L1,
|
||||||
public static final String L1 = "l1";
|
L2,
|
||||||
public static final String L2 = "l2";
|
ARENA,
|
||||||
public static final String ARENA = "arena";
|
LOBBY,
|
||||||
public static final String LOBBY = "lobby";
|
SPECTATOR,
|
||||||
public static final String SPEC = "spectator";
|
LEADERBOARD;
|
||||||
public static final String LEADERBOARD = "leaderboard";
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user