Reformat
This commit is contained in:
parent
5066934a95
commit
8a6a97cc90
@ -46,23 +46,28 @@ public class Board {
|
||||
}
|
||||
|
||||
public static void removeAt(FLocation flocation) {
|
||||
clearOwnershipAt(flocation); flocationIds.remove(flocation);
|
||||
clearOwnershipAt(flocation);
|
||||
flocationIds.remove(flocation);
|
||||
}
|
||||
|
||||
// not to be confused with claims, ownership referring to further member-specific ownership of a claim
|
||||
public static void clearOwnershipAt(FLocation flocation) {
|
||||
Faction faction = getFactionAt(flocation); if (faction != null && faction.isNormal()) {
|
||||
Faction faction = getFactionAt(flocation);
|
||||
if (faction != null && faction.isNormal()) {
|
||||
faction.clearClaimOwnership(flocation);
|
||||
}
|
||||
}
|
||||
|
||||
public static void unclaimAll(String factionId) {
|
||||
Faction faction = Factions.i.get(factionId); if (faction != null && faction.isNormal()) {
|
||||
Faction faction = Factions.i.get(factionId);
|
||||
if (faction != null && faction.isNormal()) {
|
||||
faction.clearAllClaimOwnership();
|
||||
}
|
||||
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator(); while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next(); if (entry.getValue().equals(factionId)) {
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next();
|
||||
if (entry.getValue().equals(factionId)) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
@ -71,16 +76,20 @@ public class Board {
|
||||
// Is this coord NOT completely surrounded by coords claimed by the same faction?
|
||||
// Simpler: Is there any nearby coord with a faction other than the faction here?
|
||||
public static boolean isBorderLocation(FLocation flocation) {
|
||||
Faction faction = getFactionAt(flocation); FLocation a = flocation.getRelative(1, 0);
|
||||
FLocation b = flocation.getRelative(-1, 0); FLocation c = flocation.getRelative(0, 1);
|
||||
Faction faction = getFactionAt(flocation);
|
||||
FLocation a = flocation.getRelative(1, 0);
|
||||
FLocation b = flocation.getRelative(-1, 0);
|
||||
FLocation c = flocation.getRelative(0, 1);
|
||||
FLocation d = flocation.getRelative(0, -1);
|
||||
return faction != getFactionAt(a) || faction != getFactionAt(b) || faction != getFactionAt(c) || faction != getFactionAt(d);
|
||||
}
|
||||
|
||||
// Is this coord connected to any coord claimed by the specified faction?
|
||||
public static boolean isConnectedLocation(FLocation flocation, Faction faction) {
|
||||
FLocation a = flocation.getRelative(1, 0); FLocation b = flocation.getRelative(-1, 0);
|
||||
FLocation c = flocation.getRelative(0, 1); FLocation d = flocation.getRelative(0, -1);
|
||||
FLocation a = flocation.getRelative(1, 0);
|
||||
FLocation b = flocation.getRelative(-1, 0);
|
||||
FLocation c = flocation.getRelative(0, 1);
|
||||
FLocation d = flocation.getRelative(0, -1);
|
||||
return faction == getFactionAt(a) || faction == getFactionAt(b) || faction == getFactionAt(c) || faction == getFactionAt(d);
|
||||
}
|
||||
|
||||
@ -90,9 +99,12 @@ public class Board {
|
||||
//----------------------------------------------//
|
||||
|
||||
public static void clean() {
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator(); while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next(); if (!Factions.i.exists(entry.getValue())) {
|
||||
P.p.log("Board cleaner removed " + entry.getValue() + " from " + entry.getKey()); iter.remove();
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next();
|
||||
if (!Factions.i.exists(entry.getValue())) {
|
||||
P.p.log("Board cleaner removed " + entry.getValue() + " from " + entry.getKey());
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,11 +114,13 @@ public class Board {
|
||||
//----------------------------------------------//
|
||||
|
||||
public static int getFactionCoordCount(String factionId) {
|
||||
int ret = 0; for (String thatFactionId : flocationIds.values()) {
|
||||
int ret = 0;
|
||||
for (String thatFactionId : flocationIds.values()) {
|
||||
if (thatFactionId.equals(factionId)) {
|
||||
ret += 1;
|
||||
}
|
||||
} return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int getFactionCoordCount(Faction faction) {
|
||||
@ -114,13 +128,16 @@ public class Board {
|
||||
}
|
||||
|
||||
public static int getFactionCoordCountInWorld(Faction faction, String worldName) {
|
||||
String factionId = faction.getId(); int ret = 0;
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator(); while (iter.hasNext()) {
|
||||
String factionId = faction.getId();
|
||||
int ret = 0;
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next();
|
||||
if (entry.getValue().equals(factionId) && entry.getKey().getWorldName().equals(worldName)) {
|
||||
ret += 1;
|
||||
}
|
||||
} return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
@ -132,29 +149,35 @@ public class Board {
|
||||
* of decreasing z
|
||||
*/
|
||||
public static ArrayList<String> getMap(Faction faction, FLocation flocation, double inDegrees) {
|
||||
ArrayList<String> ret = new ArrayList<String>(); Faction factionLoc = getFactionAt(flocation);
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
Faction factionLoc = getFactionAt(flocation);
|
||||
ret.add(P.p.txt.titleize("(" + flocation.getCoordString() + ") " + factionLoc.getTag(faction)));
|
||||
|
||||
int halfWidth = Conf.mapWidth / 2; int halfHeight = Conf.mapHeight / 2;
|
||||
FLocation topLeft = flocation.getRelative(-halfWidth, -halfHeight); int width = halfWidth * 2 + 1;
|
||||
int halfWidth = Conf.mapWidth / 2;
|
||||
int halfHeight = Conf.mapHeight / 2;
|
||||
FLocation topLeft = flocation.getRelative(-halfWidth, -halfHeight);
|
||||
int width = halfWidth * 2 + 1;
|
||||
int height = halfHeight * 2 + 1;
|
||||
|
||||
if (Conf.showMapFactionKey) {
|
||||
height--;
|
||||
}
|
||||
|
||||
Map<String, Character> fList = new HashMap<String, Character>(); int chrIdx = 0;
|
||||
Map<String, Character> fList = new HashMap<String, Character>();
|
||||
int chrIdx = 0;
|
||||
|
||||
// For each row
|
||||
for (int dz = 0; dz < height; dz++) {
|
||||
// Draw and add that row
|
||||
String row = ""; for (int dx = 0; dx < width; dx++) {
|
||||
String row = "";
|
||||
for (int dx = 0; dx < width; dx++) {
|
||||
if (dx == halfWidth && dz == halfHeight) {
|
||||
row += ChatColor.AQUA + "+";
|
||||
} else {
|
||||
FLocation flocationHere = topLeft.getRelative(dx, dz);
|
||||
Faction factionHere = getFactionAt(flocationHere);
|
||||
Relation relation = faction.getRelationTo(factionHere); if (factionHere.isNone()) {
|
||||
Relation relation = faction.getRelationTo(factionHere);
|
||||
if (factionHere.isNone()) {
|
||||
row += ChatColor.GRAY + "-";
|
||||
} else if (factionHere.isSafeZone()) {
|
||||
row += Conf.colorPeaceful + "+";
|
||||
@ -167,12 +190,15 @@ public class Board {
|
||||
(Conf.showEnemyFactionsOnMap && relation.equals(Relation.ENEMY))) {
|
||||
if (!fList.containsKey(factionHere.getTag())) {
|
||||
fList.put(factionHere.getTag(), Conf.mapKeyChrs[chrIdx++]);
|
||||
} char tag = fList.get(factionHere.getTag()); row += factionHere.getColorTo(faction) + "" + tag;
|
||||
}
|
||||
char tag = fList.get(factionHere.getTag());
|
||||
row += factionHere.getColorTo(faction) + "" + tag;
|
||||
} else {
|
||||
row += ChatColor.GRAY + "-";
|
||||
}
|
||||
}
|
||||
} ret.add(row);
|
||||
}
|
||||
ret.add(row);
|
||||
}
|
||||
|
||||
// Get the compass
|
||||
@ -185,9 +211,11 @@ public class Board {
|
||||
|
||||
// Add the faction key
|
||||
if (Conf.showMapFactionKey) {
|
||||
String fRow = ""; for (String key : fList.keySet()) {
|
||||
String fRow = "";
|
||||
for (String key : fList.keySet()) {
|
||||
fRow += String.format("%s%s: %s ", ChatColor.GRAY, fList.get(key), key);
|
||||
} ret.add(fRow);
|
||||
}
|
||||
ret.add(fRow);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -201,10 +229,13 @@ public class Board {
|
||||
public static Map<String, Map<String, String>> dumpAsSaveFormat() {
|
||||
Map<String, Map<String, String>> worldCoordIds = new HashMap<String, Map<String, String>>();
|
||||
|
||||
String worldName, coords; String id;
|
||||
String worldName, coords;
|
||||
String id;
|
||||
|
||||
for (Entry<FLocation, String> entry : flocationIds.entrySet()) {
|
||||
worldName = entry.getKey().getWorldName(); coords = entry.getKey().getCoordString(); id = entry.getValue();
|
||||
worldName = entry.getKey().getWorldName();
|
||||
coords = entry.getKey().getCoordString();
|
||||
id = entry.getValue();
|
||||
if (!worldCoordIds.containsKey(worldName)) {
|
||||
worldCoordIds.put(worldName, new TreeMap<String, String>());
|
||||
}
|
||||
@ -218,12 +249,18 @@ public class Board {
|
||||
public static void loadFromSaveFormat(Map<String, Map<String, String>> worldCoordIds) {
|
||||
flocationIds.clear();
|
||||
|
||||
String worldName; String[] coords; int x, z; String factionId;
|
||||
String worldName;
|
||||
String[] coords;
|
||||
int x, z;
|
||||
String factionId;
|
||||
|
||||
for (Entry<String, Map<String, String>> entry : worldCoordIds.entrySet()) {
|
||||
worldName = entry.getKey(); for (Entry<String, String> entry2 : entry.getValue().entrySet()) {
|
||||
coords = entry2.getKey().trim().split("[,\\s]+"); x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]); factionId = entry2.getValue();
|
||||
worldName = entry.getKey();
|
||||
for (Entry<String, String> entry2 : entry.getValue().entrySet()) {
|
||||
coords = entry2.getKey().trim().split("[,\\s]+");
|
||||
x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]);
|
||||
factionId = entry2.getValue();
|
||||
flocationIds.put(new FLocation(worldName, x, z), factionId);
|
||||
}
|
||||
}
|
||||
@ -235,7 +272,9 @@ public class Board {
|
||||
try {
|
||||
DiscUtil.write(file, P.p.gson.toJson(dumpAsSaveFormat()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); P.p.log("Failed to save the board to disk."); return false;
|
||||
e.printStackTrace();
|
||||
P.p.log("Failed to save the board to disk.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -245,15 +284,20 @@ public class Board {
|
||||
P.p.log("Loading board from disk");
|
||||
|
||||
if (!file.exists()) {
|
||||
P.p.log("No board to load from disk. Creating new file."); save(); return true;
|
||||
P.p.log("No board to load from disk. Creating new file.");
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
Type type = new TypeToken<Map<String, Map<String, String>>>() {}.getType();
|
||||
Type type = new TypeToken<Map<String, Map<String, String>>>() {
|
||||
}.getType();
|
||||
Map<String, Map<String, String>> worldCoordIds = P.p.gson.fromJson(DiscUtil.read(file), type);
|
||||
loadFromSaveFormat(worldCoordIds);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); P.p.log("Failed to load the board from disk."); return false;
|
||||
e.printStackTrace();
|
||||
P.p.log("Failed to load the board from disk.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -266,24 +266,37 @@ public class Conf {
|
||||
static {
|
||||
baseCommandAliases.add("f");
|
||||
|
||||
territoryEnemyDenyCommands.add("home"); territoryEnemyDenyCommands.add("sethome");
|
||||
territoryEnemyDenyCommands.add("spawn"); territoryEnemyDenyCommands.add("tpahere");
|
||||
territoryEnemyDenyCommands.add("tpaccept"); territoryEnemyDenyCommands.add("tpa");
|
||||
territoryEnemyDenyCommands.add("home");
|
||||
territoryEnemyDenyCommands.add("sethome");
|
||||
territoryEnemyDenyCommands.add("spawn");
|
||||
territoryEnemyDenyCommands.add("tpahere");
|
||||
territoryEnemyDenyCommands.add("tpaccept");
|
||||
territoryEnemyDenyCommands.add("tpa");
|
||||
|
||||
territoryProtectedMaterials.add(Material.WOODEN_DOOR); territoryProtectedMaterials.add(Material.TRAP_DOOR);
|
||||
territoryProtectedMaterials.add(Material.FENCE_GATE); territoryProtectedMaterials.add(Material.DISPENSER);
|
||||
territoryProtectedMaterials.add(Material.CHEST); territoryProtectedMaterials.add(Material.FURNACE);
|
||||
territoryProtectedMaterials.add(Material.WOODEN_DOOR);
|
||||
territoryProtectedMaterials.add(Material.TRAP_DOOR);
|
||||
territoryProtectedMaterials.add(Material.FENCE_GATE);
|
||||
territoryProtectedMaterials.add(Material.DISPENSER);
|
||||
territoryProtectedMaterials.add(Material.CHEST);
|
||||
territoryProtectedMaterials.add(Material.FURNACE);
|
||||
territoryProtectedMaterials.add(Material.BURNING_FURNACE);
|
||||
territoryProtectedMaterials.add(Material.DIODE_BLOCK_OFF);
|
||||
territoryProtectedMaterials.add(Material.DIODE_BLOCK_ON); territoryProtectedMaterials.add(Material.JUKEBOX);
|
||||
territoryProtectedMaterials.add(Material.DIODE_BLOCK_ON);
|
||||
territoryProtectedMaterials.add(Material.JUKEBOX);
|
||||
territoryProtectedMaterials.add(Material.BREWING_STAND);
|
||||
territoryProtectedMaterials.add(Material.ENCHANTMENT_TABLE); territoryProtectedMaterials.add(Material.CAULDRON);
|
||||
territoryProtectedMaterials.add(Material.SOIL); territoryProtectedMaterials.add(Material.BEACON);
|
||||
territoryProtectedMaterials.add(Material.ANVIL); territoryProtectedMaterials.add(Material.TRAPPED_CHEST);
|
||||
territoryProtectedMaterials.add(Material.DROPPER); territoryProtectedMaterials.add(Material.HOPPER);
|
||||
territoryProtectedMaterials.add(Material.ENCHANTMENT_TABLE);
|
||||
territoryProtectedMaterials.add(Material.CAULDRON);
|
||||
territoryProtectedMaterials.add(Material.SOIL);
|
||||
territoryProtectedMaterials.add(Material.BEACON);
|
||||
territoryProtectedMaterials.add(Material.ANVIL);
|
||||
territoryProtectedMaterials.add(Material.TRAPPED_CHEST);
|
||||
territoryProtectedMaterials.add(Material.DROPPER);
|
||||
territoryProtectedMaterials.add(Material.HOPPER);
|
||||
|
||||
territoryDenyUseageMaterials.add(Material.FIREBALL); territoryDenyUseageMaterials.add(Material.FLINT_AND_STEEL);
|
||||
territoryDenyUseageMaterials.add(Material.BUCKET); territoryDenyUseageMaterials.add(Material.WATER_BUCKET);
|
||||
territoryDenyUseageMaterials.add(Material.FIREBALL);
|
||||
territoryDenyUseageMaterials.add(Material.FLINT_AND_STEEL);
|
||||
territoryDenyUseageMaterials.add(Material.BUCKET);
|
||||
territoryDenyUseageMaterials.add(Material.WATER_BUCKET);
|
||||
territoryDenyUseageMaterials.add(Material.LAVA_BUCKET);
|
||||
|
||||
territoryProtectedMaterialsWhenOffline.add(Material.WOODEN_DOOR);
|
||||
@ -312,13 +325,20 @@ public class Conf {
|
||||
territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET);
|
||||
territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET);
|
||||
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.BLAZE); safeZoneNerfedCreatureTypes.add(EntityType.CAVE_SPIDER);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.CREEPER); safeZoneNerfedCreatureTypes.add(EntityType.ENDER_DRAGON);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.ENDERMAN); safeZoneNerfedCreatureTypes.add(EntityType.GHAST);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.MAGMA_CUBE); safeZoneNerfedCreatureTypes.add(EntityType.PIG_ZOMBIE);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.SILVERFISH); safeZoneNerfedCreatureTypes.add(EntityType.SKELETON);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.SPIDER); safeZoneNerfedCreatureTypes.add(EntityType.SLIME);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.WITCH); safeZoneNerfedCreatureTypes.add(EntityType.WITHER);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.BLAZE);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.CAVE_SPIDER);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.CREEPER);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.ENDER_DRAGON);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.ENDERMAN);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.GHAST);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.MAGMA_CUBE);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.PIG_ZOMBIE);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.SILVERFISH);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.SKELETON);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.SPIDER);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.SLIME);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.WITCH);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.WITHER);
|
||||
safeZoneNerfedCreatureTypes.add(EntityType.ZOMBIE);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,9 @@ public class FLocation {
|
||||
}
|
||||
|
||||
public FLocation(String worldName, int x, int z) {
|
||||
this.worldName = worldName; this.x = x; this.z = z;
|
||||
this.worldName = worldName;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public FLocation(Location location) {
|
||||
@ -124,22 +126,31 @@ public class FLocation {
|
||||
}
|
||||
|
||||
public double getDistanceTo(FLocation that) {
|
||||
double dx = that.x - this.x; double dz = that.z - this.z; return Math.sqrt(dx * dx + dz * dz);
|
||||
double dx = that.x - this.x;
|
||||
double dz = that.z - this.z;
|
||||
return Math.sqrt(dx * dx + dz * dz);
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
// Some Geometry
|
||||
//----------------------------------------------//
|
||||
public Set<FLocation> getCircle(double radius) {
|
||||
Set<FLocation> ret = new LinkedHashSet<FLocation>(); if (radius <= 0) { return ret; }
|
||||
Set<FLocation> ret = new LinkedHashSet<FLocation>();
|
||||
if (radius <= 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int xfrom = (int) Math.floor(this.x - radius); int xto = (int) Math.ceil(this.x + radius);
|
||||
int zfrom = (int) Math.floor(this.z - radius); int zto = (int) Math.ceil(this.z + radius);
|
||||
int xfrom = (int) Math.floor(this.x - radius);
|
||||
int xto = (int) Math.ceil(this.x + radius);
|
||||
int zfrom = (int) Math.floor(this.z - radius);
|
||||
int zto = (int) Math.ceil(this.z + radius);
|
||||
|
||||
for (int x = xfrom; x <= xto; x++) {
|
||||
for (int z = zfrom; z <= zto; z++) {
|
||||
FLocation potential = new FLocation(this.worldName, x, z);
|
||||
if (this.getDistanceTo(potential) <= radius) { ret.add(potential); }
|
||||
if (this.getDistanceTo(potential) <= radius) {
|
||||
ret.add(potential);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,7 +181,12 @@ public class FLocation {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) { return true; } if (!(obj instanceof FLocation)) { return false; }
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof FLocation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FLocation that = (FLocation) obj;
|
||||
return this.x == that.x && this.z == that.z && (this.worldName == null ? that.worldName == null : this.worldName.equals(that.worldName));
|
||||
|
@ -44,7 +44,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
public Faction getFaction() {
|
||||
if (this.factionId == null) {
|
||||
return null;
|
||||
} return Factions.i.get(this.factionId);
|
||||
}
|
||||
return Factions.i.get(this.factionId);
|
||||
}
|
||||
|
||||
public String getFactionId() {
|
||||
@ -56,8 +57,12 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public void setFaction(Faction faction) {
|
||||
Faction oldFaction = this.getFaction(); if (oldFaction != null) { oldFaction.removeFPlayer(this); }
|
||||
faction.addFPlayer(this); this.factionId = faction.getId();
|
||||
Faction oldFaction = this.getFaction();
|
||||
if (oldFaction != null) {
|
||||
oldFaction.removeFPlayer(this);
|
||||
}
|
||||
faction.addFPlayer(this);
|
||||
this.factionId = faction.getId();
|
||||
}
|
||||
|
||||
// FIELD: role
|
||||
@ -106,9 +111,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public void setAutoClaimFor(Faction faction) {
|
||||
this.autoClaimFor = faction; if (this.autoClaimFor != null) {
|
||||
this.autoClaimFor = faction;
|
||||
if (this.autoClaimFor != null) {
|
||||
// TODO: merge these into same autoclaim
|
||||
this.autoSafeZoneEnabled = false; this.autoWarZoneEnabled = false;
|
||||
this.autoSafeZoneEnabled = false;
|
||||
this.autoWarZoneEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,8 +127,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public void setIsAutoSafeClaimEnabled(boolean enabled) {
|
||||
this.autoSafeZoneEnabled = enabled; if (enabled) {
|
||||
this.autoClaimFor = null; this.autoWarZoneEnabled = false;
|
||||
this.autoSafeZoneEnabled = enabled;
|
||||
if (enabled) {
|
||||
this.autoClaimFor = null;
|
||||
this.autoWarZoneEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,8 +142,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public void setIsAutoWarClaimEnabled(boolean enabled) {
|
||||
this.autoWarZoneEnabled = enabled; if (enabled) {
|
||||
this.autoClaimFor = null; this.autoSafeZoneEnabled = false;
|
||||
this.autoWarZoneEnabled = enabled;
|
||||
if (enabled) {
|
||||
this.autoClaimFor = null;
|
||||
this.autoSafeZoneEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +175,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
public ChatMode getChatMode() {
|
||||
if (this.factionId.equals("0") || !Conf.factionOnlyChat) {
|
||||
this.chatMode = ChatMode.PUBLIC;
|
||||
} return chatMode;
|
||||
}
|
||||
return chatMode;
|
||||
}
|
||||
|
||||
// FIELD: chatSpy
|
||||
@ -189,12 +201,17 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
|
||||
// GSON need this noarg constructor.
|
||||
public FPlayer() {
|
||||
this.resetFactionData(false); this.power = Conf.powerPlayerStarting;
|
||||
this.lastPowerUpdateTime = System.currentTimeMillis(); this.lastLoginTime = System.currentTimeMillis();
|
||||
this.mapAutoUpdating = false; this.autoClaimFor = null; this.autoSafeZoneEnabled = false;
|
||||
this.resetFactionData(false);
|
||||
this.power = Conf.powerPlayerStarting;
|
||||
this.lastPowerUpdateTime = System.currentTimeMillis();
|
||||
this.lastLoginTime = System.currentTimeMillis();
|
||||
this.mapAutoUpdating = false;
|
||||
this.autoClaimFor = null;
|
||||
this.autoSafeZoneEnabled = false;
|
||||
this.autoWarZoneEnabled = false;
|
||||
this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false;
|
||||
this.deleteMe = false; this.powerBoost = 0.0;
|
||||
this.deleteMe = false;
|
||||
this.powerBoost = 0.0;
|
||||
|
||||
if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.i.exists(Conf.newPlayerStartingFactionID)) {
|
||||
this.factionId = Conf.newPlayerStartingFactionID;
|
||||
@ -204,14 +221,18 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
public final void resetFactionData(boolean doSpoutUpdate) {
|
||||
// clean up any territory ownership in old faction, if there is one
|
||||
if (Factions.i.exists(this.getFactionId())) {
|
||||
Faction currentFaction = this.getFaction(); currentFaction.removeFPlayer(this);
|
||||
Faction currentFaction = this.getFaction();
|
||||
currentFaction.removeFPlayer(this);
|
||||
if (currentFaction.isNormal()) {
|
||||
currentFaction.clearClaimOwnership(this);
|
||||
}
|
||||
}
|
||||
|
||||
this.factionId = "0"; // The default neutral faction
|
||||
this.chatMode = ChatMode.PUBLIC; this.role = Role.NORMAL; this.title = ""; this.autoClaimFor = null;
|
||||
this.chatMode = ChatMode.PUBLIC;
|
||||
this.role = Role.NORMAL;
|
||||
this.title = "";
|
||||
this.autoClaimFor = null;
|
||||
}
|
||||
|
||||
public void resetFactionData() {
|
||||
@ -229,7 +250,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
|
||||
|
||||
public void setLastLoginTime(long lastLoginTime) {
|
||||
losePowerFromBeingOffline(); this.lastLoginTime = lastLoginTime; this.lastPowerUpdateTime = lastLoginTime;
|
||||
losePowerFromBeingOffline();
|
||||
this.lastLoginTime = lastLoginTime;
|
||||
this.lastPowerUpdateTime = lastLoginTime;
|
||||
if (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) {
|
||||
this.loginPvpDisabled = true;
|
||||
}
|
||||
@ -248,8 +271,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
return false;
|
||||
}
|
||||
if (this.lastLoginTime + (Conf.noPVPDamageToOthersForXSecondsAfterLogin * 1000) < System.currentTimeMillis()) {
|
||||
this.loginPvpDisabled = false; return false;
|
||||
} return true;
|
||||
this.loginPvpDisabled = false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public FLocation getLastStoodAt() {
|
||||
@ -281,22 +306,27 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
public String getName() {
|
||||
if (isOnline()) {
|
||||
return getPlayer().getName();
|
||||
} OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(getId()));
|
||||
}
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(getId()));
|
||||
return player.getName() != null ? player.getName() : getId();
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
if (!this.hasFaction()) {
|
||||
return "";
|
||||
} return this.getFaction().getTag();
|
||||
}
|
||||
return this.getFaction().getTag();
|
||||
}
|
||||
|
||||
// Base concatenations:
|
||||
|
||||
public String getNameAndSomething(String something) {
|
||||
String ret = this.role.getPrefix(); if (something.length() > 0) {
|
||||
String ret = this.role.getPrefix();
|
||||
if (something.length() > 0) {
|
||||
ret += something + " ";
|
||||
} ret += this.getName(); return ret;
|
||||
}
|
||||
ret += this.getName();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getNameAndTitle() {
|
||||
@ -412,9 +442,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
// Health
|
||||
//----------------------------------------------//
|
||||
public void heal(int amnt) {
|
||||
Player player = this.getPlayer(); if (player == null) {
|
||||
Player player = this.getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
} player.setHealth(player.getHealth() + amnt);
|
||||
}
|
||||
player.setHealth(player.getHealth() + amnt);
|
||||
}
|
||||
|
||||
|
||||
@ -422,13 +454,17 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
// Power
|
||||
//----------------------------------------------//
|
||||
public double getPower() {
|
||||
this.updatePower(); return this.power;
|
||||
this.updatePower();
|
||||
return this.power;
|
||||
}
|
||||
|
||||
protected void alterPower(double delta) {
|
||||
this.power += delta; if (this.power > this.getPowerMax()) {
|
||||
this.power += delta;
|
||||
if (this.power > this.getPowerMax()) {
|
||||
this.power = this.getPowerMax();
|
||||
} else if (this.power < this.getPowerMin()) { this.power = this.getPowerMin(); }
|
||||
} else if (this.power < this.getPowerMin()) {
|
||||
this.power = this.getPowerMin();
|
||||
}
|
||||
}
|
||||
|
||||
public double getPowerMax() {
|
||||
@ -453,33 +489,41 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
|
||||
protected void updatePower() {
|
||||
if (this.isOffline()) {
|
||||
losePowerFromBeingOffline(); if (!Conf.powerRegenOffline) {
|
||||
losePowerFromBeingOffline();
|
||||
if (!Conf.powerRegenOffline) {
|
||||
return;
|
||||
}
|
||||
} long now = System.currentTimeMillis(); long millisPassed = now - this.lastPowerUpdateTime;
|
||||
}
|
||||
long now = System.currentTimeMillis();
|
||||
long millisPassed = now - this.lastPowerUpdateTime;
|
||||
this.lastPowerUpdateTime = now;
|
||||
|
||||
Player thisPlayer = this.getPlayer(); if (thisPlayer != null && thisPlayer.isDead()) {
|
||||
Player thisPlayer = this.getPlayer();
|
||||
if (thisPlayer != null && thisPlayer.isDead()) {
|
||||
return; // don't let dead players regain power until they respawn
|
||||
}
|
||||
|
||||
int millisPerMinute = 60 * 1000; this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
|
||||
int millisPerMinute = 60 * 1000;
|
||||
this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
|
||||
}
|
||||
|
||||
protected void losePowerFromBeingOffline() {
|
||||
if (Conf.powerOfflineLossPerDay > 0.0 && this.power > Conf.powerOfflineLossLimit) {
|
||||
long now = System.currentTimeMillis(); long millisPassed = now - this.lastPowerUpdateTime;
|
||||
long now = System.currentTimeMillis();
|
||||
long millisPassed = now - this.lastPowerUpdateTime;
|
||||
this.lastPowerUpdateTime = now;
|
||||
|
||||
double loss = millisPassed * Conf.powerOfflineLossPerDay / (24 * 60 * 60 * 1000);
|
||||
if (this.power - loss < Conf.powerOfflineLossLimit) {
|
||||
loss = this.power;
|
||||
} this.alterPower(-loss);
|
||||
}
|
||||
this.alterPower(-loss);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDeath() {
|
||||
this.updatePower(); this.alterPower(-Conf.powerPerDeath);
|
||||
this.updatePower();
|
||||
this.alterPower(-Conf.powerPerDeath);
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
@ -511,7 +555,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
String msg = P.p.txt.parse("<i>") + " ~ " + factionHere.getTag(this);
|
||||
if (factionHere.getDescription().length() > 0) {
|
||||
msg += " - " + factionHere.getDescription();
|
||||
} this.sendMessage(msg);
|
||||
}
|
||||
this.sendMessage(msg);
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
@ -519,27 +564,36 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
// -------------------------------
|
||||
|
||||
public void leave(boolean makePay) {
|
||||
Faction myFaction = this.getFaction(); makePay = makePay && Econ.shouldBeUsed() && !this.isAdminBypassing();
|
||||
Faction myFaction = this.getFaction();
|
||||
makePay = makePay && Econ.shouldBeUsed() && !this.isAdminBypassing();
|
||||
|
||||
if (myFaction == null) {
|
||||
resetFactionData(); return;
|
||||
resetFactionData();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean perm = myFaction.isPermanent();
|
||||
|
||||
if (!perm && this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1) {
|
||||
msg("<b>You must give the admin role to someone else first."); return;
|
||||
msg("<b>You must give the admin role to someone else first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Conf.canLeaveWithNegativePower && this.getPower() < 0) {
|
||||
msg("<b>You cannot leave until your power is positive."); return;
|
||||
msg("<b>You cannot leave until your power is positive.");
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled and they're not on the bypass list, make sure they can pay
|
||||
if (makePay && !Econ.hasAtLeast(this, Conf.econCostLeave, "to leave your faction.")) { return; }
|
||||
if (makePay && !Econ.hasAtLeast(this, Conf.econCostLeave, "to leave your faction.")) {
|
||||
return;
|
||||
}
|
||||
|
||||
FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this, myFaction, FPlayerLeaveEvent.PlayerLeaveReason.LEAVE);
|
||||
Bukkit.getServer().getPluginManager().callEvent(leaveEvent); if (leaveEvent.isCancelled()) { return; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(leaveEvent);
|
||||
if (leaveEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
if (makePay && !Econ.modifyMoney(this, -Conf.econCostLeave, "to leave your faction.", "for leaving your faction.")) {
|
||||
@ -559,7 +613,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
fplayer.msg("%s<i> left %s<i>.", this.describeTo(fplayer, true), myFaction.describeTo(fplayer));
|
||||
}
|
||||
|
||||
if (Conf.logFactionLeave) { P.p.log(this.getName() + " left the faction: " + myFaction.getTag()); }
|
||||
if (Conf.logFactionLeave) {
|
||||
P.p.log(this.getName() + " left the faction: " + myFaction.getTag());
|
||||
}
|
||||
}
|
||||
|
||||
this.resetFactionData();
|
||||
@ -570,14 +626,17 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
fplayer.msg("<i>%s<i> was disbanded.", myFaction.describeTo(fplayer, true));
|
||||
}
|
||||
|
||||
myFaction.detach(); if (Conf.logFactionDisband) {
|
||||
myFaction.detach();
|
||||
if (Conf.logFactionDisband) {
|
||||
P.p.log("The faction " + myFaction.getTag() + " (" + myFaction.getId() + ") was disbanded due to the last player (" + this.getName() + ") leaving.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canClaimForFaction(Faction forFaction) {
|
||||
if (forFaction.isNone()) { return false; }
|
||||
if (forFaction.isNone()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isAdminBypassing() || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))) {
|
||||
return true;
|
||||
@ -587,8 +646,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) {
|
||||
String error = null; FLocation flocation = new FLocation(location); Faction myFaction = getFaction();
|
||||
Faction currentFaction = Board.getFactionAt(flocation); int ownedLand = forFaction.getLandRounded();
|
||||
String error = null;
|
||||
FLocation flocation = new FLocation(location);
|
||||
Faction myFaction = getFaction();
|
||||
Faction currentFaction = Board.getFactionAt(flocation);
|
||||
int ownedLand = forFaction.getLandRounded();
|
||||
|
||||
if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) {
|
||||
// Checks for WorldGuard regions in the chunk attempting to be claimed
|
||||
@ -640,22 +702,28 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
|
||||
if (notifyFailure && error != null) {
|
||||
msg(error);
|
||||
} return error == null;
|
||||
}
|
||||
return error == null;
|
||||
}
|
||||
|
||||
public boolean attemptClaim(Faction forFaction, Location location, boolean notifyFailure) {
|
||||
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it
|
||||
// return value is false on failure, true on success
|
||||
|
||||
FLocation flocation = new FLocation(location); Faction currentFaction = Board.getFactionAt(flocation);
|
||||
FLocation flocation = new FLocation(location);
|
||||
Faction currentFaction = Board.getFactionAt(flocation);
|
||||
|
||||
int ownedLand = forFaction.getLandRounded();
|
||||
|
||||
if (!this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) { return false; }
|
||||
if (!this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if economy is enabled and they're not on the bypass list, make sure they can pay
|
||||
boolean mustPay = Econ.shouldBeUsed() && !this.isAdminBypassing() && !forFaction.isSafeZone() && !forFaction.isWarZone();
|
||||
double cost = 0.0; EconomyParticipator payee = null; if (mustPay) {
|
||||
double cost = 0.0;
|
||||
EconomyParticipator payee = null;
|
||||
if (mustPay) {
|
||||
cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
|
||||
|
||||
if (Conf.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, forFaction)) {
|
||||
@ -664,13 +732,20 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
|
||||
if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts && this.hasFaction()) {
|
||||
payee = this.getFaction();
|
||||
} else { payee = this; }
|
||||
} else {
|
||||
payee = this;
|
||||
}
|
||||
|
||||
if (!Econ.hasAtLeast(payee, cost, "to claim this land")) { return false; }
|
||||
if (!Econ.hasAtLeast(payee, cost, "to claim this land")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this);
|
||||
Bukkit.getServer().getPluginManager().callEvent(claimEvent); if (claimEvent.isCancelled()) { return false; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(claimEvent);
|
||||
if (claimEvent.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
if (mustPay && !Econ.modifyMoney(payee, -cost, "to claim this land", "for claiming this land")) {
|
||||
@ -678,8 +753,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
// announce success
|
||||
Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>(); informTheseFPlayers.add(this);
|
||||
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true)); for (FPlayer fp : informTheseFPlayers) {
|
||||
Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>();
|
||||
informTheseFPlayers.add(this);
|
||||
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true));
|
||||
for (FPlayer fp : informTheseFPlayers) {
|
||||
fp.msg("<h>%s<i> claimed land for <h>%s<i> from <h>%s<i>.", this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
|
||||
}
|
||||
|
||||
@ -700,7 +777,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
public boolean shouldBeSaved() {
|
||||
if (!this.hasFaction() && (this.getPowerRounded() == this.getPowerMaxRounded() || this.getPowerRounded() == (int) Math.round(Conf.powerPlayerStarting))) {
|
||||
return false;
|
||||
} return !this.deleteMe;
|
||||
}
|
||||
return !this.deleteMe;
|
||||
}
|
||||
|
||||
public void msg(String str, Object... args) {
|
||||
|
@ -22,7 +22,8 @@ public class FPlayers extends PlayerEntityCollection<FPlayer> {
|
||||
|
||||
@Override
|
||||
public Type getMapType() {
|
||||
return new TypeToken<Map<String, FPlayer>>() {}.getType();
|
||||
return new TypeToken<Map<String, FPlayer>>() {
|
||||
}.getType();
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
|
@ -115,19 +115,22 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
public String getTag(Faction otherFaction) {
|
||||
if (otherFaction == null) {
|
||||
return getTag();
|
||||
} return this.getTag(this.getColorTo(otherFaction).toString());
|
||||
}
|
||||
return this.getTag(this.getColorTo(otherFaction).toString());
|
||||
}
|
||||
|
||||
public String getTag(FPlayer otherFplayer) {
|
||||
if (otherFplayer == null) {
|
||||
return getTag();
|
||||
} return this.getTag(this.getColorTo(otherFplayer).toString());
|
||||
}
|
||||
return this.getTag(this.getColorTo(otherFplayer).toString());
|
||||
}
|
||||
|
||||
public void setTag(String str) {
|
||||
if (Conf.factionTagForceUpperCase) {
|
||||
str = str.toUpperCase();
|
||||
} this.tag = str;
|
||||
}
|
||||
this.tag = str;
|
||||
}
|
||||
|
||||
public String getComparisonTag() {
|
||||
@ -157,7 +160,8 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public Location getHome() {
|
||||
confirmValidHome(); return (this.home != null) ? this.home.getLocation() : null;
|
||||
confirmValidHome();
|
||||
return (this.home != null) ? this.home.getLocation() : null;
|
||||
}
|
||||
|
||||
public void confirmValidHome() {
|
||||
@ -165,7 +169,8 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
return;
|
||||
}
|
||||
|
||||
msg("<b>Your faction home has been un-set since it is no longer in your territory."); this.home = null;
|
||||
msg("<b>Your faction home has been un-set since it is no longer in your territory.");
|
||||
this.home = null;
|
||||
}
|
||||
|
||||
// FIELD: lastPlayerLoggedOffTime
|
||||
@ -179,7 +184,9 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
String aid = "faction-" + this.getId();
|
||||
|
||||
// We need to override the default money given to players.
|
||||
if (!Econ.hasAccount(aid)) { Econ.setBalance(aid, 0); }
|
||||
if (!Econ.hasAccount(aid)) {
|
||||
Econ.setBalance(aid, 0);
|
||||
}
|
||||
|
||||
return aid;
|
||||
}
|
||||
@ -217,10 +224,17 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Faction() {
|
||||
this.relationWish = new HashMap<String, Relation>(); this.invites = new HashSet<String>();
|
||||
this.open = Conf.newFactionsDefaultOpen; this.tag = "???"; this.description = "Default faction description :(";
|
||||
this.lastPlayerLoggedOffTime = 0; this.peaceful = false; this.peacefulExplosionsEnabled = false;
|
||||
this.permanent = false; this.money = 0.0; this.powerBoost = 0.0;
|
||||
this.relationWish = new HashMap<String, Relation>();
|
||||
this.invites = new HashSet<String>();
|
||||
this.open = Conf.newFactionsDefaultOpen;
|
||||
this.tag = "???";
|
||||
this.description = "Default faction description :(";
|
||||
this.lastPlayerLoggedOffTime = 0;
|
||||
this.peaceful = false;
|
||||
this.peacefulExplosionsEnabled = false;
|
||||
this.permanent = false;
|
||||
this.money = 0.0;
|
||||
this.powerBoost = 0.0;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -293,7 +307,8 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
public Relation getRelationWish(Faction otherFaction) {
|
||||
if (this.relationWish.containsKey(otherFaction.getId())) {
|
||||
return this.relationWish.get(otherFaction.getId());
|
||||
} return Relation.NEUTRAL;
|
||||
}
|
||||
return Relation.NEUTRAL;
|
||||
}
|
||||
|
||||
public void setRelationWish(Faction otherFaction, Relation relation) {
|
||||
@ -312,11 +327,14 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
return this.getPermanentPower();
|
||||
}
|
||||
|
||||
double ret = 0; for (FPlayer fplayer : fplayers) {
|
||||
double ret = 0;
|
||||
for (FPlayer fplayer : fplayers) {
|
||||
ret += fplayer.getPower();
|
||||
} if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
|
||||
}
|
||||
if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
|
||||
ret = Conf.powerFactionMax;
|
||||
} return ret + this.powerBoost;
|
||||
}
|
||||
return ret + this.powerBoost;
|
||||
}
|
||||
|
||||
public double getPowerMax() {
|
||||
@ -324,11 +342,14 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
return this.getPermanentPower();
|
||||
}
|
||||
|
||||
double ret = 0; for (FPlayer fplayer : fplayers) {
|
||||
double ret = 0;
|
||||
for (FPlayer fplayer : fplayers) {
|
||||
ret += fplayer.getPowerMax();
|
||||
} if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
|
||||
}
|
||||
if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
|
||||
ret = Conf.powerFactionMax;
|
||||
} return ret + this.powerBoost;
|
||||
}
|
||||
return ret + this.powerBoost;
|
||||
}
|
||||
|
||||
public int getPowerRounded() {
|
||||
@ -357,7 +378,10 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
|
||||
// maintain the reference list of FPlayers in this faction
|
||||
public void refreshFPlayers() {
|
||||
fplayers.clear(); if (this.isPlayerFreeType()) { return; }
|
||||
fplayers.clear();
|
||||
if (this.isPlayerFreeType()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (FPlayer fplayer : FPlayers.i.get()) {
|
||||
if (fplayer.getFaction() == this) {
|
||||
@ -367,20 +391,25 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
protected boolean addFPlayer(FPlayer fplayer) {
|
||||
if (this.isPlayerFreeType()) { return false; }
|
||||
if (this.isPlayerFreeType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fplayers.add(fplayer);
|
||||
}
|
||||
|
||||
protected boolean removeFPlayer(FPlayer fplayer) {
|
||||
if (this.isPlayerFreeType()) { return false; }
|
||||
if (this.isPlayerFreeType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fplayers.remove(fplayer);
|
||||
}
|
||||
|
||||
public Set<FPlayer> getFPlayers() {
|
||||
// return a shallow copy of the FPlayer list, to prevent tampering and concurrency issues
|
||||
Set<FPlayer> ret = new HashSet<FPlayer>(fplayers); return ret;
|
||||
Set<FPlayer> ret = new HashSet<FPlayer>(fplayers);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Set<FPlayer> getFPlayersWhereOnline(boolean online) {
|
||||
@ -396,17 +425,23 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public FPlayer getFPlayerAdmin() {
|
||||
if (!this.isNormal()) { return null; }
|
||||
if (!this.isNormal()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (FPlayer fplayer : fplayers) {
|
||||
if (fplayer.getRole() == Role.ADMIN) {
|
||||
return fplayer;
|
||||
}
|
||||
} return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<FPlayer> getFPlayersWhereRole(Role role) {
|
||||
ArrayList<FPlayer> ret = new ArrayList<FPlayer>(); if (!this.isNormal()) { return ret; }
|
||||
ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
|
||||
if (!this.isNormal()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (FPlayer fplayer : fplayers) {
|
||||
if (fplayer.getRole() == role) {
|
||||
@ -418,10 +453,14 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public ArrayList<Player> getOnlinePlayers() {
|
||||
ArrayList<Player> ret = new ArrayList<Player>(); if (this.isPlayerFreeType()) { return ret; }
|
||||
ArrayList<Player> ret = new ArrayList<Player>();
|
||||
if (this.isPlayerFreeType()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (Player player : P.p.getServer().getOnlinePlayers()) {
|
||||
FPlayer fplayer = FPlayers.i.get(player); if (fplayer.getFaction() == this) {
|
||||
FPlayer fplayer = FPlayers.i.get(player);
|
||||
if (fplayer.getFaction() == this) {
|
||||
ret.add(player);
|
||||
}
|
||||
}
|
||||
@ -432,10 +471,13 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
// slightly faster check than getOnlinePlayers() if you just want to see if there are any players online
|
||||
public boolean hasPlayersOnline() {
|
||||
// only real factions can have players online, not safe zone / war zone
|
||||
if (this.isPlayerFreeType()) { return false; }
|
||||
if (this.isPlayerFreeType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Player player : P.p.getServer().getOnlinePlayers()) {
|
||||
FPlayer fplayer = FPlayers.i.get(player); if (fplayer != null && fplayer.getFaction() == this) {
|
||||
FPlayer fplayer = FPlayers.i.get(player);
|
||||
if (fplayer != null && fplayer.getFaction() == this) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -443,7 +485,8 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
// even if all players are technically logged off, maybe someone was on recently enough to not consider them officially offline yet
|
||||
if (Conf.considerFactionsReallyOfflineAfterXMinutes > 0 && System.currentTimeMillis() < lastPlayerLoggedOffTime + (Conf.considerFactionsReallyOfflineAfterXMinutes * 60000)) {
|
||||
return true;
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void memberLoggedOff() {
|
||||
@ -454,18 +497,27 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
|
||||
// used when current leader is about to be removed from the faction; promotes new leader, or disbands faction if no other members left
|
||||
public void promoteNewLeader() {
|
||||
if (!this.isNormal()) { return; }
|
||||
if (this.isPermanent() && Conf.permanentFactionsDisableLeaderPromotion) { return; }
|
||||
if (!this.isNormal()) {
|
||||
return;
|
||||
}
|
||||
if (this.isPermanent() && Conf.permanentFactionsDisableLeaderPromotion) {
|
||||
return;
|
||||
}
|
||||
|
||||
FPlayer oldLeader = this.getFPlayerAdmin();
|
||||
|
||||
// get list of moderators, or list of normal members if there are no moderators
|
||||
ArrayList<FPlayer> replacements = this.getFPlayersWhereRole(Role.MODERATOR);
|
||||
if (replacements == null || replacements.isEmpty()) { replacements = this.getFPlayersWhereRole(Role.NORMAL); }
|
||||
if (replacements == null || replacements.isEmpty()) {
|
||||
replacements = this.getFPlayersWhereRole(Role.NORMAL);
|
||||
}
|
||||
|
||||
if (replacements == null || replacements.isEmpty()) { // faction admin is the only member; one-man faction
|
||||
if (this.isPermanent()) {
|
||||
if (oldLeader != null) { oldLeader.setRole(Role.NORMAL); } return;
|
||||
if (oldLeader != null) {
|
||||
oldLeader.setRole(Role.NORMAL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// no members left and faction isn't permanent, so disband it
|
||||
@ -479,7 +531,10 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
|
||||
this.detach();
|
||||
} else { // promote new faction admin
|
||||
if (oldLeader != null) { oldLeader.setRole(Role.NORMAL); } replacements.get(0).setRole(Role.ADMIN);
|
||||
if (oldLeader != null) {
|
||||
oldLeader.setRole(Role.NORMAL);
|
||||
}
|
||||
replacements.get(0).setRole(Role.ADMIN);
|
||||
this.msg("<i>Faction admin <h>%s<i> has been removed. %s<i> has been promoted as the new faction admin.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName());
|
||||
P.p.log("Faction " + this.getTag() + " (" + this.getId() + ") admin was removed. Replacement admin: " + replacements.get(0).getName());
|
||||
}
|
||||
@ -535,9 +590,12 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
for (Entry<FLocation, Set<String>> entry : claimOwnership.entrySet()) {
|
||||
ownerData = entry.getValue();
|
||||
|
||||
if (ownerData == null) { continue; }
|
||||
if (ownerData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Iterator<String> iter = ownerData.iterator(); while (iter.hasNext()) {
|
||||
Iterator<String> iter = ownerData.iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (iter.next().equals(player.getId())) {
|
||||
iter.remove();
|
||||
}
|
||||
@ -558,15 +616,19 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<String> ownerData = claimOwnership.get(loc); return ownerData != null && !ownerData.isEmpty();
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
return ownerData != null && !ownerData.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isPlayerInOwnerList(FPlayer player, FLocation loc) {
|
||||
if (claimOwnership.isEmpty()) {
|
||||
return false;
|
||||
} Set<String> ownerData = claimOwnership.get(loc); if (ownerData == null) {
|
||||
}
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
if (ownerData == null) {
|
||||
return false;
|
||||
} if (ownerData.contains(player.getId())) {
|
||||
}
|
||||
if (ownerData.contains(player.getId())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -574,15 +636,21 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public void setPlayerAsOwner(FPlayer player, FLocation loc) {
|
||||
Set<String> ownerData = claimOwnership.get(loc); if (ownerData == null) {
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
if (ownerData == null) {
|
||||
ownerData = new HashSet<String>();
|
||||
} ownerData.add(player.getId()); claimOwnership.put(loc, ownerData);
|
||||
}
|
||||
ownerData.add(player.getId());
|
||||
claimOwnership.put(loc, ownerData);
|
||||
}
|
||||
|
||||
public void removePlayerAsOwner(FPlayer player, FLocation loc) {
|
||||
Set<String> ownerData = claimOwnership.get(loc); if (ownerData == null) {
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
if (ownerData == null) {
|
||||
return;
|
||||
} ownerData.remove(player.getId()); claimOwnership.put(loc, ownerData);
|
||||
}
|
||||
ownerData.remove(player.getId());
|
||||
claimOwnership.put(loc, ownerData);
|
||||
}
|
||||
|
||||
public Set<String> getOwnerList(FLocation loc) {
|
||||
@ -590,18 +658,22 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
public String getOwnerListString(FLocation loc) {
|
||||
Set<String> ownerData = claimOwnership.get(loc); if (ownerData == null || ownerData.isEmpty()) {
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
if (ownerData == null || ownerData.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String ownerList = "";
|
||||
|
||||
Iterator<String> iter = ownerData.iterator(); while (iter.hasNext()) {
|
||||
Iterator<String> iter = ownerData.iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (!ownerList.isEmpty()) {
|
||||
ownerList += ", ";
|
||||
} OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(iter.next()));
|
||||
}
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(iter.next()));
|
||||
ownerList += offlinePlayer != null ? offlinePlayer.getName() : "null player";
|
||||
} return ownerList;
|
||||
}
|
||||
return ownerList;
|
||||
}
|
||||
|
||||
public boolean playerHasOwnershipRights(FPlayer fplayer, FLocation loc) {
|
||||
@ -611,13 +683,17 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
}
|
||||
|
||||
// make sure claimOwnership is initialized
|
||||
if (claimOwnership.isEmpty()) { return true; }
|
||||
if (claimOwnership.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// need to check the ownership list, then
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
|
||||
// if no owner list, owner list is empty, or player is in owner list, they're allowed
|
||||
if (ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId())) { return true; }
|
||||
if (ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -27,53 +27,66 @@ public class Factions extends EntityCollection<Faction> {
|
||||
|
||||
@Override
|
||||
public Type getMapType() {
|
||||
return new TypeToken<Map<String, Faction>>() {}.getType();
|
||||
return new TypeToken<Map<String, Faction>>() {
|
||||
}.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadFromDisc() {
|
||||
if (!super.loadFromDisc()) { return false; }
|
||||
if (!super.loadFromDisc()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the default neutral faction exists
|
||||
if (!this.exists("0")) {
|
||||
Faction faction = this.create("0"); faction.setTag(TL.WILDERNESS.toString());
|
||||
Faction faction = this.create("0");
|
||||
faction.setTag(TL.WILDERNESS.toString());
|
||||
faction.setDescription(TL.WILDERNESS_DESCRIPTION.toString());
|
||||
} else {
|
||||
if (!this.get("0").getTag().equalsIgnoreCase(TL.WILDERNESS.toString())) {
|
||||
get("0").setTag(TL.WILDERNESS.toString());
|
||||
} if (!this.get("0").getDescription().equalsIgnoreCase(TL.WILDERNESS_DESCRIPTION.toString())) {
|
||||
}
|
||||
if (!this.get("0").getDescription().equalsIgnoreCase(TL.WILDERNESS_DESCRIPTION.toString())) {
|
||||
get("0").setDescription(TL.WILDERNESS_DESCRIPTION.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the safe zone faction exists
|
||||
if (!this.exists("-1")) {
|
||||
Faction faction = this.create("-1"); faction.setTag(TL.SAFEZONE.toString());
|
||||
Faction faction = this.create("-1");
|
||||
faction.setTag(TL.SAFEZONE.toString());
|
||||
faction.setDescription(TL.SAFEZONE_DESCRIPTION.toString());
|
||||
} else {
|
||||
if (!getSafeZone().getTag().equalsIgnoreCase(TL.SAFEZONE.toString())) {
|
||||
getSafeZone().setTag(TL.SAFEZONE.toString());
|
||||
} if (!getSafeZone().getDescription().equalsIgnoreCase(TL.SAFEZONE_DESCRIPTION.toString())) {
|
||||
}
|
||||
if (!getSafeZone().getDescription().equalsIgnoreCase(TL.SAFEZONE_DESCRIPTION.toString())) {
|
||||
getSafeZone().setDescription(TL.SAFEZONE_DESCRIPTION.toString());
|
||||
}
|
||||
// if SafeZone has old pre-1.6.0 name, rename it to remove troublesome " "
|
||||
Faction faction = this.getSafeZone();
|
||||
if (faction.getTag().contains(" ")) { faction.setTag(TL.SAFEZONE.toString()); }
|
||||
if (faction.getTag().contains(" ")) {
|
||||
faction.setTag(TL.SAFEZONE.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the war zone faction exists
|
||||
if (!this.exists("-2")) {
|
||||
Faction faction = this.create("-2"); faction.setTag(TL.WARZONE.toString());
|
||||
Faction faction = this.create("-2");
|
||||
faction.setTag(TL.WARZONE.toString());
|
||||
faction.setDescription(TL.WARZONE_DESCRIPTION.toString());
|
||||
} else {
|
||||
if (!getWarZone().getTag().equalsIgnoreCase(TL.WARZONE.toString())) {
|
||||
getWarZone().setTag(TL.WARZONE.toString());
|
||||
} if (!getWarZone().getDescription().equalsIgnoreCase(TL.WARZONE_DESCRIPTION.toString())) {
|
||||
}
|
||||
if (!getWarZone().getDescription().equalsIgnoreCase(TL.WARZONE_DESCRIPTION.toString())) {
|
||||
getWarZone().setDescription(TL.WARZONE_DESCRIPTION.toString());
|
||||
}
|
||||
// if WarZone has old pre-1.6.0 name, rename it to remove troublesome " "
|
||||
Faction faction = this.getWarZone();
|
||||
if (faction.getTag().contains(" ")) { faction.setTag(TL.WARZONE.toString()); }
|
||||
if (faction.getTag().contains(" ")) {
|
||||
faction.setTag(TL.WARZONE.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// populate all faction player lists
|
||||
@ -92,7 +105,8 @@ public class Factions extends EntityCollection<Faction> {
|
||||
@Override
|
||||
public Faction get(String id) {
|
||||
if (!this.exists(id)) {
|
||||
p.log(Level.WARNING, "Non existing factionId " + id + " requested! Issuing cleaning!"); Board.clean();
|
||||
p.log(Level.WARNING, "Non existing factionId " + id + " requested! Issuing cleaning!");
|
||||
Board.clean();
|
||||
FPlayers.i.clean();
|
||||
}
|
||||
|
||||
@ -138,11 +152,13 @@ public class Factions extends EntityCollection<Faction> {
|
||||
|
||||
// Loops through all faction tags. Case and color insensitive.
|
||||
public Faction getByTag(String str) {
|
||||
String compStr = MiscUtil.getComparisonString(str); for (Faction faction : this.get()) {
|
||||
String compStr = MiscUtil.getComparisonString(str);
|
||||
for (Faction faction : this.get()) {
|
||||
if (faction.getComparisonTag().equals(compStr)) {
|
||||
return faction;
|
||||
}
|
||||
} return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Faction getBestTagMatch(String searchFor) {
|
||||
@ -153,7 +169,10 @@ public class Factions extends EntityCollection<Faction> {
|
||||
tag2faction.put(ChatColor.stripColor(faction.getTag()), faction);
|
||||
}
|
||||
|
||||
String tag = TextUtil.getBestStartWithCI(tag2faction.keySet(), searchFor); if (tag == null) { return null; }
|
||||
String tag = TextUtil.getBestStartWithCI(tag2faction.keySet(), searchFor);
|
||||
if (tag == null) {
|
||||
return null;
|
||||
}
|
||||
return tag2faction.get(tag);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,8 @@ public class P extends MPlugin {
|
||||
}
|
||||
|
||||
public void setLocked(boolean val) {
|
||||
this.locked = val; this.setAutoSave(val);
|
||||
this.locked = val;
|
||||
this.setAutoSave(val);
|
||||
}
|
||||
|
||||
private Integer AutoLeaveTask = null;
|
||||
@ -58,9 +59,12 @@ public class P extends MPlugin {
|
||||
public CmdAutoHelp cmdAutoHelp;
|
||||
|
||||
public P() {
|
||||
p = this; this.playerListener = new FactionsPlayerListener(this);
|
||||
this.chatListener = new FactionsChatListener(this); this.entityListener = new FactionsEntityListener(this);
|
||||
this.exploitListener = new FactionsExploitListener(); this.blockListener = new FactionsBlockListener(this);
|
||||
p = this;
|
||||
this.playerListener = new FactionsPlayerListener(this);
|
||||
this.chatListener = new FactionsChatListener(this);
|
||||
this.entityListener = new FactionsEntityListener(this);
|
||||
this.exploitListener = new FactionsExploitListener();
|
||||
this.blockListener = new FactionsBlockListener(this);
|
||||
}
|
||||
|
||||
|
||||
@ -71,16 +75,26 @@ public class P extends MPlugin {
|
||||
Class.forName("org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
this.log(Level.SEVERE, "GSON lib not found. Your CraftBukkit build is too old (< 1.3.2) or otherwise not compatible.");
|
||||
this.suicide(); return;
|
||||
this.suicide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preEnable()) { return; } this.loadSuccessful = false;
|
||||
if (!preEnable()) {
|
||||
return;
|
||||
}
|
||||
this.loadSuccessful = false;
|
||||
|
||||
// Load Conf from disk
|
||||
Conf.load(); Essentials.setup(); FPlayers.i.loadFromDisc(); Factions.i.loadFromDisc(); Board.load();
|
||||
Conf.load();
|
||||
Essentials.setup();
|
||||
FPlayers.i.loadFromDisc();
|
||||
Factions.i.loadFromDisc();
|
||||
Board.load();
|
||||
|
||||
// Add Base Commands
|
||||
this.cmdBase = new FCmdRoot(); this.cmdAutoHelp = new CmdAutoHelp(); this.getBaseCommands().add(cmdBase);
|
||||
this.cmdBase = new FCmdRoot();
|
||||
this.cmdAutoHelp = new CmdAutoHelp();
|
||||
this.getBaseCommands().add(cmdBase);
|
||||
|
||||
Econ.setup();
|
||||
|
||||
@ -101,12 +115,14 @@ public class P extends MPlugin {
|
||||
// since some other plugins execute commands directly through this command interface, provide it
|
||||
this.getCommand(this.refCommand).setExecutor(this);
|
||||
|
||||
postEnable(); this.loadSuccessful = true;
|
||||
postEnable();
|
||||
this.loadSuccessful = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GsonBuilder getGsonBuilder() {
|
||||
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {}.getType();
|
||||
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {
|
||||
}.getType();
|
||||
|
||||
return new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE).registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter()).registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter());
|
||||
}
|
||||
@ -115,15 +131,22 @@ public class P extends MPlugin {
|
||||
public void onDisable() {
|
||||
// only save data if plugin actually completely loaded successfully
|
||||
if (this.loadSuccessful) {
|
||||
Board.save(); Conf.save();
|
||||
} if (AutoLeaveTask != null) {
|
||||
this.getServer().getScheduler().cancelTask(AutoLeaveTask); AutoLeaveTask = null;
|
||||
} super.onDisable();
|
||||
Board.save();
|
||||
Conf.save();
|
||||
}
|
||||
if (AutoLeaveTask != null) {
|
||||
this.getServer().getScheduler().cancelTask(AutoLeaveTask);
|
||||
AutoLeaveTask = null;
|
||||
}
|
||||
super.onDisable();
|
||||
}
|
||||
|
||||
public void startAutoLeaveTask(boolean restartIfRunning) {
|
||||
if (AutoLeaveTask != null) {
|
||||
if (!restartIfRunning) { return; } this.getServer().getScheduler().cancelTask(AutoLeaveTask);
|
||||
if (!restartIfRunning) {
|
||||
return;
|
||||
}
|
||||
this.getServer().getScheduler().cancelTask(AutoLeaveTask);
|
||||
}
|
||||
|
||||
if (Conf.autoLeaveRoutineRunsEveryXMinutes > 0.0) {
|
||||
@ -134,7 +157,8 @@ public class P extends MPlugin {
|
||||
|
||||
@Override
|
||||
public void postAutoSave() {
|
||||
Board.save(); Conf.save();
|
||||
Board.save();
|
||||
Conf.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -154,7 +178,9 @@ public class P extends MPlugin {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
// if bare command at this point, it has already been handled by MPlugin's command listeners
|
||||
if (split == null || split.length == 0) { return true; }
|
||||
if (split == null || split.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// otherwise, needs to be handled; presumably another plugin directly ran the command
|
||||
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
|
||||
@ -180,16 +206,24 @@ public class P extends MPlugin {
|
||||
// enabled or use of the Factions f command without a slash; combination of isPlayerFactionChatting() and isFactionsCommand()
|
||||
|
||||
public boolean shouldLetFactionsHandleThisChat(AsyncPlayerChatEvent event) {
|
||||
if (event == null) { return false; }
|
||||
if (event == null) {
|
||||
return false;
|
||||
}
|
||||
return (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage()));
|
||||
}
|
||||
|
||||
// Does player have Faction Chat enabled? If so, chat plugins should preferably not do channels,
|
||||
// local chat, or anything else which targets individual recipients, so Faction Chat can be done
|
||||
public boolean isPlayerFactionChatting(Player player) {
|
||||
if (player == null) { return false; } FPlayer me = FPlayers.i.get(player);
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
FPlayer me = FPlayers.i.get(player);
|
||||
|
||||
if (me == null) { return false; } return me.getChatMode().isAtLeast(ChatMode.ALLIANCE);
|
||||
if (me == null) {
|
||||
return false;
|
||||
}
|
||||
return me.getChatMode().isAtLeast(ChatMode.ALLIANCE);
|
||||
}
|
||||
|
||||
// Is this chat message actually a Factions command, and thus should be left alone by other plugins?
|
||||
@ -197,7 +231,10 @@ public class P extends MPlugin {
|
||||
// TODO: GET THIS BACK AND WORKING
|
||||
|
||||
public boolean isFactionsCommand(String check) {
|
||||
if (check == null || check.isEmpty()) { return false; } return this.handleCommand(null, check, true);
|
||||
if (check == null || check.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return this.handleCommand(null, check, true);
|
||||
}
|
||||
|
||||
// Get a player's faction tag (faction name), mainly for usage by chat plugins for local/channel chat
|
||||
@ -209,55 +246,78 @@ public class P extends MPlugin {
|
||||
public String getPlayerFactionTagRelation(Player speaker, Player listener) {
|
||||
String tag = "~";
|
||||
|
||||
if (speaker == null) { return tag; }
|
||||
if (speaker == null) {
|
||||
return tag;
|
||||
}
|
||||
|
||||
FPlayer me = FPlayers.i.get(speaker); if (me == null) { return tag; }
|
||||
FPlayer me = FPlayers.i.get(speaker);
|
||||
if (me == null) {
|
||||
return tag;
|
||||
}
|
||||
|
||||
// if listener isn't set, or config option is disabled, give back uncolored tag
|
||||
if (listener == null || !Conf.chatTagRelationColored) {
|
||||
tag = me.getChatTag().trim();
|
||||
} else {
|
||||
FPlayer you = FPlayers.i.get(listener);
|
||||
if (you == null) { tag = me.getChatTag().trim(); } else // everything checks out, give the colored tag
|
||||
{ tag = me.getChatTag(you).trim(); }
|
||||
} if (tag.isEmpty()) { tag = "~"; }
|
||||
if (you == null) {
|
||||
tag = me.getChatTag().trim();
|
||||
} else // everything checks out, give the colored tag
|
||||
{
|
||||
tag = me.getChatTag(you).trim();
|
||||
}
|
||||
}
|
||||
if (tag.isEmpty()) {
|
||||
tag = "~";
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
// Get a player's title within their faction, mainly for usage by chat plugins for local/channel chat
|
||||
public String getPlayerTitle(Player player) {
|
||||
if (player == null) { return ""; }
|
||||
if (player == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
FPlayer me = FPlayers.i.get(player); if (me == null) { return ""; }
|
||||
FPlayer me = FPlayers.i.get(player);
|
||||
if (me == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return me.getTitle().trim();
|
||||
}
|
||||
|
||||
// Get a list of all faction tags (names)
|
||||
public Set<String> getFactionTags() {
|
||||
Set<String> tags = new HashSet<String>(); for (Faction faction : Factions.i.get()) {
|
||||
Set<String> tags = new HashSet<String>();
|
||||
for (Faction faction : Factions.i.get()) {
|
||||
tags.add(faction.getTag());
|
||||
} return tags;
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
// Get a list of all players in the specified faction
|
||||
public Set<String> getPlayersInFaction(String factionTag) {
|
||||
Set<String> players = new HashSet<String>(); Faction faction = Factions.i.getByTag(factionTag);
|
||||
Set<String> players = new HashSet<String>();
|
||||
Faction faction = Factions.i.getByTag(factionTag);
|
||||
if (faction != null) {
|
||||
for (FPlayer fplayer : faction.getFPlayers()) {
|
||||
players.add(fplayer.getName());
|
||||
}
|
||||
} return players;
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
// Get a list of all online players in the specified faction
|
||||
public Set<String> getOnlinePlayersInFaction(String factionTag) {
|
||||
Set<String> players = new HashSet<String>(); Faction faction = Factions.i.getByTag(factionTag);
|
||||
Set<String> players = new HashSet<String>();
|
||||
Faction faction = Factions.i.getByTag(factionTag);
|
||||
if (faction != null) {
|
||||
for (FPlayer fplayer : faction.getFPlayersWhereOnline(true)) {
|
||||
players.add(fplayer.getName());
|
||||
}
|
||||
} return players;
|
||||
}
|
||||
return players;
|
||||
}
|
||||
}
|
||||
|
@ -10,39 +10,53 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class CmdAdmin extends FCommand {
|
||||
public CmdAdmin() {
|
||||
super(); this.aliases.add("admin");
|
||||
super();
|
||||
this.aliases.add("admin");
|
||||
|
||||
this.requiredArgs.add("player name");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.ADMIN.node; this.disableOnLock = true;
|
||||
this.permission = Permission.ADMIN.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FPlayer fyou = this.argAsBestFPlayerMatch(0); if (fyou == null) { return; }
|
||||
FPlayer fyou = this.argAsBestFPlayerMatch(0);
|
||||
if (fyou == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean permAny = Permission.ADMIN_ANY.has(sender, false); Faction targetFaction = fyou.getFaction();
|
||||
boolean permAny = Permission.ADMIN_ANY.has(sender, false);
|
||||
Faction targetFaction = fyou.getFaction();
|
||||
|
||||
if (targetFaction != myFaction && !permAny) {
|
||||
msg("%s<i> is not a member in your faction.", fyou.describeTo(fme, true)); return;
|
||||
msg("%s<i> is not a member in your faction.", fyou.describeTo(fme, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (fme != null && fme.getRole() != Role.ADMIN && !permAny) {
|
||||
msg("<b>You are not the faction admin."); return;
|
||||
msg("<b>You are not the faction admin.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (fyou == fme && !permAny) {
|
||||
msg("<b>The target player musn't be yourself."); return;
|
||||
msg("<b>The target player musn't be yourself.");
|
||||
return;
|
||||
}
|
||||
|
||||
// only perform a FPlayerJoinEvent when newLeader isn't actually in the faction
|
||||
if (fyou.getFaction() != targetFaction) {
|
||||
FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.i.get(me), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FPlayer admin = targetFaction.getFPlayerAdmin();
|
||||
@ -56,7 +70,10 @@ public class CmdAdmin extends FCommand {
|
||||
}
|
||||
|
||||
// promote target player, and demote existing admin if one exists
|
||||
if (admin != null) { admin.setRole(Role.MODERATOR); } fyou.setRole(Role.ADMIN);
|
||||
if (admin != null) {
|
||||
admin.setRole(Role.MODERATOR);
|
||||
}
|
||||
fyou.setRole(Role.ADMIN);
|
||||
msg("<i>You have promoted %s<i> to the position of faction admin.", fyou.describeTo(fme, true));
|
||||
|
||||
// Inform all players
|
||||
|
@ -6,27 +6,36 @@ import com.massivecraft.factions.struct.Role;
|
||||
|
||||
public class CmdAutoClaim extends FCommand {
|
||||
public CmdAutoClaim() {
|
||||
super(); this.aliases.add("autoclaim");
|
||||
super();
|
||||
this.aliases.add("autoclaim");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction", "your");
|
||||
|
||||
this.permission = Permission.AUTOCLAIM.node; this.disableOnLock = true;
|
||||
this.permission = Permission.AUTOCLAIM.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction forFaction = this.argAsFaction(0, myFaction);
|
||||
if (forFaction == null || forFaction == fme.getAutoClaimFor()) {
|
||||
fme.setAutoClaimFor(null); msg("<i>Auto-claiming of land disabled."); return;
|
||||
fme.setAutoClaimFor(null);
|
||||
msg("<i>Auto-claiming of land disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fme.canClaimForFaction(forFaction)) {
|
||||
if (myFaction == forFaction) {
|
||||
msg("<b>You must be <h>%s<b> to claim land.", Role.MODERATOR.toString());
|
||||
} else { msg("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(fme)); }
|
||||
} else {
|
||||
msg("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(fme));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -8,7 +8,10 @@ import java.util.ArrayList;
|
||||
|
||||
public class CmdAutoHelp extends MCommand<P> {
|
||||
public CmdAutoHelp() {
|
||||
super(P.p); this.aliases.add("?"); this.aliases.add("h"); this.aliases.add("help");
|
||||
super(P.p);
|
||||
this.aliases.add("?");
|
||||
this.aliases.add("h");
|
||||
this.aliases.add("help");
|
||||
|
||||
this.setHelpShort("");
|
||||
|
||||
@ -17,7 +20,9 @@ public class CmdAutoHelp extends MCommand<P> {
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (this.commandChain.size() == 0) { return; }
|
||||
if (this.commandChain.size() == 0) {
|
||||
return;
|
||||
}
|
||||
MCommand<?> pcmd = this.commandChain.get(this.commandChain.size() - 1);
|
||||
|
||||
ArrayList<String> lines = new ArrayList<String>();
|
||||
|
@ -5,24 +5,32 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdBoom extends FCommand {
|
||||
public CmdBoom() {
|
||||
super(); this.aliases.add("noboom");
|
||||
super();
|
||||
this.aliases.add("noboom");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("on/off", "flip");
|
||||
|
||||
this.permission = Permission.NO_BOOM.node; this.disableOnLock = true;
|
||||
this.permission = Permission.NO_BOOM.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (!myFaction.isPeaceful()) {
|
||||
fme.msg("<b>This command is only usable by factions which are specially designated as peaceful."); return;
|
||||
fme.msg("<b>This command is only usable by factions which are specially designated as peaceful.");
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostNoBoom, "to toggle explosions", "for toggling explosions")) { return; }
|
||||
if (!payForCommand(Conf.econCostNoBoom, "to toggle explosions", "for toggling explosions")) {
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.setPeacefulExplosionsEnabled(this.argAsBool(0, !myFaction.getPeacefulExplosionsEnabled()));
|
||||
|
||||
|
@ -5,14 +5,19 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdBypass extends FCommand {
|
||||
public CmdBypass() {
|
||||
super(); this.aliases.add("bypass");
|
||||
super();
|
||||
this.aliases.add("bypass");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("on/off", "flip");
|
||||
|
||||
this.permission = Permission.BYPASS.node; this.disableOnLock = false;
|
||||
this.permission = Permission.BYPASS.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,7 +29,8 @@ public class CmdBypass extends FCommand {
|
||||
fme.msg("<i>You have enabled admin bypass mode. You will be able to build or destroy anywhere.");
|
||||
P.p.log(fme.getName() + " has ENABLED admin bypass mode.");
|
||||
} else {
|
||||
fme.msg("<i>You have disabled admin bypass mode."); P.p.log(fme.getName() + " DISABLED admin bypass mode.");
|
||||
fme.msg("<i>You have disabled admin bypass mode.");
|
||||
P.p.log(fme.getName() + " DISABLED admin bypass mode.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,33 +7,43 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdChat extends FCommand {
|
||||
|
||||
public CmdChat() {
|
||||
super(); this.aliases.add("c"); this.aliases.add("chat");
|
||||
super();
|
||||
this.aliases.add("c");
|
||||
this.aliases.add("chat");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("mode", "next");
|
||||
|
||||
this.permission = Permission.CHAT.node; this.disableOnLock = false;
|
||||
this.permission = Permission.CHAT.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = true; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (!Conf.factionOnlyChat) {
|
||||
msg("<b>The built in chat chat channels are disabled on this server."); return;
|
||||
msg("<b>The built in chat chat channels are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
String modeString = this.argAsString(0); ChatMode modeTarget = fme.getChatMode().getNext();
|
||||
String modeString = this.argAsString(0);
|
||||
ChatMode modeTarget = fme.getChatMode().getNext();
|
||||
|
||||
if (modeString != null) {
|
||||
modeString.toLowerCase(); if (modeString.startsWith("p")) {
|
||||
modeString.toLowerCase();
|
||||
if (modeString.startsWith("p")) {
|
||||
modeTarget = ChatMode.PUBLIC;
|
||||
} else if (modeString.startsWith("a")) {
|
||||
modeTarget = ChatMode.ALLIANCE;
|
||||
} else if (modeString.startsWith("f")) {
|
||||
modeTarget = ChatMode.FACTION;
|
||||
} else {
|
||||
msg("<b>Unrecognised chat mode. <i>Please enter either 'a','f' or 'p'"); return;
|
||||
msg("<b>Unrecognised chat mode. <i>Please enter either 'a','f' or 'p'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,18 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdChatSpy extends FCommand {
|
||||
public CmdChatSpy() {
|
||||
super(); this.aliases.add("chatspy");
|
||||
super();
|
||||
this.aliases.add("chatspy");
|
||||
|
||||
this.optionalArgs.put("on/off", "flip");
|
||||
|
||||
this.permission = Permission.CHATSPY.node; this.disableOnLock = false;
|
||||
this.permission = Permission.CHATSPY.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -19,9 +24,11 @@ public class CmdChatSpy extends FCommand {
|
||||
fme.setSpyingChat(this.argAsBool(0, !fme.isSpyingChat()));
|
||||
|
||||
if (fme.isSpyingChat()) {
|
||||
fme.msg("<i>You have enabled chat spying mode."); P.p.log(fme.getName() + " has ENABLED chat spying mode.");
|
||||
fme.msg("<i>You have enabled chat spying mode.");
|
||||
P.p.log(fme.getName() + " has ENABLED chat spying mode.");
|
||||
} else {
|
||||
fme.msg("<i>You have disabled chat spying mode."); P.p.log(fme.getName() + " DISABLED chat spying mode.");
|
||||
fme.msg("<i>You have disabled chat spying mode.");
|
||||
P.p.log(fme.getName() + " DISABLED chat spying mode.");
|
||||
}
|
||||
}
|
||||
}
|
@ -10,23 +10,31 @@ import com.massivecraft.factions.util.SpiralTask;
|
||||
public class CmdClaim extends FCommand {
|
||||
|
||||
public CmdClaim() {
|
||||
super(); this.aliases.add("claim");
|
||||
super();
|
||||
this.aliases.add("claim");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction", "your"); this.optionalArgs.put("radius", "1");
|
||||
this.optionalArgs.put("faction", "your");
|
||||
this.optionalArgs.put("radius", "1");
|
||||
|
||||
this.permission = Permission.CLAIM.node; this.disableOnLock = true;
|
||||
this.permission = Permission.CLAIM.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
// Read and validate input
|
||||
final Faction forFaction = this.argAsFaction(0, myFaction); int radius = this.argAsInt(1, 1);
|
||||
final Faction forFaction = this.argAsFaction(0, myFaction);
|
||||
int radius = this.argAsInt(1, 1);
|
||||
|
||||
if (radius < 1) {
|
||||
msg("<b>If you specify a radius, it must be at least 1."); return;
|
||||
msg("<b>If you specify a radius, it must be at least 1.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (radius < 2) {
|
||||
@ -35,7 +43,8 @@ public class CmdClaim extends FCommand {
|
||||
} else {
|
||||
// radius claim
|
||||
if (!Permission.CLAIM_RADIUS.has(sender, false)) {
|
||||
msg("<b>You do not have permission to claim in a radius."); return;
|
||||
msg("<b>You do not have permission to claim in a radius.");
|
||||
return;
|
||||
}
|
||||
|
||||
new SpiralTask(new FLocation(me), radius) {
|
||||
@ -45,8 +54,11 @@ public class CmdClaim extends FCommand {
|
||||
@Override
|
||||
public boolean work() {
|
||||
boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
|
||||
if (success) { failCount = 0; } else if (!success && failCount++ >= limit) {
|
||||
this.stop(); return false;
|
||||
if (success) {
|
||||
failCount = 0;
|
||||
} else if (!success && failCount++ >= limit) {
|
||||
this.stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -17,13 +17,19 @@ public class CmdConfig extends FCommand {
|
||||
private static HashMap<String, String> properFieldNames = new HashMap<String, String>();
|
||||
|
||||
public CmdConfig() {
|
||||
super(); this.aliases.add("config");
|
||||
super();
|
||||
this.aliases.add("config");
|
||||
|
||||
this.requiredArgs.add("setting"); this.requiredArgs.add("value"); this.errorOnToManyArgs = false;
|
||||
this.requiredArgs.add("setting");
|
||||
this.requiredArgs.add("value");
|
||||
this.errorOnToManyArgs = false;
|
||||
|
||||
this.permission = Permission.CONFIG.node; this.disableOnLock = true;
|
||||
this.permission = Permission.CONFIG.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@ -32,22 +38,27 @@ public class CmdConfig extends FCommand {
|
||||
// store a lookup map of lowercase field names paired with proper capitalization field names
|
||||
// that way, if the person using this command messes up the capitalization, we can fix that
|
||||
if (properFieldNames.isEmpty()) {
|
||||
Field[] fields = Conf.class.getDeclaredFields(); for (int i = 0; i < fields.length; i++) {
|
||||
Field[] fields = Conf.class.getDeclaredFields();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
properFieldNames.put(fields[i].getName().toLowerCase(), fields[i].getName());
|
||||
}
|
||||
}
|
||||
|
||||
String field = this.argAsString(0).toLowerCase(); if (field.startsWith("\"") && field.endsWith("\"")) {
|
||||
String field = this.argAsString(0).toLowerCase();
|
||||
if (field.startsWith("\"") && field.endsWith("\"")) {
|
||||
field = field.substring(1, field.length() - 1);
|
||||
} String fieldName = properFieldNames.get(field);
|
||||
}
|
||||
String fieldName = properFieldNames.get(field);
|
||||
|
||||
if (fieldName == null || fieldName.isEmpty()) {
|
||||
msg("<b>No configuration setting \"<h>%s<b>\" exists.", field); return;
|
||||
msg("<b>No configuration setting \"<h>%s<b>\" exists.", field);
|
||||
return;
|
||||
}
|
||||
|
||||
String success;
|
||||
|
||||
String value = args.get(1); for (int i = 2; i < args.size(); i++) {
|
||||
String value = args.get(1);
|
||||
for (int i = 2; i < args.size(); i++) {
|
||||
value += ' ' + args.get(i);
|
||||
}
|
||||
|
||||
@ -56,7 +67,8 @@ public class CmdConfig extends FCommand {
|
||||
|
||||
// boolean
|
||||
if (target.getType() == boolean.class) {
|
||||
boolean targetValue = this.strAsBool(value); target.setBoolean(null, targetValue);
|
||||
boolean targetValue = this.strAsBool(value);
|
||||
target.setBoolean(null, targetValue);
|
||||
|
||||
if (targetValue) {
|
||||
success = "\"" + fieldName + "\" option set to true (enabled).";
|
||||
@ -68,17 +80,20 @@ public class CmdConfig extends FCommand {
|
||||
// int
|
||||
else if (target.getType() == int.class) {
|
||||
try {
|
||||
int intVal = Integer.parseInt(value); target.setInt(null, intVal);
|
||||
int intVal = Integer.parseInt(value);
|
||||
target.setInt(null, intVal);
|
||||
success = "\"" + fieldName + "\" option set to " + intVal + ".";
|
||||
} catch (NumberFormatException ex) {
|
||||
sendMessage("Cannot set \"" + fieldName + "\": integer (whole number) value required."); return;
|
||||
sendMessage("Cannot set \"" + fieldName + "\": integer (whole number) value required.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// long
|
||||
else if (target.getType() == long.class) {
|
||||
try {
|
||||
long longVal = Long.parseLong(value); target.setLong(null, longVal);
|
||||
long longVal = Long.parseLong(value);
|
||||
target.setLong(null, longVal);
|
||||
success = "\"" + fieldName + "\" option set to " + longVal + ".";
|
||||
} catch (NumberFormatException ex) {
|
||||
sendMessage("Cannot set \"" + fieldName + "\": long integer (whole number) value required.");
|
||||
@ -89,38 +104,46 @@ public class CmdConfig extends FCommand {
|
||||
// double
|
||||
else if (target.getType() == double.class) {
|
||||
try {
|
||||
double doubleVal = Double.parseDouble(value); target.setDouble(null, doubleVal);
|
||||
double doubleVal = Double.parseDouble(value);
|
||||
target.setDouble(null, doubleVal);
|
||||
success = "\"" + fieldName + "\" option set to " + doubleVal + ".";
|
||||
} catch (NumberFormatException ex) {
|
||||
sendMessage("Cannot set \"" + fieldName + "\": double (numeric) value required."); return;
|
||||
sendMessage("Cannot set \"" + fieldName + "\": double (numeric) value required.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// float
|
||||
else if (target.getType() == float.class) {
|
||||
try {
|
||||
float floatVal = Float.parseFloat(value); target.setFloat(null, floatVal);
|
||||
float floatVal = Float.parseFloat(value);
|
||||
target.setFloat(null, floatVal);
|
||||
success = "\"" + fieldName + "\" option set to " + floatVal + ".";
|
||||
} catch (NumberFormatException ex) {
|
||||
sendMessage("Cannot set \"" + fieldName + "\": float (numeric) value required."); return;
|
||||
sendMessage("Cannot set \"" + fieldName + "\": float (numeric) value required.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// String
|
||||
else if (target.getType() == String.class) {
|
||||
target.set(null, value); success = "\"" + fieldName + "\" option set to \"" + value + "\".";
|
||||
target.set(null, value);
|
||||
success = "\"" + fieldName + "\" option set to \"" + value + "\".";
|
||||
}
|
||||
|
||||
// ChatColor
|
||||
else if (target.getType() == ChatColor.class) {
|
||||
ChatColor newColor = null; try {
|
||||
ChatColor newColor = null;
|
||||
try {
|
||||
newColor = ChatColor.valueOf(value.toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
|
||||
} if (newColor == null) {
|
||||
}
|
||||
if (newColor == null) {
|
||||
sendMessage("Cannot set \"" + fieldName + "\": \"" + value.toUpperCase() + "\" is not a valid color.");
|
||||
return;
|
||||
} target.set(null, newColor);
|
||||
}
|
||||
target.set(null, newColor);
|
||||
success = "\"" + fieldName + "\" color option set to \"" + value.toUpperCase() + "\".";
|
||||
}
|
||||
|
||||
@ -137,11 +160,13 @@ public class CmdConfig extends FCommand {
|
||||
|
||||
// Set<Material>
|
||||
else if (innerType == Material.class) {
|
||||
Material newMat = null; try {
|
||||
Material newMat = null;
|
||||
try {
|
||||
newMat = Material.valueOf(value.toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
|
||||
} if (newMat == null) {
|
||||
}
|
||||
if (newMat == null) {
|
||||
sendMessage("Cannot change \"" + fieldName + "\" set: \"" + value.toUpperCase() + "\" is not a valid material.");
|
||||
return;
|
||||
}
|
||||
@ -150,12 +175,14 @@ public class CmdConfig extends FCommand {
|
||||
|
||||
// Material already present, so remove it
|
||||
if (matSet.contains(newMat)) {
|
||||
matSet.remove(newMat); target.set(null, matSet);
|
||||
matSet.remove(newMat);
|
||||
target.set(null, matSet);
|
||||
success = "\"" + fieldName + "\" set: Material \"" + value.toUpperCase() + "\" removed.";
|
||||
}
|
||||
// Material not present yet, add it
|
||||
else {
|
||||
matSet.add(newMat); target.set(null, matSet);
|
||||
matSet.add(newMat);
|
||||
target.set(null, matSet);
|
||||
success = "\"" + fieldName + "\" set: Material \"" + value.toUpperCase() + "\" added.";
|
||||
}
|
||||
}
|
||||
@ -166,12 +193,14 @@ public class CmdConfig extends FCommand {
|
||||
|
||||
// String already present, so remove it
|
||||
if (stringSet.contains(value)) {
|
||||
stringSet.remove(value); target.set(null, stringSet);
|
||||
stringSet.remove(value);
|
||||
target.set(null, stringSet);
|
||||
success = "\"" + fieldName + "\" set: \"" + value + "\" removed.";
|
||||
}
|
||||
// String not present yet, add it
|
||||
else {
|
||||
stringSet.add(value); target.set(null, stringSet);
|
||||
stringSet.add(value);
|
||||
target.set(null, stringSet);
|
||||
success = "\"" + fieldName + "\" set: \"" + value + "\" added.";
|
||||
}
|
||||
}
|
||||
@ -192,14 +221,18 @@ public class CmdConfig extends FCommand {
|
||||
sendMessage("Configuration setting \"" + fieldName + "\" couldn't be matched, though it should be... please report this error.");
|
||||
return;
|
||||
} catch (IllegalAccessException ex) {
|
||||
sendMessage("Error setting configuration setting \"" + fieldName + "\" to \"" + value + "\"."); return;
|
||||
sendMessage("Error setting configuration setting \"" + fieldName + "\" to \"" + value + "\".");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!success.isEmpty()) {
|
||||
if (sender instanceof Player) {
|
||||
sendMessage(success); P.p.log(success + " Command was run by " + fme.getName() + ".");
|
||||
sendMessage(success);
|
||||
P.p.log(success + " Command was run by " + fme.getName() + ".");
|
||||
} else // using P.p.log() instead of sendMessage if run from server console so that "[Factions v#.#.#]" is prepended in server log
|
||||
{ P.p.log(success); }
|
||||
{
|
||||
P.p.log(success);
|
||||
}
|
||||
}
|
||||
// save change to disk
|
||||
Conf.save();
|
||||
|
@ -12,14 +12,19 @@ import java.util.ArrayList;
|
||||
|
||||
public class CmdCreate extends FCommand {
|
||||
public CmdCreate() {
|
||||
super(); this.aliases.add("create");
|
||||
super();
|
||||
this.aliases.add("create");
|
||||
|
||||
this.requiredArgs.add("faction tag");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.CREATE.node; this.disableOnLock = true;
|
||||
this.permission = Permission.CREATE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,32 +32,44 @@ public class CmdCreate extends FCommand {
|
||||
String tag = this.argAsString(0);
|
||||
|
||||
if (fme.hasFaction()) {
|
||||
msg("<b>You must leave your current faction first."); return;
|
||||
msg("<b>You must leave your current faction first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Factions.i.isTagTaken(tag)) {
|
||||
msg("<b>That tag is already in use."); return;
|
||||
msg("<b>That tag is already in use.");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> tagValidationErrors = Factions.validateTag(tag); if (tagValidationErrors.size() > 0) {
|
||||
sendMessage(tagValidationErrors); return;
|
||||
ArrayList<String> tagValidationErrors = Factions.validateTag(tag);
|
||||
if (tagValidationErrors.size() > 0) {
|
||||
sendMessage(tagValidationErrors);
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
|
||||
if (!canAffordCommand(Conf.econCostCreate, "to create a new faction")) { return; }
|
||||
if (!canAffordCommand(Conf.econCostCreate, "to create a new faction")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// trigger the faction creation event (cancellable)
|
||||
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
|
||||
Bukkit.getServer().getPluginManager().callEvent(createEvent); if (createEvent.isCancelled()) { return; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(createEvent);
|
||||
if (createEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
if (!payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) { return; }
|
||||
if (!payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction faction = Factions.i.create();
|
||||
|
||||
// TODO: Why would this even happen??? Auto increment clash??
|
||||
if (faction == null) {
|
||||
msg("<b>There was an internal error while trying to create your faction. Please try again."); return;
|
||||
msg("<b>There was an internal error while trying to create your faction. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
// finish setting up the Faction
|
||||
@ -64,7 +81,8 @@ public class CmdCreate extends FCommand {
|
||||
// join event cannot be cancelled or you'll have an empty faction
|
||||
|
||||
// finish setting up the FPlayer
|
||||
fme.setRole(Role.ADMIN); fme.setFaction(faction);
|
||||
fme.setRole(Role.ADMIN);
|
||||
fme.setFaction(faction);
|
||||
|
||||
for (FPlayer follower : FPlayers.i.getOnline()) {
|
||||
follower.msg("%s<i> created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower));
|
||||
@ -72,7 +90,9 @@ public class CmdCreate extends FCommand {
|
||||
|
||||
msg("<i>You should now: %s", p.cmdBase.cmdDescription.getUseageTemplate());
|
||||
|
||||
if (Conf.logFactionCreate) { P.p.log(fme.getName() + " created a new faction: " + tag); }
|
||||
if (Conf.logFactionCreate) {
|
||||
P.p.log(fme.getName() + " created a new faction: " + tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,23 +6,33 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdDeinvite extends FCommand {
|
||||
|
||||
public CmdDeinvite() {
|
||||
super(); this.aliases.add("deinvite"); this.aliases.add("deinv");
|
||||
super();
|
||||
this.aliases.add("deinvite");
|
||||
this.aliases.add("deinv");
|
||||
|
||||
this.requiredArgs.add("player name");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.DEINVITE.node; this.disableOnLock = true;
|
||||
this.permission = Permission.DEINVITE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0); if (you == null) { return; }
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getFaction() == myFaction) {
|
||||
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
|
||||
msg("<i>You might want to: %s", p.cmdBase.cmdKick.getUseageTemplate(false)); return;
|
||||
msg("<i>You might want to: %s", p.cmdBase.cmdKick.getUseageTemplate(false));
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.deinvite(you);
|
||||
|
@ -8,14 +8,20 @@ import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
|
||||
public class CmdDescription extends FCommand {
|
||||
public CmdDescription() {
|
||||
super(); this.aliases.add("desc");
|
||||
super();
|
||||
this.aliases.add("desc");
|
||||
|
||||
this.requiredArgs.add("desc"); this.errorOnToManyArgs = false;
|
||||
this.requiredArgs.add("desc");
|
||||
this.errorOnToManyArgs = false;
|
||||
//this.optionalArgs
|
||||
|
||||
this.permission = Permission.DESCRIPTION.node; this.disableOnLock = true;
|
||||
this.permission = Permission.DESCRIPTION.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,7 +35,8 @@ public class CmdDescription extends FCommand {
|
||||
|
||||
if (!Conf.broadcastDescriptionChanges) {
|
||||
fme.msg("You have changed the description for <h>%s<i> to:", myFaction.describeTo(fme));
|
||||
fme.sendMessage(myFaction.getDescription()); return;
|
||||
fme.sendMessage(myFaction.getDescription());
|
||||
return;
|
||||
}
|
||||
|
||||
// Broadcast the description to everyone
|
||||
|
@ -11,26 +11,35 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class CmdDisband extends FCommand {
|
||||
public CmdDisband() {
|
||||
super(); this.aliases.add("disband");
|
||||
super();
|
||||
this.aliases.add("disband");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction tag", "yours");
|
||||
|
||||
this.permission = Permission.DISBAND.node; this.disableOnLock = true;
|
||||
this.permission = Permission.DISBAND.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
// The faction, default to your own.. but null if console sender.
|
||||
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); if (faction == null) { return; }
|
||||
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isMyFaction = fme == null ? false : faction == myFaction;
|
||||
|
||||
if (isMyFaction) {
|
||||
if (!assertMinRole(Role.ADMIN)) { return; }
|
||||
if (!assertMinRole(Role.ADMIN)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!Permission.DISBAND_ANY.has(sender, true)) {
|
||||
return;
|
||||
@ -38,13 +47,19 @@ public class CmdDisband extends FCommand {
|
||||
}
|
||||
|
||||
if (!faction.isNormal()) {
|
||||
msg("<i>You cannot disband the Wilderness, SafeZone, or WarZone."); return;
|
||||
} if (faction.isPermanent()) {
|
||||
msg("<i>This faction is designated as permanent, so you cannot disband it."); return;
|
||||
msg("<i>You cannot disband the Wilderness, SafeZone, or WarZone.");
|
||||
return;
|
||||
}
|
||||
if (faction.isPermanent()) {
|
||||
msg("<i>This faction is designated as permanent, so you cannot disband it.");
|
||||
return;
|
||||
}
|
||||
|
||||
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId());
|
||||
Bukkit.getServer().getPluginManager().callEvent(disbandEvent); if (disbandEvent.isCancelled()) { return; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
|
||||
if (disbandEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send FPlayerLeaveEvent for each player in the faction
|
||||
for (FPlayer fplayer : faction.getFPlayers()) {
|
||||
@ -59,7 +74,8 @@ public class CmdDisband extends FCommand {
|
||||
} else {
|
||||
fplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getTag(fplayer));
|
||||
}
|
||||
} if (Conf.logFactionDisband) {
|
||||
}
|
||||
if (Conf.logFactionDisband) {
|
||||
P.p.log("The faction " + faction.getTag() + " (" + faction.getId() + ") was disbanded by " + (senderIsConsole ? "console command" : fme.getName()) + ".");
|
||||
}
|
||||
|
||||
|
@ -11,20 +11,28 @@ import java.util.ArrayList;
|
||||
public class CmdHelp extends FCommand {
|
||||
|
||||
public CmdHelp() {
|
||||
super(); this.aliases.add("help"); this.aliases.add("h"); this.aliases.add("?");
|
||||
super();
|
||||
this.aliases.add("help");
|
||||
this.aliases.add("h");
|
||||
this.aliases.add("?");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("page", "1");
|
||||
|
||||
this.permission = Permission.HELP.node; this.disableOnLock = false;
|
||||
this.permission = Permission.HELP.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (helpPages == null) { updateHelp(); }
|
||||
if (helpPages == null) {
|
||||
updateHelp();
|
||||
}
|
||||
|
||||
int page = this.argAsInt(0, 1);
|
||||
|
||||
@ -33,8 +41,10 @@ public class CmdHelp extends FCommand {
|
||||
page -= 1;
|
||||
|
||||
if (page < 0 || page >= helpPages.size()) {
|
||||
msg("<b>This page does not exist"); return;
|
||||
} sendMessage(helpPages.get(page));
|
||||
msg("<b>This page does not exist");
|
||||
return;
|
||||
}
|
||||
sendMessage(helpPages.get(page));
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
@ -44,9 +54,11 @@ public class CmdHelp extends FCommand {
|
||||
public ArrayList<ArrayList<String>> helpPages;
|
||||
|
||||
public void updateHelp() {
|
||||
helpPages = new ArrayList<ArrayList<String>>(); ArrayList<String> pageLines;
|
||||
helpPages = new ArrayList<ArrayList<String>>();
|
||||
ArrayList<String> pageLines;
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add(p.cmdBase.cmdHelp.getUseageTemplate(true));
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.cmdBase.cmdHelp.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdList.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdShow.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdPower.getUseageTemplate(true));
|
||||
@ -54,9 +66,11 @@ public class CmdHelp extends FCommand {
|
||||
pageLines.add(p.cmdBase.cmdLeave.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdChat.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdHome.getUseageTemplate(true));
|
||||
pageLines.add(p.txt.parse("<i>Learn how to create a faction on the next page.")); helpPages.add(pageLines);
|
||||
pageLines.add(p.txt.parse("<i>Learn how to create a faction on the next page."));
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add(p.cmdBase.cmdCreate.getUseageTemplate(true));
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.cmdBase.cmdCreate.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdDescription.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdTag.getUseageTemplate(true));
|
||||
pageLines.add(p.txt.parse("<i>You might want to close it and use invitations:"));
|
||||
@ -64,18 +78,25 @@ public class CmdHelp extends FCommand {
|
||||
pageLines.add(p.cmdBase.cmdInvite.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdDeinvite.getUseageTemplate(true));
|
||||
pageLines.add(p.txt.parse("<i>And don't forget to set your home:"));
|
||||
pageLines.add(p.cmdBase.cmdSethome.getUseageTemplate(true)); helpPages.add(pageLines);
|
||||
pageLines.add(p.cmdBase.cmdSethome.getUseageTemplate(true));
|
||||
helpPages.add(pageLines);
|
||||
|
||||
if (Econ.isSetup() && Conf.econEnabled && Conf.bankEnabled) {
|
||||
pageLines = new ArrayList<String>(); pageLines.add("");
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add("");
|
||||
pageLines.add(p.txt.parse("<i>Your faction has a bank which is used to pay for certain"));
|
||||
pageLines.add(p.txt.parse("<i>things, so it will need to have money deposited into it."));
|
||||
pageLines.add(p.txt.parse("<i>To learn more, use the money command.")); pageLines.add("");
|
||||
pageLines.add(p.cmdBase.cmdMoney.getUseageTemplate(true)); pageLines.add(""); pageLines.add("");
|
||||
pageLines.add(""); helpPages.add(pageLines);
|
||||
pageLines.add(p.txt.parse("<i>To learn more, use the money command."));
|
||||
pageLines.add("");
|
||||
pageLines.add(p.cmdBase.cmdMoney.getUseageTemplate(true));
|
||||
pageLines.add("");
|
||||
pageLines.add("");
|
||||
pageLines.add("");
|
||||
helpPages.add(pageLines);
|
||||
}
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add(p.cmdBase.cmdClaim.getUseageTemplate(true));
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.cmdBase.cmdClaim.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdAutoClaim.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdUnclaim.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdUnclaimall.getUseageTemplate(true));
|
||||
@ -86,16 +107,20 @@ public class CmdHelp extends FCommand {
|
||||
pageLines.add(p.txt.parse("<i>Player titles are just for fun. No rules connected to them."));
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add(p.cmdBase.cmdMap.getUseageTemplate(true));
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.cmdBase.cmdMap.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdBoom.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdOwner.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdOwnerList.getUseageTemplate(true));
|
||||
pageLines.add(p.txt.parse("<i>Claimed land with ownership set is further protected so"));
|
||||
pageLines.add(p.txt.parse("<i>that only the owner(s), faction admin, and possibly the"));
|
||||
pageLines.add(p.txt.parse("<i>faction moderators have full access.")); helpPages.add(pageLines);
|
||||
pageLines.add(p.txt.parse("<i>faction moderators have full access."));
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add(p.cmdBase.cmdDisband.getUseageTemplate(true));
|
||||
pageLines.add(""); pageLines.add(p.cmdBase.cmdRelationAlly.getUseageTemplate(true));
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.cmdBase.cmdDisband.getUseageTemplate(true));
|
||||
pageLines.add("");
|
||||
pageLines.add(p.cmdBase.cmdRelationAlly.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdRelationNeutral.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdRelationEnemy.getUseageTemplate(true));
|
||||
pageLines.add(p.txt.parse("<i>Set the relation you WISH to have with another faction."));
|
||||
@ -104,9 +129,11 @@ public class CmdHelp extends FCommand {
|
||||
pageLines.add(p.txt.parse("<i>If ONE faction chooses \"enemy\" you will be enemies."));
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add(p.txt.parse("<i>You can never hurt members or allies."));
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.txt.parse("<i>You can never hurt members or allies."));
|
||||
pageLines.add(p.txt.parse("<i>You can not hurt neutrals in their own territory."));
|
||||
pageLines.add(p.txt.parse("<i>You can always hurt enemies and players without faction.")); pageLines.add("");
|
||||
pageLines.add(p.txt.parse("<i>You can always hurt enemies and players without faction."));
|
||||
pageLines.add("");
|
||||
pageLines.add(p.txt.parse("<i>Damage from enemies is reduced in your own territory."));
|
||||
pageLines.add(p.txt.parse("<i>When you die you lose power. It is restored over time."));
|
||||
pageLines.add(p.txt.parse("<i>The power of a faction is the sum of all member power."));
|
||||
@ -117,14 +144,17 @@ public class CmdHelp extends FCommand {
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.txt.parse("<i>Only faction members can build and destroy in their own"));
|
||||
pageLines.add(p.txt.parse("<i>territory. Usage of the following items is also restricted:"));
|
||||
pageLines.add(p.txt.parse("<i>Door, Chest, Furnace, Dispenser, Diode.")); pageLines.add("");
|
||||
pageLines.add(p.txt.parse("<i>Door, Chest, Furnace, Dispenser, Diode."));
|
||||
pageLines.add("");
|
||||
pageLines.add(p.txt.parse("<i>Make sure to put pressure plates in front of doors for your"));
|
||||
pageLines.add(p.txt.parse("<i>guest visitors. Otherwise they can't get through. You can"));
|
||||
pageLines.add(p.txt.parse("<i>also use this to create member only areas."));
|
||||
pageLines.add(p.txt.parse("<i>As dispensers are protected, you can create traps without"));
|
||||
pageLines.add(p.txt.parse("<i>worrying about those arrows getting stolen.")); helpPages.add(pageLines);
|
||||
pageLines.add(p.txt.parse("<i>worrying about those arrows getting stolen."));
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add("Finally some commands for the server admins:");
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add("Finally some commands for the server admins:");
|
||||
pageLines.add(p.cmdBase.cmdBypass.getUseageTemplate(true));
|
||||
pageLines.add(p.txt.parse("<c>/f claim safezone <i>claim land for the Safe Zone"));
|
||||
pageLines.add(p.txt.parse("<c>/f claim warzone <i>claim land for the War Zone"));
|
||||
@ -132,20 +162,25 @@ public class CmdHelp extends FCommand {
|
||||
pageLines.add(p.cmdBase.cmdSafeunclaimall.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdWarunclaimall.getUseageTemplate(true));
|
||||
pageLines.add(p.txt.parse("<i>Note: " + p.cmdBase.cmdUnclaim.getUseageTemplate(false) + P.p.txt.parse("<i>") + " works on safe/war zones as well."));
|
||||
pageLines.add(p.cmdBase.cmdPeaceful.getUseageTemplate(true)); helpPages.add(pageLines);
|
||||
pageLines.add(p.cmdBase.cmdPeaceful.getUseageTemplate(true));
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add(p.txt.parse("<i>More commands for server admins:"));
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.txt.parse("<i>More commands for server admins:"));
|
||||
pageLines.add(p.cmdBase.cmdChatSpy.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdPermanent.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdPermanentPower.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdPowerBoost.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdConfig.getUseageTemplate(true)); helpPages.add(pageLines);
|
||||
pageLines.add(p.cmdBase.cmdConfig.getUseageTemplate(true));
|
||||
helpPages.add(pageLines);
|
||||
|
||||
pageLines = new ArrayList<String>(); pageLines.add(p.txt.parse("<i>Even more commands for server admins:"));
|
||||
pageLines = new ArrayList<String>();
|
||||
pageLines.add(p.txt.parse("<i>Even more commands for server admins:"));
|
||||
pageLines.add(p.cmdBase.cmdLock.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdReload.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdSaveAll.getUseageTemplate(true));
|
||||
pageLines.add(p.cmdBase.cmdVersion.getUseageTemplate(true)); helpPages.add(pageLines);
|
||||
pageLines.add(p.cmdBase.cmdVersion.getUseageTemplate(true));
|
||||
helpPages.add(pageLines);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,58 +17,82 @@ import java.util.List;
|
||||
public class CmdHome extends FCommand {
|
||||
|
||||
public CmdHome() {
|
||||
super(); this.aliases.add("home");
|
||||
super();
|
||||
this.aliases.add("home");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.HOME.node; this.disableOnLock = false;
|
||||
this.permission = Permission.HOME.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = true; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
// TODO: Hide this command on help also.
|
||||
if (!Conf.homesEnabled) {
|
||||
fme.msg("<b>Sorry, Faction homes are disabled on this server."); return;
|
||||
fme.msg("<b>Sorry, Faction homes are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Conf.homesTeleportCommandEnabled) {
|
||||
fme.msg("<b>Sorry, the ability to teleport to Faction homes is disabled on this server."); return;
|
||||
fme.msg("<b>Sorry, the ability to teleport to Faction homes is disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!myFaction.hasHome()) {
|
||||
fme.msg("<b>Your faction does not have a home. " + (fme.getRole().value < Role.MODERATOR.value ? "<i> Ask your leader to:" : "<i>You should:"));
|
||||
fme.sendMessage(p.cmdBase.cmdSethome.getUseageTemplate()); return;
|
||||
fme.sendMessage(p.cmdBase.cmdSethome.getUseageTemplate());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Conf.homesTeleportAllowedFromEnemyTerritory && fme.isInEnemyTerritory()) {
|
||||
fme.msg("<b>You cannot teleport to your faction home while in the territory of an enemy faction."); return;
|
||||
fme.msg("<b>You cannot teleport to your faction home while in the territory of an enemy faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID()) {
|
||||
fme.msg("<b>You cannot teleport to your faction home while in a different world."); return;
|
||||
fme.msg("<b>You cannot teleport to your faction home while in a different world.");
|
||||
return;
|
||||
}
|
||||
|
||||
Faction faction = Board.getFactionAt(new FLocation(me.getLocation())); Location loc = me.getLocation().clone();
|
||||
Faction faction = Board.getFactionAt(new FLocation(me.getLocation()));
|
||||
Location loc = me.getLocation().clone();
|
||||
|
||||
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
|
||||
if (Conf.homesTeleportAllowedEnemyDistance > 0 &&
|
||||
!faction.isSafeZone() &&
|
||||
(!fme.isInOwnTerritory() || (fme.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) {
|
||||
World w = loc.getWorld(); double x = loc.getX(); double y = loc.getY(); double z = loc.getZ();
|
||||
World w = loc.getWorld();
|
||||
double x = loc.getX();
|
||||
double y = loc.getY();
|
||||
double z = loc.getZ();
|
||||
|
||||
for (Player p : me.getServer().getOnlinePlayers()) {
|
||||
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) { continue; }
|
||||
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FPlayer fp = FPlayers.i.get(p); if (fme.getRelationTo(fp) != Relation.ENEMY) { continue; }
|
||||
FPlayer fp = FPlayers.i.get(p);
|
||||
if (fme.getRelationTo(fp) != Relation.ENEMY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Location l = p.getLocation(); double dx = Math.abs(x - l.getX()); double dy = Math.abs(y - l.getY());
|
||||
double dz = Math.abs(z - l.getZ()); double max = Conf.homesTeleportAllowedEnemyDistance;
|
||||
Location l = p.getLocation();
|
||||
double dx = Math.abs(x - l.getX());
|
||||
double dy = Math.abs(y - l.getY());
|
||||
double dz = Math.abs(z - l.getZ());
|
||||
double max = Conf.homesTeleportAllowedEnemyDistance;
|
||||
|
||||
// box-shaped distance check
|
||||
if (dx > max || dy > max || dz > max) { continue; }
|
||||
if (dx > max || dy > max || dz > max) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fme.msg("<b>You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
|
||||
return;
|
||||
@ -76,7 +100,9 @@ public class CmdHome extends FCommand {
|
||||
}
|
||||
|
||||
// if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown)
|
||||
if (Essentials.handleTeleport(me, myFaction.getHome())) { return; }
|
||||
if (Essentials.handleTeleport(me, myFaction.getHome())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) {
|
||||
@ -85,8 +111,10 @@ public class CmdHome extends FCommand {
|
||||
|
||||
// Create a smoke effect
|
||||
if (Conf.homesTeleportCommandSmokeEffectEnabled) {
|
||||
List<Location> smokeLocations = new ArrayList<Location>(); smokeLocations.add(loc);
|
||||
smokeLocations.add(loc.add(0, 1, 0)); smokeLocations.add(myFaction.getHome());
|
||||
List<Location> smokeLocations = new ArrayList<Location>();
|
||||
smokeLocations.add(loc);
|
||||
smokeLocations.add(loc.add(0, 1, 0));
|
||||
smokeLocations.add(myFaction.getHome());
|
||||
smokeLocations.add(myFaction.getHome().clone().add(0, 1, 0));
|
||||
SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
|
||||
}
|
||||
|
@ -6,27 +6,39 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdInvite extends FCommand {
|
||||
public CmdInvite() {
|
||||
super(); this.aliases.add("invite"); this.aliases.add("inv");
|
||||
super();
|
||||
this.aliases.add("invite");
|
||||
this.aliases.add("inv");
|
||||
|
||||
this.requiredArgs.add("player name");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.INVITE.node; this.disableOnLock = true;
|
||||
this.permission = Permission.INVITE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0); if (you == null) { return; }
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getFaction() == myFaction) {
|
||||
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
|
||||
msg("<i>You might want to: " + p.cmdBase.cmdKick.getUseageTemplate(false)); return;
|
||||
msg("<i>You might want to: " + p.cmdBase.cmdKick.getUseageTemplate(false));
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostInvite, "to invite someone", "for inviting someone")) { return; }
|
||||
if (!payForCommand(Conf.econCostInvite, "to invite someone", "for inviting someone")) {
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.invite(you);
|
||||
|
||||
|
@ -7,27 +7,39 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class CmdJoin extends FCommand {
|
||||
public CmdJoin() {
|
||||
super(); this.aliases.add("join");
|
||||
super();
|
||||
this.aliases.add("join");
|
||||
|
||||
this.requiredArgs.add("faction name"); this.optionalArgs.put("player", "you");
|
||||
this.requiredArgs.add("faction name");
|
||||
this.optionalArgs.put("player", "you");
|
||||
|
||||
this.permission = Permission.JOIN.node; this.disableOnLock = true;
|
||||
this.permission = Permission.JOIN.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction faction = this.argAsFaction(0); if (faction == null) { return; }
|
||||
Faction faction = this.argAsFaction(0);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false); boolean samePlayer = fplayer == fme;
|
||||
FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false);
|
||||
boolean samePlayer = fplayer == fme;
|
||||
|
||||
if (!samePlayer && !Permission.JOIN_OTHERS.has(sender, false)) {
|
||||
msg("<b>You do not have permission to move other players into a faction."); return;
|
||||
msg("<b>You do not have permission to move other players into a faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!faction.isNormal()) {
|
||||
msg("<b>Players may only join normal factions. This is a system faction."); return;
|
||||
msg("<b>Players may only join normal factions. This is a system faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (faction == fplayer.getFaction()) {
|
||||
@ -46,35 +58,50 @@ public class CmdJoin extends FCommand {
|
||||
}
|
||||
|
||||
if (!Conf.canLeaveWithNegativePower && fplayer.getPower() < 0) {
|
||||
msg("<b>%s cannot join a faction with a negative power level.", fplayer.describeTo(fme, true)); return;
|
||||
msg("<b>%s cannot join a faction with a negative power level.", fplayer.describeTo(fme, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(faction.getOpen() || faction.isInvited(fplayer) || fme.isAdminBypassing() || Permission.JOIN_ANY.has(sender, false))) {
|
||||
msg("<i>This faction requires invitation.");
|
||||
if (samePlayer) { faction.msg("%s<i> tried to join your faction.", fplayer.describeTo(faction, true)); }
|
||||
if (samePlayer) {
|
||||
faction.msg("%s<i> tried to join your faction.", fplayer.describeTo(faction, true));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
|
||||
if (samePlayer && !canAffordCommand(Conf.econCostJoin, "to join a faction")) { return; }
|
||||
if (samePlayer && !canAffordCommand(Conf.econCostJoin, "to join a faction")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// trigger the join event (cancellable)
|
||||
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND);
|
||||
Bukkit.getServer().getPluginManager().callEvent(joinEvent); if (joinEvent.isCancelled()) { return; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
|
||||
if (joinEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
if (samePlayer && !payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) { return; }
|
||||
if (samePlayer && !payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) {
|
||||
return;
|
||||
}
|
||||
|
||||
fme.msg("<i>%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme));
|
||||
|
||||
if (!samePlayer) {
|
||||
fplayer.msg("<i>%s moved you into the faction %s.", fme.describeTo(fplayer, true), faction.getTag(fplayer));
|
||||
} faction.msg("<i>%s joined your faction.", fplayer.describeTo(faction, true));
|
||||
}
|
||||
faction.msg("<i>%s joined your faction.", fplayer.describeTo(faction, true));
|
||||
|
||||
fplayer.resetFactionData(); fplayer.setFaction(faction); faction.deinvite(fplayer);
|
||||
fplayer.resetFactionData();
|
||||
fplayer.setFaction(faction);
|
||||
faction.deinvite(fplayer);
|
||||
|
||||
if (Conf.logFactionJoin) {
|
||||
if (samePlayer) { P.p.log("%s joined the faction %s.", fplayer.getName(), faction.getTag()); } else {
|
||||
if (samePlayer) {
|
||||
P.p.log("%s joined the faction %s.", fplayer.getName(), faction.getTag());
|
||||
} else {
|
||||
P.p.log("%s moved the player %s into the faction %s.", fme.getName(), fplayer.getName(), faction.getTag());
|
||||
}
|
||||
}
|
||||
|
@ -12,23 +12,32 @@ import org.bukkit.Bukkit;
|
||||
public class CmdKick extends FCommand {
|
||||
|
||||
public CmdKick() {
|
||||
super(); this.aliases.add("kick");
|
||||
super();
|
||||
this.aliases.add("kick");
|
||||
|
||||
this.requiredArgs.add("player name");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.KICK.node; this.disableOnLock = false;
|
||||
this.permission = Permission.KICK.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0); if (you == null) { return; }
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fme == you) {
|
||||
msg("<b>You cannot kick yourself.");
|
||||
msg("<i>You might want to: %s", p.cmdBase.cmdLeave.getUseageTemplate(false)); return;
|
||||
msg("<i>You might want to: %s", p.cmdBase.cmdLeave.getUseageTemplate(false));
|
||||
return;
|
||||
}
|
||||
|
||||
Faction yourFaction = you.getFaction();
|
||||
@ -36,25 +45,33 @@ public class CmdKick extends FCommand {
|
||||
// players with admin-level "disband" permission can bypass these requirements
|
||||
if (!Permission.KICK_ANY.has(sender)) {
|
||||
if (yourFaction != myFaction) {
|
||||
msg("%s<b> is not a member of %s", you.describeTo(fme, true), myFaction.describeTo(fme)); return;
|
||||
msg("%s<b> is not a member of %s", you.describeTo(fme, true), myFaction.describeTo(fme));
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole().value >= fme.getRole().value) {
|
||||
// TODO add more informative messages.
|
||||
msg("<b>Your rank is too low to kick this player."); return;
|
||||
msg("<b>Your rank is too low to kick this player.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Conf.canLeaveWithNegativePower && you.getPower() < 0) {
|
||||
msg("<b>You cannot kick that member until their power is positive."); return;
|
||||
msg("<b>You cannot kick that member until their power is positive.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
|
||||
if (!canAffordCommand(Conf.econCostKick, "to kick someone from the faction")) { return; }
|
||||
if (!canAffordCommand(Conf.econCostKick, "to kick someone from the faction")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// trigger the leave event (cancellable) [reason:kicked]
|
||||
FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
if (!payForCommand(Conf.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) {
|
||||
@ -71,9 +88,12 @@ public class CmdKick extends FCommand {
|
||||
P.p.log((senderIsConsole ? "A console command" : fme.getName()) + " kicked " + you.getName() + " from the faction: " + yourFaction.getTag());
|
||||
}
|
||||
|
||||
if (you.getRole() == Role.ADMIN) { yourFaction.promoteNewLeader(); }
|
||||
if (you.getRole() == Role.ADMIN) {
|
||||
yourFaction.promoteNewLeader();
|
||||
}
|
||||
|
||||
yourFaction.deinvite(you); you.resetFactionData();
|
||||
yourFaction.deinvite(you);
|
||||
you.resetFactionData();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,14 +5,19 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdLeave extends FCommand {
|
||||
|
||||
public CmdLeave() {
|
||||
super(); this.aliases.add("leave");
|
||||
super();
|
||||
this.aliases.add("leave");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.LEAVE.node; this.disableOnLock = true;
|
||||
this.permission = Permission.LEAVE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = true; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,32 +13,46 @@ import java.util.Comparator;
|
||||
public class CmdList extends FCommand {
|
||||
|
||||
public CmdList() {
|
||||
super(); this.aliases.add("list"); this.aliases.add("ls");
|
||||
super();
|
||||
this.aliases.add("list");
|
||||
this.aliases.add("ls");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("page", "1");
|
||||
|
||||
this.permission = Permission.LIST.node; this.disableOnLock = false;
|
||||
this.permission = Permission.LIST.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) { return; }
|
||||
if (!payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Faction> factionList = new ArrayList<Faction>(Factions.i.get());
|
||||
factionList.remove(Factions.i.getNone()); factionList.remove(Factions.i.getSafeZone());
|
||||
factionList.remove(Factions.i.getNone());
|
||||
factionList.remove(Factions.i.getSafeZone());
|
||||
factionList.remove(Factions.i.getWarZone());
|
||||
|
||||
// Sort by total followers first
|
||||
Collections.sort(factionList, new Comparator<Faction>() {
|
||||
@Override
|
||||
public int compare(Faction f1, Faction f2) {
|
||||
int f1Size = f1.getFPlayers().size(); int f2Size = f2.getFPlayers().size();
|
||||
if (f1Size < f2Size) { return 1; } else if (f1Size > f2Size) { return -1; } return 0;
|
||||
int f1Size = f1.getFPlayers().size();
|
||||
int f2Size = f2.getFPlayers().size();
|
||||
if (f1Size < f2Size) {
|
||||
return 1;
|
||||
} else if (f1Size > f2Size) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
@ -48,7 +62,12 @@ public class CmdList extends FCommand {
|
||||
public int compare(Faction f1, Faction f2) {
|
||||
int f1Size = f1.getFPlayersWhereOnline(true).size();
|
||||
int f2Size = f2.getFPlayersWhereOnline(true).size();
|
||||
if (f1Size < f2Size) { return 1; } else if (f1Size > f2Size) { return -1; } return 0;
|
||||
if (f1Size < f2Size) {
|
||||
return 1;
|
||||
} else if (f1Size > f2Size) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
@ -73,11 +92,19 @@ public class CmdList extends FCommand {
|
||||
|
||||
factionList.add(0, Factions.i.getNone());
|
||||
|
||||
final int pageheight = 9; int pagenumber = this.argAsInt(0, 1);
|
||||
final int pageheight = 9;
|
||||
int pagenumber = this.argAsInt(0, 1);
|
||||
int pagecount = (factionList.size() / pageheight) + 1;
|
||||
if (pagenumber > pagecount) { pagenumber = pagecount; } else if (pagenumber < 1) { pagenumber = 1; }
|
||||
int start = (pagenumber - 1) * pageheight; int end = start + pageheight;
|
||||
if (end > factionList.size()) { end = factionList.size(); }
|
||||
if (pagenumber > pagecount) {
|
||||
pagenumber = pagecount;
|
||||
} else if (pagenumber < 1) {
|
||||
pagenumber = 1;
|
||||
}
|
||||
int start = (pagenumber - 1) * pageheight;
|
||||
int end = start + pageheight;
|
||||
if (end > factionList.size()) {
|
||||
end = factionList.size();
|
||||
}
|
||||
|
||||
lines.add(p.txt.titleize("Faction List " + pagenumber + "/" + pagecount));
|
||||
|
||||
|
@ -12,14 +12,18 @@ public class CmdLock extends FCommand {
|
||||
*/
|
||||
|
||||
public CmdLock() {
|
||||
super(); this.aliases.add("lock");
|
||||
super();
|
||||
this.aliases.add("lock");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("on/off", "flip");
|
||||
|
||||
this.permission = Permission.LOCK.node; this.disableOnLock = false;
|
||||
this.permission = Permission.LOCK.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,19 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdMap extends FCommand {
|
||||
public CmdMap() {
|
||||
super(); this.aliases.add("map");
|
||||
super();
|
||||
this.aliases.add("map");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("on/off", "once");
|
||||
|
||||
this.permission = Permission.MAP.node; this.disableOnLock = false;
|
||||
this.permission = Permission.MAP.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -25,19 +30,25 @@ public class CmdMap extends FCommand {
|
||||
// Turn on
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) { return; }
|
||||
if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) {
|
||||
return;
|
||||
}
|
||||
|
||||
fme.setMapAutoUpdating(true); msg("<i>Map auto update <green>ENABLED.");
|
||||
fme.setMapAutoUpdating(true);
|
||||
msg("<i>Map auto update <green>ENABLED.");
|
||||
|
||||
// And show the map once
|
||||
showMap();
|
||||
} else {
|
||||
// Turn off
|
||||
fme.setMapAutoUpdating(false); msg("<i>Map auto update <red>DISABLED.");
|
||||
fme.setMapAutoUpdating(false);
|
||||
msg("<i>Map auto update <red>DISABLED.");
|
||||
}
|
||||
} else {
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) { return; }
|
||||
if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) {
|
||||
return;
|
||||
}
|
||||
|
||||
showMap();
|
||||
}
|
||||
|
@ -8,37 +8,49 @@ import com.massivecraft.factions.struct.Role;
|
||||
public class CmdMod extends FCommand {
|
||||
|
||||
public CmdMod() {
|
||||
super(); this.aliases.add("mod");
|
||||
super();
|
||||
this.aliases.add("mod");
|
||||
|
||||
this.requiredArgs.add("player name");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.MOD.node; this.disableOnLock = true;
|
||||
this.permission = Permission.MOD.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0); if (you == null) { return; }
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean permAny = Permission.MOD_ANY.has(sender, false); Faction targetFaction = you.getFaction();
|
||||
boolean permAny = Permission.MOD_ANY.has(sender, false);
|
||||
Faction targetFaction = you.getFaction();
|
||||
|
||||
if (targetFaction != myFaction && !permAny) {
|
||||
msg("%s<b> is not a member in your faction.", you.describeTo(fme, true)); return;
|
||||
msg("%s<b> is not a member in your faction.", you.describeTo(fme, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (fme != null && fme.getRole() != Role.ADMIN && !permAny) {
|
||||
msg("<b>You are not the faction admin."); return;
|
||||
msg("<b>You are not the faction admin.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you == fme && !permAny) {
|
||||
msg("<b>The target player musn't be yourself."); return;
|
||||
msg("<b>The target player musn't be yourself.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole() == Role.ADMIN) {
|
||||
msg("<b>The target player is a faction admin. Demote them first."); return;
|
||||
msg("<b>The target player is a faction admin. Demote them first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole() == Role.MODERATOR) {
|
||||
|
@ -11,27 +11,34 @@ public class CmdMoney extends FCommand {
|
||||
public CmdMoneyTransferPf cmdMoneyTransferPf = new CmdMoneyTransferPf();
|
||||
|
||||
public CmdMoney() {
|
||||
super(); this.aliases.add("money");
|
||||
super();
|
||||
this.aliases.add("money");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("","")
|
||||
|
||||
this.isMoneyCommand = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
this.setHelpShort("faction money commands");
|
||||
this.helpLong.add(p.txt.parseTags("<i>The faction money commands."));
|
||||
|
||||
this.addSubCommand(this.cmdMoneyBalance); this.addSubCommand(this.cmdMoneyDeposit);
|
||||
this.addSubCommand(this.cmdMoneyWithdraw); this.addSubCommand(this.cmdMoneyTransferFf);
|
||||
this.addSubCommand(this.cmdMoneyTransferFp); this.addSubCommand(this.cmdMoneyTransferPf);
|
||||
this.addSubCommand(this.cmdMoneyBalance);
|
||||
this.addSubCommand(this.cmdMoneyDeposit);
|
||||
this.addSubCommand(this.cmdMoneyWithdraw);
|
||||
this.addSubCommand(this.cmdMoneyTransferFf);
|
||||
this.addSubCommand(this.cmdMoneyTransferFp);
|
||||
this.addSubCommand(this.cmdMoneyTransferPf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
this.commandChain.add(this); P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain);
|
||||
this.commandChain.add(this);
|
||||
P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,25 +6,35 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdMoneyBalance extends FCommand {
|
||||
public CmdMoneyBalance() {
|
||||
super(); this.aliases.add("b"); this.aliases.add("balance");
|
||||
super();
|
||||
this.aliases.add("b");
|
||||
this.aliases.add("balance");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction", "yours");
|
||||
|
||||
this.permission = Permission.MONEY_BALANCE.node; this.setHelpShort("show faction balance");
|
||||
this.permission = Permission.MONEY_BALANCE.node;
|
||||
this.setHelpShort("show faction balance");
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction faction = myFaction; if (this.argIsSet(0)) {
|
||||
Faction faction = myFaction;
|
||||
if (this.argIsSet(0)) {
|
||||
faction = this.argAsFaction(0);
|
||||
}
|
||||
|
||||
if (faction == null) { return; }
|
||||
if (faction != myFaction && !Permission.MONEY_BALANCE_ANY.has(sender, true)) { return; }
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
if (faction != myFaction && !Permission.MONEY_BALANCE_ANY.has(sender, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Econ.sendBalanceInfo(fme, faction);
|
||||
}
|
||||
|
@ -11,19 +11,30 @@ import org.bukkit.ChatColor;
|
||||
public class CmdMoneyDeposit extends FCommand {
|
||||
|
||||
public CmdMoneyDeposit() {
|
||||
super(); this.aliases.add("d"); this.aliases.add("deposit");
|
||||
super();
|
||||
this.aliases.add("d");
|
||||
this.aliases.add("deposit");
|
||||
|
||||
this.requiredArgs.add("amount"); this.optionalArgs.put("faction", "yours");
|
||||
this.requiredArgs.add("amount");
|
||||
this.optionalArgs.put("faction", "yours");
|
||||
|
||||
this.permission = Permission.MONEY_DEPOSIT.node; this.setHelpShort("deposit money");
|
||||
this.permission = Permission.MONEY_DEPOSIT.node;
|
||||
this.setHelpShort("deposit money");
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
double amount = this.argAsDouble(0, 0d); EconomyParticipator faction = this.argAsFaction(1, myFaction);
|
||||
if (faction == null) { return; } boolean success = Econ.transferMoney(fme, fme, faction, amount);
|
||||
double amount = this.argAsDouble(0, 0d);
|
||||
EconomyParticipator faction = this.argAsFaction(1, myFaction);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
boolean success = Econ.transferMoney(fme, fme, faction, amount);
|
||||
|
||||
if (success && Conf.logMoneyTransactions) {
|
||||
P.p.log(ChatColor.stripColor(P.p.txt.parse("%s deposited %s in the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null))));
|
||||
|
@ -12,20 +12,32 @@ public class CmdMoneyTransferFf extends FCommand {
|
||||
public CmdMoneyTransferFf() {
|
||||
this.aliases.add("ff");
|
||||
|
||||
this.requiredArgs.add("amount"); this.requiredArgs.add("faction"); this.requiredArgs.add("faction");
|
||||
this.requiredArgs.add("amount");
|
||||
this.requiredArgs.add("faction");
|
||||
this.requiredArgs.add("faction");
|
||||
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.MONEY_F2F.node; this.setHelpShort("transfer f -> f");
|
||||
this.permission = Permission.MONEY_F2F.node;
|
||||
this.setHelpShort("transfer f -> f");
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
double amount = this.argAsDouble(0, 0d); EconomyParticipator from = this.argAsFaction(1);
|
||||
if (from == null) { return; } EconomyParticipator to = this.argAsFaction(2); if (to == null) { return; }
|
||||
double amount = this.argAsDouble(0, 0d);
|
||||
EconomyParticipator from = this.argAsFaction(1);
|
||||
if (from == null) {
|
||||
return;
|
||||
}
|
||||
EconomyParticipator to = this.argAsFaction(2);
|
||||
if (to == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success = Econ.transferMoney(fme, from, to, amount);
|
||||
|
||||
|
@ -12,21 +12,32 @@ public class CmdMoneyTransferFp extends FCommand {
|
||||
public CmdMoneyTransferFp() {
|
||||
this.aliases.add("fp");
|
||||
|
||||
this.requiredArgs.add("amount"); this.requiredArgs.add("faction"); this.requiredArgs.add("player");
|
||||
this.requiredArgs.add("amount");
|
||||
this.requiredArgs.add("faction");
|
||||
this.requiredArgs.add("player");
|
||||
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.MONEY_F2P.node; this.setHelpShort("transfer f -> p");
|
||||
this.permission = Permission.MONEY_F2P.node;
|
||||
this.setHelpShort("transfer f -> p");
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
double amount = this.argAsDouble(0, 0d); EconomyParticipator from = this.argAsFaction(1);
|
||||
if (from == null) { return; } EconomyParticipator to = this.argAsBestFPlayerMatch(2);
|
||||
if (to == null) { return; }
|
||||
double amount = this.argAsDouble(0, 0d);
|
||||
EconomyParticipator from = this.argAsFaction(1);
|
||||
if (from == null) {
|
||||
return;
|
||||
}
|
||||
EconomyParticipator to = this.argAsBestFPlayerMatch(2);
|
||||
if (to == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success = Econ.transferMoney(fme, from, to, amount);
|
||||
|
||||
|
@ -12,20 +12,32 @@ public class CmdMoneyTransferPf extends FCommand {
|
||||
public CmdMoneyTransferPf() {
|
||||
this.aliases.add("pf");
|
||||
|
||||
this.requiredArgs.add("amount"); this.requiredArgs.add("player"); this.requiredArgs.add("faction");
|
||||
this.requiredArgs.add("amount");
|
||||
this.requiredArgs.add("player");
|
||||
this.requiredArgs.add("faction");
|
||||
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.MONEY_P2F.node; this.setHelpShort("transfer p -> f");
|
||||
this.permission = Permission.MONEY_P2F.node;
|
||||
this.setHelpShort("transfer p -> f");
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
double amount = this.argAsDouble(0, 0d); EconomyParticipator from = this.argAsBestFPlayerMatch(1);
|
||||
if (from == null) { return; } EconomyParticipator to = this.argAsFaction(2); if (to == null) { return; }
|
||||
double amount = this.argAsDouble(0, 0d);
|
||||
EconomyParticipator from = this.argAsBestFPlayerMatch(1);
|
||||
if (from == null) {
|
||||
return;
|
||||
}
|
||||
EconomyParticipator to = this.argAsFaction(2);
|
||||
if (to == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success = Econ.transferMoney(fme, from, to, amount);
|
||||
|
||||
|
@ -10,19 +10,29 @@ import org.bukkit.ChatColor;
|
||||
|
||||
public class CmdMoneyWithdraw extends FCommand {
|
||||
public CmdMoneyWithdraw() {
|
||||
this.aliases.add("w"); this.aliases.add("withdraw");
|
||||
this.aliases.add("w");
|
||||
this.aliases.add("withdraw");
|
||||
|
||||
this.requiredArgs.add("amount"); this.optionalArgs.put("faction", "yours");
|
||||
this.requiredArgs.add("amount");
|
||||
this.optionalArgs.put("faction", "yours");
|
||||
|
||||
this.permission = Permission.MONEY_WITHDRAW.node; this.setHelpShort("withdraw money");
|
||||
this.permission = Permission.MONEY_WITHDRAW.node;
|
||||
this.setHelpShort("withdraw money");
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
double amount = this.argAsDouble(0, 0d); EconomyParticipator faction = this.argAsFaction(1, myFaction);
|
||||
if (faction == null) { return; } boolean success = Econ.transferMoney(fme, faction, fme, amount);
|
||||
double amount = this.argAsDouble(0, 0d);
|
||||
EconomyParticipator faction = this.argAsFaction(1, myFaction);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
boolean success = Econ.transferMoney(fme, faction, fme, amount);
|
||||
|
||||
if (success && Conf.logMoneyTransactions) {
|
||||
P.p.log(ChatColor.stripColor(P.p.txt.parse("%s withdrew %s from the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null))));
|
||||
|
@ -7,14 +7,19 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdOpen extends FCommand {
|
||||
public CmdOpen() {
|
||||
super(); this.aliases.add("open");
|
||||
super();
|
||||
this.aliases.add("open");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("yes/no", "flip");
|
||||
|
||||
this.permission = Permission.OPEN.node; this.disableOnLock = false;
|
||||
this.permission = Permission.OPEN.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,7 +38,8 @@ public class CmdOpen extends FCommand {
|
||||
for (Faction faction : Factions.i.get()) {
|
||||
if (faction == myFaction) {
|
||||
continue;
|
||||
} faction.msg("<i>The faction %s<i> is now %s", myFaction.getTag(faction), open);
|
||||
}
|
||||
faction.msg("<i>The faction %s<i> is now %s", myFaction.getTag(faction), open);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,19 @@ import com.massivecraft.factions.struct.Role;
|
||||
public class CmdOwner extends FCommand {
|
||||
|
||||
public CmdOwner() {
|
||||
super(); this.aliases.add("owner");
|
||||
super();
|
||||
this.aliases.add("owner");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("player name", "you");
|
||||
|
||||
this.permission = Permission.OWNER.node; this.disableOnLock = true;
|
||||
this.permission = Permission.OWNER.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
// TODO: Fix colors!
|
||||
@ -29,7 +34,8 @@ public class CmdOwner extends FCommand {
|
||||
}
|
||||
|
||||
if (!Conf.ownedAreasEnabled) {
|
||||
fme.msg("<b>Sorry, but owned areas are disabled on this server."); return;
|
||||
fme.msg("<b>Sorry, but owned areas are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasBypass && Conf.ownedAreasLimitPerFaction > 0 && myFaction.getCountOfClaimsWithOwners() >= Conf.ownedAreasLimitPerFaction) {
|
||||
@ -43,33 +49,42 @@ public class CmdOwner extends FCommand {
|
||||
|
||||
FLocation flocation = new FLocation(fme);
|
||||
|
||||
Faction factionHere = Board.getFactionAt(flocation); if (factionHere != myFaction) {
|
||||
Faction factionHere = Board.getFactionAt(flocation);
|
||||
if (factionHere != myFaction) {
|
||||
if (!hasBypass) {
|
||||
fme.msg("<b>This land is not claimed by your faction, so you can't set ownership of it."); return;
|
||||
fme.msg("<b>This land is not claimed by your faction, so you can't set ownership of it.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!factionHere.isNormal()) {
|
||||
fme.msg("<b>This land is not claimed by a faction. Ownership is not possible."); return;
|
||||
fme.msg("<b>This land is not claimed by a faction. Ownership is not possible.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FPlayer target = this.argAsBestFPlayerMatch(0, fme); if (target == null) { return; }
|
||||
FPlayer target = this.argAsBestFPlayerMatch(0, fme);
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String playerName = target.getName();
|
||||
|
||||
if (target.getFaction() != myFaction) {
|
||||
fme.msg("%s<i> is not a member of this faction.", playerName); return;
|
||||
fme.msg("%s<i> is not a member of this faction.", playerName);
|
||||
return;
|
||||
}
|
||||
|
||||
// if no player name was passed, and this claim does already have owners set, clear them
|
||||
if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation)) {
|
||||
myFaction.clearClaimOwnership(flocation); fme.msg("<i>You have cleared ownership for this claimed area.");
|
||||
myFaction.clearClaimOwnership(flocation);
|
||||
fme.msg("<i>You have cleared ownership for this claimed area.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (myFaction.isPlayerInOwnerList(target, flocation)) {
|
||||
myFaction.removePlayerAsOwner(target, flocation);
|
||||
fme.msg("<i>You have removed ownership of this claimed land from %s<i>.", playerName); return;
|
||||
fme.msg("<i>You have removed ownership of this claimed land from %s<i>.", playerName);
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
|
@ -9,14 +9,19 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdOwnerList extends FCommand {
|
||||
|
||||
public CmdOwnerList() {
|
||||
super(); this.aliases.add("ownerlist");
|
||||
super();
|
||||
this.aliases.add("ownerlist");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.OWNERLIST.node; this.disableOnLock = false;
|
||||
this.permission = Permission.OWNERLIST.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -28,25 +33,30 @@ public class CmdOwnerList extends FCommand {
|
||||
}
|
||||
|
||||
if (!Conf.ownedAreasEnabled) {
|
||||
fme.msg("<b>Owned areas are disabled on this server."); return;
|
||||
fme.msg("<b>Owned areas are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
FLocation flocation = new FLocation(fme);
|
||||
|
||||
if (Board.getFactionAt(flocation) != myFaction) {
|
||||
if (!hasBypass) {
|
||||
fme.msg("<b>This land is not claimed by your faction."); return;
|
||||
fme.msg("<b>This land is not claimed by your faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction = Board.getFactionAt(flocation); if (!myFaction.isNormal()) {
|
||||
fme.msg("<i>This land is not claimed by any faction, thus no owners."); return;
|
||||
myFaction = Board.getFactionAt(flocation);
|
||||
if (!myFaction.isNormal()) {
|
||||
fme.msg("<i>This land is not claimed by any faction, thus no owners.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String owners = myFaction.getOwnerListString(flocation);
|
||||
|
||||
if (owners == null || owners.isEmpty()) {
|
||||
fme.msg("<i>No owners are set here; everyone in the faction has access."); return;
|
||||
fme.msg("<i>No owners are set here; everyone in the faction has access.");
|
||||
return;
|
||||
}
|
||||
|
||||
fme.msg("<i>Current owner(s) of this land: %s", owners);
|
||||
|
@ -8,25 +8,35 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdPeaceful extends FCommand {
|
||||
|
||||
public CmdPeaceful() {
|
||||
super(); this.aliases.add("peaceful");
|
||||
super();
|
||||
this.aliases.add("peaceful");
|
||||
|
||||
this.requiredArgs.add("faction tag");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.SET_PEACEFUL.node; this.disableOnLock = true;
|
||||
this.permission = Permission.SET_PEACEFUL.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction faction = this.argAsFaction(0); if (faction == null) { return; }
|
||||
Faction faction = this.argAsFaction(0);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String change; if (faction.isPeaceful()) {
|
||||
change = "removed peaceful status from"; faction.setPeaceful(false);
|
||||
String change;
|
||||
if (faction.isPeaceful()) {
|
||||
change = "removed peaceful status from";
|
||||
faction.setPeaceful(false);
|
||||
} else {
|
||||
change = "granted peaceful status to"; faction.setPeaceful(true);
|
||||
change = "granted peaceful status to";
|
||||
faction.setPeaceful(true);
|
||||
}
|
||||
|
||||
// Inform all players
|
||||
|
@ -9,25 +9,35 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdPermanent extends FCommand {
|
||||
public CmdPermanent() {
|
||||
super(); this.aliases.add("permanent");
|
||||
super();
|
||||
this.aliases.add("permanent");
|
||||
|
||||
this.requiredArgs.add("faction tag");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.SET_PERMANENT.node; this.disableOnLock = true;
|
||||
this.permission = Permission.SET_PERMANENT.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction faction = this.argAsFaction(0); if (faction == null) { return; }
|
||||
Faction faction = this.argAsFaction(0);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String change; if (faction.isPermanent()) {
|
||||
change = "removed permanent status from"; faction.setPermanent(false);
|
||||
String change;
|
||||
if (faction.isPermanent()) {
|
||||
change = "removed permanent status from";
|
||||
faction.setPermanent(false);
|
||||
} else {
|
||||
change = "added permanent status to"; faction.setPermanent(true);
|
||||
change = "added permanent status to";
|
||||
faction.setPermanent(true);
|
||||
}
|
||||
|
||||
P.p.log((fme == null ? "A server admin" : fme.getName()) + " " + change + " the faction \"" + faction.getTag() + "\".");
|
||||
|
@ -6,25 +6,34 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdPermanentPower extends FCommand {
|
||||
public CmdPermanentPower() {
|
||||
super(); this.aliases.add("permanentpower");
|
||||
super();
|
||||
this.aliases.add("permanentpower");
|
||||
|
||||
this.requiredArgs.add("faction"); this.optionalArgs.put("power", "reset");
|
||||
this.requiredArgs.add("faction");
|
||||
this.optionalArgs.put("power", "reset");
|
||||
|
||||
this.permission = Permission.SET_PERMANENTPOWER.node; this.disableOnLock = true;
|
||||
this.permission = Permission.SET_PERMANENTPOWER.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction targetFaction = this.argAsFaction(0); if (targetFaction == null) { return; }
|
||||
Faction targetFaction = this.argAsFaction(0);
|
||||
if (targetFaction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Integer targetPower = this.argAsInt(1);
|
||||
|
||||
targetFaction.setPermanentPower(targetPower);
|
||||
|
||||
String change = "removed permanentpower status from"; if (targetFaction.hasPermanentPower()) {
|
||||
String change = "removed permanentpower status from";
|
||||
if (targetFaction.hasPermanentPower()) {
|
||||
change = "added permanentpower status to";
|
||||
}
|
||||
|
||||
|
@ -7,22 +7,32 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdPower extends FCommand {
|
||||
|
||||
public CmdPower() {
|
||||
super(); this.aliases.add("power"); this.aliases.add("pow");
|
||||
super();
|
||||
this.aliases.add("power");
|
||||
this.aliases.add("pow");
|
||||
|
||||
//this.requiredArgs.add("faction tag");
|
||||
this.optionalArgs.put("player name", "you");
|
||||
|
||||
this.permission = Permission.POWER.node; this.disableOnLock = false;
|
||||
this.permission = Permission.POWER.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FPlayer target = this.argAsBestFPlayerMatch(0, fme); if (target == null) { return; }
|
||||
FPlayer target = this.argAsBestFPlayerMatch(0, fme);
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (target != fme && !Permission.POWER_ANY.has(sender, true)) { return; }
|
||||
if (target != fme && !Permission.POWER_ANY.has(sender, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostPower, "to show player power info", "for showing player power info")) {
|
||||
|
@ -7,38 +7,56 @@ import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdPowerBoost extends FCommand {
|
||||
public CmdPowerBoost() {
|
||||
super(); this.aliases.add("powerboost");
|
||||
super();
|
||||
this.aliases.add("powerboost");
|
||||
|
||||
this.requiredArgs.add("p|f|player|faction"); this.requiredArgs.add("name"); this.requiredArgs.add("#");
|
||||
this.requiredArgs.add("p|f|player|faction");
|
||||
this.requiredArgs.add("name");
|
||||
this.requiredArgs.add("#");
|
||||
|
||||
this.permission = Permission.POWERBOOST.node; this.disableOnLock = true;
|
||||
this.permission = Permission.POWERBOOST.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
String type = this.argAsString(0).toLowerCase(); boolean doPlayer = true;
|
||||
String type = this.argAsString(0).toLowerCase();
|
||||
boolean doPlayer = true;
|
||||
if (type.equals("f") || type.equals("faction")) {
|
||||
doPlayer = false;
|
||||
} else if (!type.equals("p") && !type.equals("player")) {
|
||||
msg("<b>You must specify \"p\" or \"player\" to target a player or \"f\" or \"faction\" to target a faction.");
|
||||
msg("<b>ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5"); return;
|
||||
msg("<b>ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5");
|
||||
return;
|
||||
}
|
||||
|
||||
Double targetPower = this.argAsDouble(2); if (targetPower == null) {
|
||||
msg("<b>You must specify a valid numeric value for the power bonus/penalty amount."); return;
|
||||
Double targetPower = this.argAsDouble(2);
|
||||
if (targetPower == null) {
|
||||
msg("<b>You must specify a valid numeric value for the power bonus/penalty amount.");
|
||||
return;
|
||||
}
|
||||
|
||||
String target;
|
||||
|
||||
if (doPlayer) {
|
||||
FPlayer targetPlayer = this.argAsBestFPlayerMatch(1); if (targetPlayer == null) { return; }
|
||||
targetPlayer.setPowerBoost(targetPower); target = "Player \"" + targetPlayer.getName() + "\"";
|
||||
FPlayer targetPlayer = this.argAsBestFPlayerMatch(1);
|
||||
if (targetPlayer == null) {
|
||||
return;
|
||||
}
|
||||
targetPlayer.setPowerBoost(targetPower);
|
||||
target = "Player \"" + targetPlayer.getName() + "\"";
|
||||
} else {
|
||||
Faction targetFaction = this.argAsFaction(1); if (targetFaction == null) { return; }
|
||||
targetFaction.setPowerBoost(targetPower); target = "Faction \"" + targetFaction.getTag() + "\"";
|
||||
Faction targetFaction = this.argAsFaction(1);
|
||||
if (targetFaction == null) {
|
||||
return;
|
||||
}
|
||||
targetFaction.setPowerBoost(targetPower);
|
||||
target = "Faction \"" + targetFaction.getTag() + "\"";
|
||||
}
|
||||
|
||||
msg("<i>" + target + " now has a power bonus/penalty of " + targetPower + " to min and max power levels.");
|
||||
|
@ -4,6 +4,7 @@ import com.massivecraft.factions.struct.Relation;
|
||||
|
||||
public class CmdRelationAlly extends FRelationCommand {
|
||||
public CmdRelationAlly() {
|
||||
aliases.add("ally"); targetRelation = Relation.ALLY;
|
||||
aliases.add("ally");
|
||||
targetRelation = Relation.ALLY;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.massivecraft.factions.struct.Relation;
|
||||
|
||||
public class CmdRelationEnemy extends FRelationCommand {
|
||||
public CmdRelationEnemy() {
|
||||
aliases.add("enemy"); targetRelation = Relation.ENEMY;
|
||||
aliases.add("enemy");
|
||||
targetRelation = Relation.ENEMY;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.massivecraft.factions.struct.Relation;
|
||||
|
||||
public class CmdRelationNeutral extends FRelationCommand {
|
||||
public CmdRelationNeutral() {
|
||||
aliases.add("neutral"); targetRelation = Relation.NEUTRAL;
|
||||
aliases.add("neutral");
|
||||
targetRelation = Relation.NEUTRAL;
|
||||
}
|
||||
}
|
||||
|
@ -6,36 +6,50 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdReload extends FCommand {
|
||||
|
||||
public CmdReload() {
|
||||
super(); this.aliases.add("reload");
|
||||
super();
|
||||
this.aliases.add("reload");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("file", "all");
|
||||
|
||||
this.permission = Permission.RELOAD.node; this.disableOnLock = false;
|
||||
this.permission = Permission.RELOAD.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
long timeInitStart = System.currentTimeMillis(); String file = this.argAsString(0, "all").toLowerCase();
|
||||
long timeInitStart = System.currentTimeMillis();
|
||||
String file = this.argAsString(0, "all").toLowerCase();
|
||||
|
||||
String fileName;
|
||||
|
||||
if (file.startsWith("c")) {
|
||||
Conf.load(); fileName = "conf.json";
|
||||
Conf.load();
|
||||
fileName = "conf.json";
|
||||
} else if (file.startsWith("b")) {
|
||||
Board.load(); fileName = "board.json";
|
||||
Board.load();
|
||||
fileName = "board.json";
|
||||
} else if (file.startsWith("f")) {
|
||||
Factions.i.loadFromDisc(); fileName = "factions.json";
|
||||
Factions.i.loadFromDisc();
|
||||
fileName = "factions.json";
|
||||
} else if (file.startsWith("p")) {
|
||||
FPlayers.i.loadFromDisc(); fileName = "players.json";
|
||||
FPlayers.i.loadFromDisc();
|
||||
fileName = "players.json";
|
||||
} else if (file.startsWith("a")) {
|
||||
fileName = "all"; Conf.load(); FPlayers.i.loadFromDisc(); Factions.i.loadFromDisc(); Board.load();
|
||||
fileName = "all";
|
||||
Conf.load();
|
||||
FPlayers.i.loadFromDisc();
|
||||
Factions.i.loadFromDisc();
|
||||
Board.load();
|
||||
} else {
|
||||
P.p.log("RELOAD CANCELLED - SPECIFIED FILE INVALID");
|
||||
msg("<b>Invalid file specified. <i>Valid files: all, conf, board, factions, players"); return;
|
||||
msg("<b>Invalid file specified. <i>Valid files: all, conf, board, factions, players");
|
||||
return;
|
||||
}
|
||||
|
||||
long timeReload = (System.currentTimeMillis() - timeInitStart);
|
||||
|
@ -9,14 +9,18 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdSafeunclaimall extends FCommand {
|
||||
|
||||
public CmdSafeunclaimall() {
|
||||
this.aliases.add("safeunclaimall"); this.aliases.add("safedeclaimall");
|
||||
this.aliases.add("safeunclaimall");
|
||||
this.aliases.add("safedeclaimall");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("radius", "0");
|
||||
|
||||
this.permission = Permission.MANAGE_SAFE_ZONE.node; this.disableOnLock = true;
|
||||
this.permission = Permission.MANAGE_SAFE_ZONE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
this.setHelpShort("Unclaim all safezone land");
|
||||
@ -24,9 +28,12 @@ public class CmdSafeunclaimall extends FCommand {
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Board.unclaimAll(Factions.i.getSafeZone().getId()); msg("<i>You unclaimed ALL safe zone land.");
|
||||
Board.unclaimAll(Factions.i.getSafeZone().getId());
|
||||
msg("<i>You unclaimed ALL safe zone land.");
|
||||
|
||||
if (Conf.logLandUnclaims) { P.p.log(fme.getName() + " unclaimed all safe zones."); }
|
||||
if (Conf.logLandUnclaims) {
|
||||
P.p.log(fme.getName() + " unclaimed all safe zones.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,20 +9,29 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdSaveAll extends FCommand {
|
||||
|
||||
public CmdSaveAll() {
|
||||
super(); this.aliases.add("saveall"); this.aliases.add("save");
|
||||
super();
|
||||
this.aliases.add("saveall");
|
||||
this.aliases.add("save");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.SAVE.node; this.disableOnLock = false;
|
||||
this.permission = Permission.SAVE.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FPlayers.i.saveToDisc(); Factions.i.saveToDisc(); Board.save(); Conf.save(); msg("<i>Factions saved to disk!");
|
||||
FPlayers.i.saveToDisc();
|
||||
Factions.i.saveToDisc();
|
||||
Board.save();
|
||||
Conf.save();
|
||||
msg("<i>Factions saved to disk!");
|
||||
}
|
||||
|
||||
}
|
@ -14,40 +14,56 @@ public class CmdSethome extends FCommand {
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction tag", "mine");
|
||||
|
||||
this.permission = Permission.SETHOME.node; this.disableOnLock = true;
|
||||
this.permission = Permission.SETHOME.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (!Conf.homesEnabled) {
|
||||
fme.msg("<b>Sorry, Faction homes are disabled on this server."); return;
|
||||
fme.msg("<b>Sorry, Faction homes are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
Faction faction = this.argAsFaction(0, myFaction); if (faction == null) { return; }
|
||||
Faction faction = this.argAsFaction(0, myFaction);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Can the player set the home for this faction?
|
||||
if (faction == myFaction) {
|
||||
if (!Permission.SETHOME_ANY.has(sender) && !assertMinRole(Role.MODERATOR)) { return; }
|
||||
if (!Permission.SETHOME_ANY.has(sender) && !assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!Permission.SETHOME_ANY.has(sender, true)) { return; }
|
||||
if (!Permission.SETHOME_ANY.has(sender, true)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Can the player set the faction home HERE?
|
||||
if (!Permission.BYPASS.has(me) &&
|
||||
Conf.homesMustBeInClaimedTerritory &&
|
||||
Board.getFactionAt(new FLocation(me)) != faction) {
|
||||
fme.msg("<b>Sorry, your faction home can only be set inside your own claimed territory."); return;
|
||||
fme.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostSethome, "to set the faction home", "for setting the faction home")) { return; }
|
||||
if (!payForCommand(Conf.econCostSethome, "to set the faction home", "for setting the faction home")) {
|
||||
return;
|
||||
}
|
||||
|
||||
faction.setHome(me.getLocation());
|
||||
|
||||
faction.msg("%s<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true));
|
||||
faction.sendMessage(p.cmdBase.cmdHome.getUseageTemplate()); if (faction != myFaction) {
|
||||
faction.sendMessage(p.cmdBase.cmdHome.getUseageTemplate());
|
||||
if (faction != myFaction) {
|
||||
fme.msg("<b>You have set the home for the " + faction.getTag(fme) + "<i> faction.");
|
||||
}
|
||||
}
|
||||
|
@ -14,20 +14,29 @@ import java.util.Collection;
|
||||
public class CmdShow extends FCommand {
|
||||
|
||||
public CmdShow() {
|
||||
this.aliases.add("show"); this.aliases.add("who");
|
||||
this.aliases.add("show");
|
||||
this.aliases.add("who");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction tag", "yours");
|
||||
|
||||
this.permission = Permission.SHOW.node; this.disableOnLock = false;
|
||||
this.permission = Permission.SHOW.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction faction = myFaction; if (this.argIsSet(0)) {
|
||||
faction = this.argAsFaction(0); if (faction == null) { return; }
|
||||
Faction faction = myFaction;
|
||||
if (this.argIsSet(0)) {
|
||||
faction = this.argAsFaction(0);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
@ -39,12 +48,14 @@ public class CmdShow extends FCommand {
|
||||
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
|
||||
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);
|
||||
|
||||
msg(p.txt.titleize(faction.getTag(fme))); msg("<a>Description: <i>%s", faction.getDescription());
|
||||
msg(p.txt.titleize(faction.getTag(fme)));
|
||||
msg("<a>Description: <i>%s", faction.getDescription());
|
||||
if (!faction.isNormal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String peaceStatus = ""; if (faction.isPeaceful()) {
|
||||
String peaceStatus = "";
|
||||
if (faction.isPeaceful()) {
|
||||
peaceStatus = " " + Conf.colorNeutral + "This faction is Peaceful";
|
||||
}
|
||||
|
||||
@ -61,7 +72,8 @@ public class CmdShow extends FCommand {
|
||||
// show the land value
|
||||
if (Econ.shouldBeUsed()) {
|
||||
double value = Econ.calculateTotalLandValue(faction.getLandRounded());
|
||||
double refund = value * Conf.econClaimRefundMultiplier; if (value > 0) {
|
||||
double refund = value * Conf.econClaimRefundMultiplier;
|
||||
if (value > 0) {
|
||||
String stringValue = Econ.moneyString(value);
|
||||
String stringRefund = (refund > 0.0) ? (" (" + Econ.moneyString(refund) + " depreciated)") : "";
|
||||
msg("<a>Total land value: <i>" + stringValue + stringRefund);
|
||||
@ -76,38 +88,55 @@ public class CmdShow extends FCommand {
|
||||
String listpart;
|
||||
|
||||
// List relation
|
||||
String allyList = p.txt.parse("<a>Allies: "); String enemyList = p.txt.parse("<a>Enemies: ");
|
||||
String allyList = p.txt.parse("<a>Allies: ");
|
||||
String enemyList = p.txt.parse("<a>Enemies: ");
|
||||
for (Faction otherFaction : Factions.i.get()) {
|
||||
if (otherFaction == faction) { continue; }
|
||||
if (otherFaction == faction) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Relation rel = otherFaction.getRelationTo(faction); if (!rel.isAlly() && !rel.isEnemy()) {
|
||||
Relation rel = otherFaction.getRelationTo(faction);
|
||||
if (!rel.isAlly() && !rel.isEnemy()) {
|
||||
continue; // if not ally or enemy, drop out now so we're not wasting time on it; good performance boost
|
||||
}
|
||||
|
||||
listpart = otherFaction.getTag(fme) + p.txt.parse("<i>") + ", ";
|
||||
if (rel.isAlly()) { allyList += listpart; } else if (rel.isEnemy()) { enemyList += listpart; }
|
||||
} if (allyList.endsWith(", ")) { allyList = allyList.substring(0, allyList.length() - 2); }
|
||||
if (enemyList.endsWith(", ")) { enemyList = enemyList.substring(0, enemyList.length() - 2); }
|
||||
if (rel.isAlly()) {
|
||||
allyList += listpart;
|
||||
} else if (rel.isEnemy()) {
|
||||
enemyList += listpart;
|
||||
}
|
||||
}
|
||||
if (allyList.endsWith(", ")) {
|
||||
allyList = allyList.substring(0, allyList.length() - 2);
|
||||
}
|
||||
if (enemyList.endsWith(", ")) {
|
||||
enemyList = enemyList.substring(0, enemyList.length() - 2);
|
||||
}
|
||||
|
||||
sendMessage(allyList); sendMessage(enemyList);
|
||||
sendMessage(allyList);
|
||||
sendMessage(enemyList);
|
||||
|
||||
// List the members...
|
||||
String onlineList = p.txt.parse("<a>") + "Members online: ";
|
||||
String offlineList = p.txt.parse("<a>") + "Members offline: "; for (FPlayer follower : admins) {
|
||||
String offlineList = p.txt.parse("<a>") + "Members offline: ";
|
||||
for (FPlayer follower : admins) {
|
||||
listpart = follower.getNameAndTitle(fme) + p.txt.parse("<i>") + ", ";
|
||||
if (follower.isOnlineAndVisibleTo(me)) {
|
||||
onlineList += listpart;
|
||||
} else {
|
||||
offlineList += listpart;
|
||||
}
|
||||
} for (FPlayer follower : mods) {
|
||||
}
|
||||
for (FPlayer follower : mods) {
|
||||
listpart = follower.getNameAndTitle(fme) + p.txt.parse("<i>") + ", ";
|
||||
if (follower.isOnlineAndVisibleTo(me)) {
|
||||
onlineList += listpart;
|
||||
} else {
|
||||
offlineList += listpart;
|
||||
}
|
||||
} for (FPlayer follower : normals) {
|
||||
}
|
||||
for (FPlayer follower : normals) {
|
||||
listpart = follower.getNameAndTitle(fme) + p.txt.parse("<i>") + ", ";
|
||||
if (follower.isOnlineAndVisibleTo(me)) {
|
||||
onlineList += listpart;
|
||||
@ -118,11 +147,13 @@ public class CmdShow extends FCommand {
|
||||
|
||||
if (onlineList.endsWith(", ")) {
|
||||
onlineList = onlineList.substring(0, onlineList.length() - 2);
|
||||
} if (offlineList.endsWith(", ")) {
|
||||
}
|
||||
if (offlineList.endsWith(", ")) {
|
||||
offlineList = offlineList.substring(0, offlineList.length() - 2);
|
||||
}
|
||||
|
||||
sendMessage(onlineList); sendMessage(offlineList);
|
||||
sendMessage(onlineList);
|
||||
sendMessage(offlineList);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,9 +18,13 @@ public class CmdTag extends FCommand {
|
||||
this.requiredArgs.add("faction tag");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.TAG.node; this.disableOnLock = true;
|
||||
this.permission = Permission.TAG.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,25 +33,36 @@ public class CmdTag extends FCommand {
|
||||
|
||||
// TODO does not first test cover selfcase?
|
||||
if (Factions.i.isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) {
|
||||
msg("<b>That tag is already taken"); return;
|
||||
msg("<b>That tag is already taken");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> errors = new ArrayList<String>(); errors.addAll(Factions.validateTag(tag));
|
||||
ArrayList<String> errors = new ArrayList<String>();
|
||||
errors.addAll(Factions.validateTag(tag));
|
||||
if (errors.size() > 0) {
|
||||
sendMessage(errors); return;
|
||||
sendMessage(errors);
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
|
||||
if (!canAffordCommand(Conf.econCostTag, "to change the faction tag")) { return; }
|
||||
if (!canAffordCommand(Conf.econCostTag, "to change the faction tag")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// trigger the faction rename event (cancellable)
|
||||
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag);
|
||||
Bukkit.getServer().getPluginManager().callEvent(renameEvent); if (renameEvent.isCancelled()) { return; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(renameEvent);
|
||||
if (renameEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
if (!payForCommand(Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) { return; }
|
||||
if (!payForCommand(Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String oldtag = myFaction.getTag(); myFaction.setTag(tag);
|
||||
String oldtag = myFaction.getTag();
|
||||
myFaction.setTag(tag);
|
||||
|
||||
// Inform
|
||||
myFaction.msg("%s<i> changed your faction tag to %s", fme.describeTo(myFaction, true), myFaction.getTag(myFaction));
|
||||
|
@ -9,23 +9,36 @@ public class CmdTitle extends FCommand {
|
||||
public CmdTitle() {
|
||||
this.aliases.add("title");
|
||||
|
||||
this.requiredArgs.add("player name"); this.optionalArgs.put("title", "");
|
||||
this.requiredArgs.add("player name");
|
||||
this.optionalArgs.put("title", "");
|
||||
|
||||
this.permission = Permission.TITLE.node; this.disableOnLock = true;
|
||||
this.permission = Permission.TITLE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0); if (you == null) { return; }
|
||||
FPlayer you = this.argAsBestFPlayerMatch(0);
|
||||
if (you == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
args.remove(0); String title = TextUtil.implode(args, " ");
|
||||
args.remove(0);
|
||||
String title = TextUtil.implode(args, " ");
|
||||
|
||||
if (!canIAdministerYou(fme, you)) { return; }
|
||||
if (!canIAdministerYou(fme, you)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostTitle, "to change a players title", "for changing a players title")) { return; }
|
||||
if (!payForCommand(Conf.econCostTitle, "to change a players title", "for changing a players title")) {
|
||||
return;
|
||||
}
|
||||
|
||||
you.setTitle(title);
|
||||
|
||||
|
@ -9,40 +9,50 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class CmdUnclaim extends FCommand {
|
||||
public CmdUnclaim() {
|
||||
this.aliases.add("unclaim"); this.aliases.add("declaim");
|
||||
this.aliases.add("unclaim");
|
||||
this.aliases.add("declaim");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.UNCLAIM.node; this.disableOnLock = true;
|
||||
this.permission = Permission.UNCLAIM.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
FLocation flocation = new FLocation(fme); Faction otherFaction = Board.getFactionAt(flocation);
|
||||
FLocation flocation = new FLocation(fme);
|
||||
Faction otherFaction = Board.getFactionAt(flocation);
|
||||
|
||||
if (otherFaction.isSafeZone()) {
|
||||
if (Permission.MANAGE_SAFE_ZONE.has(sender)) {
|
||||
Board.removeAt(flocation); msg("<i>Safe zone was unclaimed.");
|
||||
Board.removeAt(flocation);
|
||||
msg("<i>Safe zone was unclaimed.");
|
||||
|
||||
if (Conf.logLandUnclaims) {
|
||||
P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag());
|
||||
}
|
||||
} else {
|
||||
msg("<b>This is a safe zone. You lack permissions to unclaim.");
|
||||
} return;
|
||||
}
|
||||
return;
|
||||
} else if (otherFaction.isWarZone()) {
|
||||
if (Permission.MANAGE_WAR_ZONE.has(sender)) {
|
||||
Board.removeAt(flocation); msg("<i>War zone was unclaimed.");
|
||||
Board.removeAt(flocation);
|
||||
msg("<i>War zone was unclaimed.");
|
||||
|
||||
if (Conf.logLandUnclaims) {
|
||||
P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag());
|
||||
}
|
||||
} else {
|
||||
msg("<b>This is a war zone. You lack permissions to unclaim.");
|
||||
} return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fme.isAdminBypassing()) {
|
||||
@ -68,11 +78,15 @@ public class CmdUnclaim extends FCommand {
|
||||
|
||||
|
||||
if (myFaction != otherFaction) {
|
||||
msg("<b>You don't own this land."); return;
|
||||
msg("<b>You don't own this land.");
|
||||
return;
|
||||
}
|
||||
|
||||
LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction, fme);
|
||||
Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); if (unclaimEvent.isCancelled()) { return; }
|
||||
Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
|
||||
if (unclaimEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Econ.shouldBeUsed()) {
|
||||
double refund = Econ.calculateClaimRefund(myFaction.getLandRounded());
|
||||
@ -82,11 +96,14 @@ public class CmdUnclaim extends FCommand {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!Econ.modifyMoney(fme, refund, "to unclaim this land", "for unclaiming this land")) { return; }
|
||||
if (!Econ.modifyMoney(fme, refund, "to unclaim this land", "for unclaiming this land")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Board.removeAt(flocation); myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true));
|
||||
Board.removeAt(flocation);
|
||||
myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true));
|
||||
|
||||
if (Conf.logLandUnclaims) {
|
||||
P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag());
|
||||
|
@ -10,14 +10,19 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class CmdUnclaimall extends FCommand {
|
||||
public CmdUnclaimall() {
|
||||
this.aliases.add("unclaimall"); this.aliases.add("declaimall");
|
||||
this.aliases.add("unclaimall");
|
||||
this.aliases.add("declaimall");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.UNCLAIM_ALL.node; this.disableOnLock = true;
|
||||
this.permission = Permission.UNCLAIM_ALL.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,9 +11,12 @@ public class CmdVersion extends FCommand {
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.VERSION.node; this.disableOnLock = false;
|
||||
this.permission = Permission.VERSION.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
|
@ -9,14 +9,18 @@ import com.massivecraft.factions.struct.Permission;
|
||||
public class CmdWarunclaimall extends FCommand {
|
||||
|
||||
public CmdWarunclaimall() {
|
||||
this.aliases.add("warunclaimall"); this.aliases.add("wardeclaimall");
|
||||
this.aliases.add("warunclaimall");
|
||||
this.aliases.add("wardeclaimall");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.MANAGE_WAR_ZONE.node; this.disableOnLock = true;
|
||||
this.permission = Permission.MANAGE_WAR_ZONE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
this.setHelpShort("unclaim all warzone land");
|
||||
@ -24,9 +28,12 @@ public class CmdWarunclaimall extends FCommand {
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Board.unclaimAll(Factions.i.getWarZone().getId()); msg("<i>You unclaimed ALL war zone land.");
|
||||
Board.unclaimAll(Factions.i.getWarZone().getId());
|
||||
msg("<i>You unclaimed ALL war zone land.");
|
||||
|
||||
if (Conf.logLandUnclaims) { P.p.log(fme.getName() + " unclaimed all war zones."); }
|
||||
if (Conf.logLandUnclaims) {
|
||||
P.p.log(fme.getName() + " unclaimed all war zones.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,14 +52,17 @@ public class FCmdRoot extends FCommand {
|
||||
public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall();
|
||||
|
||||
public FCmdRoot() {
|
||||
super(); this.aliases.addAll(Conf.baseCommandAliases);
|
||||
super();
|
||||
this.aliases.addAll(Conf.baseCommandAliases);
|
||||
this.aliases.removeAll(Collections.singletonList(null)); // remove any nulls from extra commas
|
||||
this.allowNoSlashAccess = Conf.allowNoSlashCommand;
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("","")
|
||||
|
||||
senderMustBePlayer = false; senderMustBeMember = false; senderMustBeModerator = false;
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
this.disableOnLock = false;
|
||||
@ -69,29 +72,57 @@ public class FCmdRoot extends FCommand {
|
||||
|
||||
//this.subCommands.add(p.cmdHelp);
|
||||
|
||||
this.addSubCommand(this.cmdAdmin); this.addSubCommand(this.cmdAutoClaim); this.addSubCommand(this.cmdBoom);
|
||||
this.addSubCommand(this.cmdBypass); this.addSubCommand(this.cmdChat); this.addSubCommand(this.cmdChatSpy);
|
||||
this.addSubCommand(this.cmdClaim); this.addSubCommand(this.cmdConfig); this.addSubCommand(this.cmdCreate);
|
||||
this.addSubCommand(this.cmdDeinvite); this.addSubCommand(this.cmdDescription);
|
||||
this.addSubCommand(this.cmdDisband); this.addSubCommand(this.cmdHelp); this.addSubCommand(this.cmdHome);
|
||||
this.addSubCommand(this.cmdInvite); this.addSubCommand(this.cmdJoin); this.addSubCommand(this.cmdKick);
|
||||
this.addSubCommand(this.cmdLeave); this.addSubCommand(this.cmdList); this.addSubCommand(this.cmdLock);
|
||||
this.addSubCommand(this.cmdMap); this.addSubCommand(this.cmdMod); this.addSubCommand(this.cmdMoney);
|
||||
this.addSubCommand(this.cmdOpen); this.addSubCommand(this.cmdOwner); this.addSubCommand(this.cmdOwnerList);
|
||||
this.addSubCommand(this.cmdPeaceful); this.addSubCommand(this.cmdPermanent);
|
||||
this.addSubCommand(this.cmdPermanentPower); this.addSubCommand(this.cmdPower);
|
||||
this.addSubCommand(this.cmdPowerBoost); this.addSubCommand(this.cmdRelationAlly);
|
||||
this.addSubCommand(this.cmdRelationEnemy); this.addSubCommand(this.cmdRelationNeutral);
|
||||
this.addSubCommand(this.cmdReload); this.addSubCommand(this.cmdSafeunclaimall);
|
||||
this.addSubCommand(this.cmdSaveAll); this.addSubCommand(this.cmdSethome); this.addSubCommand(this.cmdShow);
|
||||
this.addSubCommand(this.cmdTag); this.addSubCommand(this.cmdTitle); this.addSubCommand(this.cmdUnclaim);
|
||||
this.addSubCommand(this.cmdUnclaimall); this.addSubCommand(this.cmdVersion);
|
||||
this.addSubCommand(this.cmdAdmin);
|
||||
this.addSubCommand(this.cmdAutoClaim);
|
||||
this.addSubCommand(this.cmdBoom);
|
||||
this.addSubCommand(this.cmdBypass);
|
||||
this.addSubCommand(this.cmdChat);
|
||||
this.addSubCommand(this.cmdChatSpy);
|
||||
this.addSubCommand(this.cmdClaim);
|
||||
this.addSubCommand(this.cmdConfig);
|
||||
this.addSubCommand(this.cmdCreate);
|
||||
this.addSubCommand(this.cmdDeinvite);
|
||||
this.addSubCommand(this.cmdDescription);
|
||||
this.addSubCommand(this.cmdDisband);
|
||||
this.addSubCommand(this.cmdHelp);
|
||||
this.addSubCommand(this.cmdHome);
|
||||
this.addSubCommand(this.cmdInvite);
|
||||
this.addSubCommand(this.cmdJoin);
|
||||
this.addSubCommand(this.cmdKick);
|
||||
this.addSubCommand(this.cmdLeave);
|
||||
this.addSubCommand(this.cmdList);
|
||||
this.addSubCommand(this.cmdLock);
|
||||
this.addSubCommand(this.cmdMap);
|
||||
this.addSubCommand(this.cmdMod);
|
||||
this.addSubCommand(this.cmdMoney);
|
||||
this.addSubCommand(this.cmdOpen);
|
||||
this.addSubCommand(this.cmdOwner);
|
||||
this.addSubCommand(this.cmdOwnerList);
|
||||
this.addSubCommand(this.cmdPeaceful);
|
||||
this.addSubCommand(this.cmdPermanent);
|
||||
this.addSubCommand(this.cmdPermanentPower);
|
||||
this.addSubCommand(this.cmdPower);
|
||||
this.addSubCommand(this.cmdPowerBoost);
|
||||
this.addSubCommand(this.cmdRelationAlly);
|
||||
this.addSubCommand(this.cmdRelationEnemy);
|
||||
this.addSubCommand(this.cmdRelationNeutral);
|
||||
this.addSubCommand(this.cmdReload);
|
||||
this.addSubCommand(this.cmdSafeunclaimall);
|
||||
this.addSubCommand(this.cmdSaveAll);
|
||||
this.addSubCommand(this.cmdSethome);
|
||||
this.addSubCommand(this.cmdShow);
|
||||
this.addSubCommand(this.cmdTag);
|
||||
this.addSubCommand(this.cmdTitle);
|
||||
this.addSubCommand(this.cmdUnclaim);
|
||||
this.addSubCommand(this.cmdUnclaimall);
|
||||
this.addSubCommand(this.cmdVersion);
|
||||
this.addSubCommand(this.cmdWarunclaimall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
this.commandChain.add(this); this.cmdHelp.execute(this.sender, this.args, this.commandChain);
|
||||
this.commandChain.add(this);
|
||||
this.cmdHelp.execute(this.sender, this.args, this.commandChain);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,30 +32,38 @@ public abstract class FCommand extends MCommand<P> {
|
||||
// The money commands must be disabled if money should not be used.
|
||||
isMoneyCommand = false;
|
||||
|
||||
senderMustBeMember = false; senderMustBeModerator = false; senderMustBeAdmin = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
|
||||
if (sender instanceof Player) {
|
||||
this.fme = FPlayers.i.get((Player) sender); this.myFaction = this.fme.getFaction();
|
||||
this.fme = FPlayers.i.get((Player) sender);
|
||||
this.myFaction = this.fme.getFaction();
|
||||
} else {
|
||||
this.fme = null; this.myFaction = null;
|
||||
} super.execute(sender, args, commandChain);
|
||||
this.fme = null;
|
||||
this.myFaction = null;
|
||||
}
|
||||
super.execute(sender, args, commandChain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
if (p.getLocked() && this.disableOnLock) {
|
||||
msg("<b>Factions was locked by an admin. Please try again later."); return false;
|
||||
msg("<b>Factions was locked by an admin. Please try again later.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isMoneyCommand && !Conf.econEnabled) {
|
||||
msg("<b>Faction economy features are disabled on this server."); return false;
|
||||
msg("<b>Faction economy features are disabled on this server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isMoneyCommand && !Conf.bankEnabled) {
|
||||
msg("<b>The faction bank system is disabled on this server."); return false;
|
||||
msg("<b>The faction bank system is disabled on this server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -63,24 +71,34 @@ public abstract class FCommand extends MCommand<P> {
|
||||
|
||||
@Override
|
||||
public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) {
|
||||
boolean superValid = super.validSenderType(sender, informSenderIfNot); if (!superValid) { return false; }
|
||||
boolean superValid = super.validSenderType(sender, informSenderIfNot);
|
||||
if (!superValid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(this.senderMustBeMember || this.senderMustBeModerator || this.senderMustBeAdmin)) { return true; }
|
||||
if (!(this.senderMustBeMember || this.senderMustBeModerator || this.senderMustBeAdmin)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) { return false; }
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FPlayer fplayer = FPlayers.i.get((Player) sender);
|
||||
|
||||
if (!fplayer.hasFaction()) {
|
||||
sender.sendMessage(p.txt.parse("<b>You are not member of any faction.")); return false;
|
||||
sender.sendMessage(p.txt.parse("<b>You are not member of any faction."));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.senderMustBeModerator && !fplayer.getRole().isAtLeast(Role.MODERATOR)) {
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction moderators can %s.", this.getHelpShort())); return false;
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction moderators can %s.", this.getHelpShort()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.senderMustBeAdmin && !fplayer.getRole().isAtLeast(Role.ADMIN)) {
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction admins can %s.", this.getHelpShort())); return false;
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction admins can %s.", this.getHelpShort()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -91,19 +109,27 @@ public abstract class FCommand extends MCommand<P> {
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean assertHasFaction() {
|
||||
if (me == null) { return true; }
|
||||
if (me == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!fme.hasFaction()) {
|
||||
sendMessage("You are not member of any faction."); return false;
|
||||
} return true;
|
||||
sendMessage("You are not member of any faction.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean assertMinRole(Role role) {
|
||||
if (me == null) { return true; }
|
||||
if (me == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fme.getRole().value < role.value) {
|
||||
msg("<b>You <h>must be " + role + "<b> to " + this.getHelpShort() + "."); return false;
|
||||
} return true;
|
||||
msg("<b>You <h>must be " + role + "<b> to " + this.getHelpShort() + ".");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -115,7 +141,8 @@ public abstract class FCommand extends MCommand<P> {
|
||||
FPlayer ret = def;
|
||||
|
||||
if (name != null) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(name); FPlayer fplayer = FPlayers.i.get(player);
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
|
||||
FPlayer fplayer = FPlayers.i.get(player);
|
||||
if (fplayer != null) {
|
||||
ret = fplayer;
|
||||
}
|
||||
@ -176,7 +203,8 @@ public abstract class FCommand extends MCommand<P> {
|
||||
|
||||
// Next we match player names
|
||||
if (faction == null) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(name); FPlayer fplayer = FPlayers.i.get(player);
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
|
||||
FPlayer fplayer = FPlayers.i.get(player);
|
||||
if (fplayer != null) {
|
||||
faction = fplayer.getFaction();
|
||||
}
|
||||
@ -237,19 +265,27 @@ public abstract class FCommand extends MCommand<P> {
|
||||
|
||||
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
|
||||
public boolean payForCommand(double cost, String toDoThis, String forDoingThis) {
|
||||
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) { return true; }
|
||||
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
|
||||
return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
|
||||
} else { return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis); }
|
||||
} else {
|
||||
return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis);
|
||||
}
|
||||
}
|
||||
|
||||
// like above, but just make sure they can pay; returns true unless person can't afford the cost
|
||||
public boolean canAffordCommand(double cost, String toDoThis) {
|
||||
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) { return true; }
|
||||
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
|
||||
return Econ.hasAtLeast(myFaction, cost, toDoThis);
|
||||
} else { return Econ.hasAtLeast(fme, cost, toDoThis); }
|
||||
} else {
|
||||
return Econ.hasAtLeast(fme, cost, toDoThis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,28 +12,39 @@ public abstract class FRelationCommand extends FCommand {
|
||||
public Relation targetRelation;
|
||||
|
||||
public FRelationCommand() {
|
||||
super(); this.requiredArgs.add("faction tag");
|
||||
super();
|
||||
this.requiredArgs.add("faction tag");
|
||||
//this.optionalArgs.put("player name", "you");
|
||||
|
||||
this.permission = Permission.RELATION.node; this.disableOnLock = true;
|
||||
this.permission = Permission.RELATION.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true; senderMustBeMember = false; senderMustBeModerator = true; senderMustBeAdmin = false;
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction them = this.argAsFaction(0); if (them == null) { return; }
|
||||
Faction them = this.argAsFaction(0);
|
||||
if (them == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!them.isNormal()) {
|
||||
msg("<b>Nope! You can't."); return;
|
||||
msg("<b>Nope! You can't.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (them == myFaction) {
|
||||
msg("<b>Nope! You can't declare a relation to yourself :)"); return;
|
||||
msg("<b>Nope! You can't declare a relation to yourself :)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (myFaction.getRelationWish(them) == targetRelation) {
|
||||
msg("<b>You already have that relation wish set with %s.", them.getTag()); return;
|
||||
msg("<b>You already have that relation wish set with %s.", them.getTag());
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
@ -42,7 +53,8 @@ public abstract class FRelationCommand extends FCommand {
|
||||
}
|
||||
|
||||
// try to set the new relation
|
||||
Relation oldRelation = myFaction.getRelationTo(them, true); myFaction.setRelationWish(them, targetRelation);
|
||||
Relation oldRelation = myFaction.getRelationTo(them, true);
|
||||
myFaction.setRelationWish(them, targetRelation);
|
||||
Relation currentRelation = myFaction.getRelationTo(them, true);
|
||||
ChatColor currentRelationColor = currentRelation.getColor();
|
||||
|
||||
|
@ -19,7 +19,9 @@ public class FPlayerJoinEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
public FPlayerJoinEvent(FPlayer fp, Faction f, PlayerJoinReason r) {
|
||||
fplayer = fp; faction = f; reason = r;
|
||||
fplayer = fp;
|
||||
faction = f;
|
||||
reason = r;
|
||||
}
|
||||
|
||||
public FPlayer getFPlayer() {
|
||||
|
@ -18,7 +18,9 @@ public class FPlayerLeaveEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
public FPlayerLeaveEvent(FPlayer p, Faction f, PlayerLeaveReason r) {
|
||||
FPlayer = p; Faction = f; reason = r;
|
||||
FPlayer = p;
|
||||
Faction = f;
|
||||
reason = r;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
@ -49,7 +51,9 @@ public class FPlayerLeaveEvent extends Event implements Cancellable {
|
||||
@Override
|
||||
public void setCancelled(boolean c) {
|
||||
if (reason == PlayerLeaveReason.DISBAND || reason == PlayerLeaveReason.RESET) {
|
||||
cancelled = false; return;
|
||||
} cancelled = c;
|
||||
cancelled = false;
|
||||
return;
|
||||
}
|
||||
cancelled = c;
|
||||
}
|
||||
}
|
@ -16,7 +16,9 @@ public class FactionCreateEvent extends Event implements Cancellable {
|
||||
private boolean cancelled;
|
||||
|
||||
public FactionCreateEvent(Player sender, String tag) {
|
||||
this.factionTag = tag; this.sender = sender; this.cancelled = false;
|
||||
this.factionTag = tag;
|
||||
this.sender = sender;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public FPlayer getFPlayer() {
|
||||
|
@ -17,7 +17,9 @@ public class FactionDisbandEvent extends Event implements Cancellable {
|
||||
private Player sender;
|
||||
|
||||
public FactionDisbandEvent(Player sender, String factionId) {
|
||||
cancelled = false; this.sender = sender; this.id = factionId;
|
||||
cancelled = false;
|
||||
this.sender = sender;
|
||||
this.id = factionId;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
|
@ -15,7 +15,10 @@ public class FactionRelationEvent extends Event {
|
||||
private Relation frel;
|
||||
|
||||
public FactionRelationEvent(Faction sender, Faction target, Relation oldrel, Relation rel) {
|
||||
fsender = sender; ftarget = target; foldrel = oldrel; frel = rel;
|
||||
fsender = sender;
|
||||
ftarget = target;
|
||||
foldrel = oldrel;
|
||||
frel = rel;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
|
@ -16,7 +16,10 @@ public class FactionRenameEvent extends Event implements Cancellable {
|
||||
private String tag;
|
||||
|
||||
public FactionRenameEvent(FPlayer sender, String newTag) {
|
||||
fplayer = sender; faction = sender.getFaction(); tag = newTag; this.cancelled = false;
|
||||
fplayer = sender;
|
||||
faction = sender.getFaction();
|
||||
tag = newTag;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public Faction getFaction() {
|
||||
|
@ -17,7 +17,10 @@ public class LandClaimEvent extends Event implements Cancellable {
|
||||
private FPlayer fplayer;
|
||||
|
||||
public LandClaimEvent(FLocation loc, Faction f, FPlayer p) {
|
||||
cancelled = false; location = loc; faction = f; fplayer = p;
|
||||
cancelled = false;
|
||||
location = loc;
|
||||
faction = f;
|
||||
fplayer = p;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
|
@ -13,7 +13,8 @@ public class LandUnclaimAllEvent extends Event {
|
||||
private FPlayer fplayer;
|
||||
|
||||
public LandUnclaimAllEvent(Faction f, FPlayer p) {
|
||||
faction = f; fplayer = p;
|
||||
faction = f;
|
||||
fplayer = p;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
|
@ -17,7 +17,10 @@ public class LandUnclaimEvent extends Event implements Cancellable {
|
||||
private FPlayer fplayer;
|
||||
|
||||
public LandUnclaimEvent(FLocation loc, Faction f, FPlayer p) {
|
||||
cancelled = false; location = loc; faction = f; fplayer = p;
|
||||
cancelled = false;
|
||||
location = loc;
|
||||
faction = f;
|
||||
fplayer = p;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
|
@ -17,7 +17,9 @@ public class PowerLossEvent extends Event implements Cancellable {
|
||||
private String message;
|
||||
|
||||
public PowerLossEvent(Faction f, FPlayer p) {
|
||||
cancelled = false; faction = f; fplayer = p;
|
||||
cancelled = false;
|
||||
faction = f;
|
||||
fplayer = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,18 +19,23 @@ public class Econ {
|
||||
private static Economy econ = null;
|
||||
|
||||
public static void setup() {
|
||||
if (isSetup()) { return; }
|
||||
if (isSetup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" ";
|
||||
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
P.p.log(integrationFail + "is not installed."); return;
|
||||
P.p.log(integrationFail + "is not installed.");
|
||||
return;
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
P.p.log(integrationFail + "is not hooked into an economy plugin."); return;
|
||||
} econ = rsp.getProvider();
|
||||
P.p.log(integrationFail + "is not hooked into an economy plugin.");
|
||||
return;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
|
||||
P.p.log("Economy integration through Vault plugin successful.");
|
||||
|
||||
@ -53,40 +58,61 @@ public class Econ {
|
||||
|
||||
|
||||
public static void modifyUniverseMoney(double delta) {
|
||||
if (!shouldBeUsed()) { return; }
|
||||
if (!shouldBeUsed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Conf.econUniverseAccount == null) { return; } if (Conf.econUniverseAccount.length() == 0) { return; }
|
||||
if (!econ.hasAccount(Conf.econUniverseAccount)) { return; }
|
||||
if (Conf.econUniverseAccount == null) {
|
||||
return;
|
||||
}
|
||||
if (Conf.econUniverseAccount.length() == 0) {
|
||||
return;
|
||||
}
|
||||
if (!econ.hasAccount(Conf.econUniverseAccount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
modifyBalance(Conf.econUniverseAccount, delta);
|
||||
}
|
||||
|
||||
public static void sendBalanceInfo(FPlayer to, EconomyParticipator about) {
|
||||
if (!shouldBeUsed()) {
|
||||
P.p.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin."); return;
|
||||
P.p.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin.");
|
||||
return;
|
||||
}
|
||||
to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Econ.moneyString(econ.getBalance(about.getAccountId())));
|
||||
}
|
||||
|
||||
public static boolean canIControllYou(EconomyParticipator i, EconomyParticipator you) {
|
||||
Faction fI = RelationUtil.getFaction(i); Faction fYou = RelationUtil.getFaction(you);
|
||||
Faction fI = RelationUtil.getFaction(i);
|
||||
Faction fYou = RelationUtil.getFaction(you);
|
||||
|
||||
// This is a system invoker. Accept it.
|
||||
if (fI == null) { return true; }
|
||||
if (fI == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Bypassing players can do any kind of transaction
|
||||
if (i instanceof FPlayer && ((FPlayer) i).isAdminBypassing()) { return true; }
|
||||
if (i instanceof FPlayer && ((FPlayer) i).isAdminBypassing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Players with the any withdraw can do.
|
||||
if (i instanceof FPlayer && Permission.MONEY_WITHDRAW_ANY.has(((FPlayer) i).getPlayer())) { return true; }
|
||||
if (i instanceof FPlayer && Permission.MONEY_WITHDRAW_ANY.has(((FPlayer) i).getPlayer())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
|
||||
if (i == you) { return true; }
|
||||
if (i == you) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// A faction can always transfer away the money of it's members and its own money...
|
||||
// This will however probably never happen as a faction does not have free will.
|
||||
// Ohh by the way... Yes it could. For daily rent to the faction.
|
||||
if (i == fI && fI == fYou) { return true; }
|
||||
if (i == fI && fI == fYou) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Factions can be controlled by members that are moderators... or any member if any member can withdraw.
|
||||
if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer) i).getRole().value >= Role.MODERATOR.value)) {
|
||||
@ -103,16 +129,23 @@ public class Econ {
|
||||
}
|
||||
|
||||
public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) {
|
||||
if (!shouldBeUsed()) { return false; }
|
||||
if (!shouldBeUsed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The amount must be positive.
|
||||
// If the amount is negative we must flip and multiply amount with -1.
|
||||
if (amount < 0) {
|
||||
amount *= -1; EconomyParticipator temp = from; from = to; to = temp;
|
||||
amount *= -1;
|
||||
EconomyParticipator temp = from;
|
||||
from = to;
|
||||
to = temp;
|
||||
}
|
||||
|
||||
// Check the rights
|
||||
if (!canIControllYou(invoker, from)) { return false; }
|
||||
if (!canIControllYou(invoker, from)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is there enough money for the transaction to happen?
|
||||
if (!econ.has(from.getAccountId(), amount)) {
|
||||
@ -128,8 +161,12 @@ public class Econ {
|
||||
EconomyResponse erw = econ.withdrawPlayer(from.getAccountId(), amount);
|
||||
|
||||
if (erw.transactionSuccess()) {
|
||||
EconomyResponse erd = econ.depositPlayer(to.getAccountId(), amount); if (erd.transactionSuccess()) {
|
||||
if (notify) { sendTransferInfo(invoker, from, to, amount); } return true;
|
||||
EconomyResponse erd = econ.depositPlayer(to.getAccountId(), amount);
|
||||
if (erd.transactionSuccess()) {
|
||||
if (notify) {
|
||||
sendTransferInfo(invoker, from, to, amount);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// transaction failed, refund account
|
||||
econ.depositPlayer(from.getAccountId(), amount);
|
||||
@ -159,8 +196,10 @@ public class Econ {
|
||||
}
|
||||
|
||||
public static void sendTransferInfo(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) {
|
||||
Set<FPlayer> recipients = new HashSet<FPlayer>(); recipients.addAll(getFplayers(invoker));
|
||||
recipients.addAll(getFplayers(from)); recipients.addAll(getFplayers(to));
|
||||
Set<FPlayer> recipients = new HashSet<FPlayer>();
|
||||
recipients.addAll(getFplayers(invoker));
|
||||
recipients.addAll(getFplayers(from));
|
||||
recipients.addAll(getFplayers(to));
|
||||
|
||||
if (invoker == null) {
|
||||
for (FPlayer recipient : recipients) {
|
||||
@ -182,19 +221,26 @@ public class Econ {
|
||||
}
|
||||
|
||||
public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) {
|
||||
if (!shouldBeUsed()) { return true; }
|
||||
if (!shouldBeUsed()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!econ.has(ep.getAccountId(), delta)) {
|
||||
if (toDoThis != null && !toDoThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", ep.describeTo(ep, true), moneyString(delta), toDoThis);
|
||||
} return false;
|
||||
} return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) {
|
||||
if (!shouldBeUsed()) { return false; }
|
||||
if (!shouldBeUsed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String acc = ep.getAccountId(); String You = ep.describeTo(ep, true);
|
||||
String acc = ep.getAccountId();
|
||||
String You = ep.describeTo(ep, true);
|
||||
|
||||
if (delta == 0) {
|
||||
// no money actually transferred?
|
||||
@ -205,15 +251,19 @@ public class Econ {
|
||||
if (delta > 0) {
|
||||
// The player should gain money
|
||||
// The account might not have enough space
|
||||
EconomyResponse er = econ.depositPlayer(acc, delta); if (er.transactionSuccess()) {
|
||||
modifyUniverseMoney(-delta); if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
EconomyResponse er = econ.depositPlayer(acc, delta);
|
||||
if (er.transactionSuccess()) {
|
||||
modifyUniverseMoney(-delta);
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
|
||||
} return true;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// transfer to account failed
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> would have gained <h>%s<i> %s, but the deposit failed.", You, moneyString(delta), forDoingThis);
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// The player should loose money
|
||||
@ -221,14 +271,17 @@ public class Econ {
|
||||
|
||||
if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) {
|
||||
// There is enough money to pay
|
||||
modifyUniverseMoney(-delta); if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
modifyUniverseMoney(-delta);
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
|
||||
} return true;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// There was not enough money to pay
|
||||
if (toDoThis != null && !toDoThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(-delta), toDoThis);
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -239,11 +292,14 @@ public class Econ {
|
||||
}
|
||||
|
||||
public static void oldMoneyDoTransfer() {
|
||||
if (!shouldBeUsed()) { return; }
|
||||
if (!shouldBeUsed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Faction faction : Factions.i.get()) {
|
||||
if (faction.money > 0) {
|
||||
econ.depositPlayer(faction.getAccountId(), faction.money); faction.money = 0;
|
||||
econ.depositPlayer(faction.getAccountId(), faction.money);
|
||||
faction.money = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -265,9 +321,11 @@ public class Econ {
|
||||
|
||||
// calculate value of all owned land
|
||||
public static double calculateTotalLandValue(int ownedLand) {
|
||||
double amount = 0; for (int x = 0; x < ownedLand; x++) {
|
||||
double amount = 0;
|
||||
for (int x = 0; x < ownedLand; x++) {
|
||||
amount += calculateClaimCost(x, false);
|
||||
} return amount;
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
// calculate refund amount for all owned land
|
||||
@ -290,13 +348,17 @@ public class Econ {
|
||||
|
||||
public static boolean setBalance(String account, double amount) {
|
||||
double current = econ.getBalance(account);
|
||||
if (current > amount) { return econ.withdrawPlayer(account, current - amount).transactionSuccess(); } else {
|
||||
if (current > amount) {
|
||||
return econ.withdrawPlayer(account, current - amount).transactionSuccess();
|
||||
} else {
|
||||
return econ.depositPlayer(account, amount - current).transactionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean modifyBalance(String account, double amount) {
|
||||
if (amount < 0) { return econ.withdrawPlayer(account, -amount).transactionSuccess(); } else {
|
||||
if (amount < 0) {
|
||||
return econ.withdrawPlayer(account, -amount).transactionSuccess();
|
||||
} else {
|
||||
return econ.depositPlayer(account, amount).transactionSuccess();
|
||||
}
|
||||
}
|
||||
|
@ -15,20 +15,25 @@ public class Essentials {
|
||||
private static IEssentials essentials;
|
||||
|
||||
public static void setup() {
|
||||
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials"); if (ess != null) {
|
||||
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (ess != null) {
|
||||
essentials = (IEssentials) ess;
|
||||
}
|
||||
}
|
||||
|
||||
// return false if feature is disabled or Essentials isn't available
|
||||
public static boolean handleTeleport(Player player, Location loc) {
|
||||
if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) { return false; }
|
||||
if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Teleport teleport = (Teleport) essentials.getUser(player).getTeleport();
|
||||
Trade trade = new Trade(Conf.econCostHome, essentials); try {
|
||||
Trade trade = new Trade(Conf.econCostHome, essentials);
|
||||
try {
|
||||
teleport.teleport(loc, trade);
|
||||
} catch (Exception e) {
|
||||
player.sendMessage(ChatColor.RED.toString() + e.getMessage());
|
||||
} return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,13 @@ public class Worldguard {
|
||||
public static void init(Plugin plugin) {
|
||||
Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) {
|
||||
enabled = false; wg = null; P.p.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
|
||||
enabled = false;
|
||||
wg = null;
|
||||
P.p.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
|
||||
} else {
|
||||
wg = (WorldGuardPlugin) wgplug; enabled = true; P.p.log("Successfully hooked to WorldGuard.");
|
||||
wg = (WorldGuardPlugin) wgplug;
|
||||
enabled = true;
|
||||
P.p.log("Successfully hooked to WorldGuard.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,10 +57,13 @@ public class Worldguard {
|
||||
return true;
|
||||
}
|
||||
|
||||
Location loc = player.getLocation(); World world = loc.getWorld(); Vector pt = toVector(loc);
|
||||
Location loc = player.getLocation();
|
||||
World world = loc.getWorld();
|
||||
Vector pt = toVector(loc);
|
||||
|
||||
RegionManager regionManager = wg.getRegionManager(world);
|
||||
ApplicableRegionSet set = regionManager.getApplicableRegions(pt); return set.allows(DefaultFlag.PVP);
|
||||
ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
|
||||
return set.allows(DefaultFlag.PVP);
|
||||
}
|
||||
|
||||
// Check if player can build at location by worldguards rules.
|
||||
@ -69,9 +76,12 @@ public class Worldguard {
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = loc.getWorld(); Vector pt = toVector(loc);
|
||||
World world = loc.getWorld();
|
||||
Vector pt = toVector(loc);
|
||||
|
||||
if (wg.getRegionManager(world).getApplicableRegions(pt).size() > 0) { return wg.canBuild(player, loc); }
|
||||
if (wg.getRegionManager(world).getApplicableRegions(pt).size() > 0) {
|
||||
return wg.canBuild(player, loc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -85,8 +95,12 @@ public class Worldguard {
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = loc.getWorld(); Chunk chunk = world.getChunkAt(loc); int minChunkX = chunk.getX() << 4;
|
||||
int minChunkZ = chunk.getZ() << 4; int maxChunkX = minChunkX + 15; int maxChunkZ = minChunkZ + 15;
|
||||
World world = loc.getWorld();
|
||||
Chunk chunk = world.getChunkAt(loc);
|
||||
int minChunkX = chunk.getX() << 4;
|
||||
int minChunkZ = chunk.getZ() << 4;
|
||||
int maxChunkX = minChunkX + 15;
|
||||
int maxChunkZ = minChunkZ + 15;
|
||||
|
||||
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
|
||||
|
||||
@ -97,10 +111,12 @@ public class Worldguard {
|
||||
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
|
||||
Map<String, ProtectedRegion> allregions = regionManager.getRegions();
|
||||
List<ProtectedRegion> allregionslist = new ArrayList<ProtectedRegion>(allregions.values());
|
||||
List<ProtectedRegion> overlaps; boolean foundregions = false;
|
||||
List<ProtectedRegion> overlaps;
|
||||
boolean foundregions = false;
|
||||
|
||||
try {
|
||||
overlaps = region.getIntersectingRegions(allregionslist); if (overlaps == null || overlaps.isEmpty()) {
|
||||
overlaps = region.getIntersectingRegions(allregionslist);
|
||||
if (overlaps == null || overlaps.isEmpty()) {
|
||||
foundregions = false;
|
||||
} else {
|
||||
foundregions = true;
|
||||
|
@ -23,7 +23,12 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.isCancelled()) { return; } if (!event.canBuild()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (!event.canBuild()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// special case for flint&steel, which should only be prevented by DenyUsage list
|
||||
if (event.getBlockPlaced().getType() == Material.FIRE) {
|
||||
@ -37,7 +42,9 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
|
||||
event.setCancelled(true);
|
||||
@ -46,7 +53,9 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
|
||||
event.setCancelled(true);
|
||||
@ -55,7 +64,12 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||
if (event.isCancelled()) { return; } if (!Conf.pistonProtectionThroughDenyBuild) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (!Conf.pistonProtectionThroughDenyBuild) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction pistonFaction = Board.getFactionAt(new FLocation(event.getBlock()));
|
||||
|
||||
@ -64,7 +78,8 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
// if potentially pushing into air/water/lava in another territory, we need to check it out
|
||||
if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && !canPistonMoveBlock(pistonFaction, targetBlock.getLocation())) {
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -91,7 +106,8 @@ public class FactionsBlockListener implements Listener {
|
||||
Faction pistonFaction = Board.getFactionAt(new FLocation(event.getBlock()));
|
||||
|
||||
if (!canPistonMoveBlock(pistonFaction, targetLoc)) {
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +115,9 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
Faction otherFaction = Board.getFactionAt(new FLocation(target));
|
||||
|
||||
if (pistonFaction == otherFaction) { return true; }
|
||||
if (pistonFaction == otherFaction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (otherFaction.isNone()) {
|
||||
if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName())) {
|
||||
@ -108,59 +126,90 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
return false;
|
||||
} else if (otherFaction.isSafeZone()) {
|
||||
if (!Conf.safeZoneDenyBuild) { return true; }
|
||||
if (!Conf.safeZoneDenyBuild) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (otherFaction.isWarZone()) {
|
||||
if (!Conf.warZoneDenyBuild) { return true; }
|
||||
if (!Conf.warZoneDenyBuild) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Relation rel = pistonFaction.getRelationTo(otherFaction);
|
||||
|
||||
if (rel.confDenyBuild(otherFaction.hasPlayersOnline())) { return false; }
|
||||
if (rel.confDenyBuild(otherFaction.hasPlayersOnline())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) {
|
||||
String name = player.getName(); if (Conf.playersWhoBypassAllProtection.contains(name)) { return true; }
|
||||
String name = player.getName();
|
||||
if (Conf.playersWhoBypassAllProtection.contains(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer me = FPlayers.i.get(player.getUniqueId().toString()); if (me.isAdminBypassing()) { return true; }
|
||||
FPlayer me = FPlayers.i.get(player.getUniqueId().toString());
|
||||
if (me.isAdminBypassing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FLocation loc = new FLocation(location); Faction otherFaction = Board.getFactionAt(loc);
|
||||
FLocation loc = new FLocation(location);
|
||||
Faction otherFaction = Board.getFactionAt(loc);
|
||||
|
||||
if (otherFaction.isNone()) {
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { return true; }
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) {
|
||||
return true; // This is not faction territory. Use whatever you like here.
|
||||
}
|
||||
|
||||
if (!justCheck) { me.msg("<b>You can't " + action + " in the wilderness."); }
|
||||
if (!justCheck) {
|
||||
me.msg("<b>You can't " + action + " in the wilderness.");
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (otherFaction.isSafeZone()) {
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { return true; }
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) { return true; }
|
||||
if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!justCheck) { me.msg("<b>You can't " + action + " in a safe zone."); }
|
||||
if (!justCheck) {
|
||||
me.msg("<b>You can't " + action + " in a safe zone.");
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (otherFaction.isWarZone()) {
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { return true; }
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) { return true; }
|
||||
if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!justCheck) { me.msg("<b>You can't " + action + " in a war zone."); }
|
||||
if (!justCheck) {
|
||||
me.msg("<b>You can't " + action + " in a war zone.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction(); Relation rel = myFaction.getRelationTo(otherFaction);
|
||||
boolean online = otherFaction.hasPlayersOnline(); boolean pain = !justCheck && rel.confPainBuild(online);
|
||||
Faction myFaction = me.getFaction();
|
||||
Relation rel = myFaction.getRelationTo(otherFaction);
|
||||
boolean online = otherFaction.hasPlayersOnline();
|
||||
boolean pain = !justCheck && rel.confPainBuild(online);
|
||||
boolean deny = rel.confDenyBuild(online);
|
||||
|
||||
// hurt the player for building/destroying in other territory?
|
||||
@ -189,7 +238,8 @@ public class FactionsBlockListener implements Listener {
|
||||
if (!Conf.ownedAreaDenyBuild) {
|
||||
me.msg("<b>It is painful to try to " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc));
|
||||
}
|
||||
} if (Conf.ownedAreaDenyBuild) {
|
||||
}
|
||||
if (Conf.ownedAreaDenyBuild) {
|
||||
if (!justCheck) {
|
||||
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc));
|
||||
}
|
||||
|
@ -25,16 +25,22 @@ public class FactionsChatListener implements Listener {
|
||||
// this is for handling slashless command usage and faction/alliance chat, set at lowest priority so Factions gets to them first
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerEarlyChat(PlayerChatEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player talkingPlayer = event.getPlayer(); String msg = event.getMessage();
|
||||
FPlayer me = FPlayers.i.get(talkingPlayer); ChatMode chat = me.getChatMode();
|
||||
Player talkingPlayer = event.getPlayer();
|
||||
String msg = event.getMessage();
|
||||
FPlayer me = FPlayers.i.get(talkingPlayer);
|
||||
ChatMode chat = me.getChatMode();
|
||||
|
||||
// slashless factions commands need to be handled here if the user isn't in public chat mode
|
||||
if (chat != ChatMode.PUBLIC && p.handleCommand(talkingPlayer, msg, false, true)) {
|
||||
if (Conf.logPlayerCommands) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[PLAYER_COMMAND] " + talkingPlayer.getName() + ": " + msg);
|
||||
} event.setCancelled(true); return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Is it a faction chat message?
|
||||
@ -53,7 +59,8 @@ public class FactionsChatListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (chat == ChatMode.ALLIANCE) {
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
@ -64,37 +71,51 @@ public class FactionsChatListener implements Listener {
|
||||
|
||||
//Send to all our allies
|
||||
for (FPlayer fplayer : FPlayers.i.getOnline()) {
|
||||
if (myFaction.getRelationTo(fplayer) == Relation.ALLY) { fplayer.sendMessage(message); }
|
||||
if (myFaction.getRelationTo(fplayer) == Relation.ALLY) {
|
||||
fplayer.sendMessage(message);
|
||||
}
|
||||
|
||||
//Send to any players who are spying chat
|
||||
else if (fplayer.isSpyingChat()) { fplayer.sendMessage("[ACspy]: " + message); }
|
||||
else if (fplayer.isSpyingChat()) {
|
||||
fplayer.sendMessage("[ACspy]: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getLogger().log(Level.INFO, ChatColor.stripColor("AllianceChat: " + message));
|
||||
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// this is for handling insertion of the player's faction tag, set at highest priority to give other plugins a chance to modify chat first
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Are we to insert the Faction tag into the format?
|
||||
// If we are not to insert it - we are done.
|
||||
if (!Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) { return; }
|
||||
if (!Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player talkingPlayer = event.getPlayer(); String msg = event.getMessage();
|
||||
String eventFormat = event.getFormat(); FPlayer me = FPlayers.i.get(talkingPlayer); int InsertIndex;
|
||||
Player talkingPlayer = event.getPlayer();
|
||||
String msg = event.getMessage();
|
||||
String eventFormat = event.getFormat();
|
||||
FPlayer me = FPlayers.i.get(talkingPlayer);
|
||||
int InsertIndex;
|
||||
|
||||
if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString)) {
|
||||
// we're using the "replace" method of inserting the faction tags
|
||||
// if they stuck "[FACTION_TITLE]" in there, go ahead and do it too
|
||||
if (eventFormat.contains("[FACTION_TITLE]")) {
|
||||
eventFormat = eventFormat.replace("[FACTION_TITLE]", me.getTitle());
|
||||
} InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString);
|
||||
eventFormat = eventFormat.replace(Conf.chatTagReplaceString, ""); Conf.chatTagPadAfter = false;
|
||||
}
|
||||
InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString);
|
||||
eventFormat = eventFormat.replace(Conf.chatTagReplaceString, "");
|
||||
Conf.chatTagPadAfter = false;
|
||||
Conf.chatTagPadBefore = false;
|
||||
} else if (!Conf.chatTagInsertAfterString.isEmpty() && eventFormat.contains(Conf.chatTagInsertAfterString)) {
|
||||
// we're using the "insert after string" method
|
||||
@ -104,7 +125,10 @@ public class FactionsChatListener implements Listener {
|
||||
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString);
|
||||
} else {
|
||||
// we'll fall back to using the index place method
|
||||
InsertIndex = Conf.chatTagInsertIndex; if (InsertIndex > eventFormat.length()) { return; }
|
||||
InsertIndex = Conf.chatTagInsertIndex;
|
||||
if (InsertIndex > eventFormat.length()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String formatStart = eventFormat.substring(0, InsertIndex) + ((Conf.chatTagPadBefore && !me.getChatTag().isEmpty()) ? " " : "");
|
||||
@ -120,10 +144,12 @@ public class FactionsChatListener implements Listener {
|
||||
|
||||
for (Player listeningPlayer : event.getRecipients()) {
|
||||
FPlayer you = FPlayers.i.get(listeningPlayer);
|
||||
String yourFormat = formatStart + me.getChatTag(you).trim() + formatEnd; try {
|
||||
String yourFormat = formatStart + me.getChatTag(you).trim() + formatEnd;
|
||||
try {
|
||||
listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
|
||||
} catch (UnknownFormatConversionException ex) {
|
||||
Conf.chatTagInsertIndex = 0; P.p.log(Level.SEVERE, "Critical error in chat message formatting!");
|
||||
Conf.chatTagInsertIndex = 0;
|
||||
P.p.log(Level.SEVERE, "Critical error in chat message formatting!");
|
||||
P.p.log(Level.SEVERE, "NOTE: This has been automatically fixed right now by setting chatTagInsertIndex to 0.");
|
||||
P.p.log(Level.SEVERE, "For a more proper fix, please read this regarding chat configuration: http://massivecraft.com/plugins/factions/config#Chat_configuration");
|
||||
return;
|
||||
|
@ -34,11 +34,13 @@ public class FactionsEntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
Entity entity = event.getEntity(); if (!(entity instanceof Player)) {
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) entity; FPlayer fplayer = FPlayers.i.get(player);
|
||||
Player player = (Player) entity;
|
||||
FPlayer fplayer = FPlayers.i.get(player);
|
||||
Faction faction = Board.getFactionAt(new FLocation(player.getLocation()));
|
||||
|
||||
PowerLossEvent powerLossEvent = new PowerLossEvent(faction, fplayer);
|
||||
@ -48,7 +50,8 @@ public class FactionsEntityListener implements Listener {
|
||||
if (!Conf.warZonePowerLoss) {
|
||||
powerLossEvent.setMessage("<i>You didn't lose any power since you were in a war zone.");
|
||||
powerLossEvent.setCancelled(true);
|
||||
} if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) {
|
||||
}
|
||||
if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) {
|
||||
powerLossEvent.setMessage("<b>The world you are in has power loss normally disabled, but you still lost power since you were in a war zone.\n<i>Your power is now <h>%d / %d");
|
||||
}
|
||||
} else if (faction.isNone() && !Conf.wildernessPowerLoss && !Conf.worldsNoWildernessProtection.contains(player.getWorld().getName())) {
|
||||
@ -72,7 +75,8 @@ public class FactionsEntityListener implements Listener {
|
||||
fplayer.onDeath();
|
||||
}
|
||||
// Send the message from the powerLossEvent
|
||||
final String msg = powerLossEvent.getMessage(); if (msg != null && !msg.isEmpty()) {
|
||||
final String msg = powerLossEvent.getMessage();
|
||||
if (msg != null && !msg.isEmpty()) {
|
||||
fplayer.msg(msg, fplayer.getPowerRounded(), fplayer.getPowerMaxRounded());
|
||||
}
|
||||
}
|
||||
@ -83,7 +87,9 @@ public class FactionsEntityListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
|
||||
@ -98,14 +104,18 @@ public class FactionsEntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = event.getLocation(); Entity boomer = event.getEntity();
|
||||
Location loc = event.getLocation();
|
||||
Entity boomer = event.getEntity();
|
||||
Faction faction = Board.getFactionAt(new FLocation(loc));
|
||||
|
||||
if (faction.noExplosionsInTerritory()) {
|
||||
// faction is peaceful and has explosions set to disabled
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean online = faction.hasPlayersOnline();
|
||||
@ -135,12 +145,17 @@ public class FactionsEntityListener implements Listener {
|
||||
// TNT in water/lava doesn't normally destroy any surrounding blocks, which is usually desired behavior, but...
|
||||
// this change below provides workaround for waterwalling providing perfect protection,
|
||||
// and makes cheap (non-obsidian) TNT cannons require minor maintenance between shots
|
||||
Block center = loc.getBlock(); if (center.isLiquid()) {
|
||||
Block center = loc.getBlock();
|
||||
if (center.isLiquid()) {
|
||||
// a single surrounding block in all 6 directions is broken if the material is weak enough
|
||||
List<Block> targets = new ArrayList<Block>(); targets.add(center.getRelative(0, 0, 1));
|
||||
targets.add(center.getRelative(0, 0, -1)); targets.add(center.getRelative(0, 1, 0));
|
||||
targets.add(center.getRelative(0, -1, 0)); targets.add(center.getRelative(1, 0, 0));
|
||||
targets.add(center.getRelative(-1, 0, 0)); for (Block target : targets) {
|
||||
List<Block> targets = new ArrayList<Block>();
|
||||
targets.add(center.getRelative(0, 0, 1));
|
||||
targets.add(center.getRelative(0, 0, -1));
|
||||
targets.add(center.getRelative(0, 1, 0));
|
||||
targets.add(center.getRelative(0, -1, 0));
|
||||
targets.add(center.getRelative(1, 0, 0));
|
||||
targets.add(center.getRelative(-1, 0, 0));
|
||||
for (Block target : targets) {
|
||||
int id = target.getTypeId();
|
||||
// ignore air, bedrock, water, lava, obsidian, enchanting table, etc.... too bad we can't get a blast resistance value through Bukkit yet
|
||||
if (id != 0 && (id < 7 || id > 11) && id != 49 && id != 90 && id != 116 && id != 119 && id != 120 && id != 130) {
|
||||
@ -154,45 +169,62 @@ public class FactionsEntityListener implements Listener {
|
||||
// mainly for flaming arrows; don't want allies or people in safe zones to be ignited even after damage event is cancelled
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0);
|
||||
if (!this.canDamagerHurtDamagee(sub, false)) { event.setCancelled(true); } sub = null;
|
||||
if (!this.canDamagerHurtDamagee(sub, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
sub = null;
|
||||
}
|
||||
|
||||
private static final Set<PotionEffectType> badPotionEffects = new LinkedHashSet<PotionEffectType>(Arrays.asList(PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER, PotionEffectType.POISON, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.WITHER));
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPotionSplashEvent(PotionSplashEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// see if the potion has a harmful effect
|
||||
boolean badjuju = false; for (PotionEffect effect : event.getPotion().getEffects()) {
|
||||
boolean badjuju = false;
|
||||
for (PotionEffect effect : event.getPotion().getEffects()) {
|
||||
if (badPotionEffects.contains(effect.getType())) {
|
||||
badjuju = true; break;
|
||||
badjuju = true;
|
||||
break;
|
||||
}
|
||||
} if (!badjuju) { return; }
|
||||
}
|
||||
if (!badjuju) {
|
||||
return;
|
||||
}
|
||||
|
||||
ProjectileSource thrower = event.getPotion().getShooter(); if (!(thrower instanceof Entity)) {
|
||||
ProjectileSource thrower = event.getPotion().getShooter();
|
||||
if (!(thrower instanceof Entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// scan through affected entities to make sure they're all valid targets
|
||||
Iterator<LivingEntity> iter = event.getAffectedEntities().iterator(); while (iter.hasNext()) {
|
||||
Iterator<LivingEntity> iter = event.getAffectedEntities().iterator();
|
||||
while (iter.hasNext()) {
|
||||
LivingEntity target = iter.next();
|
||||
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent((Entity) thrower, target, EntityDamageEvent.DamageCause.CUSTOM, 0);
|
||||
if (!this.canDamagerHurtDamagee(sub, true)) {
|
||||
event.setIntensity(target, 0.0); // affected entity list doesn't accept modification (so no iter.remove()), but this works
|
||||
} sub = null;
|
||||
}
|
||||
sub = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPlayerInSafeZone(Entity damagee) {
|
||||
if (!(damagee instanceof Player)) {
|
||||
return false;
|
||||
} if (Board.getFactionAt(new FLocation(damagee.getLocation())).isSafeZone()) {
|
||||
}
|
||||
if (Board.getFactionAt(new FLocation(damagee.getLocation())).isSafeZone()) {
|
||||
return true;
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canDamagerHurtDamagee(EntityDamageByEntityEvent sub) {
|
||||
@ -200,13 +232,19 @@ public class FactionsEntityListener implements Listener {
|
||||
}
|
||||
|
||||
public boolean canDamagerHurtDamagee(EntityDamageByEntityEvent sub, boolean notify) {
|
||||
Entity damager = sub.getDamager(); Entity damagee = sub.getEntity(); double damage = sub.getDamage();
|
||||
Entity damager = sub.getDamager();
|
||||
Entity damagee = sub.getEntity();
|
||||
double damage = sub.getDamage();
|
||||
|
||||
if (!(damagee instanceof Player)) { return true; }
|
||||
if (!(damagee instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer defender = FPlayers.i.get((Player) damagee);
|
||||
|
||||
if (defender == null || defender.getPlayer() == null) { return true; }
|
||||
if (defender == null || defender.getPlayer() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Location defenderLoc = defender.getPlayer().getLocation();
|
||||
Faction defLocFaction = Board.getFactionAt(new FLocation(defenderLoc));
|
||||
@ -217,7 +255,9 @@ public class FactionsEntityListener implements Listener {
|
||||
}
|
||||
|
||||
if (damager == damagee) // ender pearl usage and other self-inflicted damage
|
||||
{ return true; }
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Players can not take attack damage in a SafeZone, or possibly peaceful territory
|
||||
if (defLocFaction.noPvPInTerritory()) {
|
||||
@ -225,22 +265,31 @@ public class FactionsEntityListener implements Listener {
|
||||
if (notify) {
|
||||
FPlayer attacker = FPlayers.i.get((Player) damager);
|
||||
attacker.msg("<i>You can't hurt other players in " + (defLocFaction.isSafeZone() ? "a SafeZone." : "peaceful territory."));
|
||||
} return false;
|
||||
} return !defLocFaction.noMonstersInTerritory();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return !defLocFaction.noMonstersInTerritory();
|
||||
}
|
||||
|
||||
if (!(damager instanceof Player)) { return true; }
|
||||
if (!(damager instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer attacker = FPlayers.i.get((Player) damager);
|
||||
|
||||
if (attacker == null || attacker.getPlayer() == null) { return true; }
|
||||
if (attacker == null || attacker.getPlayer() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Conf.playersWhoBypassAllProtection.contains(attacker.getName())) { return true; }
|
||||
if (Conf.playersWhoBypassAllProtection.contains(attacker.getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (attacker.hasLoginPvpDisabled()) {
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt other players for " + Conf.noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in.");
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Faction locFaction = Board.getFactionAt(new FLocation(attacker));
|
||||
@ -249,31 +298,47 @@ public class FactionsEntityListener implements Listener {
|
||||
if (locFaction.noPvPInTerritory()) {
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt other players while you are in " + (locFaction.isSafeZone() ? "a SafeZone." : "peaceful territory."));
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (locFaction.isWarZone() && Conf.warZoneFriendlyFire) { return true; }
|
||||
if (locFaction.isWarZone() && Conf.warZoneFriendlyFire) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Conf.worldsIgnorePvP.contains(defenderLoc.getWorld().getName())) { return true; }
|
||||
if (Conf.worldsIgnorePvP.contains(defenderLoc.getWorld().getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Faction defendFaction = defender.getFaction(); Faction attackFaction = attacker.getFaction();
|
||||
Faction defendFaction = defender.getFaction();
|
||||
Faction attackFaction = attacker.getFaction();
|
||||
|
||||
if (attackFaction.isNone() && Conf.disablePVPForFactionlessPlayers) {
|
||||
if (notify) { attacker.msg("<i>You can't hurt other players until you join a faction."); } return false;
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt other players until you join a faction.");
|
||||
}
|
||||
return false;
|
||||
} else if (defendFaction.isNone()) {
|
||||
if (defLocFaction == attackFaction && Conf.enablePVPAgainstFactionlessInAttackersLand) {
|
||||
// Allow PVP vs. Factionless in attacker's faction territory
|
||||
return true;
|
||||
} else if (Conf.disablePVPForFactionlessPlayers) {
|
||||
if (notify) { attacker.msg("<i>You can't hurt players who are not currently in a faction."); }
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt players who are not currently in a faction.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (defendFaction.isPeaceful()) {
|
||||
if (notify) { attacker.msg("<i>You can't hurt players who are in a peaceful faction."); } return false;
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt players who are in a peaceful faction.");
|
||||
}
|
||||
return false;
|
||||
} else if (attackFaction.isPeaceful()) {
|
||||
if (notify) { attacker.msg("<i>You can't hurt players while you are in a peaceful faction."); }
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt players while you are in a peaceful faction.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -281,15 +346,23 @@ public class FactionsEntityListener implements Listener {
|
||||
|
||||
// You can not hurt neutral factions
|
||||
if (Conf.disablePVPBetweenNeutralFactions && relation.isNeutral()) {
|
||||
if (notify) { attacker.msg("<i>You can't hurt neutral factions. Declare them as an enemy."); } return false;
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt neutral factions. Declare them as an enemy.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Players without faction may be hurt anywhere
|
||||
if (!defender.hasFaction()) { return true; }
|
||||
if (!defender.hasFaction()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// You can never hurt faction members or allies
|
||||
if (relation.isMember() || relation.isAlly()) {
|
||||
if (notify) { attacker.msg("<i>You can't hurt %s<i>.", defender.describeTo(attacker)); } return false;
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt %s<i>.", defender.describeTo(attacker));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean ownTerritory = defender.isInOwnTerritory();
|
||||
@ -299,12 +372,14 @@ public class FactionsEntityListener implements Listener {
|
||||
if (notify) {
|
||||
attacker.msg("<i>You can't hurt %s<i> in their own territory unless you declare them as an enemy.", defender.describeTo(attacker));
|
||||
defender.msg("%s<i> tried to hurt you.", attacker.describeTo(defender, true));
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Damage will be dealt. However check if the damage should be reduced.
|
||||
if (damage > 0.0 && ownTerritory && Conf.territoryShieldFactor > 0) {
|
||||
int newDamage = (int) Math.ceil(damage * (1D - Conf.territoryShieldFactor)); sub.setDamage(newDamage);
|
||||
int newDamage = (int) Math.ceil(damage * (1D - Conf.territoryShieldFactor));
|
||||
sub.setDamage(newDamage);
|
||||
|
||||
// Send message
|
||||
if (notify) {
|
||||
@ -329,10 +404,13 @@ public class FactionsEntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityTarget(EntityTargetEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if there is a target
|
||||
Entity target = event.getTarget(); if (target == null) {
|
||||
Entity target = event.getTarget();
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -349,11 +427,16 @@ public class FactionsEntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPaintingBreak(HangingBreakEvent event) {
|
||||
if (event.isCancelled()) { return; } if (event.getCause() == RemoveCause.EXPLOSION) {
|
||||
Location loc = event.getEntity().getLocation(); Faction faction = Board.getFactionAt(new FLocation(loc));
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (event.getCause() == RemoveCause.EXPLOSION) {
|
||||
Location loc = event.getEntity().getLocation();
|
||||
Faction faction = Board.getFactionAt(new FLocation(loc));
|
||||
if (faction.noExplosionsInTerritory()) {
|
||||
// faction is peaceful and has explosions set to disabled
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean online = faction.hasPlayersOnline();
|
||||
@ -371,7 +454,8 @@ public class FactionsEntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity breaker = ((HangingBreakByEntityEvent) event).getRemover(); if (!(breaker instanceof Player)) {
|
||||
Entity breaker = ((HangingBreakByEntityEvent) event).getRemover();
|
||||
if (!(breaker instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -382,7 +466,9 @@ public class FactionsEntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPaintingPlace(HangingPlaceEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "place paintings", false)) {
|
||||
event.setCancelled(true);
|
||||
@ -391,24 +477,32 @@ public class FactionsEntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
// for now, only interested in Enderman and Wither boss tomfoolery
|
||||
if (!(entity instanceof Enderman) && !(entity instanceof Wither)) { return; }
|
||||
if (!(entity instanceof Enderman) && !(entity instanceof Wither)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = event.getBlock().getLocation();
|
||||
|
||||
if (entity instanceof Enderman) {
|
||||
if (stopEndermanBlockManipulation(loc)) { event.setCancelled(true); }
|
||||
if (stopEndermanBlockManipulation(loc)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (entity instanceof Wither) {
|
||||
Faction faction = Board.getFactionAt(new FLocation(loc));
|
||||
// it's a bit crude just using fireball protection, but I'd rather not add in a whole new set of xxxBlockWitherExplosion or whatever
|
||||
if ((faction.isNone() && Conf.wildernessBlockFireballs && !Conf.worldsNoWildernessProtection.contains(loc.getWorld().getName())) ||
|
||||
(faction.isNormal() && (faction.hasPlayersOnline() ? Conf.territoryBlockFireballs : Conf.territoryBlockFireballsWhenOffline)) ||
|
||||
(faction.isWarZone() && Conf.warZoneBlockFireballs) ||
|
||||
faction.isSafeZone()) { event.setCancelled(true); }
|
||||
faction.isSafeZone()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,7 +519,8 @@ public class FactionsEntityListener implements Listener {
|
||||
return true;
|
||||
}
|
||||
|
||||
FLocation fLoc = new FLocation(loc); Faction claimFaction = Board.getFactionAt(fLoc);
|
||||
FLocation fLoc = new FLocation(loc);
|
||||
Faction claimFaction = Board.getFactionAt(fLoc);
|
||||
|
||||
if (claimFaction.isNone()) {
|
||||
return Conf.wildernessDenyEndermanBlocks;
|
||||
|
@ -14,30 +14,44 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
public class FactionsExploitListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void obsidianGenerator(BlockFromToEvent event) {
|
||||
if (event.isCancelled() == true || !Conf.handleExploitObsidianGenerators) { return; }
|
||||
if (event.isCancelled() == true || !Conf.handleExploitObsidianGenerators) {
|
||||
return;
|
||||
}
|
||||
|
||||
// thanks to ObGenBlocker and WorldGuard for this method
|
||||
Block block = event.getToBlock(); int source = event.getBlock().getTypeId(); int target = block.getTypeId();
|
||||
if ((target == 55 || target == 132) && (source == 0 || source == 10 || source == 11)) { block.setTypeId(0); }
|
||||
Block block = event.getToBlock();
|
||||
int source = event.getBlock().getTypeId();
|
||||
int target = block.getTypeId();
|
||||
if ((target == 55 || target == 132) && (source == 0 || source == 10 || source == 11)) {
|
||||
block.setTypeId(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void enderPearlTeleport(PlayerTeleportEvent event) {
|
||||
if (event.isCancelled() == true || !Conf.handleExploitEnderPearlClipping) { return; }
|
||||
if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { return; }
|
||||
if (event.isCancelled() == true || !Conf.handleExploitEnderPearlClipping) {
|
||||
return;
|
||||
}
|
||||
if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this exploit works when the target location is within 0.31 blocks or so of a door or glass block or similar...
|
||||
Location target = event.getTo(); Location from = event.getFrom();
|
||||
Location target = event.getTo();
|
||||
Location from = event.getFrom();
|
||||
|
||||
// blocks who occupy less than 1 block width or length wise need to be handled differently
|
||||
Material mat = event.getTo().getBlock().getType();
|
||||
if (((mat == Material.THIN_GLASS || mat == Material.IRON_FENCE) && clippingThrough(target, from, 0.65)) || ((mat == Material.FENCE || mat == Material.NETHER_FENCE) && clippingThrough(target, from, 0.45))) {
|
||||
event.setTo(from); return;
|
||||
event.setTo(from);
|
||||
return;
|
||||
}
|
||||
|
||||
// simple fix otherwise: ender pearl target locations are standardized to be in the center (X/Z) of the target block, not at the edges
|
||||
target.setX(target.getBlockX() + 0.5); target.setZ(target.getBlockZ() + 0.5); event.setTo(target);
|
||||
target.setX(target.getBlockX() + 0.5);
|
||||
target.setZ(target.getBlockZ() + 0.5);
|
||||
event.setTo(target);
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,24 +49,29 @@ public class FactionsPlayerListener implements Listener {
|
||||
// and update their last login time to point to when the logged off, for auto-remove routine
|
||||
me.setLastLoginTime(System.currentTimeMillis());
|
||||
|
||||
Faction myFaction = me.getFaction(); if (myFaction != null) {
|
||||
Faction myFaction = me.getFaction();
|
||||
if (myFaction != null) {
|
||||
myFaction.memberLoggedOff();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// quick check to make sure player is moving between chunks; good performance boost
|
||||
if (event.getFrom().getBlockX() >> 4 == event.getTo().getBlockX() >> 4 && event.getFrom().getBlockZ() >> 4 == event.getTo().getBlockZ() >> 4 && event.getFrom().getWorld() == event.getTo().getWorld()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer(); FPlayer me = FPlayers.i.get(player);
|
||||
Player player = event.getPlayer();
|
||||
FPlayer me = FPlayers.i.get(player);
|
||||
|
||||
// Did we change coord?
|
||||
FLocation from = me.getLastStoodAt(); FLocation to = new FLocation(event.getTo());
|
||||
FLocation from = me.getLastStoodAt();
|
||||
FLocation to = new FLocation(event.getTo());
|
||||
|
||||
if (from.equals(to)) {
|
||||
return;
|
||||
@ -77,7 +82,8 @@ public class FactionsPlayerListener implements Listener {
|
||||
me.setLastStoodAt(to);
|
||||
|
||||
// Did we change "host"(faction)?
|
||||
Faction factionFrom = Board.getFactionAt(from); Faction factionTo = Board.getFactionAt(to);
|
||||
Faction factionFrom = Board.getFactionAt(from);
|
||||
Faction factionTo = Board.getFactionAt(to);
|
||||
boolean changedFaction = (factionFrom != factionTo);
|
||||
|
||||
/* Was used for displaying on Spout but we removed Spout compatibility.
|
||||
@ -88,7 +94,8 @@ public class FactionsPlayerListener implements Listener {
|
||||
if (me.isMapAutoUpdating()) {
|
||||
me.sendMessage(Board.getMap(me.getFaction(), to, player.getLocation().getYaw()));
|
||||
} else {
|
||||
Faction myFaction = me.getFaction(); String ownersTo = myFaction.getOwnerListString(to);
|
||||
Faction myFaction = me.getFaction();
|
||||
String ownersTo = myFaction.getOwnerListString(to);
|
||||
|
||||
if (changedFaction) {
|
||||
me.sendFactionHereMessage();
|
||||
@ -100,7 +107,9 @@ public class FactionsPlayerListener implements Listener {
|
||||
if (Conf.ownedMessageByChunk || !ownersFrom.equals(ownersTo)) {
|
||||
if (!ownersTo.isEmpty()) {
|
||||
me.sendMessage(Conf.ownedLandMessage + ownersTo);
|
||||
} else if (!Conf.publicLandMessage.isEmpty()) { me.sendMessage(Conf.publicLandMessage); }
|
||||
} else if (!Conf.publicLandMessage.isEmpty()) {
|
||||
me.sendMessage(Conf.publicLandMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,7 +121,8 @@ public class FactionsPlayerListener implements Listener {
|
||||
me.setIsAutoSafeClaimEnabled(false);
|
||||
} else {
|
||||
if (!Board.getFactionAt(to).isSafeZone()) {
|
||||
Board.setFactionAt(Factions.i.getSafeZone(), to); me.msg("<i>This land is now a safe zone.");
|
||||
Board.setFactionAt(Factions.i.getSafeZone(), to);
|
||||
me.msg("<i>This land is now a safe zone.");
|
||||
}
|
||||
}
|
||||
} else if (me.isAutoWarClaimEnabled()) {
|
||||
@ -120,7 +130,8 @@ public class FactionsPlayerListener implements Listener {
|
||||
me.setIsAutoWarClaimEnabled(false);
|
||||
} else {
|
||||
if (!Board.getFactionAt(to).isWarZone()) {
|
||||
Board.setFactionAt(Factions.i.getWarZone(), to); me.msg("<i>This land is now a war zone.");
|
||||
Board.setFactionAt(Factions.i.getWarZone(), to);
|
||||
me.msg("<i>This land is now a war zone.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -128,27 +139,38 @@ public class FactionsPlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
// only need to check right-clicks and physical as of MC 1.4+; good performance boost
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) { return; }
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getClickedBlock(); Player player = event.getPlayer();
|
||||
Block block = event.getClickedBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (block == null) {
|
||||
return; // clicked in air, apparently
|
||||
}
|
||||
|
||||
if (!canPlayerUseBlock(player, block, false)) {
|
||||
event.setCancelled(true); if (Conf.handleExploitInteractionSpam) {
|
||||
String name = player.getName(); InteractAttemptSpam attempt = interactSpammers.get(name);
|
||||
event.setCancelled(true);
|
||||
if (Conf.handleExploitInteractionSpam) {
|
||||
String name = player.getName();
|
||||
InteractAttemptSpam attempt = interactSpammers.get(name);
|
||||
if (attempt == null) {
|
||||
attempt = new InteractAttemptSpam(); interactSpammers.put(name, attempt);
|
||||
} int count = attempt.increment(); if (count >= 10) {
|
||||
attempt = new InteractAttemptSpam();
|
||||
interactSpammers.put(name, attempt);
|
||||
}
|
||||
int count = attempt.increment();
|
||||
if (count >= 10) {
|
||||
FPlayer me = FPlayers.i.get(name);
|
||||
me.msg("<b>Ouch, that is starting to hurt. You should give it a rest.");
|
||||
player.damage(NumberConversions.floor((double) count / 10));
|
||||
}
|
||||
} return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
@ -156,7 +178,8 @@ public class FactionsPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
if (!playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) {
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,18 +193,31 @@ public class FactionsPlayerListener implements Listener {
|
||||
|
||||
// returns the current attempt count
|
||||
public int increment() {
|
||||
long Now = System.currentTimeMillis(); if (Now > lastAttempt + 2000) { attempts = 1; } else { attempts++; }
|
||||
lastAttempt = Now; return attempts;
|
||||
long Now = System.currentTimeMillis();
|
||||
if (Now > lastAttempt + 2000) {
|
||||
attempts = 1;
|
||||
} else {
|
||||
attempts++;
|
||||
}
|
||||
lastAttempt = Now;
|
||||
return attempts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean playerCanUseItemHere(Player player, Location location, Material material, boolean justCheck) {
|
||||
String name = player.getName(); if (Conf.playersWhoBypassAllProtection.contains(name)) { return true; }
|
||||
String name = player.getName();
|
||||
if (Conf.playersWhoBypassAllProtection.contains(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer me = FPlayers.i.get(player); if (me.isAdminBypassing()) { return true; }
|
||||
FPlayer me = FPlayers.i.get(player);
|
||||
if (me.isAdminBypassing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FLocation loc = new FLocation(location); Faction otherFaction = Board.getFactionAt(loc);
|
||||
FLocation loc = new FLocation(location);
|
||||
Faction otherFaction = Board.getFactionAt(loc);
|
||||
|
||||
if (otherFaction.hasPlayersOnline()) {
|
||||
if (!Conf.territoryDenyUseageMaterials.contains(material)) {
|
||||
@ -204,20 +240,29 @@ public class FactionsPlayerListener implements Listener {
|
||||
|
||||
return false;
|
||||
} else if (otherFaction.isSafeZone()) {
|
||||
if (!Conf.safeZoneDenyUseage || Permission.MANAGE_SAFE_ZONE.has(player)) { return true; }
|
||||
if (!Conf.safeZoneDenyUseage || Permission.MANAGE_SAFE_ZONE.has(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!justCheck) { me.msg("<b>You can't use <h>%s<b> in a safe zone.", TextUtil.getMaterialName(material)); }
|
||||
if (!justCheck) {
|
||||
me.msg("<b>You can't use <h>%s<b> in a safe zone.", TextUtil.getMaterialName(material));
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (otherFaction.isWarZone()) {
|
||||
if (!Conf.warZoneDenyUseage || Permission.MANAGE_WAR_ZONE.has(player)) { return true; }
|
||||
if (!Conf.warZoneDenyUseage || Permission.MANAGE_WAR_ZONE.has(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!justCheck) { me.msg("<b>You can't use <h>%s<b> in a war zone.", TextUtil.getMaterialName(material)); }
|
||||
if (!justCheck) {
|
||||
me.msg("<b>You can't use <h>%s<b> in a war zone.", TextUtil.getMaterialName(material));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction(); Relation rel = myFaction.getRelationTo(otherFaction);
|
||||
Faction myFaction = me.getFaction();
|
||||
Relation rel = myFaction.getRelationTo(otherFaction);
|
||||
|
||||
// Cancel if we are not in our own territory
|
||||
if (rel.confDenyUseage()) {
|
||||
@ -241,24 +286,37 @@ public class FactionsPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) {
|
||||
if (Conf.playersWhoBypassAllProtection.contains(player.getName())) { return true; }
|
||||
if (Conf.playersWhoBypassAllProtection.contains(player.getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer me = FPlayers.i.get(player); if (me.isAdminBypassing()) { return true; }
|
||||
FPlayer me = FPlayers.i.get(player);
|
||||
if (me.isAdminBypassing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Material material = block.getType(); FLocation loc = new FLocation(block);
|
||||
Material material = block.getType();
|
||||
FLocation loc = new FLocation(block);
|
||||
Faction otherFaction = Board.getFactionAt(loc);
|
||||
|
||||
// no door/chest/whatever protection in wilderness, war zones, or safe zones
|
||||
if (!otherFaction.isNormal()) { return true; }
|
||||
if (!otherFaction.isNormal()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We only care about some material types.
|
||||
if (otherFaction.hasPlayersOnline()) {
|
||||
if (!Conf.territoryProtectedMaterials.contains(material)) { return true; }
|
||||
if (!Conf.territoryProtectedMaterials.contains(material)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (!Conf.territoryProtectedMaterialsWhenOffline.contains(material)) { return true; }
|
||||
if (!Conf.territoryProtectedMaterialsWhenOffline.contains(material)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction(); Relation rel = myFaction.getRelationTo(otherFaction);
|
||||
Faction myFaction = me.getFaction();
|
||||
Relation rel = myFaction.getRelationTo(otherFaction);
|
||||
|
||||
// You may use any block unless it is another faction's territory...
|
||||
if (rel.isNeutral() || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) {
|
||||
@ -287,10 +345,11 @@ public class FactionsPlayerListener implements Listener {
|
||||
|
||||
me.getPower(); // update power, so they won't have gained any while dead
|
||||
|
||||
Location home = me.getFaction().getHome(); if (Conf.homesEnabled &&
|
||||
Conf.homesTeleportToOnDeath &&
|
||||
home != null &&
|
||||
(Conf.homesRespawnFromNoPowerLossWorlds || !Conf.worldsNoPowerLoss.contains(event.getPlayer().getWorld().getName()))) {
|
||||
Location home = me.getFaction().getHome();
|
||||
if (Conf.homesEnabled &&
|
||||
Conf.homesTeleportToOnDeath &&
|
||||
home != null &&
|
||||
(Conf.homesRespawnFromNoPowerLossWorlds || !Conf.worldsNoPowerLoss.contains(event.getPlayer().getWorld().getName()))) {
|
||||
event.setRespawnLocation(home);
|
||||
}
|
||||
}
|
||||
@ -299,23 +358,31 @@ public class FactionsPlayerListener implements Listener {
|
||||
// but these separate bucket events below always fire without fail
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlockClicked(); Player player = event.getPlayer();
|
||||
Block block = event.getBlockClicked();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) {
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlockClicked(); Player player = event.getPlayer();
|
||||
Block block = event.getBlockClicked();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) {
|
||||
event.setCancelled(true); return;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,8 +396,11 @@ public class FactionsPlayerListener implements Listener {
|
||||
FPlayer me = FPlayers.i.get(player);
|
||||
|
||||
String shortCmd; // command without the slash at the beginning
|
||||
if (fullCmd.startsWith("/")) { shortCmd = fullCmd.substring(1); } else {
|
||||
shortCmd = fullCmd; fullCmd = "/" + fullCmd;
|
||||
if (fullCmd.startsWith("/")) {
|
||||
shortCmd = fullCmd.substring(1);
|
||||
} else {
|
||||
shortCmd = fullCmd;
|
||||
fullCmd = "/" + fullCmd;
|
||||
}
|
||||
|
||||
if (me.hasFaction() &&
|
||||
@ -346,45 +416,60 @@ public class FactionsPlayerListener implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
Relation rel = me.getRelationToLocation(); if (rel.isAtLeast(Relation.ALLY)) {
|
||||
Relation rel = me.getRelationToLocation();
|
||||
if (rel.isAtLeast(Relation.ALLY)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rel.isNeutral() && !Conf.territoryNeutralDenyCommands.isEmpty() && !me.isAdminBypassing() && isCommandInList(fullCmd, shortCmd, Conf.territoryNeutralDenyCommands.iterator())) {
|
||||
me.msg("<b>You can't use the command \"" + fullCmd + "\" in neutral territory."); return true;
|
||||
me.msg("<b>You can't use the command \"" + fullCmd + "\" in neutral territory.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (rel.isEnemy() && !Conf.territoryEnemyDenyCommands.isEmpty() && !me.isAdminBypassing() && isCommandInList(fullCmd, shortCmd, Conf.territoryEnemyDenyCommands.iterator())) {
|
||||
me.msg("<b>You can't use the command \"" + fullCmd + "\" in enemy territory."); return true;
|
||||
me.msg("<b>You can't use the command \"" + fullCmd + "\" in enemy territory.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isCommandInList(String fullCmd, String shortCmd, Iterator<String> iter) {
|
||||
String cmdCheck; while (iter.hasNext()) {
|
||||
cmdCheck = iter.next(); if (cmdCheck == null) {
|
||||
iter.remove(); continue;
|
||||
String cmdCheck;
|
||||
while (iter.hasNext()) {
|
||||
cmdCheck = iter.next();
|
||||
if (cmdCheck == null) {
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
cmdCheck = cmdCheck.toLowerCase();
|
||||
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) { return true; }
|
||||
} return false;
|
||||
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
FPlayer badGuy = FPlayers.i.get(event.getPlayer()); if (badGuy == null) {
|
||||
FPlayer badGuy = FPlayers.i.get(event.getPlayer());
|
||||
if (badGuy == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if player was banned (not just kicked), get rid of their stored info
|
||||
if (Conf.removePlayerDataWhenBanned && event.getReason().equals("Banned by admin.")) {
|
||||
if (badGuy.getRole() == Role.ADMIN) { badGuy.getFaction().promoteNewLeader(); }
|
||||
if (badGuy.getRole() == Role.ADMIN) {
|
||||
badGuy.getFaction().promoteNewLeader();
|
||||
}
|
||||
|
||||
badGuy.leave(false); badGuy.detach();
|
||||
badGuy.leave(false);
|
||||
badGuy.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ public enum ChatMode {
|
||||
public final String nicename;
|
||||
|
||||
private ChatMode(final int value, final String nicename) {
|
||||
this.value = value; this.nicename = nicename;
|
||||
this.value = value;
|
||||
this.nicename = nicename;
|
||||
}
|
||||
|
||||
public boolean isAtLeast(ChatMode role) {
|
||||
@ -26,6 +27,12 @@ public enum ChatMode {
|
||||
}
|
||||
|
||||
public ChatMode getNext() {
|
||||
if (this == PUBLIC) { return ALLIANCE; } if (this == ALLIANCE) { return FACTION; } return PUBLIC;
|
||||
if (this == PUBLIC) {
|
||||
return ALLIANCE;
|
||||
}
|
||||
if (this == ALLIANCE) {
|
||||
return FACTION;
|
||||
}
|
||||
return PUBLIC;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ public enum Relation {
|
||||
public final String nicename;
|
||||
|
||||
private Relation(final int value, final String nicename) {
|
||||
this.value = value; this.nicename = nicename;
|
||||
this.value = value;
|
||||
this.nicename = nicename;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,50 +48,86 @@ public enum Relation {
|
||||
}
|
||||
|
||||
public ChatColor getColor() {
|
||||
if (this == MEMBER) { return Conf.colorMember; } else if (this == ALLY) {
|
||||
if (this == MEMBER) {
|
||||
return Conf.colorMember;
|
||||
} else if (this == ALLY) {
|
||||
return Conf.colorAlly;
|
||||
} else if (this == NEUTRAL) { return Conf.colorNeutral; } else { return Conf.colorEnemy; }
|
||||
} else if (this == NEUTRAL) {
|
||||
return Conf.colorNeutral;
|
||||
} else {
|
||||
return Conf.colorEnemy;
|
||||
}
|
||||
}
|
||||
|
||||
// return appropriate Conf setting for DenyBuild based on this relation and their online status
|
||||
public boolean confDenyBuild(boolean online) {
|
||||
if (isMember()) { return false; }
|
||||
if (isMember()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (online) {
|
||||
if (isEnemy()) { return Conf.territoryEnemyDenyBuild; } else if (isAlly()) {
|
||||
if (isEnemy()) {
|
||||
return Conf.territoryEnemyDenyBuild;
|
||||
} else if (isAlly()) {
|
||||
return Conf.territoryAllyDenyBuild;
|
||||
} else { return Conf.territoryDenyBuild; }
|
||||
} else {
|
||||
return Conf.territoryDenyBuild;
|
||||
}
|
||||
} else {
|
||||
if (isEnemy()) { return Conf.territoryEnemyDenyBuildWhenOffline; } else if (isAlly()) {
|
||||
if (isEnemy()) {
|
||||
return Conf.territoryEnemyDenyBuildWhenOffline;
|
||||
} else if (isAlly()) {
|
||||
return Conf.territoryAllyDenyBuildWhenOffline;
|
||||
} else { return Conf.territoryDenyBuildWhenOffline; }
|
||||
} else {
|
||||
return Conf.territoryDenyBuildWhenOffline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return appropriate Conf setting for PainBuild based on this relation and their online status
|
||||
public boolean confPainBuild(boolean online) {
|
||||
if (isMember()) { return false; }
|
||||
if (isMember()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (online) {
|
||||
if (isEnemy()) { return Conf.territoryEnemyPainBuild; } else if (isAlly()) {
|
||||
if (isEnemy()) {
|
||||
return Conf.territoryEnemyPainBuild;
|
||||
} else if (isAlly()) {
|
||||
return Conf.territoryAllyPainBuild;
|
||||
} else { return Conf.territoryPainBuild; }
|
||||
} else {
|
||||
return Conf.territoryPainBuild;
|
||||
}
|
||||
} else {
|
||||
if (isEnemy()) { return Conf.territoryEnemyPainBuildWhenOffline; } else if (isAlly()) {
|
||||
if (isEnemy()) {
|
||||
return Conf.territoryEnemyPainBuildWhenOffline;
|
||||
} else if (isAlly()) {
|
||||
return Conf.territoryAllyPainBuildWhenOffline;
|
||||
} else { return Conf.territoryPainBuildWhenOffline; }
|
||||
} else {
|
||||
return Conf.territoryPainBuildWhenOffline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return appropriate Conf setting for DenyUseage based on this relation
|
||||
public boolean confDenyUseage() {
|
||||
if (isMember()) { return false; } else if (isEnemy()) {
|
||||
if (isMember()) {
|
||||
return false;
|
||||
} else if (isEnemy()) {
|
||||
return Conf.territoryEnemyDenyUseage;
|
||||
} else if (isAlly()) { return Conf.territoryAllyDenyUseage; } else { return Conf.territoryDenyUseage; }
|
||||
} else if (isAlly()) {
|
||||
return Conf.territoryAllyDenyUseage;
|
||||
} else {
|
||||
return Conf.territoryDenyUseage;
|
||||
}
|
||||
}
|
||||
|
||||
public double getRelationCost() {
|
||||
if (isEnemy()) { return Conf.econCostEnemy; } else if (isAlly()) { return Conf.econCostAlly; } else {
|
||||
if (isEnemy()) {
|
||||
return Conf.econCostEnemy;
|
||||
} else if (isAlly()) {
|
||||
return Conf.econCostAlly;
|
||||
} else {
|
||||
return Conf.econCostNeutral;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ public enum Role {
|
||||
public final String nicename;
|
||||
|
||||
private Role(final int value, final String nicename) {
|
||||
this.value = value; this.nicename = nicename;
|
||||
this.value = value;
|
||||
this.nicename = nicename;
|
||||
}
|
||||
|
||||
public boolean isAtLeast(Role role) {
|
||||
|
@ -32,7 +32,10 @@ public class AsciiCompass {
|
||||
}
|
||||
|
||||
public static AsciiCompass.Point getCompassPointForDirection(double inDegrees) {
|
||||
double degrees = (inDegrees - 180) % 360; if (degrees < 0) { degrees += 360; }
|
||||
double degrees = (inDegrees - 180) % 360;
|
||||
if (degrees < 0) {
|
||||
degrees += 360;
|
||||
}
|
||||
|
||||
if (0 <= degrees && degrees < 22.5) {
|
||||
return AsciiCompass.Point.N;
|
||||
@ -50,22 +53,34 @@ public class AsciiCompass {
|
||||
return AsciiCompass.Point.W;
|
||||
} else if (292.5 <= degrees && degrees < 337.5) {
|
||||
return AsciiCompass.Point.NW;
|
||||
} else if (337.5 <= degrees && degrees < 360.0) { return AsciiCompass.Point.N; } else { return null; }
|
||||
} else if (337.5 <= degrees && degrees < 360.0) {
|
||||
return AsciiCompass.Point.N;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) {
|
||||
ArrayList<String> ret = new ArrayList<String>(); String row;
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
String row;
|
||||
|
||||
row = ""; row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
|
||||
row = "";
|
||||
row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
|
||||
row += Point.N.toString(Point.N == point, colorActive, colorDefault);
|
||||
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault); ret.add(row);
|
||||
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
|
||||
row = ""; row += Point.W.toString(Point.W == point, colorActive, colorDefault); row += colorDefault + "+";
|
||||
row += Point.E.toString(Point.E == point, colorActive, colorDefault); ret.add(row);
|
||||
row = "";
|
||||
row += Point.W.toString(Point.W == point, colorActive, colorDefault);
|
||||
row += colorDefault + "+";
|
||||
row += Point.E.toString(Point.E == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
|
||||
row = ""; row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
|
||||
row = "";
|
||||
row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
|
||||
row += Point.S.toString(Point.S == point, colorActive, colorDefault);
|
||||
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault); ret.add(row);
|
||||
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -14,17 +14,22 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
private transient double toleranceMillis;
|
||||
|
||||
public AutoLeaveProcessTask() {
|
||||
ArrayList<FPlayer> fplayers = new ArrayList<FPlayer>(FPlayers.i.get()); this.iterator = fplayers.listIterator();
|
||||
this.toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000; this.readyToGo = true;
|
||||
ArrayList<FPlayer> fplayers = new ArrayList<FPlayer>(FPlayers.i.get());
|
||||
this.iterator = fplayers.listIterator();
|
||||
this.toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
|
||||
this.readyToGo = true;
|
||||
this.finished = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (Conf.autoLeaveAfterDaysOfInactivity <= 0.0 || Conf.autoLeaveRoutineMaxMillisecondsPerTick <= 0.0) {
|
||||
this.stop(); return;
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!readyToGo) { return; }
|
||||
if (!readyToGo) {
|
||||
return;
|
||||
}
|
||||
// this is set so it only does one iteration at a time, no matter how frequently the timer fires
|
||||
readyToGo = false;
|
||||
// and this is tracked to keep one iteration from dragging on too long and possibly choking the system if there are a very large number of players to go through
|
||||
@ -35,7 +40,8 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
|
||||
// if this iteration has been running for maximum time, stop to take a breather until next tick
|
||||
if (now > loopStartTime + Conf.autoLeaveRoutineMaxMillisecondsPerTick) {
|
||||
readyToGo = true; return;
|
||||
readyToGo = true;
|
||||
return;
|
||||
}
|
||||
|
||||
FPlayer fplayer = iterator.next();
|
||||
@ -47,10 +53,13 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
// if player is faction admin, sort out the faction since he's going away
|
||||
if (fplayer.getRole() == Role.ADMIN) {
|
||||
Faction faction = fplayer.getFaction();
|
||||
if (faction != null) { fplayer.getFaction().promoteNewLeader(); }
|
||||
if (faction != null) {
|
||||
fplayer.getFaction().promoteNewLeader();
|
||||
}
|
||||
}
|
||||
|
||||
fplayer.leave(false); iterator.remove(); // go ahead and remove this list's link to the FPlayer object
|
||||
fplayer.leave(false);
|
||||
iterator.remove(); // go ahead and remove this list's link to the FPlayer object
|
||||
fplayer.detach();
|
||||
}
|
||||
}
|
||||
@ -61,7 +70,8 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
|
||||
// we're done, shut down
|
||||
public void stop() {
|
||||
readyToGo = false; finished = true;
|
||||
readyToGo = false;
|
||||
finished = true;
|
||||
|
||||
this.cancel();
|
||||
}
|
||||
|
@ -12,11 +12,16 @@ public class AutoLeaveTask implements Runnable {
|
||||
}
|
||||
|
||||
public synchronized void run() {
|
||||
if (task != null && !task.isFinished()) { return; }
|
||||
if (task != null && !task.isFinished()) {
|
||||
return;
|
||||
}
|
||||
|
||||
task = new AutoLeaveProcessTask(); task.runTaskTimer(P.p, 1, 1);
|
||||
task = new AutoLeaveProcessTask();
|
||||
task.runTaskTimer(P.p, 1, 1);
|
||||
|
||||
// maybe setting has been changed? if so, restart this task at new rate
|
||||
if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) { P.p.startAutoLeaveTask(true); }
|
||||
if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) {
|
||||
P.p.startAutoLeaveTask(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,29 +27,45 @@ public class LazyLocation {
|
||||
}
|
||||
|
||||
public LazyLocation(final String worldName, final double x, final double y, final double z, final float yaw, final float pitch) {
|
||||
this.worldName = worldName; this.x = x; this.y = y; this.z = z; this.yaw = yaw; this.pitch = pitch;
|
||||
this.worldName = worldName;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
// This returns the actual Location
|
||||
public final Location getLocation() {
|
||||
// make sure Location is initialized before returning it
|
||||
initLocation(); return location;
|
||||
initLocation();
|
||||
return location;
|
||||
}
|
||||
|
||||
// change the Location
|
||||
public final void setLocation(Location loc) {
|
||||
this.location = loc; this.worldName = loc.getWorld().getName(); this.x = loc.getX(); this.y = loc.getY();
|
||||
this.z = loc.getZ(); this.yaw = loc.getYaw(); this.pitch = loc.getPitch();
|
||||
this.location = loc;
|
||||
this.worldName = loc.getWorld().getName();
|
||||
this.x = loc.getX();
|
||||
this.y = loc.getY();
|
||||
this.z = loc.getZ();
|
||||
this.yaw = loc.getYaw();
|
||||
this.pitch = loc.getPitch();
|
||||
}
|
||||
|
||||
|
||||
// This initializes the Location
|
||||
private void initLocation() {
|
||||
// if location is already initialized, simply return
|
||||
if (location != null) { return; }
|
||||
if (location != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get World; hopefully it's initialized at this point
|
||||
World world = Bukkit.getWorld(worldName); if (world == null) { return; }
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// store the Location for future calls, and pass it on
|
||||
location = new Location(world, x, y, z, yaw, pitch);
|
||||
|
@ -19,20 +19,27 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLoca
|
||||
@Override
|
||||
public Map<FLocation, Set<String>> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject(); if (obj == null) {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<FLocation, Set<String>> locationMap = new ConcurrentHashMap<FLocation, Set<String>>();
|
||||
Set<String> nameSet; Iterator<JsonElement> iter; String worldName; String[] coords; int x, z;
|
||||
Set<String> nameSet;
|
||||
Iterator<JsonElement> iter;
|
||||
String worldName;
|
||||
String[] coords;
|
||||
int x, z;
|
||||
|
||||
for (Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
worldName = entry.getKey();
|
||||
for (Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
coords = entry2.getKey().trim().split("[,\\s]+"); x = Integer.parseInt(coords[0]);
|
||||
coords = entry2.getKey().trim().split("[,\\s]+");
|
||||
x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]);
|
||||
|
||||
nameSet = new HashSet<String>(); iter = entry2.getValue().getAsJsonArray().iterator();
|
||||
nameSet = new HashSet<String>();
|
||||
iter = entry2.getValue().getAsJsonArray().iterator();
|
||||
while (iter.hasNext()) {
|
||||
nameSet.add(iter.next().getAsString());
|
||||
}
|
||||
@ -56,18 +63,27 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLoca
|
||||
|
||||
try {
|
||||
if (src != null) {
|
||||
FLocation loc; String locWorld; Set<String> nameSet; Iterator<String> iter; JsonArray nameArray;
|
||||
FLocation loc;
|
||||
String locWorld;
|
||||
Set<String> nameSet;
|
||||
Iterator<String> iter;
|
||||
JsonArray nameArray;
|
||||
JsonPrimitive nameElement;
|
||||
|
||||
for (Entry<FLocation, Set<String>> entry : src.entrySet()) {
|
||||
loc = entry.getKey(); locWorld = loc.getWorldName(); nameSet = entry.getValue();
|
||||
loc = entry.getKey();
|
||||
locWorld = loc.getWorldName();
|
||||
nameSet = entry.getValue();
|
||||
|
||||
if (nameSet == null || nameSet.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nameArray = new JsonArray(); iter = nameSet.iterator(); while (iter.hasNext()) {
|
||||
nameElement = new JsonPrimitive(iter.next()); nameArray.add(nameElement);
|
||||
nameArray = new JsonArray();
|
||||
iter = nameSet.iterator();
|
||||
while (iter.hasNext()) {
|
||||
nameElement = new JsonPrimitive(iter.next());
|
||||
nameArray.add(nameElement);
|
||||
}
|
||||
|
||||
if (!obj.has(locWorld)) {
|
||||
@ -76,7 +92,8 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLoca
|
||||
|
||||
obj.get(locWorld).getAsJsonObject().add(loc.getCoordString(), nameArray);
|
||||
}
|
||||
} return obj;
|
||||
}
|
||||
return obj;
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -97,10 +97,12 @@ public final class Metrics {
|
||||
this.plugin = plugin;
|
||||
|
||||
// load the config
|
||||
configurationFile = getConfigFile(); configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
||||
configurationFile = getConfigFile();
|
||||
configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
||||
|
||||
// add some defaults
|
||||
configuration.addDefault("opt-out", false); configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
configuration.addDefault("opt-out", false);
|
||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
configuration.addDefault("debug", false);
|
||||
|
||||
// Do we need to create the file?
|
||||
@ -110,7 +112,8 @@ public final class Metrics {
|
||||
}
|
||||
|
||||
// Load the guid then
|
||||
guid = configuration.getString("guid"); debug = configuration.getBoolean("debug", false);
|
||||
guid = configuration.getString("guid");
|
||||
debug = configuration.getBoolean("debug", false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,7 +146,8 @@ public final class Metrics {
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && task != null) {
|
||||
task.cancel(); task = null;
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +190,8 @@ public final class Metrics {
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
configuration.set("opt-out", false); configuration.save(configurationFile);
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
@ -206,12 +211,14 @@ public final class Metrics {
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut()) {
|
||||
configuration.set("opt-out", true); configuration.save(configurationFile);
|
||||
configuration.set("opt-out", true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (task != null) {
|
||||
task.cancel(); task = null;
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -238,24 +245,30 @@ public final class Metrics {
|
||||
*/
|
||||
private void postPlugin(boolean isPing) throws IOException {
|
||||
// Server software specific section
|
||||
PluginDescriptionFile description = plugin.getDescription(); String pluginName = description.getName();
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
String pluginName = description.getName();
|
||||
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
String pluginVersion = description.getVersion(); String serverVersion = Bukkit.getVersion();
|
||||
String pluginVersion = description.getVersion();
|
||||
String serverVersion = Bukkit.getVersion();
|
||||
int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
|
||||
|
||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
||||
|
||||
// Construct the post data
|
||||
StringBuilder json = new StringBuilder(1024); json.append('{');
|
||||
StringBuilder json = new StringBuilder(1024);
|
||||
json.append('{');
|
||||
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
appendJSONPair(json, "guid", guid); appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "guid", guid);
|
||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "server_version", serverVersion);
|
||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||
|
||||
// New data as of R6
|
||||
String osname = System.getProperty("os.name"); String osarch = System.getProperty("os.arch");
|
||||
String osversion = System.getProperty("os.version"); String java_version = System.getProperty("java.version");
|
||||
String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
String osversion = System.getProperty("os.version");
|
||||
String java_version = System.getProperty("java.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
@ -263,9 +276,12 @@ public final class Metrics {
|
||||
osarch = "x86_64";
|
||||
}
|
||||
|
||||
appendJSONPair(json, "osname", osname); appendJSONPair(json, "osarch", osarch);
|
||||
appendJSONPair(json, "osversion", osversion); appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); appendJSONPair(json, "java_version", java_version);
|
||||
appendJSONPair(json, "osname", osname);
|
||||
appendJSONPair(json, "osarch", osarch);
|
||||
appendJSONPair(json, "osversion", osversion);
|
||||
appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
||||
appendJSONPair(json, "java_version", java_version);
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing) {
|
||||
@ -290,7 +306,8 @@ public final class Metrics {
|
||||
}
|
||||
|
||||
|
||||
byte[] uncompressed = json.toString().getBytes(); byte[] compressed = gzip(json.toString());
|
||||
byte[] uncompressed = json.toString().getBytes();
|
||||
byte[] compressed = gzip(json.toString());
|
||||
|
||||
// Headers
|
||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||
@ -307,14 +324,17 @@ public final class Metrics {
|
||||
}
|
||||
|
||||
// Write the data
|
||||
OutputStream os = connection.getOutputStream(); os.write(compressed); os.flush();
|
||||
OutputStream os = connection.getOutputStream();
|
||||
os.write(compressed);
|
||||
os.flush();
|
||||
|
||||
// Now read the response
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String response = reader.readLine();
|
||||
|
||||
// close resources
|
||||
os.close(); reader.close();
|
||||
os.close();
|
||||
reader.close();
|
||||
|
||||
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
||||
if (response == null) {
|
||||
@ -335,10 +355,12 @@ public final class Metrics {
|
||||
* @return
|
||||
*/
|
||||
public static byte[] gzip(String input) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos); gzos.write(input.getBytes("UTF-8"));
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@ -360,7 +382,8 @@ public final class Metrics {
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer"); return true;
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
@ -380,7 +403,8 @@ public final class Metrics {
|
||||
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value); isValueNumeric = true;
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
@ -390,7 +414,8 @@ public final class Metrics {
|
||||
json.append(',');
|
||||
}
|
||||
|
||||
json.append(escapeJSON(key)); json.append(':');
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
|
||||
if (isValueNumeric) {
|
||||
json.append(value);
|
||||
@ -409,21 +434,39 @@ public final class Metrics {
|
||||
private static String escapeJSON(String text) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append('"'); for (int index = 0; index < text.length(); index++) {
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
char chr = text.charAt(index);
|
||||
|
||||
switch (chr) {
|
||||
case '"': case '\\': builder.append('\\'); builder.append(chr); break;
|
||||
case '\b': builder.append("\\b"); break; case '\t': builder.append("\\t"); break;
|
||||
case '\n': builder.append("\\n"); break; case '\r': builder.append("\\r"); break;
|
||||
default: if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u").append(t.substring(t.length() - 4));
|
||||
} else {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
builder.append(chr);
|
||||
} break;
|
||||
break;
|
||||
case '\b':
|
||||
builder.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
builder.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
builder.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u").append(t.substring(t.length() - 4));
|
||||
} else {
|
||||
builder.append(chr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} builder.append('"');
|
||||
}
|
||||
builder.append('"');
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ public class MiscUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = entity.getClass().getSimpleName(); name = name.substring(5); // Remove "Craft"
|
||||
String name = entity.getClass().getSimpleName();
|
||||
name = name.substring(5); // Remove "Craft"
|
||||
|
||||
return EntityType.fromName(name);
|
||||
}
|
||||
@ -24,7 +25,9 @@ public class MiscUtil {
|
||||
long[] values = new long[(int) Math.abs(end - start) + 1];
|
||||
|
||||
if (end < start) {
|
||||
long oldstart = start; start = end; end = oldstart;
|
||||
long oldstart = start;
|
||||
start = end;
|
||||
end = oldstart;
|
||||
}
|
||||
|
||||
for (long i = start; i <= end; i++) {
|
||||
@ -40,13 +43,15 @@ public class MiscUtil {
|
||||
public static String getComparisonString(String str) {
|
||||
String ret = "";
|
||||
|
||||
str = ChatColor.stripColor(str); str = str.toLowerCase();
|
||||
str = ChatColor.stripColor(str);
|
||||
str = str.toLowerCase();
|
||||
|
||||
for (char c : str.toCharArray()) {
|
||||
if (substanceChars.contains(String.valueOf(c))) {
|
||||
ret += c;
|
||||
}
|
||||
} return ret.toLowerCase();
|
||||
}
|
||||
return ret.toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,14 +20,18 @@ public class MyLocationTypeAdapter implements JsonDeserializer<LazyLocation>, Js
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
|
||||
String worldName = obj.get(WORLD).getAsString(); double x = obj.get(X).getAsDouble();
|
||||
double y = obj.get(Y).getAsDouble(); double z = obj.get(Z).getAsDouble();
|
||||
float yaw = obj.get(YAW).getAsFloat(); float pitch = obj.get(PITCH).getAsFloat();
|
||||
String worldName = obj.get(WORLD).getAsString();
|
||||
double x = obj.get(X).getAsDouble();
|
||||
double y = obj.get(Y).getAsDouble();
|
||||
double z = obj.get(Z).getAsDouble();
|
||||
float yaw = obj.get(YAW).getAsFloat();
|
||||
float pitch = obj.get(PITCH).getAsFloat();
|
||||
|
||||
return new LazyLocation(worldName, x, y, z, yaw, pitch);
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(); P.p.log(Level.WARNING, "Error encountered while deserializing a LazyLocation.");
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a LazyLocation.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -37,12 +41,17 @@ public class MyLocationTypeAdapter implements JsonDeserializer<LazyLocation>, Js
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
try {
|
||||
obj.addProperty(WORLD, src.getWorldName()); obj.addProperty(X, src.getX()); obj.addProperty(Y, src.getY());
|
||||
obj.addProperty(Z, src.getZ()); obj.addProperty(YAW, src.getYaw()); obj.addProperty(PITCH, src.getPitch());
|
||||
obj.addProperty(WORLD, src.getWorldName());
|
||||
obj.addProperty(X, src.getX());
|
||||
obj.addProperty(Y, src.getY());
|
||||
obj.addProperty(Z, src.getZ());
|
||||
obj.addProperty(YAW, src.getYaw());
|
||||
obj.addProperty(PITCH, src.getPitch());
|
||||
|
||||
return obj;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(); P.p.log(Level.WARNING, "Error encountered while serializing a LazyLocation.");
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a LazyLocation.");
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ public class RelationUtil {
|
||||
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) {
|
||||
String ret = "";
|
||||
|
||||
Faction thatFaction = getFaction(that); if (thatFaction == null) {
|
||||
Faction thatFaction = getFaction(that);
|
||||
if (thatFaction == null) {
|
||||
return "ERROR"; // ERROR
|
||||
}
|
||||
|
||||
@ -26,7 +27,8 @@ public class RelationUtil {
|
||||
ret = thatFaction.getTag();
|
||||
}
|
||||
} else if (that instanceof FPlayer) {
|
||||
FPlayer fplayerthat = (FPlayer) that; if (that == me) {
|
||||
FPlayer fplayerthat = (FPlayer) that;
|
||||
if (that == me) {
|
||||
ret = "you";
|
||||
} else if (thatFaction == myFaction) {
|
||||
ret = fplayerthat.getNameAndTitle();
|
||||
@ -51,11 +53,13 @@ public class RelationUtil {
|
||||
}
|
||||
|
||||
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) {
|
||||
Faction fthat = getFaction(that); if (fthat == null) {
|
||||
Faction fthat = getFaction(that);
|
||||
if (fthat == null) {
|
||||
return Relation.NEUTRAL; // ERROR
|
||||
}
|
||||
|
||||
Faction fme = getFaction(me); if (fme == null) {
|
||||
Faction fme = getFaction(me);
|
||||
if (fme == null) {
|
||||
return Relation.NEUTRAL; // ERROR
|
||||
}
|
||||
|
||||
@ -92,7 +96,8 @@ public class RelationUtil {
|
||||
}
|
||||
|
||||
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) {
|
||||
Faction thatFaction = getFaction(that); if (thatFaction != null) {
|
||||
Faction thatFaction = getFaction(that);
|
||||
if (thatFaction != null) {
|
||||
if (thatFaction.isPeaceful() && thatFaction != getFaction(me)) {
|
||||
return Conf.colorPeaceful;
|
||||
}
|
||||
|
@ -42,11 +42,15 @@ public abstract class SpiralTask implements Runnable {
|
||||
// limit is determined based on spiral leg length for given radius; see insideRadius()
|
||||
this.limit = (radius - 1) * 2;
|
||||
|
||||
this.world = Bukkit.getWorld(fLocation.getWorldName()); if (this.world == null) {
|
||||
P.p.log(Level.WARNING, "[SpiralTask] A valid world must be specified!"); this.stop(); return;
|
||||
this.world = Bukkit.getWorld(fLocation.getWorldName());
|
||||
if (this.world == null) {
|
||||
P.p.log(Level.WARNING, "[SpiralTask] A valid world must be specified!");
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
this.x = (int) fLocation.getX(); this.z = (int) fLocation.getZ();
|
||||
this.x = (int) fLocation.getX();
|
||||
this.z = (int) fLocation.getZ();
|
||||
|
||||
this.readyToGo = true;
|
||||
|
||||
@ -94,17 +98,24 @@ public abstract class SpiralTask implements Runnable {
|
||||
*/
|
||||
|
||||
public final void setTaskID(int ID) {
|
||||
if (ID == -1) { this.stop(); } taskID = ID;
|
||||
if (ID == -1) {
|
||||
this.stop();
|
||||
}
|
||||
taskID = ID;
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
if (!this.valid() || !readyToGo) { return; }
|
||||
if (!this.valid() || !readyToGo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this is set so it only does one iteration at a time, no matter how frequently the timer fires
|
||||
readyToGo = false;
|
||||
|
||||
// make sure we're still inside the specified radius
|
||||
if (!this.insideRadius()) { return; }
|
||||
if (!this.insideRadius()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// track this to keep one iteration from dragging on too long and possibly choking the system
|
||||
long loopStartTime = now();
|
||||
@ -113,11 +124,14 @@ public abstract class SpiralTask implements Runnable {
|
||||
while (now() < loopStartTime + 20) {
|
||||
// run the primary task on the current X/Z coordinates
|
||||
if (!this.work()) {
|
||||
this.finish(); return;
|
||||
this.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// move on to next chunk in spiral
|
||||
if (!this.moveToNext()) { return; }
|
||||
if (!this.moveToNext()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ready for the next iteration to run
|
||||
@ -126,30 +140,44 @@ public abstract class SpiralTask implements Runnable {
|
||||
|
||||
// step through chunks in spiral pattern from center; returns false if we're done, otherwise returns true
|
||||
public final boolean moveToNext() {
|
||||
if (!this.valid()) { return false; }
|
||||
if (!this.valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure we don't need to turn down the next leg of the spiral
|
||||
if (current < length) {
|
||||
current++;
|
||||
|
||||
// if we're outside the radius, we're done
|
||||
if (!this.insideRadius()) { return false; }
|
||||
if (!this.insideRadius()) {
|
||||
return false;
|
||||
}
|
||||
} else { // one leg/side of the spiral down...
|
||||
current = 0; isZLeg ^= true;
|
||||
current = 0;
|
||||
isZLeg ^= true;
|
||||
// every second leg (between X and Z legs, negative or positive), length increases
|
||||
if (isZLeg) {
|
||||
isNeg ^= true; length++;
|
||||
isNeg ^= true;
|
||||
length++;
|
||||
}
|
||||
}
|
||||
|
||||
// move one chunk further in the appropriate direction
|
||||
if (isZLeg) { z += (isNeg) ? -1 : 1; } else { x += (isNeg) ? -1 : 1; }
|
||||
if (isZLeg) {
|
||||
z += (isNeg) ? -1 : 1;
|
||||
} else {
|
||||
x += (isNeg) ? -1 : 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean insideRadius() {
|
||||
boolean inside = current < limit; if (!inside) { this.finish(); } return inside;
|
||||
boolean inside = current < limit;
|
||||
if (!inside) {
|
||||
this.finish();
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
// for successful completion
|
||||
@ -160,9 +188,13 @@ public abstract class SpiralTask implements Runnable {
|
||||
|
||||
// we're done, whether finished or cancelled
|
||||
public final void stop() {
|
||||
if (!this.valid()) { return; }
|
||||
if (!this.valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
readyToGo = false; Bukkit.getServer().getScheduler().cancelTask(taskID); taskID = -1;
|
||||
readyToGo = false;
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskID);
|
||||
taskID = -1;
|
||||
}
|
||||
|
||||
// is this task still valid/workable?
|
||||
|
@ -14,6 +14,7 @@ public class FCommandHandler implements CommandExecutor {
|
||||
if (P.p.logPlayerCommands()) {
|
||||
Bukkit.getLogger().info("[PLAYER_COMMAND] " + sender.getName() + ": " + cmd.getName() + args);
|
||||
}
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
public List<MCommand<?>> subCommands;
|
||||
|
||||
public void addSubCommand(MCommand<?> subCommand) {
|
||||
subCommand.commandChain.addAll(this.commandChain); subCommand.commandChain.add(this);
|
||||
subCommand.commandChain.addAll(this.commandChain);
|
||||
subCommand.commandChain.add(this);
|
||||
this.subCommands.add(subCommand);
|
||||
}
|
||||
|
||||
@ -42,10 +43,13 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
|
||||
public String getHelpShort() {
|
||||
if (this.helpShort == null) {
|
||||
String pdesc = p.perm.getPermissionDescription(this.permission); if (pdesc != null) {
|
||||
String pdesc = p.perm.getPermissionDescription(this.permission);
|
||||
if (pdesc != null) {
|
||||
return pdesc;
|
||||
} return "*info unavailable*";
|
||||
} return this.helpShort;
|
||||
}
|
||||
return "*info unavailable*";
|
||||
}
|
||||
return this.helpShort;
|
||||
}
|
||||
|
||||
public List<String> helpLong;
|
||||
@ -69,34 +73,50 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
|
||||
this.allowNoSlashAccess = false;
|
||||
|
||||
this.subCommands = new ArrayList<MCommand<?>>(); this.aliases = new ArrayList<String>();
|
||||
this.subCommands = new ArrayList<MCommand<?>>();
|
||||
this.aliases = new ArrayList<String>();
|
||||
|
||||
this.requiredArgs = new ArrayList<String>(); this.optionalArgs = new LinkedHashMap<String, String>();
|
||||
this.requiredArgs = new ArrayList<String>();
|
||||
this.optionalArgs = new LinkedHashMap<String, String>();
|
||||
|
||||
this.helpShort = null; this.helpLong = new ArrayList<String>(); this.visibility = CommandVisibility.VISIBLE;
|
||||
this.helpShort = null;
|
||||
this.helpLong = new ArrayList<String>();
|
||||
this.visibility = CommandVisibility.VISIBLE;
|
||||
}
|
||||
|
||||
// The commandChain is a list of the parent command chain used to get to this command.
|
||||
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
|
||||
// Set the execution-time specific variables
|
||||
this.sender = sender; if (sender instanceof Player) {
|
||||
this.me = (Player) sender; this.senderIsConsole = false;
|
||||
this.sender = sender;
|
||||
if (sender instanceof Player) {
|
||||
this.me = (Player) sender;
|
||||
this.senderIsConsole = false;
|
||||
} else {
|
||||
this.me = null; this.senderIsConsole = true;
|
||||
} this.args = args; this.commandChain = commandChain;
|
||||
this.me = null;
|
||||
this.senderIsConsole = true;
|
||||
}
|
||||
this.args = args;
|
||||
this.commandChain = commandChain;
|
||||
|
||||
// Is there a matching sub command?
|
||||
if (args.size() > 0) {
|
||||
for (MCommand<?> subCommand : this.subCommands) {
|
||||
if (subCommand.aliases.contains(args.get(0))) {
|
||||
args.remove(0); commandChain.add(this); subCommand.execute(sender, args, commandChain); return;
|
||||
args.remove(0);
|
||||
commandChain.add(this);
|
||||
subCommand.execute(sender, args, commandChain);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!validCall(this.sender, this.args)) { return; }
|
||||
if (!validCall(this.sender, this.args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isEnabled()) { return; }
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
perform();
|
||||
}
|
||||
@ -141,19 +161,26 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
if (this.senderMustBePlayer && !(sender instanceof Player)) {
|
||||
if (informSenderIfNot) {
|
||||
msg(Lang.commandSenderMustBePlayer);
|
||||
} return false;
|
||||
} return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) {
|
||||
if (this.permission == null) { return true; } return p.perm.has(sender, this.permission, informSenderIfNot);
|
||||
if (this.permission == null) {
|
||||
return true;
|
||||
}
|
||||
return p.perm.has(sender, this.permission, informSenderIfNot);
|
||||
}
|
||||
|
||||
public boolean validArgs(List<String> args, CommandSender sender) {
|
||||
if (args.size() < this.requiredArgs.size()) {
|
||||
if (sender != null) {
|
||||
msg(Lang.commandToFewArgs); sender.sendMessage(this.getUseageTemplate());
|
||||
} return false;
|
||||
msg(Lang.commandToFewArgs);
|
||||
sender.sendMessage(this.getUseageTemplate());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.errorOnToManyArgs) {
|
||||
@ -162,8 +189,10 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
List<String> theToMany = args.subList(this.requiredArgs.size() + this.optionalArgs.size(), args.size());
|
||||
msg(Lang.commandToManyArgs, TextUtil.implode(theToMany, " "));
|
||||
sender.sendMessage(this.getUseageTemplate());
|
||||
} return false;
|
||||
} return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validArgs(List<String> args) {
|
||||
@ -175,10 +204,13 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getUseageTemplate(List<MCommand<?>> commandChain, boolean addShortHelp) {
|
||||
StringBuilder ret = new StringBuilder(); ret.append(p.txt.parseTags("<c>")); ret.append('/');
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append(p.txt.parseTags("<c>"));
|
||||
ret.append('/');
|
||||
|
||||
for (MCommand<?> mc : commandChain) {
|
||||
ret.append(TextUtil.implode(mc.aliases, ",")); ret.append(' ');
|
||||
ret.append(TextUtil.implode(mc.aliases, ","));
|
||||
ret.append(' ');
|
||||
}
|
||||
|
||||
ret.append(TextUtil.implode(this.aliases, ","));
|
||||
@ -190,19 +222,23 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
}
|
||||
|
||||
for (Entry<String, String> optionalArg : this.optionalArgs.entrySet()) {
|
||||
String val = optionalArg.getValue(); if (val == null) {
|
||||
String val = optionalArg.getValue();
|
||||
if (val == null) {
|
||||
val = "";
|
||||
} else {
|
||||
val = "=" + val;
|
||||
} args.add("[" + optionalArg.getKey() + val + "]");
|
||||
}
|
||||
args.add("[" + optionalArg.getKey() + val + "]");
|
||||
}
|
||||
|
||||
if (args.size() > 0) {
|
||||
ret.append(p.txt.parseTags("<p> ")); ret.append(TextUtil.implode(args, " "));
|
||||
ret.append(p.txt.parseTags("<p> "));
|
||||
ret.append(TextUtil.implode(args, " "));
|
||||
}
|
||||
|
||||
if (addShortHelp) {
|
||||
ret.append(p.txt.parseTags(" <i>")); ret.append(this.getHelpShort());
|
||||
ret.append(p.txt.parseTags(" <i>"));
|
||||
ret.append(this.getHelpShort());
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
@ -242,14 +278,16 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
public boolean argIsSet(int idx) {
|
||||
if (this.args.size() < idx + 1) {
|
||||
return false;
|
||||
} return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// STRING ======================
|
||||
public String argAsString(int idx, String def) {
|
||||
if (this.args.size() < idx + 1) {
|
||||
return def;
|
||||
} return this.args.get(idx);
|
||||
}
|
||||
return this.args.get(idx);
|
||||
}
|
||||
|
||||
public String argAsString(int idx) {
|
||||
@ -258,8 +296,12 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
|
||||
// INT ======================
|
||||
public Integer strAsInt(String str, Integer def) {
|
||||
if (str == null) { return def; } try {
|
||||
Integer ret = Integer.parseInt(str); return ret;
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
try {
|
||||
Integer ret = Integer.parseInt(str);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
@ -275,8 +317,12 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
|
||||
// Double ======================
|
||||
public Double strAsDouble(String str, Double def) {
|
||||
if (str == null) { return def; } try {
|
||||
Double ret = Double.parseDouble(str); return ret;
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
try {
|
||||
Double ret = Double.parseDouble(str);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
@ -296,11 +342,15 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
str = str.toLowerCase();
|
||||
if (str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1")) {
|
||||
return true;
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean argAsBool(int idx, boolean def) {
|
||||
String str = this.argAsString(idx); if (str == null) { return def; }
|
||||
String str = this.argAsString(idx);
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return strAsBool(str);
|
||||
}
|
||||
@ -314,7 +364,8 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
Player ret = def;
|
||||
|
||||
if (name != null) {
|
||||
Player player = Bukkit.getServer().getPlayer(name); if (player != null) {
|
||||
Player player = Bukkit.getServer().getPlayer(name);
|
||||
if (player != null) {
|
||||
ret = player;
|
||||
}
|
||||
}
|
||||
@ -343,7 +394,8 @@ public abstract class MCommand<T extends MPlugin> {
|
||||
Player ret = def;
|
||||
|
||||
if (name != null) {
|
||||
List<Player> players = Bukkit.getServer().matchPlayer(name); if (players.size() > 0) {
|
||||
List<Player> players = Bukkit.getServer().matchPlayer(name);
|
||||
if (players.size() > 0) {
|
||||
ret = players.get(0);
|
||||
}
|
||||
}
|
||||
|
@ -63,10 +63,12 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
private long timeEnableStart;
|
||||
|
||||
public boolean preEnable() {
|
||||
log("=== ENABLE START ==="); timeEnableStart = System.currentTimeMillis();
|
||||
log("=== ENABLE START ===");
|
||||
timeEnableStart = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
Metrics metrics = new Metrics(this); metrics.start();
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
// Failed to submit the stats :-(
|
||||
}
|
||||
@ -74,19 +76,23 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
this.getDataFolder().mkdirs();
|
||||
|
||||
// Create Utility Instances
|
||||
this.perm = new PermUtil(this); this.persist = new Persist(this);
|
||||
this.perm = new PermUtil(this);
|
||||
this.persist = new Persist(this);
|
||||
|
||||
// GSON 2.1 is now embedded in CraftBukkit, used by the auto-updater: https://github.com/Bukkit/CraftBukkit/commit/0ed1d1fdbb1e0bc09a70bc7bfdf40c1de8411665
|
||||
// if ( ! lib.require("gson.jar", "http://search.maven.org/remotecontent?filepath=com/google/code/gson/gson/2.1/gson-2.1.jar")) return false;
|
||||
this.gson = this.getGsonBuilder().create();
|
||||
|
||||
this.txt = new TextUtil(); initTXT();
|
||||
this.txt = new TextUtil();
|
||||
initTXT();
|
||||
|
||||
// attempt to get first command defined in plugin.yml as reference command, if any commands are defined in there
|
||||
// reference command will be used to prevent "unknown command" console messages
|
||||
try {
|
||||
Map<String, Map<String, Object>> refCmd = this.getDescription().getCommands();
|
||||
if (refCmd != null && !refCmd.isEmpty()) { this.refCommand = (String) (refCmd.keySet().toArray()[0]); }
|
||||
if (refCmd != null && !refCmd.isEmpty()) {
|
||||
this.refCommand = (String) (refCmd.keySet().toArray()[0]);
|
||||
}
|
||||
} catch (ClassCastException ex) {
|
||||
}
|
||||
|
||||
@ -106,7 +112,8 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
|
||||
loadLang();
|
||||
|
||||
loadSuccessful = true; return true;
|
||||
loadSuccessful = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void postEnable() {
|
||||
@ -114,16 +121,24 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void loadLang() {
|
||||
File lang = new File(getDataFolder(), "lang.yml"); OutputStream out = null;
|
||||
InputStream defLangStream = this.getResource("lang.yml"); if (!lang.exists()) {
|
||||
File lang = new File(getDataFolder(), "lang.yml");
|
||||
OutputStream out = null;
|
||||
InputStream defLangStream = this.getResource("lang.yml");
|
||||
if (!lang.exists()) {
|
||||
try {
|
||||
getDataFolder().mkdir(); lang.createNewFile(); if (defLangStream != null) {
|
||||
out = new FileOutputStream(lang); int read; byte[] bytes = new byte[1024];
|
||||
getDataFolder().mkdir();
|
||||
lang.createNewFile();
|
||||
if (defLangStream != null) {
|
||||
out = new FileOutputStream(lang);
|
||||
int read;
|
||||
byte[] bytes = new byte[1024];
|
||||
|
||||
while ((read = defLangStream.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read);
|
||||
} YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defLangStream);
|
||||
TL.setFile(defConfig); return;
|
||||
}
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defLangStream);
|
||||
TL.setFile(defConfig);
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // So they notice
|
||||
@ -137,7 +152,8 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} if (out != null) {
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
@ -148,30 +164,38 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang); for (TL item : TL.values()) {
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
||||
for (TL item : TL.values()) {
|
||||
if (conf.getString(item.getPath()) == null) {
|
||||
conf.set(item.getPath(), item.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
TL.setFile(conf); try {
|
||||
TL.setFile(conf);
|
||||
try {
|
||||
conf.save(lang);
|
||||
} catch (IOException e) {
|
||||
getLogger().log(Level.WARNING, "Factions: Failed to save lang.yml.");
|
||||
getLogger().log(Level.WARNING, "Factions: Report this stack trace to drtshock."); e.printStackTrace();
|
||||
getLogger().log(Level.WARNING, "Factions: Report this stack trace to drtshock.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
if (saveTask != null) {
|
||||
this.getServer().getScheduler().cancelTask(saveTask); saveTask = null;
|
||||
this.getServer().getScheduler().cancelTask(saveTask);
|
||||
saveTask = null;
|
||||
}
|
||||
// only save data if plugin actually loaded successfully
|
||||
if (loadSuccessful) { EM.saveAllToDisc(); } log("Disabled");
|
||||
if (loadSuccessful) {
|
||||
EM.saveAllToDisc();
|
||||
}
|
||||
log("Disabled");
|
||||
}
|
||||
|
||||
public void suicide() {
|
||||
log("Now I suicide!"); this.getServer().getPluginManager().disablePlugin(this);
|
||||
log("Now I suicide!");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -207,10 +231,14 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
public void initTXT() {
|
||||
this.addRawTags();
|
||||
|
||||
Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Type type = new TypeToken<Map<String, String>>() {
|
||||
}.getType();
|
||||
|
||||
Map<String, String> tagsFromFile = this.persist.load(type, "tags");
|
||||
if (tagsFromFile != null) { this.rawTags.putAll(tagsFromFile); } this.persist.save(this.rawTags, "tags");
|
||||
if (tagsFromFile != null) {
|
||||
this.rawTags.putAll(tagsFromFile);
|
||||
}
|
||||
this.persist.save(this.rawTags, "tags");
|
||||
|
||||
for (Entry<String, String> rawTag : this.rawTags.entrySet()) {
|
||||
this.txt.tags.put(rawTag.getKey(), TextUtil.parseColor(rawTag.getValue()));
|
||||
@ -231,22 +259,30 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
public boolean handleCommand(final CommandSender sender, String commandString, boolean testOnly, boolean async) {
|
||||
boolean noSlash = true; if (commandString.startsWith("/")) {
|
||||
noSlash = false; commandString = commandString.substring(1);
|
||||
boolean noSlash = true;
|
||||
if (commandString.startsWith("/")) {
|
||||
noSlash = false;
|
||||
commandString = commandString.substring(1);
|
||||
}
|
||||
|
||||
for (final MCommand<?> command : this.getBaseCommands()) {
|
||||
if (noSlash && !command.allowNoSlashAccess) { continue; }
|
||||
if (noSlash && !command.allowNoSlashAccess) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String alias : command.aliases) {
|
||||
// disallow double-space after alias, so specific commands can be prevented (preventing "f home" won't prevent "f home")
|
||||
if (commandString.startsWith(alias + " ")) { return false; }
|
||||
if (commandString.startsWith(alias + " ")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (commandString.startsWith(alias + " ") || commandString.equals(alias)) {
|
||||
final List<String> args = new ArrayList<String>(Arrays.asList(commandString.split("\\s+")));
|
||||
args.remove(0);
|
||||
|
||||
if (testOnly) { return true; }
|
||||
if (testOnly) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (async) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
@ -255,12 +291,15 @@ public abstract class MPlugin extends JavaPlugin {
|
||||
command.execute(sender, args);
|
||||
}
|
||||
});
|
||||
} else { command.execute(sender, args); }
|
||||
} else {
|
||||
command.execute(sender, args);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleCommand(CommandSender sender, String commandString) {
|
||||
|
@ -28,7 +28,8 @@ public class MPluginSecretPlayerListener implements Listener {
|
||||
if (p.handleCommand(event.getPlayer(), event.getMessage())) {
|
||||
if (p.logPlayerCommands()) {
|
||||
Bukkit.getLogger().info("[PLAYER_COMMAND] " + event.getPlayer().getName() + ": " + event.getMessage());
|
||||
} event.setCancelled(true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,10 +38,12 @@ public class MPluginSecretPlayerListener implements Listener {
|
||||
if (p.handleCommand(event.getPlayer(), event.getMessage(), false, true)) {
|
||||
if (p.logPlayerCommands()) {
|
||||
Bukkit.getLogger().info("[PLAYER_COMMAND] " + event.getPlayer().getName() + ": " + event.getMessage());
|
||||
} event.setCancelled(true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
Player speaker = event.getPlayer(); String format = event.getFormat();
|
||||
Player speaker = event.getPlayer();
|
||||
String format = event.getFormat();
|
||||
format = format.replace(Conf.chatTagReplaceString, P.p.getPlayerFactionTag(speaker)).replace("[FACTION_TITLE]", P.p.getPlayerTitle(speaker));
|
||||
event.setFormat(format);
|
||||
}
|
||||
|
@ -14,7 +14,9 @@ public class MPluginSecretServerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onServerCommand(ServerCommandEvent event) {
|
||||
if (event.getCommand().length() == 0) { return; }
|
||||
if (event.getCommand().length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p.handleCommand(event.getSender(), event.getCommand())) {
|
||||
event.setCommand(p.refCommand);
|
||||
|
@ -71,8 +71,13 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
// -------------------------------------------- //
|
||||
|
||||
public EntityCollection(Class<E> entityClass, Collection<E> entities, Map<String, E> id2entity, File file, Gson gson, boolean creative) {
|
||||
this.entityClass = entityClass; this.entities = entities; this.id2entity = id2entity; this.file = file;
|
||||
this.gson = gson; this.creative = creative; this.nextId = 1;
|
||||
this.entityClass = entityClass;
|
||||
this.entities = entities;
|
||||
this.id2entity = id2entity;
|
||||
this.file = file;
|
||||
this.gson = gson;
|
||||
this.creative = creative;
|
||||
this.nextId = 1;
|
||||
|
||||
EM.setEntitiesCollectionForEntityClass(this.entityClass, this);
|
||||
}
|
||||
@ -94,19 +99,32 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
}
|
||||
|
||||
public E get(String id) {
|
||||
if (this.creative) { return this.getCreative(id); } return id2entity.get(id);
|
||||
if (this.creative) {
|
||||
return this.getCreative(id);
|
||||
}
|
||||
return id2entity.get(id);
|
||||
}
|
||||
|
||||
public E getCreative(String id) {
|
||||
E e = id2entity.get(id); if (e != null) { return e; } return this.create(id);
|
||||
E e = id2entity.get(id);
|
||||
if (e != null) {
|
||||
return e;
|
||||
}
|
||||
return this.create(id);
|
||||
}
|
||||
|
||||
public boolean exists(String id) {
|
||||
if (id == null) { return false; } return id2entity.get(id) != null;
|
||||
if (id == null) {
|
||||
return false;
|
||||
}
|
||||
return id2entity.get(id) != null;
|
||||
}
|
||||
|
||||
public E getBestIdMatch(String pattern) {
|
||||
String id = TextUtil.getBestStartWithCI(this.id2entity.keySet(), pattern); if (id == null) { return null; }
|
||||
String id = TextUtil.getBestStartWithCI(this.id2entity.keySet(), pattern);
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
return this.id2entity.get(id);
|
||||
}
|
||||
|
||||
@ -119,15 +137,22 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
}
|
||||
|
||||
public synchronized E create(String id) {
|
||||
if (!this.isIdFree(id)) { return null; }
|
||||
if (!this.isIdFree(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
E e = null; try {
|
||||
E e = null;
|
||||
try {
|
||||
e = this.entityClass.newInstance();
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
|
||||
e.setId(id); this.entities.add(e); this.id2entity.put(e.getId(), e); this.updateNextIdForId(id); return e;
|
||||
e.setId(id);
|
||||
this.entities.add(e);
|
||||
this.id2entity.put(e.getId(), e);
|
||||
this.updateNextIdForId(id);
|
||||
return e;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -135,16 +160,27 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void attach(E entity) {
|
||||
if (entity.getId() != null) { return; } entity.setId(this.getNextId()); this.entities.add(entity);
|
||||
if (entity.getId() != null) {
|
||||
return;
|
||||
}
|
||||
entity.setId(this.getNextId());
|
||||
this.entities.add(entity);
|
||||
this.id2entity.put(entity.getId(), entity);
|
||||
}
|
||||
|
||||
public void detach(E entity) {
|
||||
entity.preDetach(); this.entities.remove(entity); this.id2entity.remove(entity.getId()); entity.postDetach();
|
||||
entity.preDetach();
|
||||
this.entities.remove(entity);
|
||||
this.id2entity.remove(entity.getId());
|
||||
entity.postDetach();
|
||||
}
|
||||
|
||||
public void detach(String id) {
|
||||
E entity = this.id2entity.get(id); if (entity == null) { return; } this.detach(entity);
|
||||
E entity = this.id2entity.get(id);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
this.detach(entity);
|
||||
}
|
||||
|
||||
public boolean attached(E entity) {
|
||||
@ -163,15 +199,20 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
private boolean saveIsRunning = false;
|
||||
|
||||
public boolean saveToDisc() {
|
||||
if (saveIsRunning) { return true; } saveIsRunning = true;
|
||||
if (saveIsRunning) {
|
||||
return true;
|
||||
}
|
||||
saveIsRunning = true;
|
||||
|
||||
Map<String, E> entitiesThatShouldBeSaved = new HashMap<String, E>(); for (E entity : this.entities) {
|
||||
Map<String, E> entitiesThatShouldBeSaved = new HashMap<String, E>();
|
||||
for (E entity : this.entities) {
|
||||
if (entity.shouldBeSaved()) {
|
||||
entitiesThatShouldBeSaved.put(entity.getId(), entity);
|
||||
}
|
||||
}
|
||||
|
||||
saveIsRunning = false; return this.saveCore(this.file, entitiesThatShouldBeSaved);
|
||||
saveIsRunning = false;
|
||||
return this.saveCore(this.file, entitiesThatShouldBeSaved);
|
||||
}
|
||||
|
||||
private boolean saveCore(File target, Map<String, E> entities) {
|
||||
@ -179,9 +220,16 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
}
|
||||
|
||||
public boolean loadFromDisc() {
|
||||
Map<String, E> id2entity = this.loadCore(); if (id2entity == null) { return false; } this.entities.clear();
|
||||
this.entities.addAll(id2entity.values()); this.id2entity.clear(); this.id2entity.putAll(id2entity);
|
||||
this.fillIds(); return true;
|
||||
Map<String, E> id2entity = this.loadCore();
|
||||
if (id2entity == null) {
|
||||
return false;
|
||||
}
|
||||
this.entities.clear();
|
||||
this.entities.addAll(id2entity.values());
|
||||
this.id2entity.clear();
|
||||
this.id2entity.putAll(id2entity);
|
||||
this.fillIds();
|
||||
return true;
|
||||
}
|
||||
|
||||
private Map<String, E> loadCore() {
|
||||
@ -189,37 +237,45 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
return new HashMap<String, E>();
|
||||
}
|
||||
|
||||
String content = DiscUtil.readCatch(this.file); if (content == null) {
|
||||
String content = DiscUtil.readCatch(this.file);
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Type type = this.getMapType(); if (type.toString().contains("FPlayer")) {
|
||||
Type type = this.getMapType();
|
||||
if (type.toString().contains("FPlayer")) {
|
||||
Map<String, FPlayer> data = this.gson.fromJson(content, type);
|
||||
Set<String> list = whichKeysNeedMigration(data.keySet());
|
||||
Set<String> invalidList = whichKeysAreInvalid(list); list.removeAll(invalidList);
|
||||
Set<String> invalidList = whichKeysAreInvalid(list);
|
||||
list.removeAll(invalidList);
|
||||
|
||||
if (list.size() > 0) {
|
||||
// We've got some converting to do!
|
||||
Bukkit.getLogger().log(Level.INFO, "Factions is now updating players.json");
|
||||
|
||||
// First we'll make a backup, because god forbid anybody heed a warning
|
||||
File file = new File(this.file.getParentFile(), "players.json.old"); try {
|
||||
File file = new File(this.file.getParentFile(), "players.json.old");
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} saveCore(file, (Map<String, E>) data);
|
||||
}
|
||||
saveCore(file, (Map<String, E>) data);
|
||||
Bukkit.getLogger().log(Level.INFO, "Backed up your old data at " + file.getAbsolutePath());
|
||||
|
||||
// Start fetching those UUIDs
|
||||
Bukkit.getLogger().log(Level.INFO, "Please wait while Factions converts " + list.size() + " old player names to UUID. This may take a while.");
|
||||
UUIDFetcher fetcher = new UUIDFetcher(new ArrayList(list)); try {
|
||||
Map<String, UUID> response = fetcher.call(); for (String s : list) {
|
||||
UUIDFetcher fetcher = new UUIDFetcher(new ArrayList(list));
|
||||
try {
|
||||
Map<String, UUID> response = fetcher.call();
|
||||
for (String s : list) {
|
||||
// Are we missing any responses?
|
||||
if (!response.containsKey(s)) {
|
||||
// They don't have a UUID so they should just be removed
|
||||
invalidList.add(s);
|
||||
}
|
||||
} for (String value : response.keySet()) {
|
||||
}
|
||||
for (String value : response.keySet()) {
|
||||
// For all the valid responses, let's replace their old named entry with a UUID key
|
||||
String id = response.get(value).toString();
|
||||
|
||||
@ -227,7 +283,8 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
|
||||
if (player == null) {
|
||||
// The player never existed here, and shouldn't persist
|
||||
invalidList.add(value); continue;
|
||||
invalidList.add(value);
|
||||
continue;
|
||||
}
|
||||
|
||||
player.setId(id); // Update the object so it knows
|
||||
@ -237,23 +294,28 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} if (invalidList.size() > 0) {
|
||||
}
|
||||
if (invalidList.size() > 0) {
|
||||
for (String name : invalidList) {
|
||||
// Remove all the invalid names we collected
|
||||
data.remove(name);
|
||||
}
|
||||
Bukkit.getLogger().log(Level.INFO, "While converting we found names that either don't have a UUID or aren't players and removed them from storage.");
|
||||
Bukkit.getLogger().log(Level.INFO, "The following names were detected as being invalid: " + StringUtils.join(invalidList, ", "));
|
||||
} saveCore(this.file, (Map<String, E>) data); // Update the flatfile
|
||||
}
|
||||
saveCore(this.file, (Map<String, E>) data); // Update the flatfile
|
||||
Bukkit.getLogger().log(Level.INFO, "Done converting players.json to UUID.");
|
||||
} return (Map<String, E>) data;
|
||||
}
|
||||
return (Map<String, E>) data;
|
||||
} else {
|
||||
Map<String, Faction> data = this.gson.fromJson(content, type);
|
||||
|
||||
// Do we have any names that need updating in claims or invites?
|
||||
|
||||
int needsUpdate = 0; for (String string : data.keySet()) {
|
||||
Faction f = data.get(string); needsUpdate += whichKeysNeedMigration(f.getInvites()).size();
|
||||
int needsUpdate = 0;
|
||||
for (String string : data.keySet()) {
|
||||
Faction f = data.get(string);
|
||||
needsUpdate += whichKeysNeedMigration(f.getInvites()).size();
|
||||
Map<FLocation, Set<String>> claims = f.getClaimOwnership();
|
||||
for (FLocation key : f.getClaimOwnership().keySet()) {
|
||||
needsUpdate += whichKeysNeedMigration(claims.get(key)).size();
|
||||
@ -265,11 +327,13 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
Bukkit.getLogger().log(Level.INFO, "Factions is now updating factions.json");
|
||||
|
||||
// First we'll make a backup, because god forbid anybody heed a warning
|
||||
File file = new File(this.file.getParentFile(), "factions.json.old"); try {
|
||||
File file = new File(this.file.getParentFile(), "factions.json.old");
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} saveCore(file, (Map<String, E>) data);
|
||||
}
|
||||
saveCore(file, (Map<String, E>) data);
|
||||
Bukkit.getLogger().log(Level.INFO, "Backed up your old data at " + file.getAbsolutePath());
|
||||
|
||||
Bukkit.getLogger().log(Level.INFO, "Please wait while Factions converts " + needsUpdate + " old player names to UUID. This may take a while.");
|
||||
@ -277,15 +341,18 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
// Update claim ownership
|
||||
|
||||
for (String string : data.keySet()) {
|
||||
Faction f = data.get(string); Map<FLocation, Set<String>> claims = f.getClaimOwnership();
|
||||
Faction f = data.get(string);
|
||||
Map<FLocation, Set<String>> claims = f.getClaimOwnership();
|
||||
for (FLocation key : claims.keySet()) {
|
||||
Set<String> set = claims.get(key);
|
||||
|
||||
Set<String> list = whichKeysNeedMigration(set);
|
||||
|
||||
if (list.size() > 0) {
|
||||
UUIDFetcher fetcher = new UUIDFetcher(new ArrayList(list)); try {
|
||||
Map<String, UUID> response = fetcher.call(); for (String value : response.keySet()) {
|
||||
UUIDFetcher fetcher = new UUIDFetcher(new ArrayList(list));
|
||||
try {
|
||||
Map<String, UUID> response = fetcher.call();
|
||||
for (String value : response.keySet()) {
|
||||
// Let's replace their old named entry with a UUID key
|
||||
String id = response.get(value).toString();
|
||||
set.remove(value.toLowerCase()); // Out with the old...
|
||||
@ -293,7 +360,8 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} claims.put(key, set); // Update
|
||||
}
|
||||
claims.put(key, set); // Update
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -301,12 +369,15 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
// Update invites
|
||||
|
||||
for (String string : data.keySet()) {
|
||||
Faction f = data.get(string); Set<String> invites = f.getInvites();
|
||||
Faction f = data.get(string);
|
||||
Set<String> invites = f.getInvites();
|
||||
Set<String> list = whichKeysNeedMigration(invites);
|
||||
|
||||
if (list.size() > 0) {
|
||||
UUIDFetcher fetcher = new UUIDFetcher(new ArrayList(list)); try {
|
||||
Map<String, UUID> response = fetcher.call(); for (String value : response.keySet()) {
|
||||
UUIDFetcher fetcher = new UUIDFetcher(new ArrayList(list));
|
||||
try {
|
||||
Map<String, UUID> response = fetcher.call();
|
||||
for (String value : response.keySet()) {
|
||||
// Let's replace their old named entry with a UUID key
|
||||
String id = response.get(value).toString();
|
||||
invites.remove(value.toLowerCase()); // Out with the old...
|
||||
@ -320,12 +391,14 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
|
||||
saveCore(this.file, (Map<String, E>) data); // Update the flatfile
|
||||
Bukkit.getLogger().log(Level.INFO, "Done converting factions.json to UUID.");
|
||||
} return (Map<String, E>) data;
|
||||
}
|
||||
return (Map<String, E>) data;
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> whichKeysNeedMigration(Set<String> keys) {
|
||||
HashSet<String> list = new HashSet<String>(); for (String value : keys) {
|
||||
HashSet<String> list = new HashSet<String>();
|
||||
for (String value : keys) {
|
||||
if (!value.matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")) {
|
||||
// Not a valid UUID..
|
||||
if (value.matches("[a-zA-Z0-9_]{2,16}")) {
|
||||
@ -333,16 +406,19 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
} return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Set<String> whichKeysAreInvalid(Set<String> keys) {
|
||||
Set<String> list = new HashSet<String>(); for (String value : keys) {
|
||||
Set<String> list = new HashSet<String>();
|
||||
for (String value : keys) {
|
||||
if (!value.matches("[a-zA-Z0-9_]{2,16}")) {
|
||||
// Not a valid player name.. go ahead and mark it for removal
|
||||
list.add(value);
|
||||
}
|
||||
} return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -352,7 +428,8 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
public String getNextId() {
|
||||
while (!isIdFree(this.nextId)) {
|
||||
this.nextId += 1;
|
||||
} return Integer.toString(this.nextId);
|
||||
}
|
||||
return Integer.toString(this.nextId);
|
||||
}
|
||||
|
||||
public boolean isIdFree(String id) {
|
||||
@ -364,8 +441,12 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
}
|
||||
|
||||
protected synchronized void fillIds() {
|
||||
this.nextId = 1; for (Entry<String, E> entry : this.id2entity.entrySet()) {
|
||||
String id = entry.getKey(); E entity = entry.getValue(); entity.id = id; this.updateNextIdForId(id);
|
||||
this.nextId = 1;
|
||||
for (Entry<String, E> entry : this.id2entity.entrySet()) {
|
||||
String id = entry.getKey();
|
||||
E entity = entry.getValue();
|
||||
entity.id = id;
|
||||
this.updateNextIdForId(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,7 +458,8 @@ public abstract class EntityCollection<E extends Entity> {
|
||||
|
||||
protected void updateNextIdForId(String id) {
|
||||
try {
|
||||
int idAsInt = Integer.parseInt(id); this.updateNextIdForId(idAsInt);
|
||||
int idAsInt = Integer.parseInt(id);
|
||||
this.updateNextIdForId(idAsInt);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user