From b9d9ee7c4f622ec3e67081fa9d99eae3e479716a Mon Sep 17 00:00:00 2001 From: Drakia Date: Mon, 11 Apr 2011 22:11:59 -0700 Subject: [PATCH] Sign option permissions Per-gate iconomy target /sg reload command Other misc fixes --- README | 5 + src/net/TheDgtl/Stargate/Gate.java | 895 ++++++++++--------- src/net/TheDgtl/Stargate/Portal.java | 6 + src/net/TheDgtl/Stargate/Stargate.java | 50 +- src/net/TheDgtl/Stargate/iConomyHandler.java | 2 +- src/plugin.yml | 8 +- 6 files changed, 513 insertions(+), 453 deletions(-) diff --git a/README b/README index b2af1f3..29a7381 100644 --- a/README +++ b/README @@ -26,6 +26,10 @@ Hmm.. None? - stargate.free.destroy - This player/group is not charged to destroy gates even if the gate has a cost. - stargate.world.{worldname} - Allow this user/group access to gates on the world {worldname} - stargate.network.{networkname} - Allow this user/group access to the network {networkname} + - stargate.option.hidden - Allow this user/group to create hidden gates. + - stargate.option.alwayson - Allow this user/group to create always-on gates. + - stargate.option.private - Allow this user/group to create private gates. + - stargate.option.free - Allow this user/group to create free gates. ============= Instructions @@ -73,6 +77,7 @@ iConomy Support: usecost=5 destroycost=5 createcost=5 +toowner=true ============== Custom Gate Layout diff --git a/src/net/TheDgtl/Stargate/Gate.java b/src/net/TheDgtl/Stargate/Gate.java index 3232f57..809e6ba 100644 --- a/src/net/TheDgtl/Stargate/Gate.java +++ b/src/net/TheDgtl/Stargate/Gate.java @@ -1,435 +1,460 @@ -package net.TheDgtl.Stargate; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Scanner; -import java.util.logging.Level; - -import org.bukkit.Material; -import org.bukkit.block.Block; - -/** - * Gate.java - Plug-in for hey0's minecraft mod. - * @author Shaun (sturmeh) - * @author Dinnerbone - */ -public class Gate { - public static final int ANYTHING = -1; - public static final int ENTRANCE = -2; - public static final int CONTROL = -3; - public static final int EXIT = -4; - private static HashMap gates = new HashMap(); - private static HashMap> controlBlocks = new HashMap>(); - - private String filename; - private Integer[][] layout; - private HashMap types; - private RelativeBlockVector[] entrances = new RelativeBlockVector[0]; - private RelativeBlockVector[] border = new RelativeBlockVector[0]; - private RelativeBlockVector[] controls = new RelativeBlockVector[0]; - private RelativeBlockVector exitBlock = null; - private HashMap exits = new HashMap(); - private int portalBlockOpen = Material.PORTAL.getId(); - private int portalBlockClosed = Material.AIR.getId(); - - // iConomy information - private int useCost = 0; - private int createCost = 0; - private int destroyCost = 0; - - private Gate(String filename, Integer[][] layout, HashMap types) { - this.filename = filename; - this.layout = layout; - this.types = types; - - populateCoordinates(); - } - - private void populateCoordinates() { - ArrayList entranceList = new ArrayList(); - ArrayList borderList = new ArrayList(); - ArrayList controlList = new ArrayList(); - RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length]; - int[] exitDepths = new int[layout[0].length]; - //int bottom = 0; - RelativeBlockVector lastExit = null; - - for (int y = 0; y < layout.length; y++) { - for (int x = 0; x < layout[y].length; x++) { - Integer id = layout[y][x]; - - if (id == ENTRANCE || id == EXIT) { - entranceList.add(new RelativeBlockVector(x, y, 0)); - exitDepths[x] = y; - if (id == EXIT) - this.exitBlock = new RelativeBlockVector(x, y, 0); - //bottom = y; - } else if (id == CONTROL) { - controlList.add(new RelativeBlockVector(x, y, 0)); - } else if (id != ANYTHING) { - borderList.add(new RelativeBlockVector(x, y, 0)); - } - } - } - - for (int x = 0; x < exitDepths.length; x++) { - relativeExits[x] = new RelativeBlockVector(x, exitDepths[x], 0); - } - - for (int x = relativeExits.length - 1; x >= 0; x--) { - if (relativeExits[x] != null) { - lastExit = relativeExits[x]; - } else { - relativeExits[x] = lastExit; - } - - if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x); - } - - this.entrances = entranceList.toArray(this.entrances); - this.border = borderList.toArray(this.border); - this.controls = controlList.toArray(this.controls); - } - - public void save(String gateFolder) { - HashMap reverse = new HashMap(); - - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename)); - - writeConfig(bw, "portal-open", portalBlockOpen); - writeConfig(bw, "portal-closed", portalBlockClosed); - if (useCost != iConomyHandler.useCost) - writeConfig(bw, "usecost", useCost); - if (createCost != iConomyHandler.createCost) - writeConfig(bw, "createcost", createCost); - if (destroyCost != iConomyHandler.destroyCost) - writeConfig(bw, "destroycost", destroyCost); - - for (Character type : types.keySet()) { - Integer value = types.get(type); - - if (!type.equals('-')) { - reverse.put(value, type); - } - - bw.append(type); - bw.append('='); - bw.append(value.toString()); - bw.newLine(); - } - - bw.newLine(); - - for (int y = 0; y < layout.length; y++) { - for (int x = 0; x < layout[y].length; x++) { - Integer id = layout[y][x]; - Character symbol; - - if (id == ENTRANCE) { - symbol = '.'; - } else if (id == ANYTHING) { - symbol = ' '; - } else if (id == CONTROL) { - symbol = '-'; - } else if (id == EXIT) { - symbol = '*'; - } else if (reverse.containsKey(id)) { - symbol = reverse.get(id); - } else { - symbol = '?'; - } - - bw.append(symbol); - } - bw.newLine(); - } - - bw.close(); - } catch (IOException ex) { - Stargate.log.log(Level.SEVERE, "Could not load Gate " + filename + " - " + ex.getMessage()); - } - } - - private void writeConfig(BufferedWriter bw, String key, int value) throws IOException { - bw.append(String.format("%s=%d", key, value)); - bw.newLine(); - } - - public Integer[][] getLayout() { - return layout; - } - - public RelativeBlockVector[] getEntrances() { - return entrances; - } - - public RelativeBlockVector[] getBorder() { - return border; - } - - public RelativeBlockVector[] getControls() { - return controls; - } - - public HashMap getExits() { - return exits; - } - public RelativeBlockVector getExit() { - return exitBlock; - } - - public int getControlBlock() { - return types.get('-'); - } - - public String getFilename() { - return filename; - } - - public int getPortalBlockOpen() { - return portalBlockOpen; - } - - public int getPortalBlockClosed() { - return portalBlockClosed; - } - - public int getUseCost() { - return useCost; - } - - public Integer getCreateCost() { - return createCost; - } - - public Integer getDestroyCost() { - return destroyCost; - } - - public boolean matches(Block topleft, int modX, int modZ) { - return matches(new Blox(topleft), modX, modZ); - } - - public boolean matches(Blox topleft, int modX, int modZ) { - for (int y = 0; y < layout.length; y++) { - for (int x = 0; x < layout[y].length; x++) { - int id = layout[y][x]; - - if (id == ENTRANCE || id == EXIT) { - if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != 0) { - return false; - } - } else if (id == CONTROL) { - if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != getControlBlock()) { - return false; - } - } else if (id != ANYTHING) { - if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != id) { - return false; - } - } - } - } - - return true; - } - - private static void registerGate(Gate gate) { - gates.put(gate.getFilename(), gate); - - int blockID = gate.getControlBlock(); - - if (!controlBlocks.containsKey(blockID)) { - controlBlocks.put(blockID, new ArrayList()); - } - - controlBlocks.get(blockID).add(gate); - } - - private static Gate loadGate(File file) { - Scanner scanner = null; - boolean designing = false; - ArrayList> design = new ArrayList>(); - HashMap types = new HashMap(); - HashMap config = new HashMap(); - int cols = 0; - - try { - scanner = new Scanner(file); - - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); - - if (designing) { - ArrayList row = new ArrayList(); - - if (line.length() > cols) { - cols = line.length(); - } - - for (Character symbol : line.toCharArray()) { - Integer id = ANYTHING; - - if (symbol.equals('.')) { - id = ENTRANCE; - } else if (symbol.equals('*')) { - id = EXIT; - } else if (symbol.equals(' ')) { - id = ANYTHING; - } else if (symbol.equals('-')) { - id = CONTROL; - } else if ((symbol.equals('?')) || (!types.containsKey(symbol))) { - Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Unknown symbol '" + symbol + "' in diagram"); - return null; - } else { - id = types.get(symbol); - } - - row.add(id); - } - - design.add(row); - } else { - if ((line.isEmpty()) || (!line.contains("="))) { - designing = true; - } else { - String[] split = line.split("="); - String key = split[0].trim(); - String value = split[1].trim(); - - if (key.length() == 1) { - Character symbol = key.charAt(0); - Integer id = Integer.parseInt(value); - - types.put(symbol, id); - } else { - config.put(key, value); - } - } - } - } - } catch (Exception ex) { - Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Invalid block ID given"); - return null; - } finally { - if (scanner != null) scanner.close(); - } - - Integer[][] layout = new Integer[design.size()][cols]; - - for (int y = 0; y < design.size(); y++) { - ArrayList row = design.get(y); - Integer[] result = new Integer[cols]; - - for (int x = 0; x < cols; x++) { - if (x < row.size()) { - result[x] = row.get(x); - } else { - result[x] = ANYTHING; - } - } - - layout[y] = result; - } - - Gate gate = new Gate(file.getName(), layout, types); - - gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen); - gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed); - gate.useCost = readConfig(config, gate, file, "usecost", iConomyHandler.useCost); - gate.destroyCost = readConfig(config, gate, file, "destroycost", iConomyHandler.destroyCost); - gate.createCost = readConfig(config, gate, file, "createcost", iConomyHandler.createCost); - - if (gate.getControls().length != 2) { - Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points."); - return null; - } else { - gate.save(file.getParent() + "/"); // Updates format for version changes - return gate; - } - } - - private static int readConfig(HashMap config, Gate gate, File file, String key, int def) { - if (config.containsKey(key)) { - try { - return Integer.parseInt(config.get(key)); - } catch (NumberFormatException ex) { - Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), file, key)); - } - } - - return def; - } - - public static void loadGates(String gateFolder) { - File dir = new File(gateFolder); - File[] files; - - if (dir.exists()) { - files = dir.listFiles(new StargateFilenameFilter()); - } else { - files = new File[0]; - } - - if (files.length == 0) { - dir.mkdir(); - populateDefaults(gateFolder); - } else { - for (File file : files) { - Gate gate = loadGate(file); - if (gate != null) registerGate(gate); - } - } - } - - public static void populateDefaults(String gateFolder) { - int Obsidian = Material.OBSIDIAN.getId(); - Integer[][] layout = new Integer[][] { - {ANYTHING, Obsidian,Obsidian, ANYTHING}, - {Obsidian, ENTRANCE, ENTRANCE, Obsidian}, - {CONTROL, ENTRANCE, ENTRANCE, CONTROL}, - {Obsidian, EXIT, ENTRANCE, Obsidian}, - {ANYTHING, Obsidian, Obsidian, ANYTHING}, - }; - HashMap types = new HashMap(); - types.put('X', Obsidian); - types.put('-', Obsidian); - - Gate gate = new Gate("nethergate.gate", layout, types); - gate.save(gateFolder); - registerGate(gate); - } - - public static Gate[] getGatesByControlBlock(Block block) { - return getGatesByControlBlock(block.getTypeId()); - } - - public static Gate[] getGatesByControlBlock(int type) { - Gate[] result = new Gate[0]; - ArrayList lookup = controlBlocks.get(type); - - if (lookup != null) result = lookup.toArray(result); - - return result; - } - - public static Gate getGateByName(String name) { - return gates.get(name); - } - - public static int getGateCount() { - return gates.size(); - } - - static class StargateFilenameFilter implements FilenameFilter { - public boolean accept(File dir, String name) { - return name.endsWith(".gate"); - } - } -} +package net.TheDgtl.Stargate; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Scanner; +import java.util.logging.Level; + +import org.bukkit.Material; +import org.bukkit.block.Block; + +/** + * Gate.java - Plug-in for hey0's minecraft mod. + * @author Shaun (sturmeh) + * @author Dinnerbone + */ +public class Gate { + public static final int ANYTHING = -1; + public static final int ENTRANCE = -2; + public static final int CONTROL = -3; + public static final int EXIT = -4; + private static HashMap gates = new HashMap(); + private static HashMap> controlBlocks = new HashMap>(); + private static HashSet frameBlocks = new HashSet(); + + private String filename; + private Integer[][] layout; + private HashMap types; + private RelativeBlockVector[] entrances = new RelativeBlockVector[0]; + private RelativeBlockVector[] border = new RelativeBlockVector[0]; + private RelativeBlockVector[] controls = new RelativeBlockVector[0]; + private RelativeBlockVector exitBlock = null; + private HashMap exits = new HashMap(); + private int portalBlockOpen = Material.PORTAL.getId(); + private int portalBlockClosed = Material.AIR.getId(); + + // iConomy information + private int useCost = 0; + private int createCost = 0; + private int destroyCost = 0; + private boolean toOwner = false; + + private Gate(String filename, Integer[][] layout, HashMap types) { + this.filename = filename; + this.layout = layout; + this.types = types; + + populateCoordinates(); + } + + private void populateCoordinates() { + ArrayList entranceList = new ArrayList(); + ArrayList borderList = new ArrayList(); + ArrayList controlList = new ArrayList(); + RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length]; + int[] exitDepths = new int[layout[0].length]; + //int bottom = 0; + RelativeBlockVector lastExit = null; + + for (int y = 0; y < layout.length; y++) { + for (int x = 0; x < layout[y].length; x++) { + Integer id = layout[y][x]; + + if (id == ENTRANCE || id == EXIT) { + entranceList.add(new RelativeBlockVector(x, y, 0)); + exitDepths[x] = y; + if (id == EXIT) + this.exitBlock = new RelativeBlockVector(x, y, 0); + //bottom = y; + } else if (id == CONTROL) { + controlList.add(new RelativeBlockVector(x, y, 0)); + } else if (id != ANYTHING) { + borderList.add(new RelativeBlockVector(x, y, 0)); + } + } + } + + for (int x = 0; x < exitDepths.length; x++) { + relativeExits[x] = new RelativeBlockVector(x, exitDepths[x], 0); + } + + for (int x = relativeExits.length - 1; x >= 0; x--) { + if (relativeExits[x] != null) { + lastExit = relativeExits[x]; + } else { + relativeExits[x] = lastExit; + } + + if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x); + } + + this.entrances = entranceList.toArray(this.entrances); + this.border = borderList.toArray(this.border); + this.controls = controlList.toArray(this.controls); + } + + public void save(String gateFolder) { + HashMap reverse = new HashMap(); + + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename)); + + writeConfig(bw, "portal-open", portalBlockOpen); + writeConfig(bw, "portal-closed", portalBlockClosed); + if (useCost != iConomyHandler.useCost) + writeConfig(bw, "usecost", useCost); + if (createCost != iConomyHandler.createCost) + writeConfig(bw, "createcost", createCost); + if (destroyCost != iConomyHandler.destroyCost) + writeConfig(bw, "destroycost", destroyCost); + writeConfig(bw, "toowner", toOwner); + + for (Character type : types.keySet()) { + Integer value = types.get(type); + + if (!type.equals('-')) { + reverse.put(value, type); + } + + bw.append(type); + bw.append('='); + bw.append(value.toString()); + bw.newLine(); + } + + bw.newLine(); + + for (int y = 0; y < layout.length; y++) { + for (int x = 0; x < layout[y].length; x++) { + Integer id = layout[y][x]; + Character symbol; + + if (id == ENTRANCE) { + symbol = '.'; + } else if (id == ANYTHING) { + symbol = ' '; + } else if (id == CONTROL) { + symbol = '-'; + } else if (id == EXIT) { + symbol = '*'; + } else if (reverse.containsKey(id)) { + symbol = reverse.get(id); + } else { + symbol = '?'; + } + + bw.append(symbol); + } + bw.newLine(); + } + + bw.close(); + } catch (IOException ex) { + Stargate.log.log(Level.SEVERE, "Could not load Gate " + filename + " - " + ex.getMessage()); + } + } + + private void writeConfig(BufferedWriter bw, String key, int value) throws IOException { + bw.append(String.format("%s=%d", key, value)); + bw.newLine(); + } + + private void writeConfig(BufferedWriter bw, String key, boolean value) throws IOException { + bw.append(String.format("%s=%b", key, value)); + bw.newLine(); + } + + public Integer[][] getLayout() { + return layout; + } + + public RelativeBlockVector[] getEntrances() { + return entrances; + } + + public RelativeBlockVector[] getBorder() { + return border; + } + + public RelativeBlockVector[] getControls() { + return controls; + } + + public HashMap getExits() { + return exits; + } + public RelativeBlockVector getExit() { + return exitBlock; + } + + public int getControlBlock() { + return types.get('-'); + } + + public String getFilename() { + return filename; + } + + public int getPortalBlockOpen() { + return portalBlockOpen; + } + + public int getPortalBlockClosed() { + return portalBlockClosed; + } + + public int getUseCost() { + return useCost; + } + + public Integer getCreateCost() { + return createCost; + } + + public Integer getDestroyCost() { + return destroyCost; + } + + public Boolean getToOwner() { + return toOwner; + } + + public boolean matches(Block topleft, int modX, int modZ) { + return matches(new Blox(topleft), modX, modZ); + } + + public boolean matches(Blox topleft, int modX, int modZ) { + for (int y = 0; y < layout.length; y++) { + for (int x = 0; x < layout[y].length; x++) { + int id = layout[y][x]; + + if (id == ENTRANCE || id == EXIT) { + if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != 0) { + return false; + } + } else if (id == CONTROL) { + if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != getControlBlock()) { + return false; + } + } else if (id != ANYTHING) { + if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != id) { + return false; + } + } + } + } + + return true; + } + + private static void registerGate(Gate gate) { + gates.put(gate.getFilename(), gate); + + int blockID = gate.getControlBlock(); + + if (!controlBlocks.containsKey(blockID)) { + controlBlocks.put(blockID, new ArrayList()); + } + + controlBlocks.get(blockID).add(gate); + } + + private static Gate loadGate(File file) { + Scanner scanner = null; + boolean designing = false; + ArrayList> design = new ArrayList>(); + HashMap types = new HashMap(); + HashMap config = new HashMap(); + int cols = 0; + + try { + scanner = new Scanner(file); + + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + + if (designing) { + ArrayList row = new ArrayList(); + + if (line.length() > cols) { + cols = line.length(); + } + + for (Character symbol : line.toCharArray()) { + Integer id = ANYTHING; + + if (symbol.equals('.')) { + id = ENTRANCE; + } else if (symbol.equals('*')) { + id = EXIT; + } else if (symbol.equals(' ')) { + id = ANYTHING; + } else if (symbol.equals('-')) { + id = CONTROL; + } else if ((symbol.equals('?')) || (!types.containsKey(symbol))) { + Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Unknown symbol '" + symbol + "' in diagram"); + return null; + } else { + id = types.get(symbol); + } + + row.add(id); + } + + design.add(row); + } else { + if ((line.isEmpty()) || (!line.contains("="))) { + designing = true; + } else { + String[] split = line.split("="); + String key = split[0].trim(); + String value = split[1].trim(); + + if (key.length() == 1) { + Character symbol = key.charAt(0); + Integer id = Integer.parseInt(value); + + types.put(symbol, id); + frameBlocks.add(id); + } else { + config.put(key, value); + } + } + } + } + } catch (Exception ex) { + Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Invalid block ID given"); + return null; + } finally { + if (scanner != null) scanner.close(); + } + + Integer[][] layout = new Integer[design.size()][cols]; + + for (int y = 0; y < design.size(); y++) { + ArrayList row = design.get(y); + Integer[] result = new Integer[cols]; + + for (int x = 0; x < cols; x++) { + if (x < row.size()) { + result[x] = row.get(x); + } else { + result[x] = ANYTHING; + } + } + + layout[y] = result; + } + + Gate gate = new Gate(file.getName(), layout, types); + + gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen); + gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed); + gate.useCost = readConfig(config, gate, file, "usecost", iConomyHandler.useCost); + gate.destroyCost = readConfig(config, gate, file, "destroycost", iConomyHandler.destroyCost); + gate.createCost = readConfig(config, gate, file, "createcost", iConomyHandler.createCost); + gate.toOwner = (config.containsKey("toowner") ? Boolean.valueOf(config.get("toowner")) : iConomyHandler.toOwner); + + if (gate.getControls().length != 2) { + Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points."); + return null; + } else { + gate.save(file.getParent() + "/"); // Updates format for version changes + return gate; + } + } + + private static int readConfig(HashMap config, Gate gate, File file, String key, int def) { + if (config.containsKey(key)) { + try { + return Integer.parseInt(config.get(key)); + } catch (NumberFormatException ex) { + Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), file, key)); + } + } + + return def; + } + + public static void loadGates(String gateFolder) { + File dir = new File(gateFolder); + File[] files; + + if (dir.exists()) { + files = dir.listFiles(new StargateFilenameFilter()); + } else { + files = new File[0]; + } + + if (files.length == 0) { + dir.mkdir(); + populateDefaults(gateFolder); + } else { + for (File file : files) { + Gate gate = loadGate(file); + if (gate != null) registerGate(gate); + } + } + } + + public static void populateDefaults(String gateFolder) { + int Obsidian = Material.OBSIDIAN.getId(); + Integer[][] layout = new Integer[][] { + {ANYTHING, Obsidian,Obsidian, ANYTHING}, + {Obsidian, ENTRANCE, ENTRANCE, Obsidian}, + {CONTROL, ENTRANCE, ENTRANCE, CONTROL}, + {Obsidian, EXIT, ENTRANCE, Obsidian}, + {ANYTHING, Obsidian, Obsidian, ANYTHING}, + }; + HashMap types = new HashMap(); + types.put('X', Obsidian); + types.put('-', Obsidian); + + Gate gate = new Gate("nethergate.gate", layout, types); + gate.save(gateFolder); + registerGate(gate); + } + + public static Gate[] getGatesByControlBlock(Block block) { + return getGatesByControlBlock(block.getTypeId()); + } + + public static Gate[] getGatesByControlBlock(int type) { + Gate[] result = new Gate[0]; + ArrayList lookup = controlBlocks.get(type); + + if (lookup != null) result = lookup.toArray(result); + + return result; + } + + public static Gate getGateByName(String name) { + return gates.get(name); + } + + public static int getGateCount() { + return gates.size(); + } + + public static boolean isGateBlock(int type) { + return frameBlocks.contains(type); + } + + static class StargateFilenameFilter implements FilenameFilter { + public boolean accept(File dir, String name) { + return name.endsWith(".gate"); + } + } + + public static void clearGates() { + gates.clear(); + controlBlocks.clear(); + frameBlocks.clear(); + } +} diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index dcbd0a6..2ac991e 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -568,6 +568,12 @@ public class Portal { boolean priv = (options.indexOf('p') != -1 || options.indexOf('P') != -1); boolean free = (options.indexOf('f') != - 1|| options.indexOf('F') != -1); + // Check permissions for options. + if (!Stargate.hasPerm(player, "stargate.option.hidden", player.isOp())) hidden = false; + if (!Stargate.hasPerm(player, "stargate.option.alwayson", player.isOp())) alwaysOn = false; + if (!Stargate.hasPerm(player, "stargate.option.private", player.isOp())) priv = false; + if (!Stargate.hasPerm(player, "stargate.option.free", player.isOp())) free = false; + // Check if the user can only create personal gates, set network if so if (Stargate.hasPerm(player, "stargate.create.personal", false) && !Stargate.hasPerm(player, "stargate.create", player.isOp()) ) { diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index 8ca7496..6dc6a3f 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -10,17 +10,19 @@ import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Vehicle; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; +import org.bukkit.event.Event.Result; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityListener; @@ -85,7 +87,6 @@ public class Stargate extends JavaPlugin { public static ConcurrentLinkedQueue openList = new ConcurrentLinkedQueue(); public static ConcurrentLinkedQueue activeList = new ConcurrentLinkedQueue(); - //private HashMap vehicles = new HashMap(); public void onDisable() { Portal.closeAllGates(); @@ -311,8 +312,9 @@ public class Stargate extends JavaPlugin { if (dest == null) return; boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp())); + String target = (portal.getGate().getToOwner() ? portal.getOwner() : null); - if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), portal.getOwner(), portal.getGate().getUseCost())) { + if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), target, portal.getGate().getUseCost())) { if (iConCharge && portal.getGate().getUseCost() > 0) { player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getUseCost())); @@ -391,6 +393,7 @@ public class Stargate extends JavaPlugin { Portal portal = Portal.getByBlock(block); // Cycle through a stargates locations if (portal != null) { + event.setUseItemInHand(Result.DENY); if (!hasPerm(player, "stargate.use", true) || (networkFilter && !hasPerm(player, "stargate.network." + portal.getNetwork(), player.isOp()))) { if (!denyMsg.isEmpty()) { @@ -432,16 +435,6 @@ public class Stargate extends JavaPlugin { } private class bListener extends BlockListener { - @Override - public void onBlockPlace(BlockPlaceEvent event) { - // Stop player from placing a block touching a portals controls - if (event.getBlockAgainst().getType() == Material.STONE_BUTTON || - event.getBlockAgainst().getType() == Material.WALL_SIGN) { - Portal portal = Portal.getByBlock(event.getBlockAgainst()); - if (portal != null) event.setCancelled(true); - } - } - @Override public void onSignChange(SignChangeEvent event) { Player player = event.getPlayer(); @@ -475,9 +468,10 @@ public class Stargate extends JavaPlugin { @Override public void onBlockBreak(BlockBreakEvent event) { + if (event.isCancelled()) return; Block block = event.getBlock(); 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.isGateBlock(block.getTypeId())) { return; } @@ -547,7 +541,7 @@ public class Stargate extends JavaPlugin { public void onEntityExplode(EntityExplodeEvent event) { if (event.isCancelled()) return; for (Block b : event.blockList()) { - if (b.getTypeId() != Material.WALL_SIGN.getId() && b.getTypeId() != Material.STONE_BUTTON.getId()) continue; + if (b.getType() != Material.WALL_SIGN && b.getType() != Material.STONE_BUTTON && !Gate.isGateBlock(b.getTypeId())) continue; Portal portal = Portal.getByBlock(b); if (portal == null) continue; if (destroyExplosion) { @@ -609,4 +603,30 @@ public class Stargate extends JavaPlugin { } } } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + sender.sendMessage("Permission Denied"); + return true; + } + String cmd = command.getName(); + if (cmd.equalsIgnoreCase("sg")) { + if (args.length != 1) return false; + if (args[0].equalsIgnoreCase("reload")) { + // Clear all lists + activeList.clear(); + openList.clear(); + Portal.clearGates(); + Gate.clearGates(); + + // Reload data + reloadConfig(); + reloadGates(); + return true; + } + return false; + } + return false; + } } diff --git a/src/net/TheDgtl/Stargate/iConomyHandler.java b/src/net/TheDgtl/Stargate/iConomyHandler.java index 4b98381..ca6d03f 100644 --- a/src/net/TheDgtl/Stargate/iConomyHandler.java +++ b/src/net/TheDgtl/Stargate/iConomyHandler.java @@ -37,7 +37,7 @@ public class iConomyHandler { if (balance < amount) return false; acc.setBalance(balance - amount); - if (toOwner && target != null && !player.equals(target)) { + if (target != null && !player.equals(target)) { Account tAcc = iConomy.getBank().getAccount(target); if (tAcc != null) { balance = tAcc.getBalance(); diff --git a/src/plugin.yml b/src/plugin.yml index af17596..733c907 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,10 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.4.0 +version: 0.4.1 description: Stargate mod for Bukkit author: Drakia -website: http://www.thedgtl.net \ No newline at end of file +website: http://www.thedgtl.net +commands: + sg: + description: Used to reload the plugin. Console use only. + usage: / reload - Used to reload the plugin. Console use only. \ No newline at end of file