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