Cleaned up code a bit
Added more output for when gates can't be loaded
This commit is contained in:
parent
352c6e4357
commit
bfde05eb5c
@ -363,16 +363,17 @@ public class Gate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void populateDefaults(String gateFolder) {
|
public static void populateDefaults(String gateFolder) {
|
||||||
|
int Obsidian = Material.OBSIDIAN.getId();
|
||||||
Integer[][] layout = new Integer[][] {
|
Integer[][] layout = new Integer[][] {
|
||||||
{ANYTHING, Portal.OBSIDIAN, Portal.OBSIDIAN, ANYTHING},
|
{ANYTHING, Obsidian,Obsidian, ANYTHING},
|
||||||
{Portal.OBSIDIAN, ENTRANCE, ENTRANCE, Portal.OBSIDIAN},
|
{Obsidian, ENTRANCE, ENTRANCE, Obsidian},
|
||||||
{CONTROL, ENTRANCE, ENTRANCE, CONTROL},
|
{CONTROL, ENTRANCE, ENTRANCE, CONTROL},
|
||||||
{Portal.OBSIDIAN, EXIT, ENTRANCE, Portal.OBSIDIAN},
|
{Obsidian, EXIT, ENTRANCE, Obsidian},
|
||||||
{ANYTHING, Portal.OBSIDIAN, Portal.OBSIDIAN, ANYTHING},
|
{ANYTHING, Obsidian, Obsidian, ANYTHING},
|
||||||
};
|
};
|
||||||
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
|
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
|
||||||
types.put('X', Portal.OBSIDIAN);
|
types.put('X', Obsidian);
|
||||||
types.put('-', Portal.OBSIDIAN);
|
types.put('-', Obsidian);
|
||||||
|
|
||||||
Gate gate = new Gate("nethergate.gate", layout, types);
|
Gate gate = new Gate("nethergate.gate", layout, types);
|
||||||
gate.save(gateFolder);
|
gate.save(gateFolder);
|
||||||
@ -401,10 +402,4 @@ public class Gate {
|
|||||||
return name.endsWith(".gate");
|
return name.endsWith(".gate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CostFor {
|
|
||||||
Using,
|
|
||||||
Activating,
|
|
||||||
Creating
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import java.io.FileWriter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -28,40 +27,41 @@ import org.bukkit.util.Vector;
|
|||||||
* @author Dinnerbone
|
* @author Dinnerbone
|
||||||
*/
|
*/
|
||||||
public class Portal {
|
public class Portal {
|
||||||
public static final int OBSIDIAN = 49;
|
// Variables used to store portal lists
|
||||||
public static final int FIRE = 51;
|
|
||||||
public static final int SIGN = 68;
|
|
||||||
public static final int BUTTON = 77;
|
|
||||||
private static final HashMap<Blox, Portal> lookupBlocks = new HashMap<Blox, Portal>();
|
private static final HashMap<Blox, Portal> lookupBlocks = new HashMap<Blox, Portal>();
|
||||||
private static final HashMap<Blox, Portal> lookupEntrances = new HashMap<Blox, Portal>();
|
private static final HashMap<Blox, Portal> lookupEntrances = new HashMap<Blox, Portal>();
|
||||||
private static final ArrayList<Portal> allPortals = new ArrayList<Portal>();
|
private static final ArrayList<Portal> allPortals = new ArrayList<Portal>();
|
||||||
private static final HashMap<String, ArrayList<String>> allPortalsNet = new HashMap<String, ArrayList<String>>();
|
private static final HashMap<String, ArrayList<String>> allPortalsNet = new HashMap<String, ArrayList<String>>();
|
||||||
private static final HashMap<String, HashMap<String, Portal>> lookupNamesNet = new HashMap<String, HashMap<String, Portal>>();
|
private static final HashMap<String, HashMap<String, Portal>> lookupNamesNet = new HashMap<String, HashMap<String, Portal>>();
|
||||||
|
|
||||||
|
// Gate location block info
|
||||||
private Blox topLeft;
|
private Blox topLeft;
|
||||||
private int modX;
|
private int modX;
|
||||||
private int modZ;
|
private int modZ;
|
||||||
private float rotX;
|
private float rotX;
|
||||||
|
// Block references
|
||||||
private SignPost id;
|
private SignPost id;
|
||||||
private String name;
|
|
||||||
private String destination;
|
|
||||||
private Blox button;
|
private Blox button;
|
||||||
private Player player;
|
|
||||||
private Blox[] frame;
|
private Blox[] frame;
|
||||||
private Blox[] entrances;
|
private Blox[] entrances;
|
||||||
private boolean verified;
|
// Gate information
|
||||||
private boolean fixed;
|
private String name;
|
||||||
private ArrayList<String> destinations = new ArrayList<String>();
|
private String destination;
|
||||||
private String network;
|
private String network;
|
||||||
private Gate gate;
|
private Gate gate;
|
||||||
private boolean isOpen = false;
|
|
||||||
private String owner = "";
|
private String owner = "";
|
||||||
private HashMap<Blox, Integer> exits;
|
|
||||||
private HashMap<Integer, Blox> reverseExits;
|
|
||||||
private boolean hidden = false;
|
private boolean hidden = false;
|
||||||
private Player activePlayer;
|
|
||||||
private boolean alwaysOn = false;
|
private boolean alwaysOn = false;
|
||||||
private boolean priv = false;
|
private boolean priv = false;
|
||||||
private World world;
|
private World world;
|
||||||
|
// Gate options
|
||||||
|
private boolean verified;
|
||||||
|
private boolean fixed;
|
||||||
|
// In-use information
|
||||||
|
private Player player;
|
||||||
|
private Player activePlayer;
|
||||||
|
private ArrayList<String> destinations = new ArrayList<String>();
|
||||||
|
private boolean isOpen = false;
|
||||||
private long openTime;
|
private long openTime;
|
||||||
|
|
||||||
private Portal(Blox topLeft, int modX, int modZ,
|
private Portal(Blox topLeft, int modX, int modZ,
|
||||||
@ -211,7 +211,7 @@ public class Portal {
|
|||||||
Location traveller = new Location(this.world, vehicle.getLocation().getX(), vehicle.getLocation().getY(), vehicle.getLocation().getZ());
|
Location traveller = new Location(this.world, vehicle.getLocation().getX(), vehicle.getLocation().getY(), vehicle.getLocation().getZ());
|
||||||
Location exit = getExit(traveller, origin);
|
Location exit = getExit(traveller, origin);
|
||||||
|
|
||||||
double velocity = vehicle.getVelocity().length();
|
//double velocity = vehicle.getVelocity().length();
|
||||||
|
|
||||||
// Stop and teleport
|
// Stop and teleport
|
||||||
vehicle.setVelocity(new Vector());
|
vehicle.setVelocity(new Vector());
|
||||||
@ -454,53 +454,6 @@ public class Portal {
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Blox, Integer> getExits() {
|
|
||||||
if (exits == null) {
|
|
||||||
exits = new HashMap<Blox, Integer>();
|
|
||||||
reverseExits = new HashMap<Integer, Blox>();
|
|
||||||
HashMap<RelativeBlockVector, Integer> relativeExits = gate.getExits();
|
|
||||||
Set<RelativeBlockVector> exitBlocks = relativeExits.keySet();
|
|
||||||
|
|
||||||
for (RelativeBlockVector vector : exitBlocks) {
|
|
||||||
Blox block = getBlockAt(vector);
|
|
||||||
Integer position = relativeExits.get(vector);
|
|
||||||
exits.put(block, position);
|
|
||||||
reverseExits.put(position, block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return exits;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<Integer, Blox> getReverseExits() {
|
|
||||||
if (reverseExits == null) {
|
|
||||||
getExits();
|
|
||||||
}
|
|
||||||
|
|
||||||
return reverseExits;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return getName().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Portal portal = (Portal) obj;
|
|
||||||
return this.getName().equalsIgnoreCase(portal.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unregister() {
|
public void unregister() {
|
||||||
Stargate.log.info("[Stargate] Unregistering gate " + getName());
|
Stargate.log.info("[Stargate] Unregistering gate " + getName());
|
||||||
close(true);
|
close(true);
|
||||||
@ -540,18 +493,10 @@ public class Portal {
|
|||||||
saveAllGates(world);
|
saveAllGates(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Blox getBlockAt(int right, int depth) {
|
|
||||||
return getBlockAt(right, depth, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Blox getBlockAt(RelativeBlockVector vector) {
|
private Blox getBlockAt(RelativeBlockVector vector) {
|
||||||
return topLeft.modRelative(vector.getRight(), vector.getDepth(), vector.getDistance(), modX, 1, modZ);
|
return topLeft.modRelative(vector.getRight(), vector.getDepth(), vector.getDistance(), modX, 1, modZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Blox getBlockAt(int right, int depth, int distance) {
|
|
||||||
return topLeft.modRelative(right, depth, distance, modX, 1, modZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void register() {
|
private void register() {
|
||||||
if (!lookupNamesNet.containsKey(getNetwork().toLowerCase()))
|
if (!lookupNamesNet.containsKey(getNetwork().toLowerCase()))
|
||||||
lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>());
|
lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>());
|
||||||
@ -577,11 +522,6 @@ public class Portal {
|
|||||||
allPortalsNet.get(getNetwork().toLowerCase()).add(getName().toLowerCase());
|
allPortalsNet.get(getNetwork().toLowerCase()).add(getName().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("Portal [id=%s, name=%s, type=%s]", id, name, gate.getFilename());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Portal createPortal(SignPost id, Player player) {
|
public static Portal createPortal(SignPost id, Player player) {
|
||||||
Block idParent = id.getParent();
|
Block idParent = id.getParent();
|
||||||
if (idParent == null) return null;
|
if (idParent == null) return null;
|
||||||
@ -672,7 +612,7 @@ public class Portal {
|
|||||||
// No button on an always-open gate.
|
// No button on an always-open gate.
|
||||||
if (!alwaysOn) {
|
if (!alwaysOn) {
|
||||||
button = topleft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ);
|
button = topleft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ);
|
||||||
button.setType(BUTTON);
|
button.setType(Material.STONE_BUTTON.getId());
|
||||||
button.setData(facing);
|
button.setData(facing);
|
||||||
}
|
}
|
||||||
portal = new Portal(topleft, modX, modZ, rotX, id, button, destName, name, true, network, gate, player.getName(), hidden, alwaysOn, priv);
|
portal = new Portal(topleft, modX, modZ, rotX, id, button, destName, name, true, network, gate, player.getName(), hidden, alwaysOn, priv);
|
||||||
@ -721,7 +661,8 @@ public class Portal {
|
|||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(loc, false));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(loc, false));
|
||||||
|
|
||||||
for (Portal portal : allPortals) {
|
for (Portal portal : allPortals) {
|
||||||
if (!portal.world.getName().equals(world.getName())) continue;
|
String wName = portal.world.getName();
|
||||||
|
if (!wName.equalsIgnoreCase(world.getName())) continue;
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
Blox sign = new Blox(portal.id.getBlock());
|
Blox sign = new Blox(portal.id.getBlock());
|
||||||
Blox button = portal.button;
|
Blox button = portal.button;
|
||||||
@ -756,7 +697,6 @@ public class Portal {
|
|||||||
builder.append(':');
|
builder.append(':');
|
||||||
builder.append(portal.world.getName());
|
builder.append(portal.world.getName());
|
||||||
|
|
||||||
|
|
||||||
bw.append(builder.toString());
|
bw.append(builder.toString());
|
||||||
bw.newLine();
|
bw.newLine();
|
||||||
}
|
}
|
||||||
@ -793,6 +733,7 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
String[] split = line.split(":");
|
String[] split = line.split(":");
|
||||||
if (split.length < 8) {
|
if (split.length < 8) {
|
||||||
|
Stargate.log.info("[Stargate] Invalid line - " + l);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String name = split[0];
|
String name = split[0];
|
||||||
@ -808,6 +749,10 @@ public class Portal {
|
|||||||
float rotX = Float.parseFloat(split[5]);
|
float rotX = Float.parseFloat(split[5]);
|
||||||
Blox topLeft = new Blox(world, split[6]);
|
Blox topLeft = new Blox(world, split[6]);
|
||||||
Gate gate = (split[7].contains(";")) ? Gate.getGateByName("nethergate.gate") : Gate.getGateByName(split[7]);
|
Gate gate = (split[7].contains(";")) ? Gate.getGateByName("nethergate.gate") : Gate.getGateByName(split[7]);
|
||||||
|
if (gate == null) {
|
||||||
|
Stargate.log.info("[Stargate] Invalid gate layout on line " + l + " [" + split[7] + "]");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String dest = (split.length > 8) ? split[8] : "";
|
String dest = (split.length > 8) ? split[8] : "";
|
||||||
String network = (split.length > 9) ? split[9] : Stargate.getDefaultNetwork();
|
String network = (split.length > 9) ? split[9] : Stargate.getDefaultNetwork();
|
||||||
@ -821,7 +766,6 @@ public class Portal {
|
|||||||
portal.close(true);
|
portal.close(true);
|
||||||
// Verify portal integrity/register portal
|
// Verify portal integrity/register portal
|
||||||
if (!portal.isVerified() || !portal.checkIntegrity()) {
|
if (!portal.isVerified() || !portal.checkIntegrity()) {
|
||||||
portal.close(true);
|
|
||||||
portal.unregister();
|
portal.unregister();
|
||||||
Stargate.log.info("[Stargate] Destroying stargate at " + portal.toString());
|
Stargate.log.info("[Stargate] Destroying stargate at " + portal.toString());
|
||||||
} else {
|
} else {
|
||||||
@ -859,7 +803,6 @@ public class Portal {
|
|||||||
Stargate.log.info("Closing all stargates.");
|
Stargate.log.info("Closing all stargates.");
|
||||||
for (Portal p : allPortals) {
|
for (Portal p : allPortals) {
|
||||||
if (p == null) continue;
|
if (p == null) continue;
|
||||||
//if (!p.isLoaded()) continue;
|
|
||||||
p.close(true);
|
p.close(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -867,4 +810,31 @@ public class Portal {
|
|||||||
public static String filterName(String input) {
|
public static String filterName(String input) {
|
||||||
return input.replaceAll("[\\|:#]", "").trim();
|
return input.replaceAll("[\\|:#]", "").trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("Portal [id=%s, network=%s name=%s, type=%s]", id, network, name, gate.getFilename());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Portal portal = (Portal) obj;
|
||||||
|
return (this.getNetwork().equalsIgnoreCase(portal.getNetwork()) &&
|
||||||
|
this.getName().equalsIgnoreCase(portal.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user