Decided to remove alot of open and closing brackets for no reason lol
This commit is contained in:
parent
ae17f3d788
commit
8f2e58733d
2
pom.xml
2
pom.xml
@ -104,7 +104,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.15.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
|
@ -14,7 +14,6 @@ import java.util.Set;
|
||||
public class FLocation implements Serializable {
|
||||
private static final long serialVersionUID = -8292915234027387983L;
|
||||
private static final boolean worldBorderSupport;
|
||||
|
||||
static {
|
||||
boolean worldBorderClassPresent = false;
|
||||
try {
|
||||
@ -22,7 +21,6 @@ public class FLocation implements Serializable {
|
||||
worldBorderClassPresent = true;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
|
||||
worldBorderSupport = worldBorderClassPresent;
|
||||
}
|
||||
|
||||
@ -45,7 +43,7 @@ public class FLocation implements Serializable {
|
||||
}
|
||||
|
||||
public FLocation(Location location) {
|
||||
this(location.getWorld().getName(), blockToChunk(location.getBlockX()), blockToChunk(location.getBlockZ()));
|
||||
this(Objects.requireNonNull(location.getWorld()).getName(), blockToChunk(location.getBlockX()), blockToChunk(location.getBlockZ()));
|
||||
}
|
||||
|
||||
public FLocation(Player player) {
|
||||
@ -180,9 +178,9 @@ public class FLocation implements Serializable {
|
||||
}
|
||||
|
||||
public boolean isInChunk(Location loc) {
|
||||
if (loc == null) {
|
||||
return false;
|
||||
}
|
||||
if(loc == null) return false;
|
||||
if(loc.getWorld() == null) return false;
|
||||
|
||||
Chunk chunk = loc.getChunk();
|
||||
return loc.getWorld().getName().equalsIgnoreCase(getWorldName()) && chunk.getX() == x && chunk.getZ() == z;
|
||||
}
|
||||
@ -194,18 +192,23 @@ public class FLocation implements Serializable {
|
||||
* @return whether this location is outside of the border
|
||||
*/
|
||||
public boolean isOutsideWorldBorder(int buffer) {
|
||||
if (!worldBorderSupport) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!worldBorderSupport) return false;
|
||||
WorldBorder border = getWorld().getWorldBorder();
|
||||
Chunk chunk = border.getCenter().getChunk();
|
||||
Location center = border.getCenter();
|
||||
double size = border.getSize();
|
||||
|
||||
int lim = FLocation.chunkToRegion((int) border.getSize()) - buffer;
|
||||
int diffX = chunk.getX() - x;
|
||||
int diffZ = chunk.getZ() - z;
|
||||
int bufferBlocks = buffer << 4;
|
||||
|
||||
return (diffX > lim || diffZ > lim) || (-diffX >= lim || -diffZ >= lim);
|
||||
double borderMinX = (center.getX() - size / 2.0D) + bufferBlocks;
|
||||
double borderMinZ = (center.getZ() - size / 2.0D) + bufferBlocks;
|
||||
double borderMaxX = (center.getX() + size / 2.0D) - bufferBlocks;
|
||||
double borderMaxZ = (center.getZ() + size / 2.0D) - bufferBlocks;
|
||||
|
||||
int chunkMinX = this.x << 4;
|
||||
int chunkMaxX = chunkMinX | 15;
|
||||
int chunkMinZ = this.z << 4;
|
||||
int chunkMaxZ = chunkMinZ | 15;
|
||||
return (chunkMinX >= borderMaxX) || (chunkMinZ >= borderMaxZ) || (chunkMaxX <= borderMinX) || (chunkMaxZ <= borderMinZ);
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
@ -215,10 +218,7 @@ public class FLocation implements Serializable {
|
||||
double radiusSquared = radius * radius;
|
||||
|
||||
Set<FLocation> ret = new LinkedHashSet<>();
|
||||
if (radius <= 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
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);
|
||||
@ -232,7 +232,6 @@ public class FLocation implements Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -248,13 +247,8 @@ public class FLocation implements Serializable {
|
||||
|
||||
@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 && (Objects.equals(this.worldName, that.worldName));
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ import com.massivecraft.factions.zcore.MPlugin;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.fupgrades.*;
|
||||
import com.massivecraft.factions.zcore.fupgrades.FUpgradesGUI;
|
||||
import com.massivecraft.factions.zcore.fupgrades.UpgradesListener;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
import me.lucko.commodore.CommodoreProvider;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
@ -39,8 +40,6 @@ import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@ -54,7 +53,6 @@ import java.io.*;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@ -144,7 +142,7 @@ public class FactionsPlugin extends MPlugin {
|
||||
}
|
||||
|
||||
public void playSound(Player p, String sound) {
|
||||
float pitch = Float.valueOf(sound.split(":")[1]);
|
||||
float pitch = Float.parseFloat(sound.split(":")[1]);
|
||||
sound = sound.split(":")[0];
|
||||
p.playSound(p.getLocation(), Sound.valueOf(sound), pitch, 5.0F);
|
||||
}
|
||||
|
@ -77,6 +77,10 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
|
||||
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
||||
Faction faction = fPlayer.getFaction();
|
||||
if (placeholder.contains("faction_territory")) {
|
||||
faction = Board.getInstance().getFactionAt(fPlayer.getLastStoodAt());
|
||||
placeholder = placeholder.replace("_territory", "");
|
||||
}
|
||||
switch (placeholder) {
|
||||
// First list player stuff
|
||||
case "player_name":
|
||||
|
@ -338,7 +338,7 @@ public abstract class MemoryBoard extends Board {
|
||||
|
||||
public abstract void convertFrom(MemoryBoard old);
|
||||
|
||||
public class MemoryBoardMap extends HashMap<FLocation, String> {
|
||||
public static class MemoryBoardMap extends HashMap<FLocation, String> {
|
||||
private static final long serialVersionUID = -6689617828610585368L;
|
||||
|
||||
Multimap<String, FLocation> factionToLandMap = HashMultimap.create();
|
||||
|
@ -203,17 +203,11 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
public void setFaction(Faction faction, boolean alt) {
|
||||
Faction oldFaction = this.getFaction();
|
||||
if (oldFaction != null) {
|
||||
if (this.isAlt()) {
|
||||
oldFaction.removeAltPlayer(this);
|
||||
}
|
||||
|
||||
if (this.isAlt()) oldFaction.removeAltPlayer(this);
|
||||
oldFaction.removeFPlayer(this);
|
||||
}
|
||||
if (alt) {
|
||||
faction.addAltPlayer(this);
|
||||
} else {
|
||||
faction.addFPlayer(this);
|
||||
}
|
||||
if (alt) faction.addAltPlayer(this);
|
||||
else faction.addFPlayer(this);
|
||||
this.factionId = faction.getId();
|
||||
}
|
||||
|
||||
@ -263,18 +257,12 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public Role getRole() {
|
||||
// Hack to fix null roles..
|
||||
if (role == null) {
|
||||
this.role = Role.NORMAL;
|
||||
}
|
||||
|
||||
if (role == null) this.role = Role.NORMAL;
|
||||
return this.role;
|
||||
}
|
||||
|
||||
public void setRole(Role role) {
|
||||
if (this.role == role) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.role == role) return;
|
||||
FPlayerRoleChangeEvent event = new FPlayerRoleChangeEvent(getFaction(), this, role);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
@ -343,10 +331,8 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public void setIsAutoSafeClaimEnabled(boolean enabled) {
|
||||
this.autoSafeZoneEnabled = enabled;
|
||||
if (enabled) {
|
||||
this.autoClaimFor = null;
|
||||
if (enabled) this.autoClaimFor = null;
|
||||
this.autoWarZoneEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAutoWarClaimEnabled() {
|
||||
@ -355,10 +341,8 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public void setIsAutoWarClaimEnabled(boolean enabled) {
|
||||
this.autoWarZoneEnabled = enabled;
|
||||
if (enabled) {
|
||||
this.autoClaimFor = null;
|
||||
if (enabled) this.autoClaimFor = null;
|
||||
this.autoSafeZoneEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAdminBypassing() {
|
||||
@ -374,9 +358,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
}
|
||||
|
||||
public ChatMode getChatMode() {
|
||||
if (this.factionId.equals("0") || !Conf.factionOnlyChat) {
|
||||
this.chatMode = ChatMode.PUBLIC;
|
||||
}
|
||||
if (this.factionId.equals("0") || !Conf.factionOnlyChat) this.chatMode = ChatMode.PUBLIC;
|
||||
return chatMode;
|
||||
}
|
||||
|
||||
@ -417,22 +399,14 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
try {
|
||||
if (Discord.useDiscord && this.discordSetup() && Discord.isInMainGuild(this.discordUser()) && Discord.mainGuild != null) {
|
||||
Member m = Discord.mainGuild.getMember(this.discordUser());
|
||||
if (Conf.leaderRoles && this.role == Role.LEADER && Discord.leader != null) {
|
||||
Discord.mainGuild.getController().removeSingleRoleFromMember(m, Discord.leader).queue();
|
||||
}
|
||||
if (Conf.factionRoles) {
|
||||
Discord.mainGuild.getController().removeSingleRoleFromMember(m, Objects.requireNonNull(Discord.createFactionRole(this.getFaction().getTag()))).queue();
|
||||
}
|
||||
if (Conf.factionDiscordTags) {
|
||||
Discord.resetNick(this);
|
||||
}
|
||||
if (Conf.leaderRoles && this.role == Role.LEADER && Discord.leader != null) Discord.mainGuild.getController().removeSingleRoleFromMember(m, Discord.leader).queue();
|
||||
if (Conf.factionRoles) Discord.mainGuild.getController().removeSingleRoleFromMember(m, Objects.requireNonNull(Discord.createFactionRole(this.getFaction().getTag()))).queue();
|
||||
if (Conf.factionDiscordTags) Discord.resetNick(this);
|
||||
}
|
||||
} catch (HierarchyException e) {System.out.print(e.getMessage());}
|
||||
//End Discord
|
||||
currentFaction.removeFPlayer(this);
|
||||
if (currentFaction.isNormal()) {
|
||||
currentFaction.clearClaimOwnership(this);
|
||||
}
|
||||
if (currentFaction.isNormal()) currentFaction.clearClaimOwnership(this);
|
||||
}
|
||||
|
||||
this.factionId = "0"; // The default neutral faction
|
||||
@ -455,9 +429,8 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
losePowerFromBeingOffline();
|
||||
this.lastLoginTime = lastLoginTime;
|
||||
this.lastPowerUpdateTime = lastLoginTime;
|
||||
if (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) {
|
||||
this.loginPvpDisabled = true;
|
||||
}
|
||||
if (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) this.loginPvpDisabled = true;
|
||||
|
||||
}
|
||||
|
||||
public boolean isMapAutoUpdating() {
|
||||
@ -475,9 +448,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
// Base:
|
||||
|
||||
public boolean hasLoginPvpDisabled() {
|
||||
if (!loginPvpDisabled) {
|
||||
return false;
|
||||
}
|
||||
if (!loginPvpDisabled) return false;
|
||||
if (this.lastLoginTime + (Conf.noPVPDamageToOthersForXSecondsAfterLogin * 1000) < System.currentTimeMillis()) {
|
||||
this.loginPvpDisabled = false;
|
||||
return false;
|
||||
@ -499,10 +470,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public void setTitle(CommandSender sender, String title) {
|
||||
// Check if the setter has it.
|
||||
if (sender.hasPermission(Permission.TITLE_COLOR.node)) {
|
||||
title = ChatColor.translateAlternateColorCodes('&', title);
|
||||
}
|
||||
|
||||
if (sender.hasPermission(Permission.TITLE_COLOR.node)) title = ChatColor.translateAlternateColorCodes('&', title);
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@ -532,9 +500,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public String getNameAndSomething(String something) {
|
||||
String ret = this.role.getPrefix();
|
||||
if (something.length() > 0) {
|
||||
ret += something + " ";
|
||||
}
|
||||
if (something.length() > 0) ret += something + " ";
|
||||
ret += this.getName();
|
||||
return ret;
|
||||
}
|
||||
@ -581,7 +547,6 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public int getDeaths() {
|
||||
return isOnline() ? getPlayer().getStatistic(Statistic.DEATHS) : this.deaths;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -618,9 +583,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
//----------------------------------------------//
|
||||
public void heal(int amnt) {
|
||||
Player player = this.getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
player.setHealth(player.getHealth() + amnt);
|
||||
}
|
||||
|
||||
@ -634,11 +597,10 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public void alterPower(double delta) {
|
||||
this.power += delta;
|
||||
if (this.power > this.getPowerMax()) {
|
||||
if (this.power > this.getPowerMax())
|
||||
this.power = this.getPowerMax();
|
||||
} else if (this.power < this.getPowerMin()) {
|
||||
else if (this.power < this.getPowerMin())
|
||||
this.power = this.getPowerMin();
|
||||
}
|
||||
}
|
||||
|
||||
public double getPowerMax() {
|
||||
@ -670,9 +632,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
public void updatePower() {
|
||||
if (this.isOffline()) {
|
||||
losePowerFromBeingOffline();
|
||||
if (!Conf.powerRegenOffline) {
|
||||
return;
|
||||
}
|
||||
if (!Conf.powerRegenOffline) return;
|
||||
} else if (hasFaction() && getFaction().isPowerFrozen()) {
|
||||
return; // Don't let power regen if faction power is frozen.
|
||||
}
|
||||
@ -682,19 +642,13 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
this.lastPowerUpdateTime = now;
|
||||
|
||||
Player thisPlayer = this.getPlayer();
|
||||
if (thisPlayer != null && thisPlayer.isDead()) {
|
||||
return; // don't let dead players regain power until they respawn
|
||||
}
|
||||
|
||||
if (thisPlayer != null && thisPlayer.isDead()) return; // don't let dead players regain power until they respawn
|
||||
PowerRegenEvent powerRegenEvent = new PowerRegenEvent(getFaction(), this);
|
||||
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent));
|
||||
|
||||
if (!powerRegenEvent.isCancelled())
|
||||
if (!powerRegenEvent.usingCustomPower()) {
|
||||
this.alterPower(millisPassed * Conf.powerPerMinute / 60000); // millisPerMinute : 60 * 1000
|
||||
} else {
|
||||
this.alterPower(+powerRegenEvent.getCustomPower());
|
||||
}
|
||||
if (!powerRegenEvent.usingCustomPower()) this.alterPower(millisPassed * Conf.powerPerMinute / 60000); // millisPerMinute : 60 * 1000
|
||||
else this.alterPower(+powerRegenEvent.getCustomPower());
|
||||
}
|
||||
|
||||
public void losePowerFromBeingOffline() {
|
||||
@ -704,9 +658,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
this.lastPowerUpdateTime = now;
|
||||
|
||||
double loss = millisPassed * Conf.powerOfflineLossPerDay / (24 * 60 * 60 * 1000);
|
||||
if (this.power - loss < Conf.powerOfflineLossLimit) {
|
||||
loss = this.power;
|
||||
}
|
||||
if (this.power - loss < Conf.powerOfflineLossLimit) loss = this.power;
|
||||
this.alterPower(-loss);
|
||||
}
|
||||
}
|
||||
@ -714,9 +666,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
public void onDeath() {
|
||||
this.updatePower();
|
||||
this.alterPower(-Conf.powerPerDeath);
|
||||
if (hasFaction()) {
|
||||
getFaction().setLastDeath(System.currentTimeMillis());
|
||||
}
|
||||
if (hasFaction()) getFaction().setLastDeath(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
@ -750,9 +700,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
FScoreboard.get(this).setTemporarySidebar(new FInfoSidebar(toShow));
|
||||
showChat = FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.also-send-chat", true);
|
||||
}
|
||||
if (showChat) {
|
||||
this.sendMessage(FactionsPlugin.getInstance().txt.parse(TL.FACTION_LEAVE.format(from.getTag(this), toShow.getTag(this))));
|
||||
}
|
||||
if (showChat) this.sendMessage(FactionsPlugin.getInstance().txt.parse(TL.FACTION_LEAVE.format(from.getTag(this), toShow.getTag(this))));
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
@ -801,64 +749,48 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
}
|
||||
|
||||
// if economy is enabled and they're not on the bypass list, make sure they can pay
|
||||
if (makePay && !Econ.hasAtLeast(this, Conf.econCostLeave, TL.LEAVE_TOLEAVE.toString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (makePay && !Econ.hasAtLeast(this, Conf.econCostLeave, TL.LEAVE_TOLEAVE.toString())) return;
|
||||
FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this, myFaction, FPlayerLeaveEvent.PlayerLeaveReason.LEAVE);
|
||||
Bukkit.getServer().getPluginManager().callEvent(leaveEvent);
|
||||
if (leaveEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (leaveEvent.isCancelled()) return;
|
||||
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
if (makePay && !Econ.modifyMoney(this, -Conf.econCostLeave, TL.LEAVE_TOLEAVE.toString(), TL.LEAVE_FORLEAVE.toString())) {
|
||||
if (makePay && !Econ.modifyMoney(this, -Conf.econCostLeave, TL.LEAVE_TOLEAVE.toString(), TL.LEAVE_FORLEAVE.toString()))
|
||||
return;
|
||||
}
|
||||
|
||||
// Am I the last one in the faction?
|
||||
if (myFaction.getFPlayers().size() == 1) {
|
||||
// Transfer all money
|
||||
if (Econ.shouldBeUsed()) {
|
||||
Econ.transferMoney(this, myFaction, this, Econ.getBalance(myFaction.getAccountId()));
|
||||
}
|
||||
if (Econ.shouldBeUsed()) Econ.transferMoney(this, myFaction, this, Econ.getBalance(myFaction.getAccountId()));
|
||||
|
||||
}
|
||||
|
||||
if (myFaction.isNormal()) {
|
||||
for (FPlayer fplayer : myFaction.getFPlayersWhereOnline(true)) {
|
||||
for (FPlayer fplayer : myFaction.getFPlayersWhereOnline(true))
|
||||
fplayer.msg(TL.LEAVE_LEFT, this.describeTo(fplayer, true), myFaction.describeTo(fplayer));
|
||||
}
|
||||
|
||||
if (Conf.logFactionLeave) {
|
||||
if (Conf.logFactionLeave)
|
||||
FactionsPlugin.getInstance().log(TL.LEAVE_LEFT.format(this.getName(), myFaction.getTag()));
|
||||
}
|
||||
}
|
||||
|
||||
myFaction.removeAnnouncements(this);
|
||||
|
||||
if (this.isAlt()) {
|
||||
myFaction.removeAltPlayer(this);
|
||||
this.msg(TL.LEAVE_LEFT, this.describeTo(this, true), myFaction.describeTo(this));
|
||||
}
|
||||
|
||||
this.resetFactionData();
|
||||
FactionsPlugin.instance.logFactionEvent(myFaction, FLogType.INVITES, this.getName(), CC.Red + "left", "the faction");
|
||||
|
||||
setFlying(false);
|
||||
|
||||
if (myFaction.isNormal() && !perm && myFaction.getFPlayers().isEmpty()) {
|
||||
// Remove this faction
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers())
|
||||
fplayer.msg(TL.LEAVE_DISBANDED, myFaction.describeTo(fplayer, true));
|
||||
}
|
||||
|
||||
|
||||
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(getPlayer(), myFaction.getId(), PlayerDisbandReason.LEAVE);
|
||||
Bukkit.getPluginManager().callEvent(disbandEvent);
|
||||
|
||||
Factions.getInstance().removeFaction(myFaction.getId());
|
||||
if (Conf.logFactionDisband) {
|
||||
FactionsPlugin.getInstance().log(TL.LEAVE_DISBANDEDLOG.format(myFaction.getTag(), myFaction.getId(), this.getName()));
|
||||
}
|
||||
if (Conf.logFactionDisband) FactionsPlugin.getInstance().log(TL.LEAVE_DISBANDEDLOG.format(myFaction.getTag(), myFaction.getId(), this.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -942,9 +874,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
}
|
||||
// TODO: Add more else if statements.
|
||||
|
||||
if (notifyFailure && error != null) {
|
||||
msg(error);
|
||||
}
|
||||
if (notifyFailure && error != null) msg(error);
|
||||
return error == null;
|
||||
}
|
||||
|
||||
@ -1000,10 +930,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
if (!damage) {
|
||||
msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled");
|
||||
if (!fly) {
|
||||
sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + ""));
|
||||
}
|
||||
|
||||
if (!fly) sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + ""));
|
||||
} else {
|
||||
msg(TL.COMMAND_FLY_DAMAGE);
|
||||
}
|
||||
@ -1021,7 +948,6 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> setTakeFallDamage(true), 20L * cooldown);
|
||||
}
|
||||
}
|
||||
|
||||
isFlying = fly;
|
||||
}
|
||||
|
||||
@ -1045,14 +971,8 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public boolean canFlyAtLocation(FLocation location) {
|
||||
Faction faction = Board.getInstance().getFactionAt(location);
|
||||
if ((faction == getFaction() && getRole() == Role.LEADER) || isAdminBypassing) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (faction.isSystemFaction()) {
|
||||
return CmdFly.checkBypassPerms(this, getPlayer(), faction);
|
||||
}
|
||||
|
||||
if ((faction == getFaction() && getRole() == Role.LEADER) || isAdminBypassing) return true;
|
||||
if (faction.isSystemFaction()) return CmdFly.checkBypassPerms(this, getPlayer(), faction);
|
||||
Access access = faction.getAccess(this, PermissableAction.FLY);
|
||||
return access == null || access == Access.UNDEFINED || access == Access.ALLOW;
|
||||
}
|
||||
@ -1083,53 +1003,35 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
}
|
||||
|
||||
public void sendMessage(String msg) {
|
||||
if (msg.contains("{null}")) {
|
||||
return; // user wants this message to not send
|
||||
}
|
||||
if (msg.contains("{null}")) return; // user wants this message to not send
|
||||
|
||||
if (msg.contains("/n/")) {
|
||||
for (String s : msg.split("/n/")) {
|
||||
sendMessage(s);
|
||||
}
|
||||
for (String s : msg.split("/n/")) sendMessage(s);
|
||||
return;
|
||||
}
|
||||
Player player = this.getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
|
||||
public void sendMessage(List<String> msgs) {
|
||||
for (String msg : msgs) {
|
||||
this.sendMessage(msg);
|
||||
}
|
||||
for (String msg : msgs) this.sendMessage(msg);
|
||||
}
|
||||
|
||||
public void sendFancyMessage(FancyMessage message) {
|
||||
Player player = getPlayer();
|
||||
if (player == null || !player.isOnGround()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player == null || !player.isOnGround()) return;
|
||||
message.send(player);
|
||||
}
|
||||
|
||||
public void sendFancyMessage(List<FancyMessage> messages) {
|
||||
Player player = getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (FancyMessage msg : messages) {
|
||||
msg.send(player);
|
||||
}
|
||||
if (player == null) return;
|
||||
for (FancyMessage msg : messages) msg.send(player);
|
||||
}
|
||||
|
||||
public int getMapHeight() {
|
||||
if (this.mapHeight < 1) {
|
||||
this.mapHeight = Conf.mapHeight;
|
||||
}
|
||||
|
||||
if (this.mapHeight < 1) this.mapHeight = Conf.mapHeight;
|
||||
return this.mapHeight;
|
||||
}
|
||||
|
||||
@ -1183,9 +1085,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
@Override
|
||||
public void addWarmup(WarmUpUtil.Warmup warmup, int taskId) {
|
||||
if (this.warmup != null) {
|
||||
this.clearWarmup();
|
||||
}
|
||||
if (this.warmup != null) this.clearWarmup();
|
||||
this.warmup = warmup;
|
||||
this.warmupTask = taskId;
|
||||
}
|
||||
@ -1194,24 +1094,15 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
public boolean checkIfNearbyEnemies() {
|
||||
Player me = this.getPlayer();
|
||||
|
||||
if (me == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (me == null) return false;
|
||||
int radius = Conf.stealthFlyCheckRadius;
|
||||
for (Entity e : me.getNearbyEntities(radius, 255, radius)) {
|
||||
if (e == null) {
|
||||
continue;
|
||||
}
|
||||
if (e == null) continue;
|
||||
if (e instanceof Player) {
|
||||
Player eplayer = (((Player) e).getPlayer());
|
||||
if (eplayer == null) {
|
||||
continue;
|
||||
}
|
||||
if (eplayer == null) continue;
|
||||
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
|
||||
if (efplayer == null) {
|
||||
continue;
|
||||
}
|
||||
if (efplayer == null) continue;
|
||||
if (efplayer.isVanished()) continue;
|
||||
if (this.getRelationTo(efplayer).equals(Relation.ENEMY) && !efplayer.isStealthEnabled()) {
|
||||
setFlying(false);
|
||||
@ -1281,10 +1172,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
Faction currentFaction = Board.getInstance().getFactionAt(flocation);
|
||||
int ownedLand = forFaction.getLandRounded();
|
||||
|
||||
if (!this.canClaimForFactionAtLocation(forFaction, flocation, notifyFailure)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.canClaimForFactionAtLocation(forFaction, flocation, 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() && (Conf.econCostClaimWilderness != 0);
|
||||
double cost = 0.0;
|
||||
@ -1303,42 +1191,33 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
payee = this;
|
||||
}
|
||||
|
||||
if (!Econ.hasAtLeast(payee, cost, TL.CLAIM_TOCLAIM.toString())) {
|
||||
return false;
|
||||
}
|
||||
if (!Econ.hasAtLeast(payee, cost, TL.CLAIM_TOCLAIM.toString())) return false;
|
||||
}
|
||||
|
||||
LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this);
|
||||
Bukkit.getPluginManager().callEvent(claimEvent);
|
||||
if (claimEvent.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
if (claimEvent.isCancelled()) return false;
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
if (mustPay && !Econ.modifyMoney(payee, -cost, TL.CLAIM_TOCLAIM.toString(), TL.CLAIM_FORCLAIM.toString())) {
|
||||
if (mustPay && !Econ.modifyMoney(payee, -cost, TL.CLAIM_TOCLAIM.toString(), TL.CLAIM_FORCLAIM.toString()))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Was an over claim
|
||||
if (mustPay && currentFaction.isNormal() && currentFaction.hasLandInflation()) {
|
||||
if (mustPay && currentFaction.isNormal() && currentFaction.hasLandInflation())
|
||||
// Give them money for over claiming.
|
||||
Econ.modifyMoney(payee, Conf.econOverclaimRewardMultiplier, TL.CLAIM_TOOVERCLAIM.toString(), TL.CLAIM_FOROVERCLAIM.toString());
|
||||
}
|
||||
|
||||
|
||||
// announce success
|
||||
Set<FPlayer> informTheseFPlayers = new HashSet<>();
|
||||
informTheseFPlayers.add(this);
|
||||
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true));
|
||||
for (FPlayer fp : informTheseFPlayers) {
|
||||
for (FPlayer fp : informTheseFPlayers)
|
||||
fp.msg(TL.CLAIM_CLAIMED, this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
|
||||
}
|
||||
|
||||
|
||||
Board.getInstance().setFactionAt(forFaction, flocation);
|
||||
|
||||
if (Conf.logLandClaims) {
|
||||
FactionsPlugin.getInstance().log(TL.CLAIM_CLAIMEDLOG.toString(), this.getName(), flocation.getCoordString(), forFaction.getTag());
|
||||
}
|
||||
|
||||
if (Conf.logLandClaims) FactionsPlugin.getInstance().log(TL.CLAIM_CLAIMEDLOG.toString(), this.getName(), flocation.getCoordString(), forFaction.getTag());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1358,7 +1237,6 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
case LEADER:
|
||||
return Conf.prefixLeader;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1061,8 +1061,6 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
// ----------------------------------------------//
|
||||
public double getPower() {
|
||||
if (this.hasPermanentPower()) return this.getPermanentPower();
|
||||
|
||||
|
||||
double ret = 0;
|
||||
for (FPlayer fplayer : fplayers) ret += fplayer.getPower();
|
||||
for (FPlayer fplayer : alts) ret += fplayer.getPower();
|
||||
@ -1074,16 +1072,10 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
|
||||
public double getPowerMax() {
|
||||
if (this.hasPermanentPower()) return this.getPermanentPower();
|
||||
|
||||
|
||||
double ret = 0;
|
||||
for (FPlayer fplayer : fplayers) ret += fplayer.getPowerMax();
|
||||
|
||||
for (FPlayer fplayer : alts) ret += fplayer.getPowerMax();
|
||||
|
||||
if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
|
||||
ret = Conf.powerFactionMax;
|
||||
}
|
||||
if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) ret = Conf.powerFactionMax;
|
||||
return ret + this.powerBoost;
|
||||
}
|
||||
|
||||
@ -1115,10 +1107,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
public void refreshFPlayers() {
|
||||
fplayers.clear();
|
||||
alts.clear();
|
||||
if (this.isPlayerFreeType()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPlayerFreeType()) return;
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getAllFPlayers()) {
|
||||
if (fplayer.getFactionId().equalsIgnoreCase(id)) {
|
||||
if (fplayer.isAlt()) {
|
||||
@ -1166,21 +1155,15 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
public Set<FPlayer> getFPlayersWhereOnline(boolean online) {
|
||||
Set<FPlayer> ret = new HashSet<>();
|
||||
|
||||
for (FPlayer fplayer : fplayers) {
|
||||
if (fplayer.isOnline() == online) {
|
||||
ret.add(fplayer);
|
||||
}
|
||||
}
|
||||
for (FPlayer fplayer : fplayers)
|
||||
if (fplayer.isOnline() == online) ret.add(fplayer);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Set<FPlayer> getFPlayersWhereOnline(boolean online, FPlayer viewer) {
|
||||
Set<FPlayer> ret = new HashSet<>();
|
||||
if (!this.isNormal()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!this.isNormal()) return ret;
|
||||
for (FPlayer viewed : fplayers) {
|
||||
// Add if their online status is what we want
|
||||
if (viewed.isOnline() == online) {
|
||||
@ -1198,20 +1181,14 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public FPlayer getFPlayerAdmin() {
|
||||
if (!this.isNormal()) return null;
|
||||
|
||||
|
||||
for (FPlayer fplayer : fplayers) {
|
||||
if (fplayer.getRole() == Role.LEADER) {
|
||||
return fplayer;
|
||||
}
|
||||
}
|
||||
for (FPlayer fplayer : fplayers)
|
||||
if (fplayer.getRole() == Role.LEADER) return fplayer;
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1221,33 +1198,23 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
|
||||
public ArrayList<FPlayer> getFPlayersWhereRole(Role role) {
|
||||
ArrayList<FPlayer> ret = new ArrayList<>();
|
||||
if (!this.isNormal()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (FPlayer fplayer : fplayers) {
|
||||
if (fplayer.getRole() == role) {
|
||||
ret.add(fplayer);
|
||||
}
|
||||
}
|
||||
if (!this.isNormal()) return ret;
|
||||
|
||||
for (FPlayer fplayer : fplayers)
|
||||
if (fplayer.getRole() == role) ret.add(fplayer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Player> getOnlinePlayers() {
|
||||
ArrayList<Player> ret = new ArrayList<>();
|
||||
if (this.isPlayerFreeType()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (this.isPlayerFreeType()) return ret;
|
||||
for (Player player : FactionsPlugin.getInstance().getServer().getOnlinePlayers()) {
|
||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
||||
if (fplayer.getFaction() == this && !fplayer.isAlt()) {
|
||||
ret.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1255,9 +1222,8 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
// 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 : FactionsPlugin.getInstance().getServer().getOnlinePlayers()) {
|
||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
||||
@ -1265,16 +1231,13 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// even if all players are technically logged off, maybe someone was on
|
||||
// recently enough to not consider them officially offline yet
|
||||
return Conf.considerFactionsReallyOfflineAfterXMinutes > 0 && System.currentTimeMillis() < lastPlayerLoggedOffTime + (Conf.considerFactionsReallyOfflineAfterXMinutes * 60000);
|
||||
}
|
||||
|
||||
public void memberLoggedOff() {
|
||||
if (this.isNormal()) {
|
||||
lastPlayerLoggedOffTime = System.currentTimeMillis();
|
||||
}
|
||||
if (this.isNormal()) lastPlayerLoggedOffTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// used when current leader is about to be removed from the faction;
|
||||
@ -1286,58 +1249,45 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
|
||||
@Override
|
||||
public void promoteNewLeader(boolean autoLeave) {
|
||||
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);
|
||||
}
|
||||
if (oldLeader != null) oldLeader.setRole(Role.NORMAL);
|
||||
return;
|
||||
}
|
||||
|
||||
// no members left and faction isn't permanent, so disband it
|
||||
if (Conf.logFactionDisband) {
|
||||
if (Conf.logFactionDisband)
|
||||
FactionsPlugin.getInstance().log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left" + (autoLeave ? " and by inactivity" : "") + ".");
|
||||
}
|
||||
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers())
|
||||
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_GENERIC, this.getTag(fplayer));
|
||||
}
|
||||
|
||||
|
||||
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(null, getId(), autoLeave ? PlayerDisbandReason.INACTIVITY : PlayerDisbandReason.LEAVE);
|
||||
Bukkit.getPluginManager().callEvent(disbandEvent);
|
||||
|
||||
Factions.getInstance().removeFaction(getId());
|
||||
} else { // promote new faction admin
|
||||
if (oldLeader != null) {
|
||||
oldLeader.setRole(Role.NORMAL);
|
||||
}
|
||||
if (oldLeader != null) oldLeader.setRole(Role.NORMAL);
|
||||
replacements.get(0).setRole(Role.LEADER);
|
||||
if (Discord.useDiscord && replacements.get(0).discordSetup() && Discord.isInMainGuild(replacements.get(0).discordUser()) && Discord.mainGuild != null) {
|
||||
Member m = Discord.mainGuild.getMember(replacements.get(0).discordUser());
|
||||
if (Conf.factionRoles) {
|
||||
if (Conf.factionRoles)
|
||||
Discord.mainGuild.getController().addSingleRoleToMember(m, Objects.requireNonNull(Discord.createFactionRole(this.getTag()))).queue();
|
||||
}
|
||||
if (Conf.leaderRoles) {
|
||||
if (Conf.leaderRoles)
|
||||
Discord.mainGuild.getController().addSingleRoleToMember(m, Discord.mainGuild.getRoleById(Conf.leaderRole)).queue();
|
||||
}
|
||||
if (Conf.factionDiscordTags) {
|
||||
if (Conf.factionDiscordTags)
|
||||
Discord.mainGuild.getController().setNickname(m, Discord.getNicknameString(replacements.get(0)));
|
||||
}
|
||||
}
|
||||
this.msg(TL.AUTOLEAVE_ADMIN_PROMOTED, oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName());
|
||||
FactionsPlugin.getInstance().log("Faction " + this.getTag() + " (" + this.getId() + ") admin was removed. Replacement admin: " + replacements.get(0).getName());
|
||||
@ -1349,10 +1299,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
// ----------------------------------------------//
|
||||
public void msg(String message, Object... args) {
|
||||
message = FactionsPlugin.getInstance().txt.parse(message, args);
|
||||
|
||||
for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) {
|
||||
fplayer.sendMessage(message);
|
||||
}
|
||||
for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) fplayer.sendMessage(message);
|
||||
}
|
||||
|
||||
public void msg(TL translation, Object... args) {
|
||||
@ -1360,15 +1307,11 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) {
|
||||
fplayer.sendMessage(message);
|
||||
}
|
||||
for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) fplayer.sendMessage(message);
|
||||
}
|
||||
|
||||
public void sendMessage(List<String> messages) {
|
||||
for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) {
|
||||
fplayer.sendMessage(messages);
|
||||
}
|
||||
for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) fplayer.sendMessage(messages);
|
||||
}
|
||||
|
||||
// ----------------------------------------------//
|
||||
@ -1397,24 +1340,14 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
}
|
||||
|
||||
public void clearClaimOwnership(FPlayer player) {
|
||||
if (id == null || id.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == null || id.isEmpty()) return;
|
||||
Set<String> ownerData;
|
||||
|
||||
for (Entry<FLocation, Set<String>> entry : claimOwnership.entrySet()) {
|
||||
ownerData = entry.getValue();
|
||||
|
||||
if (ownerData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ownerData == null) continue;
|
||||
ownerData.removeIf(s -> s.equals(player.getId()));
|
||||
|
||||
if (ownerData.isEmpty()) {
|
||||
claimOwnership.remove(entry.getKey());
|
||||
}
|
||||
if (ownerData.isEmpty()) claimOwnership.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1423,27 +1356,20 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
}
|
||||
|
||||
public boolean doesLocationHaveOwnersSet(FLocation loc) {
|
||||
if (claimOwnership.isEmpty() || !claimOwnership.containsKey(loc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (claimOwnership.isEmpty() || !claimOwnership.containsKey(loc)) return false;
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
return ownerData != null && !ownerData.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isPlayerInOwnerList(FPlayer player, FLocation loc) {
|
||||
if (claimOwnership.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (claimOwnership.isEmpty()) return false;
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
return ownerData != null && ownerData.contains(player.getId());
|
||||
}
|
||||
|
||||
public void setPlayerAsOwner(FPlayer player, FLocation loc) {
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
if (ownerData == null) {
|
||||
ownerData = new HashSet<>();
|
||||
}
|
||||
if (ownerData == null) ownerData = new HashSet<>();
|
||||
ownerData.add(player.getId());
|
||||
claimOwnership.put(loc, ownerData);
|
||||
}
|
||||
@ -1451,7 +1377,6 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
public void removePlayerAsOwner(FPlayer player, FLocation loc) {
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
if (ownerData == null) return;
|
||||
|
||||
ownerData.remove(player.getId());
|
||||
claimOwnership.put(loc, ownerData);
|
||||
}
|
||||
@ -1462,16 +1387,11 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
|
||||
public String getOwnerListString(FLocation loc) {
|
||||
Set<String> ownerData = claimOwnership.get(loc);
|
||||
if (ownerData == null || ownerData.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (ownerData == null || ownerData.isEmpty()) return "";
|
||||
StringBuilder ownerList = new StringBuilder();
|
||||
|
||||
for (String anOwnerData : ownerData) {
|
||||
if (ownerList.length() > 0) {
|
||||
ownerList.append(", ");
|
||||
}
|
||||
if (ownerList.length() > 0) ownerList.append(", ");
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(anOwnerData));
|
||||
ownerList.append(offlinePlayer != null ? offlinePlayer.getName() : TL.GENERIC_NULLPLAYER.toString());
|
||||
}
|
||||
@ -1499,20 +1419,11 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
// Persistance and entity management
|
||||
// ----------------------------------------------//
|
||||
public void remove() {
|
||||
if (Econ.shouldBeUsed()) {
|
||||
Econ.setBalance(getAccountId(), 0);
|
||||
}
|
||||
|
||||
if (Econ.shouldBeUsed()) Econ.setBalance(getAccountId(), 0);
|
||||
// Clean the board
|
||||
((MemoryBoard) Board.getInstance()).clean(id);
|
||||
|
||||
for (FPlayer fPlayer : fplayers) {
|
||||
fPlayer.resetFactionData(false);
|
||||
}
|
||||
|
||||
for (FPlayer fPlayer : alts) {
|
||||
fPlayer.resetFactionData(false);
|
||||
}
|
||||
for (FPlayer fPlayer : fplayers) fPlayer.resetFactionData(false);
|
||||
for (FPlayer fPlayer : alts) fPlayer.resetFactionData(false);
|
||||
}
|
||||
|
||||
public Set<FLocation> getAllClaims() {
|
||||
|
@ -25,12 +25,8 @@ public abstract class MemoryFactions extends Factions {
|
||||
faction.setDescription(TL.WILDERNESS_DESCRIPTION.toString());
|
||||
} else {
|
||||
Faction faction = factions.get("0");
|
||||
if (!faction.getTag().equalsIgnoreCase(TL.WILDERNESS.toString())) {
|
||||
faction.setTag(TL.WILDERNESS.toString());
|
||||
}
|
||||
if (!faction.getDescription().equalsIgnoreCase(TL.WILDERNESS_DESCRIPTION.toString())) {
|
||||
faction.setDescription(TL.WILDERNESS_DESCRIPTION.toString());
|
||||
}
|
||||
if (!faction.getTag().equalsIgnoreCase(TL.WILDERNESS.toString())) faction.setTag(TL.WILDERNESS.toString());
|
||||
if (!faction.getDescription().equalsIgnoreCase(TL.WILDERNESS_DESCRIPTION.toString())) faction.setDescription(TL.WILDERNESS_DESCRIPTION.toString());
|
||||
}
|
||||
|
||||
// Make sure the safe zone faction exists
|
||||
@ -41,16 +37,10 @@ public abstract class MemoryFactions extends Factions {
|
||||
faction.setDescription(TL.SAFEZONE_DESCRIPTION.toString());
|
||||
} else {
|
||||
Faction faction = factions.get("-1");
|
||||
if (!faction.getTag().equalsIgnoreCase(TL.SAFEZONE.toString())) {
|
||||
faction.setTag(TL.SAFEZONE.toString());
|
||||
}
|
||||
if (!faction.getDescription().equalsIgnoreCase(TL.SAFEZONE_DESCRIPTION.toString())) {
|
||||
faction.setDescription(TL.SAFEZONE_DESCRIPTION.toString());
|
||||
}
|
||||
if (!faction.getTag().equalsIgnoreCase(TL.SAFEZONE.toString())) faction.setTag(TL.SAFEZONE.toString());
|
||||
if (!faction.getDescription().equalsIgnoreCase(TL.SAFEZONE_DESCRIPTION.toString())) faction.setDescription(TL.SAFEZONE_DESCRIPTION.toString());
|
||||
// if SafeZone has old pre-1.6.0 name, rename it to remove troublesome " "
|
||||
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
|
||||
@ -61,16 +51,10 @@ public abstract class MemoryFactions extends Factions {
|
||||
faction.setDescription(TL.WARZONE_DESCRIPTION.toString());
|
||||
} else {
|
||||
Faction faction = factions.get("-2");
|
||||
if (!faction.getTag().equalsIgnoreCase(TL.WARZONE.toString())) {
|
||||
faction.setTag(TL.WARZONE.toString());
|
||||
}
|
||||
if (!faction.getDescription().equalsIgnoreCase(TL.WARZONE_DESCRIPTION.toString())) {
|
||||
faction.setDescription(TL.WARZONE_DESCRIPTION.toString());
|
||||
}
|
||||
if (!faction.getTag().equalsIgnoreCase(TL.WARZONE.toString())) faction.setTag(TL.WARZONE.toString());
|
||||
if (!faction.getDescription().equalsIgnoreCase(TL.WARZONE_DESCRIPTION.toString())) faction.setDescription(TL.WARZONE_DESCRIPTION.toString());
|
||||
// if WarZone has old pre-1.6.0 name, rename it to remove troublesome " "
|
||||
if (faction.getTag().contains(" ")) {
|
||||
faction.setTag(TL.WARZONE.toString());
|
||||
}
|
||||
if (faction.getTag().contains(" ")) faction.setTag(TL.WARZONE.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,9 +67,7 @@ public abstract class MemoryFactions extends Factions {
|
||||
public Faction getByTag(String str) {
|
||||
String compStr = MiscUtil.getComparisonString(str);
|
||||
for (Faction faction : factions.values()) {
|
||||
if (faction.getComparisonTag().equals(compStr)) {
|
||||
return faction;
|
||||
}
|
||||
if (faction.getComparisonTag().equals(compStr)) return faction;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -98,24 +80,17 @@ public abstract class MemoryFactions extends Factions {
|
||||
for (Faction faction : factions.values()) {
|
||||
String candidate = faction.getTag();
|
||||
candidate = ChatColor.stripColor(candidate);
|
||||
if (candidate.length() < minlength) {
|
||||
continue;
|
||||
}
|
||||
if (!candidate.toLowerCase().startsWith(start)) {
|
||||
continue;
|
||||
}
|
||||
if (candidate.length() < minlength) continue;
|
||||
if (!candidate.toLowerCase().startsWith(start)) continue;
|
||||
|
||||
// The closer to zero the better
|
||||
int lendiff = candidate.length() - minlength;
|
||||
if (lendiff == 0) {
|
||||
return faction;
|
||||
}
|
||||
if (lendiff < best || best == 0) {
|
||||
if (lendiff == 0) return faction;
|
||||
|
||||
if (lendiff < best || best == 0)
|
||||
best = lendiff;
|
||||
bestMatch = faction;
|
||||
}
|
||||
}
|
||||
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
@ -135,9 +110,7 @@ public abstract class MemoryFactions extends Factions {
|
||||
|
||||
public Set<String> getFactionTags() {
|
||||
Set<String> tags = new HashSet<>();
|
||||
for (Faction faction : factions.values()) {
|
||||
tags.add(faction.getTag());
|
||||
}
|
||||
for (Faction faction : factions.values()) tags.add(faction.getTag());
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,7 @@ public class SaveTask implements Runnable {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (!p.getAutoSave() || running) {
|
||||
return;
|
||||
}
|
||||
if (!p.getAutoSave() || running) return;
|
||||
running = true;
|
||||
p.preAutoSave();
|
||||
Factions.getInstance().forceSave(false);
|
||||
|
@ -63,24 +63,16 @@ public class JSONFPlayers extends MemoryFPlayers {
|
||||
|
||||
public void load() {
|
||||
Map<String, JSONFPlayer> fplayers = this.loadCore();
|
||||
if (fplayers == null) {
|
||||
return;
|
||||
}
|
||||
if (fplayers == null) return;
|
||||
this.fPlayers.clear();
|
||||
this.fPlayers.putAll(fplayers);
|
||||
FactionsPlugin.getInstance().log("Loaded " + fPlayers.size() + " players");
|
||||
}
|
||||
|
||||
private Map<String, JSONFPlayer> loadCore() {
|
||||
if (!this.file.exists()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
if (!this.file.exists()) return new HashMap<>();
|
||||
String content = DiscUtil.readCatch(this.file);
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (content == null) return null;
|
||||
Map<String, JSONFPlayer> data = this.gson.fromJson(content, new TypeToken<Map<String, JSONFPlayer>>() {
|
||||
}.getType());
|
||||
Set<String> list = new HashSet<>();
|
||||
@ -161,12 +153,12 @@ public class JSONFPlayers extends MemoryFPlayers {
|
||||
}
|
||||
|
||||
private boolean doesKeyNeedMigration(String key) {
|
||||
if (!key.matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")) {
|
||||
if (!key.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..
|
||||
// Valid playername, we'll mark this as one for conversion
|
||||
// to UUID
|
||||
return key.matches("[a-zA-Z0-9_]{2,16}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -49,9 +49,8 @@ public class JSONFactions extends MemoryFactions {
|
||||
|
||||
public void forceSave(boolean sync) {
|
||||
final Map<String, JSONFaction> entitiesThatShouldBeSaved = new HashMap<>();
|
||||
for (Faction entity : this.factions.values()) {
|
||||
for (Faction entity : this.factions.values())
|
||||
entitiesThatShouldBeSaved.put(entity.getId(), (JSONFaction) entity);
|
||||
}
|
||||
|
||||
saveCore(file, entitiesThatShouldBeSaved, sync);
|
||||
}
|
||||
@ -62,24 +61,16 @@ public class JSONFactions extends MemoryFactions {
|
||||
|
||||
public void load() {
|
||||
Map<String, JSONFaction> factions = this.loadCore();
|
||||
if (factions == null) {
|
||||
return;
|
||||
}
|
||||
if (factions == null) return;
|
||||
this.factions.putAll(factions);
|
||||
|
||||
super.load();
|
||||
FactionsPlugin.getInstance().log("Loaded " + factions.size() + " Factions");
|
||||
}
|
||||
|
||||
private Map<String, JSONFaction> loadCore() {
|
||||
if (!this.file.exists()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
if (!this.file.exists()) return new HashMap<>();
|
||||
String content = DiscUtil.readCatch(this.file);
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
if (content == null) return null;
|
||||
|
||||
Map<String, JSONFaction> data = this.gson.fromJson(content, new TypeToken<Map<String, JSONFaction>>() {
|
||||
}.getType());
|
||||
@ -95,9 +86,7 @@ public class JSONFactions extends MemoryFactions {
|
||||
f.setId(id);
|
||||
this.updateNextIdForId(id);
|
||||
needsUpdate += whichKeysNeedMigration(f.getInvites()).size();
|
||||
for (Set<String> keys : f.getClaimOwnership().values()) {
|
||||
needsUpdate += whichKeysNeedMigration(keys).size();
|
||||
}
|
||||
for (Set<String> keys : f.getClaimOwnership().values()) needsUpdate += whichKeysNeedMigration(keys).size();
|
||||
}
|
||||
|
||||
if (needsUpdate > 0) {
|
||||
@ -198,9 +187,7 @@ public class JSONFactions extends MemoryFactions {
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getNextId() {
|
||||
while (!isIdFree(this.nextId)) {
|
||||
this.nextId += 1;
|
||||
}
|
||||
while (!isIdFree(this.nextId)) this.nextId += 1;
|
||||
return Integer.toString(this.nextId);
|
||||
}
|
||||
|
||||
@ -213,9 +200,7 @@ public class JSONFactions extends MemoryFactions {
|
||||
}
|
||||
|
||||
protected synchronized void updateNextIdForId(int id) {
|
||||
if (this.nextId < id) {
|
||||
this.nextId = id + 1;
|
||||
}
|
||||
if (this.nextId < id) this.nextId = id + 1;
|
||||
}
|
||||
|
||||
protected void updateNextIdForId(String id) {
|
||||
|
@ -28,14 +28,12 @@ public class PermUtil {
|
||||
*/
|
||||
public final void setup() {
|
||||
for (Permission permission : p.getDescription().getPermissions()) {
|
||||
//plugin.log("\""+permission.getName()+"\" = \""+permission.getDescription()+"\"");
|
||||
this.permissionDescriptions.put(permission.getName(), permission.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
public String getPermissionDescription(String perm) {
|
||||
String desc = permissionDescriptions.get(perm);
|
||||
|
||||
return desc != null ? desc : TL.GENERIC_DOTHAT.toString();
|
||||
}
|
||||
|
||||
@ -47,28 +45,22 @@ public class PermUtil {
|
||||
}
|
||||
|
||||
public boolean has(CommandSender me, String perm, boolean informSenderIfNot) {
|
||||
if (has(me, perm)) {
|
||||
if (has(me, perm))
|
||||
return true;
|
||||
} else if (informSenderIfNot && me != null) {
|
||||
else if (informSenderIfNot && me != null)
|
||||
me.sendMessage(this.getForbiddenMessage(perm));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T> T pickFirstVal(CommandSender me, Map<String, T> perm2val) {
|
||||
if (perm2val == null) {
|
||||
return null;
|
||||
}
|
||||
if (perm2val == null) return null;
|
||||
T ret = null;
|
||||
|
||||
for (Entry<String, T> entry : perm2val.entrySet()) {
|
||||
ret = entry.getValue();
|
||||
if (has(me, entry.getKey())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,9 +32,7 @@ public class SmokeUtil {
|
||||
|
||||
// Single ========
|
||||
public static void spawnSingle(Location location, int direction) {
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
if (location == null) return;
|
||||
location.getWorld().playEffect(location.clone(), Effect.SMOKE, direction);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user