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);
}
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);
}
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);
}
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);
}
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);
}
public void setType(int type) {
world.getBlockAt(x, y, z).setTypeId(type);

View File

@ -19,387 +19,387 @@ import org.bukkit.block.Block;
* @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<String, Gate> gates = new HashMap<String, Gate>();
private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<Integer, ArrayList<Gate>>();
private String filename;
private Integer[][] layout;
private HashMap<Character, Integer> 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<RelativeBlockVector, Integer> exits = new HashMap<RelativeBlockVector, Integer>();
private int portalBlockOpen = Material.PORTAL.getId();
private int portalBlockClosed = Material.AIR.getId();
private Gate(String filename, Integer[][] layout, HashMap<Character, Integer> types) {
this.filename = filename;
this.layout = layout;
this.types = types;
populateCoordinates();
}
private void populateCoordinates() {
ArrayList<RelativeBlockVector> entranceList = new ArrayList<RelativeBlockVector>();
ArrayList<RelativeBlockVector> borderList = new ArrayList<RelativeBlockVector>();
ArrayList<RelativeBlockVector> controlList = new ArrayList<RelativeBlockVector>();
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<Integer, Character> reverse = new HashMap<Integer, Character>();
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename));
writeConfig(bw, "portal-open", portalBlockOpen);
writeConfig(bw, "portal-closed", portalBlockClosed);
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<RelativeBlockVector, Integer> 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 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<Gate>());
}
controlBlocks.get(blockID).add(gate);
}
private static Gate loadGate(File file) {
Scanner scanner = null;
boolean designing = false;
ArrayList<ArrayList<Integer>> design = new ArrayList<ArrayList<Integer>>();
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
HashMap<String, String> config = new HashMap<String, String>();
int cols = 0;
try {
scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (designing) {
ArrayList<Integer> row = new ArrayList<Integer>();
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<Integer> 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);
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<String, String> 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<Character, Integer> types = new HashMap<Character, Integer>();
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<Gate> lookup = controlBlocks.get(type);
if (lookup != null) result = lookup.toArray(result);
return result;
}
public static Gate getGateByName(String name) {
return gates.get(name);
}
static class StargateFilenameFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return name.endsWith(".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<String, Gate> gates = new HashMap<String, Gate>();
private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<Integer, ArrayList<Gate>>();
private String filename;
private Integer[][] layout;
private HashMap<Character, Integer> 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<RelativeBlockVector, Integer> exits = new HashMap<RelativeBlockVector, Integer>();
private int portalBlockOpen = Material.PORTAL.getId();
private int portalBlockClosed = Material.AIR.getId();
private Gate(String filename, Integer[][] layout, HashMap<Character, Integer> types) {
this.filename = filename;
this.layout = layout;
this.types = types;
populateCoordinates();
}
private void populateCoordinates() {
ArrayList<RelativeBlockVector> entranceList = new ArrayList<RelativeBlockVector>();
ArrayList<RelativeBlockVector> borderList = new ArrayList<RelativeBlockVector>();
ArrayList<RelativeBlockVector> controlList = new ArrayList<RelativeBlockVector>();
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<Integer, Character> reverse = new HashMap<Integer, Character>();
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename));
writeConfig(bw, "portal-open", portalBlockOpen);
writeConfig(bw, "portal-closed", portalBlockClosed);
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<RelativeBlockVector, Integer> 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 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<Gate>());
}
controlBlocks.get(blockID).add(gate);
}
private static Gate loadGate(File file) {
Scanner scanner = null;
boolean designing = false;
ArrayList<ArrayList<Integer>> design = new ArrayList<ArrayList<Integer>>();
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
HashMap<String, String> config = new HashMap<String, String>();
int cols = 0;
try {
scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (designing) {
ArrayList<Integer> row = new ArrayList<Integer>();
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<Integer> 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);
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<String, String> 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<Character, Integer> types = new HashMap<Character, Integer>();
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<Gate> lookup = controlBlocks.get(type);
if (lookup != null) result = lookup.toArray(result);
return result;
}
public static Gate getGateByName(String name) {
return gates.get(name);
}
static class StargateFilenameFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
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
*/
public class RelativeBlockVector {
private int right = 0;
private int depth = 0;
private int distance = 0;
private int right = 0;
private int depth = 0;
private int distance = 0;
public RelativeBlockVector(int right, int depth, int distance) {
this.right = right;
this.depth = depth;
this.distance = distance;
}
public RelativeBlockVector(int right, int depth, int distance) {
this.right = right;
this.depth = depth;
this.distance = distance;
}
public int getRight() {
return right;
}
public int getRight() {
return right;
}
public int getDepth() {
return depth;
}
public int getDepth() {
return depth;
}
public int getDistance() {
return distance;
}
public int getDistance() {
return distance;
}
}

View File

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