Sign option permissions
Per-gate iconomy target /sg reload command Other misc fixes
This commit is contained in:
parent
2d97b497d8
commit
b9d9ee7c4f
5
README
5
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.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.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.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
|
Instructions
|
||||||
@ -73,6 +77,7 @@ iConomy Support:
|
|||||||
usecost=5
|
usecost=5
|
||||||
destroycost=5
|
destroycost=5
|
||||||
createcost=5
|
createcost=5
|
||||||
|
toowner=true
|
||||||
|
|
||||||
==============
|
==============
|
||||||
Custom Gate Layout
|
Custom Gate Layout
|
||||||
|
@ -1,435 +1,460 @@
|
|||||||
package net.TheDgtl.Stargate;
|
package net.TheDgtl.Stargate;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Scanner;
|
import java.util.HashSet;
|
||||||
import java.util.logging.Level;
|
import java.util.Scanner;
|
||||||
|
import java.util.logging.Level;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
/**
|
|
||||||
* Gate.java - Plug-in for hey0's minecraft mod.
|
/**
|
||||||
* @author Shaun (sturmeh)
|
* Gate.java - Plug-in for hey0's minecraft mod.
|
||||||
* @author Dinnerbone
|
* @author Shaun (sturmeh)
|
||||||
*/
|
* @author Dinnerbone
|
||||||
public class Gate {
|
*/
|
||||||
public static final int ANYTHING = -1;
|
public class Gate {
|
||||||
public static final int ENTRANCE = -2;
|
public static final int ANYTHING = -1;
|
||||||
public static final int CONTROL = -3;
|
public static final int ENTRANCE = -2;
|
||||||
public static final int EXIT = -4;
|
public static final int CONTROL = -3;
|
||||||
private static HashMap<String, Gate> gates = new HashMap<String, Gate>();
|
public static final int EXIT = -4;
|
||||||
private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<Integer, ArrayList<Gate>>();
|
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 static HashSet<Integer> frameBlocks = new HashSet<Integer>();
|
||||||
private Integer[][] layout;
|
|
||||||
private HashMap<Character, Integer> types;
|
private String filename;
|
||||||
private RelativeBlockVector[] entrances = new RelativeBlockVector[0];
|
private Integer[][] layout;
|
||||||
private RelativeBlockVector[] border = new RelativeBlockVector[0];
|
private HashMap<Character, Integer> types;
|
||||||
private RelativeBlockVector[] controls = new RelativeBlockVector[0];
|
private RelativeBlockVector[] entrances = new RelativeBlockVector[0];
|
||||||
private RelativeBlockVector exitBlock = null;
|
private RelativeBlockVector[] border = new RelativeBlockVector[0];
|
||||||
private HashMap<RelativeBlockVector, Integer> exits = new HashMap<RelativeBlockVector, Integer>();
|
private RelativeBlockVector[] controls = new RelativeBlockVector[0];
|
||||||
private int portalBlockOpen = Material.PORTAL.getId();
|
private RelativeBlockVector exitBlock = null;
|
||||||
private int portalBlockClosed = Material.AIR.getId();
|
private HashMap<RelativeBlockVector, Integer> exits = new HashMap<RelativeBlockVector, Integer>();
|
||||||
|
private int portalBlockOpen = Material.PORTAL.getId();
|
||||||
// iConomy information
|
private int portalBlockClosed = Material.AIR.getId();
|
||||||
private int useCost = 0;
|
|
||||||
private int createCost = 0;
|
// iConomy information
|
||||||
private int destroyCost = 0;
|
private int useCost = 0;
|
||||||
|
private int createCost = 0;
|
||||||
private Gate(String filename, Integer[][] layout, HashMap<Character, Integer> types) {
|
private int destroyCost = 0;
|
||||||
this.filename = filename;
|
private boolean toOwner = false;
|
||||||
this.layout = layout;
|
|
||||||
this.types = types;
|
private Gate(String filename, Integer[][] layout, HashMap<Character, Integer> types) {
|
||||||
|
this.filename = filename;
|
||||||
populateCoordinates();
|
this.layout = layout;
|
||||||
}
|
this.types = types;
|
||||||
|
|
||||||
private void populateCoordinates() {
|
populateCoordinates();
|
||||||
ArrayList<RelativeBlockVector> entranceList = new ArrayList<RelativeBlockVector>();
|
}
|
||||||
ArrayList<RelativeBlockVector> borderList = new ArrayList<RelativeBlockVector>();
|
|
||||||
ArrayList<RelativeBlockVector> controlList = new ArrayList<RelativeBlockVector>();
|
private void populateCoordinates() {
|
||||||
RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length];
|
ArrayList<RelativeBlockVector> entranceList = new ArrayList<RelativeBlockVector>();
|
||||||
int[] exitDepths = new int[layout[0].length];
|
ArrayList<RelativeBlockVector> borderList = new ArrayList<RelativeBlockVector>();
|
||||||
//int bottom = 0;
|
ArrayList<RelativeBlockVector> controlList = new ArrayList<RelativeBlockVector>();
|
||||||
RelativeBlockVector lastExit = null;
|
RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length];
|
||||||
|
int[] exitDepths = new int[layout[0].length];
|
||||||
for (int y = 0; y < layout.length; y++) {
|
//int bottom = 0;
|
||||||
for (int x = 0; x < layout[y].length; x++) {
|
RelativeBlockVector lastExit = null;
|
||||||
Integer id = layout[y][x];
|
|
||||||
|
for (int y = 0; y < layout.length; y++) {
|
||||||
if (id == ENTRANCE || id == EXIT) {
|
for (int x = 0; x < layout[y].length; x++) {
|
||||||
entranceList.add(new RelativeBlockVector(x, y, 0));
|
Integer id = layout[y][x];
|
||||||
exitDepths[x] = y;
|
|
||||||
if (id == EXIT)
|
if (id == ENTRANCE || id == EXIT) {
|
||||||
this.exitBlock = new RelativeBlockVector(x, y, 0);
|
entranceList.add(new RelativeBlockVector(x, y, 0));
|
||||||
//bottom = y;
|
exitDepths[x] = y;
|
||||||
} else if (id == CONTROL) {
|
if (id == EXIT)
|
||||||
controlList.add(new RelativeBlockVector(x, y, 0));
|
this.exitBlock = new RelativeBlockVector(x, y, 0);
|
||||||
} else if (id != ANYTHING) {
|
//bottom = y;
|
||||||
borderList.add(new RelativeBlockVector(x, y, 0));
|
} 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 = 0; x < exitDepths.length; x++) {
|
||||||
for (int x = relativeExits.length - 1; x >= 0; x--) {
|
relativeExits[x] = new RelativeBlockVector(x, exitDepths[x], 0);
|
||||||
if (relativeExits[x] != null) {
|
}
|
||||||
lastExit = relativeExits[x];
|
|
||||||
} else {
|
for (int x = relativeExits.length - 1; x >= 0; x--) {
|
||||||
relativeExits[x] = lastExit;
|
if (relativeExits[x] != null) {
|
||||||
}
|
lastExit = relativeExits[x];
|
||||||
|
} else {
|
||||||
if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x);
|
relativeExits[x] = lastExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entrances = entranceList.toArray(this.entrances);
|
if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x);
|
||||||
this.border = borderList.toArray(this.border);
|
}
|
||||||
this.controls = controlList.toArray(this.controls);
|
|
||||||
}
|
this.entrances = entranceList.toArray(this.entrances);
|
||||||
|
this.border = borderList.toArray(this.border);
|
||||||
public void save(String gateFolder) {
|
this.controls = controlList.toArray(this.controls);
|
||||||
HashMap<Integer, Character> reverse = new HashMap<Integer, Character>();
|
}
|
||||||
|
|
||||||
try {
|
public void save(String gateFolder) {
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename));
|
HashMap<Integer, Character> reverse = new HashMap<Integer, Character>();
|
||||||
|
|
||||||
writeConfig(bw, "portal-open", portalBlockOpen);
|
try {
|
||||||
writeConfig(bw, "portal-closed", portalBlockClosed);
|
BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename));
|
||||||
if (useCost != iConomyHandler.useCost)
|
|
||||||
writeConfig(bw, "usecost", useCost);
|
writeConfig(bw, "portal-open", portalBlockOpen);
|
||||||
if (createCost != iConomyHandler.createCost)
|
writeConfig(bw, "portal-closed", portalBlockClosed);
|
||||||
writeConfig(bw, "createcost", createCost);
|
if (useCost != iConomyHandler.useCost)
|
||||||
if (destroyCost != iConomyHandler.destroyCost)
|
writeConfig(bw, "usecost", useCost);
|
||||||
writeConfig(bw, "destroycost", destroyCost);
|
if (createCost != iConomyHandler.createCost)
|
||||||
|
writeConfig(bw, "createcost", createCost);
|
||||||
for (Character type : types.keySet()) {
|
if (destroyCost != iConomyHandler.destroyCost)
|
||||||
Integer value = types.get(type);
|
writeConfig(bw, "destroycost", destroyCost);
|
||||||
|
writeConfig(bw, "toowner", toOwner);
|
||||||
if (!type.equals('-')) {
|
|
||||||
reverse.put(value, type);
|
for (Character type : types.keySet()) {
|
||||||
}
|
Integer value = types.get(type);
|
||||||
|
|
||||||
bw.append(type);
|
if (!type.equals('-')) {
|
||||||
bw.append('=');
|
reverse.put(value, type);
|
||||||
bw.append(value.toString());
|
}
|
||||||
bw.newLine();
|
|
||||||
}
|
bw.append(type);
|
||||||
|
bw.append('=');
|
||||||
bw.newLine();
|
bw.append(value.toString());
|
||||||
|
bw.newLine();
|
||||||
for (int y = 0; y < layout.length; y++) {
|
}
|
||||||
for (int x = 0; x < layout[y].length; x++) {
|
|
||||||
Integer id = layout[y][x];
|
bw.newLine();
|
||||||
Character symbol;
|
|
||||||
|
for (int y = 0; y < layout.length; y++) {
|
||||||
if (id == ENTRANCE) {
|
for (int x = 0; x < layout[y].length; x++) {
|
||||||
symbol = '.';
|
Integer id = layout[y][x];
|
||||||
} else if (id == ANYTHING) {
|
Character symbol;
|
||||||
symbol = ' ';
|
|
||||||
} else if (id == CONTROL) {
|
if (id == ENTRANCE) {
|
||||||
symbol = '-';
|
symbol = '.';
|
||||||
} else if (id == EXIT) {
|
} else if (id == ANYTHING) {
|
||||||
symbol = '*';
|
symbol = ' ';
|
||||||
} else if (reverse.containsKey(id)) {
|
} else if (id == CONTROL) {
|
||||||
symbol = reverse.get(id);
|
symbol = '-';
|
||||||
} else {
|
} else if (id == EXIT) {
|
||||||
symbol = '?';
|
symbol = '*';
|
||||||
}
|
} else if (reverse.containsKey(id)) {
|
||||||
|
symbol = reverse.get(id);
|
||||||
bw.append(symbol);
|
} else {
|
||||||
}
|
symbol = '?';
|
||||||
bw.newLine();
|
}
|
||||||
}
|
|
||||||
|
bw.append(symbol);
|
||||||
bw.close();
|
}
|
||||||
} catch (IOException ex) {
|
bw.newLine();
|
||||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + filename + " - " + ex.getMessage());
|
}
|
||||||
}
|
|
||||||
}
|
bw.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
private void writeConfig(BufferedWriter bw, String key, int value) throws IOException {
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + filename + " - " + ex.getMessage());
|
||||||
bw.append(String.format("%s=%d", key, value));
|
}
|
||||||
bw.newLine();
|
}
|
||||||
}
|
|
||||||
|
private void writeConfig(BufferedWriter bw, String key, int value) throws IOException {
|
||||||
public Integer[][] getLayout() {
|
bw.append(String.format("%s=%d", key, value));
|
||||||
return layout;
|
bw.newLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelativeBlockVector[] getEntrances() {
|
private void writeConfig(BufferedWriter bw, String key, boolean value) throws IOException {
|
||||||
return entrances;
|
bw.append(String.format("%s=%b", key, value));
|
||||||
}
|
bw.newLine();
|
||||||
|
}
|
||||||
public RelativeBlockVector[] getBorder() {
|
|
||||||
return border;
|
public Integer[][] getLayout() {
|
||||||
}
|
return layout;
|
||||||
|
}
|
||||||
public RelativeBlockVector[] getControls() {
|
|
||||||
return controls;
|
public RelativeBlockVector[] getEntrances() {
|
||||||
}
|
return entrances;
|
||||||
|
}
|
||||||
public HashMap<RelativeBlockVector, Integer> getExits() {
|
|
||||||
return exits;
|
public RelativeBlockVector[] getBorder() {
|
||||||
}
|
return border;
|
||||||
public RelativeBlockVector getExit() {
|
}
|
||||||
return exitBlock;
|
|
||||||
}
|
public RelativeBlockVector[] getControls() {
|
||||||
|
return controls;
|
||||||
public int getControlBlock() {
|
}
|
||||||
return types.get('-');
|
|
||||||
}
|
public HashMap<RelativeBlockVector, Integer> getExits() {
|
||||||
|
return exits;
|
||||||
public String getFilename() {
|
}
|
||||||
return filename;
|
public RelativeBlockVector getExit() {
|
||||||
}
|
return exitBlock;
|
||||||
|
}
|
||||||
public int getPortalBlockOpen() {
|
|
||||||
return portalBlockOpen;
|
public int getControlBlock() {
|
||||||
}
|
return types.get('-');
|
||||||
|
}
|
||||||
public int getPortalBlockClosed() {
|
|
||||||
return portalBlockClosed;
|
public String getFilename() {
|
||||||
}
|
return filename;
|
||||||
|
}
|
||||||
public int getUseCost() {
|
|
||||||
return useCost;
|
public int getPortalBlockOpen() {
|
||||||
}
|
return portalBlockOpen;
|
||||||
|
}
|
||||||
public Integer getCreateCost() {
|
|
||||||
return createCost;
|
public int getPortalBlockClosed() {
|
||||||
}
|
return portalBlockClosed;
|
||||||
|
}
|
||||||
public Integer getDestroyCost() {
|
|
||||||
return destroyCost;
|
public int getUseCost() {
|
||||||
}
|
return useCost;
|
||||||
|
}
|
||||||
public boolean matches(Block topleft, int modX, int modZ) {
|
|
||||||
return matches(new Blox(topleft), modX, modZ);
|
public Integer getCreateCost() {
|
||||||
}
|
return createCost;
|
||||||
|
}
|
||||||
public boolean matches(Blox topleft, int modX, int modZ) {
|
|
||||||
for (int y = 0; y < layout.length; y++) {
|
public Integer getDestroyCost() {
|
||||||
for (int x = 0; x < layout[y].length; x++) {
|
return destroyCost;
|
||||||
int id = layout[y][x];
|
}
|
||||||
|
|
||||||
if (id == ENTRANCE || id == EXIT) {
|
public Boolean getToOwner() {
|
||||||
if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != 0) {
|
return toOwner;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
} else if (id == CONTROL) {
|
public boolean matches(Block topleft, int modX, int modZ) {
|
||||||
if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != getControlBlock()) {
|
return matches(new Blox(topleft), modX, modZ);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
} else if (id != ANYTHING) {
|
public boolean matches(Blox topleft, int modX, int modZ) {
|
||||||
if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != id) {
|
for (int y = 0; y < layout.length; y++) {
|
||||||
return false;
|
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;
|
||||||
return true;
|
}
|
||||||
}
|
} else if (id == CONTROL) {
|
||||||
|
if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != getControlBlock()) {
|
||||||
private static void registerGate(Gate gate) {
|
return false;
|
||||||
gates.put(gate.getFilename(), gate);
|
}
|
||||||
|
} else if (id != ANYTHING) {
|
||||||
int blockID = gate.getControlBlock();
|
if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != id) {
|
||||||
|
return false;
|
||||||
if (!controlBlocks.containsKey(blockID)) {
|
}
|
||||||
controlBlocks.put(blockID, new ArrayList<Gate>());
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
controlBlocks.get(blockID).add(gate);
|
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
private static Gate loadGate(File file) {
|
|
||||||
Scanner scanner = null;
|
private static void registerGate(Gate gate) {
|
||||||
boolean designing = false;
|
gates.put(gate.getFilename(), gate);
|
||||||
ArrayList<ArrayList<Integer>> design = new ArrayList<ArrayList<Integer>>();
|
|
||||||
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
|
int blockID = gate.getControlBlock();
|
||||||
HashMap<String, String> config = new HashMap<String, String>();
|
|
||||||
int cols = 0;
|
if (!controlBlocks.containsKey(blockID)) {
|
||||||
|
controlBlocks.put(blockID, new ArrayList<Gate>());
|
||||||
try {
|
}
|
||||||
scanner = new Scanner(file);
|
|
||||||
|
controlBlocks.get(blockID).add(gate);
|
||||||
while (scanner.hasNextLine()) {
|
}
|
||||||
String line = scanner.nextLine();
|
|
||||||
|
private static Gate loadGate(File file) {
|
||||||
if (designing) {
|
Scanner scanner = null;
|
||||||
ArrayList<Integer> row = new ArrayList<Integer>();
|
boolean designing = false;
|
||||||
|
ArrayList<ArrayList<Integer>> design = new ArrayList<ArrayList<Integer>>();
|
||||||
if (line.length() > cols) {
|
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
|
||||||
cols = line.length();
|
HashMap<String, String> config = new HashMap<String, String>();
|
||||||
}
|
int cols = 0;
|
||||||
|
|
||||||
for (Character symbol : line.toCharArray()) {
|
try {
|
||||||
Integer id = ANYTHING;
|
scanner = new Scanner(file);
|
||||||
|
|
||||||
if (symbol.equals('.')) {
|
while (scanner.hasNextLine()) {
|
||||||
id = ENTRANCE;
|
String line = scanner.nextLine();
|
||||||
} else if (symbol.equals('*')) {
|
|
||||||
id = EXIT;
|
if (designing) {
|
||||||
} else if (symbol.equals(' ')) {
|
ArrayList<Integer> row = new ArrayList<Integer>();
|
||||||
id = ANYTHING;
|
|
||||||
} else if (symbol.equals('-')) {
|
if (line.length() > cols) {
|
||||||
id = CONTROL;
|
cols = line.length();
|
||||||
} 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;
|
for (Character symbol : line.toCharArray()) {
|
||||||
} else {
|
Integer id = ANYTHING;
|
||||||
id = types.get(symbol);
|
|
||||||
}
|
if (symbol.equals('.')) {
|
||||||
|
id = ENTRANCE;
|
||||||
row.add(id);
|
} else if (symbol.equals('*')) {
|
||||||
}
|
id = EXIT;
|
||||||
|
} else if (symbol.equals(' ')) {
|
||||||
design.add(row);
|
id = ANYTHING;
|
||||||
} else {
|
} else if (symbol.equals('-')) {
|
||||||
if ((line.isEmpty()) || (!line.contains("="))) {
|
id = CONTROL;
|
||||||
designing = true;
|
} else if ((symbol.equals('?')) || (!types.containsKey(symbol))) {
|
||||||
} else {
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Unknown symbol '" + symbol + "' in diagram");
|
||||||
String[] split = line.split("=");
|
return null;
|
||||||
String key = split[0].trim();
|
} else {
|
||||||
String value = split[1].trim();
|
id = types.get(symbol);
|
||||||
|
}
|
||||||
if (key.length() == 1) {
|
|
||||||
Character symbol = key.charAt(0);
|
row.add(id);
|
||||||
Integer id = Integer.parseInt(value);
|
}
|
||||||
|
|
||||||
types.put(symbol, id);
|
design.add(row);
|
||||||
} else {
|
} else {
|
||||||
config.put(key, value);
|
if ((line.isEmpty()) || (!line.contains("="))) {
|
||||||
}
|
designing = true;
|
||||||
}
|
} else {
|
||||||
}
|
String[] split = line.split("=");
|
||||||
}
|
String key = split[0].trim();
|
||||||
} catch (Exception ex) {
|
String value = split[1].trim();
|
||||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Invalid block ID given");
|
|
||||||
return null;
|
if (key.length() == 1) {
|
||||||
} finally {
|
Character symbol = key.charAt(0);
|
||||||
if (scanner != null) scanner.close();
|
Integer id = Integer.parseInt(value);
|
||||||
}
|
|
||||||
|
types.put(symbol, id);
|
||||||
Integer[][] layout = new Integer[design.size()][cols];
|
frameBlocks.add(id);
|
||||||
|
} else {
|
||||||
for (int y = 0; y < design.size(); y++) {
|
config.put(key, value);
|
||||||
ArrayList<Integer> row = design.get(y);
|
}
|
||||||
Integer[] result = new Integer[cols];
|
}
|
||||||
|
}
|
||||||
for (int x = 0; x < cols; x++) {
|
}
|
||||||
if (x < row.size()) {
|
} catch (Exception ex) {
|
||||||
result[x] = row.get(x);
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Invalid block ID given");
|
||||||
} else {
|
return null;
|
||||||
result[x] = ANYTHING;
|
} finally {
|
||||||
}
|
if (scanner != null) scanner.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
layout[y] = result;
|
Integer[][] layout = new Integer[design.size()][cols];
|
||||||
}
|
|
||||||
|
for (int y = 0; y < design.size(); y++) {
|
||||||
Gate gate = new Gate(file.getName(), layout, types);
|
ArrayList<Integer> row = design.get(y);
|
||||||
|
Integer[] result = new Integer[cols];
|
||||||
gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen);
|
|
||||||
gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed);
|
for (int x = 0; x < cols; x++) {
|
||||||
gate.useCost = readConfig(config, gate, file, "usecost", iConomyHandler.useCost);
|
if (x < row.size()) {
|
||||||
gate.destroyCost = readConfig(config, gate, file, "destroycost", iConomyHandler.destroyCost);
|
result[x] = row.get(x);
|
||||||
gate.createCost = readConfig(config, gate, file, "createcost", iConomyHandler.createCost);
|
} else {
|
||||||
|
result[x] = ANYTHING;
|
||||||
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 {
|
layout[y] = result;
|
||||||
gate.save(file.getParent() + "/"); // Updates format for version changes
|
}
|
||||||
return gate;
|
|
||||||
}
|
Gate gate = new Gate(file.getName(), layout, types);
|
||||||
}
|
|
||||||
|
gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen);
|
||||||
private static int readConfig(HashMap<String, String> config, Gate gate, File file, String key, int def) {
|
gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed);
|
||||||
if (config.containsKey(key)) {
|
gate.useCost = readConfig(config, gate, file, "usecost", iConomyHandler.useCost);
|
||||||
try {
|
gate.destroyCost = readConfig(config, gate, file, "destroycost", iConomyHandler.destroyCost);
|
||||||
return Integer.parseInt(config.get(key));
|
gate.createCost = readConfig(config, gate, file, "createcost", iConomyHandler.createCost);
|
||||||
} catch (NumberFormatException ex) {
|
gate.toOwner = (config.containsKey("toowner") ? Boolean.valueOf(config.get("toowner")) : iConomyHandler.toOwner);
|
||||||
Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), file, key));
|
|
||||||
}
|
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;
|
||||||
return def;
|
} else {
|
||||||
}
|
gate.save(file.getParent() + "/"); // Updates format for version changes
|
||||||
|
return gate;
|
||||||
public static void loadGates(String gateFolder) {
|
}
|
||||||
File dir = new File(gateFolder);
|
}
|
||||||
File[] files;
|
|
||||||
|
private static int readConfig(HashMap<String, String> config, Gate gate, File file, String key, int def) {
|
||||||
if (dir.exists()) {
|
if (config.containsKey(key)) {
|
||||||
files = dir.listFiles(new StargateFilenameFilter());
|
try {
|
||||||
} else {
|
return Integer.parseInt(config.get(key));
|
||||||
files = new File[0];
|
} catch (NumberFormatException ex) {
|
||||||
}
|
Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), file, key));
|
||||||
|
}
|
||||||
if (files.length == 0) {
|
}
|
||||||
dir.mkdir();
|
|
||||||
populateDefaults(gateFolder);
|
return def;
|
||||||
} else {
|
}
|
||||||
for (File file : files) {
|
|
||||||
Gate gate = loadGate(file);
|
public static void loadGates(String gateFolder) {
|
||||||
if (gate != null) registerGate(gate);
|
File dir = new File(gateFolder);
|
||||||
}
|
File[] files;
|
||||||
}
|
|
||||||
}
|
if (dir.exists()) {
|
||||||
|
files = dir.listFiles(new StargateFilenameFilter());
|
||||||
public static void populateDefaults(String gateFolder) {
|
} else {
|
||||||
int Obsidian = Material.OBSIDIAN.getId();
|
files = new File[0];
|
||||||
Integer[][] layout = new Integer[][] {
|
}
|
||||||
{ANYTHING, Obsidian,Obsidian, ANYTHING},
|
|
||||||
{Obsidian, ENTRANCE, ENTRANCE, Obsidian},
|
if (files.length == 0) {
|
||||||
{CONTROL, ENTRANCE, ENTRANCE, CONTROL},
|
dir.mkdir();
|
||||||
{Obsidian, EXIT, ENTRANCE, Obsidian},
|
populateDefaults(gateFolder);
|
||||||
{ANYTHING, Obsidian, Obsidian, ANYTHING},
|
} else {
|
||||||
};
|
for (File file : files) {
|
||||||
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
|
Gate gate = loadGate(file);
|
||||||
types.put('X', Obsidian);
|
if (gate != null) registerGate(gate);
|
||||||
types.put('-', Obsidian);
|
}
|
||||||
|
}
|
||||||
Gate gate = new Gate("nethergate.gate", layout, types);
|
}
|
||||||
gate.save(gateFolder);
|
|
||||||
registerGate(gate);
|
public static void populateDefaults(String gateFolder) {
|
||||||
}
|
int Obsidian = Material.OBSIDIAN.getId();
|
||||||
|
Integer[][] layout = new Integer[][] {
|
||||||
public static Gate[] getGatesByControlBlock(Block block) {
|
{ANYTHING, Obsidian,Obsidian, ANYTHING},
|
||||||
return getGatesByControlBlock(block.getTypeId());
|
{Obsidian, ENTRANCE, ENTRANCE, Obsidian},
|
||||||
}
|
{CONTROL, ENTRANCE, ENTRANCE, CONTROL},
|
||||||
|
{Obsidian, EXIT, ENTRANCE, Obsidian},
|
||||||
public static Gate[] getGatesByControlBlock(int type) {
|
{ANYTHING, Obsidian, Obsidian, ANYTHING},
|
||||||
Gate[] result = new Gate[0];
|
};
|
||||||
ArrayList<Gate> lookup = controlBlocks.get(type);
|
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
|
||||||
|
types.put('X', Obsidian);
|
||||||
if (lookup != null) result = lookup.toArray(result);
|
types.put('-', Obsidian);
|
||||||
|
|
||||||
return result;
|
Gate gate = new Gate("nethergate.gate", layout, types);
|
||||||
}
|
gate.save(gateFolder);
|
||||||
|
registerGate(gate);
|
||||||
public static Gate getGateByName(String name) {
|
}
|
||||||
return gates.get(name);
|
|
||||||
}
|
public static Gate[] getGatesByControlBlock(Block block) {
|
||||||
|
return getGatesByControlBlock(block.getTypeId());
|
||||||
public static int getGateCount() {
|
}
|
||||||
return gates.size();
|
|
||||||
}
|
public static Gate[] getGatesByControlBlock(int type) {
|
||||||
|
Gate[] result = new Gate[0];
|
||||||
static class StargateFilenameFilter implements FilenameFilter {
|
ArrayList<Gate> lookup = controlBlocks.get(type);
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith(".gate");
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -568,6 +568,12 @@ public class Portal {
|
|||||||
boolean priv = (options.indexOf('p') != -1 || options.indexOf('P') != -1);
|
boolean priv = (options.indexOf('p') != -1 || options.indexOf('P') != -1);
|
||||||
boolean free = (options.indexOf('f') != - 1|| options.indexOf('F') != -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
|
// Check if the user can only create personal gates, set network if so
|
||||||
if (Stargate.hasPerm(player, "stargate.create.personal", false) &&
|
if (Stargate.hasPerm(player, "stargate.create.personal", false) &&
|
||||||
!Stargate.hasPerm(player, "stargate.create", player.isOp()) ) {
|
!Stargate.hasPerm(player, "stargate.create", player.isOp()) ) {
|
||||||
|
@ -10,17 +10,19 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Vehicle;
|
import org.bukkit.entity.Vehicle;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
|
import org.bukkit.event.Event.Result;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockFromToEvent;
|
import org.bukkit.event.block.BlockFromToEvent;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.BlockListener;
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityListener;
|
import org.bukkit.event.entity.EntityListener;
|
||||||
@ -85,7 +87,6 @@ public class Stargate extends JavaPlugin {
|
|||||||
|
|
||||||
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>();
|
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
Portal.closeAllGates();
|
Portal.closeAllGates();
|
||||||
@ -311,8 +312,9 @@ public class Stargate extends JavaPlugin {
|
|||||||
if (dest == null) return;
|
if (dest == null) return;
|
||||||
|
|
||||||
boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp()));
|
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) {
|
if (iConCharge && portal.getGate().getUseCost() > 0) {
|
||||||
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getUseCost()));
|
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);
|
Portal portal = Portal.getByBlock(block);
|
||||||
// Cycle through a stargates locations
|
// Cycle through a stargates locations
|
||||||
if (portal != null) {
|
if (portal != null) {
|
||||||
|
event.setUseItemInHand(Result.DENY);
|
||||||
if (!hasPerm(player, "stargate.use", true) ||
|
if (!hasPerm(player, "stargate.use", true) ||
|
||||||
(networkFilter && !hasPerm(player, "stargate.network." + portal.getNetwork(), player.isOp()))) {
|
(networkFilter && !hasPerm(player, "stargate.network." + portal.getNetwork(), player.isOp()))) {
|
||||||
if (!denyMsg.isEmpty()) {
|
if (!denyMsg.isEmpty()) {
|
||||||
@ -432,16 +435,6 @@ public class Stargate extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class bListener extends BlockListener {
|
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
|
@Override
|
||||||
public void onSignChange(SignChangeEvent event) {
|
public void onSignChange(SignChangeEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@ -475,9 +468,10 @@ public class Stargate extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
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.isGateBlock(block.getTypeId())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +541,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
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.getType() != Material.WALL_SIGN && b.getType() != Material.STONE_BUTTON && !Gate.isGateBlock(b.getTypeId())) continue;
|
||||||
Portal portal = Portal.getByBlock(b);
|
Portal portal = Portal.getByBlock(b);
|
||||||
if (portal == null) continue;
|
if (portal == null) continue;
|
||||||
if (destroyExplosion) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class iConomyHandler {
|
|||||||
if (balance < amount) return false;
|
if (balance < amount) return false;
|
||||||
acc.setBalance(balance - amount);
|
acc.setBalance(balance - amount);
|
||||||
|
|
||||||
if (toOwner && target != null && !player.equals(target)) {
|
if (target != null && !player.equals(target)) {
|
||||||
Account tAcc = iConomy.getBank().getAccount(target);
|
Account tAcc = iConomy.getBank().getAccount(target);
|
||||||
if (tAcc != null) {
|
if (tAcc != null) {
|
||||||
balance = tAcc.getBalance();
|
balance = tAcc.getBalance();
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
name: Stargate
|
name: Stargate
|
||||||
main: net.TheDgtl.Stargate.Stargate
|
main: net.TheDgtl.Stargate.Stargate
|
||||||
version: 0.4.0
|
version: 0.4.1
|
||||||
description: Stargate mod for Bukkit
|
description: Stargate mod for Bukkit
|
||||||
author: Drakia
|
author: Drakia
|
||||||
website: http://www.thedgtl.net
|
website: http://www.thedgtl.net
|
||||||
|
commands:
|
||||||
|
sg:
|
||||||
|
description: Used to reload the plugin. Console use only.
|
||||||
|
usage: /<command> reload - Used to reload the plugin. Console use only.
|
Loading…
Reference in New Issue
Block a user