commit
927b70fd2d
@ -27,228 +27,202 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
|||||||
import java.util.*;
|
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 */
|
||||||
protected Set<Location> gateBlockLocations = new HashSet<Location>(); /* Locations of the blocks inside the gate */
|
|
||||||
protected Set<Block> gateFrameBlocks = new HashSet<Block>();
|
protected Set<Block> gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
protected Location exit;
|
protected Location exit;
|
||||||
|
|
||||||
protected boolean isHidden = false;
|
protected boolean isHidden = false;
|
||||||
protected boolean isOpen = false;
|
protected boolean isOpen = false;
|
||||||
|
|
||||||
protected boolean allowsVehicles = true;
|
protected boolean allowsVehicles = true;
|
||||||
|
|
||||||
protected String id;
|
protected String id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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)'.
|
||||||
|
*
|
||||||
* @param id This parameter must not be 'null'. An exception will be thrown otherwise!
|
* @param id This parameter must not be 'null'. An exception will be thrown otherwise!
|
||||||
*/
|
*/
|
||||||
public Gate(final String id)
|
public Gate(final String id) {
|
||||||
{
|
|
||||||
setId(id);
|
setId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
return super.toString() + " " + this.getId();
|
||||||
return super.toString() + " " + this.getId();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return This method might return a 'null' data.
|
* @return This method might return a 'null' data.
|
||||||
*/
|
*/
|
||||||
public Location getLocation()
|
public Location getLocation() {
|
||||||
{
|
return location;
|
||||||
return location;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param location Supplying 'null' is permitted.
|
* @param location Supplying 'null' is permitted.
|
||||||
* @throws Exception Will throw an exception if the gate is open and an invalid (no gate frame) location is
|
* @throws Exception Will throw an exception if the gate is open and an invalid (no gate frame) location is
|
||||||
* supplied. Note that the supplied 'location' will be set even if an exception is thrown. Note that this
|
* supplied. Note that the supplied 'location' will be set even if an exception is thrown. Note that this
|
||||||
* gate will be closed if an exception is thrown.
|
* gate will be closed if an exception is thrown.
|
||||||
*/
|
*/
|
||||||
public void setLocation(final Location location) throws Exception
|
public void setLocation(final Location location) throws Exception {
|
||||||
{
|
this.location = location;
|
||||||
this.location = location;
|
|
||||||
|
if (isOpen) {
|
||||||
if (isOpen) {
|
|
||||||
findPortalBlocks();
|
findPortalBlocks();
|
||||||
validate();
|
validate();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return This method might return a 'null' value.
|
* @return This method might return a 'null' value.
|
||||||
*/
|
*/
|
||||||
public Location getExit()
|
public Location getExit() {
|
||||||
{
|
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
|
||||||
* supplied 'exit' will be set even if an exception is thrown. Note that this gate will be closed if an
|
* supplied 'exit' will be set even if an exception is thrown. Note that this gate will be closed if an
|
||||||
* exception is thrown.
|
* exception is thrown.
|
||||||
*/
|
*/
|
||||||
public void setExit(final Location exit) throws Exception
|
public void setExit(final Location exit) throws Exception {
|
||||||
{
|
this.exit = exit;
|
||||||
this.exit = exit;
|
validate();
|
||||||
validate();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return This method will never return 'null'.
|
* @return This method will never return 'null'.
|
||||||
*/
|
*/
|
||||||
public String getId()
|
public String getId() {
|
||||||
{
|
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!
|
||||||
|
*
|
||||||
* @param id This parameter must not be 'null'. An exception will be thrown otherwise!
|
* @param id This parameter must not be 'null'. An exception will be thrown otherwise!
|
||||||
*/
|
*/
|
||||||
public void setId(final String id)
|
public void setId(final String id) {
|
||||||
{
|
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new IllegalArgumentException("gate 'id' cannot be 'null'");
|
throw new IllegalArgumentException("gate 'id' cannot be 'null'");
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isOpen = isOpen;
|
this.isOpen = isOpen;
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
public Set<Location> getGateBlockLocations()
|
public Set<Location> getGateBlockLocations() {
|
||||||
{
|
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.
|
||||||
*/
|
*/
|
||||||
public Set<Block> getGateFrameBlocks()
|
public Set<Block> getGateFrameBlocks() {
|
||||||
{
|
|
||||||
return gateFrameBlocks;
|
return gateFrameBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void findPortalBlocks() {
|
||||||
|
gateBlockLocations = new HashSet<Location>();
|
||||||
|
Set<Block> gateBlocks = FloodUtil.getGatePortalBlocks(location.getBlock());
|
||||||
|
|
||||||
protected void findPortalBlocks()
|
if (gateBlocks != null) {
|
||||||
{
|
for (Block b : gateBlocks) {
|
||||||
gateBlockLocations = new HashSet<Location>();
|
gateBlockLocations.add(b.getLocation());
|
||||||
Set<Block> gateBlocks = FloodUtil.getGatePortalBlocks(location.getBlock());
|
}
|
||||||
|
}
|
||||||
if (gateBlocks != null) {
|
|
||||||
for (Block b : gateBlocks) {
|
|
||||||
gateBlockLocations.add(b.getLocation());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
public void validate() throws Exception {
|
||||||
{
|
if (!isOpen) {
|
||||||
if (!isOpen) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (location == null) {
|
|
||||||
isOpen = false;
|
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
|
||||||
|
|
||||||
throw new Exception("Gate got closed. It has no location.");
|
if (location == null) {
|
||||||
}
|
|
||||||
|
|
||||||
if (exit == null) {
|
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
throw new Exception("Gate got closed. It has no exit.");
|
throw new Exception("Gate got closed. It has no location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gateBlockLocations.size() == 0) {
|
if (exit == null) {
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
this.gateBlockLocations = new HashSet<Location>();
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
this.gateFrameBlocks = new HashSet<Block>();
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)");
|
throw new Exception("Gate got closed. It has no exit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gateBlockLocations.size() == 0) {
|
||||||
|
isOpen = false;
|
||||||
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
|
throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)");
|
||||||
|
}
|
||||||
|
|
||||||
if (!isHidden() && Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey)) {
|
if (!isHidden() && Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey)) {
|
||||||
|
|
||||||
@ -263,105 +237,101 @@ public class Gate implements ConfigurationSerializable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* INTERFACE: ConfigurationSerializable
|
* INTERFACE: ConfigurationSerializable
|
||||||
*/
|
*/
|
||||||
static protected String idKey = "id";
|
static protected String idKey = "id";
|
||||||
static protected String locationKey = "location";
|
static protected String locationKey = "location";
|
||||||
static protected String gateBlocksKey = "gateBlocks";
|
static protected String gateBlocksKey = "gateBlocks";
|
||||||
static protected String exitKey = "exit";
|
static protected String exitKey = "exit";
|
||||||
static protected String isHiddenKey = "hidden";
|
static protected String isHiddenKey = "hidden";
|
||||||
static protected String isOpenKey = "open";
|
static protected String isOpenKey = "open";
|
||||||
static protected String locationYawKey = "locationYaw";
|
static protected String locationYawKey = "locationYaw";
|
||||||
static protected String locationPitchKey = "locationPitch";
|
static protected String locationPitchKey = "locationPitch";
|
||||||
static protected String exitYawKey = "exitYaw";
|
static protected String exitYawKey = "exitYaw";
|
||||||
static protected String exitPitchKey = "exitPitch";
|
static protected String exitPitchKey = "exitPitch";
|
||||||
static protected String allowsVehiclesKey = "allowsVehiclesKey";
|
static protected String allowsVehiclesKey = "allowsVehiclesKey";
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Gate(Map<String, Object> map)
|
public Gate(Map<String, Object> map) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
id = map.get(idKey).toString().toLowerCase();
|
id = map.get(idKey).toString().toLowerCase();
|
||||||
|
|
||||||
isHidden = (Boolean)map.get(isHiddenKey);
|
isHidden = (Boolean) map.get(isHiddenKey);
|
||||||
isOpen = (Boolean)map.get(isOpenKey);
|
isOpen = (Boolean) map.get(isOpenKey);
|
||||||
|
|
||||||
location = LocationUtil.deserializeLocation((Map<String, Object>) map.get(locationKey));
|
location = LocationUtil.deserializeLocation((Map<String, Object>) map.get(locationKey));
|
||||||
exit = LocationUtil.deserializeLocation((Map<String, Object>) map.get(exitKey));
|
exit = LocationUtil.deserializeLocation((Map<String, Object>) map.get(exitKey));
|
||||||
|
|
||||||
if (map.containsKey(exitPitchKey)) {
|
if (map.containsKey(exitPitchKey)) {
|
||||||
exit.setPitch(((Number)map.get(exitPitchKey)).floatValue());
|
exit.setPitch(((Number) map.get(exitPitchKey)).floatValue());
|
||||||
exit.setYaw(((Number)map.get(exitYawKey)).floatValue());
|
exit.setYaw(((Number) map.get(exitYawKey)).floatValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map.containsKey(locationPitchKey)) {
|
if (map.containsKey(locationPitchKey)) {
|
||||||
location.setPitch(((Number)map.get(locationPitchKey)).floatValue());
|
location.setPitch(((Number) map.get(locationPitchKey)).floatValue());
|
||||||
location.setYaw(((Number)map.get(locationYawKey)).floatValue());
|
location.setYaw(((Number) map.get(locationYawKey)).floatValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map.containsKey(allowsVehiclesKey)) {
|
if (map.containsKey(allowsVehiclesKey)) {
|
||||||
allowsVehicles = (Boolean)map.get(allowsVehiclesKey);
|
allowsVehicles = (Boolean) map.get(allowsVehiclesKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
gateBlockLocations = new HashSet<Location>();
|
||||||
|
List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>) map.get(gateBlocksKey);
|
||||||
|
|
||||||
|
for (Map<String, Object> sgb : serializedGateBlocks) {
|
||||||
|
gateBlockLocations.add(LocationUtil.deserializeLocation(sgb));
|
||||||
}
|
}
|
||||||
|
|
||||||
gateBlockLocations = new HashSet<Location>();
|
|
||||||
List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>)map.get(gateBlocksKey);
|
|
||||||
|
|
||||||
for (Map<String, Object> sgb : serializedGateBlocks) {
|
|
||||||
gateBlockLocations.add(LocationUtil.deserializeLocation(sgb));
|
|
||||||
}
|
|
||||||
|
|
||||||
gateFrameBlocks = FloodUtil.getFrameWithLocations(gateBlockLocations);
|
gateFrameBlocks = FloodUtil.getFrameWithLocations(gateBlockLocations);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
Plugin.log("ERROR: Failed to load gate '" + id + "'! (" + e.getMessage() + ")");
|
||||||
Plugin.log("ERROR: Failed to load gate '" + id + "'! (" + e.getMessage() + ")");
|
Plugin.log("NOTE: This gate will be removed from 'gates.yml' and added to 'invalid_gates.yml'!");
|
||||||
Plugin.log("NOTE: This gate will be removed from 'gates.yml' and added to 'invalid_gates.yml'!");
|
|
||||||
|
Plugin.getPlugin().getGatesManager().storeInvalidGate(map);
|
||||||
Plugin.getPlugin().getGatesManager().storeInvalidGate(map);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
validate(); // make sure to not write invalid stuff to disk
|
validate(); // make sure to not write invalid stuff to disk
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
Plugin.log("The loaded gate " + this.getId() + " seems to be not valid: " + e.getMessage());
|
Plugin.log("The loaded gate " + this.getId() + " seems to be not valid: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Object> serialize()
|
public Map<String, Object> serialize() {
|
||||||
{
|
Map<String, Object> retVal = new HashMap<String, Object>();
|
||||||
Map<String, Object> retVal = new HashMap<String, Object>();
|
|
||||||
|
retVal.put(idKey, id);
|
||||||
retVal.put(idKey, id);
|
retVal.put(locationKey, LocationUtil.serializeLocation(location));
|
||||||
retVal.put(locationKey, LocationUtil.serializeLocation(location));
|
retVal.put(exitKey, LocationUtil.serializeLocation(exit));
|
||||||
retVal.put(exitKey, LocationUtil.serializeLocation(exit));
|
retVal.put(isHiddenKey, isHidden);
|
||||||
retVal.put(isHiddenKey, isHidden);
|
retVal.put(isOpenKey, isOpen);
|
||||||
retVal.put(isOpenKey, isOpen);
|
|
||||||
retVal.put(allowsVehiclesKey, allowsVehicles);
|
retVal.put(allowsVehiclesKey, allowsVehicles);
|
||||||
|
|
||||||
if (exit != null) {
|
if (exit != null) {
|
||||||
retVal.put(exitPitchKey, exit.getPitch());
|
retVal.put(exitPitchKey, exit.getPitch());
|
||||||
retVal.put(exitYawKey, exit.getYaw());
|
retVal.put(exitYawKey, exit.getYaw());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
retVal.put(locationPitchKey, location.getPitch());
|
retVal.put(locationPitchKey, location.getPitch());
|
||||||
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<Map<String, Object>>();
|
||||||
|
|
||||||
for (Location l : gateBlockLocations) {
|
for (Location l : gateBlockLocations) {
|
||||||
serializedGateBlocks.add(LocationUtil.serializeLocation(l));
|
serializedGateBlocks.add(LocationUtil.serializeLocation(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
retVal.put(gateBlocksKey, serializedGateBlocks);
|
retVal.put(gateBlocksKey, serializedGateBlocks);
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,12 @@ 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
|
public static final String newGate = "GateChangeListener-newGate"; // value will be null
|
||||||
public static final String removedGate = "GateChangeListener-removedGate"; // value will be null
|
public static final String removedGate = "GateChangeListener-removedGate"; // value will be null
|
||||||
public static final String changedID = "GateChangeListener-changedID"; // value will be the old ID
|
public static final String changedID = "GateChangeListener-changedID"; // value will be the old ID
|
||||||
public static final String changedLocation = "GateChangeListener-changedLocation"; // value will the old location
|
public static final String changedLocation = "GateChangeListener-changedLocation"; // value will the old location
|
||||||
public static final String changedExit = "GateChangeListener-changedExit"; // value will be the old exit
|
public static final String changedExit = "GateChangeListener-changedExit"; // value will be the old exit
|
||||||
|
|
||||||
public void gateChangedHandler(final Gate g, final Map<String, Object>changeSet);
|
public void gateChangedHandler(final Gate g, final Map<String, Object> changeSet);
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,7 @@ import de.craftinc.gates.util.SimpleChunk;
|
|||||||
import de.craftinc.gates.util.SimpleLocation;
|
import de.craftinc.gates.util.SimpleLocation;
|
||||||
|
|
||||||
|
|
||||||
public class GatesManager
|
public class GatesManager {
|
||||||
{
|
|
||||||
protected File gatesConfigFile;
|
protected File gatesConfigFile;
|
||||||
protected FileConfiguration gatesConfig;
|
protected FileConfiguration gatesConfig;
|
||||||
protected static final String gatesPath = "gates"; // path to gates inside the yaml file
|
protected static final String gatesPath = "gates"; // path to gates inside the yaml file
|
||||||
@ -57,38 +56,34 @@ public class GatesManager
|
|||||||
protected Set<GateChangeListener> changeListeners = new HashSet<GateChangeListener>();
|
protected Set<GateChangeListener> changeListeners = new HashSet<GateChangeListener>();
|
||||||
|
|
||||||
|
|
||||||
public void addGateChangeListener(GateChangeListener listener)
|
public void addGateChangeListener(GateChangeListener listener) {
|
||||||
{
|
|
||||||
this.changeListeners.add(listener);
|
this.changeListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeGateChangeListener(GateChangeListener listener)
|
public void removeGateChangeListener(GateChangeListener listener) {
|
||||||
{
|
|
||||||
this.changeListeners.remove(listener);
|
this.changeListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
{
|
return gatesByChunk.get(simpleChunk);
|
||||||
SimpleChunk simpleChunk = new SimpleChunk(chunk);
|
}
|
||||||
return gatesByChunk.get(simpleChunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the closest gate.
|
* Returns the closest gate.
|
||||||
|
*
|
||||||
* @param location The location at which to look for a gate.
|
* @param location The location at which to look for a gate.
|
||||||
* @return Might return null if there are no nearby gates.
|
* @return Might return null if there are no nearby gates.
|
||||||
*/
|
*/
|
||||||
public Gate getNearestGate(final Location location)
|
public Gate getNearestGate(final Location location) {
|
||||||
{
|
|
||||||
Set<Gate> nearbyGates = getNearbyGates(location.getChunk());
|
Set<Gate> nearbyGates = getNearbyGates(location.getChunk());
|
||||||
|
|
||||||
if (nearbyGates == null) {
|
if (nearbyGates == null) {
|
||||||
@ -110,105 +105,97 @@ public class GatesManager
|
|||||||
return nearestGate;
|
return nearestGate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Gate getGateAtLocation(final Location location)
|
public Gate getGateAtLocation(final Location location) {
|
||||||
{
|
SimpleLocation simpleLocation = new SimpleLocation(location);
|
||||||
SimpleLocation simpleLocation = new SimpleLocation(location);
|
return gatesByLocation.get(simpleLocation);
|
||||||
return gatesByLocation.get(simpleLocation);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Gate getGateAtFrameLocation(final Location location)
|
public Gate getGateAtFrameLocation(final Location location) {
|
||||||
{
|
|
||||||
SimpleLocation simpleLocation = new SimpleLocation(location);
|
SimpleLocation simpleLocation = new SimpleLocation(location);
|
||||||
return gatesByFrameLocation.get(simpleLocation);
|
return gatesByFrameLocation.get(simpleLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void saveGatesToDisk()
|
public void saveGatesToDisk() {
|
||||||
{
|
if (storageFileIsInvalid) {
|
||||||
if (storageFileIsInvalid) {
|
|
||||||
Plugin.log(Level.SEVERE, "ERROR: Not saving gates to disk. Storage file is invalid or corrupted!");
|
Plugin.log(Level.SEVERE, "ERROR: Not saving gates to disk. Storage file is invalid or corrupted!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gatesConfig.set(gatesPath, gates);
|
gatesConfig.set(gatesPath, gates);
|
||||||
gatesConfig.set(storageVersionPath, storageVersion);
|
gatesConfig.set(storageVersionPath, storageVersion);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gatesConfig.save(gatesConfigFile);
|
gatesConfig.save(gatesConfigFile);
|
||||||
Plugin.log("Saved gates to disk.");
|
Plugin.log("Saved gates to disk.");
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
Plugin.log(Level.SEVERE, "ERROR: Could not save gates to disk.");
|
||||||
Plugin.log(Level.SEVERE, "ERROR: Could not save gates to disk.");
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@SuppressWarnings("unchecked")
|
public boolean loadGatesFromDisk() {
|
||||||
public boolean loadGatesFromDisk()
|
this.gatesConfigFile = new File(Plugin.getPlugin().getDataFolder(), "gates.yml");
|
||||||
{
|
|
||||||
this.gatesConfigFile = new File(Plugin.getPlugin().getDataFolder(), "gates.yml");
|
if (!this.gatesConfigFile.exists()) {
|
||||||
|
try {
|
||||||
if(!this.gatesConfigFile.exists()) {
|
|
||||||
try {
|
|
||||||
boolean isNew = this.gatesConfigFile.createNewFile();
|
boolean isNew = this.gatesConfigFile.createNewFile();
|
||||||
|
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
Plugin.log(Level.FINEST, "Created gate storage file.");
|
Plugin.log(Level.FINEST, "Created gate storage file.");
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
this.storageFileIsInvalid = true;
|
this.storageFileIsInvalid = true;
|
||||||
Plugin.log(Level.SEVERE, "Cannot create gate storage file! No gates will be persisted.");
|
Plugin.log(Level.SEVERE, "Cannot create gate storage file! No gates will be persisted.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gatesConfig = new YamlConfiguration();
|
this.gatesConfig = new YamlConfiguration();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.gatesConfig.load(this.gatesConfigFile);
|
this.gatesConfig.load(this.gatesConfigFile);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
this.storageFileIsInvalid = true;
|
this.storageFileIsInvalid = true;
|
||||||
Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled! (" + Arrays.toString(e.getStackTrace()) + ")");
|
Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled! (" + Arrays.toString(e.getStackTrace()) + ")");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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<Gate>();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Object o : this.gates) {
|
for (Object o : this.gates) {
|
||||||
|
|
||||||
if (!(o instanceof Gate)) {
|
if (!(o instanceof Gate)) {
|
||||||
this.storageFileIsInvalid = true;
|
this.storageFileIsInvalid = true;
|
||||||
Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled! (Invalid gate class detected)");
|
Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled! (Invalid gate class detected)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Gate g : this.gates) {
|
for (Gate g : this.gates) {
|
||||||
try {
|
try {
|
||||||
g.validate();
|
g.validate();
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
try {
|
try {
|
||||||
g.setOpen(false);
|
g.setOpen(false);
|
||||||
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
catch (Exception ignored) { }
|
|
||||||
|
|
||||||
Plugin.log(Level.FINER, "closed gate '" + g.getId() + "' reason: " + e.getMessage());
|
Plugin.log(Level.FINER, "closed gate '" + g.getId() + "' reason: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fillGatesById();
|
fillGatesById();
|
||||||
fillGatesByChunk();
|
fillGatesByChunk();
|
||||||
fillGatesByLocation();
|
fillGatesByLocation();
|
||||||
fillGatesByFrameLocation();
|
fillGatesByFrameLocation();
|
||||||
|
|
||||||
Plugin.log("Loaded " + this.gates.size() + " gates.");
|
Plugin.log("Loaded " + this.gates.size() + " gates.");
|
||||||
@ -231,11 +218,10 @@ public class GatesManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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;
|
||||||
@ -245,21 +231,19 @@ public class GatesManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void fillGatesById()
|
protected void fillGatesById() {
|
||||||
{
|
gatesById = new HashMap<String, Gate>((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);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void fillGatesByChunk()
|
protected void fillGatesByChunk() {
|
||||||
{
|
HashSet<SimpleChunk> chunksUsedByGates = new HashSet<SimpleChunk>();
|
||||||
HashSet<SimpleChunk> chunksUsedByGates = new HashSet<SimpleChunk>();
|
|
||||||
|
for (Gate g : gates) {
|
||||||
for (Gate g : gates) {
|
|
||||||
|
|
||||||
if (g.getLocation() != null) {
|
if (g.getLocation() != null) {
|
||||||
|
|
||||||
@ -268,59 +252,57 @@ public class GatesManager
|
|||||||
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<SimpleChunk, Set<Gate>>((int) (chunksUsedByGates.size() * 1.25));
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
this.addGateByChunk(g);
|
this.addGateByChunk(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void fillGatesByLocation()
|
protected void fillGatesByLocation() {
|
||||||
{
|
Set<Location> gateBlocks = new HashSet<Location>();
|
||||||
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 = new Location(l.getWorld(),
|
Location headLocation = new Location(l.getWorld(),
|
||||||
l.getX(),
|
l.getX(),
|
||||||
l.getY()+1,
|
l.getY() + 1,
|
||||||
l.getZ());
|
l.getZ());
|
||||||
|
|
||||||
gateBlocks.add(headLocation);
|
gateBlocks.add(headLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gatesByLocation = new HashMap<SimpleLocation, Gate>((int)(gateBlocks.size()*1.25));
|
gatesByLocation = new HashMap<SimpleLocation, Gate>((int) (gateBlocks.size() * 1.25));
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
this.addGateByLocations(g);
|
this.addGateByLocations(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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.gateFrameBlocks.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
gatesByFrameLocation = new HashMap<SimpleLocation, Gate>((int)(numFrameBlocks*1.25));
|
gatesByFrameLocation = new HashMap<SimpleLocation, Gate>((int) (numFrameBlocks * 1.25));
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
this.addGateByFrameLocations(g);
|
this.addGateByFrameLocations(g);
|
||||||
@ -328,21 +310,18 @@ public class GatesManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void removeGateById(final String id)
|
protected void removeGateById(final String id) {
|
||||||
{
|
gatesById.remove(id);
|
||||||
gatesById.remove(id);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void addGateWithId(final Gate g)
|
protected void addGateWithId(final Gate g) {
|
||||||
{
|
gatesById.put(g.getId(), g);
|
||||||
gatesById.put(g.getId(), g);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected 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) {
|
||||||
|
|
||||||
@ -353,11 +332,10 @@ public class GatesManager
|
|||||||
gatesByLocation.remove(headLocation);
|
gatesByLocation.remove(headLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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) {
|
||||||
@ -368,21 +346,19 @@ public class GatesManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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);
|
||||||
gatesByLocation.put(sl, g);
|
gatesByLocation.put(sl, g);
|
||||||
|
|
||||||
SimpleLocation headLocation = new SimpleLocation(l, true);
|
SimpleLocation headLocation = new SimpleLocation(l, true);
|
||||||
gatesByLocation.put(headLocation, g);
|
gatesByLocation.put(headLocation, g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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);
|
||||||
@ -390,20 +366,19 @@ public class GatesManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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();
|
||||||
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++) {
|
||||||
|
|
||||||
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
|
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
|
||||||
Set<Gate> gatesInChunk = gatesByChunk.get(sc);
|
Set<Gate> gatesInChunk = gatesByChunk.get(sc);
|
||||||
|
|
||||||
if (gatesInChunk != null) {
|
if (gatesInChunk != null) {
|
||||||
gatesInChunk.remove(g);
|
gatesInChunk.remove(g);
|
||||||
@ -412,22 +387,21 @@ public class GatesManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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) {
|
||||||
|
|
||||||
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++) {
|
||||||
|
|
||||||
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
|
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
|
||||||
|
|
||||||
@ -442,67 +416,63 @@ public class GatesManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void storeInvalidGate(Map<String, Object> map)
|
|
||||||
{
|
|
||||||
File invalidGatesFile = new File(Plugin.getPlugin().getDataFolder(), "invalid_gates.yml");
|
|
||||||
Boolean invalidGatesFileExists = invalidGatesFile.exists();
|
|
||||||
|
|
||||||
try {
|
|
||||||
FileWriter fileWriter = new FileWriter(invalidGatesFile, true);
|
|
||||||
|
|
||||||
if (!invalidGatesFileExists) {
|
|
||||||
fileWriter.write("gates:\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fileWriter.write("- ==: ");
|
|
||||||
fileWriter.write(map.get("==").toString() + "\n");
|
|
||||||
map.remove("==");
|
|
||||||
|
|
||||||
fileWriter.write("\topen: false\n");
|
|
||||||
map.remove("open");
|
|
||||||
|
|
||||||
fileWriter.write("\tgateBlocks: []\n");
|
|
||||||
map.remove("gateBlocks");
|
|
||||||
|
|
||||||
|
|
||||||
for (String key : map.keySet()) {
|
|
||||||
Object value = map.get(key);
|
|
||||||
|
|
||||||
fileWriter.write("\t" + key + ": ");
|
|
||||||
|
|
||||||
if (value instanceof Map) {
|
|
||||||
fileWriter.write("\n");
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> valueMap = (Map<String, Object>)value;
|
|
||||||
|
|
||||||
for (String k : valueMap.keySet()) {
|
|
||||||
Object v = valueMap.get(k);
|
|
||||||
|
|
||||||
fileWriter.write("\t\t" + k + ": " + v.toString() + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
public void storeInvalidGate(Map<String, Object> map) {
|
||||||
fileWriter.write(value.toString() + "\n");
|
File invalidGatesFile = new File(Plugin.getPlugin().getDataFolder(), "invalid_gates.yml");
|
||||||
}
|
Boolean invalidGatesFileExists = invalidGatesFile.exists();
|
||||||
}
|
|
||||||
|
try {
|
||||||
fileWriter.close();
|
FileWriter fileWriter = new FileWriter(invalidGatesFile, true);
|
||||||
}
|
|
||||||
catch (IOException e) {
|
if (!invalidGatesFileExists) {
|
||||||
Plugin.log("ERROR: Could not save invalid gates to disk. Reason: \n" + Arrays.toString(e.getStackTrace()));
|
fileWriter.write("gates:\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fileWriter.write("- ==: ");
|
||||||
|
fileWriter.write(map.get("==").toString() + "\n");
|
||||||
public void handleGateIdChange(final Gate g, final String oldId)
|
map.remove("==");
|
||||||
{
|
|
||||||
this.removeGateById(oldId);
|
fileWriter.write("\topen: false\n");
|
||||||
this.addGateWithId(g);
|
map.remove("open");
|
||||||
|
|
||||||
|
fileWriter.write("\tgateBlocks: []\n");
|
||||||
|
map.remove("gateBlocks");
|
||||||
|
|
||||||
|
|
||||||
|
for (String key : map.keySet()) {
|
||||||
|
Object value = map.get(key);
|
||||||
|
|
||||||
|
fileWriter.write("\t" + key + ": ");
|
||||||
|
|
||||||
|
if (value instanceof Map) {
|
||||||
|
fileWriter.write("\n");
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> valueMap = (Map<String, Object>) value;
|
||||||
|
|
||||||
|
for (String k : valueMap.keySet()) {
|
||||||
|
Object v = valueMap.get(k);
|
||||||
|
|
||||||
|
fileWriter.write("\t\t" + k + ": " + v.toString() + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fileWriter.write(value.toString() + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileWriter.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Plugin.log("ERROR: Could not save invalid gates to disk. Reason: \n" + Arrays.toString(e.getStackTrace()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void handleGateIdChange(final Gate g, final String oldId) {
|
||||||
|
this.removeGateById(oldId);
|
||||||
|
this.addGateWithId(g);
|
||||||
|
|
||||||
Map<String, Object> changeSet = new HashMap<String, Object>();
|
Map<String, Object> changeSet = new HashMap<String, Object>();
|
||||||
changeSet.put(GateChangeListener.changedID, oldId);
|
changeSet.put(GateChangeListener.changedID, oldId);
|
||||||
@ -510,19 +480,18 @@ public class GatesManager
|
|||||||
for (GateChangeListener l : this.changeListeners) {
|
for (GateChangeListener l : this.changeListeners) {
|
||||||
l.gateChangedHandler(g, changeSet);
|
l.gateChangedHandler(g, changeSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void handleGateLocationChange(final Gate g,
|
public void handleGateLocationChange(final Gate g,
|
||||||
final Location oldLocation,
|
final Location oldLocation,
|
||||||
final Set<Location> oldGateBlockLocations,
|
final Set<Location> oldGateBlockLocations,
|
||||||
final Set<Block> oldGateFrameBlocks)
|
final Set<Block> oldGateFrameBlocks) {
|
||||||
{
|
this.removeGateFromChunk(g, oldLocation);
|
||||||
this.removeGateFromChunk(g, oldLocation);
|
this.addGateByChunk(g);
|
||||||
this.addGateByChunk(g);
|
|
||||||
|
this.removeGateByLocation(oldGateBlockLocations);
|
||||||
this.removeGateByLocation(oldGateBlockLocations);
|
this.addGateByLocations(g);
|
||||||
this.addGateByLocations(g);
|
|
||||||
|
|
||||||
this.removeGateByFrameLocation(oldGateFrameBlocks);
|
this.removeGateByFrameLocation(oldGateFrameBlocks);
|
||||||
this.addGateByFrameLocations(g);
|
this.addGateByFrameLocations(g);
|
||||||
@ -533,11 +502,10 @@ public class GatesManager
|
|||||||
for (GateChangeListener l : this.changeListeners) {
|
for (GateChangeListener l : this.changeListeners) {
|
||||||
l.gateChangedHandler(g, changeSet);
|
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>();
|
Map<String, Object> changeSet = new HashMap<String, Object>();
|
||||||
@ -547,15 +515,14 @@ public class GatesManager
|
|||||||
l.gateChangedHandler(g, changeSet);
|
l.gateChangedHandler(g, changeSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void handleNewGate(final Gate g)
|
public void handleNewGate(final Gate g) {
|
||||||
{
|
this.gates.add(g);
|
||||||
this.gates.add(g);
|
|
||||||
|
|
||||||
this.addGateByChunk(g);
|
this.addGateByChunk(g);
|
||||||
this.addGateByLocations(g);
|
this.addGateByLocations(g);
|
||||||
this.addGateWithId(g);
|
this.addGateWithId(g);
|
||||||
this.addGateByFrameLocations(g);
|
this.addGateByFrameLocations(g);
|
||||||
|
|
||||||
|
|
||||||
@ -565,16 +532,15 @@ public class GatesManager
|
|||||||
for (GateChangeListener l : this.changeListeners) {
|
for (GateChangeListener l : this.changeListeners) {
|
||||||
l.gateChangedHandler(g, changeSet);
|
l.gateChangedHandler(g, changeSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void handleDeletion(final Gate g)
|
public void handleDeletion(final Gate g) {
|
||||||
{
|
|
||||||
this.gates.remove(g);
|
this.gates.remove(g);
|
||||||
|
|
||||||
this.removeGateById(g.getId());
|
this.removeGateById(g.getId());
|
||||||
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>();
|
Map<String, Object> changeSet = new HashMap<String, Object>();
|
||||||
@ -583,17 +549,15 @@ public class GatesManager
|
|||||||
for (GateChangeListener l : this.changeListeners) {
|
for (GateChangeListener l : this.changeListeners) {
|
||||||
l.gateChangedHandler(g, changeSet);
|
l.gateChangedHandler(g, changeSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean gateExists(final String id)
|
public boolean gateExists(final String id) {
|
||||||
{
|
return gatesById.containsKey(id.toLowerCase());
|
||||||
return gatesById.containsKey(id.toLowerCase());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
public List<Gate> allGates() {
|
||||||
public List<Gate> allGates ()
|
return gates;
|
||||||
{
|
}
|
||||||
return gates;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -38,16 +38,15 @@ import de.craftinc.gates.commands.*;
|
|||||||
import org.mcstats.Metrics;
|
import org.mcstats.Metrics;
|
||||||
|
|
||||||
|
|
||||||
public class Plugin extends JavaPlugin
|
public class Plugin extends JavaPlugin {
|
||||||
{
|
public static final String permissionInfo = "craftincgates.info";
|
||||||
public static final String permissionInfo = "craftincgates.info";
|
public static final String permissionManage = "craftincgates.manage";
|
||||||
public static final String permissionManage = "craftincgates.manage";
|
public static final String permissionUse = "craftincgates.use";
|
||||||
public static final String permissionUse = "craftincgates.use";
|
|
||||||
|
private static Plugin instance;
|
||||||
private static Plugin instance;
|
private static Permission permission;
|
||||||
private static Permission permission;
|
|
||||||
|
protected String baseCommand;
|
||||||
protected String baseCommand;
|
|
||||||
protected List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
protected List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
||||||
protected GatesManager gatesManager = new GatesManager();
|
protected GatesManager gatesManager = new GatesManager();
|
||||||
|
|
||||||
@ -57,118 +56,105 @@ public class Plugin extends JavaPlugin
|
|||||||
protected PlayerChangedWorldListener worldChangeListener = new PlayerChangedWorldListener();
|
protected PlayerChangedWorldListener worldChangeListener = new PlayerChangedWorldListener();
|
||||||
protected PlayerJoinListener joinListener = new PlayerJoinListener();
|
protected PlayerJoinListener joinListener = new PlayerJoinListener();
|
||||||
protected BlockBreakListener blockBreakListener = new BlockBreakListener();
|
protected BlockBreakListener blockBreakListener = new BlockBreakListener();
|
||||||
|
|
||||||
|
|
||||||
public Plugin()
|
|
||||||
{
|
|
||||||
instance = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Plugin getPlugin()
|
|
||||||
{
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public GatesManager getGatesManager()
|
|
||||||
{
|
|
||||||
return gatesManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
public Plugin() {
|
||||||
public void onLoad()
|
instance = this;
|
||||||
{
|
}
|
||||||
ConfigurationSerialization.registerClass(Gate.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void setupPermissions()
|
public static Plugin getPlugin() {
|
||||||
{
|
return instance;
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public GatesManager getGatesManager() {
|
||||||
|
return gatesManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
ConfigurationSerialization.registerClass(Gate.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void setupPermissions() {
|
||||||
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
|
|
||||||
if (rsp != null)
|
|
||||||
{
|
|
||||||
log("Using permission provider provided by Vault.");
|
|
||||||
permission = rsp.getProvider();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log("Not using setup permission provider provided by Vault.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
if (rsp != null) {
|
||||||
public void onDisable()
|
log("Using permission provider provided by Vault.");
|
||||||
{
|
permission = rsp.getProvider();
|
||||||
// Save gates
|
} else {
|
||||||
gatesManager.saveGatesToDisk();
|
log("Not using setup permission provider provided by Vault.");
|
||||||
|
}
|
||||||
log("Disabled");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onDisable() {
|
||||||
{
|
// Save gates
|
||||||
// Setup Metrics
|
gatesManager.saveGatesToDisk();
|
||||||
|
|
||||||
|
log("Disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
// Setup Metrics
|
||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics(this);
|
||||||
metrics.start();
|
metrics.start();
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
log("Failed to start metrics!");
|
log("Failed to start metrics!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup configuration
|
// Setup configuration
|
||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
|
|
||||||
// Setup permissions
|
// Setup permissions
|
||||||
setupPermissions();
|
setupPermissions();
|
||||||
|
|
||||||
// Add the commands
|
// Add the commands
|
||||||
commands.add(new CommandHelp());
|
commands.add(new CommandHelp());
|
||||||
commands.add(new CommandNew());
|
commands.add(new CommandNew());
|
||||||
commands.add(new CommandRemove());
|
commands.add(new CommandRemove());
|
||||||
commands.add(new CommandLocation());
|
commands.add(new CommandLocation());
|
||||||
commands.add(new CommandExit());
|
commands.add(new CommandExit());
|
||||||
commands.add(new CommandOpen());
|
commands.add(new CommandOpen());
|
||||||
commands.add(new CommandRename());
|
commands.add(new CommandRename());
|
||||||
commands.add(new CommandClose());
|
commands.add(new CommandClose());
|
||||||
commands.add(new CommandList());
|
commands.add(new CommandList());
|
||||||
commands.add(new CommandInfo());
|
commands.add(new CommandInfo());
|
||||||
commands.add(new CommandHide());
|
commands.add(new CommandHide());
|
||||||
commands.add(new CommandUnhide());
|
commands.add(new CommandUnhide());
|
||||||
commands.add(new CommandExitOpen());
|
commands.add(new CommandExitOpen());
|
||||||
commands.add(new CommandNearby());
|
commands.add(new CommandNearby());
|
||||||
commands.add(new CommandAllowRiding());
|
commands.add(new CommandAllowRiding());
|
||||||
commands.add(new CommandDenyRiding());
|
commands.add(new CommandDenyRiding());
|
||||||
|
|
||||||
|
|
||||||
// Register events
|
// Register events
|
||||||
this.registerEventListeners();
|
this.registerEventListeners();
|
||||||
|
|
||||||
// Load gates
|
// Load gates
|
||||||
boolean success = gatesManager.loadGatesFromDisk();
|
boolean success = gatesManager.loadGatesFromDisk();
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
log("Enabled");
|
log("Enabled");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
pm.disablePlugin(this);
|
pm.disablePlugin(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void registerEventListeners()
|
protected void registerEventListeners() {
|
||||||
{
|
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
|
|
||||||
pm.registerEvents(this.moveListener, this);
|
pm.registerEvents(this.moveListener, this);
|
||||||
@ -182,74 +168,66 @@ public class Plugin extends JavaPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// Commands
|
// Commands
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public String getBaseCommand()
|
public String getBaseCommand() {
|
||||||
{
|
if (this.baseCommand != null)
|
||||||
if (this.baseCommand != null)
|
return this.baseCommand;
|
||||||
return this.baseCommand;
|
|
||||||
|
Map<String, Map<String, Object>> Commands = this.getDescription().getCommands();
|
||||||
Map<String, Map<String, Object>> Commands = this.getDescription().getCommands();
|
|
||||||
|
this.baseCommand = Commands.keySet().iterator().next();
|
||||||
this.baseCommand = Commands.keySet().iterator().next();
|
|
||||||
|
return this.baseCommand;
|
||||||
return this.baseCommand;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
|
||||||
{
|
|
||||||
List<String> parameters = new ArrayList<String>(Arrays.asList(args));
|
|
||||||
this.handleCommand(sender, parameters);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void handleCommand(CommandSender sender, List<String> parameters)
|
|
||||||
{
|
|
||||||
if (parameters.size() == 0)
|
|
||||||
{
|
|
||||||
this.commands.get(0).execute(sender, parameters);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String commandName = parameters.get(0).toLowerCase();
|
|
||||||
parameters.remove(0);
|
|
||||||
|
|
||||||
for (BaseCommand fcommand : this.commands)
|
|
||||||
{
|
|
||||||
if (fcommand.getAliases().contains(commandName))
|
|
||||||
{
|
|
||||||
fcommand.execute(sender, parameters);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.RED + "Unknown gate-command \"" + commandName + "\"." +
|
|
||||||
ChatColor.GREEN + " Try " + "/" + getBaseCommand() + " help");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Logging
|
|
||||||
*/
|
|
||||||
public static void log(String msg)
|
|
||||||
{
|
|
||||||
log(Level.INFO, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void log(Level level, String msg)
|
|
||||||
{
|
|
||||||
Logger.getLogger("Minecraft").log(level, "["+instance.getDescription().getFullName()+"] "+msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Permission getPermission() {
|
@Override
|
||||||
return permission;
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||||
}
|
List<String> parameters = new ArrayList<String>(Arrays.asList(args));
|
||||||
|
this.handleCommand(sender, parameters);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void handleCommand(CommandSender sender, List<String> parameters) {
|
||||||
|
if (parameters.size() == 0) {
|
||||||
|
this.commands.get(0).execute(sender, parameters);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String commandName = parameters.get(0).toLowerCase();
|
||||||
|
parameters.remove(0);
|
||||||
|
|
||||||
|
for (BaseCommand fcommand : this.commands) {
|
||||||
|
if (fcommand.getAliases().contains(commandName)) {
|
||||||
|
fcommand.execute(sender, parameters);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.RED + "Unknown gate-command \"" + commandName + "\"." +
|
||||||
|
ChatColor.GREEN + " Try " + "/" + getBaseCommand() + " help");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logging
|
||||||
|
*/
|
||||||
|
public static void log(String msg) {
|
||||||
|
log(Level.INFO, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void log(Level level, String msg) {
|
||||||
|
Logger.getLogger("Minecraft").log(level, "[" + instance.getDescription().getFullName() + "] " + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Permission getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||||||
import de.craftinc.gates.util.ConfigurationUtil;
|
import de.craftinc.gates.util.ConfigurationUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
import de.craftinc.gates.Gate;
|
||||||
@ -29,224 +30,213 @@ import de.craftinc.gates.GatesManager;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
import de.craftinc.gates.util.TextUtil;
|
import de.craftinc.gates.util.TextUtil;
|
||||||
|
|
||||||
public abstract class BaseCommand
|
public abstract class BaseCommand {
|
||||||
{
|
|
||||||
protected List<String> aliases = new ArrayList<String>();
|
|
||||||
protected List<String> requiredParameters = new ArrayList<String>();
|
|
||||||
protected List<String> optionalParameters = new ArrayList<String>();
|
|
||||||
|
|
||||||
protected String helpDescription = "no description";
|
|
||||||
|
|
||||||
protected List<String> parameters;
|
|
||||||
protected CommandSender sender;
|
|
||||||
protected Player player;
|
|
||||||
protected Gate gate;
|
|
||||||
|
|
||||||
protected boolean senderMustBePlayer = true;
|
|
||||||
protected boolean hasGateParam = true;
|
|
||||||
|
|
||||||
protected String requiredPermission;
|
|
||||||
protected boolean needsPermissionAtCurrentLocation;
|
|
||||||
|
|
||||||
protected boolean shouldPersistToDisk;
|
|
||||||
|
|
||||||
|
protected List<String> aliases = new ArrayList<String>();
|
||||||
public List<String> getAliases() {
|
protected List<String> requiredParameters = new ArrayList<String>();
|
||||||
return aliases;
|
protected List<String> optionalParameters = new ArrayList<String>();
|
||||||
}
|
|
||||||
|
protected String helpDescription = "no description";
|
||||||
|
|
||||||
public void execute(CommandSender sender, List<String> parameters) {
|
protected List<String> parameters;
|
||||||
this.sender = sender;
|
protected CommandSender sender;
|
||||||
this.parameters = parameters;
|
protected Player player;
|
||||||
|
protected Gate gate;
|
||||||
if (!this.validateCall()) {
|
|
||||||
return;
|
protected boolean senderMustBePlayer = true;
|
||||||
}
|
protected boolean hasGateParam = true;
|
||||||
|
|
||||||
if (this.senderMustBePlayer) {
|
protected String requiredPermission;
|
||||||
this.player = (Player)sender;
|
protected boolean needsPermissionAtCurrentLocation;
|
||||||
}
|
|
||||||
|
protected boolean shouldPersistToDisk;
|
||||||
this.perform();
|
|
||||||
|
|
||||||
if (this.shouldPersistToDisk && Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confSaveOnChangesKey)) {
|
public List<String> getAliases() {
|
||||||
Plugin.getPlugin().getGatesManager().saveGatesToDisk();
|
return aliases;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, List<String> parameters) {
|
||||||
abstract protected void perform();
|
this.sender = sender;
|
||||||
|
this.parameters = parameters;
|
||||||
|
|
||||||
protected void sendMessage(String message) {
|
if (!this.validateCall()) {
|
||||||
sender.sendMessage(message);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.senderMustBePlayer) {
|
||||||
protected void sendMessage(List<String> messages) {
|
this.player = (Player) sender;
|
||||||
for(String message : messages) {
|
}
|
||||||
this.sendMessage(message);
|
|
||||||
}
|
this.perform();
|
||||||
}
|
|
||||||
|
if (this.shouldPersistToDisk && getSaveOnChanges()) {
|
||||||
|
Plugin.getPlugin().getGatesManager().saveGatesToDisk();
|
||||||
protected boolean validateCall()
|
}
|
||||||
{
|
}
|
||||||
boolean allParametersThere = parameters.size() >= requiredParameters.size();
|
|
||||||
boolean senderIsPlayer = this.sender instanceof Player;
|
private boolean getSaveOnChanges() {
|
||||||
boolean hasGateParameter = false;
|
FileConfiguration config = Plugin.getPlugin().getConfig();
|
||||||
|
return config.getBoolean(ConfigurationUtil.confSaveOnChangesKey);
|
||||||
if (this.hasGateParam && this.parameters.size() > 0 && this.setGateUsingParameter(this.parameters.get(0))) {
|
}
|
||||||
hasGateParameter = true;
|
|
||||||
}
|
|
||||||
|
abstract protected void perform();
|
||||||
boolean senderHasPermission = this.hasPermission();
|
|
||||||
boolean valid;
|
|
||||||
|
protected void sendMessage(String message) {
|
||||||
if (this.senderMustBePlayer && !senderIsPlayer) {
|
sender.sendMessage(message);
|
||||||
sendMessage(ChatColor.RED + "This command can only be used by ingame players.");
|
}
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
else {
|
protected void sendMessage(List<String> messages) {
|
||||||
|
for (String message : messages) {
|
||||||
|
this.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean validateCall() {
|
||||||
|
boolean allParametersThere = parameters.size() >= requiredParameters.size();
|
||||||
|
boolean senderIsPlayer = this.sender instanceof Player;
|
||||||
|
boolean hasGateParameter = false;
|
||||||
|
|
||||||
|
if (this.hasGateParam && this.parameters.size() > 0 && this.setGateUsingParameter(this.parameters.get(0))) {
|
||||||
|
hasGateParameter = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean senderHasPermission = this.hasPermission();
|
||||||
|
boolean valid;
|
||||||
|
|
||||||
|
if (this.senderMustBePlayer && !senderIsPlayer) {
|
||||||
|
sendMessage(ChatColor.RED + "This command can only be used by ingame players.");
|
||||||
|
valid = false;
|
||||||
|
} 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(true));
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected boolean setGateUsingParameter(String param)
|
|
||||||
{
|
|
||||||
GatesManager gateManager = Plugin.getPlugin().getGatesManager();
|
|
||||||
|
|
||||||
if (!gateManager.gateExists(param)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gate = gateManager.getGateWithId(param);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will return false if a gate is required for this command but this.gate == null.
|
|
||||||
*/
|
|
||||||
protected boolean hasPermission()
|
|
||||||
{
|
|
||||||
if (Plugin.getPermission() == null) { // fallback - use the standard bukkit permission system
|
|
||||||
return this.sender.hasPermission(this.requiredPermission);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(this.sender instanceof Player)) {
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean setGateUsingParameter(String param) {
|
||||||
|
GatesManager gateManager = Plugin.getPlugin().getGatesManager();
|
||||||
|
|
||||||
|
if (!gateManager.gateExists(param)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
gate = gateManager.getGateWithId(param);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will return false if a gate is required for this command but this.gate == null.
|
||||||
|
*/
|
||||||
|
protected boolean hasPermission() {
|
||||||
|
if (Plugin.getPermission() == null) { // fallback - use the standard bukkit permission system
|
||||||
|
return this.sender.hasPermission(this.requiredPermission);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(this.sender instanceof Player)) {
|
||||||
// sender is no player - there is no information about the senders locations
|
// sender is no player - there is no information about the senders locations
|
||||||
return Plugin.getPermission().has(this.sender, this.requiredPermission);
|
return Plugin.getPermission().has(this.sender, this.requiredPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Player p = (Player) this.sender;
|
|
||||||
boolean hasPermission = false;
|
|
||||||
|
|
||||||
if (this.requiredPermission.equals(Plugin.permissionInfo)) {
|
|
||||||
|
|
||||||
if (this.hasGateParam) {
|
Player p = (Player) this.sender;
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
boolean hasPermission = false;
|
||||||
}
|
|
||||||
else {
|
|
||||||
hasPermission = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.requiredPermission.equals(Plugin.permissionUse) ) {
|
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
|
||||||
}
|
|
||||||
else if (this.requiredPermission.equals(Plugin.permissionManage)) {
|
|
||||||
|
|
||||||
if (this.needsPermissionAtCurrentLocation && this.hasGateParam) {
|
if (this.requiredPermission.equals(Plugin.permissionInfo)) {
|
||||||
boolean hasPersmissionAtCurrentLocation = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
hasPermission = hasPersmissionAtCurrentLocation && this.hasPermissionAtGateLocationAndExit(p);
|
|
||||||
}
|
|
||||||
else if (this.needsPermissionAtCurrentLocation) {
|
|
||||||
hasPermission = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasPermission;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected boolean hasPermissionAtGateLocationAndExit(Player p)
|
|
||||||
{
|
|
||||||
if (this.gate == null || p == null) { // make sure we don't run into a nullpointer exception
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean permAtLocation = this.gate.getLocation() == null || Plugin.getPermission().has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
boolean permAtExit = this.gate.getExit() == null || Plugin.getPermission().has(this.gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
|
|
||||||
return permAtLocation & permAtExit;
|
if (this.hasGateParam) {
|
||||||
}
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
|
} else {
|
||||||
|
hasPermission = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
||||||
// -------------------------------------------- //
|
}
|
||||||
// Help and usage description
|
} else if (this.requiredPermission.equals(Plugin.permissionUse)) {
|
||||||
// -------------------------------------------- //
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
protected String getUsageTemplate(boolean withColor, boolean withDescription)
|
} else if (this.requiredPermission.equals(Plugin.permissionManage)) {
|
||||||
{
|
|
||||||
String ret = "";
|
if (this.needsPermissionAtCurrentLocation && this.hasGateParam) {
|
||||||
|
boolean hasPersmissionAtCurrentLocation = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
||||||
if (withColor) {
|
hasPermission = hasPersmissionAtCurrentLocation && this.hasPermissionAtGateLocationAndExit(p);
|
||||||
ret += ChatColor.AQUA;
|
} else if (this.needsPermissionAtCurrentLocation) {
|
||||||
}
|
hasPermission = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
||||||
|
} else {
|
||||||
ret += "/" + Plugin.getPlugin().getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",")+" ";
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
|
}
|
||||||
List<String> parts = new ArrayList<String>();
|
}
|
||||||
|
|
||||||
for (String requiredParameter : this.requiredParameters) {
|
return hasPermission;
|
||||||
parts.add("["+requiredParameter+"]");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (String optionalParameter : this.optionalParameters) {
|
protected boolean hasPermissionAtGateLocationAndExit(Player p) {
|
||||||
parts.add("*["+optionalParameter+"]");
|
if (this.gate == null || p == null) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
if (withColor) {
|
|
||||||
ret += ChatColor.DARK_AQUA;
|
boolean permAtLocation = this.gate.getLocation() == null || Plugin.getPermission().has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
||||||
}
|
boolean permAtExit = this.gate.getExit() == null || Plugin.getPermission().has(this.gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
||||||
|
|
||||||
ret += TextUtil.implode(parts, " ");
|
return permAtLocation & permAtExit;
|
||||||
|
}
|
||||||
if (withDescription) {
|
|
||||||
ret += " ";
|
|
||||||
|
// -------------------------------------------- //
|
||||||
if (withColor) {
|
// Help and usage description
|
||||||
ret += ChatColor.YELLOW;
|
// -------------------------------------------- //
|
||||||
}
|
protected String getUsageTemplate(boolean withColor, boolean withDescription) {
|
||||||
|
String ret = "";
|
||||||
ret += this.helpDescription;
|
|
||||||
}
|
if (withColor) {
|
||||||
return ret;
|
ret += ChatColor.AQUA;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getUsageTemplate(boolean withColor)
|
ret += "/" + Plugin.getPlugin().getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",") + " ";
|
||||||
{
|
|
||||||
return getUsageTemplate(withColor, false);
|
List<String> parts = new ArrayList<String>();
|
||||||
}
|
|
||||||
|
for (String requiredParameter : this.requiredParameters) {
|
||||||
|
parts.add("[" + requiredParameter + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String optionalParameter : this.optionalParameters) {
|
||||||
|
parts.add("*[" + optionalParameter + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (withColor) {
|
||||||
|
ret += ChatColor.DARK_AQUA;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret += TextUtil.implode(parts, " ");
|
||||||
|
|
||||||
|
if (withDescription) {
|
||||||
|
ret += " ";
|
||||||
|
|
||||||
|
if (withColor) {
|
||||||
|
ret += ChatColor.YELLOW;
|
||||||
|
}
|
||||||
|
ret += this.helpDescription;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getUsageTemplate(boolean withColor) {
|
||||||
|
return getUsageTemplate(withColor, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,27 +21,25 @@ 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
|
public abstract class BaseLocationCommand extends BaseCommand {
|
||||||
{
|
|
||||||
protected Location getValidPlayerLocation()
|
protected 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();
|
||||||
Block playerBlock = player.getLocation().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 player.getLocation();
|
} else if (upBlock.getType() == Material.AIR) {
|
||||||
}
|
return new Location(player.getLocation().getWorld(),
|
||||||
else if (upBlock.getType() == Material.AIR) {
|
player.getLocation().getX(),
|
||||||
return new Location(player.getLocation().getWorld(),
|
player.getLocation().getY() + 1,
|
||||||
player.getLocation().getX(),
|
player.getLocation().getZ(),
|
||||||
player.getLocation().getY() + 1,
|
player.getLocation().getYaw(),
|
||||||
player.getLocation().getZ(),
|
player.getLocation().getPitch());
|
||||||
player.getLocation().getYaw(),
|
}
|
||||||
player.getLocation().getPitch());
|
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,19 +20,16 @@ package de.craftinc.gates.commands;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
public class CommandAllowRiding extends BaseCommand
|
public class CommandAllowRiding extends BaseCommand {
|
||||||
{
|
|
||||||
public CommandAllowRiding()
|
public CommandAllowRiding() {
|
||||||
{
|
|
||||||
aliases.add("allowRiding");
|
aliases.add("allowRiding");
|
||||||
aliases.add("ar");
|
aliases.add("ar");
|
||||||
|
|
||||||
requiredParameters.add("id");
|
requiredParameters.add("id");
|
||||||
|
|
||||||
helpDescription = "Allow players to travel while riding.";
|
helpDescription = "Allow players to travel while riding.";
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
needsPermissionAtCurrentLocation = false;
|
||||||
shouldPersistToDisk = true;
|
shouldPersistToDisk = true;
|
||||||
|
|
||||||
@ -40,8 +37,7 @@ public class CommandAllowRiding extends BaseCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void perform()
|
protected void perform() {
|
||||||
{
|
|
||||||
gate.setAllowsVehicles(true);
|
gate.setAllowsVehicles(true);
|
||||||
sendMessage(ChatColor.GREEN + "Traveling while riding is now enabled for this gate.");
|
sendMessage(ChatColor.GREEN + "Traveling while riding is now enabled for this gate.");
|
||||||
}
|
}
|
||||||
|
@ -24,41 +24,30 @@ import org.bukkit.ChatColor;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class CommandClose extends BaseCommand
|
public class CommandClose extends BaseCommand {
|
||||||
{
|
|
||||||
public CommandClose()
|
|
||||||
{
|
|
||||||
aliases.add("close");
|
|
||||||
aliases.add("c");
|
|
||||||
|
|
||||||
requiredParameters.add("id");
|
|
||||||
|
|
||||||
helpDescription = "Closes a gate to prevent players from using it.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gate.setOpen(false);
|
|
||||||
GateBlockChangeSender.updateGateBlocks(gate);
|
|
||||||
sendMessage(ChatColor.GREEN + "The gate was closed.");
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "Opening the gate failed! See server log for more information");
|
|
||||||
Plugin.log(Level.WARNING, e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public CommandClose() {
|
||||||
|
aliases.add("close");
|
||||||
|
aliases.add("c");
|
||||||
|
|
||||||
|
requiredParameters.add("id");
|
||||||
|
helpDescription = "Closes a gate to prevent players from using it.";
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
needsPermissionAtCurrentLocation = false;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void perform() {
|
||||||
|
try {
|
||||||
|
gate.setOpen(false);
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
|
sendMessage(ChatColor.GREEN + "The gate was closed.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
sendMessage(ChatColor.RED + "Opening the gate failed! See server log for more information");
|
||||||
|
Plugin.log(Level.WARNING, e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -19,28 +19,22 @@ package de.craftinc.gates.commands;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
public class CommandDenyRiding extends BaseCommand
|
public class CommandDenyRiding extends BaseCommand {
|
||||||
{
|
|
||||||
public CommandDenyRiding()
|
public CommandDenyRiding() {
|
||||||
{
|
|
||||||
aliases.add("denyRiding");
|
aliases.add("denyRiding");
|
||||||
aliases.add("dr");
|
aliases.add("dr");
|
||||||
|
|
||||||
requiredParameters.add("id");
|
requiredParameters.add("id");
|
||||||
|
|
||||||
helpDescription = "Deny players to travel while riding.";
|
helpDescription = "Deny players to travel while riding.";
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
needsPermissionAtCurrentLocation = false;
|
||||||
shouldPersistToDisk = true;
|
shouldPersistToDisk = true;
|
||||||
|
|
||||||
senderMustBePlayer = false;
|
senderMustBePlayer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void perform()
|
protected void perform() {
|
||||||
{
|
|
||||||
gate.setAllowsVehicles(false);
|
gate.setAllowsVehicles(false);
|
||||||
sendMessage(ChatColor.GREEN + "Traveling while riding is now disabled for this gate.");
|
sendMessage(ChatColor.GREEN + "Traveling while riding is now disabled for this gate.");
|
||||||
}
|
}
|
||||||
|
@ -24,41 +24,35 @@ import org.bukkit.ChatColor;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class CommandExit extends BaseCommand {
|
||||||
|
|
||||||
public class CommandExit extends BaseCommand
|
public CommandExit() {
|
||||||
{
|
aliases.add("exit");
|
||||||
public CommandExit()
|
aliases.add("e");
|
||||||
{
|
|
||||||
aliases.add("exit");
|
requiredParameters.add("id");
|
||||||
aliases.add("e");
|
|
||||||
|
helpDescription = "Change exit of location.";
|
||||||
requiredParameters.add("id");
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
helpDescription = "Change exit of location.";
|
|
||||||
|
needsPermissionAtCurrentLocation = true;
|
||||||
requiredPermission = Plugin.permissionManage;
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = true;
|
||||||
needsPermissionAtCurrentLocation = true;
|
}
|
||||||
shouldPersistToDisk = true;
|
|
||||||
senderMustBePlayer = true;
|
|
||||||
}
|
public void perform() {
|
||||||
|
try {
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Location oldExit = gate.getExit();
|
Location oldExit = gate.getExit();
|
||||||
gate.setExit(player.getLocation());
|
gate.setExit(player.getLocation());
|
||||||
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
||||||
Plugin.getPlugin().getGatesManager().handleGateExitChange(gate, oldExit);
|
Plugin.getPlugin().getGatesManager().handleGateExitChange(gate, oldExit);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
GateBlockChangeSender.updateGateBlocks(gate);
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! See server log for more information");
|
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! See server log for more information");
|
||||||
Plugin.log(Level.WARNING, e.getMessage());
|
Plugin.log(Level.WARNING, e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,29 +24,23 @@ import org.bukkit.Location;
|
|||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class CommandExitOpen extends BaseCommand
|
public class CommandExitOpen extends BaseCommand {
|
||||||
{
|
|
||||||
public CommandExitOpen()
|
public CommandExitOpen() {
|
||||||
{
|
|
||||||
aliases.add("exitopen");
|
aliases.add("exitopen");
|
||||||
aliases.add("eo");
|
aliases.add("eo");
|
||||||
|
|
||||||
requiredParameters.add("id");
|
requiredParameters.add("id");
|
||||||
|
|
||||||
helpDescription = "Change exit of location and open that gate afterwards.";
|
helpDescription = "Change exit of location and open that gate afterwards.";
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = true;
|
needsPermissionAtCurrentLocation = true;
|
||||||
shouldPersistToDisk = true;
|
shouldPersistToDisk = true;
|
||||||
senderMustBePlayer = true;
|
senderMustBePlayer = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
public void perform() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
Location oldExit = gate.getExit();
|
Location oldExit = gate.getExit();
|
||||||
gate.setExit(player.getLocation());
|
gate.setExit(player.getLocation());
|
||||||
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
||||||
@ -68,12 +62,10 @@ public class CommandExitOpen extends BaseCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(ChatColor.GREEN + "The gate was opened.");
|
sendMessage(ChatColor.GREEN + "The gate was opened.");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
sendMessage(ChatColor.RED + e.getMessage());
|
sendMessage(ChatColor.RED + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
GateBlockChangeSender.updateGateBlocks(gate);
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! This gate is now closed! (See server log for more information.)");
|
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! This gate is now closed! (See server log for more information.)");
|
||||||
Plugin.log(Level.WARNING, e.getMessage());
|
Plugin.log(Level.WARNING, e.getMessage());
|
||||||
|
@ -23,89 +23,84 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandHelp extends BaseCommand
|
public class CommandHelp extends BaseCommand {
|
||||||
{
|
|
||||||
public static List<List<String>> helpPages;
|
public 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<String>();
|
|
||||||
|
allUsageStrings.add(new CommandHelp().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandHelp().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandNew().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandNew().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandRemove().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandRemove().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandLocation().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandLocation().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandExit().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandExit().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandOpen().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandOpen().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandRename().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandRename().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandClose().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandClose().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandList().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandList().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandInfo().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandInfo().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandHide().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandHide().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandUnhide().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandUnhide().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandExitOpen().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandExitOpen().getUsageTemplate(true, true) );
|
allUsageStrings.add(new CommandNearby().getUsageTemplate(true, true));
|
||||||
allUsageStrings.add( new CommandNearby().getUsageTemplate(true, true) );
|
|
||||||
|
Collections.sort(allUsageStrings);
|
||||||
Collections.sort(allUsageStrings);
|
|
||||||
|
|
||||||
|
|
||||||
// put 5 commands on one page
|
|
||||||
helpPages = new ArrayList<List<String>>();
|
|
||||||
|
|
||||||
while (!allUsageStrings.isEmpty()) {
|
|
||||||
int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size();
|
|
||||||
List<String> currentHelpPage = new ArrayList<String>(allUsageStrings.subList(0, toIndex));
|
|
||||||
helpPages.add(currentHelpPage);
|
|
||||||
|
|
||||||
allUsageStrings.removeAll(currentHelpPage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public CommandHelp()
|
|
||||||
{
|
|
||||||
aliases.add("help");
|
|
||||||
aliases.add("?");
|
|
||||||
|
|
||||||
optionalParameters.add("page");
|
|
||||||
helpDescription = "prints this help page";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionInfo;
|
|
||||||
|
|
||||||
hasGateParam = false;
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
|
||||||
shouldPersistToDisk = false;
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
// put 5 commands on one page
|
||||||
{
|
helpPages = new ArrayList<List<String>>();
|
||||||
int page;
|
|
||||||
|
while (!allUsageStrings.isEmpty()) {
|
||||||
if (parameters.size() > 0) {
|
int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size();
|
||||||
try {
|
List<String> currentHelpPage = new ArrayList<String>(allUsageStrings.subList(0, toIndex));
|
||||||
page = Integer.parseInt(parameters.get(0));
|
helpPages.add(currentHelpPage);
|
||||||
}
|
|
||||||
catch (NumberFormatException e) {
|
allUsageStrings.removeAll(currentHelpPage);
|
||||||
// wasn't an integer
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public CommandHelp() {
|
||||||
|
aliases.add("help");
|
||||||
|
aliases.add("?");
|
||||||
|
|
||||||
|
optionalParameters.add("page");
|
||||||
|
helpDescription = "prints this help page";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionInfo;
|
||||||
|
|
||||||
|
hasGateParam = false;
|
||||||
|
needsPermissionAtCurrentLocation = false;
|
||||||
|
shouldPersistToDisk = false;
|
||||||
|
senderMustBePlayer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void perform() {
|
||||||
|
int page;
|
||||||
|
|
||||||
|
if (parameters.size() > 0) {
|
||||||
|
try {
|
||||||
|
page = Integer.parseInt(parameters.get(0));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// wasn't an integer
|
||||||
page = 1;
|
page = 1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
page = 1;
|
page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(TextUtil.titleize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")"));
|
sendMessage(TextUtil.titleize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")"));
|
||||||
|
|
||||||
page -= 1;
|
page -= 1;
|
||||||
if (page < 0 || page >= helpPages.size()) {
|
if (page < 0 || page >= helpPages.size()) {
|
||||||
sendMessage("This page does not exist");
|
sendMessage("This page does not exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(helpPages.get(page));
|
sendMessage(helpPages.get(page));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,36 +24,33 @@ import org.bukkit.ChatColor;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class CommandHide extends BaseCommand
|
public class CommandHide extends BaseCommand {
|
||||||
{
|
|
||||||
public CommandHide()
|
public CommandHide() {
|
||||||
{
|
aliases.add("hide");
|
||||||
aliases.add("hide");
|
|
||||||
aliases.add("h");
|
aliases.add("h");
|
||||||
|
|
||||||
requiredParameters.add("id");
|
requiredParameters.add("id");
|
||||||
|
|
||||||
helpDescription = "Makes a gate NOT consist of gate blocks while open.";
|
helpDescription = "Makes a gate NOT consist of gate blocks while open.";
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
needsPermissionAtCurrentLocation = false;
|
||||||
shouldPersistToDisk = true;
|
shouldPersistToDisk = true;
|
||||||
senderMustBePlayer = false;
|
senderMustBePlayer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
public void perform() {
|
||||||
{
|
try {
|
||||||
try {
|
gate.setHidden(true);
|
||||||
gate.setHidden(true);
|
|
||||||
GateBlockChangeSender.updateGateBlocks(gate);
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
sendMessage(ChatColor.GREEN + "The gate '" + gate.getId() + "' is now hidden.");
|
sendMessage(ChatColor.GREEN + "The gate '" + gate.getId() + "' is now hidden.");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
sendMessage(ChatColor.RED + "Hiding the gate failed! See server log for more information");
|
||||||
sendMessage(ChatColor.RED + "Hiding the gate failed! See server log for more information");
|
Plugin.log(Level.WARNING, e.getMessage());
|
||||||
Plugin.log(Level.WARNING, e.getMessage());
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
|
||||||
import de.craftinc.gates.util.GateBlockChangeSender;
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
@ -24,30 +23,27 @@ import de.craftinc.gates.Plugin;
|
|||||||
import de.craftinc.gates.util.TextUtil;
|
import de.craftinc.gates.util.TextUtil;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class CommandInfo extends BaseCommand {
|
||||||
|
|
||||||
public class CommandInfo extends BaseCommand
|
public CommandInfo() {
|
||||||
{
|
aliases.add("info");
|
||||||
public CommandInfo()
|
aliases.add("i");
|
||||||
{
|
|
||||||
aliases.add("info");
|
|
||||||
aliases.add("i");
|
|
||||||
|
|
||||||
optionalParameters.add("id");
|
optionalParameters.add("id");
|
||||||
|
|
||||||
helpDescription = "Print detailed information about a certain or the closest gate.";
|
helpDescription = "Print detailed information about a certain or the closest gate.";
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionInfo;
|
requiredPermission = Plugin.permissionInfo;
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
needsPermissionAtCurrentLocation = false;
|
||||||
shouldPersistToDisk = false;
|
shouldPersistToDisk = false;
|
||||||
senderMustBePlayer = false;
|
senderMustBePlayer = false;
|
||||||
hasGateParam = false;
|
hasGateParam = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
public void perform() {
|
||||||
{
|
if (this.parameters.size() > 0) {
|
||||||
if (this.parameters.size() > 0) {
|
|
||||||
|
|
||||||
if (!this.setGateUsingParameter(this.parameters.get(0))) {
|
if (!this.setGateUsingParameter(this.parameters.get(0))) {
|
||||||
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());
|
||||||
@ -55,8 +51,7 @@ public class CommandInfo extends BaseCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(TextUtil.titleize("Information about: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
|
sendMessage(TextUtil.titleize("Information about: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
boolean senderIsPlayer = this.sender instanceof Player;
|
boolean senderIsPlayer = this.sender instanceof Player;
|
||||||
|
|
||||||
if (!senderIsPlayer) {
|
if (!senderIsPlayer) {
|
||||||
@ -64,7 +59,7 @@ public class CommandInfo extends BaseCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player p = (Player)this.sender;
|
Player p = (Player) this.sender;
|
||||||
this.gate = Plugin.getPlugin().getGatesManager().getNearestGate(p.getLocation());
|
this.gate = Plugin.getPlugin().getGatesManager().getNearestGate(p.getLocation());
|
||||||
|
|
||||||
if (!this.hasPermission() || this.gate == null) {
|
if (!this.hasPermission() || this.gate == null) {
|
||||||
@ -85,22 +80,22 @@ public class CommandInfo extends BaseCommand
|
|||||||
openHiddenMessage += ChatColor.AQUA + " closed";
|
openHiddenMessage += ChatColor.AQUA + " closed";
|
||||||
|
|
||||||
if (gate.isHidden())
|
if (gate.isHidden())
|
||||||
openHiddenMessage += ChatColor.DARK_AQUA +" and" + ChatColor.AQUA + " hidden";
|
openHiddenMessage += ChatColor.DARK_AQUA + " and" + ChatColor.AQUA + " hidden";
|
||||||
|
|
||||||
openHiddenMessage += ".\n";
|
openHiddenMessage += ".\n";
|
||||||
|
|
||||||
sendMessage(openHiddenMessage);
|
sendMessage(openHiddenMessage);
|
||||||
|
|
||||||
if (gate.getLocation() != null)
|
if (gate.getLocation() != null)
|
||||||
sendMessage(ChatColor.DARK_AQUA + "location: " + ChatColor.AQUA + "( " + (int)gate.getLocation().getX() +
|
sendMessage(ChatColor.DARK_AQUA + "location: " + ChatColor.AQUA + "( " + (int) gate.getLocation().getX() +
|
||||||
" | " + (int)gate.getLocation().getY() + " | " + (int)gate.getLocation().getZ() + " ) in " +
|
" | " + (int) gate.getLocation().getY() + " | " + (int) gate.getLocation().getZ() + " ) in " +
|
||||||
gate.getLocation().getWorld().getName());
|
gate.getLocation().getWorld().getName());
|
||||||
else
|
else
|
||||||
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no location");
|
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no location");
|
||||||
|
|
||||||
if (gate.getExit() != null)
|
if (gate.getExit() != null)
|
||||||
sendMessage(ChatColor.DARK_AQUA + "exit: " + ChatColor.AQUA + "( " + (int)gate.getExit().getX() + " | "
|
sendMessage(ChatColor.DARK_AQUA + "exit: " + ChatColor.AQUA + "( " + (int) gate.getExit().getX() + " | "
|
||||||
+ (int)gate.getExit().getY() + " | " + (int)gate.getExit().getZ() + " ) in " +
|
+ (int) gate.getExit().getY() + " | " + (int) gate.getExit().getZ() + " ) in " +
|
||||||
gate.getExit().getWorld().getName());
|
gate.getExit().getWorld().getName());
|
||||||
else
|
else
|
||||||
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no exit");
|
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no exit");
|
||||||
@ -111,7 +106,7 @@ public class CommandInfo extends BaseCommand
|
|||||||
|
|
||||||
|
|
||||||
if (this.sender instanceof Player) {
|
if (this.sender instanceof Player) {
|
||||||
GateBlockChangeSender.temporaryHighlightGateFrame((Player)this.sender, this.gate);
|
GateBlockChangeSender.temporaryHighlightGateFrame((Player) this.sender, this.gate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,324 +28,287 @@ import de.craftinc.gates.Gate;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
import de.craftinc.gates.util.TextUtil;
|
import de.craftinc.gates.util.TextUtil;
|
||||||
|
|
||||||
|
public class CommandList extends BaseCommand {
|
||||||
|
|
||||||
public class CommandList extends BaseCommand
|
private static final int linesPerPage = 10;
|
||||||
{
|
|
||||||
protected static final int linesPerPage = 10;
|
|
||||||
protected static final int charactersPerLine = 52; /* this is actually no true. the
|
|
||||||
font used by minecraft is not
|
|
||||||
monospace. but I don't think
|
|
||||||
there is a (easy) way for a
|
|
||||||
bukkit plugin to calculate
|
|
||||||
the drawing-size of a string.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public CommandList()
|
|
||||||
{
|
|
||||||
aliases.add("list");
|
|
||||||
aliases.add("ls");
|
|
||||||
|
|
||||||
optionalParameters.add("page");
|
|
||||||
hasGateParam = false;
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
|
||||||
|
|
||||||
helpDescription = "lists all availible gates.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionInfo;
|
|
||||||
shouldPersistToDisk = false;
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected static List<String> linesOfGateIds(List<String> gates)
|
|
||||||
{
|
|
||||||
List<String> lines = new ArrayList<String>();
|
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
List<String> gateIdsForCurrentLine = new ArrayList<String>();
|
|
||||||
int numCharactersInCurrentLine = 0;
|
|
||||||
|
|
||||||
|
|
||||||
while (index < gates.size()) {
|
|
||||||
String gateId = gates.get(index);
|
|
||||||
int gateIdLength = gateId.length() + 2; // actual length + comma + whitespace
|
|
||||||
|
|
||||||
// special case: very long gate id
|
|
||||||
if (gateIdLength > charactersPerLine && numCharactersInCurrentLine == 0) {
|
|
||||||
gateIdsForCurrentLine = new ArrayList<String>();
|
|
||||||
numCharactersInCurrentLine = 0;
|
|
||||||
|
|
||||||
while ((gateId.length() + 2) > charactersPerLine) {
|
|
||||||
|
|
||||||
int cutPos = charactersPerLine;
|
|
||||||
|
|
||||||
// is the id too long to add comma and whitespace but not longer than the line?
|
|
||||||
if (gateId.length() <= charactersPerLine) {
|
|
||||||
cutPos -= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.add(gateId.substring(0, cutPos));
|
|
||||||
gateId = gateId.substring(cutPos, gateId.length());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
gateIdsForCurrentLine.add(gateId);
|
/* this is actually not true. the font used by Minecraft is not
|
||||||
|
monospaced. but there seems to be no (easy) way to calculate
|
||||||
numCharactersInCurrentLine += gateId.length();
|
the drawing-size of a string.
|
||||||
index++;
|
*/
|
||||||
}
|
private static final int charactersPerLine = 52;
|
||||||
|
|
||||||
// gate fits into current line
|
public CommandList() {
|
||||||
else if ((numCharactersInCurrentLine + gateIdLength) <= charactersPerLine) {
|
aliases.add("list");
|
||||||
gateIdsForCurrentLine.add(gateId);
|
aliases.add("ls");
|
||||||
numCharactersInCurrentLine += gateIdLength;
|
|
||||||
|
optionalParameters.add("page");
|
||||||
index++;
|
hasGateParam = false;
|
||||||
}
|
needsPermissionAtCurrentLocation = false;
|
||||||
|
|
||||||
// the current gate does not fit on the
|
helpDescription = "lists all availible gates.";
|
||||||
else {
|
|
||||||
lines.add(TextUtil.implode(gateIdsForCurrentLine, ", ") + ", ");
|
requiredPermission = Plugin.permissionInfo;
|
||||||
|
shouldPersistToDisk = false;
|
||||||
gateIdsForCurrentLine = new ArrayList<String>();
|
senderMustBePlayer = false;
|
||||||
numCharactersInCurrentLine = 0;
|
}
|
||||||
}
|
|
||||||
}
|
public void perform() {
|
||||||
|
int page = this.getPageParameter();
|
||||||
lines.add(TextUtil.implode(gateIdsForCurrentLine, ", "));
|
List<String> allPages = this.pagedGateIds();
|
||||||
return lines;
|
|
||||||
}
|
if (allPages == null) { // no gates exist
|
||||||
|
sendMessage(ChatColor.RED + "There are no gates yet. " + ChatColor.RESET +
|
||||||
|
"(Note that you might not be allowed to get information about certain gates)");
|
||||||
protected static String intToTitleString(int i, boolean addPreviousPageNote, boolean addNextPageNote)
|
return;
|
||||||
{
|
}
|
||||||
String retVal = ChatColor.DARK_AQUA + "";
|
|
||||||
|
if (page > allPages.size() || page < 1) {
|
||||||
if ( i < 26 ) {
|
sendMessage(ChatColor.RED + "The requested page is not availible");
|
||||||
retVal += (char)(i+65);
|
return;
|
||||||
}
|
}
|
||||||
else if ( i == 26 ) {
|
|
||||||
retVal += "0-9";
|
String message = TextUtil.titleize("List of all gates (" + page + "/" + allPages.size() + ")") + "\n";
|
||||||
}
|
message += allPages.get(page - 1);
|
||||||
else {
|
|
||||||
retVal += "!@#$";
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addPreviousPageNote && addNextPageNote) {
|
private static List<String> linesOfGateIds(List<String> gates) {
|
||||||
retVal += " (more on previous and next page)";
|
List<String> lines = new ArrayList<String>();
|
||||||
}
|
|
||||||
else if (addPreviousPageNote) {
|
int index = 0;
|
||||||
retVal += " (more on previous page)";
|
List<String> gateIdsForCurrentLine = new ArrayList<String>();
|
||||||
}
|
int numCharactersInCurrentLine = 0;
|
||||||
else if (addNextPageNote) {
|
|
||||||
retVal += " (more on next page)";
|
while (index < gates.size()) {
|
||||||
}
|
String gateId = gates.get(index);
|
||||||
|
int gateIdLength = gateId.length() + 2; // actual length + comma + whitespace
|
||||||
return retVal + "\n";
|
|
||||||
}
|
if (gateIdLength > charactersPerLine && numCharactersInCurrentLine == 0) { // special case: very long gate id
|
||||||
|
gateIdsForCurrentLine = new ArrayList<String>();
|
||||||
|
numCharactersInCurrentLine = 0;
|
||||||
/**
|
|
||||||
* Method for getting a collection of gates the player is allowed to see.
|
while ((gateId.length() + 2) > charactersPerLine) {
|
||||||
*/
|
int cutPos = charactersPerLine;
|
||||||
protected Collection<Gate> getAllGates()
|
|
||||||
{
|
// is the id too long to add comma and whitespace but not longer than the line?
|
||||||
Collection<Gate> gates = Plugin.getPlugin().getGatesManager().allGates();
|
if (gateId.length() <= charactersPerLine) {
|
||||||
|
cutPos -= 2;
|
||||||
if (this.sender instanceof Player && Plugin.getPermission() != null) {
|
}
|
||||||
Player p = (Player)this.sender;
|
|
||||||
|
lines.add(gateId.substring(0, cutPos));
|
||||||
// create a copy since we cannot iterate over a collection while modifying it!
|
gateId = gateId.substring(cutPos, gateId.length());
|
||||||
Collection<Gate> gatesCopy = new ArrayList<Gate>(gates);
|
}
|
||||||
|
|
||||||
for (Gate gate : gatesCopy) {
|
gateIdsForCurrentLine.add(gateId);
|
||||||
|
|
||||||
if (gate.getLocation() != null) {
|
numCharactersInCurrentLine += gateId.length();
|
||||||
boolean permissionAtGateLocation = Plugin.getPermission().has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
index++;
|
||||||
if (!permissionAtGateLocation) {
|
} else if ((numCharactersInCurrentLine + gateIdLength) <= charactersPerLine) { // gate fits into current line
|
||||||
gates.remove(gate);
|
gateIdsForCurrentLine.add(gateId);
|
||||||
continue;
|
numCharactersInCurrentLine += gateIdLength;
|
||||||
}
|
|
||||||
}
|
index++;
|
||||||
|
} else { // the current gate does not fit on the
|
||||||
if (gate.getExit() != null) {
|
lines.add(TextUtil.implode(gateIdsForCurrentLine, ", ") + ", ");
|
||||||
|
|
||||||
boolean permissionAtGateExit = Plugin.getPermission().has(gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
gateIdsForCurrentLine = new ArrayList<String>();
|
||||||
if (!permissionAtGateExit) {
|
numCharactersInCurrentLine = 0;
|
||||||
gates.remove(gate);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
lines.add(TextUtil.implode(gateIdsForCurrentLine, ", "));
|
||||||
}
|
return lines;
|
||||||
|
}
|
||||||
return gates;
|
|
||||||
}
|
private static String intToTitleString(int i, boolean addPreviousPageNote, boolean addNextPageNote) {
|
||||||
|
String retVal = ChatColor.DARK_AQUA + "";
|
||||||
|
|
||||||
/**
|
if (i < 26) {
|
||||||
* Sorts all gates by there first character.
|
retVal += (char) (i + 65);
|
||||||
* Puts gates in corresponding Lists: (all returned lists will be sorted alphabetically)
|
} else if (i == 26) {
|
||||||
* list 0-25: a,b,c,..,z
|
retVal += "0-9";
|
||||||
* list 26: 0-9
|
} else {
|
||||||
* list 27: other
|
retVal += "!@#$";
|
||||||
*/
|
}
|
||||||
protected static List<List<String>> gatesSortedByName(Collection<Gate> allGates)
|
|
||||||
{
|
if (addPreviousPageNote && addNextPageNote) {
|
||||||
// create the lists
|
retVal += " (more on previous and next page)";
|
||||||
List<List<String>> ids = new ArrayList<List<String>>();
|
} else if (addPreviousPageNote) {
|
||||||
|
retVal += " (more on previous page)";
|
||||||
for (int i=0; i<28; i++) {
|
} else if (addNextPageNote) {
|
||||||
ids.add(new ArrayList<String>());
|
retVal += " (more on next page)";
|
||||||
}
|
}
|
||||||
|
|
||||||
// put all gates into correct lists
|
return retVal + "\n";
|
||||||
for (Gate gate : allGates) {
|
}
|
||||||
String id = gate.getId();
|
|
||||||
int first = id.charAt(0);
|
/**
|
||||||
|
* Method for getting a collection of gates the player is allowed to see.
|
||||||
if (first > 96 && first < 123) { // convert lower case chars
|
*/
|
||||||
first -= 97;
|
private Collection<Gate> getAllGates() {
|
||||||
}
|
Collection<Gate> gates = Plugin.getPlugin().getGatesManager().allGates();
|
||||||
else if (first > 64 && first < 91) { // convert upper case chars
|
|
||||||
first -= 65;
|
if (this.sender instanceof Player && Plugin.getPermission() != null) {
|
||||||
}
|
Player p = (Player) this.sender;
|
||||||
else if (first > 47 && first < 58) { // convert numbers
|
|
||||||
first = 26;
|
// create a copy since we cannot iterate over a collection while modifying it!
|
||||||
}
|
Collection<Gate> gatesCopy = new ArrayList<Gate>(gates);
|
||||||
else { // everything else
|
|
||||||
first = 27;
|
for (Gate gate : gatesCopy) {
|
||||||
}
|
if (gate.getLocation() != null) {
|
||||||
|
boolean permissionAtGateLocation = Plugin.getPermission().has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
||||||
ids.get(first).add(id);
|
if (!permissionAtGateLocation) {
|
||||||
}
|
gates.remove(gate);
|
||||||
|
continue;
|
||||||
// sort everything
|
}
|
||||||
for (int i=0; i<28; i++) {
|
}
|
||||||
Collections.sort(ids.get(i));
|
|
||||||
}
|
if (gate.getExit() != null) {
|
||||||
|
boolean permissionAtGateExit = Plugin.getPermission().has(gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
||||||
return ids;
|
if (!permissionAtGateExit) {
|
||||||
}
|
gates.remove(gate);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Returns a list of strings.
|
}
|
||||||
* Each string is the text for a page.
|
|
||||||
* The maximum number of lines per page is 'linesPerPage' minus 1.
|
return gates;
|
||||||
* Will return an empty list if no gates are availible.
|
}
|
||||||
*/
|
|
||||||
protected List<String> pagedGateIds()
|
/**
|
||||||
{
|
* Sorts all gates by there first character.
|
||||||
Collection<Gate> gates = this.getAllGates();
|
* Puts gates in corresponding Lists: (all returned lists will be sorted alphabetically)
|
||||||
|
* list 0-25: a,b,c,..,z
|
||||||
if (gates.size() == 0) {
|
* list 26: 0-9
|
||||||
return null;
|
* list 27: other
|
||||||
}
|
*/
|
||||||
|
private static List<List<String>> gatesSortedByName(Collection<Gate> allGates) {
|
||||||
List<List<String>> gatesSortedByName = gatesSortedByName(gates);
|
// create the lists
|
||||||
List<String> allPages = new ArrayList<String>();
|
List<List<String>> ids = new ArrayList<List<String>>();
|
||||||
int linesLeftOnPage = linesPerPage - 1;
|
|
||||||
String currentPageString = "";
|
for (int i = 0; i < 28; i++) {
|
||||||
|
ids.add(new ArrayList<String>());
|
||||||
for (int i=0; i<gatesSortedByName.size(); i++) {
|
}
|
||||||
|
|
||||||
List<String> currentGates = gatesSortedByName.get(i);
|
// put all gates into correct lists
|
||||||
|
for (Gate gate : allGates) {
|
||||||
if(currentGates.isEmpty()) {
|
String id = gate.getId();
|
||||||
continue;
|
int first = id.charAt(0);
|
||||||
}
|
|
||||||
|
if (first > 96 && first < 123) { // convert lower case chars
|
||||||
List<String> currentGatesAsLines = linesOfGateIds(currentGates);
|
first -= 97;
|
||||||
boolean moreGatesOnLastPage = false;
|
} else if (first > 64 && first < 91) { // convert upper case chars
|
||||||
|
first -= 65;
|
||||||
while (!currentGatesAsLines.isEmpty()) {
|
} else if (first > 47 && first < 58) { // convert numbers
|
||||||
|
first = 26;
|
||||||
if (linesLeftOnPage < 2) {
|
} else { // everything else
|
||||||
currentPageString = currentPageString.substring(0, currentPageString.length()-2); // remove newlines add the end of the page
|
first = 27;
|
||||||
allPages.add(currentPageString);
|
}
|
||||||
currentPageString = "";
|
|
||||||
|
ids.get(first).add(id);
|
||||||
linesLeftOnPage = linesPerPage - 1;
|
}
|
||||||
}
|
|
||||||
|
// sort everything
|
||||||
// calculate number of lines to add to current page
|
for (int i = 0; i < 28; i++) {
|
||||||
int linesNecessaryForCurrentGates = currentGatesAsLines.size();
|
Collections.sort(ids.get(i));
|
||||||
int linesToFill;
|
}
|
||||||
boolean moreGatesOnNextPage;
|
|
||||||
|
return ids;
|
||||||
if (linesNecessaryForCurrentGates < linesLeftOnPage) {
|
}
|
||||||
linesToFill = linesNecessaryForCurrentGates;
|
|
||||||
moreGatesOnNextPage = false;
|
/**
|
||||||
}
|
* Returns a list of strings.
|
||||||
else {
|
* Each string is the text for a page.
|
||||||
linesToFill = linesLeftOnPage -1;
|
* The maximum number of lines per page is 'linesPerPage' minus 1.
|
||||||
moreGatesOnNextPage = true;
|
* Will return an empty list if no gates are availible.
|
||||||
}
|
*/
|
||||||
|
private List<String> pagedGateIds() {
|
||||||
// add title
|
Collection<Gate> gates = this.getAllGates();
|
||||||
currentPageString += intToTitleString(i, moreGatesOnLastPage, moreGatesOnNextPage);
|
|
||||||
currentPageString += ChatColor.AQUA;
|
if (gates.size() == 0) {
|
||||||
linesLeftOnPage--;
|
return null;
|
||||||
|
}
|
||||||
// add gate lines
|
|
||||||
for (int j=0; j<linesToFill; j++) {
|
List<List<String>> gatesSortedByName = gatesSortedByName(gates);
|
||||||
currentPageString += currentGatesAsLines.get(j) + "\n";
|
List<String> allPages = new ArrayList<String>();
|
||||||
}
|
int linesLeftOnPage = linesPerPage - 1;
|
||||||
|
String currentPageString = "";
|
||||||
// remove lines added
|
|
||||||
for (int j=0; j<linesToFill; j++) {
|
for (int i = 0; i < gatesSortedByName.size(); i++) {
|
||||||
currentGatesAsLines.remove(0);
|
|
||||||
}
|
List<String> currentGates = gatesSortedByName.get(i);
|
||||||
|
|
||||||
// cleanup
|
if (currentGates.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> currentGatesAsLines = linesOfGateIds(currentGates);
|
||||||
|
boolean moreGatesOnLastPage = false;
|
||||||
|
|
||||||
|
while (!currentGatesAsLines.isEmpty()) {
|
||||||
|
|
||||||
|
if (linesLeftOnPage < 2) {
|
||||||
|
currentPageString = currentPageString.substring(0, currentPageString.length() - 2); // remove newlines add the end of the page
|
||||||
|
allPages.add(currentPageString);
|
||||||
|
currentPageString = "";
|
||||||
|
|
||||||
|
linesLeftOnPage = linesPerPage - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate number of lines to add to current page
|
||||||
|
int linesNecessaryForCurrentGates = currentGatesAsLines.size();
|
||||||
|
int linesToFill;
|
||||||
|
boolean moreGatesOnNextPage;
|
||||||
|
|
||||||
|
if (linesNecessaryForCurrentGates < linesLeftOnPage) {
|
||||||
|
linesToFill = linesNecessaryForCurrentGates;
|
||||||
|
moreGatesOnNextPage = false;
|
||||||
|
} else {
|
||||||
|
linesToFill = linesLeftOnPage - 1;
|
||||||
|
moreGatesOnNextPage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add title
|
||||||
|
currentPageString += intToTitleString(i, moreGatesOnLastPage, moreGatesOnNextPage);
|
||||||
|
currentPageString += ChatColor.AQUA;
|
||||||
|
linesLeftOnPage--;
|
||||||
|
|
||||||
|
// add gate lines
|
||||||
|
for (int j = 0; j < linesToFill; j++) {
|
||||||
|
currentPageString += currentGatesAsLines.get(j) + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove lines added
|
||||||
|
for (int j = 0; j < linesToFill; j++) {
|
||||||
|
currentGatesAsLines.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanup
|
||||||
moreGatesOnLastPage = linesNecessaryForCurrentGates >= linesLeftOnPage;
|
moreGatesOnLastPage = linesNecessaryForCurrentGates >= linesLeftOnPage;
|
||||||
linesLeftOnPage -= linesToFill;
|
linesLeftOnPage -= linesToFill;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the last page
|
|
||||||
if (!currentPageString.isEmpty()) {
|
|
||||||
currentPageString = currentPageString.substring(0, currentPageString.length()-2); // remove newlines add the end of the page
|
|
||||||
allPages.add(currentPageString);
|
|
||||||
}
|
|
||||||
|
|
||||||
return allPages;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected int getPageParameter()
|
|
||||||
{
|
|
||||||
int page = 1;
|
|
||||||
|
|
||||||
try {
|
|
||||||
page = new Integer(parameters.get(0));
|
|
||||||
}
|
|
||||||
catch (Exception ignored) { }
|
|
||||||
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
int page = this.getPageParameter();
|
|
||||||
List<String> allPages = this.pagedGateIds();
|
|
||||||
|
|
||||||
if (allPages == null) { // no gates exist
|
// add the last page
|
||||||
sendMessage(ChatColor.RED + "There are no gates yet. " + ChatColor.RESET +
|
if (!currentPageString.isEmpty()) {
|
||||||
"(Note that you might not be allowed to get information about certain gates)");
|
currentPageString = currentPageString.substring(0, currentPageString.length() - 2); // remove newlines add the end of the page
|
||||||
return;
|
allPages.add(currentPageString);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page > allPages.size() || page < 1) {
|
|
||||||
sendMessage(ChatColor.RED + "The requested page is not availible");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String message = TextUtil.titleize("List of all gates (" + page + "/" + allPages.size() + ")") + "\n";
|
|
||||||
message += allPages.get(page-1);
|
|
||||||
|
|
||||||
sendMessage(message);
|
return allPages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int getPageParameter() {
|
||||||
|
int page = 1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
page = new Integer(parameters.get(0));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return page;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.craftinc.gates.util.GateBlockChangeSender;
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
@ -26,59 +25,46 @@ import org.bukkit.Location;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
public class CommandLocation extends BaseLocationCommand {
|
||||||
|
|
||||||
public class CommandLocation extends BaseLocationCommand
|
public CommandLocation() {
|
||||||
{
|
aliases.add("location");
|
||||||
public CommandLocation()
|
aliases.add("lo");
|
||||||
{
|
|
||||||
aliases.add("location");
|
requiredParameters.add("id");
|
||||||
aliases.add("lo");
|
helpDescription = "Set the entrance of the gate to your current location.";
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
requiredParameters.add("id");
|
|
||||||
|
needsPermissionAtCurrentLocation = true;
|
||||||
helpDescription = "Set the entrance of the gate to your current location.";
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = true;
|
||||||
requiredPermission = Plugin.permissionManage;
|
}
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = true;
|
public void perform() {
|
||||||
shouldPersistToDisk = true;
|
Location playerLocation = getValidPlayerLocation();
|
||||||
senderMustBePlayer = true;
|
|
||||||
}
|
if (playerLocation == null) {
|
||||||
|
sendMessage("There is not enough room for a gate to open here");
|
||||||
|
return;
|
||||||
public void perform()
|
}
|
||||||
{
|
|
||||||
Location playerLocation = getValidPlayerLocation();
|
|
||||||
|
|
||||||
if (playerLocation == null)
|
|
||||||
{
|
|
||||||
sendMessage("There is not enough room for a gate to open here");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location oldLocation = gate.getLocation();
|
Location oldLocation = gate.getLocation();
|
||||||
Set<Location> oldGateBlockLocations = gate.getGateBlockLocations();
|
Set<Location> oldGateBlockLocations = gate.getGateBlockLocations();
|
||||||
Set<Block> oldFrameBlocks = gate.getGateFrameBlocks();
|
Set<Block> oldFrameBlocks = gate.getGateFrameBlocks();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
if (gate.isOpen()) {
|
if (gate.isOpen()) {
|
||||||
GateBlockChangeSender.updateGateBlocks(gate, true);
|
GateBlockChangeSender.updateGateBlocks(gate, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
gate.setLocation(playerLocation);
|
gate.setLocation(playerLocation);
|
||||||
|
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, 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
import de.craftinc.gates.Gate;
|
||||||
import de.craftinc.gates.GatesManager;
|
import de.craftinc.gates.GatesManager;
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
@ -10,33 +9,27 @@ import de.craftinc.gates.util.TextUtil;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class CommandNearby extends BaseLocationCommand
|
public class CommandNearby extends BaseLocationCommand {
|
||||||
{
|
|
||||||
public CommandNearby()
|
public CommandNearby() {
|
||||||
{
|
|
||||||
aliases.add("nearby");
|
aliases.add("nearby");
|
||||||
aliases.add("nb");
|
aliases.add("nb");
|
||||||
|
|
||||||
helpDescription = "Highlight nearby gates";
|
helpDescription = "Highlight nearby gates";
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionInfo;
|
requiredPermission = Plugin.permissionInfo;
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = true;
|
needsPermissionAtCurrentLocation = true;
|
||||||
shouldPersistToDisk = false;
|
shouldPersistToDisk = false;
|
||||||
senderMustBePlayer = true;
|
senderMustBePlayer = true;
|
||||||
hasGateParam = false;
|
hasGateParam = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void perform() {
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
GatesManager manager = Plugin.getPlugin().getGatesManager();
|
GatesManager manager = Plugin.getPlugin().getGatesManager();
|
||||||
Set<Gate> nearbyGates = manager.getNearbyGates(player.getLocation().getChunk());
|
Set<Gate> nearbyGates = manager.getNearbyGates(player.getLocation().getChunk());
|
||||||
|
|
||||||
if (nearbyGates == null) {
|
if (nearbyGates == null) {
|
||||||
player.sendMessage("There are no gates near you!");
|
player.sendMessage("There are no gates near you!");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
GateBlockChangeSender.temporaryHighlightGatesFrames(player, nearbyGates);
|
GateBlockChangeSender.temporaryHighlightGatesFrames(player, nearbyGates);
|
||||||
|
|
||||||
ArrayList<String> gateNames = new ArrayList<String>();
|
ArrayList<String> gateNames = new ArrayList<String>();
|
||||||
@ -44,10 +37,7 @@ public class CommandNearby extends BaseLocationCommand
|
|||||||
for (Gate g : nearbyGates) {
|
for (Gate g : nearbyGates) {
|
||||||
gateNames.add(g.getId());
|
gateNames.add(g.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage("Nearby gates: " + TextUtil.implode(gateNames, ", "));
|
player.sendMessage("Nearby gates: " + TextUtil.implode(gateNames, ", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,61 +23,48 @@ import de.craftinc.gates.Gate;
|
|||||||
import de.craftinc.gates.GatesManager;
|
import de.craftinc.gates.GatesManager;
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
public class CommandNew extends BaseLocationCommand {
|
||||||
|
|
||||||
public class CommandNew extends BaseLocationCommand
|
public CommandNew() {
|
||||||
{
|
aliases.add("new");
|
||||||
public CommandNew()
|
|
||||||
{
|
|
||||||
aliases.add("new");
|
|
||||||
aliases.add("n");
|
aliases.add("n");
|
||||||
|
|
||||||
requiredParameters.add("id");
|
requiredParameters.add("id");
|
||||||
|
|
||||||
senderMustBePlayer = true;
|
|
||||||
hasGateParam = false;
|
|
||||||
|
|
||||||
helpDescription = "Create a gate at your current location.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = true;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
|
|
||||||
senderMustBePlayer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
String id = parameters.get(0);
|
|
||||||
GatesManager gatesManager = Plugin.getPlugin().getGatesManager();
|
|
||||||
|
|
||||||
if (gatesManager.gateExists(id)) {
|
|
||||||
sendMessage(ChatColor.RED + "Creating the gate failed! " + "A gate with the supplied id already exists!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gate = new Gate(id);
|
|
||||||
sendMessage(ChatColor.GREEN + "Gate with id '" + id + "' was created.");
|
|
||||||
|
|
||||||
|
senderMustBePlayer = true;
|
||||||
Location playerLocation = getValidPlayerLocation();
|
hasGateParam = false;
|
||||||
|
helpDescription = "Create a gate at your current location.";
|
||||||
if (playerLocation != null) {
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
needsPermissionAtCurrentLocation = true;
|
||||||
try {
|
shouldPersistToDisk = true;
|
||||||
gate.setLocation(playerLocation);
|
senderMustBePlayer = true;
|
||||||
sendMessage(ChatColor.AQUA + "The gates location has been set to your current location.");
|
}
|
||||||
}
|
|
||||||
catch (Exception ignored) {}
|
public void perform() {
|
||||||
}
|
String id = parameters.get(0);
|
||||||
else
|
GatesManager gatesManager = Plugin.getPlugin().getGatesManager();
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "Your location is invalid!" + ChatColor.AQUA + "Go somewhere else and execute:");
|
if (gatesManager.gateExists(id)) {
|
||||||
sendMessage(new CommandLocation().getUsageTemplate(true, true));
|
sendMessage(ChatColor.RED + "Creating the gate failed! " + "A gate with the supplied id already exists!");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gate = new Gate(id);
|
||||||
|
sendMessage(ChatColor.GREEN + "Gate with id '" + id + "' was created.");
|
||||||
|
|
||||||
|
Location playerLocation = getValidPlayerLocation();
|
||||||
|
|
||||||
|
if (playerLocation != null) {
|
||||||
|
try {
|
||||||
|
gate.setLocation(playerLocation);
|
||||||
|
sendMessage(ChatColor.AQUA + "The gates location has been set to your current location.");
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sendMessage(ChatColor.RED + "Your location is invalid!" + ChatColor.AQUA + "Go somewhere else and execute:");
|
||||||
|
sendMessage(new CommandLocation().getUsageTemplate(true, true));
|
||||||
|
}
|
||||||
|
|
||||||
gatesManager.handleNewGate(gate);
|
gatesManager.handleNewGate(gate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,39 +16,31 @@
|
|||||||
*/
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
|
||||||
import de.craftinc.gates.util.GateBlockChangeSender;
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
public class CommandOpen extends BaseCommand {
|
||||||
|
|
||||||
public class CommandOpen extends BaseCommand
|
public CommandOpen() {
|
||||||
{
|
aliases.add("open");
|
||||||
|
aliases.add("o");
|
||||||
public CommandOpen()
|
|
||||||
{
|
requiredParameters.add("id");
|
||||||
aliases.add("open");
|
helpDescription = "Open a gate so players can use it.";
|
||||||
aliases.add("o");
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
requiredParameters.add("id");
|
needsPermissionAtCurrentLocation = false;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
helpDescription = "Open a gate so players can use it.";
|
senderMustBePlayer = false;
|
||||||
|
}
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
public void perform() {
|
||||||
needsPermissionAtCurrentLocation = false;
|
try {
|
||||||
shouldPersistToDisk = true;
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
boolean needsGateManagerUpdate = false;
|
boolean needsGateManagerUpdate = false;
|
||||||
|
|
||||||
if (gate.getGateBlockLocations().isEmpty()) {
|
if (gate.getGateBlockLocations().isEmpty()) {
|
||||||
needsGateManagerUpdate = true;
|
needsGateManagerUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +52,9 @@ public class CommandOpen extends BaseCommand
|
|||||||
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, null, null, null);
|
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(ChatColor.GREEN + "The gate was opened.");
|
sendMessage(ChatColor.GREEN + "The gate was opened.");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
sendMessage(ChatColor.RED + e.getMessage());
|
||||||
sendMessage(ChatColor.RED + e.getMessage());
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,33 +21,29 @@ import org.bukkit.ChatColor;
|
|||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
public class CommandRemove extends BaseCommand {
|
||||||
|
|
||||||
public class CommandRemove extends BaseCommand
|
public CommandRemove() {
|
||||||
{
|
aliases.add("delete");
|
||||||
public CommandRemove()
|
aliases.add("del");
|
||||||
{
|
aliases.add("remove");
|
||||||
aliases.add("delete");
|
|
||||||
aliases.add("del");
|
requiredParameters.add("id");
|
||||||
aliases.add("remove");
|
|
||||||
|
senderMustBePlayer = false;
|
||||||
requiredParameters.add("id");
|
helpDescription = "Removes the gate from the game.";
|
||||||
|
|
||||||
senderMustBePlayer = false;
|
requiredPermission = Plugin.permissionManage;
|
||||||
helpDescription = "Removes the gate from the game.";
|
|
||||||
|
needsPermissionAtCurrentLocation = false;
|
||||||
requiredPermission = Plugin.permissionManage;
|
shouldPersistToDisk = true;
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
senderMustBePlayer = false;
|
||||||
shouldPersistToDisk = true;
|
}
|
||||||
|
|
||||||
senderMustBePlayer = false;
|
public void perform() {
|
||||||
}
|
Plugin.getPlugin().getGatesManager().handleDeletion(gate);
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
Plugin.getPlugin().getGatesManager().handleDeletion(gate);
|
|
||||||
GateBlockChangeSender.updateGateBlocks(gate, true);
|
GateBlockChangeSender.updateGateBlocks(gate, true);
|
||||||
sendMessage(ChatColor.GREEN + "Gate with id '" + gate.getId() + "' was deleted.");
|
sendMessage(ChatColor.GREEN + "Gate with id '" + gate.getId() + "' was deleted.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,46 +21,41 @@ import org.bukkit.ChatColor;
|
|||||||
import de.craftinc.gates.GatesManager;
|
import de.craftinc.gates.GatesManager;
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
public class CommandRename extends BaseCommand {
|
||||||
|
|
||||||
public class CommandRename extends BaseCommand
|
public CommandRename() {
|
||||||
{
|
aliases.add("rename");
|
||||||
public CommandRename()
|
aliases.add("rn");
|
||||||
{
|
|
||||||
aliases.add("rename");
|
|
||||||
aliases.add("rn");
|
|
||||||
|
|
||||||
hasGateParam = true;
|
hasGateParam = true;
|
||||||
senderMustBePlayer = false;
|
senderMustBePlayer = false;
|
||||||
|
|
||||||
requiredParameters.add("current name");
|
|
||||||
requiredParameters.add("new name");
|
|
||||||
|
|
||||||
helpDescription = "Changes the id of a gate.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
String newId = parameters.get(1);
|
|
||||||
GatesManager gatesManager = Plugin.getPlugin().getGatesManager();
|
|
||||||
|
|
||||||
if (gatesManager.gateExists(newId)) {
|
|
||||||
sendMessage(ChatColor.RED + "Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
String oldId = gate.getId();
|
|
||||||
|
|
||||||
gate.setId(newId);
|
|
||||||
gatesManager.handleGateIdChange(gate, oldId);
|
|
||||||
|
|
||||||
sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " is now known as " + newId + ".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
requiredParameters.add("current name");
|
||||||
|
requiredParameters.add("new name");
|
||||||
|
|
||||||
|
helpDescription = "Changes the id of a gate.";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
|
needsPermissionAtCurrentLocation = false;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void perform() {
|
||||||
|
String newId = parameters.get(1);
|
||||||
|
GatesManager gatesManager = Plugin.getPlugin().getGatesManager();
|
||||||
|
|
||||||
|
if (gatesManager.gateExists(newId)) {
|
||||||
|
sendMessage(ChatColor.RED + "Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
|
||||||
|
} else {
|
||||||
|
String oldId = gate.getId();
|
||||||
|
|
||||||
|
gate.setId(newId);
|
||||||
|
gatesManager.handleGateIdChange(gate, oldId);
|
||||||
|
|
||||||
|
sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " is now known as " + newId + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,38 +21,27 @@ import org.bukkit.ChatColor;
|
|||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
public class CommandUnhide extends BaseCommand {
|
||||||
|
|
||||||
public class CommandUnhide extends BaseCommand
|
public CommandUnhide() {
|
||||||
{
|
aliases.add("unhide");
|
||||||
|
aliases.add("u");
|
||||||
public CommandUnhide()
|
|
||||||
{
|
requiredParameters.add("id");
|
||||||
aliases.add("unhide");
|
helpDescription = "Make that gate visible";
|
||||||
aliases.add("u");
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
needsPermissionAtCurrentLocation = false;
|
||||||
requiredParameters.add("id");
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = false;
|
||||||
helpDescription = "Make that gate visible";
|
}
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
public void perform() {
|
||||||
|
try {
|
||||||
needsPermissionAtCurrentLocation = false;
|
gate.setHidden(false);
|
||||||
shouldPersistToDisk = true;
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gate.setHidden(false);
|
|
||||||
GateBlockChangeSender.updateGateBlocks(gate);
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
sendMessage(ChatColor.GREEN + "The gate " + gate.getId() + " is now visible.");
|
sendMessage(ChatColor.GREEN + "The gate " + gate.getId() + " is now visible.");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
sendMessage(ChatColor.RED + e.getMessage());
|
||||||
sendMessage(ChatColor.RED + e.getMessage());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -25,11 +25,9 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|
||||||
public class BlockBreakListener implements Listener
|
public class BlockBreakListener implements Listener {
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onBlockBreak(BlockBreakEvent event)
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
{
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -39,8 +37,8 @@ public class BlockBreakListener implements Listener
|
|||||||
if (gate != null && !gate.isHidden()) {
|
if (gate != null && !gate.isHidden()) {
|
||||||
try {
|
try {
|
||||||
gate.setOpen(false);
|
gate.setOpen(false);
|
||||||
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
catch (Exception ignored) { }
|
|
||||||
|
|
||||||
GateBlockChangeSender.updateGateBlocks(gate);
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,9 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
|
|
||||||
|
|
||||||
public class PlayerChangedWorldListener implements Listener
|
public class PlayerChangedWorldListener implements Listener {
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPlayerChangeWorld(PlayerChangedWorldEvent event)
|
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
|
||||||
{
|
|
||||||
GateBlockChangeSender.updateGateBlocks(event.getPlayer());
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,9 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
public class PlayerJoinListener implements Listener
|
public class PlayerJoinListener implements Listener {
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
{
|
|
||||||
GateBlockChangeSender.updateGateBlocks(event.getPlayer());
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,71 +38,68 @@ import de.craftinc.gates.Plugin;
|
|||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
|
|
||||||
public class PlayerMoveListener implements Listener
|
public class PlayerMoveListener implements Listener {
|
||||||
{
|
protected HashMap<String, Long> lastNoPermissionMessages = new HashMap<String, Long>();
|
||||||
protected HashMap<String, Long> lastNoPermissionMessages = new HashMap<String, Long>();
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
public void onPlayerMove(PlayerMoveEvent event)
|
if (event.isCancelled()) {
|
||||||
{
|
return;
|
||||||
if (event.isCancelled()) {
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getFrom().getChunk() != event.getTo().getChunk()) {
|
if (event.getFrom().getChunk() != event.getTo().getChunk()) {
|
||||||
GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getTo());
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
final GatesManager gateManager = Plugin.getPlugin().getGatesManager();
|
final GatesManager gateManager = Plugin.getPlugin().getGatesManager();
|
||||||
final Gate gateAtLocation = gateManager.getGateAtLocation(event.getTo());
|
final Gate gateAtLocation = gateManager.getGateAtLocation(event.getTo());
|
||||||
|
|
||||||
if ((gateAtLocation == null) || !gateAtLocation.isOpen()) {
|
if ((gateAtLocation == null) || !gateAtLocation.isOpen()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for permission
|
||||||
|
if (!hasPermission(event.getPlayer(), gateAtLocation)
|
||||||
|
&& Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confShowTeleportNoPermissionMessageKey)) {
|
||||||
|
|
||||||
|
final String playerName = event.getPlayer().getName();
|
||||||
|
|
||||||
|
if (playerName == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for permission
|
// get the current time
|
||||||
if (!hasPermission(event.getPlayer(), gateAtLocation)
|
final Long now = Calendar.getInstance().getTimeInMillis();
|
||||||
&& Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confShowTeleportNoPermissionMessageKey)) {
|
|
||||||
|
// do not display messages more often than once per second
|
||||||
final String playerName = event.getPlayer().getName();
|
if (!this.lastNoPermissionMessages.containsKey(playerName) || this.lastNoPermissionMessages.get(playerName) < now - 10000L) {
|
||||||
|
|
||||||
if (playerName == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the current time
|
|
||||||
final Long now = Calendar.getInstance().getTimeInMillis();
|
|
||||||
|
|
||||||
// do not display messages more often than once per second
|
|
||||||
if (!this.lastNoPermissionMessages.containsKey(playerName) || this.lastNoPermissionMessages.get(playerName) < now - 10000L) {
|
|
||||||
|
|
||||||
final String noPermissionString = Plugin.getPlugin().getConfig().getString(ConfigurationUtil.confGateTeleportNoPermissionMessageKey);
|
final String noPermissionString = Plugin.getPlugin().getConfig().getString(ConfigurationUtil.confGateTeleportNoPermissionMessageKey);
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + noPermissionString);
|
event.getPlayer().sendMessage(ChatColor.RED + noPermissionString);
|
||||||
this.lastNoPermissionMessages.put(playerName, now);
|
this.lastNoPermissionMessages.put(playerName, now);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.teleportPlayer(event.getPlayer(), gateAtLocation);
|
this.teleportPlayer(event.getPlayer(), gateAtLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teleports a player.
|
* Teleports a player.
|
||||||
|
*
|
||||||
* @param player The player to teleport.
|
* @param player The player to teleport.
|
||||||
* @param gate The gate to which exit the player will be teleported.
|
* @param gate The gate to which exit the player will be teleported.
|
||||||
*/
|
*/
|
||||||
private void teleportPlayer(final Player player, final Gate gate)
|
private void teleportPlayer(final Player player, final Gate gate) {
|
||||||
{
|
|
||||||
// Destination
|
// Destination
|
||||||
final Float newYaw = gate.getExit().getYaw() - gate.getLocation().getYaw() + player.getLocation().getYaw();
|
final Float newYaw = gate.getExit().getYaw() - gate.getLocation().getYaw() + player.getLocation().getYaw();
|
||||||
final Location destLocation = new Location( gate.getExit().getWorld(),
|
final Location destLocation = new Location(gate.getExit().getWorld(),
|
||||||
gate.getExit().getX(),
|
gate.getExit().getX(),
|
||||||
gate.getExit().getY(),
|
gate.getExit().getY(),
|
||||||
gate.getExit().getZ(),
|
gate.getExit().getZ(),
|
||||||
newYaw,
|
newYaw,
|
||||||
player.getLocation().getPitch()
|
player.getLocation().getPitch()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Riding
|
// Riding
|
||||||
final Entity vehicle = player.getVehicle();
|
final Entity vehicle = player.getVehicle();
|
||||||
@ -135,12 +132,11 @@ public class PlayerMoveListener implements Listener
|
|||||||
destLocation.getChunk().load(); // load the destination chunk, no new entity will be created otherwise
|
destLocation.getChunk().load(); // load the destination chunk, no new entity will be created otherwise
|
||||||
|
|
||||||
scheduler.scheduleSyncDelayedTask(plugin, new Runnable() {
|
scheduler.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
// FIXME: the code below should be executed after the chunk got loaded and not after a fixed time!
|
// FIXME: the code below should be executed after the chunk got loaded and not after a fixed time!
|
||||||
|
|
||||||
// create a new entity at the destination location
|
// create a new entity at the destination location
|
||||||
final Vehicle newVehicle = VehicleCloner.clone((Vehicle)vehicle, destLocation);
|
final Vehicle newVehicle = VehicleCloner.clone((Vehicle) vehicle, destLocation);
|
||||||
newVehicle.setPassenger(player);
|
newVehicle.setPassenger(player);
|
||||||
}
|
}
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -151,19 +147,17 @@ public class PlayerMoveListener implements Listener
|
|||||||
final String teleportMessage = Plugin.getPlugin().getConfig().getString(ConfigurationUtil.confGateTeleportMessageKey);
|
final String teleportMessage = Plugin.getPlugin().getConfig().getString(ConfigurationUtil.confGateTeleportMessageKey);
|
||||||
player.sendMessage(ChatColor.DARK_AQUA + teleportMessage);
|
player.sendMessage(ChatColor.DARK_AQUA + teleportMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected boolean hasPermission(final Player player, final Gate gate)
|
protected 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 {
|
||||||
}
|
final boolean permAtLocation = Plugin.getPermission().has(gate.getLocation().getWorld(), player.getName(), Plugin.permissionUse);
|
||||||
else {
|
final boolean permAtExit = Plugin.getPermission().has(gate.getExit().getWorld(), player.getName(), Plugin.permissionUse);
|
||||||
final boolean permAtLocation = Plugin.getPermission().has(gate.getLocation().getWorld(), player.getName(), Plugin.permissionUse);
|
|
||||||
final boolean permAtExit = Plugin.getPermission().has(gate.getExit().getWorld(), player.getName(), Plugin.permissionUse);
|
return permAtLocation && permAtExit;
|
||||||
|
}
|
||||||
return permAtLocation && permAtExit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,9 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
|
||||||
|
|
||||||
public class PlayerRespawnListener implements Listener
|
public class PlayerRespawnListener implements Listener {
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPlayerRespawn(PlayerRespawnEvent event)
|
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||||
{
|
|
||||||
GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getRespawnLocation(), true);
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getRespawnLocation(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,9 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
public class PlayerTeleportListener implements Listener
|
public class PlayerTeleportListener implements Listener {
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||||
{
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -18,34 +18,33 @@ package de.craftinc.gates.persistence;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class LocationUtil
|
public class LocationUtil {
|
||||||
{
|
protected final static String worldKey = "world";
|
||||||
protected final static String worldKey = "world";
|
protected final static String xKey = "x";
|
||||||
protected final static String xKey = "x";
|
protected final static String yKey = "y";
|
||||||
protected final static String yKey = "y";
|
protected final static String zKey = "z";
|
||||||
protected 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) {
|
|
||||||
throw new IllegalArgumentException("The name of the world must not be 'null");
|
throw new IllegalArgumentException("The name of the world must not be 'null");
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = Plugin.getPlugin().getServer().getWorld(name);
|
World world = Plugin.getPlugin().getServer().getWorld(name);
|
||||||
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
throw new Exception("World '" + name + "' does not exists anymore! Cannot get instance!");
|
throw new Exception("World '" + name + "' does not exists anymore! Cannot get instance!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,46 +54,43 @@ public class LocationUtil
|
|||||||
* @param l The location to serialize. Supplying 'null' is ok..
|
* @param l The location to serialize. Supplying 'null' is ok..
|
||||||
* @return A Map object ready for storing inside a yaml file. Will return 'null' if 'l' is null.
|
* @return A Map object ready for storing inside a yaml file. Will return 'null' if 'l' is null.
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> serializeLocation(final Location l)
|
public static Map<String, Object> serializeLocation(final Location l) {
|
||||||
{
|
if (l == null) {
|
||||||
if (l == null) {
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
Map<String, Object> serializedLocation = new HashMap<String, Object>();
|
||||||
Map<String, Object> serializedLocation = new HashMap<String, Object>();
|
|
||||||
|
serializedLocation.put(worldKey, l.getWorld().getName());
|
||||||
serializedLocation.put(worldKey, l.getWorld().getName());
|
serializedLocation.put(xKey, l.getX());
|
||||||
serializedLocation.put(xKey, l.getX());
|
serializedLocation.put(yKey, l.getY());
|
||||||
serializedLocation.put(yKey, l.getY());
|
serializedLocation.put(zKey, l.getZ());
|
||||||
serializedLocation.put(zKey, l.getZ());
|
|
||||||
|
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!
|
||||||
* @throws Exception This method will throw an exception if the world of the supplied serialized location
|
* @throws Exception This method will throw an exception if the world of the supplied serialized location
|
||||||
* does not exist or if 'map' does not contain all necessary keys!
|
* does not exist or if 'map' does not contain all necessary keys!
|
||||||
*/
|
*/
|
||||||
public static Location deserializeLocation(final Map<String, Object> map) throws Exception
|
public static Location deserializeLocation(final Map<String, Object> map) throws Exception {
|
||||||
{
|
if (map == null) {
|
||||||
if (map == null) {
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
World w = getWorld((String)map.get(worldKey));
|
|
||||||
|
|
||||||
Number x = (Number)map.get(xKey);
|
World w = getWorld((String) map.get(worldKey));
|
||||||
Number y = (Number)map.get(yKey);
|
|
||||||
Number z = (Number)map.get(zKey);
|
Number x = (Number) map.get(xKey);
|
||||||
|
Number y = (Number) map.get(yKey);
|
||||||
|
Number z = (Number) map.get(zKey);
|
||||||
|
|
||||||
if (x == null || y == null || z == null) {
|
if (x == null || y == null || z == null) {
|
||||||
throw new IllegalArgumentException("Supplied map is invalid x, y or z coordinate was not supplied");
|
throw new IllegalArgumentException("Supplied map is invalid x, y or z coordinate was not supplied");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Location(w, x.doubleValue(), y.doubleValue(), z.doubleValue());
|
return new Location(w, x.doubleValue(), y.doubleValue(), z.doubleValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,30 +27,25 @@ import java.util.List;
|
|||||||
import java.util.logging.Level;
|
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);
|
||||||
updateAllowVehicles(gates);
|
updateAllowVehicles(gates);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (storageVersion == 1 && currentVersion >= 2) {
|
||||||
else if (storageVersion == 1 && currentVersion >= 2) {
|
|
||||||
updateAllowVehicles(gates);
|
updateAllowVehicles(gates);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Plugin.log(Level.SEVERE, "Supplied storage version is currently not supported! Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!");
|
Plugin.log(Level.SEVERE, "Supplied storage version is currently not supported! Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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()) {
|
||||||
@ -64,8 +59,7 @@ public class MigrationUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected 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);
|
||||||
|
@ -23,8 +23,7 @@ import org.bukkit.Material;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
||||||
public class ConfigurationUtil
|
public class ConfigurationUtil {
|
||||||
{
|
|
||||||
public static final String confMaxGateBlocksKey = "maxGateBlocks";
|
public static final String confMaxGateBlocksKey = "maxGateBlocks";
|
||||||
public static final String confPlayerGateBlockUpdateRadiusKey = "playerGateBlockUpdateRadius";
|
public static final String confPlayerGateBlockUpdateRadiusKey = "playerGateBlockUpdateRadius";
|
||||||
public static final String confCheckForBrokenGateFramesKey = "checkForBrokenGateFrames";
|
public static final String confCheckForBrokenGateFramesKey = "checkForBrokenGateFrames";
|
||||||
@ -38,79 +37,56 @@ public class ConfigurationUtil
|
|||||||
public static final String confGateMaterialKey = "gateMaterial";
|
public static final String confGateMaterialKey = "gateMaterial";
|
||||||
|
|
||||||
|
|
||||||
public static GateMaterial getPortalMaterial()
|
public 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")) {
|
if (materialString.equals("sapling")) {
|
||||||
material.material = Material.SAPLING;
|
material.material = Material.SAPLING;
|
||||||
}
|
} else if (materialString.equals("water")) {
|
||||||
else if (materialString.equals("water")) {
|
|
||||||
material.material = Material.STATIONARY_WATER;
|
material.material = Material.STATIONARY_WATER;
|
||||||
}
|
} else if (materialString.equals("lava")) {
|
||||||
else if (materialString.equals("lava")) {
|
|
||||||
material.material = Material.STATIONARY_LAVA;
|
material.material = Material.STATIONARY_LAVA;
|
||||||
}
|
} else if (materialString.equals("cobweb")) {
|
||||||
else if (materialString.equals("cobweb")) {
|
|
||||||
material.material = Material.WEB;
|
material.material = Material.WEB;
|
||||||
}
|
} else if (materialString.equals("grass")) {
|
||||||
else if (materialString.equals("grass")) {
|
|
||||||
material.material = Material.LONG_GRASS;
|
material.material = Material.LONG_GRASS;
|
||||||
material.data = 1;
|
material.data = 1;
|
||||||
}
|
} else if (materialString.equals("dead bush")) {
|
||||||
else if (materialString.equals("dead bush")) {
|
|
||||||
material.material = Material.DEAD_BUSH;
|
material.material = Material.DEAD_BUSH;
|
||||||
}
|
} else if (materialString.equals("dandelion")) {
|
||||||
else if (materialString.equals("dandelion")) {
|
|
||||||
material.material = Material.YELLOW_FLOWER;
|
material.material = Material.YELLOW_FLOWER;
|
||||||
}
|
} else if (materialString.equals("poppy")) {
|
||||||
else if (materialString.equals("poppy")) {
|
|
||||||
material.material = Material.RED_ROSE;
|
material.material = Material.RED_ROSE;
|
||||||
}
|
} else if (materialString.equals("brown mushroom")) {
|
||||||
else if (materialString.equals("brown mushroom")) {
|
|
||||||
material.material = Material.BROWN_MUSHROOM;
|
material.material = Material.BROWN_MUSHROOM;
|
||||||
}
|
} else if (materialString.equals("red mushroom")) {
|
||||||
else if (materialString.equals("red mushroom")) {
|
|
||||||
material.material = Material.RED_MUSHROOM;
|
material.material = Material.RED_MUSHROOM;
|
||||||
}
|
} else if (materialString.equals("torch")) {
|
||||||
else if (materialString.equals("torch")) {
|
|
||||||
material.material = Material.TORCH;
|
material.material = Material.TORCH;
|
||||||
}
|
} else if (materialString.equals("redstone torch (off)")) {
|
||||||
else if (materialString.equals("redstone torch (off)")) {
|
|
||||||
material.material = Material.REDSTONE_TORCH_OFF;
|
material.material = Material.REDSTONE_TORCH_OFF;
|
||||||
}
|
} else if (materialString.equals("redstone torch (on)")) {
|
||||||
else if (materialString.equals("redstone torch (on)")) {
|
|
||||||
material.material = Material.REDSTONE_TORCH_ON;
|
material.material = Material.REDSTONE_TORCH_ON;
|
||||||
}
|
} else if (materialString.equals("fence")) {
|
||||||
else if (materialString.equals("fence")) {
|
|
||||||
material.material = Material.FENCE;
|
material.material = Material.FENCE;
|
||||||
}
|
} else if (materialString.equals("nether portal")) {
|
||||||
else if (materialString.equals("nether portal")) {
|
|
||||||
material.material = Material.PORTAL;
|
material.material = Material.PORTAL;
|
||||||
}
|
} else if (materialString.equals("iron bars")) {
|
||||||
else if (materialString.equals("iron bars")) {
|
|
||||||
material.material = Material.IRON_FENCE;
|
material.material = Material.IRON_FENCE;
|
||||||
}
|
} else if (materialString.equals("glass pane")) {
|
||||||
else if (materialString.equals("glass pane")) {
|
|
||||||
material.material = Material.THIN_GLASS;
|
material.material = Material.THIN_GLASS;
|
||||||
}
|
} else if (materialString.equals("fence gate")) {
|
||||||
else if (materialString.equals("fence gate")) {
|
|
||||||
material.material = Material.FENCE_GATE;
|
material.material = Material.FENCE_GATE;
|
||||||
}
|
} else if (materialString.equals("nether brick fence")) {
|
||||||
else if (materialString.equals("nether brick fence")) {
|
|
||||||
material.material = Material.NETHER_FENCE;
|
material.material = Material.NETHER_FENCE;
|
||||||
}
|
} else if (materialString.equals("nether wart")) {
|
||||||
else if (materialString.equals("nether wart")) {
|
|
||||||
material.material = Material.NETHER_WARTS;
|
material.material = Material.NETHER_WARTS;
|
||||||
}
|
} else if (materialString.equals("end portal")) {
|
||||||
else if (materialString.equals("end portal")) {
|
|
||||||
material.material = Material.ENDER_PORTAL;
|
material.material = Material.ENDER_PORTAL;
|
||||||
}
|
} else if (materialString.equals("cobblestone wall")) {
|
||||||
else if (materialString.equals("cobblestone wall")) {
|
|
||||||
material.material = Material.COBBLE_WALL;
|
material.material = Material.COBBLE_WALL;
|
||||||
}
|
} else { // fallback!
|
||||||
else { // 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!");
|
||||||
}
|
}
|
||||||
@ -120,8 +96,7 @@ public class ConfigurationUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class GateMaterial
|
class GateMaterial {
|
||||||
{
|
|
||||||
public Material material = Material.PORTAL;
|
public Material material = Material.PORTAL;
|
||||||
public byte data = 0;
|
public byte data = 0;
|
||||||
}
|
}
|
||||||
|
@ -28,32 +28,30 @@ import org.bukkit.block.BlockFace;
|
|||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class FloodUtil
|
public class FloodUtil {
|
||||||
{
|
protected static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
|
||||||
protected static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
|
|
||||||
protected static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
|
protected static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
|
||||||
|
|
||||||
static
|
static {
|
||||||
{
|
exp1.add(BlockFace.UP);
|
||||||
exp1.add(BlockFace.UP);
|
exp1.add(BlockFace.DOWN);
|
||||||
exp1.add(BlockFace.DOWN);
|
exp1.add(BlockFace.EAST);
|
||||||
exp1.add(BlockFace.EAST);
|
exp1.add(BlockFace.WEST);
|
||||||
exp1.add(BlockFace.WEST);
|
|
||||||
|
exp2.add(BlockFace.UP);
|
||||||
exp2.add(BlockFace.UP);
|
exp2.add(BlockFace.DOWN);
|
||||||
exp2.add(BlockFace.DOWN);
|
exp2.add(BlockFace.NORTH);
|
||||||
exp2.add(BlockFace.NORTH);
|
exp2.add(BlockFace.SOUTH);
|
||||||
exp2.add(BlockFace.SOUTH);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the all frame blocks of an gate.
|
* Returns the all frame blocks of an gate.
|
||||||
|
*
|
||||||
* @param blocks All blocks inside the gate.
|
* @param blocks All blocks inside the gate.
|
||||||
* @return A Set containing all frame block. Will never return 'null'.
|
* @return A Set containing all frame block. Will never return 'null'.
|
||||||
*/
|
*/
|
||||||
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<Block>();
|
||||||
}
|
}
|
||||||
@ -64,7 +62,7 @@ public class FloodUtil
|
|||||||
for (Block b : blocks) {
|
for (Block b : blocks) {
|
||||||
|
|
||||||
if (blocks.contains(b.getRelative(BlockFace.EAST)) ||
|
if (blocks.contains(b.getRelative(BlockFace.EAST)) ||
|
||||||
blocks.contains(b.getRelative(BlockFace.WEST))) {
|
blocks.contains(b.getRelative(BlockFace.WEST))) {
|
||||||
|
|
||||||
gateFrameSearchFaces = exp1;
|
gateFrameSearchFaces = exp1;
|
||||||
break;
|
break;
|
||||||
@ -81,8 +79,7 @@ public class FloodUtil
|
|||||||
|
|
||||||
if (gateFrameSearchFaces != null) {
|
if (gateFrameSearchFaces != null) {
|
||||||
return _getFrame(blocks, gateFrameSearchFaces);
|
return _getFrame(blocks, gateFrameSearchFaces);
|
||||||
}
|
} else { // no direction found (the gate might only consist of blocks one over another)
|
||||||
else { // no direction found (the gate might only consist of blocks one over another)
|
|
||||||
|
|
||||||
// Try one direction and check if the found blocks are not air.
|
// Try one direction and check if the found blocks are not air.
|
||||||
// If air is found (frame broken or wrong direction) return the other direction
|
// If air is found (frame broken or wrong direction) return the other direction
|
||||||
@ -100,9 +97,7 @@ public class FloodUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static Set<Block> _getFrame(final Set<Block> blocks, final Set<BlockFace> searchDirections) {
|
||||||
protected static Set<Block> _getFrame(final Set<Block> blocks, final Set<BlockFace> searchDirections)
|
|
||||||
{
|
|
||||||
Set<Block> frameBlocks = new HashSet<Block>();
|
Set<Block> frameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
for (Block b : blocks) {
|
for (Block b : blocks) {
|
||||||
@ -122,11 +117,11 @@ public class FloodUtil
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the all frame blocks of an gate.
|
* Returns the all frame blocks of an gate.
|
||||||
|
*
|
||||||
* @param locations All locations inside the gate.
|
* @param locations All locations inside the gate.
|
||||||
* @return A Set containing all frame block. Will never return 'null'.
|
* @return A Set containing all frame block. Will never return 'null'.
|
||||||
*/
|
*/
|
||||||
public static Set<Block> getFrameWithLocations(final Set<Location> locations)
|
public static Set<Block> getFrameWithLocations(final Set<Location> locations) {
|
||||||
{
|
|
||||||
if (locations == null) {
|
if (locations == null) {
|
||||||
throw new IllegalArgumentException("'locations' must not be 'null'");
|
throw new IllegalArgumentException("'locations' must not be 'null'");
|
||||||
}
|
}
|
||||||
@ -140,10 +135,9 @@ public class FloodUtil
|
|||||||
return getFrame(blocks);
|
return getFrame(blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// For the same frame and location this set of blocks is deterministic
|
// For the same frame and location this set of blocks is deterministic
|
||||||
public static Set<Block> getGatePortalBlocks(final Block block)
|
public static Set<Block> getGatePortalBlocks(final Block block) {
|
||||||
{
|
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
throw new IllegalArgumentException("'block' must not be 'null'");
|
throw new IllegalArgumentException("'block' must not be 'null'");
|
||||||
}
|
}
|
||||||
@ -151,57 +145,56 @@ public class FloodUtil
|
|||||||
int frameBlockSearchLimit = Plugin.getPlugin().getConfig().getInt(ConfigurationUtil.confMaxGateBlocksKey);
|
int frameBlockSearchLimit = Plugin.getPlugin().getConfig().getInt(ConfigurationUtil.confMaxGateBlocksKey);
|
||||||
|
|
||||||
Set<Block> blocks1 = getAirFloodBlocks(block, new HashSet<Block>(), exp1, frameBlockSearchLimit);
|
Set<Block> blocks1 = getAirFloodBlocks(block, new HashSet<Block>(), exp1, frameBlockSearchLimit);
|
||||||
Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, frameBlockSearchLimit);
|
Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, frameBlockSearchLimit);
|
||||||
|
|
||||||
if (blocks1 == null && blocks2 == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blocks1 == null) {
|
|
||||||
return blocks2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blocks2 == null) {
|
|
||||||
return blocks1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blocks1.size() > blocks2.size()) {
|
|
||||||
return blocks2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return blocks1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (blocks1 == null && blocks2 == null) {
|
||||||
protected static Set<Block> getAirFloodBlocks(final Block startBlock,
|
return null;
|
||||||
Set<Block> foundBlocks,
|
|
||||||
final Set<BlockFace> expandFaces,
|
|
||||||
int limit)
|
|
||||||
{
|
|
||||||
if (foundBlocks == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundBlocks.size() > limit) {
|
|
||||||
Plugin.log(Level.ALL, "exceeding gate size limit.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundBlocks.contains(startBlock)) {
|
|
||||||
return foundBlocks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startBlock.getType() == Material.AIR) {
|
if (blocks1 == null) {
|
||||||
// ... We found a block :D ...
|
return blocks2;
|
||||||
foundBlocks.add(startBlock);
|
}
|
||||||
|
|
||||||
// ... And flood away !
|
if (blocks2 == null) {
|
||||||
for (BlockFace face : expandFaces) {
|
return blocks1;
|
||||||
Block potentialBlock = startBlock.getRelative(face);
|
}
|
||||||
foundBlocks = getAirFloodBlocks(potentialBlock, foundBlocks, expandFaces, limit);
|
|
||||||
}
|
if (blocks1.size() > blocks2.size()) {
|
||||||
}
|
return blocks2;
|
||||||
|
}
|
||||||
return foundBlocks;
|
|
||||||
}
|
return blocks1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static Set<Block> getAirFloodBlocks(final Block startBlock,
|
||||||
|
Set<Block> foundBlocks,
|
||||||
|
final Set<BlockFace> expandFaces,
|
||||||
|
int limit) {
|
||||||
|
if (foundBlocks == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundBlocks.size() > limit) {
|
||||||
|
Plugin.log(Level.ALL, "exceeding gate size limit.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundBlocks.contains(startBlock)) {
|
||||||
|
return foundBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startBlock.getType() == Material.AIR) {
|
||||||
|
// ... We found a block :D ...
|
||||||
|
foundBlocks.add(startBlock);
|
||||||
|
|
||||||
|
// ... And flood away !
|
||||||
|
for (BlockFace face : expandFaces) {
|
||||||
|
Block potentialBlock = startBlock.getRelative(face);
|
||||||
|
foundBlocks = getAirFloodBlocks(potentialBlock, foundBlocks, expandFaces, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundBlocks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,17 +32,16 @@ import java.util.Set;
|
|||||||
import static de.craftinc.gates.util.ConfigurationUtil.*;
|
import static de.craftinc.gates.util.ConfigurationUtil.*;
|
||||||
|
|
||||||
|
|
||||||
public class GateBlockChangeSender
|
public class GateBlockChangeSender {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Replaces gate frame blocks with glowstone for a short period of time.
|
* Replaces gate frame blocks with glowstone for a short period of time.
|
||||||
* Uses the data stored in 'highlightDuration' inside the config file
|
* Uses the data stored in 'highlightDuration' inside the config file
|
||||||
* for determining when to de-highlight the frames.
|
* for determining when to de-highlight the frames.
|
||||||
|
*
|
||||||
* @param player The player for whom the frame should be highlighted.
|
* @param player The player for whom the frame should be highlighted.
|
||||||
* Must not be null!
|
* Must not be null!
|
||||||
*/
|
*/
|
||||||
public static void temporaryHighlightGatesFrames(final Player player, final Set<Gate> gates)
|
public static void temporaryHighlightGatesFrames(final Player player, final Set<Gate> gates) {
|
||||||
{
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
throw new IllegalArgumentException("'player' must not be 'null'!");
|
throw new IllegalArgumentException("'player' must not be 'null'!");
|
||||||
}
|
}
|
||||||
@ -55,7 +54,7 @@ public class GateBlockChangeSender
|
|||||||
Set<Block> frameBlocks = g.getGateFrameBlocks();
|
Set<Block> frameBlocks = g.getGateFrameBlocks();
|
||||||
|
|
||||||
for (Block b : frameBlocks) {
|
for (Block b : frameBlocks) {
|
||||||
player.sendBlockChange(b.getLocation(), Material.GLOWSTONE, (byte)0);
|
player.sendBlockChange(b.getLocation(), Material.GLOWSTONE, (byte) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,8 +70,7 @@ public class GateBlockChangeSender
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void temporaryHighlightGateFrame(final Player player, final Gate gate)
|
public static void temporaryHighlightGateFrame(final Player player, final Gate gate) {
|
||||||
{
|
|
||||||
if (gate == null) {
|
if (gate == null) {
|
||||||
throw new IllegalArgumentException("'gate' must not be 'null!");
|
throw new IllegalArgumentException("'gate' must not be 'null!");
|
||||||
}
|
}
|
||||||
@ -84,7 +82,7 @@ public class GateBlockChangeSender
|
|||||||
Set<Block> frameBlocks = gate.getGateFrameBlocks();
|
Set<Block> frameBlocks = gate.getGateFrameBlocks();
|
||||||
|
|
||||||
for (Block b : frameBlocks) {
|
for (Block b : frameBlocks) {
|
||||||
player.sendBlockChange(b.getLocation(), Material.GLOWSTONE, (byte)0);
|
player.sendBlockChange(b.getLocation(), Material.GLOWSTONE, (byte) 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin plugin = Plugin.getPlugin();
|
Plugin plugin = Plugin.getPlugin();
|
||||||
@ -99,24 +97,22 @@ public class GateBlockChangeSender
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static void dehighlightGatesFrames(final Player player, final Set<Gate> gates)
|
protected 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();
|
||||||
|
|
||||||
for (Block b : frameBlocks) {
|
for (Block b : frameBlocks) {
|
||||||
player.sendBlockChange(b.getLocation(), b.getType(), (byte)0);
|
player.sendBlockChange(b.getLocation(), b.getType(), (byte) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static void dehighlightGateFrame(final Player player, final Gate gate)
|
protected 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) {
|
||||||
player.sendBlockChange(b.getLocation(), b.getType(), (byte)0);
|
player.sendBlockChange(b.getLocation(), b.getType(), (byte) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,13 +120,13 @@ public class GateBlockChangeSender
|
|||||||
/**
|
/**
|
||||||
* Sends gate blocks to player at a given location. Will send the updates either immediately or
|
* Sends gate blocks to player at a given location. Will send the updates either immediately or
|
||||||
* immediately and after a short delay.
|
* immediately and after a short delay.
|
||||||
|
*
|
||||||
* @param player A player to send block changes to. Must not be null!
|
* @param player A player to send block changes to. Must not be null!
|
||||||
* @param location The location to look for gates nearby. Must not be null!
|
* @param location The location to look for gates nearby. Must not be null!
|
||||||
* @param sendDelayed Set to 'true' if the block changes shall be send a second time after a one
|
* @param sendDelayed Set to 'true' if the block changes shall be send a second time after a one
|
||||||
* second delay.
|
* second delay.
|
||||||
*/
|
*/
|
||||||
public static void updateGateBlocks(final Player player, final Location location, boolean sendDelayed)
|
public static void updateGateBlocks(final Player player, final Location location, boolean sendDelayed) {
|
||||||
{
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
throw new IllegalArgumentException("'player' must not be 'null'!");
|
throw new IllegalArgumentException("'player' must not be 'null'!");
|
||||||
}
|
}
|
||||||
@ -161,11 +157,9 @@ public class GateBlockChangeSender
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sendDelayed) {
|
if (sendDelayed) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.getPlugin(), new Runnable()
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.getPlugin(), new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
updateGateBlocks(player, location, false);
|
updateGateBlocks(player, location, false);
|
||||||
}
|
}
|
||||||
}, 20L);
|
}, 20L);
|
||||||
@ -176,16 +170,14 @@ public class GateBlockChangeSender
|
|||||||
/**
|
/**
|
||||||
* This method calls: updateGateBlocks(player, location, false);
|
* This method calls: updateGateBlocks(player, location, false);
|
||||||
*/
|
*/
|
||||||
public static void updateGateBlocks(final Player player, final Location location)
|
public static void updateGateBlocks(final Player player, final Location location) {
|
||||||
{
|
|
||||||
updateGateBlocks(player, location, false);
|
updateGateBlocks(player, location, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method calls: updateGateBlocks(player, player.getLocation(), false);
|
* This method calls: updateGateBlocks(player, player.getLocation(), false);
|
||||||
*/
|
*/
|
||||||
public static void updateGateBlocks(final Player player)
|
public static void updateGateBlocks(final Player player) {
|
||||||
{
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
throw new IllegalArgumentException("'player' must not be 'null'!");
|
throw new IllegalArgumentException("'player' must not be 'null'!");
|
||||||
}
|
}
|
||||||
@ -194,18 +186,17 @@ public class GateBlockChangeSender
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void updateGateBlocks(final Gate gate)
|
public static void updateGateBlocks(final Gate gate) {
|
||||||
{
|
|
||||||
updateGateBlocks(gate, false);
|
updateGateBlocks(gate, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends block changes to players near a given gate.
|
* Sends block changes to players near a given gate.
|
||||||
* @param gate Must not be 'null'!
|
*
|
||||||
|
* @param gate Must not be 'null'!
|
||||||
* @param remove Set to true if all visible gate blocks shall be removed.
|
* @param remove Set to true if all visible gate blocks shall be removed.
|
||||||
*/
|
*/
|
||||||
public static void updateGateBlocks(final Gate gate, boolean remove)
|
public static void updateGateBlocks(final Gate gate, boolean remove) {
|
||||||
{
|
|
||||||
if (gate == null) {
|
if (gate == null) {
|
||||||
throw new IllegalArgumentException("'gate must not be 'null'!");
|
throw new IllegalArgumentException("'gate must not be 'null'!");
|
||||||
}
|
}
|
||||||
@ -234,8 +225,7 @@ public class GateBlockChangeSender
|
|||||||
if (gate.isOpen() && !gate.isHidden() && !remove) {
|
if (gate.isOpen() && !gate.isHidden() && !remove) {
|
||||||
material = gateMaterial.material;
|
material = gateMaterial.material;
|
||||||
data = gateMaterial.data;
|
data = gateMaterial.data;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
material = Material.AIR;
|
material = Material.AIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,61 +19,55 @@ package de.craftinc.gates.util;
|
|||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
public class SimpleChunk
|
public class SimpleChunk {
|
||||||
{
|
private int x;
|
||||||
private int x;
|
private int z;
|
||||||
private int z;
|
private String world;
|
||||||
private String world;
|
|
||||||
|
public SimpleChunk(Chunk c) {
|
||||||
public SimpleChunk(Chunk c)
|
this.x = c.getX();
|
||||||
{
|
this.z = c.getZ();
|
||||||
this.x = c.getX();
|
this.world = c.getWorld().getName();
|
||||||
this.z = c.getZ();
|
}
|
||||||
this.world = c.getWorld().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public SimpleChunk(int x, int z, World w)
|
public SimpleChunk(int x, int z, World w) {
|
||||||
{
|
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.world = w.getName();
|
this.world = w.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (o instanceof SimpleChunk) {
|
|
||||||
SimpleChunk otherLocation = (SimpleChunk)o;
|
|
||||||
|
|
||||||
if (otherLocation.x == this.x
|
|
||||||
&& otherLocation.z == this.z
|
|
||||||
&& otherLocation.world.equals(this.world)) {
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public boolean equals(Object o) {
|
||||||
{
|
if (o instanceof SimpleChunk) {
|
||||||
int hash = 11;
|
SimpleChunk otherLocation = (SimpleChunk) o;
|
||||||
hash = 29 * hash + x;
|
|
||||||
hash = 37 * hash + z;
|
if (otherLocation.x == this.x
|
||||||
hash = 29 * hash + world.hashCode();
|
&& otherLocation.z == this.z
|
||||||
|
&& otherLocation.world.equals(this.world)) {
|
||||||
return hash;
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public int hashCode() {
|
||||||
{
|
int hash = 11;
|
||||||
|
hash = 29 * hash + x;
|
||||||
|
hash = 37 * hash + z;
|
||||||
|
hash = 29 * hash + world.hashCode();
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
return this.getClass().toString() + " (x=" + this.x + " z=" + this.z + " world='" + this.world + "')";
|
return this.getClass().toString() + " (x=" + this.x + " z=" + this.z + " world='" + this.world + "')";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,28 +18,25 @@ package de.craftinc.gates.util;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public class SimpleLocation
|
public class SimpleLocation {
|
||||||
{
|
private String world;
|
||||||
private String world;
|
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
|
|
||||||
|
|
||||||
public SimpleLocation(Location l)
|
public SimpleLocation(Location l) {
|
||||||
{
|
this.world = l.getWorld().getName();
|
||||||
this.world = l.getWorld().getName();
|
|
||||||
|
|
||||||
// Using Block coordinates makes it possible to compare block locations with player locations.
|
// Using Block coordinates makes it possible to compare block locations with player locations.
|
||||||
// There might be an offset of 1 otherwise.
|
// There might be an offset of 1 otherwise.
|
||||||
this.x = l.getBlockX();
|
this.x = l.getBlockX();
|
||||||
this.y = l.getBlockY();
|
this.y = l.getBlockY();
|
||||||
this.z = l.getBlockZ();
|
this.z = l.getBlockZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SimpleLocation(Location l, boolean isHeadPosition)
|
public SimpleLocation(Location l, boolean isHeadPosition) {
|
||||||
{
|
|
||||||
this.world = l.getWorld().getName();
|
this.world = l.getWorld().getName();
|
||||||
|
|
||||||
// Using Block coordinates makes it possible to compare block locations with player locations.
|
// Using Block coordinates makes it possible to compare block locations with player locations.
|
||||||
@ -55,41 +52,37 @@ public class SimpleLocation
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return super.toString() + " x: " + x + " y: " + y + " z: " + z + " world: " + world;
|
return super.toString() + " x: " + x + " y: " + y + " z: " + z + " world: " + world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object o)
|
public boolean equals(final Object o) {
|
||||||
{
|
if (o instanceof SimpleLocation) {
|
||||||
if (o instanceof SimpleLocation) {
|
SimpleLocation otherLocation = (SimpleLocation) o;
|
||||||
SimpleLocation otherLocation = (SimpleLocation)o;
|
|
||||||
|
if (otherLocation.x == this.x
|
||||||
if (otherLocation.x == this.x
|
&& otherLocation.y == this.y
|
||||||
&& otherLocation.y == this.y
|
&& otherLocation.z == this.z
|
||||||
&& otherLocation.z == this.z
|
&& otherLocation.world.equals(this.world)) {
|
||||||
&& otherLocation.world.equals(this.world)) {
|
|
||||||
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode() {
|
||||||
{
|
int hash = 13;
|
||||||
int hash = 13;
|
hash = 37 * hash + x;
|
||||||
hash = 37 * hash + x;
|
hash = 31 * hash + y;
|
||||||
hash = 31 * hash + y;
|
hash = 37 * hash + z;
|
||||||
hash = 37 * hash + z;
|
hash = 31 * hash + world.hashCode();
|
||||||
hash = 31 * hash + world.hashCode();
|
|
||||||
|
return hash;
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,16 +20,13 @@ 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 titleize(String str)
|
String center = ".[ " + ChatColor.YELLOW + str + ChatColor.GOLD + " ].";
|
||||||
{
|
|
||||||
String center = ".[ " + ChatColor.YELLOW + str + ChatColor.GOLD + " ].";
|
|
||||||
|
|
||||||
if (center.length() >= 60) {
|
if (center.length() >= 60) {
|
||||||
return ChatColor.GOLD + center;
|
return ChatColor.GOLD + center;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
String line = ChatColor.GOLD + repeat("_", 60);
|
String line = ChatColor.GOLD + repeat("_", 60);
|
||||||
|
|
||||||
int pivot = line.length() / 2;
|
int pivot = line.length() / 2;
|
||||||
@ -38,35 +35,33 @@ public class TextUtil
|
|||||||
|
|
||||||
return line.substring(0, pivot - eatLeft) + center + line.substring(pivot + eatRight);
|
return line.substring(0, pivot - eatLeft) + center + line.substring(pivot + eatRight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String repeat(String s, int times)
|
public static String repeat(String s, int times) {
|
||||||
{
|
if (times <= 0)
|
||||||
if (times <= 0)
|
return "";
|
||||||
return "";
|
|
||||||
|
return s + repeat(s, times - 1);
|
||||||
return s + repeat(s, times-1);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* Joins all elements of list into a single string, separating the original strings with glue.
|
||||||
* Joins all elements of list into a single string, separating the original strings with glue.
|
*/
|
||||||
*/
|
public static String implode(List<String> list, String glue) {
|
||||||
public static String implode(List<String> list, String glue)
|
if (list.size() == 0) {
|
||||||
{
|
return "";
|
||||||
if (list.size() == 0) {
|
}
|
||||||
return "";
|
|
||||||
}
|
String ret = list.get(0);
|
||||||
|
|
||||||
String ret = list.get(0);
|
for (int i = 1; i < list.size(); i++) {
|
||||||
|
ret += glue + list.get(i);
|
||||||
for (int i=1; i<list.size(); i++) {
|
}
|
||||||
ret += glue + list.get(i);
|
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,10 +20,8 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.*;
|
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());
|
||||||
|
|
||||||
clone.setFallDistance(parent.getFallDistance());
|
clone.setFallDistance(parent.getFallDistance());
|
||||||
@ -33,18 +31,17 @@ public class VehicleCloner
|
|||||||
clone.setLastDamageCause(parent.getLastDamageCause());
|
clone.setLastDamageCause(parent.getLastDamageCause());
|
||||||
|
|
||||||
if (clone instanceof Boat) {
|
if (clone instanceof Boat) {
|
||||||
Boat boat = (Boat)clone;
|
Boat boat = (Boat) clone;
|
||||||
Boat parentBoat = (Boat)parent;
|
Boat parentBoat = (Boat) parent;
|
||||||
|
|
||||||
boat.setMaxSpeed(parentBoat.getMaxSpeed());
|
boat.setMaxSpeed(parentBoat.getMaxSpeed());
|
||||||
boat.setOccupiedDeceleration(parentBoat.getOccupiedDeceleration());
|
boat.setOccupiedDeceleration(parentBoat.getOccupiedDeceleration());
|
||||||
boat.setUnoccupiedDeceleration(parentBoat.getUnoccupiedDeceleration());
|
boat.setUnoccupiedDeceleration(parentBoat.getUnoccupiedDeceleration());
|
||||||
boat.setWorkOnLand(parentBoat.getWorkOnLand());
|
boat.setWorkOnLand(parentBoat.getWorkOnLand());
|
||||||
boat.setVelocity(parentBoat.getVelocity());
|
boat.setVelocity(parentBoat.getVelocity());
|
||||||
}
|
} else if (clone instanceof Animals) {
|
||||||
else if (clone instanceof Animals) {
|
Animals animal = (Animals) clone;
|
||||||
Animals animal = (Animals)clone;
|
Animals parentAnimal = (Animals) parent;
|
||||||
Animals parentAnimal = (Animals)parent;
|
|
||||||
|
|
||||||
animal.setMaxHealth(parentAnimal.getMaxHealth());
|
animal.setMaxHealth(parentAnimal.getMaxHealth());
|
||||||
animal.setHealth(parentAnimal.getMaxHealth());
|
animal.setHealth(parentAnimal.getMaxHealth());
|
||||||
@ -63,8 +60,8 @@ public class VehicleCloner
|
|||||||
animal.setAgeLock(parentAnimal.getAgeLock());
|
animal.setAgeLock(parentAnimal.getAgeLock());
|
||||||
|
|
||||||
if (clone instanceof Horse) {
|
if (clone instanceof Horse) {
|
||||||
Horse horse = (Horse)clone;
|
Horse horse = (Horse) clone;
|
||||||
Horse parentHorse = (Horse)parent;
|
Horse parentHorse = (Horse) parent;
|
||||||
|
|
||||||
horse.getInventory().setArmor(parentHorse.getInventory().getArmor());
|
horse.getInventory().setArmor(parentHorse.getInventory().getArmor());
|
||||||
horse.getInventory().setSaddle(parentHorse.getInventory().getSaddle());
|
horse.getInventory().setSaddle(parentHorse.getInventory().getSaddle());
|
||||||
@ -81,23 +78,20 @@ public class VehicleCloner
|
|||||||
|
|
||||||
if (parentHorse.isAdult()) {
|
if (parentHorse.isAdult()) {
|
||||||
horse.setAdult();
|
horse.setAdult();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
horse.setBaby();
|
horse.setBaby();
|
||||||
}
|
}
|
||||||
|
|
||||||
horse.setBreed(parentHorse.canBreed());
|
horse.setBreed(parentHorse.canBreed());
|
||||||
}
|
} else if (clone instanceof Pig) {
|
||||||
else if (clone instanceof Pig) {
|
Pig pig = (Pig) clone;
|
||||||
Pig pig = (Pig)clone;
|
Pig parentPig = (Pig) parent;
|
||||||
Pig parentPig = (Pig)parent;
|
|
||||||
|
|
||||||
pig.setSaddle(parentPig.hasSaddle());
|
pig.setSaddle(parentPig.hasSaddle());
|
||||||
}
|
}
|
||||||
}
|
} else if (clone instanceof Minecart) {
|
||||||
else if (clone instanceof Minecart) {
|
Minecart minecart = (Minecart) clone;
|
||||||
Minecart minecart = (Minecart)clone;
|
Minecart parentMinecart = (Minecart) parent;
|
||||||
Minecart parentMinecart = (Minecart)parent;
|
|
||||||
|
|
||||||
minecart.setDerailedVelocityMod(parentMinecart.getDerailedVelocityMod());
|
minecart.setDerailedVelocityMod(parentMinecart.getDerailedVelocityMod());
|
||||||
minecart.setFlyingVelocityMod(parentMinecart.getFlyingVelocityMod());
|
minecart.setFlyingVelocityMod(parentMinecart.getFlyingVelocityMod());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user