From ce9038742f7af94f32810732ff23f007f729b4d0 Mon Sep 17 00:00:00 2001 From: Driftay Date: Tue, 9 Jun 2020 06:28:34 -0400 Subject: [PATCH] Code Optimizations --- .../java/com/massivecraft/factions/Conf.java | 1 - .../massivecraft/factions/FactionsPlugin.java | 10 +- .../factions/cmd/CmdAnnounce.java | 2 +- .../massivecraft/factions/cmd/CmdBanner.java | 1 - .../massivecraft/factions/cmd/CmdBoom.java | 1 - .../massivecraft/factions/cmd/CmdBypass.java | 1 - .../massivecraft/factions/cmd/CmdChat.java | 3 +- .../factions/cmd/CmdCheckpoint.java | 3 +- .../massivecraft/factions/cmd/CmdCreate.java | 2 +- .../factions/cmd/CmdDescription.java | 2 +- .../massivecraft/factions/cmd/CmdDisband.java | 16 +-- .../massivecraft/factions/cmd/CmdHome.java | 6 +- .../factions/cmd/CmdInventorySee.java | 1 + .../massivecraft/factions/cmd/CmdInvite.java | 2 +- .../massivecraft/factions/cmd/CmdRules.java | 6 +- .../massivecraft/factions/cmd/CmdShow.java | 2 +- .../factions/cmd/CmdTpBanner.java | 4 +- .../massivecraft/factions/cmd/CmdUnban.java | 6 +- .../factions/cmd/CommandRequirements.java | 10 +- .../factions/cmd/alts/CmdAltsList.java | 2 +- .../factions/cmd/audit/FAuditMenu.java | 4 +- .../factions/cmd/audit/FLogManager.java | 5 +- .../factions/cmd/audit/FactionLogs.java | 4 +- .../factions/cmd/audit/LogTimer.java | 4 +- .../factions/cmd/check/CheckHistoryFrame.java | 8 +- .../cmd/check/CheckSettingsFrame.java | 5 +- .../factions/cmd/check/WeeWooTask.java | 7 - .../factions/cmd/chest/AntiChestListener.java | 12 +- .../factions/cmd/claim/CmdAutoClaim.java | 11 +- .../factions/cmd/claim/CmdClaim.java | 19 +-- .../factions/cmd/claim/CmdClaimLine.java | 15 +- .../factions/cmd/econ/CmdMoneyWithdraw.java | 13 +- .../factions/cmd/grace/CmdGrace.java | 36 +++-- .../factions/cmd/logout/LogoutHandler.java | 2 - .../cmd/relational/FRelationCommand.java | 20 ++- .../factions/cmd/wild/CmdWild.java | 8 +- .../factions/discord/CmdSetGuild.java | 10 +- .../factions/discord/Discord.java | 41 +++--- .../factions/discord/DiscordListener.java | 4 +- .../factions/discord/DiscordSetupAttempt.java | 4 +- .../factions/discord/FactionChatHandler.java | 2 +- .../factions/integration/Econ.java | 12 +- .../factions/integration/Worldguard.java | 1 - .../integration/dynmap/EngineDynmap.java | 30 ++-- .../integration/dynmap/TempMarkerSet.java | 6 +- .../listeners/FactionsBlockListener.java | 134 +++++++++--------- .../listeners/FactionsChatListener.java | 2 +- .../listeners/FactionsEntityListener.java | 119 +++++----------- .../listeners/FactionsPlayerListener.java | 66 ++++----- .../factions/listeners/MenuListener.java | 3 - .../factions/scoreboards/FScoreboard.java | 2 +- .../factions/scoreboards/FTeamWrapper.java | 17 ++- .../factions/shop/ShopGUIFrame.java | 13 +- .../massivecraft/factions/struct/Role.java | 8 +- .../massivecraft/factions/tag/FactionTag.java | 62 ++++---- .../massivecraft/factions/tag/FancyTag.java | 2 +- .../factions/util/AutoLeaveProcessTask.java | 4 +- .../massivecraft/factions/util/Cooldown.java | 2 +- .../factions/util/InventoryUtil.java | 2 +- .../massivecraft/factions/util/MiscUtil.java | 2 - .../factions/util/RelationUtil.java | 2 - .../factions/util/SpiralTask.java | 1 - .../factions/util/VisualizeUtil.java | 3 +- .../factions/util/timer/TimerRunnable.java | 7 - .../factions/util/timer/type/GraceTimer.java | 14 +- 65 files changed, 333 insertions(+), 496 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/Conf.java b/src/main/java/com/massivecraft/factions/Conf.java index 543df599..cb4316a1 100644 --- a/src/main/java/com/massivecraft/factions/Conf.java +++ b/src/main/java/com/massivecraft/factions/Conf.java @@ -268,7 +268,6 @@ public class Conf { public static boolean ownedMessageInsideTerritory = true; public static boolean ownedMessageByChunk = false; public static boolean pistonProtectionThroughDenyBuild = true; - public static Set loggableMaterials = EnumSet.noneOf(Material.class); public static Set territoryProtectedMaterials = EnumSet.noneOf(Material.class); public static Set territoryDenyUsageMaterials = EnumSet.noneOf(Material.class); public static Set territoryProtectedMaterialsWhenOffline = EnumSet.noneOf(Material.class); diff --git a/src/main/java/com/massivecraft/factions/FactionsPlugin.java b/src/main/java/com/massivecraft/factions/FactionsPlugin.java index cc9be833..b9b9224a 100755 --- a/src/main/java/com/massivecraft/factions/FactionsPlugin.java +++ b/src/main/java/com/massivecraft/factions/FactionsPlugin.java @@ -167,12 +167,14 @@ public class FactionsPlugin extends MPlugin { FactionsPlugin.instance.log("Minecraft Version 1.15 found."); mc115 = true; break; + default: + throw new IllegalStateException("Unexpected value: " + version); } migrateFPlayerLeaders(); log("==== End Setup ===="); int pluginId = 7013; - Metrics metrics = new Metrics(this, pluginId); + new Metrics(this, pluginId); if (!preEnable()) { this.loadSuccessful = false; @@ -394,14 +396,12 @@ public class FactionsPlugin extends MPlugin { return this.mvdwPlaceholderAPIManager; } - private boolean setupPermissions() { + private void setupPermissions() { try { RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Permission.class); if (rsp != null) perms = rsp.getProvider(); - } catch (NoClassDefFoundError ex) { - return false; + } catch (NoClassDefFoundError ignored) { } - return perms != null; } private boolean setupPlayervaults() { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java b/src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java index 633199e9..4276a172 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java @@ -50,7 +50,7 @@ public class CmdAnnounce extends FCommand { return TL.COMMAND_ANNOUNCE_DESCRIPTION; } - protected class AnnounceBrigadier implements BrigadierProvider { + protected static class AnnounceBrigadier implements BrigadierProvider { @Override public ArgumentBuilder get(ArgumentBuilder parent) { return parent.then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString())); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBanner.java b/src/main/java/com/massivecraft/factions/cmd/CmdBanner.java index cb8c3002..6e4635d4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBanner.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBanner.java @@ -60,7 +60,6 @@ public class CmdBanner extends FCommand { @Deprecated public void takeMoney(FPlayer fme, int amt) { if (this.hasMoney(fme, amt)) { - Economy econ = FactionsPlugin.getInstance().getEcon(); fme.sendMessage(TL.COMMAND_BANNER_MONEYTAKE.toString().replace("{amount}", amt + "")); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBoom.java b/src/main/java/com/massivecraft/factions/cmd/CmdBoom.java index 8bf5bf7a..460f2fac 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBoom.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBoom.java @@ -14,7 +14,6 @@ public class CmdBoom extends FCommand { super(); this.aliases.addAll(Aliases.boom); - //this.requiredArgs.add(""); this.optionalArgs.put("on/off", "flip"); this.requirements = new CommandRequirements.Builder(Permission.NO_BOOM) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBypass.java b/src/main/java/com/massivecraft/factions/cmd/CmdBypass.java index 272f06a2..b9cd7000 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBypass.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBypass.java @@ -14,7 +14,6 @@ public class CmdBypass extends FCommand { super(); this.aliases.addAll(Aliases.bypass); - //this.requiredArgs.add(""); this.optionalArgs.put("on/off", "flip"); this.requirements = new CommandRequirements.Builder(Permission.BYPASS) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdChat.java b/src/main/java/com/massivecraft/factions/cmd/CmdChat.java index f0b9f7dd..35313626 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdChat.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdChat.java @@ -18,7 +18,6 @@ public class CmdChat extends FCommand { super(); this.aliases.addAll(Aliases.chat); - //this.requiredArgs.add(""); this.optionalArgs.put("mode", "next"); this.requirements = new CommandRequirements.Builder(Permission.CHAT) @@ -86,7 +85,7 @@ public class CmdChat extends FCommand { return TL.COMMAND_CHAT_DESCRIPTION; } - protected class ChatBrigadier implements BrigadierProvider { + protected static class ChatBrigadier implements BrigadierProvider { @Override public ArgumentBuilder get(ArgumentBuilder parent) { return parent.then(LiteralArgumentBuilder.literal("public")) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdCheckpoint.java b/src/main/java/com/massivecraft/factions/cmd/CmdCheckpoint.java index b70ebb92..0982b24b 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdCheckpoint.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdCheckpoint.java @@ -35,11 +35,10 @@ public class CmdCheckpoint extends FCommand { if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == context.faction) { context.faction.setCheckpoint(context.player.getLocation()); context.msg(TL.COMMAND_CHECKPOINT_SET); - return; } else { context.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION); - return; } + return; } if (context.faction.getCheckpoint() == null) { context.msg(TL.COMMAND_CHECKPOINT_NOT_SET); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java b/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java index c160163e..e4c4b2c3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java @@ -66,7 +66,7 @@ public class CmdCreate extends FCommand { } ArrayList tagValidationErrors = MiscUtil.validateTag(tag); - if (tagValidationErrors.size() > 0) { + if (tagValidationErrors.isEmpty()) { context.sendMessage(tagValidationErrors); return; } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDescription.java b/src/main/java/com/massivecraft/factions/cmd/CmdDescription.java index 6e7992a3..96ef4645 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDescription.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDescription.java @@ -39,7 +39,7 @@ public class CmdDescription extends FCommand { // since "&" color tags seem to work even through plain old FPlayer.sendMessage() for some reason, we need to break those up // And replace all the % because it messes with string formatting and this is easy way around that. - String desc = TextUtil.implode(context.args, " ").replaceAll("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2"); + String desc = TextUtil.implode(context.args, " ").replace("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2"); context.faction.setDescription(desc); Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.FDESC_EDIT, context.fPlayer.getName(), desc)); if (!Conf.broadcastDescriptionChanges) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java index 6010810d..03645f59 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java @@ -42,8 +42,8 @@ public class CmdDisband extends FCommand { boolean isMyFaction = context.fPlayer != null && faction == context.faction; - if (!isMyFaction) { - if (!Permission.DISBAND_ANY.has(context.sender, true)) return; + if (!isMyFaction && !Permission.DISBAND_ANY.has(context.sender, true)) { + return; } @@ -70,7 +70,7 @@ public class CmdDisband extends FCommand { return; } - if(Cooldown.isOnCooldown(context.fPlayer.getPlayer(), "disbandCooldown") && !context.fPlayer.isAdminBypassing()){ + if (Cooldown.isOnCooldown(context.fPlayer.getPlayer(), "disbandCooldown") && !context.fPlayer.isAdminBypassing()) { context.msg(TL.COMMAND_COOLDOWN); return; } @@ -81,13 +81,9 @@ public class CmdDisband extends FCommand { access = true; } - if (!access) { - if (Conf.useDisbandGUI && (!context.fPlayer.isAdminBypassing() || !context.player.isOp())) { - if (!disbandMap.containsKey(context.player.getUniqueId().toString())) { - new FDisbandFrame(context.faction).buildGUI(context.fPlayer); - return; - } - } + if (!access && Conf.useDisbandGUI && (!context.fPlayer.isAdminBypassing() || !context.player.isOp()) && !disbandMap.containsKey(context.player.getUniqueId().toString())) { + new FDisbandFrame(context.faction).buildGUI(context.fPlayer); + return; } // check for tnt before disbanding. diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java index e2b84cff..c54817cc 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java @@ -88,11 +88,7 @@ public class CmdHome extends FCommand { final Location loc = context.player.getLocation().clone(); // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby - if (Conf.homesTeleportAllowedEnemyDistance > 0 - && !faction.isSafeZone() - && (!context.fPlayer.isInOwnTerritory() - || (context.fPlayer.isInOwnTerritory() - && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) { + if (Conf.homesTeleportAllowedEnemyDistance > 0 && !faction.isSafeZone() && (!context.fPlayer.isInOwnTerritory() || !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)) { World w = loc.getWorld(); double x = loc.getX(); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInventorySee.java b/src/main/java/com/massivecraft/factions/cmd/CmdInventorySee.java index 53f1d1e6..84da598e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInventorySee.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInventorySee.java @@ -49,6 +49,7 @@ public class CmdInventorySee extends FCommand { FPlayer targetInv = context.argAsFPlayer(0); if (targetInv == null || !fplayers.contains(targetInv.getPlayer())) { + assert targetInv != null; context.msg(TL.PLAYER_NOT_FOUND, Objects.requireNonNull(targetInv.getName())); return; } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java index f6656197..230a75e3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java @@ -63,7 +63,7 @@ public class CmdInvite extends FCommand { FancyMessage message = new FancyMessage(TL.COMMAND_INVITE_INVITEDYOU.toString() .replace("%1$s", context.fPlayer.describeTo(target, true)) .replace("%2$s", context.faction.getTag()) - .replaceAll("&", "§")) + .replace("&", "§")) .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag()); message.send(target.getPlayer()); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdRules.java b/src/main/java/com/massivecraft/factions/cmd/CmdRules.java index eec5aae1..fe86bea5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdRules.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdRules.java @@ -66,18 +66,16 @@ public class CmdRules extends FCommand { String message = ""; StringBuilder string = new StringBuilder(message); for (int i = 1; i <= context.args.size() - 1; i++) { - string.append(" " + context.args.get(i)); + string.append(" ").append(context.args.get(i)); } context.faction.addRule(string.toString()); context.msg(TL.COMMAND_RULES_ADD_SUCCESS); } - if (context.args.size() == 2) { - if (context.args.get(0).equalsIgnoreCase("remove")) { + if (context.args.size() == 2 && context.args.get(0).equalsIgnoreCase("remove")) { int index = context.argAsInt(1); context.faction.removeRule(index - 1); context.msg(TL.COMMAND_RULES_REMOVE_SUCCESS); - } } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java index 6de26d8a..978c136d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java @@ -110,7 +110,7 @@ public class CmdShow extends FCommand { parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString(); } if (parsed.contains("%")) { - parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. + parsed = parsed.replace("%", ""); // Just in case it got in there before we disallowed it. } parsed = FactionsPlugin.getInstance().txt.parse(parsed); FancyMessage localFancy = instance.txt.parseFancy(parsed); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdTpBanner.java b/src/main/java/com/massivecraft/factions/cmd/CmdTpBanner.java index 2fcd7a03..2ed036d1 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdTpBanner.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdTpBanner.java @@ -30,9 +30,7 @@ public class CmdTpBanner extends FCommand { if (FactionsBlockListener.bannerLocations.containsKey(context.fPlayer.getTag())) { context.msg(TL.COMMAND_TPBANNER_SUCCESS); - context.doWarmUp(WarmUpUtil.Warmup.BANNER, TL.WARMUPS_NOTIFY_TELEPORT, "Banner", () -> { - context.player.teleport(FactionsBlockListener.bannerLocations.get(context.fPlayer.getTag())); - }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-banner", 0)); + context.doWarmUp(WarmUpUtil.Warmup.BANNER, TL.WARMUPS_NOTIFY_TELEPORT, "Banner", () -> context.player.teleport(FactionsBlockListener.bannerLocations.get(context.fPlayer.getTag())), FactionsPlugin.getInstance().getConfig().getLong("warmups.f-banner", 0)); } else { context.msg(TL.COMMAND_TPBANNER_NOTSET); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java b/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java index 442b74aa..d533bd3a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java @@ -33,12 +33,8 @@ public class CmdUnban extends FCommand { return; // the above method sends a message if fails to find someone. } - if (target.getFaction() != context.fPlayer.getFaction()) { - if (target.getFaction().getAccess(context.fPlayer, PermissableAction.BAN) != Access.ALLOW) { - if (!context.fPlayer.isAdminBypassing()) { + if (target.getFaction() != context.fPlayer.getFaction() && target.getFaction().getAccess(context.fPlayer, PermissableAction.BAN) != Access.ALLOW && !context.fPlayer.isAdminBypassing()) { context.fPlayer.msg(TL.COMMAND_UNBAN_TARGET_IN_OTHER_FACTION, target.getName()); - } - } } if (!context.faction.isBanned(target)) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CommandRequirements.java b/src/main/java/com/massivecraft/factions/cmd/CommandRequirements.java index feb6afce..e7c8b9e6 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CommandRequirements.java +++ b/src/main/java/com/massivecraft/factions/cmd/CommandRequirements.java @@ -70,13 +70,9 @@ public class CommandRequirements { return false; } - if (access != Access.ALLOW) { - // They have undefined assert their role - if (role != null && !context.fPlayer.getRole().isAtLeast(role)) { - // They do not fullfill the role - if (informIfNot) context.msg(TL.GENERIC_YOUMUSTBE, role.translation); - return false; - } + if (access != Access.ALLOW && role != null && !context.fPlayer.getRole().isAtLeast(role)) { + if (informIfNot) context.msg(TL.GENERIC_YOUMUSTBE, role.translation); + return false; } // They have been explicitly allowed return true; diff --git a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java index 8c5a03c6..d181512d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java +++ b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java @@ -44,7 +44,7 @@ public class CmdAltsList extends FCommand { return; } - if (faction.getAltPlayers().size() == 0) { + if (faction.getAltPlayers().isEmpty()) { context.msg(TL.COMMAND_ALTS_LIST_NOALTS, faction.getTag()); return; } diff --git a/src/main/java/com/massivecraft/factions/cmd/audit/FAuditMenu.java b/src/main/java/com/massivecraft/factions/cmd/audit/FAuditMenu.java index 51e89a66..d250761e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/audit/FAuditMenu.java +++ b/src/main/java/com/massivecraft/factions/cmd/audit/FAuditMenu.java @@ -114,7 +114,7 @@ public class FAuditMenu extends GUIMenu { } lore.add(""); lore.add(CC.Gray + "Click to toggle timestamp"); - setItem(slot++, (new ClickableItemStack((new ItemBuilder(Material.PAPER)).name(CC.GreenB + "Log #" + page).lore(lore).build())).setClickCallback((e) -> { + setItem(slot++, (new ClickableItemStack((new ItemBuilder(Material.PAPER)).name(CC.GreenB + "Log #" + page).lore(lore).build())).setClickCallback(e -> { e.setCancelled(true); timeStamp = !timeStamp; drawItems(); @@ -122,7 +122,7 @@ public class FAuditMenu extends GUIMenu { } } } - setItem(getSize() - 1, (new ClickableItemStack((new ItemBuilder(Material.ARROW)).name(CC.Green + "Previous Page").lore("", CC.Gray + "Click to view previous page!").build())).setClickCallback((event) -> { + setItem(getSize() - 1, (new ClickableItemStack((new ItemBuilder(Material.ARROW)).name(CC.Green + "Previous Page").lore("", CC.Gray + "Click to view previous page!").build())).setClickCallback(event -> { event.setCancelled(true); Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> (new FAuditMenu(player, faction)).open(player)); })); diff --git a/src/main/java/com/massivecraft/factions/cmd/audit/FLogManager.java b/src/main/java/com/massivecraft/factions/cmd/audit/FLogManager.java index 7b5eb28a..ac054be5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/audit/FLogManager.java +++ b/src/main/java/com/massivecraft/factions/cmd/audit/FLogManager.java @@ -25,8 +25,6 @@ public class FLogManager { private Map logTimers = new ConcurrentHashMap<>(); private boolean saving = false; - public FLogManager() { - } public void log(Faction faction, FLogType type, String... arguments) { FactionLogs logs = factionLogMap.computeIfAbsent(faction.getId(), (n) -> new FactionLogs()); @@ -90,8 +88,7 @@ public class FLogManager { Faction faction = null; for (Map.Entry uuidLogTimerEntry : getLogTimers().entrySet()) { - Map.Entry timer = uuidLogTimerEntry; - LogTimer logTimer = timer.getValue(); + LogTimer logTimer = uuidLogTimerEntry.getValue(); if (faction == null) { faction = Factions.getInstance().getFactionById(logTimer.getFactionId()); } diff --git a/src/main/java/com/massivecraft/factions/cmd/audit/FactionLogs.java b/src/main/java/com/massivecraft/factions/cmd/audit/FactionLogs.java index efebf420..e4371944 100644 --- a/src/main/java/com/massivecraft/factions/cmd/audit/FactionLogs.java +++ b/src/main/java/com/massivecraft/factions/cmd/audit/FactionLogs.java @@ -65,11 +65,11 @@ public class FactionLogs { } } } - if (logs.size() <= 0) + if (logs.isEmpty()) toRemove.add(logType); } }); - toRemove.forEach((rem) -> mostRecentLogs.remove(rem)); + toRemove.forEach(rem -> mostRecentLogs.remove(rem)); } public Map> getMostRecentLogs() { diff --git a/src/main/java/com/massivecraft/factions/cmd/audit/LogTimer.java b/src/main/java/com/massivecraft/factions/cmd/audit/LogTimer.java index d32831f6..b31ebeda 100644 --- a/src/main/java/com/massivecraft/factions/cmd/audit/LogTimer.java +++ b/src/main/java/com/massivecraft/factions/cmd/audit/LogTimer.java @@ -26,11 +26,11 @@ public class LogTimer extends ConcurrentHashMap getCurrentTimersOrCreate(LogTimer.TimerType type) { - return this.computeIfAbsent(type, (m) -> new ConcurrentHashMap<>()); + return this.computeIfAbsent(type, m -> new ConcurrentHashMap<>()); } public LogTimer.Timer attemptLog(LogTimer.TimerType type, LogTimer.TimerSubType subType, long increment) { - return this.getCurrentTimersOrCreate(type).computeIfAbsent(subType, (e) -> new Timer(System.currentTimeMillis(), 0L, null)).increment(increment); + return this.getCurrentTimersOrCreate(type).computeIfAbsent(subType, e -> new Timer(System.currentTimeMillis(), 0L, null)).increment(increment); } public void pushLogs(Faction faction, LogTimer.TimerType type) { diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java b/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java index ee9ea1be..4359e5c1 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java @@ -13,24 +13,19 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.material.MaterialData; +import org.jetbrains.annotations.NotNull; import java.text.SimpleDateFormat; import java.util.*; public class CheckHistoryFrame implements FactionGUI { - /** - * @author Driftay - */ - - private FactionsPlugin plugin; private Faction faction; private Inventory inventory; private SimpleDateFormat simpleDateFormat; public CheckHistoryFrame(FactionsPlugin plugin, Faction faction) { this.simpleDateFormat = new SimpleDateFormat(Conf.dateFormat); - this.plugin = plugin; this.faction = faction; this.inventory = plugin.getServer().createInventory(this, 54, TL.CHECK_HISTORY_GUI_TITLE.toString()); } @@ -88,6 +83,7 @@ public class CheckHistoryFrame implements FactionGUI { } } + @NotNull public Inventory getInventory() { return inventory; } diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java b/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java index 6a07a792..98243fc9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java @@ -12,6 +12,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -71,6 +72,7 @@ public class CheckSettingsFrame implements InventoryHolder, FactionGUI { inventory.setItem(FactionsPlugin.getInstance().getConfig().getInt("f-check.history.slot"), historyStack); } + @NotNull public Inventory getInventory() { return this.inventory; } @@ -92,9 +94,6 @@ public class CheckSettingsFrame implements InventoryHolder, FactionGUI { case 15: { return 30; } - case 30: { - return 0; - } default: { return 0; } diff --git a/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java b/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java index 7b8421d6..19d621f6 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java @@ -11,14 +11,7 @@ import net.dv8tion.jda.core.entities.TextChannel; public class WeeWooTask implements Runnable { - /** - * @author Driftay - */ - - private FactionsPlugin plugin; - public WeeWooTask(FactionsPlugin plugin) { - this.plugin = plugin; } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/chest/AntiChestListener.java b/src/main/java/com/massivecraft/factions/cmd/chest/AntiChestListener.java index b6dfba1a..84f97321 100644 --- a/src/main/java/com/massivecraft/factions/cmd/chest/AntiChestListener.java +++ b/src/main/java/com/massivecraft/factions/cmd/chest/AntiChestListener.java @@ -29,13 +29,11 @@ public class AntiChestListener implements Listener { Inventory clicked = e.getClickedInventory(); Inventory clicker = e.getWhoClicked().getInventory(); - if (e.getClick().isShiftClick()) { - if (clicked == clicker) { - ItemStack clickedOn = e.getCurrentItem(); - if (clickedOn != null && FactionsPlugin.getInstance().itemList.contains(clickedOn.getType().toString())) { - fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, clickedOn.getType().toString()); - e.setCancelled(true); - } + if (e.getClick().isShiftClick() && clicked == clicker) { + ItemStack clickedOn = e.getCurrentItem(); + if (clickedOn != null && FactionsPlugin.getInstance().itemList.contains(clickedOn.getType().toString())) { + fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, clickedOn.getType().toString()); + e.setCancelled(true); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java index 5568f1be..8c2c7016 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java @@ -26,7 +26,6 @@ public class CmdAutoClaim extends FCommand { super(); this.aliases.addAll(Aliases.claim_auto); - //this.requiredArgs.add(""); this.optionalArgs.put("faction", "your"); this.requirements = new CommandRequirements.Builder(Permission.AUTOCLAIM) @@ -39,13 +38,9 @@ public class CmdAutoClaim extends FCommand { public void perform(CommandContext context) { Faction forFaction = context.argAsFaction(0, context.faction); - if (forFaction != context.fPlayer.getFaction()) { - if (!context.fPlayer.isAdminBypassing()) { - if (forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) { - context.msg(TL.COMMAND_CLAIM_DENIED); - return; - } - } + if (forFaction != context.fPlayer.getFaction() && !context.fPlayer.isAdminBypassing() && forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) { + context.msg(TL.COMMAND_CLAIM_DENIED); + return; } if (forFaction == null || forFaction == context.fPlayer.getAutoClaimFor()) { diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java index c80f91d2..014331d4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java @@ -41,13 +41,9 @@ public class CmdClaim extends FCommand { int radius = context.argAsInt(0, 1); // Default to 1 final Faction forFaction = context.argAsFaction(1, context.faction); // Default to own - if (!context.fPlayer.isAdminBypassing()) { - if (!(context.fPlayer.getFaction().equals(forFaction) && context.fPlayer.getRole() == Role.LEADER)) { - if (forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) { - context.msg(TL.COMMAND_CLAIM_DENIED); - return; - } - } + if (!context.fPlayer.isAdminBypassing() && !(context.fPlayer.getFaction().equals(forFaction) && context.fPlayer.getRole() == Role.LEADER) && forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) { + context.msg(TL.COMMAND_CLAIM_DENIED); + return; } @@ -90,12 +86,11 @@ public class CmdClaim extends FCommand { return true; } + @Override public void finish() { - if (FactionsPlugin.cachedRadiusClaim) { - if (successfulClaims > 0) { - context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_RADIUS_CLAIM, context.fPlayer.describeTo(f, true), String.valueOf(successfulClaims), context.fPlayer.getPlayer().getLocation().getChunk().getX(), context.fPlayer.getPlayer().getLocation().getChunk().getZ())); - stop(); - } + if (FactionsPlugin.cachedRadiusClaim && successfulClaims > 0) { + context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_RADIUS_CLAIM, context.fPlayer.describeTo(f, true), String.valueOf(successfulClaims), context.fPlayer.getPlayer().getLocation().getChunk().getX(), context.fPlayer.getPlayer().getLocation().getChunk().getZ())); + stop(); } } }; diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java index 33474a6d..8628cd52 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java @@ -68,15 +68,10 @@ public class CmdClaimLine extends FCommand { } final Faction forFaction = context.argAsFaction(2, context.faction); - Faction at = Board.getInstance().getFactionAt(new FLocation(context.fPlayer.getPlayer().getLocation())); - if (forFaction != context.fPlayer.getFaction()) { - if (!context.fPlayer.isAdminBypassing()) { - if (forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) { + if (forFaction != context.fPlayer.getFaction() && !context.fPlayer.isAdminBypassing() && forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) { context.msg(TL.COMMAND_CLAIM_DENIED); return; - } - } } Location location = context.player.getLocation(); @@ -85,13 +80,11 @@ public class CmdClaimLine extends FCommand { int claims = 0; for (int i = 0; i < amount; i++) { - if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), false)) { - claims++; - } else { + if (!FactionsPlugin.cachedRadiusClaim || !context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), false)) { context.fPlayer.attemptClaim(forFaction, location, true); - claims++; } - location = location.add(blockFace.getModX() * 16, 0, blockFace.getModZ() * 16); + claims++; + location = location.add(blockFace.getModX() * 16D, 0, blockFace.getModZ() * 16D); FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", String.valueOf(i), new FLocation(context.player.getLocation()).formatXAndZ(",")); } int cachedClaims = claims; diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java index 338542e1..1a2767b0 100644 --- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java +++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java @@ -8,7 +8,6 @@ import com.massivecraft.factions.cmd.CommandContext; import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.cmd.audit.FLogType; -import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -44,23 +43,21 @@ public class CmdMoneyWithdraw extends FCommand { return; } - EconomyParticipator faction = context.argAsFaction(1, context.faction); + Faction faction = context.argAsFaction(1, context.faction); if (faction == null) { return; } Access access = context.faction.getAccess(context.fPlayer, PermissableAction.WITHDRAW); - if (context.fPlayer.getRole() != Role.LEADER) { - if (access == Access.DENY) { - context.msg(TL.GENERIC_NOPERMISSION, "withdraw", "withdraw money from the bank"); - return; - } + if (context.fPlayer.getRole() != Role.LEADER && access == Access.DENY) { + context.msg(TL.GENERIC_NOPERMISSION, "withdraw", "withdraw money from the bank"); + return; } boolean success = Econ.transferMoney(context.fPlayer, faction, context.fPlayer, amount); if (success && Conf.logMoneyTransactions) { FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYWITHDRAW_WITHDRAW.toString(), context.fPlayer.getName(), Econ.moneyString(amount), faction.describeTo(null)))); - FactionsPlugin.instance.logFactionEvent((Faction) faction, FLogType.BANK_EDIT, context.fPlayer.getName(), CC.RedB + "WITHDREW", amount + ""); + FactionsPlugin.instance.logFactionEvent(faction, FLogType.BANK_EDIT, context.fPlayer.getName(), CC.RedB + "WITHDREW", amount + ""); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java b/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java index de6f5894..e066dd20 100644 --- a/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java +++ b/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java @@ -37,31 +37,29 @@ public class CmdGrace extends FCommand { return; } - if(context.args.size() == 1) { - if (context.sender.hasPermission(String.valueOf(Permission.GRACETOGGLE))) { - if (context.argAsString(0).equalsIgnoreCase("on") || context.argAsString(0).equalsIgnoreCase("start")) { - FactionsPlugin.getInstance().getTimerManager().graceTimer.setPaused(false); - FactionsPlugin.getInstance().getTimerManager().graceTimer.setRemaining(TimeUnit.DAYS.toMillis(Conf.gracePeriodTimeDays), true); - if (Conf.broadcastGraceToggles) { - for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) - follower.msg(TL.COMMAND_GRACE_ENABLED_FORMAT, String.valueOf(TimerManager.getRemaining(FactionsPlugin.getInstance().getTimerManager().graceTimer.getRemaining(), true))); - } - return; + if (context.args.size() == 1 && context.sender.hasPermission(String.valueOf(Permission.GRACETOGGLE))) { + if (context.argAsString(0).equalsIgnoreCase("on") || context.argAsString(0).equalsIgnoreCase("start")) { + FactionsPlugin.getInstance().getTimerManager().graceTimer.setPaused(false); + FactionsPlugin.getInstance().getTimerManager().graceTimer.setRemaining(TimeUnit.DAYS.toMillis(Conf.gracePeriodTimeDays), true); + if (Conf.broadcastGraceToggles) { + for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) + follower.msg(TL.COMMAND_GRACE_ENABLED_FORMAT, String.valueOf(TimerManager.getRemaining(FactionsPlugin.getInstance().getTimerManager().graceTimer.getRemaining(), true))); } + return; + } - if (context.argAsString(0).equalsIgnoreCase("off") || context.argAsString(0).equalsIgnoreCase("stop")) { - FactionsPlugin.getInstance().getTimerManager().graceTimer.setRemaining(TimeUnit.SECONDS.toMillis(0L), true); - FactionsPlugin.getInstance().getTimerManager().graceTimer.setPaused(false); - if (Conf.broadcastGraceToggles) { - for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) - follower.msg(TL.COMMAND_GRACE_DISABLED_FORMAT); - } - return; + if (context.argAsString(0).equalsIgnoreCase("off") || context.argAsString(0).equalsIgnoreCase("stop")) { + FactionsPlugin.getInstance().getTimerManager().graceTimer.setRemaining(TimeUnit.SECONDS.toMillis(0L), true); + FactionsPlugin.getInstance().getTimerManager().graceTimer.setPaused(false); + if (Conf.broadcastGraceToggles) { + for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) + follower.msg(TL.COMMAND_GRACE_DISABLED_FORMAT); } + return; } } - if(FactionsPlugin.getInstance().getTimerManager().graceTimer.getRemaining() <= 0L) { + if (FactionsPlugin.getInstance().getTimerManager().graceTimer.getRemaining() <= 0L) { context.fPlayer.msg(TL.COMMAND_GRACE_DISABLED_NO_FORMAT.toString()); } else { context.fPlayer.msg(TL.COMMAND_GRACE_TIME_REMAINING, String.valueOf(TimerManager.getRemaining(FactionsPlugin.getInstance().getTimerManager().graceTimer.getRemaining(), true))); diff --git a/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java b/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java index 0596e2c6..629b4ed4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java +++ b/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java @@ -15,10 +15,8 @@ public class LogoutHandler { public static Map factionDatas = new HashMap<>(); private Map logoutCooldown = new HashMap<>(); - private String name; public LogoutHandler(String name) { - this.name = name; factionDatas.put(name, this); } diff --git a/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java b/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java index 37274b7a..fd772287 100644 --- a/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java @@ -41,7 +41,7 @@ public abstract class FRelationCommand extends FCommand { Faction them = context.argAsFaction(0); if (them == null) return; - if(!context.faction.isNormal()) return; + if (!context.faction.isNormal()) return; if (!them.isNormal()) { context.msg(TL.COMMAND_RELATIONS_ALLTHENOPE); @@ -112,16 +112,14 @@ public abstract class FRelationCommand extends FCommand { private boolean hasMaxRelations(Faction us, Faction them, Relation targetRelation) { int max = FactionsPlugin.getInstance().getConfig().getInt("max-relations." + targetRelation.toString(), -1); - if (FactionsPlugin.getInstance().getConfig().getBoolean("max-relations.enabled", false)) { - if (max != -1) { - if (us.getRelationCount(targetRelation) >= max) { - us.msg(TL.COMMAND_RELATIONS_EXCEEDS_ME, max, targetRelation.getPluralTranslation()); - return true; - } - if (them.getRelationCount(targetRelation) >= max) { - them.msg(TL.COMMAND_RELATIONS_EXCEEDS_THEY, max, targetRelation.getPluralTranslation()); - return true; - } + if (FactionsPlugin.getInstance().getConfig().getBoolean("max-relations.enabled", false) && max != -1) { + if (us.getRelationCount(targetRelation) >= max) { + us.msg(TL.COMMAND_RELATIONS_EXCEEDS_ME, max, targetRelation.getPluralTranslation()); + return true; + } + if (them.getRelationCount(targetRelation) >= max) { + them.msg(TL.COMMAND_RELATIONS_EXCEEDS_THEY, max, targetRelation.getPluralTranslation()); + return true; } } return false; diff --git a/src/main/java/com/massivecraft/factions/cmd/wild/CmdWild.java b/src/main/java/com/massivecraft/factions/cmd/wild/CmdWild.java index bdefeaaa..5252134f 100644 --- a/src/main/java/com/massivecraft/factions/cmd/wild/CmdWild.java +++ b/src/main/java/com/massivecraft/factions/cmd/wild/CmdWild.java @@ -26,8 +26,8 @@ import java.util.Random; * @author DroppingAnvil */ public class CmdWild extends FCommand implements WaitedTask { - public static HashMap teleportRange; - public static HashSet teleporting; + public static HashMap teleportRange = new HashMap<>(); + public static HashSet teleporting = new HashSet<>(); public static CmdWild instance; public CmdWild() { @@ -37,9 +37,7 @@ public class CmdWild extends FCommand implements WaitedTask { this.requirements = new CommandRequirements.Builder(Permission.WILD) .playerOnly() .build(); - teleporting = new HashSet<>(); - teleportRange = new HashMap<>(); - } + } @Override public void perform(CommandContext context) { diff --git a/src/main/java/com/massivecraft/factions/discord/CmdSetGuild.java b/src/main/java/com/massivecraft/factions/discord/CmdSetGuild.java index 72decd19..61c054f1 100644 --- a/src/main/java/com/massivecraft/factions/discord/CmdSetGuild.java +++ b/src/main/java/com/massivecraft/factions/discord/CmdSetGuild.java @@ -60,17 +60,17 @@ public class CmdSetGuild extends FCommand { if (guild == null) { context.msg(TL.SET_GUILD_ID_INVALID_ID); - } else if (Factions.getInstance().getAllFactions().stream().anyMatch((f) -> guildId.equals(f.getGuildId()))) { + } else if (Factions.getInstance().getAllFactions().stream().anyMatch(f -> guildId.equals(f.getGuildId()))) { context.msg(TL.SET_GUILD_ID_GUILD_ALREADY_LINKED); } else { context.msg(TL.SET_GUILD_ID_PMING_OWNER); User user = guild.getOwner().getUser(); Guild finalGuild = guild; Guild finalGuild1 = guild; - user.openPrivateChannel().queue((privateChannel) -> privateChannel.sendMessage("Link guild **" + finalGuild1.getName() + "** to faction **" + ChatColor.stripColor(faction.getTag()) + "**?").queue((message) -> { + user.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage("Link guild **" + finalGuild1.getName() + "** to faction **" + ChatColor.stripColor(faction.getTag()) + "**?").queue(message -> { String checkMark = "✅"; message.addReaction(checkMark).queue(); - this.eventWaiter.waitForEvent(PrivateMessageReactionAddEvent.class, (event) -> event.getReactionEmote().getName().equals(checkMark) && event.getUser().getId().equals(user.getId()) && event.getMessageId().equals(message.getId()), (event) -> { + this.eventWaiter.waitForEvent(PrivateMessageReactionAddEvent.class, event -> event.getReactionEmote().getName().equals(checkMark) && event.getUser().getId().equals(user.getId()) && event.getMessageId().equals(message.getId()), event -> { faction.setGuildId(context.argAsString(0)); context.msg(TL.SET_GUILD_ID_SUCCESS); privateChannel.sendMessage("Successfully linked **" + finalGuild.getName() + " & " + ChatColor.stripColor(faction.getTag()) + "**").queue(); @@ -78,9 +78,7 @@ public class CmdSetGuild extends FCommand { privateChannel.sendMessage(TL.SET_GUILD_ID_TIMED_OUT_DISCORD.toString()).queue(); context.msg(TL.SET_GUILD_ID_TIMED_OUT_MINECRAFT); }); - }, (t) -> { - context.msg(TL.SET_GUILD_ID_UNABLE_TO_MESSAGE_GUILD_OWNER); - }), (t) -> context.msg(TL.SET_GUILD_ID_UNABLE_TO_MESSAGE_GUILD_OWNER)); + }, t -> context.msg(TL.SET_GUILD_ID_UNABLE_TO_MESSAGE_GUILD_OWNER)), t -> context.msg(TL.SET_GUILD_ID_UNABLE_TO_MESSAGE_GUILD_OWNER)); } } else { faction.setGuildId(null); diff --git a/src/main/java/com/massivecraft/factions/discord/Discord.java b/src/main/java/com/massivecraft/factions/discord/Discord.java index a8dafb03..94d29a18 100644 --- a/src/main/java/com/massivecraft/factions/discord/Discord.java +++ b/src/main/java/com/massivecraft/factions/discord/Discord.java @@ -31,7 +31,7 @@ public class Discord { public static Boolean confUseDiscord; public static String botToken; public static String mainGuildID; - public static Boolean useDiscord; + public static boolean useDiscord; public static java.awt.Color roleColor; public static Guild mainGuild; public static Role leader; @@ -53,13 +53,11 @@ public class Discord { * Called to reload variables and if needed start JDA */ public static void setupDiscord() { - if (jda == null) { - if (startBot()) { - varSetup(); - jda.addEventListener(new FactionChatHandler(plugin)); - jda.addEventListener(new DiscordListener(plugin)); - return; - } + if (jda == null && startBot()) { + varSetup(); + jda.addEventListener(new FactionChatHandler(plugin)); + jda.addEventListener(new DiscordListener(plugin)); + return; } varSetup(); } @@ -84,6 +82,7 @@ public class Discord { confUseDiscord = Conf.useDiscordSystem; botToken = Conf.discordBotToken; if (jda != null && Conf.leaderRoles || Conf.factionDiscordTags) { + assert jda != null; mainGuild = jda.getGuildById(Conf.mainGuildID); } else { mainGuild = null; @@ -151,12 +150,9 @@ public class Discord { * @param s String target Faction tag * @return */ - public static Boolean doesFactionRoleExist(String s) { - StringBuilder sb = new StringBuilder(); - sb.append(Conf.factionRolePrefix); - sb.append(s); - sb.append(Conf.factionRoleSuffix); - return getRoleFromName(sb.toString()) != null; + public static boolean doesFactionRoleExist(String s) { + String sb = Conf.factionRolePrefix + s + Conf.factionRoleSuffix; + return getRoleFromName(sb) != null; } public static Role getRoleFromName(String s) { @@ -189,7 +185,8 @@ public class Discord { sb.append(Conf.factionRoleSuffix); if (!doesFactionRoleExist(sb.toString())) { try { - Role newRole = mainGuild.getController().createRole() + Role newRole; + newRole = mainGuild.getController().createRole() .setName(sb.toString()) .setColor(roleColor) .setPermissions(Permission.EMPTY_PERMISSIONS) @@ -211,11 +208,7 @@ public class Discord { * @return Name of would be Role */ public static String getFactionRoleName(String tag) { - StringBuilder sb = new StringBuilder(); - sb.append(Conf.factionRolePrefix); - sb.append(tag); - sb.append(Conf.factionRoleSuffix); - return sb.toString(); + return Conf.factionRolePrefix + tag + Conf.factionRoleSuffix; } /** @@ -224,7 +217,7 @@ public class Discord { * @param u User * @return Boolean */ - public static Boolean isInMainGuild(User u) { + public static boolean isInMainGuild(User u) { if (mainGuild == null) return false; return mainGuild.getMember(u) == null ? Boolean.FALSE : Boolean.TRUE; } @@ -252,10 +245,12 @@ public class Discord { if (fp.discordSetup() && isInMainGuild(fp.discordUser())) { try { Member m = mainGuild.getMember(fp.discordUser()); - if (Conf.factionDiscordTags) { + boolean discordTags = Conf.factionDiscordTags; + boolean factionRoles = Conf.factionRoles; + if (discordTags) { mainGuild.getController().setNickname(m, Discord.getNicknameString(fp)).queue(); } - if (Conf.factionRoles) { + if (factionRoles) { mainGuild.getController().removeSingleRoleFromMember(m, Objects.requireNonNull(getRoleFromName(oldTag))).queue(); mainGuild.getController().addSingleRoleToMember(m, Objects.requireNonNull(createFactionRole(f.getTag()))).queue(); } diff --git a/src/main/java/com/massivecraft/factions/discord/DiscordListener.java b/src/main/java/com/massivecraft/factions/discord/DiscordListener.java index 0375bec0..4615bd5e 100644 --- a/src/main/java/com/massivecraft/factions/discord/DiscordListener.java +++ b/src/main/java/com/massivecraft/factions/discord/DiscordListener.java @@ -37,7 +37,7 @@ public class DiscordListener extends ListenerAdapter { this.decimalFormat = new DecimalFormat("$#,###.##"); this.plugin = plugin; int minute = 3600; - plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, DiscordListener::saveGuilds, minute * 15, minute * 15); + plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, DiscordListener::saveGuilds, minute * 15L, minute * 15L); } private static JSONGuilds loadGuilds() { @@ -64,6 +64,7 @@ public class DiscordListener extends ListenerAdapter { } } + @Override public void onPrivateMessageReceived(PrivateMessageReceivedEvent e) { Integer i; if (e.getAuthor().isBot()) return; @@ -85,6 +86,7 @@ public class DiscordListener extends ListenerAdapter { } } + @Override public void onGuildMessageReceived(GuildMessageReceivedEvent event) { try { if (event.getMessage().isWebhookMessage() || event.getAuthor().isBot()) return; diff --git a/src/main/java/com/massivecraft/factions/discord/DiscordSetupAttempt.java b/src/main/java/com/massivecraft/factions/discord/DiscordSetupAttempt.java index 9d0f5fec..e5f99c5c 100644 --- a/src/main/java/com/massivecraft/factions/discord/DiscordSetupAttempt.java +++ b/src/main/java/com/massivecraft/factions/discord/DiscordSetupAttempt.java @@ -109,7 +109,7 @@ public class DiscordSetupAttempt { sb.append(inProcessTime); //Just a separator for looks sb.append(" "); - String s = ""; + String s; switch (timeIndex) { case 0: s = "MS"; @@ -129,6 +129,8 @@ public class DiscordSetupAttempt { case 5: s = "Years"; break; + default: + throw new IllegalStateException("Unexpected value: " + timeIndex); } sb.append(s); sb.append(" ago"); diff --git a/src/main/java/com/massivecraft/factions/discord/FactionChatHandler.java b/src/main/java/com/massivecraft/factions/discord/FactionChatHandler.java index ee32afd0..8e712ec4 100644 --- a/src/main/java/com/massivecraft/factions/discord/FactionChatHandler.java +++ b/src/main/java/com/massivecraft/factions/discord/FactionChatHandler.java @@ -35,7 +35,7 @@ public class FactionChatHandler extends ListenerAdapter { this.plugin = plugin; } - public static void sendMessage(FactionsPlugin plugin, Faction faction, UUID uuid, String username, String message) { + public static void sendMessage(Faction faction, UUID uuid, String username, String message) { String factionsChatChannelId = faction.getFactionChatChannelId(); String messageWithMentions = null; if (factionsChatChannelId == null || factionsChatChannelId.isEmpty()) return; diff --git a/src/main/java/com/massivecraft/factions/integration/Econ.java b/src/main/java/com/massivecraft/factions/integration/Econ.java index 659e5643..387596c8 100644 --- a/src/main/java/com/massivecraft/factions/integration/Econ.java +++ b/src/main/java/com/massivecraft/factions/integration/Econ.java @@ -49,7 +49,6 @@ public class Econ { econ = rsp.getProvider(); FactionsPlugin.getInstance().log("Economy integration through Vault plugin successful."); if (!Conf.econEnabled) FactionsPlugin.getInstance().log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true"); - //FactionsPlugin.getInstance().cmdBase.cmdHelp.updateHelp(); } public static boolean shouldBeUsed() { @@ -103,7 +102,6 @@ public class Econ { // Factions can be controlled by members that are moderators... or any member if any member can withdraw. if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || (i instanceof FPlayer && ((FPlayer) i).getRole().value >= Role.MODERATOR.value))) return true; - // Otherwise you may not!;,,; i.msg(TL.ECON_CANTCONTROLMONEY, i.describeTo(i, true), you.describeTo(i)); return false; } @@ -237,7 +235,7 @@ public class Econ { acc = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId())); if (acc.getName() == null) return false; } else acc = Bukkit.getOfflinePlayer(ep.getAccountId()); - String You = ep.describeTo(ep, true); + String you = ep.describeTo(ep, true); if (delta == 0) return true; else if (delta > 0) { @@ -247,12 +245,12 @@ public class Econ { if (er.transactionSuccess()) { modifyUniverseMoney(-delta); if (forDoingThis != null && !forDoingThis.isEmpty()) - ep.msg(TL.COMMAND_MONEY_GAINED, You, moneyString(delta), forDoingThis); + ep.msg(TL.COMMAND_MONEY_GAINED, you, moneyString(delta), forDoingThis); return true; } else { // transfer to account failed if (forDoingThis != null && !forDoingThis.isEmpty()) - ep.msg(TL.ECON_DEPOSITFAILED, You, moneyString(delta), forDoingThis); + ep.msg(TL.ECON_DEPOSITFAILED, you, moneyString(delta), forDoingThis); return false; } } else { @@ -262,12 +260,12 @@ public class Econ { // There is enough money to pay modifyUniverseMoney(-delta); if (forDoingThis != null && !forDoingThis.isEmpty()) - ep.msg(TL.ECON_MONEYLOST, You, moneyString(-delta), forDoingThis); + ep.msg(TL.ECON_MONEYLOST, you, moneyString(-delta), forDoingThis); return true; } else { // There was not enough money to pay if (toDoThis != null && !toDoThis.isEmpty()) - ep.msg(TL.ECON_CANTAFFORD, You, moneyString(-delta), toDoThis); + ep.msg(TL.ECON_CANTAFFORD, you, moneyString(-delta), toDoThis); return false; } } diff --git a/src/main/java/com/massivecraft/factions/integration/Worldguard.java b/src/main/java/com/massivecraft/factions/integration/Worldguard.java index be5c9bad..343a2a51 100644 --- a/src/main/java/com/massivecraft/factions/integration/Worldguard.java +++ b/src/main/java/com/massivecraft/factions/integration/Worldguard.java @@ -159,7 +159,6 @@ public class Worldguard { FactionsPlugin.getInstance().log("We failed to load Vector Classes from WorldGuard! Support will be removed!"); FactionsPlugin.getInstance().log("WorldGuard 7.0.0 support is currently in BETA. Please be careful!"); regionContainer = null; - return; } } } diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java index a44a6daf..ebd82085 100644 --- a/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java @@ -26,20 +26,17 @@ public class EngineDynmap { // CONSTANTS // -------------------------------------------- // - public final static int BLOCKS_PER_CHUNK = 16; + public static final int BLOCKS_PER_CHUNK = 16; - public final static String DYNMAP_INTEGRATION = "\u00A7dDynmap Integration: \u00A7e"; + public static final String DYNMAP_INTEGRATION = "\u00A7dDynmap Integration: \u00A7e"; - public final static String FACTIONS = "factions"; - public final static String FACTIONS_ = FACTIONS + "_"; - - public final static String FACTIONS_MARKERSET = FACTIONS_ + "markerset"; - - public final static String FACTIONS_HOME = FACTIONS_ + "home"; - public final static String FACTIONS_HOME_ = FACTIONS_HOME + "_"; - - public final static String FACTIONS_PLAYERSET = FACTIONS_ + "playerset"; - public final static String FACTIONS_PLAYERSET_ = FACTIONS_PLAYERSET + "_"; + public static final String FACTIONS = "factions"; + public static final String FACTIONS_ = FACTIONS + "_"; + public static final String FACTIONS_MARKERSET = FACTIONS_ + "markerset"; + public static final String FACTIONS_HOME = FACTIONS_ + "home"; + public static final String FACTIONS_HOME_ = FACTIONS_HOME + "_"; + public static final String FACTIONS_PLAYERSET = FACTIONS_ + "playerset"; + public static final String FACTIONS_PLAYERSET_ = FACTIONS_PLAYERSET + "_"; // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -277,13 +274,13 @@ public class EngineDynmap { String world = entry.getKey().getWorldName(); Faction chunkOwner = Factions.getInstance().getFactionById(entry.getValue()); - Map> factionChunks = worldFactionChunks.get(world); + Map> factionChunks = worldFactionChunks.computeIfAbsent(world, s -> null); if (factionChunks == null) { factionChunks = new HashMap<>(); worldFactionChunks.put(world, factionChunks); } - Set factionTerritory = factionChunks.get(chunkOwner); + Set factionTerritory = factionChunks.computeIfAbsent(chunkOwner, s -> null); if (factionTerritory == null) { factionTerritory = new HashSet<>(); factionChunks.put(chunkOwner, factionTerritory); @@ -735,8 +732,7 @@ public class EngineDynmap { } // Find all contiguous blocks, set in target and clear in source - private int floodFillTarget(TileFlags source, TileFlags destination, int x, int y) { - int cnt = 0; + private void floodFillTarget(TileFlags source, TileFlags destination, int x, int y) { ArrayDeque stack = new ArrayDeque<>(); stack.push(new int[]{x, y}); @@ -747,7 +743,6 @@ public class EngineDynmap { if (source.getFlag(x, y)) { // Set in src source.setFlag(x, y, false); // Clear source destination.setFlag(x, y, true); // Set in destination - cnt++; if (source.getFlag(x + 1, y)) { stack.push(new int[]{x + 1, y}); } @@ -762,7 +757,6 @@ public class EngineDynmap { } } } - return cnt; } enum Direction { diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/TempMarkerSet.java b/src/main/java/com/massivecraft/factions/integration/dynmap/TempMarkerSet.java index 887c7363..50c5241a 100644 --- a/src/main/java/com/massivecraft/factions/integration/dynmap/TempMarkerSet.java +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/TempMarkerSet.java @@ -15,7 +15,7 @@ public class TempMarkerSet { public boolean hideByDefault; public MarkerSet create(MarkerAPI markerApi, String id) { - MarkerSet ret = markerApi.createMarkerSet(id, this.label, null, false); // ("null, false" at the end means "all icons allowed, not perisistent") + MarkerSet ret = markerApi.createMarkerSet(id, this.label, null, false); // ("null, false" at the end means "all icons allowed, not persistent") if (ret == null) { return null; @@ -41,10 +41,8 @@ public class TempMarkerSet { markerset.setMarkerSetLabel(this.label); } - if (this.minimumZoom > 0) { - if (markerset.getMinZoom() != this.minimumZoom) { + if (this.minimumZoom > 0 && markerset.getMinZoom() != this.minimumZoom) { markerset.setMinZoom(this.minimumZoom); - } } if (markerset.getLayerPriority() != this.priority) { diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index 42178e29..ec38c559 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -47,6 +47,8 @@ public class FactionsBlockListener implements Listener { public static HashMap bannerLocations = new HashMap<>(); private HashMap bannerCooldownMap = new HashMap<>(); private long placeTimer = TimeUnit.SECONDS.toMillis(15L); + private static final String varFac = "{faction}"; + private static final String varAction = "{action}"; public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) { @@ -61,9 +63,8 @@ public class FactionsBlockListener implements Listener { if (otherFaction.isWilderness()) { if (Conf.worldGuardBuildPriority && Worldguard.getInstance().playerCanBuild(player, location)) return true; - if (location.getWorld() != null) { - if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) - return true; + if (location.getWorld() != null && !Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) { + return true; } if (!justCheck) me.msg(TL.ACTION_DENIED_WILDERNESS, action); return false; @@ -93,24 +94,27 @@ public class FactionsBlockListener implements Listener { boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId()))) return true; - else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { - me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); - if (shouldHurt) { - player.damage(Conf.actionDeniedPainAmount); - me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); - } - return false; - } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway - if (shouldHurt) { - player.damage(Conf.actionDeniedPainAmount); - if ((Board.getInstance().getFactionAt(loc).getTag(myFaction)) != null) - me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); - } - if (myFaction.getTag(me.getFaction()) != null && action != null) - me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); - return false; - } else if (access == Access.ALLOW) return true; - me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); + else { + String replace = TL.ACTIONS_NOPERMISSIONPAIN.toString().replace(varAction, action.toString()); + if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { + me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); + if (shouldHurt) { + player.damage(Conf.actionDeniedPainAmount); + me.msg(replace.replace(varFac, Board.getInstance().getFactionAt(loc).getTag(myFaction))); + } + return false; + } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway + if (shouldHurt) { + player.damage(Conf.actionDeniedPainAmount); + if ((Board.getInstance().getFactionAt(loc).getTag(myFaction)) != null) + me.msg(replace.replace(varFac, Board.getInstance().getFactionAt(loc).getTag(myFaction))); + } + if (myFaction.getTag(me.getFaction()) != null && action != null) + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace(varFac, myFaction.getTag(me.getFaction())).replace(varAction, action.toString())); + return false; + } else if (access == Access.ALLOW) return true; + } + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace(varFac, myFaction.getTag(me.getFaction())).replace(varAction, action.toString())); return false; } @@ -118,10 +122,10 @@ public class FactionsBlockListener implements Listener { if (Conf.ownedAreasEnabled && target.doesLocationHaveOwnersSet(location) && !target.playerHasOwnershipRights(me, location)) { // If pain should be applied if (pain && Conf.ownedAreaPainBuild) - me.msg(TL.ACTIONS_OWNEDTERRITORYPAINDENY.toString().replace("{action}", action.toString()).replace("{faction}", target.getOwnerListString(location))); + me.msg(TL.ACTIONS_OWNEDTERRITORYPAINDENY.toString().replace(varAction, action.toString()).replace(varFac, target.getOwnerListString(location))); if (Conf.ownedAreaDenyBuild && pain) return false; else if (Conf.ownedAreaDenyBuild) { - me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", target.getTag(me.getFaction())).replace("{action}", action.toString())); + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace(varFac, target.getTag(me.getFaction())).replace(varAction, action.toString())); return false; } } @@ -168,11 +172,9 @@ public class FactionsBlockListener implements Listener { return; } - if (isSpawner) { - if (Conf.spawnerLock) { - event.setCancelled(true); - event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString())); - } + if (isSpawner && Conf.spawnerLock) { + event.setCancelled(true); + event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString())); } } @@ -180,23 +182,21 @@ public class FactionsBlockListener implements Listener { public void onBlockFromTo(BlockFromToEvent event) { if (!Conf.handleExploitLiquidFlow) return; - if (event.getBlock().isLiquid()) { - if (event.getToBlock().isEmpty()) { - Faction from = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); - Faction to = Board.getInstance().getFactionAt(new FLocation(event.getToBlock())); - if (from == to) return; - // from faction != to faction - if(to.isSystemFaction()) { - event.setCancelled(true); + if (event.getBlock().isLiquid() && event.getToBlock().isEmpty()) { + Faction from = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); + Faction to = Board.getInstance().getFactionAt(new FLocation(event.getToBlock())); + if (from == to) return; + // from faction != to faction + if (to.isSystemFaction()) { + event.setCancelled(true); + return; + } + + if (to.isNormal()) { + if (from.isNormal() && from.getRelationTo(to).isAlly()) { return; } - - if (to.isNormal()) { - if (from.isNormal() && from.getRelationTo(to).isAlly()) { - return; - } - event.setCancelled(true); - } + event.setCancelled(true); } } } @@ -217,7 +217,7 @@ public class FactionsBlockListener implements Listener { Block targetBlock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1); // if potentially pushing into air/water/lava in another territory, we need to check it out - if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && !canPistonMoveBlock(pistonFaction, targetBlock.getLocation())) + if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && canPistonMoveBlock(pistonFaction, targetBlock.getLocation())) event.setCancelled(true); } @@ -286,12 +286,10 @@ public class FactionsBlockListener implements Listener { continue; } - if (blockLoc.getBlock().getType() == XMaterial.CHEST.parseMaterial()) { - if (factionAt.getVault().equals(blockLoc)) { - e.setCancelled(true); - fme.msg(TL.COMMAND_VAULT_NO_HOPPER); - return; - } + if (blockLoc.getBlock().getType() == XMaterial.CHEST.parseMaterial() && factionAt.getVault().equals(blockLoc)) { + e.setCancelled(true); + fme.msg(TL.COMMAND_VAULT_NO_HOPPER); + return; } } } @@ -316,7 +314,7 @@ public class FactionsBlockListener implements Listener { // if potentially retracted block is just air/water/lava, no worries if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) return; Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); - if (!canPistonMoveBlock(pistonFaction, targetLoc)) event.setCancelled(true); + if (canPistonMoveBlock(pistonFaction, targetLoc)) event.setCancelled(true); } @EventHandler @@ -326,11 +324,9 @@ public class FactionsBlockListener implements Listener { return; } - if (bannerLocations.containsValue(e.getBlock().getLocation())) { - if (e.getBlock().getType().name().contains("BANNER")) { - e.setCancelled(true); - fme.msg(TL.BANNER_CANNOT_BREAK); - } + if (bannerLocations.containsValue(e.getBlock().getLocation()) && e.getBlock().getType().name().contains("BANNER")) { + e.setCancelled(true); + fme.msg(TL.BANNER_CANNOT_BREAK); } } @@ -430,7 +426,8 @@ public class FactionsBlockListener implements Listener { if (!justCheck) fPlayer.setLastFrostwalkerMessage(); // Check if they have build permissions here. If not, block this from happening. - if (!playerCanBuildDestroyBlock(player, location, PermissableAction.FROST_WALK.toString(), justCheck)) event.setCancelled(true); + if (!playerCanBuildDestroyBlock(player, location, PermissableAction.FROST_WALK.toString(), justCheck)) + event.setCancelled(true); } @EventHandler @@ -448,15 +445,15 @@ public class FactionsBlockListener implements Listener { private boolean canPistonMoveBlock(Faction pistonFaction, Location target) { Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(target)); - if (pistonFaction == otherFaction) return true; + if (pistonFaction == otherFaction) return false; if (otherFaction.isWilderness()) - return !Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName()); - else if (otherFaction.isSafeZone()) return !Conf.safeZoneDenyBuild; - else if (otherFaction.isWarZone()) return !Conf.warZoneDenyBuild; + return Conf.wildernessDenyBuild && !Conf.worldsNoWildernessProtection.contains(target.getWorld().getName()); + else if (otherFaction.isSafeZone()) return Conf.safeZoneDenyBuild; + else if (otherFaction.isWarZone()) return Conf.warZoneDenyBuild; Relation rel = pistonFaction.getRelationTo(otherFaction); - return !rel.confDenyBuild(otherFaction.hasPlayersOnline()); + return rel.confDenyBuild(otherFaction.hasPlayersOnline()); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -504,15 +501,12 @@ public class FactionsBlockListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) - public void FrameRemove(HangingBreakByEntityEvent event) { + public void frameRemove(HangingBreakByEntityEvent event) { if (event.getRemover() == null) return; - if ((event.getRemover() instanceof Player)) { - if (event.getEntity().getType().equals(EntityType.ITEM_FRAME)) { - Player p = (Player) event.getRemover(); - if (!playerCanBuildDestroyBlock(p, event.getEntity().getLocation(), "destroy", true)) { - event.setCancelled(true); - return; - } + if ((event.getRemover() instanceof Player) && event.getEntity().getType().equals(EntityType.ITEM_FRAME)) { + Player p = (Player) event.getRemover(); + if (!playerCanBuildDestroyBlock(p, event.getEntity().getLocation(), "destroy", true)) { + event.setCancelled(true); } } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java index a966c0a6..a5d9e978 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java @@ -87,7 +87,7 @@ public class FactionsChatListener implements Listener { fplayer.sendMessage("[FCspy] " + myFaction.getTag() + ": " + message); } } - FactionChatHandler.sendMessage(FactionsPlugin.getInstance(), myFaction, me.getPlayer().getUniqueId(), me.getPlayer().getName(), event.getMessage()); + FactionChatHandler.sendMessage(myFaction, me.getPlayer().getUniqueId(), me.getPlayer().getName(), event.getMessage()); event.setCancelled(true); } else if (chat == ChatMode.ALLIANCE) { Faction myFaction = me.getFaction(); diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java index 5f055dbf..158f567a 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -4,7 +4,6 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.event.PowerLossEvent; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.MiscUtil; -import com.massivecraft.factions.util.timer.type.GraceTimer; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -144,7 +143,7 @@ public class FactionsEntityListener implements Listener { } else { // we don't want to let mobs/arrows destroy item frames/armor stands // so we only have to run the check as if there had been an explosion at the damager location - if (!this.checkExplosionForBlock(damager, damagee.getLocation().getBlock())) + if (this.checkExplosionForBlock(damager, damagee.getLocation().getBlock())) event.setCancelled(true); } // we don't need to go after @@ -217,7 +216,7 @@ public class FactionsEntityListener implements Listener { Entity boomer = event.getEntity(); // Before we need to check the location where the block is placed - if (!this.checkExplosionForBlock(boomer, event.getLocation().getBlock())) { + if (this.checkExplosionForBlock(boomer, event.getLocation().getBlock())) { event.setCancelled(true); return; } @@ -225,7 +224,7 @@ public class FactionsEntityListener implements Listener { // Loop the blocklist to run checks on each aimed block // The block don't have to explode - event.blockList().removeIf(block -> !this.checkExplosionForBlock(boomer, block)); + event.blockList().removeIf(block -> this.checkExplosionForBlock(boomer, block)); // Cancel the event if no block will explode if (!event.blockList().isEmpty() && (boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart) && Conf.handleExploitTNTWaterlog) { @@ -260,7 +259,7 @@ public class FactionsEntityListener implements Listener { Faction faction = Board.getInstance().getFactionAt(new FLocation(block.getLocation())); if (faction.noExplosionsInTerritory() || (faction.isPeaceful() && Conf.peacefulTerritoryDisableBoom)) - return false; + return true; // faction is peaceful and has explosions set to disabled boolean online = faction.hasPlayersOnline(); @@ -270,17 +269,17 @@ public class FactionsEntityListener implements Listener { (faction.isWarZone() && Conf.warZoneBlockCreepers) || faction.isSafeZone())) { // creeper which needs prevention - return false; + return true; } else if ( // it's a bit crude just using fireball protection for Wither boss too, but I'd rather not add in a whole new set of xxxBlockWitherExplosion or whatever (boomer instanceof Fireball || boomer instanceof Wither) && (faction.isWilderness() && Conf.wildernessBlockFireballs && !Conf.worldsNoWildernessProtection.contains(block.getWorld().getName()) || faction.isNormal() && (online ? Conf.territoryBlockFireballs : Conf.territoryBlockFireballsWhenOffline) || faction.isWarZone() && Conf.warZoneBlockFireballs || faction.isSafeZone())) { // ghast fireball which needs prevention - return false; + return true; } else - return (!(boomer instanceof TNTPrimed) && !(boomer instanceof ExplosiveMinecart)) || ((!faction.isWilderness() || !Conf.wildernessBlockTNT || Conf.worldsNoWildernessProtection.contains(block.getWorld().getName())) && - (!faction.isNormal() || (online ? !Conf.territoryBlockTNT : !Conf.territoryBlockTNTWhenOffline)) && - (!faction.isWarZone() || !Conf.warZoneBlockTNT) && - (!faction.isSafeZone() || !Conf.safeZoneBlockTNT)); + return (boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart) && ((faction.isWilderness() && Conf.wildernessBlockTNT && !Conf.worldsNoWildernessProtection.contains(block.getWorld().getName())) || + (faction.isNormal() && (online ? Conf.territoryBlockTNT : Conf.territoryBlockTNTWhenOffline)) || + (faction.isWarZone() && Conf.warZoneBlockTNT) || + (faction.isSafeZone() && Conf.safeZoneBlockTNT)); // No condition retained, destroy the block! } @@ -312,7 +311,7 @@ public class FactionsEntityListener implements Listener { if (thrower instanceof Player) { Player player = (Player) thrower; FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - if (badjuju && fPlayer.getFaction().isPeaceful()) { + if (fPlayer.getFaction().isPeaceful()) { event.setCancelled(true); return; } @@ -507,10 +506,8 @@ public class FactionsEntityListener implements Listener { if (!(e.getRemover() instanceof Player)) return; Player p = (Player) e.getRemover(); - if (e.getEntity().getType() == EntityType.PAINTING || e.getEntity().getType() == EntityType.ITEM_FRAME) { - if (!FactionsBlockListener.playerCanBuildDestroyBlock(p, e.getEntity().getLocation(), "destroy", false)) { - e.setCancelled(true); - } + if (e.getEntity().getType() == EntityType.PAINTING || e.getEntity().getType() == EntityType.ITEM_FRAME && !FactionsBlockListener.playerCanBuildDestroyBlock(p, e.getEntity().getLocation(), "destroy", false)) { + e.setCancelled(true); } } @@ -518,11 +515,9 @@ public class FactionsEntityListener implements Listener { public void onPaintingPlace(HangingPlaceEvent e) { if (e.getPlayer() == null) return; - if (e.getEntity().getType() == EntityType.PAINTING || e.getEntity().getType() == EntityType.ITEM_FRAME) { - if (!FactionsBlockListener.playerCanBuildDestroyBlock(e.getPlayer(), e.getBlock().getLocation(), "build", false)) { - e.setCancelled(true); - e.getPlayer().updateInventory(); - } + if (e.getEntity().getType() == EntityType.PAINTING || e.getEntity().getType() == EntityType.ITEM_FRAME && !FactionsBlockListener.playerCanBuildDestroyBlock(e.getPlayer(), e.getBlock().getLocation(), "build", false)) { + e.setCancelled(true); + e.getPlayer().updateInventory(); } } @@ -547,73 +542,37 @@ public class FactionsEntityListener implements Listener { } - /* - @EventHandler - public void onTravel(PlayerPortalEvent event) { - if (!FactionsPlugin.getInstance().getConfig().getBoolean("portals.limit", false)) - return; // Don't do anything if they don't want us to. - - - TravelAgent agent = event.getPortalTravelAgent(); - - // If they aren't able to find a portal, it'll try to create one. - if (event.useTravelAgent() && agent.getCanCreatePortal() && agent.findPortal(event.getTo()) == null) { - FLocation loc = new FLocation(event.getTo()); - Faction faction = Board.getInstance().getFactionAt(loc); - if (faction.isWilderness()) { - return; // We don't care about wilderness. - } else if (!faction.isNormal() && !event.getPlayer().isOp()) { - // Don't let non ops make portals in safezone or warzone. - event.setCancelled(true); - return; - } - - FPlayer fp = FPlayers.getInstance().getByPlayer(event.getPlayer()); - String mininumRelation = FactionsPlugin.getInstance().getConfig().getString("portals.minimum-relation", "MEMBER"); // Defaults to Neutral if typed wrong. - if (!fp.getFaction().getRelationTo(faction).isAtLeast(Relation.fromString(mininumRelation))) { - event.setCancelled(true); - } - } - } - */ - @EventHandler public void onHit(EntityDamageByEntityEvent e) { - if (e.getDamager() instanceof Player) { - if (e.getEntity() instanceof Player) { - Player victim = (Player) e.getEntity(); - Player attacker = (Player) e.getDamager(); - FPlayer fvictim = FPlayers.getInstance().getByPlayer(victim); - FPlayer fattacker = FPlayers.getInstance().getByPlayer(attacker); - if (fattacker.getRelationTo(fvictim) == Relation.TRUCE) { - fattacker.msg(TL.PLAYER_PVP_CANTHURT, fvictim.describeTo(fattacker)); - e.setCancelled(true); - } + if (e.getDamager() instanceof Player && e.getEntity() instanceof Player) { + Player victim = (Player) e.getEntity(); + Player attacker = (Player) e.getDamager(); + FPlayer fvictim = FPlayers.getInstance().getByPlayer(victim); + FPlayer fattacker = FPlayers.getInstance().getByPlayer(attacker); + if (fattacker.getRelationTo(fvictim) == Relation.TRUCE) { + fattacker.msg(TL.PLAYER_PVP_CANTHURT, fvictim.describeTo(fattacker)); + e.setCancelled(true); } } } @EventHandler public void onBowHit(EntityDamageByEntityEvent e) { - if (e.getDamager() instanceof Projectile) { - if (e.getEntity() instanceof Player) { - Projectile arrow = ((Projectile) e.getDamager()); - if (arrow.getShooter() instanceof Player) { - Player damager = (Player) ((Projectile) e.getDamager()).getShooter(); - Player victim = (Player) e.getEntity(); - FPlayer fdamager = FPlayers.getInstance().getByPlayer(damager); - FPlayer fvictim = FPlayers.getInstance().getByPlayer(victim); - if (damager == victim) return; - if (fdamager == fvictim) return; - if (fvictim.getRelationTo(fdamager) == Relation.TRUCE) { - fdamager.msg(TL.PLAYER_PVP_CANTHURT, fvictim.describeTo(fdamager)); - e.setCancelled(true); - } - if (fvictim.getRelationTo(fdamager) == Relation.ENEMY) { - if (fvictim.isFlying()) { - fvictim.setFFlying(false, true); - } - } + if (e.getDamager() instanceof Projectile && e.getEntity() instanceof Player) { + Projectile arrow = ((Projectile) e.getDamager()); + if (arrow.getShooter() instanceof Player) { + Player damager = (Player) ((Projectile) e.getDamager()).getShooter(); + Player victim = (Player) e.getEntity(); + FPlayer fdamager = FPlayers.getInstance().getByPlayer(damager); + FPlayer fvictim = FPlayers.getInstance().getByPlayer(victim); + if (damager == victim) return; + if (fdamager == fvictim) return; + if (fvictim.getRelationTo(fdamager) == Relation.TRUCE) { + fdamager.msg(TL.PLAYER_PVP_CANTHURT, fvictim.describeTo(fdamager)); + e.setCancelled(true); + } + if (fvictim.getRelationTo(fdamager) == Relation.ENEMY && fvictim.isFlying()) { + fvictim.setFFlying(false, true); } } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index bbd81f8e..1ca18115 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -4,7 +4,6 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.cmd.CmdFGlobal; import com.massivecraft.factions.cmd.CmdFly; import com.massivecraft.factions.cmd.CmdSeeChunk; -import com.massivecraft.factions.cmd.FCmdRoot; import com.massivecraft.factions.cmd.audit.FLogType; import com.massivecraft.factions.cmd.logout.LogoutHandler; import com.massivecraft.factions.cmd.wild.CmdWild; @@ -36,8 +35,6 @@ import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.TextChannel; import org.bukkit.*; import org.bukkit.block.Block; -import org.bukkit.entity.Boat; -import org.bukkit.entity.Minecart; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; @@ -191,7 +188,6 @@ public class FactionsPlayerListener implements Listener { FLocation loc = new FLocation(block); Faction otherFaction = Board.getInstance().getFactionAt(loc); Faction myFaction = me.getFaction(); - Relation rel = myFaction.getRelationTo(otherFaction); // no door/chest/whatever protection in wilderness, war zones, or safe zones if (otherFaction.isSystemFaction()) return true; @@ -522,13 +518,11 @@ public class FactionsPlayerListener implements Listener { @EventHandler public void onPlayerFall(EntityDamageEvent e) { - if (e.getEntity() instanceof Player) { - if (e.getCause() == EntityDamageEvent.DamageCause.FALL) { - Player player = (Player) e.getEntity(); - if (fallMap.containsKey(player)) { - e.setCancelled(true); - fallMap.remove(player); - } + if (e.getEntity() instanceof Player && e.getCause() == EntityDamageEvent.DamageCause.FALL) { + Player player = (Player) e.getEntity(); + if (fallMap.containsKey(player)) { + e.setCancelled(true); + fallMap.remove(player); } } } @@ -616,7 +610,7 @@ public class FactionsPlayerListener implements Listener { fplayer.msg(TL.COMMAND_INSPECT_BYPASS); } List info = CoreProtect.getInstance().getAPI().blockLookup(e.getClickedBlock(), 0); - if (info.size() == 0) { + if (info.isEmpty()) { e.getPlayer().sendMessage(TL.COMMAND_INSPECT_NODATA.toString()); return; } @@ -656,7 +650,7 @@ public class FactionsPlayerListener implements Listener { } public static BukkitTask positionTask = null; - public final static Map lastLocations = new HashMap<>(); + public final Map lastLocations = new HashMap<>(); public void startPositionCheck() { positionTask = Bukkit.getScheduler().runTaskTimer(FactionsPlugin.getInstance(), () -> { @@ -830,18 +824,14 @@ public class FactionsPlayerListener implements Listener { // Do type null checks so if XMaterial has a parsing issue and fills null as a value it will not bypass. // territoryCancelAndAllowItemUseMaterial bypass the protection system but only if they're not clicking on territoryDenySwitchMaterials // if they're clicking on territoryDenySwitchMaterials, let the protection system handle the permissions - if (type != null && !Conf.territoryDenySwitchMaterials.contains(block.getType())) { - if (Conf.territoryCancelAndAllowItemUseMaterial.contains(type)) { - return; - } + if (type != null && !Conf.territoryDenySwitchMaterials.contains(block.getType()) && Conf.territoryCancelAndAllowItemUseMaterial.contains(type)) { + return; } - if (GetPermissionFromUsableBlock(block.getType()) != null) { - if (!canPlayerUseBlock(player, block, false)) { - event.setCancelled(true); - event.setUseInteractedBlock(Event.Result.DENY); - return; - } + if (GetPermissionFromUsableBlock(block.getType()) != null && !canPlayerUseBlock(player, block, false)) { + event.setCancelled(true); + event.setUseInteractedBlock(Event.Result.DENY); + return; } if (type != null && !playerCanUseItemHere(player, block.getLocation(), event.getItem().getType(), false, PermissableAction.ITEM)) { @@ -862,14 +852,13 @@ public class FactionsPlayerListener implements Listener { public void onPlayerBoneMeal(PlayerInteractEvent event) { Block block = event.getClickedBlock(); if (event.getAction() == Action.RIGHT_CLICK_BLOCK && block.getType() == XMaterial.GRASS_BLOCK.parseMaterial() - && event.hasItem() && event.getItem().getType() == XMaterial.BONE_MEAL.parseMaterial()) { - if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), block.getLocation(), PermissableAction.BUILD.name(), true)) { - FPlayer me = FPlayers.getInstance().getById(event.getPlayer().getUniqueId().toString()); - Faction myFaction = me.getFaction(); + && event.hasItem() && event.getItem().getType() == XMaterial.BONE_MEAL.parseMaterial() + && !FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), block.getLocation(), PermissableAction.BUILD.name(), true)) { + FPlayer me = FPlayers.getInstance().getById(event.getPlayer().getUniqueId().toString()); + Faction myFaction = me.getFaction(); - me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", "use bone meal")); - event.setCancelled(true); - } + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", "use bone meal")); + event.setCancelled(true); } } @@ -937,10 +926,8 @@ public class FactionsPlayerListener implements Listener { player.sendMessage(String.valueOf(TL.COMMAND_LOGOUT_DAMAGE_TAKEN)); } WaitExecutor.handleAction(player); - if (CmdWild.teleporting.contains(player)) { - if (!FactionsPlugin.getInstance().getConfig().getBoolean("Wild.FallDamage") && e.getCause() == EntityDamageEvent.DamageCause.FALL) { - e.setCancelled(true); - } + if (CmdWild.teleporting.contains(player) && !FactionsPlugin.getInstance().getConfig().getBoolean("Wild.FallDamage") && e.getCause() == EntityDamageEvent.DamageCause.FALL) { + e.setCancelled(true); } } } @@ -949,7 +936,6 @@ public class FactionsPlayerListener implements Listener { public void onTeleport(PlayerTeleportEvent e) { Player player = e.getPlayer(); - if (player == null) return; LogoutHandler handler = LogoutHandler.getByName(player.getName()); if (handler.isLogoutActive(player)) { handler.cancelLogout(player); @@ -987,7 +973,7 @@ public class FactionsPlayerListener implements Listener { } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - final public void onFactionJoin(FPlayerJoinEvent event) { + final void onFactionJoin(FPlayerJoinEvent event) { FTeamWrapper.applyUpdatesLater(event.getFaction()); } @@ -1001,7 +987,7 @@ public class FactionsPlayerListener implements Listener { } @EventHandler - public void AsyncPlayerChatEvent(AsyncPlayerChatEvent e) { + public void asyncPlayerChatEvent(AsyncPlayerChatEvent e) { Player p = e.getPlayer(); if (CmdFGlobal.toggled.contains(p.getUniqueId())) { @@ -1027,10 +1013,8 @@ public class FactionsPlayerListener implements Listener { for (int i = l.size() - 1; i >= 0; i--) { // going backwards in the list to prevent a ConcurrentModificationException Player recipient = l.get(i); - if (recipient != null) { - if (CmdFGlobal.toggled.contains(recipient.getUniqueId())) { - e.getRecipients().remove(recipient); - } + if (recipient != null && CmdFGlobal.toggled.contains(recipient.getUniqueId())) { + e.getRecipients().remove(recipient); } } } diff --git a/src/main/java/com/massivecraft/factions/listeners/MenuListener.java b/src/main/java/com/massivecraft/factions/listeners/MenuListener.java index be98f033..e4c42f26 100644 --- a/src/main/java/com/massivecraft/factions/listeners/MenuListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/MenuListener.java @@ -15,9 +15,6 @@ import org.bukkit.inventory.ItemStack; */ public class MenuListener implements Listener { - public MenuListener() { - } - @EventHandler public void onInventoryClick(InventoryClickEvent event) { if (event.getView().getTitle().equals("Faction Logs")) { diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java b/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java index 4df3269e..feed9f94 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java @@ -137,7 +137,7 @@ public class FScoreboard { updateObjective(); } } - }.runTaskLater(FactionsPlugin.getInstance(), FactionsPlugin.getInstance().getConfig().getInt("scoreboard.expiration", 7) * 20); + }.runTaskLater(FactionsPlugin.getInstance(), FactionsPlugin.getInstance().getConfig().getInt("scoreboard.expiration", 7) * 20L); } private void updateObjective() { diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java b/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java index 98996e85..169302ad 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java @@ -25,6 +25,8 @@ public class FTeamWrapper { private final String teamName; private final Faction faction; private final Set members = new HashSet<>(); + private static final String defaultPrefixes = "scoreboard.default-prefixes"; + private static final String invisFactionMembers = "See-Invisible-Faction-Members"; private FTeamWrapper(Faction faction) { this.teamName = "faction_" + (factionTeamPtr++); @@ -44,7 +46,7 @@ public class FTeamWrapper { return; } - if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false) || FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members")) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean(defaultPrefixes, false) || FactionsPlugin.getInstance().getConfig().getBoolean(invisFactionMembers)) { return; } @@ -66,7 +68,7 @@ public class FTeamWrapper { return; } - if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false) || FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members")) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean(defaultPrefixes, false) || FactionsPlugin.getInstance().getConfig().getBoolean(invisFactionMembers)) { return; } @@ -158,7 +160,7 @@ public class FTeamWrapper { } private void updatePrefixes() { - if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) { + if (FactionsPlugin.getInstance().getConfig().getBoolean(defaultPrefixes, false)) { for (FScoreboard fboard : teams.keySet()) { updatePrefix(fboard); } @@ -166,19 +168,19 @@ public class FTeamWrapper { } private void updatePrefix(FScoreboard fboard) { - if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) { + if (FactionsPlugin.getInstance().getConfig().getBoolean(defaultPrefixes, false)) { FPlayer fplayer = fboard.getFPlayer(); Team team = teams.get(fboard); boolean focused = false; - if (FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members", false)) { + if (FactionsPlugin.getInstance().getConfig().getBoolean(invisFactionMembers, false)) { team.setCanSeeFriendlyInvisibles(true); } if ((FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled")) && (fplayer.getFaction() != null) && (fplayer.getFaction().getFocused() != null)) { for (FPlayer fp : faction.getFPlayersWhereOnline(true)) { if (fplayer.getFaction().getFocused().equalsIgnoreCase(fp.getName())) { - team.setPrefix(ChatColor.translateAlternateColorCodes('&', FactionsPlugin.getInstance().getConfig().getString("ffocus.Prefix", "&7»&b"))); + team.setPrefix(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(FactionsPlugin.getInstance().getConfig().getString("ffocus.Prefix", "&7»&b")))); focused = true; } } @@ -191,7 +193,8 @@ public class FTeamWrapper { prefix = prefix.replace("{relationcolor}", faction.getRelationTo(fplayer).getColor().toString()); prefix = prefix.replace("{faction}", faction.getTag().substring(0, Math.min("{faction}".length() + 16 - prefix.length(), faction.getTag().length()))); - if ((team.getPrefix() == null) || (!team.getPrefix().equals(prefix))) { + team.getPrefix(); + if (!team.getPrefix().equals(prefix)) { team.setPrefix(prefix); } } diff --git a/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java b/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java index 5f7667c4..cf952c03 100644 --- a/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java +++ b/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java @@ -45,12 +45,13 @@ public class ShopGUIFrame { int items = FactionsPlugin.getInstance().getFileManager().getShop().getConfig().getConfigurationSection("items").getKeys(false).size(); for (int a = 1; a <= items; a++) { String s = a + ""; - int slot = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".slot"); - ItemStack item = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".block")).get().parseItem(); - int cost = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".cost"); - String name = FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".name"); - boolean glowing = FactionsPlugin.getInstance().getFileManager().getShop().fetchBoolean("items." + s + ".glowing"); - List lore = FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".lore"); + String varItems = "items."; + int slot = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt(varItems + s + ".slot"); + ItemStack item = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getFileManager().getShop().fetchString(varItems + s + ".block")).get().parseItem(); + int cost = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt(varItems + s + ".cost"); + String name = FactionsPlugin.getInstance().getFileManager().getShop().fetchString(varItems + s + ".name"); + boolean glowing = FactionsPlugin.getInstance().getFileManager().getShop().fetchBoolean(varItems + s + ".glowing"); + List lore = FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList(varItems + s + ".lore"); assert item != null; diff --git a/src/main/java/com/massivecraft/factions/struct/Role.java b/src/main/java/com/massivecraft/factions/struct/Role.java index ed7910e2..31202cb5 100644 --- a/src/main/java/com/massivecraft/factions/struct/Role.java +++ b/src/main/java/com/massivecraft/factions/struct/Role.java @@ -55,9 +55,9 @@ public enum Role implements Permissable { return COLEADER; case 4: return LEADER; + default: + throw new IllegalStateException("Unexpected value: " + value); } - - return null; } public static Role fromString(String check) { @@ -76,9 +76,9 @@ public enum Role implements Permissable { case "recruit": case "rec": return RECRUIT; + default: + throw new IllegalStateException("Unexpected value: " + check.toLowerCase()); } - - return null; } public boolean isAtLeast(Role role) { diff --git a/src/main/java/com/massivecraft/factions/tag/FactionTag.java b/src/main/java/com/massivecraft/factions/tag/FactionTag.java index c799e47b..7343a7ef 100644 --- a/src/main/java/com/massivecraft/factions/tag/FactionTag.java +++ b/src/main/java/com/massivecraft/factions/tag/FactionTag.java @@ -17,27 +17,27 @@ public enum FactionTag implements Tag { * @author FactionsUUID Team */ - HOME_X("{x}", (fac) -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockX()) : Tag.isMinimalShow() ? null : "{ig}"), - HOME_Y("{y}", (fac) -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockY()) : Tag.isMinimalShow() ? null : "{ig}"), - HOME_Z("{z}", (fac) -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockZ()) : Tag.isMinimalShow() ? null : "{ig}"), - CHUNKS("{chunks}", (fac) -> String.valueOf(fac.getLandRounded())), - WARPS("{warps}", (fac) -> String.valueOf(fac.getWarps().size())), + HOME_X("{x}", fac -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockX()) : Tag.isMinimalShow() ? null : "{ig}"), + HOME_Y("{y}", fac -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockY()) : Tag.isMinimalShow() ? null : "{ig}"), + HOME_Z("{z}", fac -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockZ()) : Tag.isMinimalShow() ? null : "{ig}"), + CHUNKS("{chunks}", fac -> String.valueOf(fac.getLandRounded())), + WARPS("{warps}", fac -> String.valueOf(fac.getWarps().size())), HEADER("{header}", (fac, fp) -> FactionsPlugin.getInstance().txt.titleize(fac.getTag(fp))), - POWER("{power}", (fac) -> String.valueOf(fac.getPowerRounded())), - MAX_POWER("{maxPower}", (fac) -> String.valueOf(fac.getPowerMaxRounded())), - POWER_BOOST("{power-boost}", (fac) -> { + POWER("{power}", fac -> String.valueOf(fac.getPowerRounded())), + MAX_POWER("{maxPower}", fac -> String.valueOf(fac.getPowerMaxRounded())), + POWER_BOOST("{power-boost}", fac -> { double powerBoost = fac.getPowerBoost(); return (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString() + powerBoost + ")"); }), - LEADER("{leader}", (fac) -> { + LEADER("{leader}", fac -> { FPlayer fAdmin = fac.getFPlayerAdmin(); return fAdmin == null ? "Server" : fAdmin.getName().substring(0, fAdmin.getName().length() > 14 ? 13 : fAdmin.getName().length()); }), - JOINING("{joining}", (fac) -> (fac.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString())), + JOINING("{joining}", fac -> (fac.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString())), FACTION("{faction}", (Function) Faction::getTag), FACTION_RELATION_COLOR("{faction-relation-color}", (fac, fp) -> fp == null ? "" : fp.getColorTo(fac).toString()), - HOME_WORLD("{world}", (fac) -> fac.hasHome() ? fac.getHome().getWorld().getName() : Tag.isMinimalShow() ? null : "{ig}"), - RAIDABLE("{raidable}", (fac) -> { + HOME_WORLD("{world}", fac -> fac.hasHome() ? fac.getHome().getWorld().getName() : Tag.isMinimalShow() ? null : "{ig}"), + RAIDABLE("{raidable}", fac -> { if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false)) { boolean raidable = fac.getLandRounded() >= fac.getPowerRounded(); String str = raidable ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString(); @@ -50,37 +50,35 @@ public enum FactionTag implements Tag { return null; }), - ANNOUNCEMENT("{announcement}", (fac) -> { - return String.valueOf(fac.getAnnouncements()); - }), - PEACEFUL("{peaceful}", (fac) -> fac.isPeaceful() ? Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString() : ""), - PERMANENT("permanent", (fac) -> fac.isPermanent() ? "permanent" : "{notPermanent}"), // no braces needed - LAND_VALUE("{land-value}", (fac) -> Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(fac.getLandRounded())) : Tag.isMinimalShow() ? null : TL.ECON_OFF.format("value")), + ANNOUNCEMENT("{announcement}", fac -> String.valueOf(fac.getAnnouncements())), + PEACEFUL("{peaceful}", fac -> fac.isPeaceful() ? Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString() : ""), + PERMANENT("permanent", fac -> fac.isPermanent() ? "permanent" : "{notPermanent}"), // no braces needed + LAND_VALUE("{land-value}", fac -> Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(fac.getLandRounded())) : Tag.isMinimalShow() ? null : TL.ECON_OFF.format("value")), DESCRIPTION("{description}", Faction::getDescription), - CREATE_DATE("{create-date}", (fac) -> TL.sdf.format(fac.getFoundedDate())), - LAND_REFUND("{land-refund}", (fac) -> Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(fac.getLandRounded())) : Tag.isMinimalShow() ? null : TL.ECON_OFF.format("refund")), - BANK_BALANCE("{faction-balance}", (fac) -> { + CREATE_DATE("{create-date}", fac -> TL.sdf.format(fac.getFoundedDate())), + LAND_REFUND("{land-refund}", fac -> Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(fac.getLandRounded())) : Tag.isMinimalShow() ? null : TL.ECON_OFF.format("refund")), + BANK_BALANCE("{faction-balance}", fac -> { if (Econ.shouldBeUsed()) { return Conf.bankEnabled ? Econ.moneyString(Econ.getBalance(fac.getAccountId())) : Tag.isMinimalShow() ? null : TL.ECON_OFF.format("balance"); } return Tag.isMinimalShow() ? null : TL.ECON_OFF.format("balance"); }), - TNT_BALANCE("{tnt-balance}", (fac) -> { + TNT_BALANCE("{tnt-balance}", fac -> { if (FactionsPlugin.instance.getConfig().getBoolean("ftnt.Enabled")) { return String.valueOf(fac.getTnt()); } return Tag.isMinimalShow() ? null : ""; }), - TNT_MAX("{tnt-max-balance}", (fac) -> { + TNT_MAX("{tnt-max-balance}", fac -> { if (FactionsPlugin.instance.getConfig().getBoolean("ftnt.Enabled")) { return String.valueOf(fac.getTntBankLimit()); } return Tag.isMinimalShow() ? null : ""; }), - ALLIES_COUNT("{allies}", (fac) -> String.valueOf(fac.getRelationCount(Relation.ALLY))), - ENEMIES_COUNT("{enemies}", (fac) -> String.valueOf(fac.getRelationCount(Relation.ENEMY))), - TRUCES_COUNT("{truces}", (fac) -> String.valueOf(fac.getRelationCount(Relation.TRUCE))), + ALLIES_COUNT("{allies}", fac -> String.valueOf(fac.getRelationCount(Relation.ALLY))), + ENEMIES_COUNT("{enemies}", fac -> String.valueOf(fac.getRelationCount(Relation.ENEMY))), + TRUCES_COUNT("{truces}", fac -> String.valueOf(fac.getRelationCount(Relation.TRUCE))), ONLINE_COUNT("{online}", (fac, fp) -> { if (fp != null && fp.isOnline()) { return String.valueOf(fac.getFPlayersWhereOnline(true, fp).size()); @@ -97,12 +95,12 @@ public enum FactionTag implements Tag { return String.valueOf(fac.getFPlayersWhereOnline(false).size()); } }), - FACTION_STRIKES("{faction-strikes}", (fac) -> String.valueOf(fac.getStrikes())), - FACTION_POINTS("{faction-points}", (fac) -> String.valueOf(fac.getPoints())), - FACTION_SIZE("{members}", (fac) -> String.valueOf(fac.getFPlayers().size())), - FACTION_KILLS("{faction-kills}", (fac) -> String.valueOf(fac.getKills())), - FACTION_DEATHS("{faction-deaths}", (fac) -> String.valueOf(fac.getDeaths())), - FACTION_BANCOUNT("{faction-bancount}", (fac) -> String.valueOf(fac.getBannedPlayers().size())), + FACTION_STRIKES("{faction-strikes}", fac -> String.valueOf(fac.getStrikes())), + FACTION_POINTS("{faction-points}", fac -> String.valueOf(fac.getPoints())), + FACTION_SIZE("{members}", fac -> String.valueOf(fac.getFPlayers().size())), + FACTION_KILLS("{faction-kills}", fac -> String.valueOf(fac.getKills())), + FACTION_DEATHS("{faction-deaths}", fac -> String.valueOf(fac.getDeaths())), + FACTION_BANCOUNT("{faction-bancount}", fac -> String.valueOf(fac.getBannedPlayers().size())), ; private final String tag; diff --git a/src/main/java/com/massivecraft/factions/tag/FancyTag.java b/src/main/java/com/massivecraft/factions/tag/FancyTag.java index d8f70f7e..4012fbf8 100644 --- a/src/main/java/com/massivecraft/factions/tag/FancyTag.java +++ b/src/main/java/com/massivecraft/factions/tag/FancyTag.java @@ -177,7 +177,7 @@ public enum FancyTag implements Tag { public List getMessage(String text, Faction faction, FPlayer player, Map groupMap) { if (!this.foundInString(text)) { - return Collections.EMPTY_LIST; // We really, really shouldn't be here. + return Collections.emptyList(); // We really, really shouldn't be here. } return this.function.apply(faction, player, text.replace(this.getTag(), ""), groupMap); } diff --git a/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java b/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java index 33ca2fd2..34e03985 100644 --- a/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java +++ b/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java @@ -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 iterator; private transient double toleranceMillis; diff --git a/src/main/java/com/massivecraft/factions/util/Cooldown.java b/src/main/java/com/massivecraft/factions/util/Cooldown.java index c9011fd3..9021e38c 100644 --- a/src/main/java/com/massivecraft/factions/util/Cooldown.java +++ b/src/main/java/com/massivecraft/factions/util/Cooldown.java @@ -19,7 +19,7 @@ public class Cooldown { } public static boolean isOnCooldown(Player player, String name) { - if (!player.hasMetadata(name) || player.getMetadata(name).size() <= 0) return false; + if (!player.hasMetadata(name) || player.getMetadata(name).isEmpty()) return false; long time = player.getMetadata(name).get(0).asLong(); return (time > System.currentTimeMillis()); } diff --git a/src/main/java/com/massivecraft/factions/util/InventoryUtil.java b/src/main/java/com/massivecraft/factions/util/InventoryUtil.java index ef9ad2b3..a26e0be0 100644 --- a/src/main/java/com/massivecraft/factions/util/InventoryUtil.java +++ b/src/main/java/com/massivecraft/factions/util/InventoryUtil.java @@ -15,7 +15,7 @@ import java.io.IOException; public class InventoryUtil { - public static String InventoryToString(ItemStack[] items) throws IllegalStateException { + public static String InventoryToString(ItemStack[] items) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); diff --git a/src/main/java/com/massivecraft/factions/util/MiscUtil.java b/src/main/java/com/massivecraft/factions/util/MiscUtil.java index 736d479e..dfa17a15 100644 --- a/src/main/java/com/massivecraft/factions/util/MiscUtil.java +++ b/src/main/java/com/massivecraft/factions/util/MiscUtil.java @@ -109,8 +109,6 @@ public class MiscUtil { switch (player.getRole()) { case LEADER: - admins.add(player); - break; case COLEADER: admins.add(player); break; diff --git a/src/main/java/com/massivecraft/factions/util/RelationUtil.java b/src/main/java/com/massivecraft/factions/util/RelationUtil.java index 4c656f84..f78703bf 100644 --- a/src/main/java/com/massivecraft/factions/util/RelationUtil.java +++ b/src/main/java/com/massivecraft/factions/util/RelationUtil.java @@ -20,8 +20,6 @@ public class RelationUtil { } Faction myFaction = getFaction(me); -// if (myFaction == null) return that.describeTo(null); // no relation, but can show basic name or tag - if (that instanceof Faction) { if (me instanceof FPlayer && myFaction == thatFaction) { ret = TL.GENERIC_YOURFACTION.toString(); diff --git a/src/main/java/com/massivecraft/factions/util/SpiralTask.java b/src/main/java/com/massivecraft/factions/util/SpiralTask.java index 2733a423..9bc7e889 100644 --- a/src/main/java/com/massivecraft/factions/util/SpiralTask.java +++ b/src/main/java/com/massivecraft/factions/util/SpiralTask.java @@ -187,7 +187,6 @@ public abstract class SpiralTask implements Runnable { // for successful completion public void finish() { -// FactionsPlugin.getInstance().log("SpiralTask successfully completed!"); this.stop(); } diff --git a/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java b/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java index 54825151..6c823706 100644 --- a/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java +++ b/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java @@ -16,8 +16,7 @@ public class VisualizeUtil { } public static Set getPlayerLocations(UUID uuid) { - Set ret = playerLocations.computeIfAbsent(uuid, k -> new HashSet<>()); - return ret; + return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>()); } @SuppressWarnings("deprecation") diff --git a/src/main/java/com/massivecraft/factions/util/timer/TimerRunnable.java b/src/main/java/com/massivecraft/factions/util/timer/TimerRunnable.java index af426821..f0a7f5fd 100644 --- a/src/main/java/com/massivecraft/factions/util/timer/TimerRunnable.java +++ b/src/main/java/com/massivecraft/factions/util/timer/TimerRunnable.java @@ -25,13 +25,6 @@ public class TimerRunnable { } - public TimerRunnable(UUID playerUUID, Timer timer, long duration) { - this.timer = timer; - setRemaining(duration); - FactionsPlugin plugin = FactionsPlugin.getInstance(); - plugin.getTimerManager().getTimerRunnableList().add(this); - } - public boolean isCancelled() { return cancelled; } diff --git a/src/main/java/com/massivecraft/factions/util/timer/type/GraceTimer.java b/src/main/java/com/massivecraft/factions/util/timer/type/GraceTimer.java index f5a740df..042ce6ff 100644 --- a/src/main/java/com/massivecraft/factions/util/timer/type/GraceTimer.java +++ b/src/main/java/com/massivecraft/factions/util/timer/type/GraceTimer.java @@ -26,22 +26,20 @@ public class GraceTimer extends GlobalTimer implements Listener { @EventHandler public void onBreak(EntityExplodeEvent e) { - if(getRemaining() > 0) - e.setCancelled(true); + if (getRemaining() > 0) { + e.setCancelled(true); + } } @EventHandler public void onTNTPlace(BlockPlaceEvent event) { FPlayer fp = FPlayers.getInstance().getByPlayer(event.getPlayer()); - if(getRemaining() > 0) { - if (!fp.isAdminBypassing()) { - if (event.getBlock().getType().equals(Material.TNT)) { - event.setCancelled(true); - } - } + if (getRemaining() > 0 && !fp.isAdminBypassing() && event.getBlock().getType().equals(Material.TNT)) { + event.setCancelled(true); } } + @Override public void load(Config config) { setPaused(config.getBoolean(this.name + ".paused"));