Updated access modifiers, fixed all warnings.
This commit is contained in:
parent
927b70fd2d
commit
3bc5ba500c
2
pom.xml
2
pom.xml
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- License -->
|
<!-- License -->
|
||||||
|
@ -29,18 +29,23 @@ import java.util.*;
|
|||||||
|
|
||||||
public class Gate implements ConfigurationSerializable {
|
public class Gate implements ConfigurationSerializable {
|
||||||
protected Location location; /* saving both location and gateBlockLocations is redundant but makes it easy to allow players to reshape gates */
|
protected Location location; /* saving both location and gateBlockLocations is redundant but makes it easy to allow players to reshape gates */
|
||||||
protected Set<Location> gateBlockLocations = new HashSet<Location>(); /* Locations of the blocks inside the gate */
|
private Set<Location> gateBlockLocations = new HashSet<>(); /* Locations of the blocks inside the gate */
|
||||||
protected Set<Block> gateFrameBlocks = new HashSet<Block>();
|
|
||||||
|
private Set<Block> gateFrameBlocks = new HashSet<>();
|
||||||
|
|
||||||
protected Location exit;
|
protected Location exit;
|
||||||
|
|
||||||
protected boolean isHidden = false;
|
private boolean isHidden = false;
|
||||||
protected boolean isOpen = false;
|
private boolean isOpen = false;
|
||||||
|
|
||||||
protected boolean allowsVehicles = true;
|
private boolean allowsVehicles = true;
|
||||||
|
|
||||||
protected String id;
|
protected String id;
|
||||||
|
|
||||||
|
public static String getGateBlocksKey() {
|
||||||
|
return gateBlocksKey;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You should never create two gates with the same 'id'. Also see 'setId(String id)'.
|
* You should never create two gates with the same 'id'. Also see 'setId(String id)'.
|
||||||
*
|
*
|
||||||
@ -77,12 +82,11 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
findPortalBlocks();
|
findPortalBlocks();
|
||||||
validate();
|
validate();
|
||||||
} else {
|
} else {
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
this.gateBlockLocations = new HashSet<>();
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
this.gateFrameBlocks = new HashSet<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return This method might return a 'null' value.
|
* @return This method might return a 'null' value.
|
||||||
*/
|
*/
|
||||||
@ -90,7 +94,6 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
return exit;
|
return exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param exit Supplying 'null' is permitted.
|
* @param exit Supplying 'null' is permitted.
|
||||||
* @throws Exception An exception will be thrown if 'null' data is supplied and this gate is open. Note that the
|
* @throws Exception An exception will be thrown if 'null' data is supplied and this gate is open. Note that the
|
||||||
@ -102,7 +105,6 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return This method will never return 'null'.
|
* @return This method will never return 'null'.
|
||||||
*/
|
*/
|
||||||
@ -110,7 +112,6 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every gate should have an unique 'id'. You should therefore check if another gate with the same 'id' exists.
|
* Every gate should have an unique 'id'. You should therefore check if another gate with the same 'id' exists.
|
||||||
* Note that this method will not check if another gate with the same 'id' exists!
|
* Note that this method will not check if another gate with the same 'id' exists!
|
||||||
@ -125,23 +126,19 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
this.id = id.toLowerCase();
|
this.id = id.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isHidden() {
|
public boolean isHidden() {
|
||||||
return isHidden;
|
return isHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setHidden(boolean isHidden) throws Exception {
|
public void setHidden(boolean isHidden) throws Exception {
|
||||||
this.isHidden = isHidden;
|
this.isHidden = isHidden;
|
||||||
this.validate();
|
this.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isOpen() {
|
public boolean isOpen() {
|
||||||
return isOpen;
|
return isOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setOpen(boolean isOpen) throws Exception {
|
public void setOpen(boolean isOpen) throws Exception {
|
||||||
if (isOpen && !this.isOpen) {
|
if (isOpen && !this.isOpen) {
|
||||||
findPortalBlocks();
|
findPortalBlocks();
|
||||||
@ -151,17 +148,14 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setAllowsVehicles(boolean allowsVehicles) {
|
public void setAllowsVehicles(boolean allowsVehicles) {
|
||||||
this.allowsVehicles = allowsVehicles;
|
this.allowsVehicles = allowsVehicles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean getAllowsVehicles() {
|
public boolean getAllowsVehicles() {
|
||||||
return this.allowsVehicles;
|
return this.allowsVehicles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Will never return 'null' but might return an empty Set.
|
* @return Will never return 'null' but might return an empty Set.
|
||||||
*/
|
*/
|
||||||
@ -169,7 +163,6 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
return gateBlockLocations;
|
return gateBlockLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Will never return 'null' but might return an empty Set.
|
* @return Will never return 'null' but might return an empty Set.
|
||||||
*/
|
*/
|
||||||
@ -177,9 +170,8 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
return gateFrameBlocks;
|
return gateFrameBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void findPortalBlocks() {
|
||||||
protected void findPortalBlocks() {
|
gateBlockLocations = new HashSet<>();
|
||||||
gateBlockLocations = new HashSet<Location>();
|
|
||||||
Set<Block> gateBlocks = FloodUtil.getGatePortalBlocks(location.getBlock());
|
Set<Block> gateBlocks = FloodUtil.getGatePortalBlocks(location.getBlock());
|
||||||
|
|
||||||
if (gateBlocks != null) {
|
if (gateBlocks != null) {
|
||||||
@ -191,35 +183,34 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
gateFrameBlocks = FloodUtil.getFrame(gateBlocks);
|
gateFrameBlocks = FloodUtil.getFrame(gateBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if values attributes do add up; will close gate on wrong values.
|
* Checks if values attributes do add up; will close gate on wrong values.
|
||||||
*/
|
*/
|
||||||
public void validate() throws Exception {
|
void validate() throws Exception {
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
this.gateBlockLocations = new HashSet<>();
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
this.gateFrameBlocks = new HashSet<>();
|
||||||
|
|
||||||
throw new Exception("Gate got closed. It has no location.");
|
throw new Exception("Gate got closed. It has no location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exit == null) {
|
if (exit == null) {
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
this.gateBlockLocations = new HashSet<>();
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
this.gateFrameBlocks = new HashSet<>();
|
||||||
|
|
||||||
throw new Exception("Gate got closed. It has no exit.");
|
throw new Exception("Gate got closed. It has no exit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gateBlockLocations.size() == 0) {
|
if (gateBlockLocations.size() == 0) {
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
this.gateBlockLocations = new HashSet<>();
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
this.gateFrameBlocks = new HashSet<>();
|
||||||
|
|
||||||
throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)");
|
throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)");
|
||||||
}
|
}
|
||||||
@ -230,8 +221,8 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
|
|
||||||
if (b.getType() == Material.AIR) {
|
if (b.getType() == Material.AIR) {
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
this.gateBlockLocations = new HashSet<>();
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
this.gateFrameBlocks = new HashSet<>();
|
||||||
|
|
||||||
throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))");
|
throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))");
|
||||||
}
|
}
|
||||||
@ -243,17 +234,17 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
/*
|
/*
|
||||||
* INTERFACE: ConfigurationSerializable
|
* INTERFACE: ConfigurationSerializable
|
||||||
*/
|
*/
|
||||||
static protected String idKey = "id";
|
static private String idKey = "id";
|
||||||
static protected String locationKey = "location";
|
static private String locationKey = "location";
|
||||||
static protected String gateBlocksKey = "gateBlocks";
|
static private String gateBlocksKey = "gateBlocks";
|
||||||
static protected String exitKey = "exit";
|
static private String exitKey = "exit";
|
||||||
static protected String isHiddenKey = "hidden";
|
static private String isHiddenKey = "hidden";
|
||||||
static protected String isOpenKey = "open";
|
static private String isOpenKey = "open";
|
||||||
static protected String locationYawKey = "locationYaw";
|
static private String locationYawKey = "locationYaw";
|
||||||
static protected String locationPitchKey = "locationPitch";
|
static private String locationPitchKey = "locationPitch";
|
||||||
static protected String exitYawKey = "exitYaw";
|
static private String exitYawKey = "exitYaw";
|
||||||
static protected String exitPitchKey = "exitPitch";
|
static private String exitPitchKey = "exitPitch";
|
||||||
static protected String allowsVehiclesKey = "allowsVehiclesKey";
|
static private String allowsVehiclesKey = "allowsVehiclesKey";
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -281,7 +272,7 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
allowsVehicles = (Boolean) map.get(allowsVehiclesKey);
|
allowsVehicles = (Boolean) map.get(allowsVehiclesKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
gateBlockLocations = new HashSet<Location>();
|
gateBlockLocations = new HashSet<>();
|
||||||
List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>) map.get(gateBlocksKey);
|
List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>) map.get(gateBlocksKey);
|
||||||
|
|
||||||
for (Map<String, Object> sgb : serializedGateBlocks) {
|
for (Map<String, Object> sgb : serializedGateBlocks) {
|
||||||
@ -305,7 +296,7 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
|
|
||||||
|
|
||||||
public Map<String, Object> serialize() {
|
public Map<String, Object> serialize() {
|
||||||
Map<String, Object> retVal = new HashMap<String, Object>();
|
Map<String, Object> retVal = new HashMap<>();
|
||||||
|
|
||||||
retVal.put(idKey, id);
|
retVal.put(idKey, id);
|
||||||
retVal.put(locationKey, LocationUtil.serializeLocation(location));
|
retVal.put(locationKey, LocationUtil.serializeLocation(location));
|
||||||
@ -324,7 +315,7 @@ public class Gate implements ConfigurationSerializable {
|
|||||||
retVal.put(locationYawKey, location.getYaw());
|
retVal.put(locationYawKey, location.getYaw());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map<String, Object>> serializedGateBlocks = new ArrayList<Map<String, Object>>();
|
List<Map<String, Object>> serializedGateBlocks = new ArrayList<>();
|
||||||
|
|
||||||
for (Location l : gateBlockLocations) {
|
for (Location l : gateBlockLocations) {
|
||||||
serializedGateBlocks.add(LocationUtil.serializeLocation(l));
|
serializedGateBlocks.add(LocationUtil.serializeLocation(l));
|
||||||
|
@ -20,11 +20,11 @@ package de.craftinc.gates;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface GateChangeListener {
|
public interface GateChangeListener {
|
||||||
public static final String newGate = "GateChangeListener-newGate"; // value will be null
|
String newGate = "GateChangeListener-newGate"; // value will be null
|
||||||
public static final String removedGate = "GateChangeListener-removedGate"; // value will be null
|
String removedGate = "GateChangeListener-removedGate"; // value will be null
|
||||||
public static final String changedID = "GateChangeListener-changedID"; // value will be the old ID
|
String changedID = "GateChangeListener-changedID"; // value will be the old ID
|
||||||
public static final String changedLocation = "GateChangeListener-changedLocation"; // value will the old location
|
String changedLocation = "GateChangeListener-changedLocation"; // value will the old location
|
||||||
public static final String changedExit = "GateChangeListener-changedExit"; // value will be the old exit
|
String changedExit = "GateChangeListener-changedExit"; // value will be the old exit
|
||||||
|
|
||||||
public void gateChangedHandler(final Gate g, final Map<String, Object> changeSet);
|
void gateChangedHandler(final Gate g, final Map<String, Object> changeSet);
|
||||||
}
|
}
|
||||||
|
@ -36,47 +36,30 @@ import de.craftinc.gates.util.SimpleLocation;
|
|||||||
|
|
||||||
|
|
||||||
public class GatesManager {
|
public class GatesManager {
|
||||||
protected File gatesConfigFile;
|
|
||||||
protected FileConfiguration gatesConfig;
|
|
||||||
protected static final String gatesPath = "gates"; // path to gates inside the yaml file
|
|
||||||
protected static final String storageVersionPath = "version";
|
|
||||||
protected static final int storageVersion = 2;
|
|
||||||
|
|
||||||
protected int chunkRadius;
|
|
||||||
|
|
||||||
protected Map<String, Gate> gatesById;
|
|
||||||
protected Map<SimpleChunk, Set<Gate>> gatesByChunk;
|
|
||||||
protected Map<SimpleLocation, Gate> gatesByLocation;
|
|
||||||
protected Map<SimpleLocation, Gate> gatesByFrameLocation;
|
|
||||||
|
|
||||||
protected List<Gate> gates;
|
protected List<Gate> gates;
|
||||||
|
|
||||||
protected boolean storageFileIsInvalid = false;
|
private static final String gatesPath = "gates"; // path to gates inside the yaml file
|
||||||
|
private static final String storageVersionPath = "version";
|
||||||
protected Set<GateChangeListener> changeListeners = new HashSet<GateChangeListener>();
|
private static final int storageVersion = 2;
|
||||||
|
|
||||||
|
|
||||||
public void addGateChangeListener(GateChangeListener listener) {
|
|
||||||
this.changeListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void removeGateChangeListener(GateChangeListener listener) {
|
|
||||||
this.changeListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private File gatesConfigFile;
|
||||||
|
private FileConfiguration gatesConfig;
|
||||||
|
private int chunkRadius;
|
||||||
|
private Map<String, Gate> gatesById;
|
||||||
|
private Map<SimpleChunk, Set<Gate>> gatesByChunk;
|
||||||
|
private Map<SimpleLocation, Gate> gatesByLocation;
|
||||||
|
private Map<SimpleLocation, Gate> gatesByFrameLocation;
|
||||||
|
private boolean storageFileIsInvalid = false;
|
||||||
|
|
||||||
public Gate getGateWithId(final String id) {
|
public Gate getGateWithId(final String id) {
|
||||||
return gatesById.get(id.toLowerCase());
|
return gatesById.get(id.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Set<Gate> getNearbyGates(final Chunk chunk) {
|
public Set<Gate> getNearbyGates(final Chunk chunk) {
|
||||||
SimpleChunk simpleChunk = new SimpleChunk(chunk);
|
SimpleChunk simpleChunk = new SimpleChunk(chunk);
|
||||||
return gatesByChunk.get(simpleChunk);
|
return gatesByChunk.get(simpleChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the closest gate.
|
* Returns the closest gate.
|
||||||
*
|
*
|
||||||
@ -138,7 +121,7 @@ public class GatesManager {
|
|||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public boolean loadGatesFromDisk() {
|
boolean loadGatesFromDisk() {
|
||||||
this.gatesConfigFile = new File(Plugin.getPlugin().getDataFolder(), "gates.yml");
|
this.gatesConfigFile = new File(Plugin.getPlugin().getDataFolder(), "gates.yml");
|
||||||
|
|
||||||
if (!this.gatesConfigFile.exists()) {
|
if (!this.gatesConfigFile.exists()) {
|
||||||
@ -168,7 +151,7 @@ public class GatesManager {
|
|||||||
this.gates = (List<Gate>) gatesConfig.getList(gatesPath);
|
this.gates = (List<Gate>) gatesConfig.getList(gatesPath);
|
||||||
|
|
||||||
if (this.gates == null) {
|
if (this.gates == null) {
|
||||||
this.gates = new ArrayList<Gate>();
|
this.gates = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Object o : this.gates) {
|
for (Object o : this.gates) {
|
||||||
@ -220,8 +203,7 @@ public class GatesManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getChunkRadius() {
|
||||||
protected int getChunkRadius() {
|
|
||||||
if (this.chunkRadius == 0) {
|
if (this.chunkRadius == 0) {
|
||||||
this.chunkRadius = Plugin.getPlugin().getConfig().getInt(ConfigurationUtil.confPlayerGateBlockUpdateRadiusKey);
|
this.chunkRadius = Plugin.getPlugin().getConfig().getInt(ConfigurationUtil.confPlayerGateBlockUpdateRadiusKey);
|
||||||
this.chunkRadius = this.chunkRadius >> 4;
|
this.chunkRadius = this.chunkRadius >> 4;
|
||||||
@ -230,97 +212,80 @@ public class GatesManager {
|
|||||||
return this.chunkRadius;
|
return this.chunkRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillGatesById() {
|
||||||
protected void fillGatesById() {
|
gatesById = new HashMap<>((int) (gates.size() * 1.25));
|
||||||
gatesById = new HashMap<String, Gate>((int) (gates.size() * 1.25));
|
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
this.addGateWithId(g);
|
this.addGateWithId(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillGatesByChunk() {
|
||||||
protected void fillGatesByChunk() {
|
HashSet<SimpleChunk> chunksUsedByGates = new HashSet<>();
|
||||||
HashSet<SimpleChunk> chunksUsedByGates = new HashSet<SimpleChunk>();
|
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
|
|
||||||
if (g.getLocation() != null) {
|
if (g.getLocation() != null) {
|
||||||
|
|
||||||
Chunk c = g.getLocation().getChunk();
|
Chunk c = g.getLocation().getChunk();
|
||||||
|
|
||||||
int x = c.getX();
|
int x = c.getX();
|
||||||
int z = c.getZ();
|
int z = c.getZ();
|
||||||
|
|
||||||
for (int i = x - getChunkRadius(); i < x + getChunkRadius(); i++) {
|
for (int i = x - getChunkRadius(); i < x + getChunkRadius(); i++) {
|
||||||
|
|
||||||
for (int j = z - getChunkRadius(); j < z + getChunkRadius(); j++) {
|
for (int j = z - getChunkRadius(); j < z + getChunkRadius(); j++) {
|
||||||
|
|
||||||
chunksUsedByGates.add(new SimpleChunk(i, j, c.getWorld()));
|
chunksUsedByGates.add(new SimpleChunk(i, j, c.getWorld()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gatesByChunk = new HashMap<SimpleChunk, Set<Gate>>((int) (chunksUsedByGates.size() * 1.25));
|
gatesByChunk = new HashMap<>((int) (chunksUsedByGates.size() * 1.25));
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
this.addGateByChunk(g);
|
this.addGateByChunk(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillGatesByLocation() {
|
||||||
protected void fillGatesByLocation() {
|
Set<Location> gateBlocks = new HashSet<>();
|
||||||
Set<Location> gateBlocks = new HashSet<Location>();
|
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
|
|
||||||
for (Location l : g.getGateBlockLocations()) {
|
for (Location l : g.getGateBlockLocations()) {
|
||||||
gateBlocks.add(l);
|
gateBlocks.add(l);
|
||||||
|
Location headLocation = l.clone().add(0, 1, 0);
|
||||||
Location headLocation = new Location(l.getWorld(),
|
|
||||||
l.getX(),
|
|
||||||
l.getY() + 1,
|
|
||||||
l.getZ());
|
|
||||||
|
|
||||||
gateBlocks.add(headLocation);
|
gateBlocks.add(headLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gatesByLocation = new HashMap<SimpleLocation, Gate>((int) (gateBlocks.size() * 1.25));
|
gatesByLocation = new HashMap<>((int) (gateBlocks.size() * 1.25));
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
this.addGateByLocations(g);
|
this.addGateByLocations(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillGatesByFrameLocation() {
|
||||||
protected void fillGatesByFrameLocation() {
|
|
||||||
int numFrameBlocks = 0;
|
int numFrameBlocks = 0;
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
numFrameBlocks += g.gateFrameBlocks.size();
|
numFrameBlocks += g.getGateFrameBlocks().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
gatesByFrameLocation = new HashMap<SimpleLocation, Gate>((int) (numFrameBlocks * 1.25));
|
gatesByFrameLocation = new HashMap<>((int) (numFrameBlocks * 1.25));
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
this.addGateByFrameLocations(g);
|
this.addGateByFrameLocations(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeGateById(final String id) {
|
||||||
protected void removeGateById(final String id) {
|
|
||||||
gatesById.remove(id);
|
gatesById.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addGateWithId(final Gate g) {
|
||||||
protected void addGateWithId(final Gate g) {
|
|
||||||
gatesById.put(g.getId(), g);
|
gatesById.put(g.getId(), g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeGateByLocation(final Set<Location> gateBlocks) {
|
||||||
protected void removeGateByLocation(final Set<Location> gateBlocks) {
|
|
||||||
if (gateBlocks != null) {
|
if (gateBlocks != null) {
|
||||||
|
|
||||||
for (Location l : gateBlocks) {
|
for (Location l : gateBlocks) {
|
||||||
@ -334,8 +299,7 @@ public class GatesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeGateByFrameLocation(final Set<Block> gateFrameBlocks) {
|
||||||
protected void removeGateByFrameLocation(final Set<Block> gateFrameBlocks) {
|
|
||||||
if (gateFrameBlocks != null) {
|
if (gateFrameBlocks != null) {
|
||||||
|
|
||||||
for (Block block : gateFrameBlocks) {
|
for (Block block : gateFrameBlocks) {
|
||||||
@ -345,8 +309,7 @@ public class GatesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addGateByLocations(final Gate g) {
|
||||||
protected void addGateByLocations(final Gate g) {
|
|
||||||
for (Location l : g.getGateBlockLocations()) {
|
for (Location l : g.getGateBlockLocations()) {
|
||||||
|
|
||||||
SimpleLocation sl = new SimpleLocation(l);
|
SimpleLocation sl = new SimpleLocation(l);
|
||||||
@ -357,16 +320,14 @@ public class GatesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addGateByFrameLocations(final Gate g) {
|
||||||
protected void addGateByFrameLocations(final Gate g) {
|
|
||||||
for (Block block : g.getGateFrameBlocks()) {
|
for (Block block : g.getGateFrameBlocks()) {
|
||||||
SimpleLocation sl = new SimpleLocation(block.getLocation());
|
SimpleLocation sl = new SimpleLocation(block.getLocation());
|
||||||
gatesByFrameLocation.put(sl, g);
|
gatesByFrameLocation.put(sl, g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeGateFromChunk(final Gate g, final Location l) {
|
||||||
protected void removeGateFromChunk(final Gate g, final Location l) {
|
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
|
|
||||||
Chunk c = l.getChunk();
|
Chunk c = l.getChunk();
|
||||||
@ -389,8 +350,7 @@ public class GatesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addGateByChunk(final Gate g) {
|
||||||
protected void addGateByChunk(final Gate g) {
|
|
||||||
Location gateLocation = g.getLocation();
|
Location gateLocation = g.getLocation();
|
||||||
|
|
||||||
if (gateLocation != null) {
|
if (gateLocation != null) {
|
||||||
@ -418,8 +378,7 @@ public class GatesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void storeInvalidGate(Map<String, Object> map) {
|
||||||
public void storeInvalidGate(Map<String, Object> map) {
|
|
||||||
File invalidGatesFile = new File(Plugin.getPlugin().getDataFolder(), "invalid_gates.yml");
|
File invalidGatesFile = new File(Plugin.getPlugin().getDataFolder(), "invalid_gates.yml");
|
||||||
Boolean invalidGatesFileExists = invalidGatesFile.exists();
|
Boolean invalidGatesFileExists = invalidGatesFile.exists();
|
||||||
|
|
||||||
@ -473,13 +432,6 @@ public class GatesManager {
|
|||||||
public void handleGateIdChange(final Gate g, final String oldId) {
|
public void handleGateIdChange(final Gate g, final String oldId) {
|
||||||
this.removeGateById(oldId);
|
this.removeGateById(oldId);
|
||||||
this.addGateWithId(g);
|
this.addGateWithId(g);
|
||||||
|
|
||||||
Map<String, Object> changeSet = new HashMap<String, Object>();
|
|
||||||
changeSet.put(GateChangeListener.changedID, oldId);
|
|
||||||
|
|
||||||
for (GateChangeListener l : this.changeListeners) {
|
|
||||||
l.gateChangedHandler(g, changeSet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -495,25 +447,11 @@ public class GatesManager {
|
|||||||
|
|
||||||
this.removeGateByFrameLocation(oldGateFrameBlocks);
|
this.removeGateByFrameLocation(oldGateFrameBlocks);
|
||||||
this.addGateByFrameLocations(g);
|
this.addGateByFrameLocations(g);
|
||||||
|
|
||||||
Map<String, Object> changeSet = new HashMap<String, Object>();
|
|
||||||
changeSet.put(GateChangeListener.changedLocation, oldLocation);
|
|
||||||
|
|
||||||
for (GateChangeListener l : this.changeListeners) {
|
|
||||||
l.gateChangedHandler(g, changeSet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void handleGateExitChange(final Gate g, final Location oldExit) {
|
public void handleGateExitChange(final Gate g, final Location oldExit) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
|
|
||||||
Map<String, Object> changeSet = new HashMap<String, Object>();
|
|
||||||
changeSet.put(GateChangeListener.changedExit, oldExit);
|
|
||||||
|
|
||||||
for (GateChangeListener l : this.changeListeners) {
|
|
||||||
l.gateChangedHandler(g, changeSet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -524,14 +462,6 @@ public class GatesManager {
|
|||||||
this.addGateByLocations(g);
|
this.addGateByLocations(g);
|
||||||
this.addGateWithId(g);
|
this.addGateWithId(g);
|
||||||
this.addGateByFrameLocations(g);
|
this.addGateByFrameLocations(g);
|
||||||
|
|
||||||
|
|
||||||
Map<String, Object> changeSet = new HashMap<String, Object>();
|
|
||||||
changeSet.put(GateChangeListener.newGate, null);
|
|
||||||
|
|
||||||
for (GateChangeListener l : this.changeListeners) {
|
|
||||||
l.gateChangedHandler(g, changeSet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -542,13 +472,6 @@ public class GatesManager {
|
|||||||
this.removeGateFromChunk(g, g.getLocation());
|
this.removeGateFromChunk(g, g.getLocation());
|
||||||
this.removeGateByLocation(g.getGateBlockLocations());
|
this.removeGateByLocation(g.getGateBlockLocations());
|
||||||
this.removeGateByFrameLocation(g.getGateFrameBlocks());
|
this.removeGateByFrameLocation(g.getGateFrameBlocks());
|
||||||
|
|
||||||
Map<String, Object> changeSet = new HashMap<String, Object>();
|
|
||||||
changeSet.put(GateChangeListener.removedGate, null);
|
|
||||||
|
|
||||||
for (GateChangeListener l : this.changeListeners) {
|
|
||||||
l.gateChangedHandler(g, changeSet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,16 +46,16 @@ public class Plugin extends JavaPlugin {
|
|||||||
private static Plugin instance;
|
private static Plugin instance;
|
||||||
private static Permission permission;
|
private static Permission permission;
|
||||||
|
|
||||||
protected String baseCommand;
|
private String baseCommand;
|
||||||
protected List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
protected List<BaseCommand> commands = new ArrayList<>();
|
||||||
protected GatesManager gatesManager = new GatesManager();
|
private GatesManager gatesManager = new GatesManager();
|
||||||
|
|
||||||
protected PlayerMoveListener moveListener = new PlayerMoveListener();
|
private PlayerMoveListener moveListener = new PlayerMoveListener();
|
||||||
protected PlayerTeleportListener teleportListener = new PlayerTeleportListener();
|
private PlayerTeleportListener teleportListener = new PlayerTeleportListener();
|
||||||
protected PlayerRespawnListener respawnListener = new PlayerRespawnListener();
|
private PlayerRespawnListener respawnListener = new PlayerRespawnListener();
|
||||||
protected PlayerChangedWorldListener worldChangeListener = new PlayerChangedWorldListener();
|
private PlayerChangedWorldListener worldChangeListener = new PlayerChangedWorldListener();
|
||||||
protected PlayerJoinListener joinListener = new PlayerJoinListener();
|
private PlayerJoinListener joinListener = new PlayerJoinListener();
|
||||||
protected BlockBreakListener blockBreakListener = new BlockBreakListener();
|
private BlockBreakListener blockBreakListener = new BlockBreakListener();
|
||||||
|
|
||||||
|
|
||||||
public Plugin() {
|
public Plugin() {
|
||||||
@ -79,7 +79,7 @@ public class Plugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void setupPermissions() {
|
private void setupPermissions() {
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ public class Plugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void registerEventListeners() {
|
private void registerEventListeners() {
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
|
|
||||||
pm.registerEvents(this.moveListener, this);
|
pm.registerEvents(this.moveListener, this);
|
||||||
@ -187,13 +187,13 @@ public class Plugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||||
List<String> parameters = new ArrayList<String>(Arrays.asList(args));
|
List<String> parameters = new ArrayList<>(Arrays.asList(args));
|
||||||
this.handleCommand(sender, parameters);
|
this.handleCommand(sender, parameters);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void handleCommand(CommandSender sender, List<String> parameters) {
|
private void handleCommand(CommandSender sender, List<String> parameters) {
|
||||||
if (parameters.size() == 0) {
|
if (parameters.size() == 0) {
|
||||||
this.commands.get(0).execute(sender, parameters);
|
this.commands.get(0).execute(sender, parameters);
|
||||||
return;
|
return;
|
||||||
@ -202,9 +202,9 @@ public class Plugin extends JavaPlugin {
|
|||||||
String commandName = parameters.get(0).toLowerCase();
|
String commandName = parameters.get(0).toLowerCase();
|
||||||
parameters.remove(0);
|
parameters.remove(0);
|
||||||
|
|
||||||
for (BaseCommand fcommand : this.commands) {
|
for (BaseCommand command : this.commands) {
|
||||||
if (fcommand.getAliases().contains(commandName)) {
|
if (command.getAliases().contains(commandName)) {
|
||||||
fcommand.execute(sender, parameters);
|
command.execute(sender, parameters);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,7 +213,6 @@ public class Plugin extends JavaPlugin {
|
|||||||
ChatColor.GREEN + " Try " + "/" + getBaseCommand() + " help");
|
ChatColor.GREEN + " Try " + "/" + getBaseCommand() + " help");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Logging
|
* Logging
|
||||||
*/
|
*/
|
||||||
|
@ -32,31 +32,29 @@ import de.craftinc.gates.util.TextUtil;
|
|||||||
|
|
||||||
public abstract class BaseCommand {
|
public abstract class BaseCommand {
|
||||||
|
|
||||||
protected List<String> aliases = new ArrayList<String>();
|
protected List<String> aliases = new ArrayList<>();
|
||||||
protected List<String> requiredParameters = new ArrayList<String>();
|
protected List<String> requiredParameters = new ArrayList<>();
|
||||||
protected List<String> optionalParameters = new ArrayList<String>();
|
List<String> optionalParameters = new ArrayList<>();
|
||||||
|
|
||||||
protected String helpDescription = "no description";
|
protected String helpDescription = "no description";
|
||||||
|
|
||||||
protected List<String> parameters;
|
List<String> parameters;
|
||||||
protected CommandSender sender;
|
CommandSender sender;
|
||||||
protected Player player;
|
protected Player player;
|
||||||
protected Gate gate;
|
protected Gate gate;
|
||||||
|
|
||||||
protected boolean senderMustBePlayer = true;
|
protected boolean senderMustBePlayer = true;
|
||||||
protected boolean hasGateParam = true;
|
boolean hasGateParam = true;
|
||||||
|
|
||||||
protected String requiredPermission;
|
protected String requiredPermission;
|
||||||
protected boolean needsPermissionAtCurrentLocation;
|
protected boolean needsPermissionAtCurrentLocation;
|
||||||
|
|
||||||
protected boolean shouldPersistToDisk;
|
protected boolean shouldPersistToDisk;
|
||||||
|
|
||||||
|
|
||||||
public List<String> getAliases() {
|
public List<String> getAliases() {
|
||||||
return aliases;
|
return aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void execute(CommandSender sender, List<String> parameters) {
|
public void execute(CommandSender sender, List<String> parameters) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
@ -81,23 +79,19 @@ public abstract class BaseCommand {
|
|||||||
return config.getBoolean(ConfigurationUtil.confSaveOnChangesKey);
|
return config.getBoolean(ConfigurationUtil.confSaveOnChangesKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
abstract protected void perform();
|
abstract protected void perform();
|
||||||
|
|
||||||
|
|
||||||
protected void sendMessage(String message) {
|
protected void sendMessage(String message) {
|
||||||
sender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void sendMessage(List<String> messages) {
|
protected void sendMessage(List<String> messages) {
|
||||||
for (String message : messages) {
|
for (String message : messages) {
|
||||||
this.sendMessage(message);
|
this.sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean validateCall() {
|
||||||
protected boolean validateCall() {
|
|
||||||
boolean allParametersThere = parameters.size() >= requiredParameters.size();
|
boolean allParametersThere = parameters.size() >= requiredParameters.size();
|
||||||
boolean senderIsPlayer = this.sender instanceof Player;
|
boolean senderIsPlayer = this.sender instanceof Player;
|
||||||
boolean hasGateParameter = false;
|
boolean hasGateParameter = false;
|
||||||
@ -110,17 +104,23 @@ public abstract class BaseCommand {
|
|||||||
boolean valid;
|
boolean valid;
|
||||||
|
|
||||||
if (this.senderMustBePlayer && !senderIsPlayer) {
|
if (this.senderMustBePlayer && !senderIsPlayer) {
|
||||||
sendMessage(ChatColor.RED + "This command can only be used by ingame players.");
|
sendMessage(ChatColor.RED + "This command can only be used by in-game players.");
|
||||||
valid = false;
|
valid = false;
|
||||||
} else {
|
} else {
|
||||||
if (!allParametersThere) {
|
if (!allParametersThere) {
|
||||||
sendMessage(ChatColor.RED + "Some parameters are missing! " + ChatColor.AQUA + "Usage: " + this.getUsageTemplate(true));
|
sendMessage(ChatColor.RED + "Some parameters are missing! " +
|
||||||
|
ChatColor.AQUA + "Usage: " +
|
||||||
|
this.getUsageTemplate()
|
||||||
|
);
|
||||||
valid = false;
|
valid = false;
|
||||||
} else if ((!senderHasPermission && this.hasGateParam) ||
|
} else if ((!senderHasPermission && this.hasGateParam) ||
|
||||||
(!senderHasPermission) ||
|
(!senderHasPermission) ||
|
||||||
(this.hasGateParam && !hasGateParameter)) {
|
(this.hasGateParam && !hasGateParameter)) {
|
||||||
|
|
||||||
sendMessage(ChatColor.RED + "You either provided a invalid gate or do not have permission to " + this.helpDescription.toLowerCase());
|
sendMessage(ChatColor.RED +
|
||||||
|
"You either provided a invalid gate or do not have permission to " +
|
||||||
|
this.helpDescription.toLowerCase()
|
||||||
|
);
|
||||||
valid = false;
|
valid = false;
|
||||||
} else {
|
} else {
|
||||||
valid = true;
|
valid = true;
|
||||||
@ -130,8 +130,7 @@ public abstract class BaseCommand {
|
|||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean setGateUsingParameter(String param) {
|
||||||
protected boolean setGateUsingParameter(String param) {
|
|
||||||
GatesManager gateManager = Plugin.getPlugin().getGatesManager();
|
GatesManager gateManager = Plugin.getPlugin().getGatesManager();
|
||||||
|
|
||||||
if (!gateManager.gateExists(param)) {
|
if (!gateManager.gateExists(param)) {
|
||||||
@ -142,11 +141,10 @@ public abstract class BaseCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will return false if a gate is required for this command but this.gate == null.
|
* This will return false if a gate is required for this command but this.gate == null.
|
||||||
*/
|
*/
|
||||||
protected boolean hasPermission() {
|
boolean hasPermission() {
|
||||||
if (Plugin.getPermission() == null) { // fallback - use the standard bukkit permission system
|
if (Plugin.getPermission() == null) { // fallback - use the standard bukkit permission system
|
||||||
return this.sender.hasPermission(this.requiredPermission);
|
return this.sender.hasPermission(this.requiredPermission);
|
||||||
}
|
}
|
||||||
@ -160,32 +158,35 @@ public abstract class BaseCommand {
|
|||||||
Player p = (Player) this.sender;
|
Player p = (Player) this.sender;
|
||||||
boolean hasPermission = false;
|
boolean hasPermission = false;
|
||||||
|
|
||||||
if (this.requiredPermission.equals(Plugin.permissionInfo)) {
|
switch (this.requiredPermission) {
|
||||||
|
case Plugin.permissionInfo:
|
||||||
|
|
||||||
if (this.hasGateParam) {
|
if (this.hasGateParam) {
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
} else {
|
} else {
|
||||||
hasPermission = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
hasPermission = hasPermissionAtPlayerLocation(p);
|
||||||
}
|
}
|
||||||
} else if (this.requiredPermission.equals(Plugin.permissionUse)) {
|
break;
|
||||||
|
case Plugin.permissionUse:
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
} else if (this.requiredPermission.equals(Plugin.permissionManage)) {
|
break;
|
||||||
|
case Plugin.permissionManage:
|
||||||
|
|
||||||
if (this.needsPermissionAtCurrentLocation && this.hasGateParam) {
|
if (this.needsPermissionAtCurrentLocation && this.hasGateParam) {
|
||||||
boolean hasPersmissionAtCurrentLocation = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
boolean hasPermissionAtCurrentLocation = hasPermissionAtPlayerLocation(p);
|
||||||
hasPermission = hasPersmissionAtCurrentLocation && this.hasPermissionAtGateLocationAndExit(p);
|
hasPermission = hasPermissionAtCurrentLocation && this.hasPermissionAtGateLocationAndExit(p);
|
||||||
} else if (this.needsPermissionAtCurrentLocation) {
|
} else if (this.needsPermissionAtCurrentLocation) {
|
||||||
hasPermission = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
hasPermission = hasPermissionAtPlayerLocation(p);
|
||||||
} else {
|
} else {
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasPermission;
|
return hasPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasPermissionAtGateLocationAndExit(Player p) {
|
||||||
protected boolean hasPermissionAtGateLocationAndExit(Player p) {
|
|
||||||
if (this.gate == null || p == null) {
|
if (this.gate == null || p == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -196,20 +197,21 @@ public abstract class BaseCommand {
|
|||||||
return permAtLocation & permAtExit;
|
return permAtLocation & permAtExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasPermissionAtPlayerLocation(Player p) {
|
||||||
// -------------------------------------------- //
|
return Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
||||||
// Help and usage description
|
|
||||||
// -------------------------------------------- //
|
|
||||||
protected String getUsageTemplate(boolean withColor, boolean withDescription) {
|
|
||||||
String ret = "";
|
|
||||||
|
|
||||||
if (withColor) {
|
|
||||||
ret += ChatColor.AQUA;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Help and usage description
|
||||||
|
*/
|
||||||
|
|
||||||
|
String getUsageTemplate(boolean withDescription) {
|
||||||
|
String ret = "";
|
||||||
|
|
||||||
|
ret += ChatColor.AQUA;
|
||||||
ret += "/" + Plugin.getPlugin().getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",") + " ";
|
ret += "/" + Plugin.getPlugin().getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",") + " ";
|
||||||
|
|
||||||
List<String> parts = new ArrayList<String>();
|
List<String> parts = new ArrayList<>();
|
||||||
|
|
||||||
for (String requiredParameter : this.requiredParameters) {
|
for (String requiredParameter : this.requiredParameters) {
|
||||||
parts.add("[" + requiredParameter + "]");
|
parts.add("[" + requiredParameter + "]");
|
||||||
@ -219,24 +221,19 @@ public abstract class BaseCommand {
|
|||||||
parts.add("*[" + optionalParameter + "]");
|
parts.add("*[" + optionalParameter + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withColor) {
|
|
||||||
ret += ChatColor.DARK_AQUA;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ret += ChatColor.DARK_AQUA;
|
||||||
ret += TextUtil.implode(parts, " ");
|
ret += TextUtil.implode(parts, " ");
|
||||||
|
|
||||||
if (withDescription) {
|
if (withDescription) {
|
||||||
ret += " ";
|
ret += " ";
|
||||||
|
|
||||||
if (withColor) {
|
|
||||||
ret += ChatColor.YELLOW;
|
ret += ChatColor.YELLOW;
|
||||||
}
|
|
||||||
ret += this.helpDescription;
|
ret += this.helpDescription;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getUsageTemplate(boolean withColor) {
|
private String getUsageTemplate() {
|
||||||
return getUsageTemplate(withColor, false);
|
return getUsageTemplate(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,25 +21,21 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
public abstract class BaseLocationCommand extends BaseCommand {
|
abstract class BaseLocationCommand extends BaseCommand {
|
||||||
|
|
||||||
protected Location getValidPlayerLocation() {
|
Location getValidPlayerLocation() {
|
||||||
// The player might stand in a half block or a sign or whatever
|
// The player might stand in a half block or a sign or whatever
|
||||||
// Therefore we load some extra locations and blocks
|
// Therefore we load some extra locations and blocks
|
||||||
Block playerBlock = player.getLocation().getBlock();
|
Location location = player.getLocation().clone();
|
||||||
|
Block playerBlock = location.getBlock();
|
||||||
Block upBlock = playerBlock.getRelative(BlockFace.UP);
|
Block upBlock = playerBlock.getRelative(BlockFace.UP);
|
||||||
|
|
||||||
if (playerBlock.getType() == Material.AIR) {
|
if (playerBlock.getType() == Material.AIR) {
|
||||||
return player.getLocation();
|
return location;
|
||||||
} else if (upBlock.getType() == Material.AIR) {
|
} else if (upBlock.getType() == Material.AIR) {
|
||||||
return new Location(player.getLocation().getWorld(),
|
return location.add(0, 1, 0);
|
||||||
player.getLocation().getX(),
|
} else {
|
||||||
player.getLocation().getY() + 1,
|
|
||||||
player.getLocation().getZ(),
|
|
||||||
player.getLocation().getYaw(),
|
|
||||||
player.getLocation().getPitch());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -25,36 +25,36 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CommandHelp extends BaseCommand {
|
public class CommandHelp extends BaseCommand {
|
||||||
|
|
||||||
public static List<List<String>> helpPages;
|
private static List<List<String>> helpPages;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// sort the usage strings
|
// sort the usage strings
|
||||||
List<String> allUsageStrings = new ArrayList<String>();
|
List<String> allUsageStrings = new ArrayList<>();
|
||||||
|
|
||||||
allUsageStrings.add(new CommandHelp().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandHelp().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandNew().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandNew().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandRemove().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandRemove().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandLocation().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandLocation().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandExit().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandExit().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandOpen().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandOpen().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandRename().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandRename().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandClose().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandClose().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandList().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandList().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandInfo().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandInfo().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandHide().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandHide().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandUnhide().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandUnhide().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandExitOpen().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandExitOpen().getUsageTemplate(true));
|
||||||
allUsageStrings.add(new CommandNearby().getUsageTemplate(true, true));
|
allUsageStrings.add(new CommandNearby().getUsageTemplate(true));
|
||||||
|
|
||||||
Collections.sort(allUsageStrings);
|
Collections.sort(allUsageStrings);
|
||||||
|
|
||||||
|
|
||||||
// put 5 commands on one page
|
// put 5 commands on one page
|
||||||
helpPages = new ArrayList<List<String>>();
|
helpPages = new ArrayList<>();
|
||||||
|
|
||||||
while (!allUsageStrings.isEmpty()) {
|
while (!allUsageStrings.isEmpty()) {
|
||||||
int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size();
|
int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size();
|
||||||
List<String> currentHelpPage = new ArrayList<String>(allUsageStrings.subList(0, toIndex));
|
List<String> currentHelpPage = new ArrayList<>(allUsageStrings.subList(0, toIndex));
|
||||||
helpPages.add(currentHelpPage);
|
helpPages.add(currentHelpPage);
|
||||||
|
|
||||||
allUsageStrings.removeAll(currentHelpPage);
|
allUsageStrings.removeAll(currentHelpPage);
|
||||||
@ -92,7 +92,7 @@ public class CommandHelp extends BaseCommand {
|
|||||||
page = 1;
|
page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(TextUtil.titleize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")"));
|
sendMessage(TextUtil.titleSize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")"));
|
||||||
|
|
||||||
page -= 1;
|
page -= 1;
|
||||||
if (page < 0 || page >= helpPages.size()) {
|
if (page < 0 || page >= helpPages.size()) {
|
||||||
|
@ -50,7 +50,7 @@ public class CommandInfo extends BaseCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(TextUtil.titleize("Information about: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
|
sendMessage(TextUtil.titleSize("Information about: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
|
||||||
} else {
|
} else {
|
||||||
boolean senderIsPlayer = this.sender instanceof Player;
|
boolean senderIsPlayer = this.sender instanceof Player;
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ public class CommandInfo extends BaseCommand {
|
|||||||
|
|
||||||
Plugin.log(this.gate.toString());
|
Plugin.log(this.gate.toString());
|
||||||
|
|
||||||
sendMessage(TextUtil.titleize("Information about closest gate: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
|
sendMessage(TextUtil.titleSize("Information about closest gate: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
String openHiddenMessage = ChatColor.DARK_AQUA + "This gate is";
|
String openHiddenMessage = ChatColor.DARK_AQUA + "This gate is";
|
||||||
|
@ -68,17 +68,17 @@ public class CommandList extends BaseCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = TextUtil.titleize("List of all gates (" + page + "/" + allPages.size() + ")") + "\n";
|
String message = TextUtil.titleSize("List of all gates (" + page + "/" + allPages.size() + ")") + "\n";
|
||||||
message += allPages.get(page - 1);
|
message += allPages.get(page - 1);
|
||||||
|
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> linesOfGateIds(List<String> gates) {
|
private static List<String> linesOfGateIds(List<String> gates) {
|
||||||
List<String> lines = new ArrayList<String>();
|
List<String> lines = new ArrayList<>();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
List<String> gateIdsForCurrentLine = new ArrayList<String>();
|
List<String> gateIdsForCurrentLine = new ArrayList<>();
|
||||||
int numCharactersInCurrentLine = 0;
|
int numCharactersInCurrentLine = 0;
|
||||||
|
|
||||||
while (index < gates.size()) {
|
while (index < gates.size()) {
|
||||||
@ -86,7 +86,7 @@ public class CommandList extends BaseCommand {
|
|||||||
int gateIdLength = gateId.length() + 2; // actual length + comma + whitespace
|
int gateIdLength = gateId.length() + 2; // actual length + comma + whitespace
|
||||||
|
|
||||||
if (gateIdLength > charactersPerLine && numCharactersInCurrentLine == 0) { // special case: very long gate id
|
if (gateIdLength > charactersPerLine && numCharactersInCurrentLine == 0) { // special case: very long gate id
|
||||||
gateIdsForCurrentLine = new ArrayList<String>();
|
gateIdsForCurrentLine = new ArrayList<>();
|
||||||
numCharactersInCurrentLine = 0;
|
numCharactersInCurrentLine = 0;
|
||||||
|
|
||||||
while ((gateId.length() + 2) > charactersPerLine) {
|
while ((gateId.length() + 2) > charactersPerLine) {
|
||||||
@ -113,7 +113,7 @@ public class CommandList extends BaseCommand {
|
|||||||
} else { // the current gate does not fit on the
|
} else { // the current gate does not fit on the
|
||||||
lines.add(TextUtil.implode(gateIdsForCurrentLine, ", ") + ", ");
|
lines.add(TextUtil.implode(gateIdsForCurrentLine, ", ") + ", ");
|
||||||
|
|
||||||
gateIdsForCurrentLine = new ArrayList<String>();
|
gateIdsForCurrentLine = new ArrayList<>();
|
||||||
numCharactersInCurrentLine = 0;
|
numCharactersInCurrentLine = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ public class CommandList extends BaseCommand {
|
|||||||
Player p = (Player) this.sender;
|
Player p = (Player) this.sender;
|
||||||
|
|
||||||
// create a copy since we cannot iterate over a collection while modifying it!
|
// create a copy since we cannot iterate over a collection while modifying it!
|
||||||
Collection<Gate> gatesCopy = new ArrayList<Gate>(gates);
|
Collection<Gate> gatesCopy = new ArrayList<>(gates);
|
||||||
|
|
||||||
for (Gate gate : gatesCopy) {
|
for (Gate gate : gatesCopy) {
|
||||||
if (gate.getLocation() != null) {
|
if (gate.getLocation() != null) {
|
||||||
@ -186,7 +186,7 @@ public class CommandList extends BaseCommand {
|
|||||||
*/
|
*/
|
||||||
private static List<List<String>> gatesSortedByName(Collection<Gate> allGates) {
|
private static List<List<String>> gatesSortedByName(Collection<Gate> allGates) {
|
||||||
// create the lists
|
// create the lists
|
||||||
List<List<String>> ids = new ArrayList<List<String>>();
|
List<List<String>> ids = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < 28; i++) {
|
for (int i = 0; i < 28; i++) {
|
||||||
ids.add(new ArrayList<String>());
|
ids.add(new ArrayList<String>());
|
||||||
@ -232,7 +232,7 @@ public class CommandList extends BaseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<List<String>> gatesSortedByName = gatesSortedByName(gates);
|
List<List<String>> gatesSortedByName = gatesSortedByName(gates);
|
||||||
List<String> allPages = new ArrayList<String>();
|
List<String> allPages = new ArrayList<>();
|
||||||
int linesLeftOnPage = linesPerPage - 1;
|
int linesLeftOnPage = linesPerPage - 1;
|
||||||
String currentPageString = "";
|
String currentPageString = "";
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class CommandLocation extends BaseLocationCommand {
|
|||||||
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
|
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sendMessage(ChatColor.RED + "There seems to be no frame at your new location! The gate got closed!" + ChatColor.AQUA + " You should build a frame now and execute:");
|
sendMessage(ChatColor.RED + "There seems to be no frame at your new location! The gate got closed!" + ChatColor.AQUA + " You should build a frame now and execute:");
|
||||||
sendMessage(new CommandOpen().getUsageTemplate(true, true));
|
sendMessage(new CommandOpen().getUsageTemplate(true));
|
||||||
} finally {
|
} finally {
|
||||||
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks);
|
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks);
|
||||||
GateBlockChangeSender.updateGateBlocks(gate);
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
|
@ -32,7 +32,7 @@ public class CommandNearby extends BaseLocationCommand {
|
|||||||
} else {
|
} else {
|
||||||
GateBlockChangeSender.temporaryHighlightGatesFrames(player, nearbyGates);
|
GateBlockChangeSender.temporaryHighlightGatesFrames(player, nearbyGates);
|
||||||
|
|
||||||
ArrayList<String> gateNames = new ArrayList<String>();
|
ArrayList<String> gateNames = new ArrayList<>();
|
||||||
|
|
||||||
for (Gate g : nearbyGates) {
|
for (Gate g : nearbyGates) {
|
||||||
gateNames.add(g.getId());
|
gateNames.add(g.getId());
|
||||||
|
@ -62,7 +62,7 @@ public class CommandNew extends BaseLocationCommand {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sendMessage(ChatColor.RED + "Your location is invalid!" + ChatColor.AQUA + "Go somewhere else and execute:");
|
sendMessage(ChatColor.RED + "Your location is invalid!" + ChatColor.AQUA + "Go somewhere else and execute:");
|
||||||
sendMessage(new CommandLocation().getUsageTemplate(true, true));
|
sendMessage(new CommandLocation().getUsageTemplate(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
gatesManager.handleNewGate(gate);
|
gatesManager.handleNewGate(gate);
|
||||||
|
@ -39,7 +39,7 @@ import org.bukkit.scheduler.BukkitScheduler;
|
|||||||
|
|
||||||
|
|
||||||
public class PlayerMoveListener implements Listener {
|
public class PlayerMoveListener implements Listener {
|
||||||
protected HashMap<String, Long> lastNoPermissionMessages = new HashMap<String, Long>();
|
private HashMap<String, Long> lastNoPermissionMessages = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
@ -150,7 +150,7 @@ public class PlayerMoveListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected boolean hasPermission(final Player player, final Gate gate) {
|
private boolean hasPermission(final Player player, final Gate gate) {
|
||||||
if (Plugin.getPermission() == null) { // fallback: use the standard bukkit permission system
|
if (Plugin.getPermission() == null) { // fallback: use the standard bukkit permission system
|
||||||
return player.hasPermission(Plugin.permissionUse);
|
return player.hasPermission(Plugin.permissionUse);
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,11 +26,11 @@ import de.craftinc.gates.Plugin;
|
|||||||
|
|
||||||
|
|
||||||
public class LocationUtil {
|
public class LocationUtil {
|
||||||
protected final static String worldKey = "world";
|
|
||||||
protected final static String xKey = "x";
|
|
||||||
protected final static String yKey = "y";
|
|
||||||
protected final static String zKey = "z";
|
|
||||||
|
|
||||||
|
private final static String worldKey = "world";
|
||||||
|
private final static String xKey = "x";
|
||||||
|
private final static String yKey = "y";
|
||||||
|
private final static String zKey = "z";
|
||||||
|
|
||||||
protected static World getWorld(final String name) throws Exception {
|
protected static World getWorld(final String name) throws Exception {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
@ -46,7 +46,6 @@ public class LocationUtil {
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes a location. Helps storing locations inside yaml files. NOTE: We do not care about yaw
|
* Serializes a location. Helps storing locations inside yaml files. NOTE: We do not care about yaw
|
||||||
* and pitch for gate locations. So we won't serialize them.
|
* and pitch for gate locations. So we won't serialize them.
|
||||||
@ -59,7 +58,7 @@ public class LocationUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> serializedLocation = new HashMap<String, Object>();
|
Map<String, Object> serializedLocation = new HashMap<>();
|
||||||
|
|
||||||
serializedLocation.put(worldKey, l.getWorld().getName());
|
serializedLocation.put(worldKey, l.getWorld().getName());
|
||||||
serializedLocation.put(xKey, l.getX());
|
serializedLocation.put(xKey, l.getX());
|
||||||
@ -69,7 +68,6 @@ public class LocationUtil {
|
|||||||
return serializedLocation;
|
return serializedLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param map A map generated with the 'serializeLocation' method. Supplying 'null' is ok.
|
* @param map A map generated with the 'serializeLocation' method. Supplying 'null' is ok.
|
||||||
* @return A deserialized location. This method will return 'null' if 'map' is null!
|
* @return A deserialized location. This method will return 'null' if 'map' is null!
|
||||||
|
@ -28,6 +28,7 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
|
|
||||||
public class MigrationUtil {
|
public class MigrationUtil {
|
||||||
|
|
||||||
public static boolean performMigration(int storageVersion, int currentVersion, List<Gate> gates) {
|
public static boolean performMigration(int storageVersion, int currentVersion, List<Gate> gates) {
|
||||||
if (storageVersion == 0 && currentVersion >= 2) {
|
if (storageVersion == 0 && currentVersion >= 2) {
|
||||||
removePortalBlocks(gates);
|
removePortalBlocks(gates);
|
||||||
@ -44,8 +45,7 @@ public class MigrationUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void removePortalBlocks(List<Gate> gates) {
|
||||||
protected static void removePortalBlocks(List<Gate> gates) {
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
|
|
||||||
for (Location l : g.getGateBlockLocations()) {
|
for (Location l : g.getGateBlockLocations()) {
|
||||||
@ -58,10 +58,8 @@ public class MigrationUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void updateAllowVehicles(List<Gate> gates) {
|
||||||
protected static void updateAllowVehicles(List<Gate> gates) {
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
|
|
||||||
g.setAllowsVehicles(true);
|
g.setAllowsVehicles(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,58 +37,82 @@ public class ConfigurationUtil {
|
|||||||
public static final String confGateMaterialKey = "gateMaterial";
|
public static final String confGateMaterialKey = "gateMaterial";
|
||||||
|
|
||||||
|
|
||||||
public static GateMaterial getPortalMaterial() {
|
static GateMaterial getPortalMaterial() {
|
||||||
String materialString = Plugin.getPlugin().getConfig().getString(confGateMaterialKey);
|
String materialString = Plugin.getPlugin().getConfig().getString(confGateMaterialKey);
|
||||||
GateMaterial material = new GateMaterial();
|
GateMaterial material = new GateMaterial();
|
||||||
|
|
||||||
if (materialString.equals("sapling")) {
|
switch (materialString) {
|
||||||
|
case "sapling":
|
||||||
material.material = Material.SAPLING;
|
material.material = Material.SAPLING;
|
||||||
} else if (materialString.equals("water")) {
|
break;
|
||||||
|
case "water":
|
||||||
material.material = Material.STATIONARY_WATER;
|
material.material = Material.STATIONARY_WATER;
|
||||||
} else if (materialString.equals("lava")) {
|
break;
|
||||||
|
case "lava":
|
||||||
material.material = Material.STATIONARY_LAVA;
|
material.material = Material.STATIONARY_LAVA;
|
||||||
} else if (materialString.equals("cobweb")) {
|
break;
|
||||||
|
case "cobweb":
|
||||||
material.material = Material.WEB;
|
material.material = Material.WEB;
|
||||||
} else if (materialString.equals("grass")) {
|
break;
|
||||||
|
case "grass":
|
||||||
material.material = Material.LONG_GRASS;
|
material.material = Material.LONG_GRASS;
|
||||||
material.data = 1;
|
material.data = 1;
|
||||||
} else if (materialString.equals("dead bush")) {
|
break;
|
||||||
|
case "dead bush":
|
||||||
material.material = Material.DEAD_BUSH;
|
material.material = Material.DEAD_BUSH;
|
||||||
} else if (materialString.equals("dandelion")) {
|
break;
|
||||||
|
case "dandelion":
|
||||||
material.material = Material.YELLOW_FLOWER;
|
material.material = Material.YELLOW_FLOWER;
|
||||||
} else if (materialString.equals("poppy")) {
|
break;
|
||||||
|
case "poppy":
|
||||||
material.material = Material.RED_ROSE;
|
material.material = Material.RED_ROSE;
|
||||||
} else if (materialString.equals("brown mushroom")) {
|
break;
|
||||||
|
case "brown mushroom":
|
||||||
material.material = Material.BROWN_MUSHROOM;
|
material.material = Material.BROWN_MUSHROOM;
|
||||||
} else if (materialString.equals("red mushroom")) {
|
break;
|
||||||
|
case "red mushroom":
|
||||||
material.material = Material.RED_MUSHROOM;
|
material.material = Material.RED_MUSHROOM;
|
||||||
} else if (materialString.equals("torch")) {
|
break;
|
||||||
|
case "torch":
|
||||||
material.material = Material.TORCH;
|
material.material = Material.TORCH;
|
||||||
} else if (materialString.equals("redstone torch (off)")) {
|
break;
|
||||||
|
case "redstone torch (off)":
|
||||||
material.material = Material.REDSTONE_TORCH_OFF;
|
material.material = Material.REDSTONE_TORCH_OFF;
|
||||||
} else if (materialString.equals("redstone torch (on)")) {
|
break;
|
||||||
|
case "redstone torch (on)":
|
||||||
material.material = Material.REDSTONE_TORCH_ON;
|
material.material = Material.REDSTONE_TORCH_ON;
|
||||||
} else if (materialString.equals("fence")) {
|
break;
|
||||||
|
case "fence":
|
||||||
material.material = Material.FENCE;
|
material.material = Material.FENCE;
|
||||||
} else if (materialString.equals("nether portal")) {
|
break;
|
||||||
|
case "nether portal":
|
||||||
material.material = Material.PORTAL;
|
material.material = Material.PORTAL;
|
||||||
} else if (materialString.equals("iron bars")) {
|
break;
|
||||||
|
case "iron bars":
|
||||||
material.material = Material.IRON_FENCE;
|
material.material = Material.IRON_FENCE;
|
||||||
} else if (materialString.equals("glass pane")) {
|
break;
|
||||||
|
case "glass pane":
|
||||||
material.material = Material.THIN_GLASS;
|
material.material = Material.THIN_GLASS;
|
||||||
} else if (materialString.equals("fence gate")) {
|
break;
|
||||||
|
case "fence gate":
|
||||||
material.material = Material.FENCE_GATE;
|
material.material = Material.FENCE_GATE;
|
||||||
} else if (materialString.equals("nether brick fence")) {
|
break;
|
||||||
|
case "nether brick fence":
|
||||||
material.material = Material.NETHER_FENCE;
|
material.material = Material.NETHER_FENCE;
|
||||||
} else if (materialString.equals("nether wart")) {
|
break;
|
||||||
|
case "nether wart":
|
||||||
material.material = Material.NETHER_WARTS;
|
material.material = Material.NETHER_WARTS;
|
||||||
} else if (materialString.equals("end portal")) {
|
break;
|
||||||
|
case "end portal":
|
||||||
material.material = Material.ENDER_PORTAL;
|
material.material = Material.ENDER_PORTAL;
|
||||||
} else if (materialString.equals("cobblestone wall")) {
|
break;
|
||||||
|
case "cobblestone wall":
|
||||||
material.material = Material.COBBLE_WALL;
|
material.material = Material.COBBLE_WALL;
|
||||||
} else { // fallback!
|
break;
|
||||||
|
default: // fallback!
|
||||||
material.material = Material.PORTAL;
|
material.material = Material.PORTAL;
|
||||||
Plugin.log(Level.WARNING, "Gate material invalid! Please check and correct your configuration file!");
|
Plugin.log(Level.WARNING, "Gate material invalid! Please check and correct your configuration file!");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return material;
|
return material;
|
||||||
|
@ -29,8 +29,8 @@ import de.craftinc.gates.Plugin;
|
|||||||
|
|
||||||
|
|
||||||
public class FloodUtil {
|
public class FloodUtil {
|
||||||
protected static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
|
private static final Set<BlockFace> exp1 = new HashSet<>();
|
||||||
protected static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
|
private static final Set<BlockFace> exp2 = new HashSet<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
exp1.add(BlockFace.UP);
|
exp1.add(BlockFace.UP);
|
||||||
@ -53,7 +53,7 @@ public class FloodUtil {
|
|||||||
*/
|
*/
|
||||||
public static Set<Block> getFrame(final Set<Block> blocks) {
|
public static Set<Block> getFrame(final Set<Block> blocks) {
|
||||||
if (blocks == null || blocks.isEmpty()) {
|
if (blocks == null || blocks.isEmpty()) {
|
||||||
return new HashSet<Block>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to find gate's direction (north-south or east-west)
|
// try to find gate's direction (north-south or east-west)
|
||||||
@ -97,8 +97,8 @@ public class FloodUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static Set<Block> _getFrame(final Set<Block> blocks, final Set<BlockFace> searchDirections) {
|
private static Set<Block> _getFrame(final Set<Block> blocks, final Set<BlockFace> searchDirections) {
|
||||||
Set<Block> frameBlocks = new HashSet<Block>();
|
Set<Block> frameBlocks = new HashSet<>();
|
||||||
|
|
||||||
for (Block b : blocks) {
|
for (Block b : blocks) {
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class FloodUtil {
|
|||||||
throw new IllegalArgumentException("'locations' must not be 'null'");
|
throw new IllegalArgumentException("'locations' must not be 'null'");
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Block> blocks = new HashSet<Block>();
|
Set<Block> blocks = new HashSet<>();
|
||||||
|
|
||||||
for (Location l : locations) {
|
for (Location l : locations) {
|
||||||
blocks.add(l.getBlock());
|
blocks.add(l.getBlock());
|
||||||
@ -167,7 +167,7 @@ public class FloodUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static Set<Block> getAirFloodBlocks(final Block startBlock,
|
private static Set<Block> getAirFloodBlocks(final Block startBlock,
|
||||||
Set<Block> foundBlocks,
|
Set<Block> foundBlocks,
|
||||||
final Set<BlockFace> expandFaces,
|
final Set<BlockFace> expandFaces,
|
||||||
int limit) {
|
int limit) {
|
||||||
|
@ -97,7 +97,7 @@ public class GateBlockChangeSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static void dehighlightGatesFrames(final Player player, final Set<Gate> gates) {
|
private static void dehighlightGatesFrames(final Player player, final Set<Gate> gates) {
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
Set<Block> frameBlocks = g.getGateFrameBlocks();
|
Set<Block> frameBlocks = g.getGateFrameBlocks();
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ public class GateBlockChangeSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static void dehighlightGateFrame(final Player player, final Gate gate) {
|
private static void dehighlightGateFrame(final Player player, final Gate gate) {
|
||||||
Set<Block> frameBlocks = gate.getGateFrameBlocks();
|
Set<Block> frameBlocks = gate.getGateFrameBlocks();
|
||||||
|
|
||||||
for (Block b : frameBlocks) {
|
for (Block b : frameBlocks) {
|
||||||
@ -207,7 +207,7 @@ public class GateBlockChangeSender {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Player> playersNearby = new ArrayList<Player>();
|
ArrayList<Player> playersNearby = new ArrayList<>();
|
||||||
|
|
||||||
int searchRadius = Plugin.getPlugin().getConfig().getInt(confPlayerGateBlockUpdateRadiusKey);
|
int searchRadius = Plugin.getPlugin().getConfig().getInt(confPlayerGateBlockUpdateRadiusKey);
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ import org.bukkit.ChatColor;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TextUtil {
|
public class TextUtil {
|
||||||
public static String titleize(String str) {
|
|
||||||
|
public static String titleSize(String str) {
|
||||||
String center = ".[ " + ChatColor.YELLOW + str + ChatColor.GOLD + " ].";
|
String center = ".[ " + ChatColor.YELLOW + str + ChatColor.GOLD + " ].";
|
||||||
|
|
||||||
if (center.length() >= 60) {
|
if (center.length() >= 60) {
|
||||||
@ -38,7 +39,7 @@ public class TextUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String repeat(String s, int times) {
|
private static String repeat(String s, int times) {
|
||||||
if (times <= 0)
|
if (times <= 0)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import org.bukkit.entity.*;
|
|||||||
|
|
||||||
|
|
||||||
public class VehicleCloner {
|
public class VehicleCloner {
|
||||||
|
|
||||||
public static Vehicle clone(Vehicle parent, Location cloneLocation) {
|
public static Vehicle clone(Vehicle parent, Location cloneLocation) {
|
||||||
Vehicle clone = cloneLocation.getWorld().spawn(cloneLocation, parent.getClass());
|
Vehicle clone = cloneLocation.getWorld().spawn(cloneLocation, parent.getClass());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user