Replaced spaces with tabs

This commit is contained in:
Drakia 2011-03-20 01:34:56 -07:00
parent 67e54157bc
commit eef287f526
5 changed files with 1685 additions and 1685 deletions

View File

@ -47,13 +47,13 @@ public class Blox {
return new Location(this.world, (double)this.x + x, (double)this.y + y, (double)this.z + z, rotX, rotY); return new Location(this.world, (double)this.x + x, (double)this.y + y, (double)this.z + z, rotX, rotY);
} }
public Blox modRelative(int right, int depth, int distance, int modX, int modY, int modZ) { public Blox modRelative(int right, int depth, int distance, int modX, int modY, int modZ) {
return makeRelative(-right * modX + distance * modZ, -depth * modY, -right * modZ + -distance * modX); return makeRelative(-right * modX + distance * modZ, -depth * modY, -right * modZ + -distance * modX);
} }
public Location modRelativeLoc(double right, double depth, double distance, float rotX, float rotY, int modX, int modY, int modZ) { public Location modRelativeLoc(double right, double depth, double distance, float rotX, float rotY, int modX, int modY, int modZ) {
return makeRelativeLoc(0.5 + -right * modX + distance * modZ, depth, 0.5 + -right * modZ + -distance * modX, rotX, 0); return makeRelativeLoc(0.5 + -right * modX + distance * modZ, depth, 0.5 + -right * modZ + -distance * modX, rotX, 0);
} }
public void setType(int type) { public void setType(int type) {
world.getBlockAt(x, y, z).setTypeId(type); world.getBlockAt(x, y, z).setTypeId(type);

View File

@ -19,387 +19,387 @@ import org.bukkit.block.Block;
* @author Dinnerbone * @author Dinnerbone
*/ */
public class Gate { public class Gate {
public static final int ANYTHING = -1; public static final int ANYTHING = -1;
public static final int ENTRANCE = -2; public static final int ENTRANCE = -2;
public static final int CONTROL = -3; public static final int CONTROL = -3;
public static final int EXIT = -4; public static final int EXIT = -4;
private static HashMap<String, Gate> gates = new HashMap<String, Gate>(); private static HashMap<String, Gate> gates = new HashMap<String, Gate>();
private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<Integer, ArrayList<Gate>>(); private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<Integer, ArrayList<Gate>>();
private String filename; private String filename;
private Integer[][] layout; private Integer[][] layout;
private HashMap<Character, Integer> types; private HashMap<Character, Integer> types;
private RelativeBlockVector[] entrances = new RelativeBlockVector[0]; private RelativeBlockVector[] entrances = new RelativeBlockVector[0];
private RelativeBlockVector[] border = new RelativeBlockVector[0]; private RelativeBlockVector[] border = new RelativeBlockVector[0];
private RelativeBlockVector[] controls = new RelativeBlockVector[0]; private RelativeBlockVector[] controls = new RelativeBlockVector[0];
private RelativeBlockVector exitBlock = null; private RelativeBlockVector exitBlock = null;
private HashMap<RelativeBlockVector, Integer> exits = new HashMap<RelativeBlockVector, Integer>(); private HashMap<RelativeBlockVector, Integer> exits = new HashMap<RelativeBlockVector, Integer>();
private int portalBlockOpen = Material.PORTAL.getId(); private int portalBlockOpen = Material.PORTAL.getId();
private int portalBlockClosed = Material.AIR.getId(); private int portalBlockClosed = Material.AIR.getId();
private Gate(String filename, Integer[][] layout, HashMap<Character, Integer> types) { private Gate(String filename, Integer[][] layout, HashMap<Character, Integer> types) {
this.filename = filename; this.filename = filename;
this.layout = layout; this.layout = layout;
this.types = types; this.types = types;
populateCoordinates(); populateCoordinates();
} }
private void populateCoordinates() { private void populateCoordinates() {
ArrayList<RelativeBlockVector> entranceList = new ArrayList<RelativeBlockVector>(); ArrayList<RelativeBlockVector> entranceList = new ArrayList<RelativeBlockVector>();
ArrayList<RelativeBlockVector> borderList = new ArrayList<RelativeBlockVector>(); ArrayList<RelativeBlockVector> borderList = new ArrayList<RelativeBlockVector>();
ArrayList<RelativeBlockVector> controlList = new ArrayList<RelativeBlockVector>(); ArrayList<RelativeBlockVector> controlList = new ArrayList<RelativeBlockVector>();
RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length]; RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length];
int[] exitDepths = new int[layout[0].length]; int[] exitDepths = new int[layout[0].length];
//int bottom = 0; //int bottom = 0;
RelativeBlockVector lastExit = null; RelativeBlockVector lastExit = null;
for (int y = 0; y < layout.length; y++) { for (int y = 0; y < layout.length; y++) {
for (int x = 0; x < layout[y].length; x++) { for (int x = 0; x < layout[y].length; x++) {
Integer id = layout[y][x]; Integer id = layout[y][x];
if (id == ENTRANCE || id == EXIT) { if (id == ENTRANCE || id == EXIT) {
entranceList.add(new RelativeBlockVector(x, y, 0)); entranceList.add(new RelativeBlockVector(x, y, 0));
exitDepths[x] = y; exitDepths[x] = y;
if (id == EXIT) if (id == EXIT)
this.exitBlock = new RelativeBlockVector(x, y, 0); this.exitBlock = new RelativeBlockVector(x, y, 0);
//bottom = y; //bottom = y;
} else if (id == CONTROL) { } else if (id == CONTROL) {
controlList.add(new RelativeBlockVector(x, y, 0)); controlList.add(new RelativeBlockVector(x, y, 0));
} else if (id != ANYTHING) { } else if (id != ANYTHING) {
borderList.add(new RelativeBlockVector(x, y, 0)); borderList.add(new RelativeBlockVector(x, y, 0));
} }
} }
} }
for (int x = 0; x < exitDepths.length; x++) { for (int x = 0; x < exitDepths.length; x++) {
relativeExits[x] = new RelativeBlockVector(x, exitDepths[x], 0); relativeExits[x] = new RelativeBlockVector(x, exitDepths[x], 0);
} }
for (int x = relativeExits.length - 1; x >= 0; x--) { for (int x = relativeExits.length - 1; x >= 0; x--) {
if (relativeExits[x] != null) { if (relativeExits[x] != null) {
lastExit = relativeExits[x]; lastExit = relativeExits[x];
} else { } else {
relativeExits[x] = lastExit; relativeExits[x] = lastExit;
} }
if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x); if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x);
} }
this.entrances = entranceList.toArray(this.entrances); this.entrances = entranceList.toArray(this.entrances);
this.border = borderList.toArray(this.border); this.border = borderList.toArray(this.border);
this.controls = controlList.toArray(this.controls); this.controls = controlList.toArray(this.controls);
} }
public void save(String gateFolder) { public void save(String gateFolder) {
HashMap<Integer, Character> reverse = new HashMap<Integer, Character>(); HashMap<Integer, Character> reverse = new HashMap<Integer, Character>();
try { try {
BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename)); BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename));
writeConfig(bw, "portal-open", portalBlockOpen); writeConfig(bw, "portal-open", portalBlockOpen);
writeConfig(bw, "portal-closed", portalBlockClosed); writeConfig(bw, "portal-closed", portalBlockClosed);
for (Character type : types.keySet()) { for (Character type : types.keySet()) {
Integer value = types.get(type); Integer value = types.get(type);
if (!type.equals('-')) { if (!type.equals('-')) {
reverse.put(value, type); reverse.put(value, type);
} }
bw.append(type); bw.append(type);
bw.append('='); bw.append('=');
bw.append(value.toString()); bw.append(value.toString());
bw.newLine(); bw.newLine();
} }
bw.newLine(); bw.newLine();
for (int y = 0; y < layout.length; y++) { for (int y = 0; y < layout.length; y++) {
for (int x = 0; x < layout[y].length; x++) { for (int x = 0; x < layout[y].length; x++) {
Integer id = layout[y][x]; Integer id = layout[y][x];
Character symbol; Character symbol;
if (id == ENTRANCE) { if (id == ENTRANCE) {
symbol = '.'; symbol = '.';
} else if (id == ANYTHING) { } else if (id == ANYTHING) {
symbol = ' '; symbol = ' ';
} else if (id == CONTROL) { } else if (id == CONTROL) {
symbol = '-'; symbol = '-';
} else if (id == EXIT) { } else if (id == EXIT) {
symbol = '*'; symbol = '*';
} else if (reverse.containsKey(id)) { } else if (reverse.containsKey(id)) {
symbol = reverse.get(id); symbol = reverse.get(id);
} else { } else {
symbol = '?'; symbol = '?';
} }
bw.append(symbol); bw.append(symbol);
} }
bw.newLine(); bw.newLine();
} }
bw.close(); bw.close();
} catch (IOException ex) { } catch (IOException ex) {
Stargate.log.log(Level.SEVERE, "Could not load Gate " + filename + " - " + ex.getMessage()); Stargate.log.log(Level.SEVERE, "Could not load Gate " + filename + " - " + ex.getMessage());
} }
} }
private void writeConfig(BufferedWriter bw, String key, int value) throws IOException { private void writeConfig(BufferedWriter bw, String key, int value) throws IOException {
bw.append(String.format("%s=%d", key, value)); bw.append(String.format("%s=%d", key, value));
bw.newLine(); bw.newLine();
} }
public Integer[][] getLayout() { public Integer[][] getLayout() {
return layout; return layout;
} }
public RelativeBlockVector[] getEntrances() { public RelativeBlockVector[] getEntrances() {
return entrances; return entrances;
} }
public RelativeBlockVector[] getBorder() { public RelativeBlockVector[] getBorder() {
return border; return border;
} }
public RelativeBlockVector[] getControls() { public RelativeBlockVector[] getControls() {
return controls; return controls;
} }
public HashMap<RelativeBlockVector, Integer> getExits() { public HashMap<RelativeBlockVector, Integer> getExits() {
return exits; return exits;
} }
public RelativeBlockVector getExit() { public RelativeBlockVector getExit() {
return exitBlock; return exitBlock;
} }
public int getControlBlock() { public int getControlBlock() {
return types.get('-'); return types.get('-');
} }
public String getFilename() { public String getFilename() {
return filename; return filename;
} }
public int getPortalBlockOpen() { public int getPortalBlockOpen() {
return portalBlockOpen; return portalBlockOpen;
} }
public int getPortalBlockClosed() { public int getPortalBlockClosed() {
return portalBlockClosed; return portalBlockClosed;
} }
public boolean matches(Block topleft, int modX, int modZ) { public boolean matches(Block topleft, int modX, int modZ) {
return matches(new Blox(topleft), modX, modZ); return matches(new Blox(topleft), modX, modZ);
} }
public boolean matches(Blox topleft, int modX, int modZ) { public boolean matches(Blox topleft, int modX, int modZ) {
for (int y = 0; y < layout.length; y++) { for (int y = 0; y < layout.length; y++) {
for (int x = 0; x < layout[y].length; x++) { for (int x = 0; x < layout[y].length; x++) {
int id = layout[y][x]; int id = layout[y][x];
if (id == ENTRANCE || id == EXIT) { if (id == ENTRANCE || id == EXIT) {
if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != 0) { if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != 0) {
return false; return false;
} }
} else if (id == CONTROL) { } else if (id == CONTROL) {
if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != getControlBlock()) { if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != getControlBlock()) {
return false; return false;
} }
} else if (id != ANYTHING) { } else if (id != ANYTHING) {
if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != id) { if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != id) {
return false; return false;
} }
} }
} }
} }
return true; return true;
} }
private static void registerGate(Gate gate) { private static void registerGate(Gate gate) {
gates.put(gate.getFilename(), gate); gates.put(gate.getFilename(), gate);
int blockID = gate.getControlBlock(); int blockID = gate.getControlBlock();
if (!controlBlocks.containsKey(blockID)) { if (!controlBlocks.containsKey(blockID)) {
controlBlocks.put(blockID, new ArrayList<Gate>()); controlBlocks.put(blockID, new ArrayList<Gate>());
} }
controlBlocks.get(blockID).add(gate); controlBlocks.get(blockID).add(gate);
} }
private static Gate loadGate(File file) { private static Gate loadGate(File file) {
Scanner scanner = null; Scanner scanner = null;
boolean designing = false; boolean designing = false;
ArrayList<ArrayList<Integer>> design = new ArrayList<ArrayList<Integer>>(); ArrayList<ArrayList<Integer>> design = new ArrayList<ArrayList<Integer>>();
HashMap<Character, Integer> types = new HashMap<Character, Integer>(); HashMap<Character, Integer> types = new HashMap<Character, Integer>();
HashMap<String, String> config = new HashMap<String, String>(); HashMap<String, String> config = new HashMap<String, String>();
int cols = 0; int cols = 0;
try { try {
scanner = new Scanner(file); scanner = new Scanner(file);
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String line = scanner.nextLine(); String line = scanner.nextLine();
if (designing) { if (designing) {
ArrayList<Integer> row = new ArrayList<Integer>(); ArrayList<Integer> row = new ArrayList<Integer>();
if (line.length() > cols) { if (line.length() > cols) {
cols = line.length(); cols = line.length();
} }
for (Character symbol : line.toCharArray()) { for (Character symbol : line.toCharArray()) {
Integer id = ANYTHING; Integer id = ANYTHING;
if (symbol.equals('.')) { if (symbol.equals('.')) {
id = ENTRANCE; id = ENTRANCE;
} else if (symbol.equals('*')) { } else if (symbol.equals('*')) {
id = EXIT; id = EXIT;
} else if (symbol.equals(' ')) { } else if (symbol.equals(' ')) {
id = ANYTHING; id = ANYTHING;
} else if (symbol.equals('-')) { } else if (symbol.equals('-')) {
id = CONTROL; id = CONTROL;
} else if ((symbol.equals('?')) || (!types.containsKey(symbol))) { } else if ((symbol.equals('?')) || (!types.containsKey(symbol))) {
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Unknown symbol '" + symbol + "' in diagram"); Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Unknown symbol '" + symbol + "' in diagram");
return null; return null;
} else { } else {
id = types.get(symbol); id = types.get(symbol);
} }
row.add(id); row.add(id);
} }
design.add(row); design.add(row);
} else { } else {
if ((line.isEmpty()) || (!line.contains("="))) { if ((line.isEmpty()) || (!line.contains("="))) {
designing = true; designing = true;
} else { } else {
String[] split = line.split("="); String[] split = line.split("=");
String key = split[0].trim(); String key = split[0].trim();
String value = split[1].trim(); String value = split[1].trim();
if (key.length() == 1) { if (key.length() == 1) {
Character symbol = key.charAt(0); Character symbol = key.charAt(0);
Integer id = Integer.parseInt(value); Integer id = Integer.parseInt(value);
types.put(symbol, id); types.put(symbol, id);
} else { } else {
config.put(key, value); config.put(key, value);
} }
} }
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Invalid block ID given"); Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Invalid block ID given");
return null; return null;
} finally { } finally {
if (scanner != null) scanner.close(); if (scanner != null) scanner.close();
} }
Integer[][] layout = new Integer[design.size()][cols]; Integer[][] layout = new Integer[design.size()][cols];
for (int y = 0; y < design.size(); y++) { for (int y = 0; y < design.size(); y++) {
ArrayList<Integer> row = design.get(y); ArrayList<Integer> row = design.get(y);
Integer[] result = new Integer[cols]; Integer[] result = new Integer[cols];
for (int x = 0; x < cols; x++) { for (int x = 0; x < cols; x++) {
if (x < row.size()) { if (x < row.size()) {
result[x] = row.get(x); result[x] = row.get(x);
} else { } else {
result[x] = ANYTHING; result[x] = ANYTHING;
} }
} }
layout[y] = result; layout[y] = result;
} }
Gate gate = new Gate(file.getName(), layout, types); Gate gate = new Gate(file.getName(), layout, types);
gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen); gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen);
gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed); gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed);
if (gate.getControls().length != 2) { if (gate.getControls().length != 2) {
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points."); Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points.");
return null; return null;
} else { } else {
gate.save(file.getParent() + "/"); // Updates format for version changes gate.save(file.getParent() + "/"); // Updates format for version changes
return gate; return gate;
} }
} }
private static int readConfig(HashMap<String, String> config, Gate gate, File file, String key, int def) { private static int readConfig(HashMap<String, String> config, Gate gate, File file, String key, int def) {
if (config.containsKey(key)) { if (config.containsKey(key)) {
try { try {
return Integer.parseInt(config.get(key)); return Integer.parseInt(config.get(key));
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), file, key)); Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), file, key));
} }
} }
return def; return def;
} }
public static void loadGates(String gateFolder) { public static void loadGates(String gateFolder) {
File dir = new File(gateFolder); File dir = new File(gateFolder);
File[] files; File[] files;
if (dir.exists()) { if (dir.exists()) {
files = dir.listFiles(new StargateFilenameFilter()); files = dir.listFiles(new StargateFilenameFilter());
} else { } else {
files = new File[0]; files = new File[0];
} }
if (files.length == 0) { if (files.length == 0) {
dir.mkdir(); dir.mkdir();
populateDefaults(gateFolder); populateDefaults(gateFolder);
} else { } else {
for (File file : files) { for (File file : files) {
Gate gate = loadGate(file); Gate gate = loadGate(file);
if (gate != null) registerGate(gate); if (gate != null) registerGate(gate);
} }
} }
} }
public static void populateDefaults(String gateFolder) { public static void populateDefaults(String gateFolder) {
int Obsidian = Material.OBSIDIAN.getId(); int Obsidian = Material.OBSIDIAN.getId();
Integer[][] layout = new Integer[][] { Integer[][] layout = new Integer[][] {
{ANYTHING, Obsidian,Obsidian, ANYTHING}, {ANYTHING, Obsidian,Obsidian, ANYTHING},
{Obsidian, ENTRANCE, ENTRANCE, Obsidian}, {Obsidian, ENTRANCE, ENTRANCE, Obsidian},
{CONTROL, ENTRANCE, ENTRANCE, CONTROL}, {CONTROL, ENTRANCE, ENTRANCE, CONTROL},
{Obsidian, EXIT, ENTRANCE, Obsidian}, {Obsidian, EXIT, ENTRANCE, Obsidian},
{ANYTHING, Obsidian, 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', Obsidian); types.put('X', Obsidian);
types.put('-', 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);
registerGate(gate); registerGate(gate);
} }
public static Gate[] getGatesByControlBlock(Block block) { public static Gate[] getGatesByControlBlock(Block block) {
return getGatesByControlBlock(block.getTypeId()); return getGatesByControlBlock(block.getTypeId());
} }
public static Gate[] getGatesByControlBlock(int type) { public static Gate[] getGatesByControlBlock(int type) {
Gate[] result = new Gate[0]; Gate[] result = new Gate[0];
ArrayList<Gate> lookup = controlBlocks.get(type); ArrayList<Gate> lookup = controlBlocks.get(type);
if (lookup != null) result = lookup.toArray(result); if (lookup != null) result = lookup.toArray(result);
return result; return result;
} }
public static Gate getGateByName(String name) { public static Gate getGateByName(String name) {
return gates.get(name); return gates.get(name);
} }
static class StargateFilenameFilter implements FilenameFilter { static class StargateFilenameFilter implements FilenameFilter {
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
return name.endsWith(".gate"); return name.endsWith(".gate");
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -6,25 +6,25 @@ package net.TheDgtl.Stargate;
* @author Dinnerbone * @author Dinnerbone
*/ */
public class RelativeBlockVector { public class RelativeBlockVector {
private int right = 0; private int right = 0;
private int depth = 0; private int depth = 0;
private int distance = 0; private int distance = 0;
public RelativeBlockVector(int right, int depth, int distance) { public RelativeBlockVector(int right, int depth, int distance) {
this.right = right; this.right = right;
this.depth = depth; this.depth = depth;
this.distance = distance; this.distance = distance;
} }
public int getRight() { public int getRight() {
return right; return right;
} }
public int getDepth() { public int getDepth() {
return depth; return depth;
} }
public int getDistance() { public int getDistance() {
return distance; return distance;
} }
} }

View File

@ -54,123 +54,123 @@ public class Stargate extends JavaPlugin {
// Permissions // Permissions
private static Permissions permissions = null; private static Permissions permissions = null;
private final bListener blockListener = new bListener(); private final bListener blockListener = new bListener();
private final pListener playerListener = new pListener(); private final pListener playerListener = new pListener();
private final vListener vehicleListener = new vListener(); private final vListener vehicleListener = new vListener();
private final wListener worldListener = new wListener(); private final wListener worldListener = new wListener();
private final eListener entityListener = new eListener(); private final eListener entityListener = new eListener();
private final sListener serverListener = new sListener(); private final sListener serverListener = new sListener();
public static Logger log; public static Logger log;
private Configuration config; private Configuration config;
private PluginManager pm; private PluginManager pm;
private static String portalFolder; private static String portalFolder;
private static String gateFolder; private static String gateFolder;
private static String teleMsg = "Teleported"; private static String teleMsg = "Teleported";
private static String regMsg = "Gate Created"; private static String regMsg = "Gate Created";
private static String dmgMsg = "Gate Destroyed"; private static String dmgMsg = "Gate Destroyed";
private static String denyMsg = "Access Denied"; private static String denyMsg = "Access Denied";
private static String invMsg = "Invalid Destination"; private static String invMsg = "Invalid Destination";
private static String blockMsg = "Destination Blocked"; private static String blockMsg = "Destination Blocked";
private static String defNetwork = "central"; private static String defNetwork = "central";
private static boolean destroyExplosion = false; private static boolean destroyExplosion = false;
private static int activeLimit = 10; private static int activeLimit = 10;
private static int openLimit = 10; private static int openLimit = 10;
public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<Portal>(); public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<Portal>();
public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<Portal>(); public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<Portal>();
//private HashMap<Integer, Location> vehicles = new HashMap<Integer, Location>(); //private HashMap<Integer, Location> vehicles = new HashMap<Integer, Location>();
public void onDisable() { public void onDisable() {
Portal.closeAllGates(); Portal.closeAllGates();
Portal.clearGates(); Portal.clearGates();
} }
public void onEnable() { public void onEnable() {
PluginDescriptionFile pdfFile = this.getDescription(); PluginDescriptionFile pdfFile = this.getDescription();
pm = getServer().getPluginManager(); pm = getServer().getPluginManager();
config = this.getConfiguration(); config = this.getConfiguration();
log = Logger.getLogger("Minecraft"); log = Logger.getLogger("Minecraft");
// Set portalFile and gateFolder to the plugin folder as defaults. // Set portalFile and gateFolder to the plugin folder as defaults.
portalFolder = getDataFolder() + "/portals"; portalFolder = getDataFolder() + "/portals";
gateFolder = getDataFolder() + "/gates/"; gateFolder = getDataFolder() + "/gates/";
log.info(pdfFile.getName() + " v." + pdfFile.getVersion() + " is enabled."); log.info(pdfFile.getName() + " v." + pdfFile.getVersion() + " is enabled.");
pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
this.reloadConfig(); this.reloadConfig();
this.migrate(); this.migrate();
this.reloadGates(); this.reloadGates();
// Check to see if iConomy/Permissions is loaded yet. // Check to see if iConomy/Permissions is loaded yet.
checkiConomy(); checkiConomy();
checkPermissions(); checkPermissions();
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this); pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this);
pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.WORLD_LOADED, worldListener, Priority.Normal, this); pm.registerEvent(Event.Type.WORLD_LOADED, worldListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this);
// iConomy Loading // iConomy Loading
pm.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Priority.Monitor, this); pm.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Priority.Monitor, this); pm.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Priority.Monitor, this);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L);
} }
public void reloadConfig() { public void reloadConfig() {
config.load(); config.load();
portalFolder = config.getString("portal-folder", portalFolder); portalFolder = config.getString("portal-folder", portalFolder);
gateFolder = config.getString("gate-folder", gateFolder); gateFolder = config.getString("gate-folder", gateFolder);
teleMsg = config.getString("teleport-message", teleMsg); teleMsg = config.getString("teleport-message", teleMsg);
regMsg = config.getString("portal-create-message", regMsg); regMsg = config.getString("portal-create-message", regMsg);
dmgMsg = config.getString("portal-destroy-message", dmgMsg); dmgMsg = config.getString("portal-destroy-message", dmgMsg);
denyMsg = config.getString("not-owner-message", denyMsg); denyMsg = config.getString("not-owner-message", denyMsg);
invMsg = config.getString("not-selected-message", invMsg); invMsg = config.getString("not-selected-message", invMsg);
blockMsg = config.getString("other-side-blocked-message", blockMsg); blockMsg = config.getString("other-side-blocked-message", blockMsg);
defNetwork = config.getString("default-gate-network", defNetwork).trim(); defNetwork = config.getString("default-gate-network", defNetwork).trim();
destroyExplosion = config.getBoolean("destroyexplosion", destroyExplosion); destroyExplosion = config.getBoolean("destroyexplosion", destroyExplosion);
// iConomy // iConomy
iConomyHandler.useiConomy = config.getBoolean("useiconomy", iConomyHandler.useiConomy); iConomyHandler.useiConomy = config.getBoolean("useiconomy", iConomyHandler.useiConomy);
iConomyHandler.createCost = config.getInt("createcost", iConomyHandler.createCost); iConomyHandler.createCost = config.getInt("createcost", iConomyHandler.createCost);
iConomyHandler.destroyCost = config.getInt("destroycost", iConomyHandler.destroyCost); iConomyHandler.destroyCost = config.getInt("destroycost", iConomyHandler.destroyCost);
iConomyHandler.useCost = config.getInt("usecost", iConomyHandler.useCost); iConomyHandler.useCost = config.getInt("usecost", iConomyHandler.useCost);
iConomyHandler.inFundMsg = config.getString("not-enough-money-message", iConomyHandler.inFundMsg); iConomyHandler.inFundMsg = config.getString("not-enough-money-message", iConomyHandler.inFundMsg);
saveConfig(); saveConfig();
} }
public void saveConfig() { public void saveConfig() {
config.setProperty("portal-folder", portalFolder); config.setProperty("portal-folder", portalFolder);
config.setProperty("gate-folder", gateFolder); config.setProperty("gate-folder", gateFolder);
config.setProperty("teleport-message", teleMsg); config.setProperty("teleport-message", teleMsg);
config.setProperty("portal-create-message", regMsg); config.setProperty("portal-create-message", regMsg);
config.setProperty("portal-destroy-message", dmgMsg); config.setProperty("portal-destroy-message", dmgMsg);
config.setProperty("not-owner-message", denyMsg); config.setProperty("not-owner-message", denyMsg);
config.setProperty("not-selected-message", invMsg); config.setProperty("not-selected-message", invMsg);
config.setProperty("other-side-blocked-message", blockMsg); config.setProperty("other-side-blocked-message", blockMsg);
config.setProperty("default-gate-network", defNetwork); config.setProperty("default-gate-network", defNetwork);
config.setProperty("destroyexplosion", destroyExplosion); config.setProperty("destroyexplosion", destroyExplosion);
// iConomy // iConomy
config.setProperty("useiconomy", iConomyHandler.useiConomy); config.setProperty("useiconomy", iConomyHandler.useiConomy);
config.setProperty("createcost", iConomyHandler.createCost); config.setProperty("createcost", iConomyHandler.createCost);
config.setProperty("destroycost", iConomyHandler.destroyCost); config.setProperty("destroycost", iConomyHandler.destroyCost);
config.setProperty("usecost", iConomyHandler.useCost); config.setProperty("usecost", iConomyHandler.useCost);
config.setProperty("not-enough-money-message", iConomyHandler.inFundMsg); config.setProperty("not-enough-money-message", iConomyHandler.inFundMsg);
config.save(); config.save();
} }
public void reloadGates() { public void reloadGates() {
@ -194,87 +194,87 @@ public class Stargate extends JavaPlugin {
File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db"); File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db");
if (!newFile.exists()) { if (!newFile.exists()) {
newFile.getParentFile().mkdirs(); newFile.getParentFile().mkdirs();
// Migrate not-so-old stargate db // Migrate not-so-old stargate db
File oldishFile = new File("plugins/Stargate/stargate.db"); File oldishFile = new File("plugins/Stargate/stargate.db");
if (oldishFile.exists()) { if (oldishFile.exists()) {
Stargate.log.info("[Stargate] Migrating existing stargate.db"); Stargate.log.info("[Stargate] Migrating existing stargate.db");
oldishFile.renameTo(newFile); oldishFile.renameTo(newFile);
} }
} }
// Migrate old gates if applicaple // Migrate old gates if applicaple
File oldDir = new File("stargates"); File oldDir = new File("stargates");
if (oldDir.exists()) { if (oldDir.exists()) {
File newDir = new File(gateFolder); File newDir = new File(gateFolder);
if (!newDir.exists()) newDir.mkdirs(); if (!newDir.exists()) newDir.mkdirs();
for (File file : oldDir.listFiles(new Gate.StargateFilenameFilter())) { for (File file : oldDir.listFiles(new Gate.StargateFilenameFilter())) {
Stargate.log.info("[Stargate] Migrating existing gate " + file.getName()); Stargate.log.info("[Stargate] Migrating existing gate " + file.getName());
file.renameTo(new File(gateFolder, file.getName())); file.renameTo(new File(gateFolder, file.getName()));
} }
} }
} }
public static String getSaveLocation() { public static String getSaveLocation() {
return portalFolder; return portalFolder;
} }
public static String getDefaultNetwork() { public static String getDefaultNetwork() {
return defNetwork; return defNetwork;
} }
private void onButtonPressed(Player player, Portal gate) { private void onButtonPressed(Player player, Portal gate) {
Portal destination = gate.getDestination(); Portal destination = gate.getDestination();
if (!gate.isOpen()) { if (!gate.isOpen()) {
if (iConomyHandler.useiConomy() && iConomyHandler.getBalance(player.getName()) < iConomyHandler.useCost) { if (iConomyHandler.useiConomy() && iConomyHandler.getBalance(player.getName()) < iConomyHandler.useCost) {
player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg);
} else if ((!gate.isFixed()) && gate.isActive() && (gate.getActivePlayer() != player)) { } else if ((!gate.isFixed()) && gate.isActive() && (gate.getActivePlayer() != player)) {
gate.deactivate(); gate.deactivate();
if (!denyMsg.isEmpty()) { if (!denyMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + denyMsg); player.sendMessage(ChatColor.RED + denyMsg);
} }
} else if (gate.isPrivate() && !gate.getOwner().equals(player.getName()) && !hasPerm(player, "stargate.private", player.isOp())) { } else if (gate.isPrivate() && !gate.getOwner().equals(player.getName()) && !hasPerm(player, "stargate.private", player.isOp())) {
if (!denyMsg.isEmpty()) { if (!denyMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + denyMsg); player.sendMessage(ChatColor.RED + denyMsg);
} }
} else if ((destination == null) || (destination == gate)) { } else if ((destination == null) || (destination == gate)) {
if (!invMsg.isEmpty()) { if (!invMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + invMsg); player.sendMessage(ChatColor.RED + invMsg);
} }
} else if ((destination.isOpen()) && (!destination.isAlwaysOn())) { } else if ((destination.isOpen()) && (!destination.isAlwaysOn())) {
if (!blockMsg.isEmpty()) { if (!blockMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + blockMsg); player.sendMessage(ChatColor.RED + blockMsg);
} }
} else { } else {
gate.open(player, false); gate.open(player, false);
} }
} else { } else {
gate.close(false); gate.close(false);
} }
} }
/* /*
* Check if iConomy is loaded/enabled already * Check if iConomy is loaded/enabled already
*/ */
private void checkiConomy() { private void checkiConomy() {
if (!iConomyHandler.useiConomy) return; if (!iConomyHandler.useiConomy) return;
Plugin ico = pm.getPlugin("iConomy"); Plugin ico = pm.getPlugin("iConomy");
if (ico != null && ico.isEnabled()) { if (ico != null && ico.isEnabled()) {
iConomyHandler.iConomy = (iConomy)ico; iConomyHandler.iConomy = (iConomy)ico;
Stargate.log.info("[Stargate] Using iConomy (v" + iConomyHandler.iConomy.getDescription().getVersion() + ")"); Stargate.log.info("[Stargate] Using iConomy (v" + iConomyHandler.iConomy.getDescription().getVersion() + ")");
} }
} }
/* /*
* Check if Permissions is loaded/enabled already * Check if Permissions is loaded/enabled already
*/ */
private void checkPermissions() { private void checkPermissions() {
Plugin perm = pm.getPlugin("Permissions"); Plugin perm = pm.getPlugin("Permissions");
if (perm != null && perm.isEnabled()) { if (perm != null && perm.isEnabled()) {
permissions = (Permissions)perm; permissions = (Permissions)perm;
Stargate.log.info("[Stargate] Using Permissions (v" + permissions.getDescription().getVersion() + ")"); Stargate.log.info("[Stargate] Using Permissions (v" + permissions.getDescription().getVersion() + ")");
} }
} }
/* /*
* Check whether the player has the given permissions. * Check whether the player has the given permissions.
@ -287,307 +287,307 @@ public class Stargate extends JavaPlugin {
} }
} }
private class vListener extends VehicleListener { private class vListener extends VehicleListener {
@Override @Override
public void onVehicleMove(VehicleMoveEvent event) { public void onVehicleMove(VehicleMoveEvent event) {
Entity passenger = event.getVehicle().getPassenger(); Entity passenger = event.getVehicle().getPassenger();
Vehicle vehicle = event.getVehicle(); Vehicle vehicle = event.getVehicle();
Portal portal = Portal.getByEntrance(event.getTo()); Portal portal = Portal.getByEntrance(event.getTo());
if (portal != null && portal.isOpen()) { if (portal != null && portal.isOpen()) {
if (passenger instanceof Player) { if (passenger instanceof Player) {
Player player = (Player)event.getVehicle().getPassenger(); Player player = (Player)event.getVehicle().getPassenger();
if (!portal.isOpenFor(player)) { if (!portal.isOpenFor(player)) {
player.sendMessage(ChatColor.RED + denyMsg); player.sendMessage(ChatColor.RED + denyMsg);
return; return;
} }
Portal dest = portal.getDestination(); Portal dest = portal.getDestination();
if (dest == null) return; if (dest == null) return;
dest.teleport(vehicle, portal); dest.teleport(vehicle, portal);
if (!teleMsg.isEmpty()) if (!teleMsg.isEmpty())
player.sendMessage(ChatColor.BLUE + teleMsg); player.sendMessage(ChatColor.BLUE + teleMsg);
portal.close(false); portal.close(false);
} else { } else {
} }
} }
} }
} }
private class pListener extends PlayerListener { private class pListener extends PlayerListener {
@Override @Override
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Portal portal = Portal.getByEntrance(event.getTo()); Portal portal = Portal.getByEntrance(event.getTo());
if ((portal != null) && (portal.isOpen())) { if ((portal != null) && (portal.isOpen())) {
if (portal.isOpenFor(player)) { if (portal.isOpenFor(player)) {
Portal destination = portal.getDestination(); Portal destination = portal.getDestination();
if (destination != null) { if (destination != null) {
if (!iConomyHandler.useiConomy() || iConomyHandler.chargePlayer(player.getName(), iConomyHandler.useCost)) { if (!iConomyHandler.useiConomy() || iConomyHandler.chargePlayer(player.getName(), iConomyHandler.useCost)) {
if (iConomyHandler.useiConomy()) { if (iConomyHandler.useiConomy()) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.useCost)); player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.useCost));
} }
if (!teleMsg.isEmpty()) { if (!teleMsg.isEmpty()) {
player.sendMessage(ChatColor.BLUE + teleMsg); player.sendMessage(ChatColor.BLUE + teleMsg);
} }
destination.teleport(player, portal, event); destination.teleport(player, portal, event);
} else { } else {
if (!iConomyHandler.inFundMsg.isEmpty()) { if (!iConomyHandler.inFundMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg);
} }
} }
portal.close(false); portal.close(false);
} }
} else { } else {
if (!denyMsg.isEmpty()) { if (!denyMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + denyMsg); player.sendMessage(ChatColor.RED + denyMsg);
} }
} }
} }
} }
} }
private class bListener extends BlockListener { private class bListener extends BlockListener {
@Override @Override
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
// Stop player from placing a block touching a portals controls // Stop player from placing a block touching a portals controls
if (event.getBlockAgainst().getType() == Material.STONE_BUTTON || if (event.getBlockAgainst().getType() == Material.STONE_BUTTON ||
event.getBlockAgainst().getType() == Material.WALL_SIGN) { event.getBlockAgainst().getType() == Material.WALL_SIGN) {
Portal portal = Portal.getByBlock(event.getBlockAgainst()); Portal portal = Portal.getByBlock(event.getBlockAgainst());
if (portal != null) event.setCancelled(true); if (portal != null) event.setCancelled(true);
} }
} }
@Override @Override
public void onSignChange(SignChangeEvent event) { public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
if (block.getType() != Material.WALL_SIGN) return; if (block.getType() != Material.WALL_SIGN) return;
// Initialize a stargate // Initialize a stargate
if (hasPerm(player, "stargate.create", player.isOp()) || if (hasPerm(player, "stargate.create", player.isOp()) ||
hasPerm(player, "stargate.create.personal", false)) { hasPerm(player, "stargate.create.personal", false)) {
if (iConomyHandler.useiConomy() && !iConomyHandler.chargePlayer(player.getName(), iConomyHandler.createCost)) { if (iConomyHandler.useiConomy() && !iConomyHandler.chargePlayer(player.getName(), iConomyHandler.createCost)) {
if (!iConomyHandler.inFundMsg.isEmpty()) { if (!iConomyHandler.inFundMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg);
} }
return; return;
} }
SignPost sign = new SignPost(new Blox(block)); SignPost sign = new SignPost(new Blox(block));
// Set sign text so we can create a gate with it. // Set sign text so we can create a gate with it.
sign.setText(0, event.getLine(0)); sign.setText(0, event.getLine(0));
sign.setText(1, event.getLine(1)); sign.setText(1, event.getLine(1));
sign.setText(2, event.getLine(2)); sign.setText(2, event.getLine(2));
sign.setText(3, event.getLine(3)); sign.setText(3, event.getLine(3));
Portal portal = Portal.createPortal(sign, player); Portal portal = Portal.createPortal(sign, player);
if (portal == null) return; if (portal == null) return;
if (iConomyHandler.useiConomy()) { if (iConomyHandler.useiConomy()) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.createCost)); player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.createCost));
} }
if (!regMsg.isEmpty()) { if (!regMsg.isEmpty()) {
player.sendMessage(ChatColor.GREEN + regMsg); player.sendMessage(ChatColor.GREEN + regMsg);
} }
log.info("[Stargate] Initialized stargate: " + portal.getName()); log.info("[Stargate] Initialized stargate: " + portal.getName());
portal.drawSign(); portal.drawSign();
// Set event text so our new sign is instantly initialized // Set event text so our new sign is instantly initialized
event.setLine(0, sign.getText(0)); event.setLine(0, sign.getText(0));
event.setLine(1, sign.getText(1)); event.setLine(1, sign.getText(1));
event.setLine(2, sign.getText(2)); event.setLine(2, sign.getText(2));
event.setLine(3, sign.getText(3)); event.setLine(3, sign.getText(3));
} }
} }
@Override @Override
public void onBlockRightClick(BlockRightClickEvent event) { public void onBlockRightClick(BlockRightClickEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
if (block.getType() == Material.WALL_SIGN) { if (block.getType() == Material.WALL_SIGN) {
Portal portal = Portal.getByBlock(block); Portal portal = Portal.getByBlock(block);
// Cycle through a stargates locations // Cycle through a stargates locations
if (portal != null) { if (portal != null) {
if (hasPerm(player, "stargate.use", true)) { if (hasPerm(player, "stargate.use", true)) {
if ((!portal.isOpen()) && (!portal.isFixed())) { if ((!portal.isOpen()) && (!portal.isFixed())) {
portal.cycleDestination(player); portal.cycleDestination(player);
} }
} else { } else {
if (!denyMsg.isEmpty()) { if (!denyMsg.isEmpty()) {
player.sendMessage(denyMsg); player.sendMessage(denyMsg);
} }
} }
} }
} }
// Implement right-click to toggle a stargate, gets around spawn protection problem. // Implement right-click to toggle a stargate, gets around spawn protection problem.
if ((block.getType() == Material.STONE_BUTTON)) { if ((block.getType() == Material.STONE_BUTTON)) {
if (hasPerm(player, "stargate.use", true)) { if (hasPerm(player, "stargate.use", true)) {
Portal portal = Portal.getByBlock(block); Portal portal = Portal.getByBlock(block);
if (portal != null) { if (portal != null) {
onButtonPressed(player, portal); onButtonPressed(player, portal);
} }
} }
} }
} }
@Override @Override
public void onBlockDamage(BlockDamageEvent event) { public void onBlockDamage(BlockDamageEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
// Check if we're pushing a button. // Check if we're pushing a button.
if (block.getType() == Material.STONE_BUTTON && event.getDamageLevel() == BlockDamageLevel.STARTED) { if (block.getType() == Material.STONE_BUTTON && event.getDamageLevel() == BlockDamageLevel.STARTED) {
if (hasPerm(player, "stargate.use", true)) { if (hasPerm(player, "stargate.use", true)) {
Portal portal = Portal.getByBlock(block); Portal portal = Portal.getByBlock(block);
if (portal != null) { if (portal != null) {
onButtonPressed(player, portal); onButtonPressed(player, portal);
} }
} }
} }
} }
@Override @Override
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
Player player = event.getPlayer(); Player player = event.getPlayer();
if (block.getType() != Material.WALL_SIGN && block.getType() != Material.STONE_BUTTON && Gate.getGatesByControlBlock(block).length == 0) { if (block.getType() != Material.WALL_SIGN && block.getType() != Material.STONE_BUTTON && Gate.getGatesByControlBlock(block).length == 0) {
return; return;
} }
Portal portal = Portal.getByBlock(block); Portal portal = Portal.getByBlock(block);
if (portal == null) return; if (portal == null) return;
if (hasPerm(player, "stargate.destroy", player.isOp()) || hasPerm(player, "stargate.destroy.all", player.isOp()) || if (hasPerm(player, "stargate.destroy", player.isOp()) || hasPerm(player, "stargate.destroy.all", player.isOp()) ||
( portal.getOwner().equalsIgnoreCase(player.getName()) && hasPerm(player, "stargate.destroy.owner", false) )) { ( portal.getOwner().equalsIgnoreCase(player.getName()) && hasPerm(player, "stargate.destroy.owner", false) )) {
// Can't afford // Can't afford
if (iConomyHandler.useiConomy() && (iConomyHandler.destroyCost > 0 && iConomyHandler.getBalance(player.getName()) < iConomyHandler.destroyCost)) { if (iConomyHandler.useiConomy() && (iConomyHandler.destroyCost > 0 && iConomyHandler.getBalance(player.getName()) < iConomyHandler.destroyCost)) {
if (!iConomyHandler.inFundMsg.isEmpty()) { if (!iConomyHandler.inFundMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
if (iConomyHandler.useiConomy()) { if (iConomyHandler.useiConomy()) {
iConomyHandler.chargePlayer(player.getName(), iConomyHandler.destroyCost); iConomyHandler.chargePlayer(player.getName(), iConomyHandler.destroyCost);
if (iConomyHandler.destroyCost > 0) { if (iConomyHandler.destroyCost > 0) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.destroyCost)); player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.destroyCost));
} else if (iConomyHandler.destroyCost < 0) { } else if (iConomyHandler.destroyCost < 0) {
player.sendMessage(ChatColor.GREEN + "Refunded " + iConomy.getBank().format(-iConomyHandler.destroyCost)); player.sendMessage(ChatColor.GREEN + "Refunded " + iConomy.getBank().format(-iConomyHandler.destroyCost));
} }
} }
portal.unregister(true); portal.unregister(true);
if (!dmgMsg.isEmpty()) { if (!dmgMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + dmgMsg); player.sendMessage(ChatColor.RED + dmgMsg);
} }
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
} }
@Override @Override
public void onBlockPhysics(BlockPhysicsEvent event) { public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
if (block.getType() == Material.PORTAL) { if (block.getType() == Material.PORTAL) {
event.setCancelled((Portal.getByEntrance(block) != null)); event.setCancelled((Portal.getByEntrance(block) != null));
} }
} }
@Override @Override
public void onBlockFlow(BlockFromToEvent event) { public void onBlockFlow(BlockFromToEvent event) {
Portal portal = Portal.getByEntrance(event.getBlock()); Portal portal = Portal.getByEntrance(event.getBlock());
if (portal != null) { if (portal != null) {
event.setCancelled((event.getBlock().getY() == event.getToBlock().getY())); event.setCancelled((event.getBlock().getY() == event.getToBlock().getY()));
} }
} }
} }
private class wListener extends WorldListener { private class wListener extends WorldListener {
@Override @Override
public void onWorldLoaded(WorldEvent event) { public void onWorldLoaded(WorldEvent event) {
World w = event.getWorld(); World w = event.getWorld();
// We have to make sure the world is actually loaded. This gets called twice for some reason. // We have to make sure the world is actually loaded. This gets called twice for some reason.
if (w.getBlockAt(w.getSpawnLocation()).getWorld() != null) { if (w.getBlockAt(w.getSpawnLocation()).getWorld() != null) {
Portal.loadAllGates(w); Portal.loadAllGates(w);
} }
} }
} }
private class eListener extends EntityListener { private class eListener extends EntityListener {
@Override @Override
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) return;
for (Block b : event.blockList()) { for (Block b : event.blockList()) {
if (b.getTypeId() != Material.WALL_SIGN.getId() && b.getTypeId() != Material.STONE_BUTTON.getId()) continue; if (b.getTypeId() != Material.WALL_SIGN.getId() && b.getTypeId() != Material.STONE_BUTTON.getId()) continue;
Portal portal = Portal.getByBlock(b); Portal portal = Portal.getByBlock(b);
if (portal == null) continue; if (portal == null) continue;
if (destroyExplosion) { if (destroyExplosion) {
portal.unregister(true); portal.unregister(true);
} else { } else {
b.setType(b.getType()); b.setType(b.getType());
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
} }
private class sListener extends ServerListener { private class sListener extends ServerListener {
@Override @Override
public void onPluginEnabled(PluginEvent event) { public void onPluginEnabled(PluginEvent event) {
if (iConomyHandler.useiConomy && iConomyHandler.iConomy == null) { if (iConomyHandler.useiConomy && iConomyHandler.iConomy == null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) { if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) {
iConomyHandler.iConomy = (iConomy)event.getPlugin(); iConomyHandler.iConomy = (iConomy)event.getPlugin();
Stargate.log.info("[Stargate] Using iConomy (v" + iConomyHandler.iConomy.getDescription().getVersion() + ")"); Stargate.log.info("[Stargate] Using iConomy (v" + iConomyHandler.iConomy.getDescription().getVersion() + ")");
} }
} }
if (permissions == null) { if (permissions == null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("Permissions")) { if (event.getPlugin().getDescription().getName().equalsIgnoreCase("Permissions")) {
permissions = (Permissions)event.getPlugin(); permissions = (Permissions)event.getPlugin();
Stargate.log.info("[Stargate] Using Permissions (v" + permissions.getDescription().getVersion() + ")"); Stargate.log.info("[Stargate] Using Permissions (v" + permissions.getDescription().getVersion() + ")");
} }
} }
} }
@Override @Override
public void onPluginDisabled(PluginEvent event) { public void onPluginDisabled(PluginEvent event) {
if (iConomyHandler.useiConomy && iConomyHandler.iConomy != null) { if (iConomyHandler.useiConomy && iConomyHandler.iConomy != null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) { if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) {
iConomyHandler.iConomy = null; iConomyHandler.iConomy = null;
Stargate.log.info("[Stargate] iConomy Disabled"); Stargate.log.info("[Stargate] iConomy Disabled");
} }
} }
if (permissions != null) { if (permissions != null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("Permissions")) { if (event.getPlugin().getDescription().getName().equalsIgnoreCase("Permissions")) {
permissions = null; permissions = null;
Stargate.log.info("[Stargate] Permissions Disabled"); Stargate.log.info("[Stargate] Permissions Disabled");
} }
} }
} }
} }
private class SGThread implements Runnable { private class SGThread implements Runnable {
public void run() { public void run() {
long time = System.currentTimeMillis() / 1000; long time = System.currentTimeMillis() / 1000;
// Close open portals // Close open portals
for (Iterator<Portal> iter = Stargate.openList.iterator(); iter.hasNext();) { for (Iterator<Portal> iter = Stargate.openList.iterator(); iter.hasNext();) {
Portal p = iter.next(); Portal p = iter.next();
if (time > p.getOpenTime() + Stargate.openLimit) { if (time > p.getOpenTime() + Stargate.openLimit) {
p.close(false); p.close(false);
iter.remove(); iter.remove();
} }
} }
// Deactivate active portals // Deactivate active portals
for (Iterator<Portal> iter = Stargate.activeList.iterator(); iter.hasNext();) { for (Iterator<Portal> iter = Stargate.activeList.iterator(); iter.hasNext();) {
Portal p = iter.next(); Portal p = iter.next();
if (time > p.getOpenTime() + Stargate.activeLimit) { if (time > p.getOpenTime() + Stargate.activeLimit) {
p.deactivate(); p.deactivate();
iter.remove(); iter.remove();
} }
} }
} }
} }
} }