Some light code cleanup for happiness

This commit is contained in:
CmdrKittens 2019-07-19 02:17:32 -04:00
parent 1274fce2e8
commit bccea383ad
37 changed files with 240 additions and 390 deletions

View File

@ -392,6 +392,18 @@ public class Conf {
public static transient char[] mapKeyChrs = "\\/#$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz?".toCharArray();
private static void protectMaterial(String material) {
Material mat = FactionMaterial.from(material).get();
territoryProtectedMaterials.add(mat);
territoryProtectedMaterialsWhenOffline.add(mat);
}
private static void protectUsage(String material) {
Material mat = FactionMaterial.from(material).get();
territoryDenyUseageMaterials.add(mat);
territoryDenyUseageMaterialsWhenOffline.add(mat);
}
public static void preLoad() {
baseCommandAliases.add("f");
@ -402,104 +414,56 @@ public class Conf {
territoryEnemyDenyCommands.add("tpaccept");
territoryEnemyDenyCommands.add("tpa");
territoryProtectedMaterials.add(FactionMaterial.from("BIRCH_DOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("ACACIA_DOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("IRON_DOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("JUNGLE_DOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("OAK_DOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("SPRUCE_DOOR").get());
protectMaterial("DARK_OAK_DOOR");
protectMaterial("BIRCH_DOOR");
protectMaterial("ACACIA_DOOR");
protectMaterial("IRON_DOOR");
protectMaterial("JUNGLE_DOOR");
protectMaterial("OAK_DOOR");
protectMaterial("SPRUCE_DOOR");
territoryProtectedMaterials.add(FactionMaterial.from("ACACIA_TRAPDOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("BIRCH_TRAPDOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("DARK_OAK_TRAPDOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("IRON_TRAPDOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("JUNGLE_TRAPDOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("OAK_TRAPDOOR").get());
territoryProtectedMaterials.add(FactionMaterial.from("SPRUCE_TRAPDOOR").get());
protectMaterial("ACACIA_TRAPDOOR");
protectMaterial("BIRCH_TRAPDOOR");
protectMaterial("DARK_OAK_TRAPDOOR");
protectMaterial("IRON_TRAPDOOR");
protectMaterial("JUNGLE_TRAPDOOR");
protectMaterial("OAK_TRAPDOOR");
protectMaterial("SPRUCE_TRAPDOOR");
territoryProtectedMaterials.add(FactionMaterial.from("ACACIA_FENCE").get());
territoryProtectedMaterials.add(FactionMaterial.from("BIRCH_FENCE").get());
territoryProtectedMaterials.add(FactionMaterial.from("DARK_OAK_FENCE").get());
territoryProtectedMaterials.add(FactionMaterial.from("OAK_FENCE").get());
territoryProtectedMaterials.add(FactionMaterial.from("NETHER_BRICK_FENCE").get());
territoryProtectedMaterials.add(FactionMaterial.from("SPRUCE_FENCE").get());
protectMaterial("ACACIA_FENCE");
protectMaterial("BIRCH_FENCE");
protectMaterial("DARK_OAK_FENCE");
protectMaterial("OAK_FENCE");
protectMaterial("NETHER_BRICK_FENCE");
protectMaterial("SPRUCE_FENCE");
territoryProtectedMaterials.add(FactionMaterial.from("OAK_FENCE_GATE").get());
territoryProtectedMaterials.add(FactionMaterial.from("SPRUCE_FENCE_GATE").get());
territoryProtectedMaterials.add(FactionMaterial.from("BIRCH_FENCE_GATE").get());
territoryProtectedMaterials.add(FactionMaterial.from("JUNGLE_FENCE_GATE").get());
territoryProtectedMaterials.add(FactionMaterial.from("ACACIA_FENCE_GATE").get());
territoryProtectedMaterials.add(FactionMaterial.from("DARK_OAK_FENCE_GATE").get());
protectMaterial("OAK_FENCE_GATE");
protectMaterial("SPRUCE_FENCE_GATE");
protectMaterial("BIRCH_FENCE_GATE");
protectMaterial("JUNGLE_FENCE_GATE");
protectMaterial("ACACIA_FENCE_GATE");
protectMaterial("DARK_OAK_FENCE_GATE");
territoryProtectedMaterials.add(FactionMaterial.from("DISPENSER").get());
territoryProtectedMaterials.add(FactionMaterial.from("CHEST").get());
territoryProtectedMaterials.add(FactionMaterial.from("FURNACE").get());
territoryProtectedMaterials.add(FactionMaterial.from("REPEATER").get());
territoryProtectedMaterials.add(FactionMaterial.from("JUKEBOX").get());
territoryProtectedMaterials.add(FactionMaterial.from("BREWING_STAND").get());
territoryProtectedMaterials.add(FactionMaterial.from("ENCHANTING_TABLE").get());
territoryProtectedMaterials.add(FactionMaterial.from("CAULDRON").get());
territoryProtectedMaterials.add(FactionMaterial.from("FARMLAND").get());
territoryProtectedMaterials.add(FactionMaterial.from("BEACON").get());
territoryProtectedMaterials.add(FactionMaterial.from("ANVIL").get());
territoryProtectedMaterials.add(FactionMaterial.from("TRAPPED_CHEST").get());
territoryProtectedMaterials.add(FactionMaterial.from("DROPPER").get());
territoryProtectedMaterials.add(FactionMaterial.from("HOPPER").get());
protectMaterial("DISPENSER");
protectMaterial("CHEST");
protectMaterial("FURNACE");
protectMaterial("REPEATER");
protectMaterial("JUKEBOX");
protectMaterial("BREWING_STAND");
protectMaterial("ENCHANTING_TABLE");
protectMaterial("CAULDRON");
protectMaterial("FARMLAND");
protectMaterial("BEACON");
protectMaterial("ANVIL");
protectMaterial("TRAPPED_CHEST");
protectMaterial("DROPPER");
protectMaterial("HOPPER");
territoryDenyUseageMaterials.add(FactionMaterial.from("FIRE_CHARGE").get());
territoryDenyUseageMaterials.add(FactionMaterial.from("FLINT_AND_STEEL").get());
territoryDenyUseageMaterials.add(FactionMaterial.from("BUCKET").get());
territoryDenyUseageMaterials.add(FactionMaterial.from("WATER_BUCKET").get());
territoryDenyUseageMaterials.add(FactionMaterial.from("LAVA_BUCKET").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("DARK_OAK_DOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("BIRCH_DOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("ACACIA_DOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("IRON_DOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("JUNGLE_DOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("OAK_DOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("SPRUCE_DOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("ACACIA_TRAPDOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("BIRCH_TRAPDOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("DARK_OAK_TRAPDOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("IRON_TRAPDOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("JUNGLE_TRAPDOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("OAK_TRAPDOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("SPRUCE_TRAPDOOR").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("ACACIA_FENCE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("BIRCH_FENCE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("DARK_OAK_FENCE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("OAK_FENCE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("NETHER_BRICK_FENCE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("SPRUCE_FENCE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("DISPENSER").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("CHEST").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("FURNACE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("REPEATER").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("JUKEBOX").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("BREWING_STAND").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("ENCHANTING_TABLE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("CAULDRON").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("FARMLAND").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("BEACON").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("ANVIL").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("TRAPPED_CHEST").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("DROPPER").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("HOPPER").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("OAK_FENCE_GATE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("SPRUCE_FENCE_GATE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("BIRCH_FENCE_GATE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("JUNGLE_FENCE_GATE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("ACACIA_FENCE_GATE").get());
territoryProtectedMaterialsWhenOffline.add(FactionMaterial.from("DARK_OAK_FENCE_GATE").get());
territoryDenyUseageMaterialsWhenOffline.add(FactionMaterial.from("FIRE_CHARGE").get());
territoryDenyUseageMaterialsWhenOffline.add(FactionMaterial.from("FLINT_AND_STEEL").get());
territoryDenyUseageMaterialsWhenOffline.add(FactionMaterial.from("BUCKET").get());
territoryDenyUseageMaterialsWhenOffline.add(FactionMaterial.from("WATER_BUCKET").get());
territoryDenyUseageMaterialsWhenOffline.add(FactionMaterial.from("LAVA_BUCKET").get());
protectUsage("FIRE_CHARGE");
protectUsage("FLINT_AND_STEEL");
protectUsage("BUCKET");
protectUsage("WATER_BUCKET");
protectUsage("LAVA_BUCKET");
safeZoneNerfedCreatureTypes.add(EntityType.BLAZE);
safeZoneNerfedCreatureTypes.add(EntityType.CAVE_SPIDER);

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import java.io.Serializable;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
public class FLocation implements Serializable {
@ -104,7 +105,7 @@ public class FLocation implements Serializable {
}
public static FLocation fromString(String string) {
int index = string.indexOf(",", 0);
int index = string.indexOf(",");
int start = 1;
String worldName = string.substring(start, index);
start = index + 1;
@ -251,6 +252,6 @@ public class FLocation implements Serializable {
}
FLocation that = (FLocation) obj;
return this.x == that.x && this.z == that.z && (this.worldName == null ? that.worldName == null : this.worldName.equals(that.worldName));
return this.x == that.x && this.z == that.z && (Objects.equals(this.worldName, that.worldName));
}
}

View File

@ -16,8 +16,6 @@ import com.massivecraft.factions.listeners.versionspecific.PortalHandler;
import com.massivecraft.factions.listeners.versionspecific.PortalListenerLegacy;
import com.massivecraft.factions.listeners.versionspecific.PortalListener_114;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.*;
import com.massivecraft.factions.util.material.FactionMaterial;
import com.massivecraft.factions.util.material.MaterialDb;

View File

@ -25,9 +25,7 @@ public class CmdAutoHelp extends FCommand {
}
FCommand pcmd = context.commandChain.get(context.commandChain.size() - 1);
ArrayList<String> lines = new ArrayList<>();
lines.addAll(pcmd.helpLong);
ArrayList<String> lines = new ArrayList<>(pcmd.helpLong);
for (FCommand scmd : pcmd.subCommands) {
if (scmd.visibility == CommandVisibility.VISIBLE) {

View File

@ -62,14 +62,11 @@ public class CmdFWarp extends FCommand {
}
final FPlayer fPlayer = context.fPlayer;
final UUID uuid = context.fPlayer.getPlayer().getUniqueId();
context.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation());
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
}
context.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation());
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
}
}, this.p.getConfig().getLong("warmups.f-warp", 0));
} else {

View File

@ -7,7 +7,6 @@ import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.FlightUtil;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.TL;
import org.slf4j.event.Level;
public class CmdFly extends FCommand {
@ -59,12 +58,8 @@ public class CmdFly extends FCommand {
return;
}
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", new Runnable() {
@Override
public void run() {
context.fPlayer.setFlying(true);
}
}, this.p.getConfig().getLong("warmups.f-fly", 0));
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () ->
context.fPlayer.setFlying(true), this.p.getConfig().getLong("warmups.f-fly", 0));
}
@Override

View File

@ -121,21 +121,18 @@ public class CmdHome extends FCommand {
return;
}
context.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", new Runnable() {
@Override
public void run() {
// Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled) {
List<Location> smokeLocations = new ArrayList<>();
smokeLocations.add(loc);
smokeLocations.add(loc.add(0, 1, 0));
smokeLocations.add(context.faction.getHome());
smokeLocations.add(context.faction.getHome().clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
}
context.player.teleport(context.faction.getHome());
context.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", () -> {
// Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled) {
List<Location> smokeLocations = new ArrayList<>();
smokeLocations.add(loc);
smokeLocations.add(loc.add(0, 1, 0));
smokeLocations.add(context.faction.getHome());
smokeLocations.add(context.faction.getHome().clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
}
context.player.teleport(context.faction.getHome());
}, this.p.getConfig().getLong("warmups.f-home", 0));
}

View File

@ -8,7 +8,11 @@ import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.tag.Tag;
import com.massivecraft.factions.zcore.util.TL;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
public class CmdList extends FCommand {
@ -45,44 +49,14 @@ public class CmdList extends FCommand {
// remove exempt factions
if (!context.sender.hasPermission("factions.show.bypassexempt")) {
List<String> exemptFactions = P.p.getConfig().getStringList("show-exempt");
Iterator<Faction> factionIterator = factionList.iterator();
while (factionIterator.hasNext()) {
Faction next = factionIterator.next();
if (exemptFactions.contains(next.getTag())) {
factionIterator.remove();
}
}
factionList.removeIf(next -> exemptFactions.contains(next.getTag()));
}
// Sort by total followers first
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
}
});
factionList.sort(this.compare(Faction::getFPlayers));
// Then sort by how many members are online now
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
int f1Size = f1.getFPlayersWhereOnline(true).size();
int f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
}
});
factionList.sort(this.compare(f -> f.getFPlayersWhereOnline(true)));
ArrayList<String> lines = new ArrayList<>();
@ -117,6 +91,19 @@ public class CmdList extends FCommand {
context.sendMessage(lines);
}
private Comparator<Faction> compare(Function<Faction, ? extends Collection<?>> func) {
return (f1, f2) -> {
int f1Size = func.apply(f1).size();
int f2Size = func.apply(f2).size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
};
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_LIST_DESCRIPTION;

View File

@ -26,7 +26,7 @@ public class CmdStatus extends FCommand {
for (FPlayer fp : context.faction.getFPlayers()) {
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
String last = fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
String power = ChatColor.YELLOW + String.valueOf(fp.getPowerRounded()) + " / " + String.valueOf(fp.getPowerMaxRounded()) + ChatColor.RESET;
String power = ChatColor.YELLOW + String.valueOf(fp.getPowerRounded()) + " / " + fp.getPowerMaxRounded() + ChatColor.RESET;
ret.add(String.format(TL.COMMAND_STATUS_FORMAT.toString(), ChatColor.GOLD + fp.getRole().getPrefix() + fp.getName() + ChatColor.RESET, power, last).trim());
}
context.fPlayer.sendMessage(ret);

View File

@ -9,8 +9,6 @@ import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class CmdTop extends FCommand {
@ -38,96 +36,78 @@ public class CmdTop extends FCommand {
// TODO: Better way to sort?
if (criteria.equalsIgnoreCase("members")) {
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
factionList.sort((f1, f2) -> {
int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("start")) {
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
long f1start = f1.getFoundedDate();
long f2start = f2.getFoundedDate();
// flip signs because a smaller date is farther in the past
if (f1start > f2start) {
return 1;
} else if (f1start < f2start) {
return -1;
}
return 0;
factionList.sort((f1, f2) -> {
long f1start = f1.getFoundedDate();
long f2start = f2.getFoundedDate();
// flip signs because a smaller date is farther in the past
if (f1start > f2start) {
return 1;
} else if (f1start < f2start) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("power")) {
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
int f1Size = f1.getPowerRounded();
int f2Size = f2.getPowerRounded();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
factionList.sort((f1, f2) -> {
int f1Size = f1.getPowerRounded();
int f2Size = f2.getPowerRounded();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("land")) {
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
int f1Size = f1.getLandRounded();
int f2Size = f2.getLandRounded();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
factionList.sort((f1, f2) -> {
int f1Size = f1.getLandRounded();
int f2Size = f2.getLandRounded();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("online")) {
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
int f1Size = f1.getFPlayersWhereOnline(true).size();
int f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
factionList.sort((f1, f2) -> {
int f1Size = f1.getFPlayersWhereOnline(true).size();
int f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("money") || criteria.equalsIgnoreCase("balance") || criteria.equalsIgnoreCase("bal")) {
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
double f1Size = Econ.getBalance(f1.getAccountId());
// Lets get the balance of /all/ the players in the Faction.
for (FPlayer fp : f1.getFPlayers()) {
f1Size = f1Size + Econ.getBalance(fp.getAccountId());
}
double f2Size = Econ.getBalance(f2.getAccountId());
for (FPlayer fp : f2.getFPlayers()) {
f2Size = f2Size + Econ.getBalance(fp.getAccountId());
}
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
factionList.sort((f1, f2) -> {
double f1Size = Econ.getBalance(f1.getAccountId());
// Lets get the balance of /all/ the players in the Faction.
for (FPlayer fp : f1.getFPlayers()) {
f1Size = f1Size + Econ.getBalance(fp.getAccountId());
}
double f2Size = Econ.getBalance(f2.getAccountId());
for (FPlayer fp : f2.getFPlayers()) {
f2Size = f2Size + Econ.getBalance(fp.getAccountId());
}
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else {
context.msg(TL.COMMAND_TOP_INVALID, criteria);
@ -171,8 +151,6 @@ public class CmdTop extends FCommand {
return String.valueOf(faction.getFPlayers().size());
} else if (criteria.equalsIgnoreCase("land")) {
return String.valueOf(faction.getLandRounded());
} else if (criteria.equalsIgnoreCase("start")) {
return sdf.format(faction.getFoundedDate());
} else if (criteria.equalsIgnoreCase("power")) {
return String.valueOf(faction.getPowerRounded());
} else { // Last one is balance, and it has 3 different things it could be.

View File

@ -62,7 +62,7 @@ public class PowerLossEvent extends FactionPlayerEvent implements Cancellable {
/**
* Set the power loss message.
*
* @param message
* @param message message
*/
public void setMessage(String message) {
this.message = message;

View File

@ -4,9 +4,9 @@ import com.massivecraft.factions.zcore.util.TL;
public interface EconomyParticipator extends RelationParticipator {
public String getAccountId();
String getAccountId();
public void msg(String str, Object... args);
void msg(String str, Object... args);
public void msg(TL translation, Object... args);
void msg(TL translation, Object... args);
}

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.integration;
import com.massivecraft.factions.FLocation;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;

View File

@ -81,27 +81,24 @@ public class EngineDynmap {
}
// Shedule non thread safe sync at the end!
Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
@Override
public void run() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> {
final Map<String, TempMarker> homes = createHomes();
final Map<String, TempAreaMarker> areas = createAreas();
final Map<String, Set<String>> playerSets = createPlayersets();
final Map<String, TempMarker> homes = createHomes();
final Map<String, TempAreaMarker> areas = createAreas();
final Map<String, Set<String>> playerSets = createPlayersets();
if (!updateCore()) {
return;
}
// createLayer() is thread safe but it makes use of fields set in updateCore() so we must have it after.
if (!updateLayer(createLayer())) {
return;
}
updateHomes(homes);
updateAreas(areas);
updatePlayersets(playerSets);
if (!updateCore()) {
return;
}
// createLayer() is thread safe but it makes use of fields set in updateCore() so we must have it after.
if (!updateLayer(createLayer())) {
return;
}
updateHomes(homes);
updateAreas(areas);
updatePlayersets(playerSets);
}, 100L, 100L);
this.enabled = true;
@ -242,17 +239,9 @@ public class EngineDynmap {
String world = entry.getKey().getWorldName();
Faction chunkOwner = Factions.getInstance().getFactionById(entry.getValue());
Map<Faction, Set<FLocation>> factionChunks = worldFactionChunks.get(world);
if (factionChunks == null) {
factionChunks = new HashMap<>();
worldFactionChunks.put(world, factionChunks);
}
Map<Faction, Set<FLocation>> factionChunks = worldFactionChunks.computeIfAbsent(world, k -> new HashMap<>());
Set<FLocation> factionTerritory = factionChunks.get(chunkOwner);
if (factionTerritory == null) {
factionTerritory = new HashSet<>();
factionChunks.put(chunkOwner, factionTerritory);
}
Set<FLocation> factionTerritory = factionChunks.computeIfAbsent(chunkOwner, k -> new HashSet<>());
factionTerritory.add(entry.getKey());
}

View File

@ -10,8 +10,8 @@ public class TempAreaMarker {
public String label;
public String world;
public double x[];
public double z[];
public double[] x;
public double[] z;
public String description;
public int lineColor;
@ -91,7 +91,7 @@ public class TempAreaMarker {
// UTIL
// -------------------------------------------- //
public static boolean equals(AreaMarker marker, double x[], double z[]) {
public static boolean equals(AreaMarker marker, double[] x, double[] z) {
int length = marker.getCornerCount();
if (x.length != length) {

View File

@ -21,9 +21,6 @@ public class PortalHandler implements PortalListenerBase {
FPlayer fp = FPlayers.getInstance().getByPlayer(player);
String mininumRelation = P.p.getConfig().getString("portals.minimum-relation", "MEMBER"); // Defaults to Neutral if typed wrong.
if (!fp.getFaction().getRelationTo(faction).isAtLeast(Relation.fromString(mininumRelation))) {
return true;
}
return false;
return !fp.getFaction().getRelationTo(faction).isAtLeast(Relation.fromString(mininumRelation));
}
}

View File

@ -1,11 +1,12 @@
package com.massivecraft.factions.tag;
import com.google.common.base.Supplier;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import java.util.function.Supplier;
public enum GeneralTag implements Tag {
MAX_WARPS("{max-warps}", () -> String.valueOf(P.p.getConfig().getInt("max-warps", 5))),
MAX_ALLIES("{max-allies}", () -> getRelation("ally")),

View File

@ -10,8 +10,8 @@ import java.util.logging.Level;
public class AutoLeaveProcessTask extends BukkitRunnable {
private transient boolean readyToGo = false;
private transient boolean finished = false;
private transient boolean readyToGo;
private transient boolean finished;
private transient ListIterator<FPlayer> iterator;
private transient double toleranceMillis;

View File

@ -111,7 +111,7 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
case "faction_claims":
return String.valueOf(faction.getAllClaims().size());
case "faction_founded":
return String.valueOf(TL.sdf.format(faction.getFoundedDate()));
return TL.sdf.format(faction.getFoundedDate());
case "faction_joining":
return (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString());
case "faction_peaceful":

View File

@ -50,7 +50,7 @@ public final class EnumTypeAdapter<T extends Enum<T>> extends TypeAdapter<T> {
public static <TT> TypeAdapterFactory newEnumTypeHierarchyFactory() {
return new TypeAdapterFactory() {
@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({"unchecked"})
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
Class<? super T> rawType = typeToken.getRawType();
if (!Enum.class.isAssignableFrom(rawType) || rawType == Enum.class) {

View File

@ -18,7 +18,6 @@ public class FlightUtil {
private static FlightUtil instance;
private EnemiesTask enemiesTask;
private ParticleTrailsTask trailsTask;
private FlightUtil() {
double enemyCheck = P.p.getConfig().getDouble("f-fly.radius-check", 1) * 20;
@ -29,8 +28,7 @@ public class FlightUtil {
double spawnRate = P.p.getConfig().getDouble("f-fly.trails.spawn-rate", 0) * 20;
if (spawnRate > 0) {
trailsTask = new ParticleTrailsTask();
trailsTask.runTaskTimer(P.p, 0, (long) spawnRate);
new ParticleTrailsTask().runTaskTimer(P.p, 0, (long) spawnRate);
}
}

View File

@ -305,17 +305,14 @@ public class Metrics {
data.add("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(new Runnable() {
@Override
public void run() {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
new Thread(() -> {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}).start();
@ -483,6 +480,7 @@ public class Metrics {
this.callable = callable;
}
@SuppressWarnings("Duplicates")
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
@ -608,6 +606,7 @@ public class Metrics {
this.callable = callable;
}
@SuppressWarnings("Duplicates")
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();

View File

@ -25,7 +25,7 @@ import java.util.logging.Level;
public abstract class SpiralTask implements Runnable {
// general task-related reference data
private transient World world = null;
private transient World world;
private transient boolean readyToGo = false;
private transient int taskID = -1;
private transient int limit = 0;

View File

@ -17,12 +17,7 @@ public class VisualizeUtil {
}
public static Set<Location> getPlayerLocations(UUID uuid) {
Set<Location> ret = playerLocations.get(uuid);
if (ret == null) {
ret = new HashSet<>();
playerLocations.put(uuid, ret);
}
return ret;
return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>());
}
@SuppressWarnings("deprecation")

View File

@ -37,7 +37,7 @@ public class WarmUpUtil {
}
public enum Warmup {
HOME, WARP, FLIGHT;
HOME, WARP, FLIGHT
}
}

View File

@ -41,33 +41,27 @@ public class ParticleColor {
case BLACK:
return new ParticleColor(Color.BLACK);
case BLUE:
return new ParticleColor(Color.BLUE);
case DARK_AQUA:
return new ParticleColor(Color.BLUE);
case DARK_BLUE:
return new ParticleColor(Color.BLUE);
case DARK_GRAY:
case GRAY:
return new ParticleColor(Color.GRAY);
case DARK_GREEN:
return new ParticleColor(Color.GREEN);
case DARK_PURPLE:
return new ParticleColor(Color.PURPLE);
case DARK_RED:
return new ParticleColor(Color.RED);
case GOLD:
return new ParticleColor(Color.YELLOW);
case GRAY:
return new ParticleColor(Color.GRAY);
case GREEN:
return new ParticleColor(Color.LIME);
case LIGHT_PURPLE:
return new ParticleColor(Color.PURPLE);
case DARK_RED:
case RED:
return new ParticleColor(Color.RED);
case WHITE:
return new ParticleColor(Color.WHITE);
case GOLD:
case YELLOW:
return new ParticleColor(Color.YELLOW);
case GREEN:
return new ParticleColor(Color.LIME);
case WHITE:
return new ParticleColor(Color.WHITE);
default:
break;
}

View File

@ -11,7 +11,7 @@ public interface ParticleProvider<Effect> {
void playerSpawn(Player player, Effect effect, Location location, int count);
public void spawn(Effect effect, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ);
void spawn(Effect effect, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ);
void playerSpawn(Player player, Effect effect, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ);

View File

@ -3,5 +3,5 @@ package com.massivecraft.factions.zcore;
public enum CommandVisibility {
VISIBLE, // Visible commands are visible to anyone. Even those who don't have permission to use it or is of invalid sender type.
SECRET, // Secret commands are visible only to those who can use the command. These commands are usually some kind of admin commands.
INVISIBLE; // Invisible commands are invisible to everyone, even those who can use the command.
INVISIBLE // Invisible commands are invisible to everyone, even those who can use the command.
}

View File

@ -18,8 +18,8 @@ public enum Access {
/**
* Case insensitive check for access.
*
* @param check
* @return
* @param check check
* @return access
*/
public static Access fromString(String check) {
for (Access access : values()) {

View File

@ -6,12 +6,12 @@ import org.bukkit.inventory.ItemStack;
public interface Permissable {
public ItemStack buildItem(FPlayer fme);
ItemStack buildItem(FPlayer fme);
public String replacePlaceholders(String string, FPlayer fme);
String replacePlaceholders(String string, FPlayer fme);
public String name();
String name();
public ChatColor getColor();
ChatColor getColor();
}

View File

@ -56,8 +56,8 @@ public enum PermissableAction {
/**
* Case insensitive check for action.
*
* @param check
* @return
* @param check check
* @return permissible
*/
public static PermissableAction fromString(String check) {
for (PermissableAction permissableAction : values()) {

View File

@ -130,14 +130,11 @@ public class WarpGUI extends FactionGUI<Integer> implements FactionGUI.Dynamic {
}
private void doWarmup(final String warp) {
WarmUpUtil.process(user, WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warp, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(user.getPlayer().getUniqueId());
if (player != null) {
player.teleport(user.getFaction().getWarp(warp).getLocation());
user.msg(TL.COMMAND_FWARP_WARPED, warp);
}
WarmUpUtil.process(user, WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warp, () -> {
Player player = Bukkit.getPlayer(user.getPlayer().getUniqueId());
if (player != null) {
player.teleport(user.getFaction().getWarp(warp).getLocation());
user.msg(TL.COMMAND_FWARP_WARPED, warp);
}
}, P.p.getConfig().getLong("warmups.f-warp", 0));
}

View File

@ -6,7 +6,6 @@ import com.massivecraft.factions.*;
import com.massivecraft.factions.integration.LWC;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.AsciiCompass;
import com.massivecraft.factions.util.LazyLocation;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
@ -98,12 +97,7 @@ public abstract class MemoryBoard extends Board {
public void removeAt(FLocation flocation) {
Faction faction = getFactionAt(flocation);
Iterator<LazyLocation> it = faction.getWarps().values().iterator();
while (it.hasNext()) {
if (flocation.isInChunk(it.next().getLocation())) {
it.remove();
}
}
faction.getWarps().values().removeIf(lazyLocation -> flocation.isInChunk(lazyLocation.getLocation()));
for (Entity entity : flocation.getChunk().getEntities()) {
if (entity instanceof Player) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer((Player) entity);
@ -157,9 +151,7 @@ public abstract class MemoryBoard extends Board {
public void clean(String factionId) {
if (LWC.getEnabled() && P.p.getConfig().getBoolean("lwc.reset-locks-unclaim", false)) {
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
while (iter.hasNext()) {
Entry<FLocation, String> entry = iter.next();
for (Entry<FLocation, String> entry : flocationIds.entrySet()) {
if (entry.getValue().equals(factionId)) {
LWC.clearAllLocks(entry.getKey());
}

View File

@ -59,7 +59,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
public void addAnnouncement(FPlayer fPlayer, String msg) {
List<String> list = announcements.containsKey(fPlayer.getId()) ? announcements.get(fPlayer.getId()) : new ArrayList<String>();
List<String> list = announcements.containsKey(fPlayer.getId()) ? announcements.get(fPlayer.getId()) : new ArrayList<>();
list.add(msg);
announcements.put(fPlayer.getId(), list);
}
@ -77,9 +77,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
public void removeAnnouncements(FPlayer fPlayer) {
if (announcements.containsKey(fPlayer.getId())) {
announcements.remove(fPlayer.getId());
}
announcements.remove(fPlayer.getId());
}
public ConcurrentHashMap<String, LazyLocation> getWarps() {
@ -157,12 +155,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
public void unban(FPlayer player) {
Iterator<BanInfo> iter = bans.iterator();
while (iter.hasNext()) {
if (iter.next().getBanned().equalsIgnoreCase(player.getId())) {
iter.remove();
}
}
bans.removeIf(banInfo -> banInfo.getBanned().equalsIgnoreCase(player.getId()));
}
public boolean isBanned(FPlayer player) {
@ -373,9 +366,9 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
/**
* Get the Access of a player. Will use player's Role if they are a faction member. Otherwise, uses their Relation.
*
* @param player
* @param permissableAction
* @return
* @param player player
* @param permissableAction permissible
* @return player's access
*/
public Access getAccess(FPlayer player, PermissableAction permissableAction) {
if (player == null || permissableAction == null) {
@ -434,7 +427,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
/**
* Read only map of Permissions.
*
* @return
* @return map of permissions
*/
public Map<Permissable, Map<PermissableAction, Access>> getPermissions() {
return Collections.unmodifiableMap(permissions);
@ -901,12 +894,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
continue;
}
Iterator<String> iter = ownerData.iterator();
while (iter.hasNext()) {
if (iter.next().equals(player.getId())) {
iter.remove();
}
}
ownerData.removeIf(s -> s.equals(player.getId()));
if (ownerData.isEmpty()) {
if (LWC.getEnabled() && P.p.getConfig().getBoolean("lwc.reset-locks-unclaim", false)) {

View File

@ -34,7 +34,7 @@ public class JSONBoard extends MemoryBoard {
coords = entry.getKey().getCoordString();
id = entry.getValue();
if (!worldCoordIds.containsKey(worldName)) {
worldCoordIds.put(worldName, new TreeMap<String, String>());
worldCoordIds.put(worldName, new TreeMap<>());
}
worldCoordIds.get(worldName).put(coords, id);

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.zcore.persist.json;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@ -40,12 +39,7 @@ public class JSONFPlayers extends MemoryFPlayers {
}
public void convertFrom(MemoryFPlayers old) {
this.fPlayers.putAll(Maps.transformValues(old.fPlayers, new Function<FPlayer, JSONFPlayer>() {
@Override
public JSONFPlayer apply(FPlayer arg0) {
return new JSONFPlayer((MemoryFPlayer) arg0);
}
}));
this.fPlayers.putAll(Maps.transformValues(old.fPlayers, faction -> new JSONFPlayer((MemoryFPlayer) faction)));
forceSave();
FPlayers.instance = this;
}
@ -171,11 +165,9 @@ 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}")) {
// Not a valid UUID..
if (key.matches("[a-zA-Z0-9_]{2,16}")) {
// Valid playername, we'll mark this as one for conversion
// to UUID
return true;
}
// Valid playername, we'll mark this as one for conversion
// to UUID
return key.matches("[a-zA-Z0-9_]{2,16}");
}
return false;
}

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.zcore.persist.json;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@ -241,12 +240,7 @@ public class JSONFactions extends MemoryFactions {
@Override
public void convertFrom(MemoryFactions old) {
this.factions.putAll(Maps.transformValues(old.factions, new Function<Faction, JSONFaction>() {
@Override
public JSONFaction apply(Faction arg0) {
return new JSONFaction((MemoryFaction) arg0);
}
}));
this.factions.putAll(Maps.transformValues(old.factions, faction -> new JSONFaction((MemoryFaction) faction)));
this.nextId = old.nextId;
forceSave();
Factions.instance = this;