From ba86f289944e967aa0c3898aa15d4205f3ea1930 Mon Sep 17 00:00:00 2001 From: AigleDev Date: Thu, 12 Sep 2019 21:20:20 +0200 Subject: [PATCH 1/7] NPE fix --- .../massivecraft/factions/listeners/FactionsPlayerListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 36b9b647..99fc0642 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -804,7 +804,7 @@ public class FactionsPlayerListener implements Listener { Block block = event.getClickedBlock(); Player player = event.getPlayer(); // Check if the material is bypassing protection - if (block == null) return; // clicked in air, apparently + if (block == null || event.getItem() == null) return; // clicked in air, apparently if (Conf.territoryBypassProtectedMaterials.contains(event.getItem().getType())) return; if (GetPermissionFromUsableBlock(event.getClickedBlock().getType()) != null) { if (!canPlayerUseBlock(player, block, false)) { From 0d8526372ef19419ae8779785c6572effd5c2a31 Mon Sep 17 00:00:00 2001 From: AigleDev Date: Thu, 12 Sep 2019 21:21:23 +0200 Subject: [PATCH 2/7] change --- .../factions/listeners/FactionsPlayerListener.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 99fc0642..8e3a07bf 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -804,8 +804,10 @@ public class FactionsPlayerListener implements Listener { Block block = event.getClickedBlock(); Player player = event.getPlayer(); // Check if the material is bypassing protection - if (block == null || event.getItem() == null) return; // clicked in air, apparently - if (Conf.territoryBypassProtectedMaterials.contains(event.getItem().getType())) return; + if (block == null) return; // clicked in air, apparently + if(event.getItem() != null) { + if (Conf.territoryBypassProtectedMaterials.contains(event.getItem().getType())) return; + } if (GetPermissionFromUsableBlock(event.getClickedBlock().getType()) != null) { if (!canPlayerUseBlock(player, block, false)) { event.setCancelled(true); From 3c9b606bb9c0b777c29c59103a5f4e37aa86ad02 Mon Sep 17 00:00:00 2001 From: Driftay Date: Sat, 14 Sep 2019 15:13:01 -0400 Subject: [PATCH 3/7] Introduced Brigadier Command System. More Formatting Coming in next commit. --- javadoc/com/massivecraft/factions/P.html | 2 +- pom.xml | 27 +- .../java/com/massivecraft/factions/Conf.java | 8 +- .../factions/{P.java => FactionsPlugin.java} | 135 +++-- .../factions/cmd/BrigadierManager.java | 92 ++++ .../factions/cmd/BrigadierProvider.java | 9 + .../massivecraft/factions/cmd/CmdAHome.java | 26 +- .../massivecraft/factions/cmd/CmdAdmin.java | 59 +-- .../factions/cmd/CmdAnnounce.java | 39 +- .../factions/cmd/CmdAutoHelp.java | 22 +- .../com/massivecraft/factions/cmd/CmdBan.java | 59 +-- .../massivecraft/factions/cmd/CmdBanlist.java | 28 +- .../massivecraft/factions/cmd/CmdBanner.java | 45 +- .../massivecraft/factions/cmd/CmdBoom.java | 25 +- .../massivecraft/factions/cmd/CmdBypass.java | 29 +- .../massivecraft/factions/cmd/CmdChat.java | 56 +- .../massivecraft/factions/cmd/CmdChatSpy.java | 27 +- .../factions/cmd/CmdCheckpoint.java | 47 +- .../factions/cmd/CmdColeader.java | 49 +- .../massivecraft/factions/cmd/CmdConfig.java | 60 +-- .../massivecraft/factions/cmd/CmdConvert.java | 20 +- .../massivecraft/factions/cmd/CmdCoords.java | 21 +- .../massivecraft/factions/cmd/CmdCreate.java | 70 +-- .../factions/cmd/CmdDeinvite.java | 66 ++- .../factions/cmd/CmdDelFWarp.java | 29 +- .../factions/cmd/CmdDescription.java | 32 +- .../massivecraft/factions/cmd/CmdDisband.java | 79 ++- .../massivecraft/factions/cmd/CmdFGlobal.java | 28 +- .../massivecraft/factions/cmd/CmdFWarp.java | 61 +-- .../com/massivecraft/factions/cmd/CmdFly.java | 97 ++-- .../massivecraft/factions/cmd/CmdFocus.java | 41 +- .../factions/cmd/CmdGetVault.java | 38 +- .../massivecraft/factions/cmd/CmdHelp.java | 208 ++++---- .../massivecraft/factions/cmd/CmdHome.java | 123 ++--- .../massivecraft/factions/cmd/CmdInspect.java | 26 +- .../factions/cmd/CmdInventorySee.java | 36 +- .../massivecraft/factions/cmd/CmdInvite.java | 59 +-- .../massivecraft/factions/cmd/CmdJoin.java | 89 ++-- .../massivecraft/factions/cmd/CmdKick.java | 80 ++- .../factions/cmd/CmdKillHolograms.java | 20 +- .../massivecraft/factions/cmd/CmdLeave.java | 22 +- .../massivecraft/factions/cmd/CmdList.java | 36 +- .../massivecraft/factions/cmd/CmdLock.java | 22 +- .../massivecraft/factions/cmd/CmdLogins.java | 15 +- .../factions/cmd/CmdLowPower.java | 24 +- .../com/massivecraft/factions/cmd/CmdMap.java | 43 +- .../factions/cmd/CmdMapHeight.java | 20 +- .../com/massivecraft/factions/cmd/CmdMod.java | 48 +- .../factions/cmd/CmdModifyPower.java | 20 +- .../massivecraft/factions/cmd/CmdNear.java | 34 +- .../factions/cmd/CmdNotifications.java | 37 -- .../massivecraft/factions/cmd/CmdOpen.java | 39 +- .../massivecraft/factions/cmd/CmdOwner.java | 62 +-- .../factions/cmd/CmdOwnerList.java | 44 +- .../factions/cmd/CmdPaypalSee.java | 49 +- .../factions/cmd/CmdPaypalSet.java | 48 +- .../factions/cmd/CmdPeaceful.java | 18 +- .../massivecraft/factions/cmd/CmdPerm.java | 57 +- .../factions/cmd/CmdPermanent.java | 23 +- .../factions/cmd/CmdPermanentPower.java | 23 +- .../massivecraft/factions/cmd/CmdPower.java | 22 +- .../factions/cmd/CmdPowerBoost.java | 38 +- .../massivecraft/factions/cmd/CmdReload.java | 27 +- .../massivecraft/factions/cmd/CmdRules.java | 76 ++- .../com/massivecraft/factions/cmd/CmdSB.java | 20 +- .../massivecraft/factions/cmd/CmdSaveAll.java | 19 +- .../factions/cmd/CmdSeeChunk.java | 38 +- .../factions/cmd/CmdSetBanner.java | 22 +- .../factions/cmd/CmdSetDefaultRole.java | 22 +- .../factions/cmd/CmdSetFWarp.java | 59 +-- .../factions/cmd/CmdSetMaxVaults.java | 24 +- .../massivecraft/factions/cmd/CmdSethome.java | 55 +- .../massivecraft/factions/cmd/CmdShow.java | 48 +- .../factions/cmd/CmdShowClaims.java | 25 +- .../factions/cmd/CmdShowInvites.java | 14 +- .../massivecraft/factions/cmd/CmdSpam.java | 33 -- .../massivecraft/factions/cmd/CmdStatus.java | 17 +- .../massivecraft/factions/cmd/CmdStealth.java | 29 +- .../massivecraft/factions/cmd/CmdStrike.java | 52 -- .../factions/cmd/CmdStrikeSet.java | 86 --- .../massivecraft/factions/cmd/CmdStrikes.java | 41 ++ .../factions/cmd/CmdStrikesGive.java | 37 ++ .../factions/cmd/CmdStrikesInfo.java | 37 ++ .../factions/cmd/CmdStrikesSet.java | 37 ++ .../factions/cmd/CmdStrikesTake.java | 38 ++ .../massivecraft/factions/cmd/CmdStuck.java | 67 +-- .../com/massivecraft/factions/cmd/CmdTag.java | 55 +- .../massivecraft/factions/cmd/CmdTitle.java | 45 +- .../factions/cmd/CmdToggleAllianceChat.java | 25 +- .../com/massivecraft/factions/cmd/CmdTop.java | 25 +- .../factions/cmd/CmdTpBanner.java | 34 +- .../massivecraft/factions/cmd/CmdUnban.java | 45 +- .../factions/cmd/CmdUpgrades.java | 24 +- .../massivecraft/factions/cmd/CmdVault.java | 57 +- .../massivecraft/factions/cmd/CmdVersion.java | 22 +- .../factions/cmd/CmdViewChest.java | 26 +- .../factions/cmd/CommandContext.java | 418 +++++++++++++++ .../factions/cmd/CommandRequirements.java | 155 ++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 91 ++-- .../massivecraft/factions/cmd/FCommand.java | 499 +++++++----------- .../factions/cmd/alts/CmdAlts.java | 29 +- .../factions/cmd/alts/CmdAltsList.java | 30 +- .../factions/cmd/alts/CmdInviteAlt.java | 60 +-- .../factions/cmd/check/CheckHistoryFrame.java | 6 +- .../cmd/check/CheckSettingsFrame.java | 24 +- .../factions/cmd/check/CheckTask.java | 6 +- .../factions/cmd/check/CmdCheck.java | 85 ++- .../factions/cmd/check/CmdWeeWoo.java | 36 +- .../factions/cmd/check/WeeWooTask.java | 6 +- .../factions/cmd/chest/CmdChest.java | 37 +- .../factions/cmd/claim/CmdAutoClaim.java | 50 +- .../factions/cmd/claim/CmdClaim.java | 45 +- .../factions/cmd/claim/CmdClaimAt.java | 35 +- .../factions/cmd/claim/CmdClaimLine.java | 46 +- .../factions/cmd/claim/CmdCorner.java | 33 +- .../factions/cmd/claim/CmdSafeunclaimall.java | 26 +- .../factions/cmd/claim/CmdUnclaim.java | 123 ++--- .../factions/cmd/claim/CmdUnclaimall.java | 61 ++- .../factions/cmd/claim/CmdWarunclaimall.java | 34 +- .../factions/cmd/econ/CmdMoney.java | 25 +- .../factions/cmd/econ/CmdMoneyBalance.java | 26 +- .../factions/cmd/econ/CmdMoneyDeposit.java | 28 +- .../factions/cmd/econ/CmdMoneyTransferFf.java | 40 +- .../factions/cmd/econ/CmdMoneyTransferFp.java | 34 +- .../factions/cmd/econ/CmdMoneyTransferPf.java | 32 +- .../factions/cmd/econ/CmdMoneyWithdraw.java | 44 +- .../factions/cmd/grace/CmdGrace.java | 32 +- .../factions/cmd/logout/CmdLogout.java | 25 +- .../factions/cmd/logout/LogoutHandler.java | 6 +- .../factions/cmd/points/CmdPoints.java | 25 +- .../factions/cmd/points/CmdPointsAdd.java | 32 +- .../factions/cmd/points/CmdPointsRemove.java | 32 +- .../factions/cmd/points/CmdPointsSet.java | 32 +- .../cmd/relational/FRelationCommand.java | 77 +-- .../factions/cmd/roles/FPromoteCommand.java | 59 +-- .../massivecraft/factions/cmd/tnt/CmdTnt.java | 125 ++--- .../factions/cmd/tnt/CmdTntFill.java | 260 +++++---- .../factions/integration/Econ.java | 14 +- .../factions/integration/Worldguard.java | 6 +- .../integration/dynmap/EngineDynmap.java | 2 +- .../listeners/EssentialsHomeHandler.java | 4 +- .../listeners/FactionsBlockListener.java | 104 ++-- .../listeners/FactionsChatListener.java | 8 +- .../listeners/FactionsEntityListener.java | 8 +- .../listeners/FactionsExploitListener.java | 4 +- .../listeners/FactionsPlayerListener.java | 58 +- .../factions/missions/CmdMissions.java | 25 +- .../factions/missions/MissionGUI.java | 6 +- .../factions/missions/MissionHandler.java | 8 +- .../factions/scoreboards/FScoreboard.java | 6 +- .../scoreboards/FSidebarProvider.java | 4 +- .../factions/scoreboards/FTeamWrapper.java | 16 +- .../scoreboards/sidebar/FDefaultSidebar.java | 8 +- .../scoreboards/sidebar/FInfoSidebar.java | 4 +- .../massivecraft/factions/shop/CmdShop.java | 22 +- .../factions/shop/ShopClickPersistence.java | 4 +- .../massivecraft/factions/shop/ShopGUI.java | 12 +- .../factions/struct/Permission.java | 8 +- .../factions/struct/Relation.java | 4 +- .../massivecraft/factions/struct/Role.java | 6 +- .../massivecraft/factions/tag/FactionTag.java | 135 +++++ .../massivecraft/factions/tag/FancyTag.java | 178 +++++++ .../massivecraft/factions/tag/GeneralTag.java | 58 ++ .../massivecraft/factions/tag/PlayerTag.java | 56 ++ .../com/massivecraft/factions/tag/Tag.java | 80 +++ .../factions/util/AutoLeaveProcessTask.java | 4 +- .../factions/util/AutoLeaveTask.java | 6 +- .../util/ClipPlaceholderAPIManager.java | 6 +- .../factions/util/FactionWarpsFrame.java | 25 +- .../factions/util/LocationTypeAdapter.java | 6 +- .../util/MapFLocToStringSetTypeAdapter.java | 6 +- .../massivecraft/factions/util/MiscUtil.java | 10 +- .../factions/util/MyLocationTypeAdapter.java | 6 +- .../factions/util/Particles/Particles.java | 10 +- .../util/PermissionsMapTypeAdapter.java | 4 +- .../factions/util/QuadFunction.java | 6 + .../factions/util/SpiralTask.java | 8 +- .../massivecraft/factions/util/UtilFly.java | 18 +- .../factions/util/WarmUpUtil.java | 4 +- .../massivecraft/factions/zcore/MCommand.java | 4 +- .../massivecraft/factions/zcore/MPlugin.java | 2 +- .../zcore/MPluginSecretPlayerListener.java | 2 +- .../factions/zcore/fperms/Access.java | 4 +- .../zcore/fperms/PermissableAction.java | 12 +- .../fperms/gui/PermissableActionFrame.java | 24 +- .../fperms/gui/PermissableRelationFrame.java | 20 +- .../zcore/fupgrades/CropUpgrades.java | 8 +- .../factions/zcore/fupgrades/EXPUpgrade.java | 8 +- .../zcore/fupgrades/FUpgradesGUI.java | 176 +++--- .../zcore/fupgrades/RedstoneUpgrade.java | 6 +- .../zcore/fupgrades/SpawnerUpgrades.java | 8 +- .../factions/zcore/persist/MemoryBoard.java | 18 +- .../factions/zcore/persist/MemoryFPlayer.java | 88 +-- .../zcore/persist/MemoryFPlayers.java | 4 +- .../factions/zcore/persist/MemoryFaction.java | 30 +- .../zcore/persist/json/FactionsJSON.java | 4 +- .../zcore/persist/json/JSONBoard.java | 16 +- .../zcore/persist/json/JSONFPlayers.java | 8 +- .../zcore/persist/json/JSONFactions.java | 8 +- .../factions/zcore/util/DiscUtil.java | 4 +- .../massivecraft/factions/zcore/util/TL.java | 33 +- .../factions/zcore/util/TagReplacer.java | 22 +- .../factions/zcore/util/TagUtil.java | 24 +- .../factions/zcore/util/TextUtil.java | 2 +- src/main/resources/config.yml | 15 +- src/main/resources/lang/it_IT.yml | 2 +- src/main/resources/plugin.yml | 2 +- 207 files changed, 4465 insertions(+), 4017 deletions(-) rename src/main/java/com/massivecraft/factions/{P.java => FactionsPlugin.java} (83%) create mode 100644 src/main/java/com/massivecraft/factions/cmd/BrigadierManager.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/BrigadierProvider.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdNotifications.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdSpam.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdStrike.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdStrikeSet.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdStrikes.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdStrikesGive.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdStrikesInfo.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdStrikesSet.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdStrikesTake.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CommandContext.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CommandRequirements.java create mode 100644 src/main/java/com/massivecraft/factions/tag/FactionTag.java create mode 100644 src/main/java/com/massivecraft/factions/tag/FancyTag.java create mode 100644 src/main/java/com/massivecraft/factions/tag/GeneralTag.java create mode 100644 src/main/java/com/massivecraft/factions/tag/PlayerTag.java create mode 100644 src/main/java/com/massivecraft/factions/tag/Tag.java create mode 100644 src/main/java/com/massivecraft/factions/util/QuadFunction.java diff --git a/javadoc/com/massivecraft/factions/P.html b/javadoc/com/massivecraft/factions/P.html index 319fd4f0..6625eb4d 100644 --- a/javadoc/com/massivecraft/factions/P.html +++ b/javadoc/com/massivecraft/factions/P.html @@ -108,7 +108,7 @@ var activeTableTab = "activeTableTab";
  • com.massivecraft.factions.zcore.MPlugin
    • -
    • com.massivecraft.factions.P
    • +
    • com.massivecraft.factions.FactionsPlugin
  • diff --git a/pom.xml b/pom.xml index 3b6ca9ea..bbce7640 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,18 @@ + + me.lucko + commodore + 1.3 + compile + + + com.mojang + brigadier + 1.0.14 + compile + com.github.stefvanschie.inventoryframework IF @@ -352,7 +364,11 @@ - + + org.codemc.worldguardwrapper + worldguardwrapper + 1.1.6-SNAPSHOT + @@ -360,6 +376,10 @@ net.coreprotect http://maven.playpro.com/ + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + ess-repo http://ci.ender.zone/plugin/repository/everything/ @@ -393,6 +413,11 @@ jitpack.io https://jitpack.io + + minecraft-libraries + Minecraft Libraries + https://libraries.minecraft.net + diff --git a/src/main/java/com/massivecraft/factions/Conf.java b/src/main/java/com/massivecraft/factions/Conf.java index 37300043..637d0e86 100644 --- a/src/main/java/com/massivecraft/factions/Conf.java +++ b/src/main/java/com/massivecraft/factions/Conf.java @@ -386,7 +386,7 @@ public class Conf { territoryDenyUseageMaterials.add(Material.BUCKET); territoryDenyUseageMaterials.add(Material.WATER_BUCKET); territoryDenyUseageMaterials.add(Material.LAVA_BUCKET); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { territoryDenyUseageMaterials.add(Material.ARMOR_STAND); } @@ -398,7 +398,7 @@ public class Conf { territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND); } safeZoneNerfedCreatureTypes.add(EntityType.BLAZE); @@ -426,11 +426,11 @@ public class Conf { } public static void load() { - P.p.persist.loadOrSaveDefault(i, Conf.class, "conf"); + FactionsPlugin.getInstance().persist.loadOrSaveDefault(i, Conf.class, "conf"); } public static void save() { - P.p.persist.save(i); + FactionsPlugin.getInstance().persist.save(i); } public enum Backend { diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/FactionsPlugin.java similarity index 83% rename from src/main/java/com/massivecraft/factions/P.java rename to src/main/java/com/massivecraft/factions/FactionsPlugin.java index 9289ce54..b9ad2f73 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/FactionsPlugin.java @@ -5,7 +5,9 @@ import ch.njol.skript.SkriptAddon; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.massivecraft.factions.cmd.CmdAutoHelp; +import com.massivecraft.factions.cmd.CommandContext; import com.massivecraft.factions.cmd.FCmdRoot; +import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.cmd.check.CheckTask; import com.massivecraft.factions.cmd.check.WeeWooTask; import com.massivecraft.factions.cmd.chest.ChestLogsHandler; @@ -17,16 +19,18 @@ import com.massivecraft.factions.missions.MissionHandler; import com.massivecraft.factions.shop.ShopClickPersistence; import com.massivecraft.factions.shop.ShopConfig; import com.massivecraft.factions.struct.ChatMode; +import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.*; import com.massivecraft.factions.util.Particles.ReflectionUtils; import com.massivecraft.factions.zcore.CommandVisibility; -import com.massivecraft.factions.zcore.MCommand; import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fupgrades.*; import com.massivecraft.factions.zcore.util.TextUtil; +import me.lucko.commodore.CommodoreProvider; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; import org.bukkit.*; @@ -52,11 +56,11 @@ import java.util.logging.Level; import java.util.stream.Collectors; -public class P extends MPlugin { +public class FactionsPlugin extends MPlugin { // Our single plugin instance. // Single 4 life. - public static P p; + public static FactionsPlugin instance; public static Permission perms = null; // This plugin sets the boolean true when fully enabled. // Plugins can check this boolean while hooking in have @@ -85,8 +89,12 @@ public class P extends MPlugin { private Listener[] eventsListener; - public P() { - p = this; + public FactionsPlugin() { + instance = this; + } + + public static FactionsPlugin getInstance() { + return instance; } public boolean getLocked() { @@ -139,29 +147,29 @@ public class P extends MPlugin { // Vault dependency check. if (getServer().getPluginManager().getPlugin("Vault") == null) { log("Vault is not present, the plugin will not run properly."); - getServer().getPluginManager().disablePlugin(p); + getServer().getPluginManager().disablePlugin(instance); return; } int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]); switch (version) { case 7: - P.p.log("Minecraft Version 1.7 found, disabling banners, itemflags inside GUIs, and Titles."); + FactionsPlugin.instance.log("Minecraft Version 1.7 found, disabling banners, itemflags inside GUIs, and Titles."); mc17 = true; break; case 8: - P.p.log("Minecraft Version 1.8 found, Title Fadeouttime etc will not be configurable."); + FactionsPlugin.instance.log("Minecraft Version 1.8 found, Title Fadeouttime etc will not be configurable."); mc18 = true; break; case 12: mc112 = true; break; case 13: - P.p.log("Minecraft Version 1.13 found, New Items will be used."); + FactionsPlugin.instance.log("Minecraft Version 1.13 found, New Items will be used."); mc113 = true; break; case 14: - P.p.log("Minecraft Version 1.14 found."); + FactionsPlugin.instance.log("Minecraft Version 1.14 found."); mc114 = true; break; } @@ -206,7 +214,6 @@ public class P extends MPlugin { // Add Base Commands this.cmdBase = new FCmdRoot(); this.cmdAutoHelp = new CmdAutoHelp(); - this.getBaseCommands().add(cmdBase); Econ.setup(); setupPermissions(); @@ -230,7 +237,7 @@ public class P extends MPlugin { } if (getServer().getPluginManager().getPlugin("Skript") != null) { - log("Skript was found! Registering P Addon..."); + log("Skript was found! Registering FactionsPlugin Addon..."); skriptAddon = Skript.registerAddon(this); try { skriptAddon.loadClasses("com.massivecraft.factions.skript", "expressions"); @@ -272,13 +279,13 @@ public class P extends MPlugin { for (Listener eventListener : eventsListener) getServer().getPluginManager().registerEvents(eventListener, this); - // since some other plugins execute commands directly through this command interface, provide it - getCommand(this.refCommand).setExecutor(this); - getCommand(this.refCommand).setTabCompleter(this); + this.getCommand(refCommand).setExecutor(cmdBase); + + if (!CommodoreProvider.isSupported()) this.getCommand(refCommand).setTabCompleter(this); - RegisteredServiceProvider rsp = P.this.getServer().getServicesManager().getRegistration(Economy.class); - P.econ = rsp.getProvider(); + RegisteredServiceProvider rsp = FactionsPlugin.this.getServer().getServicesManager().getRegistration(Economy.class); + FactionsPlugin.econ = rsp.getProvider(); if (getDescription().getFullName().contains("BETA")) { divider(); @@ -292,7 +299,7 @@ public class P extends MPlugin { this.postEnable(); this.loadSuccessful = true; // Set startup finished to true. to give plugins hooking in a greenlight - P.startupFinished = true; + FactionsPlugin.startupFinished = true; } public SkriptAddon getSkriptAddon() { @@ -455,14 +462,14 @@ public class P extends MPlugin { public ItemStack createLazyItem(Material material, int amount, short datavalue, String name, String lore) { ItemStack item = new ItemStack(material, amount, datavalue); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(color(P.p.getConfig().getString(name))); - meta.setLore(colorList(P.p.getConfig().getStringList(lore))); + meta.setDisplayName(color(FactionsPlugin.instance.getConfig().getString(name))); + meta.setLore(colorList(FactionsPlugin.instance.getConfig().getStringList(lore))); item.setItemMeta(meta); return item; } public Economy getEcon() { - RegisteredServiceProvider rsp = P.p.getServer().getServicesManager().getRegistration(Economy.class); + RegisteredServiceProvider rsp = FactionsPlugin.instance.getServer().getServicesManager().getRegistration(Economy.class); return rsp.getProvider(); } @@ -488,48 +495,62 @@ public class P extends MPlugin { return handleCommand(sender, cmd + " " + TextUtil.implode(Arrays.asList(split), " "), false); } + // This method must stay for < 1.12 versions @Override public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - FPlayer fPlayer = FPlayers.getInstance().getByPlayer((Player) sender); - List completions = new ArrayList<>(); + // Must be a LinkedList to prevent UnsupportedOperationException. + List argsList = new LinkedList<>(Arrays.asList(args)); + CommandContext context = new CommandContext(sender, argsList, alias); String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0); - List argsList = new ArrayList<>(Arrays.asList(args)); - argsList.remove(argsList.size() - 1); - String cmdValid = (cmd + " " + TextUtil.implode(argsList, " ")).trim(); - MCommand commandEx = cmdBase; - List> commandsList = cmdBase.subCommands; +// String cmdValid = (cmd + " " + TextUtil.implode(context.args, " ")).trim(); + List commandsList = cmdBase.subCommands; + FCommand commandsEx = cmdBase; + List completions = new ArrayList<>(); - for (; !commandsList.isEmpty() && !argsList.isEmpty(); argsList.remove(0)) { - String cmdName = argsList.get(0).toLowerCase(); - MCommand commandFounded = commandsList.stream() - .filter(c -> c.aliases.contains(cmdName)) - .findFirst().orElse(null); - - if (commandFounded != null) { - commandEx = commandFounded; - commandsList = commandFounded.subCommands; - } else break; - } - - if (argsList.isEmpty()) { - for (MCommand subCommand : commandEx.subCommands) { - subCommand.setCommandSender(sender); - if (handleCommand(sender, cmdValid + " " + subCommand.aliases.get(0), true) - && subCommand.visibility != CommandVisibility.INVISIBLE - && subCommand.validSenderType(sender, false) - && subCommand.validSenderPermissions(sender, false)) + // Check for "" first arg because spigot is mangled. + if (context.args.get(0).equals("")) { + for (FCommand subCommand : commandsEx.subCommands) { + if (subCommand.requirements.playerOnly && sender.hasPermission(subCommand.requirements.permission.node) && subCommand.visibility != CommandVisibility.INVISIBLE) completions.addAll(subCommand.aliases); } - } + return completions; + } else if (context.args.size() == 1) { + for (; !commandsList.isEmpty() && !context.args.isEmpty(); context.args.remove(0)) { + String cmdName = context.args.get(0).toLowerCase(); + boolean toggle = false; + for (FCommand fCommand : commandsList) { + for (String s : fCommand.aliases) { + if (s.startsWith(cmdName)) { + commandsList = fCommand.subCommands; + completions.addAll(fCommand.aliases); + toggle = true; + break; + } + } + if (toggle) break; + } + } + String lastArg = args[args.length - 1].toLowerCase(); - String lastArg = args[args.length - 1].toLowerCase(); - for (Player player : Bukkit.getServer().getOnlinePlayers()) { - completions.add(player.getName()); + completions = completions.stream() + .filter(m -> m.toLowerCase().startsWith(lastArg)) + .collect(Collectors.toList()); + + return completions; + + } else { + String lastArg = args[args.length - 1].toLowerCase(); + + for (Role value : Role.values()) completions.add(value.nicename); + for (Relation value : Relation.values()) completions.add(value.nicename); + // The stream and foreach from the old implementation looped 2 times, by looping all players -> filtered -> looped filter and added -> filtered AGAIN at the end. + // This loops them once and just adds, because we are filtering the arguments at the end anyways + for (Player player : Bukkit.getServer().getOnlinePlayers()) completions.add(player.getName()); + for (Faction faction : Factions.getInstance().getAllFactions()) + completions.add(ChatColor.stripColor(faction.getTag())); + completions = completions.stream().filter(m -> m.toLowerCase().startsWith(lastArg)).collect(Collectors.toList()); + return completions; } - completions = completions.stream() - .filter(m -> m.toLowerCase().startsWith(lastArg)) - .collect(Collectors.toList()); - return completions; } public void createTimedHologram(final Location location, String text, Long timeout) { @@ -537,11 +558,11 @@ public class P extends MPlugin { as.setVisible(false); //Makes the ArmorStand invisible as.setGravity(false); //Make sure it doesn't fall as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName(P.p.color(text)); //Set this to the text you want + as.setCustomName(FactionsPlugin.instance.color(text)); //Set this to the text you want as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not final ArmorStand armorStand = as; - Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> { + Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> { armorStand.remove(); getLogger().info("Removing Hologram."); } diff --git a/src/main/java/com/massivecraft/factions/cmd/BrigadierManager.java b/src/main/java/com/massivecraft/factions/cmd/BrigadierManager.java new file mode 100644 index 00000000..ecd4851b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/BrigadierManager.java @@ -0,0 +1,92 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.FactionsPlugin; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.tree.CommandNode; +import me.lucko.commodore.Commodore; +import me.lucko.commodore.CommodoreProvider; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class BrigadierManager { + + public Commodore commodore; + public LiteralArgumentBuilder brigadier = LiteralArgumentBuilder.literal("factions"); + + public BrigadierManager() { + commodore = CommodoreProvider.getCommodore(FactionsPlugin.getInstance()); + } + + public void build() { + commodore.register(brigadier.build()); + + // Add factions children to f alias + LiteralArgumentBuilder fLiteral = LiteralArgumentBuilder.literal("f"); + for (CommandNode node : brigadier.getArguments()) fLiteral.then(node); + commodore.register(fLiteral.build()); + } + + public void addSubCommand(FCommand subCommand) { + // Register brigadier to all command aliases + for (String alias : subCommand.aliases) { + LiteralArgumentBuilder literal = LiteralArgumentBuilder.literal(alias); + + if (subCommand.requirements.brigadier != null) { + // If the requirements explicitly provide a BrigadierProvider then use it + Class brigadierProvider = subCommand.requirements.brigadier; + + try { + Constructor constructor = brigadierProvider.getDeclaredConstructor(subCommand.getClass()); + brigadier.then(constructor.newInstance(subCommand).get(literal)); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + // Generate our own based on args - quite ugly + + // We create an orderly stack of all args, required and optional, format them differently + List> stack = new ArrayList<>(); + for (String required : subCommand.requiredArgs) { + // Simply add the arg name as required + stack.add(RequiredArgumentBuilder.argument(required, StringArgumentType.word())); + } + + for (Map.Entry optionalEntry : subCommand.optionalArgs.entrySet()) { + RequiredArgumentBuilder optional; + + // Optional without default + if (optionalEntry.getKey().equalsIgnoreCase(optionalEntry.getValue())) { + optional = RequiredArgumentBuilder.argument(":" + optionalEntry.getKey(), StringArgumentType.word()); + // Optional with default, explain + } else { + optional = RequiredArgumentBuilder.argument(optionalEntry.getKey() + "|" + optionalEntry.getValue(), StringArgumentType.word()); + } + + stack.add(optional); + } + + // Reverse the stack and apply .then() + RequiredArgumentBuilder previous = null; + for (int i = stack.size() - 1; i >= 0; i--) { + if (previous == null) { + previous = stack.get(i); + } else { + previous = stack.get(i).then(previous); + } + } + + if (previous == null) { + brigadier.then(literal); + } else { + brigadier.then(literal.then(previous)); + } + } + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/BrigadierProvider.java b/src/main/java/com/massivecraft/factions/cmd/BrigadierProvider.java new file mode 100644 index 00000000..455b3877 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/BrigadierProvider.java @@ -0,0 +1,9 @@ +package com.massivecraft.factions.cmd; + +import com.mojang.brigadier.builder.ArgumentBuilder; + +public interface BrigadierProvider { + + ArgumentBuilder get(ArgumentBuilder parent); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdAHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdAHome.java index 2e305f66..a7763eea 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdAHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdAHome.java @@ -12,23 +12,17 @@ public class CmdAHome extends FCommand { super(); this.aliases.add("ahome"); - this.requiredArgs.add("player name"); + this.requiredArgs.add("player"); - this.permission = Permission.AHOME.node; - this.disableOnLock = false; - this.disableOnSpam = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.AHOME).noDisableOnLock().build(); } + @Override - public void perform() { - FPlayer target = argAsBestFPlayerMatch(0); + public void perform(CommandContext context) { + FPlayer target = context.argAsBestFPlayerMatch(0); if (target == null) { - msg(TL.GENERIC_NOPLAYERMATCH, argAsString(0)); + context.msg(TL.GENERIC_NOPLAYERMATCH, context.argAsString(0)); return; } @@ -36,13 +30,13 @@ public class CmdAHome extends FCommand { Faction faction = target.getFaction(); if (faction.hasHome()) { target.getPlayer().teleport(faction.getHome(), PlayerTeleportEvent.TeleportCause.PLUGIN); - msg(TL.COMMAND_AHOME_SUCCESS, target.getName()); + context.msg(TL.COMMAND_AHOME_SUCCESS, target.getName()); target.msg(TL.COMMAND_AHOME_TARGET); } else { - msg(TL.COMMAND_AHOME_NOHOME, target.getName()); + context.msg(TL.COMMAND_AHOME_NOHOME, target.getName()); } } else { - msg(TL.COMMAND_AHOME_OFFLINE, target.getName()); + context.msg(TL.COMMAND_AHOME_OFFLINE, target.getName()); } } @@ -50,4 +44,4 @@ public class CmdAHome extends FCommand { public TL getUsageTranslation() { return TL.COMMAND_AHOME_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdAdmin.java b/src/main/java/com/massivecraft/factions/cmd/CmdAdmin.java index 26be8ede..3af1ef18 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdAdmin.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdAdmin.java @@ -8,7 +8,6 @@ import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; public class CmdAdmin extends FCommand { @@ -19,52 +18,39 @@ public class CmdAdmin extends FCommand { this.aliases.add("leader"); this.aliases.add("setleader"); - this.requiredArgs.add("player name"); + this.requiredArgs.add("player"); - this.permission = Permission.ADMIN.node; - this.disableOnLock = true; - this.disableOnSpam = true; - - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.ADMIN).build(); } @Override - public void perform() { - FPlayer fyou = this.argAsBestFPlayerMatch(0); - if (fyou == null || fyou.getFaction().isWarZone() || fyou.getFaction().isWilderness() || fyou.getFaction().isSafeZone()) { + public void perform(CommandContext context) { + // Allows admins bypass this. + if (!context.fPlayer.isAdminBypassing() && !context.fPlayer.getRole().equals(Role.LEADER)) { + context.msg(TL.COMMAND_ADMIN_NOTADMIN); + return; + } + FPlayer fyou = context.argAsBestFPlayerMatch(0); + if (fyou == null) { return; } - boolean permAny = Permission.ADMIN_ANY.has(sender, false); + boolean permAny = Permission.ADMIN_ANY.has(context.sender, false); Faction targetFaction = fyou.getFaction(); - if (fyou.isAlt()) { - msg(ChatColor.RED + "You can not promote alt accounts."); + if (targetFaction != context.faction && !permAny) { + context.msg(TL.COMMAND_ADMIN_NOTMEMBER, fyou.describeTo(context.fPlayer, true)); return; } - if (targetFaction != myFaction && !permAny) { - msg(TL.COMMAND_ADMIN_NOTMEMBER, fyou.describeTo(fme, true)); - return; - } - - if (fme != null && fme.getRole() != Role.LEADER && !permAny) { - msg(TL.COMMAND_ADMIN_NOTADMIN); - return; - } - - if (fyou == fme && !permAny) { - msg(TL.COMMAND_ADMIN_TARGETSELF); + if (fyou == context.fPlayer && !permAny) { + context.msg(TL.COMMAND_ADMIN_TARGETSELF); return; } // only perform a FPlayerJoinEvent when newLeader isn't actually in the faction if (fyou.getFaction() != targetFaction) { - FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(me), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER); + FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; @@ -73,16 +59,11 @@ public class CmdAdmin extends FCommand { FPlayer admin = targetFaction.getFPlayerAdmin(); - if (fyou == admin && fyou.getFaction().getSize() == 1) { - msg(TL.COMMAND_ADMIN_NOMEMBERS); - return; - } - // if target player is currently admin, demote and replace him if (fyou == admin) { targetFaction.promoteNewLeader(); - msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(fme, true)); - fyou.msg(TL.COMMAND_ADMIN_DEMOTED, senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fyou, true)); + context.msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(context.fPlayer, true)); + fyou.msg(TL.COMMAND_ADMIN_DEMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fyou, true)); return; } @@ -91,11 +72,11 @@ public class CmdAdmin extends FCommand { admin.setRole(Role.COLEADER); } fyou.setRole(Role.LEADER); - msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(fme, true)); + context.msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(context.fPlayer, true)); // Inform all players for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { - fplayer.msg(TL.COMMAND_ADMIN_PROMOTED, senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true), fyou.describeTo(fplayer), targetFaction.describeTo(fplayer)); + fplayer.msg(TL.COMMAND_ADMIN_PROMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true), fyou.describeTo(fplayer), targetFaction.describeTo(fplayer)); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java b/src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java index 6924fcf2..91378e95 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java @@ -3,6 +3,9 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -15,30 +18,27 @@ public class CmdAnnounce extends FCommand { this.aliases.add("announce"); this.requiredArgs.add("message"); - this.errorOnToManyArgs = false; - this.permission = Permission.ANNOUNCE.node; - this.disableOnLock = false; - this.disableOnSpam = false; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; + this.requirements = new CommandRequirements.Builder(Permission.ANNOUNCE) + .playerOnly() + .memberOnly() + .brigadier(AnnounceBrigadier.class) + .noErrorOnManyArgs() + .build(); } @Override - public void perform() { - String prefix = ChatColor.GREEN + myFaction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + me.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET; - String message = StringUtils.join(args, " "); + public void perform(CommandContext context) { + String prefix = ChatColor.GREEN + context.faction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + context.player.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET; + String message = StringUtils.join(context.args, " "); - for (Player player : myFaction.getOnlinePlayers()) { + for (Player player : context.faction.getOnlinePlayers()) { player.sendMessage(prefix + message); } // Add for offline players. - for (FPlayer fp : myFaction.getFPlayersWhereOnline(false)) { - myFaction.addAnnouncement(fp, prefix + message); + for (FPlayer fp : context.faction.getFPlayersWhereOnline(false)) { + context.faction.addAnnouncement(fp, prefix + message); } } @@ -47,4 +47,11 @@ public class CmdAnnounce extends FCommand { return TL.COMMAND_ANNOUNCE_DESCRIPTION; } -} + protected class AnnounceBrigadier implements BrigadierProvider { + @Override + public ArgumentBuilder get(ArgumentBuilder parent) { + return parent.then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString())); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdAutoHelp.java b/src/main/java/com/massivecraft/factions/cmd/CmdAutoHelp.java index 22b7653d..87884a5c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdAutoHelp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdAutoHelp.java @@ -1,16 +1,14 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.CommandVisibility; -import com.massivecraft.factions.zcore.MCommand; import com.massivecraft.factions.zcore.util.TL; import java.util.ArrayList; -public class CmdAutoHelp extends MCommand

    { +public class CmdAutoHelp extends FCommand { public CmdAutoHelp() { - super(P.p); this.aliases.add("?"); this.aliases.add("h"); this.aliases.add("help"); @@ -21,22 +19,22 @@ public class CmdAutoHelp extends MCommand

    { } @Override - public void perform() { - - if (this.commandChain.size() == 0) { + public void perform(CommandContext context) { + if (context.commandChain.size() == 0) { return; } - MCommand pcmd = this.commandChain.get(this.commandChain.size() - 1); + FCommand pcmd = context.commandChain.get(context.commandChain.size() - 1); ArrayList lines = new ArrayList<>(pcmd.helpLong); - for (MCommand scmd : pcmd.subCommands) { - if (scmd.visibility == CommandVisibility.VISIBLE || (scmd.visibility == CommandVisibility.SECRET && scmd.validSenderPermissions(sender, false))) { - lines.add(scmd.getUseageTemplate(this.commandChain, true)); + for (FCommand scmd : pcmd.subCommands) { + if (scmd.visibility == CommandVisibility.VISIBLE) { + lines.add(scmd.getUseageTemplate(context, true)); } + // TODO deal with other visibilities } - sendMessage(p.txt.getPage(lines, this.argAsInt(0, 1), TL.COMMAND_AUTOHELP_HELPFOR.toString() + pcmd.aliases.get(0) + "\"")); + context.sendMessage(FactionsPlugin.getInstance().txt.getPage(lines, context.argAsInt(0, 1), TL.COMMAND_AUTOHELP_HELPFOR.toString() + pcmd.aliases.get(0) + "\"")); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBan.java b/src/main/java/com/massivecraft/factions/cmd/CmdBan.java index 80cdd283..f9158d10 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBan.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBan.java @@ -1,12 +1,10 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.struct.BanInfo; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; @@ -21,78 +19,63 @@ public class CmdBan extends FCommand { this.requiredArgs.add("target"); - this.permission = Permission.BAN.node; - this.disableOnLock = true; - this.disableOnSpam = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.BAN) + .playerOnly() + .withAction(PermissableAction.BAN) + .build(); } @Override - public void perform() { - - // Adds bypass to admins and clean permission check - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.BAN); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "ban"); - return; - } - } - + public void perform(CommandContext context) { // Good on permission checks. Now lets just ban the player. - FPlayer target = argAsFPlayer(0); + FPlayer target = context.argAsFPlayer(0); if (target == null) { return; // the above method sends a message if fails to find someone. } - if (fme == target) { + if (context.fPlayer == target) { // You may not ban yourself - fme.msg(TL.COMMAND_BAN_SELF); + context.msg(TL.COMMAND_BAN_SELF); return; - } else if (target.getFaction() == myFaction && target.getRole().value >= fme.getRole().value) { + } else if (target.getFaction() == context.faction && target.getRole().value >= context.fPlayer.getRole().value) { // You may not ban someone that has same or higher faction rank - fme.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName()); + context.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName()); return; } - for (BanInfo banInfo : myFaction.getBannedPlayers()) { + for (BanInfo banInfo : context.faction.getBannedPlayers()) { if (banInfo.getBanned().equals(target.getId())) { - msg(TL.COMMAND_BAN_ALREADYBANNED); + context.msg(TL.COMMAND_BAN_ALREADYBANNED); return; } } // Ban the user. - myFaction.ban(target, fme); - myFaction.deinvite(target); // can't hurt + context.faction.ban(target, context.fPlayer); + context.faction.deinvite(target); // can't hurt // If in same Faction, lets make sure to kick them and throw an event. - if (target.getFaction() == myFaction) { + if (target.getFaction() == context.faction) { - FPlayerLeaveEvent event = new FPlayerLeaveEvent(target, myFaction, FPlayerLeaveEvent.PlayerLeaveReason.BANNED); + FPlayerLeaveEvent event = new FPlayerLeaveEvent(target, context.faction, FPlayerLeaveEvent.PlayerLeaveReason.BANNED); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { // if someone cancels a ban, we'll get people complaining here. So lets log it. - P.p.log(Level.WARNING, "Attempted to ban {0} but someone cancelled the kick event. This isn't good.", target.getName()); + FactionsPlugin.getInstance().log(Level.WARNING, "Attempted to ban {0} but someone cancelled the kick event. This isn't good.", target.getName()); return; } // Didn't get cancelled so remove them and reset their invite. - myFaction.removeFPlayer(target); + context.faction.removeFPlayer(target); target.resetFactionData(); } // Lets inform the people! - target.msg(TL.COMMAND_BAN_TARGET, myFaction.getTag(target.getFaction())); - myFaction.msg(TL.COMMAND_BAN_BANNED, fme.getName(), target.getName()); + target.msg(TL.COMMAND_BAN_TARGET, context.faction.getTag(target.getFaction())); + context.faction.msg(TL.COMMAND_BAN_BANNED, context.fPlayer.getName(), target.getName()); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBanlist.java b/src/main/java/com/massivecraft/factions/cmd/CmdBanlist.java index c5586b35..41efc743 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBanlist.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBanlist.java @@ -21,35 +21,31 @@ public class CmdBanlist extends FCommand { this.optionalArgs.put("faction", "faction"); - this.permission = Permission.BAN.node; - this.disableOnLock = true; - this.disableOnSpam = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.BAN) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - Faction target = myFaction; - if (!args.isEmpty()) { - target = argAsFaction(0); + public void perform(CommandContext context) { + Faction target = context.faction; + if (!context.args.isEmpty()) { + target = context.argAsFaction(0); } if (target == Factions.getInstance().getWilderness()) { - sender.sendMessage(TL.COMMAND_BANLIST_NOFACTION.toString()); + context.sender.sendMessage(TL.COMMAND_BANLIST_NOFACTION.toString()); return; } if (target == null) { - sender.sendMessage(TL.COMMAND_BANLIST_INVALID.format(argAsString(0))); + context.sender.sendMessage(TL.COMMAND_BANLIST_INVALID.format(context.argAsString(0))); return; } List lines = new ArrayList<>(); - lines.add(TL.COMMAND_BANLIST_HEADER.format(target.getBannedPlayers().size(), target.getTag(myFaction))); + lines.add(TL.COMMAND_BANLIST_HEADER.format(target.getBannedPlayers().size(), target.getTag(context.faction))); int i = 1; for (BanInfo info : target.getBannedPlayers()) { @@ -62,7 +58,7 @@ public class CmdBanlist extends FCommand { } for (String s : lines) { - fme.sendMessage(s); + context.fPlayer.getPlayer().sendMessage(s); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBanner.java b/src/main/java/com/massivecraft/factions/cmd/CmdBanner.java index a52cb6e2..d4578676 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBanner.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBanner.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.zcore.util.TL; @@ -20,50 +20,45 @@ public class CmdBanner extends FCommand { this.aliases.add("banner"); this.aliases.add("warbanner"); - this.permission = Permission.BANNER.node; - this.disableOnLock = false; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.BANNER) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("fbanners.Enabled")) { - msg(TL.COMMAND_BANNER_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Enabled")) { + context.msg(TL.COMMAND_BANNER_DISABLED); return; } - if (!fme.hasMoney(P.p.getConfig().getInt("fbanners.Banner-Cost", 5000))) { - msg(TL.COMMAND_BANNER_NOTENOUGHMONEY); + if (!context.fPlayer.hasMoney(FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000))) { + context.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY); return; } - takeMoney(fme, P.p.getConfig().getInt("fbanners.Banner-Cost", 5000)); + takeMoney(context.fPlayer, FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000)); - //ItemStack warBanner = P.p.createItem(Material.BANNER, 1, (short) 1, P.p.getConfig().getString("fbanners.Item.Name"), P.p.getConfig().getStringList("fbanners.Item.Lore")); + //ItemStack warBanner = FactionsPlugin.getInstance().createItem(Material.BANNER, 1, (short) 1, FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"), FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")); //BannerMeta bannerMeta = (BannerMeta) warBanner.getItemMeta(); - ItemStack warBanner = fme.getFaction().getBanner(); + ItemStack warBanner = context.fPlayer.getFaction().getBanner(); if (warBanner != null) { ItemMeta warmeta = warBanner.getItemMeta(); - warmeta.setDisplayName(P.p.color(P.p.getConfig().getString("fbanners.Item.Name"))); - warmeta.setLore(P.p.colorList(P.p.getConfig().getStringList("fbanners.Item.Lore"))); + warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"))); + warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore"))); warBanner.setItemMeta(warmeta); } else { - warBanner = P.p.createItem(XMaterial.BLACK_BANNER.parseMaterial(), 1, (short) 1, P.p.getConfig().getString("fbanners.Item.Name"), P.p.getConfig().getStringList("fbanners.Item.Lore")); + warBanner = FactionsPlugin.getInstance().createItem(XMaterial.BLACK_BANNER.parseMaterial(), 1, (short) 1, FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"), FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")); } - fme.msg(TL.COMMAND_BANNER_SUCCESS); + context.msg(TL.COMMAND_BANNER_SUCCESS); warBanner.setAmount(1); - me.getInventory().addItem(warBanner); + context.player.getInventory().addItem(warBanner); } public boolean hasMoney(FPlayer fme, int amt) { - Economy econ = P.p.getEcon(); + Economy econ = FactionsPlugin.getInstance().getEcon(); if (econ.getBalance(fme.getPlayer()) >= amt) { return true; } else { @@ -74,7 +69,7 @@ public class CmdBanner extends FCommand { public void takeMoney(FPlayer fme, int amt) { if (hasMoney(fme, amt)) { - Economy econ = P.p.getEcon(); + Economy econ = FactionsPlugin.getInstance().getEcon(); econ.withdrawPlayer(fme.getPlayer(), amt); 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 fcbe859f..26a06943 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBoom.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBoom.java @@ -15,34 +15,29 @@ public class CmdBoom extends FCommand { //this.requiredArgs.add(""); this.optionalArgs.put("on/off", "flip"); - this.permission = Permission.NO_BOOM.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.NO_BOOM) + .playerOnly() + .build(); } @Override - public void perform() { - if (!myFaction.isPeaceful()) { - fme.msg(TL.COMMAND_BOOM_PEACEFULONLY); + public void perform(CommandContext context) { + if (!context.faction.isPeaceful()) { + context.msg(TL.COMMAND_BOOM_PEACEFULONLY); return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostNoBoom, TL.COMMAND_BOOM_TOTOGGLE, TL.COMMAND_BOOM_FORTOGGLE)) { + if (!context.payForCommand(Conf.econCostNoBoom, TL.COMMAND_BOOM_TOTOGGLE, TL.COMMAND_BOOM_FORTOGGLE)) { return; } - myFaction.setPeacefulExplosionsEnabled(this.argAsBool(0, !myFaction.getPeacefulExplosionsEnabled())); + context.faction.setPeacefulExplosionsEnabled(context.argAsBool(0, !context.faction.getPeacefulExplosionsEnabled())); - String enabled = myFaction.noExplosionsInTerritory() ? TL.GENERIC_DISABLED.toString() : TL.GENERIC_ENABLED.toString(); + String enabled = context.faction.noExplosionsInTerritory() ? TL.GENERIC_DISABLED.toString() : TL.GENERIC_ENABLED.toString(); // Inform - myFaction.msg(TL.COMMAND_BOOM_ENABLED, fme.describeTo(myFaction), enabled); + context.faction.msg(TL.COMMAND_BOOM_ENABLED, context.fPlayer.describeTo(context.faction), enabled); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBypass.java b/src/main/java/com/massivecraft/factions/cmd/CmdBypass.java index 6c7ea644..b95a30a8 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBypass.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBypass.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -13,27 +13,22 @@ public class CmdBypass extends FCommand { //this.requiredArgs.add(""); this.optionalArgs.put("on/off", "flip"); - this.permission = Permission.BYPASS.node; - this.disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.BYPASS) + .playerOnly() + .build(); } @Override - public void perform() { - fme.setIsAdminBypassing(this.argAsBool(0, !fme.isAdminBypassing())); + public void perform(CommandContext context) { + context.fPlayer.setIsAdminBypassing(context.argAsBool(0, !context.fPlayer.isAdminBypassing())); // TODO: Move this to a transient field in the model?? - if (fme.isAdminBypassing()) { - fme.msg(TL.COMMAND_BYPASS_ENABLE.toString()); - P.p.log(fme.getName() + TL.COMMAND_BYPASS_ENABLELOG.toString()); + if (context.fPlayer.isAdminBypassing()) { + context.fPlayer.msg(TL.COMMAND_BYPASS_ENABLE.toString()); + FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_BYPASS_ENABLELOG.toString()); } else { - fme.msg(TL.COMMAND_BYPASS_DISABLE.toString()); - P.p.log(fme.getName() + TL.COMMAND_BYPASS_DISABLELOG.toString()); + context.fPlayer.msg(TL.COMMAND_BYPASS_DISABLE.toString()); + FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_BYPASS_DISABLELOG.toString()); } } @@ -41,4 +36,4 @@ public class CmdBypass extends FCommand { public TL getUsageTranslation() { return TL.COMMAND_BYPASS_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdChat.java b/src/main/java/com/massivecraft/factions/cmd/CmdChat.java index 983868c0..d23946f5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdChat.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdChat.java @@ -5,6 +5,8 @@ import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.util.TL; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; public class CmdChat extends FCommand { @@ -16,33 +18,29 @@ public class CmdChat extends FCommand { //this.requiredArgs.add(""); this.optionalArgs.put("mode", "next"); - this.permission = Permission.CHAT.node; - this.disableOnLock = false; - - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CHAT) + .playerOnly() + .memberOnly() + .brigadier(ChatBrigadier.class) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { if (!Conf.factionOnlyChat) { - msg(TL.COMMAND_CHAT_DISABLED.toString()); + context.msg(TL.COMMAND_CHAT_DISABLED.toString()); return; } - String modeString = this.argAsString(0); - ChatMode modeTarget = fme.getChatMode().getNext(); + String modeString = context.argAsString(0); + ChatMode modeTarget = context.fPlayer.getChatMode().getNext(); if (modeString != null) { modeString = modeString.toLowerCase(); // Only allow Mods and higher rank to switch to this channel. if (modeString.startsWith("m")) { - if (!fme.getRole().isAtLeast(Role.MODERATOR)) { - msg(TL.COMMAND_CHAT_MOD_ONLY); + if (!context.fPlayer.getRole().isAtLeast(Role.MODERATOR)) { + context.msg(TL.COMMAND_CHAT_MOD_ONLY); return; } else modeTarget = ChatMode.MOD; } else if (modeString.startsWith("p")) { @@ -54,28 +52,28 @@ public class CmdChat extends FCommand { } else if (modeString.startsWith("t")) { modeTarget = ChatMode.TRUCE; } else { - msg(TL.COMMAND_CHAT_INVALIDMODE); + context.msg(TL.COMMAND_CHAT_INVALIDMODE); return; } } - fme.setChatMode(modeTarget); + context.fPlayer.setChatMode(modeTarget); - switch (fme.getChatMode()) { + switch (context.fPlayer.getChatMode()) { case MOD: - msg(TL.COMMAND_CHAT_MODE_MOD); + context.msg(TL.COMMAND_CHAT_MODE_MOD); break; case PUBLIC: - msg(TL.COMMAND_CHAT_MODE_PUBLIC); + context.msg(TL.COMMAND_CHAT_MODE_PUBLIC); break; case ALLIANCE: - msg(TL.COMMAND_CHAT_MODE_ALLIANCE); + context.msg(TL.COMMAND_CHAT_MODE_ALLIANCE); break; case TRUCE: - msg(TL.COMMAND_CHAT_MODE_TRUCE); + context.msg(TL.COMMAND_CHAT_MODE_TRUCE); break; default: - msg(TL.COMMAND_CHAT_MODE_FACTION); + context.msg(TL.COMMAND_CHAT_MODE_FACTION); break; } } @@ -84,4 +82,16 @@ public class CmdChat extends FCommand { public TL getUsageTranslation() { return TL.COMMAND_CHAT_DESCRIPTION; } + + protected class ChatBrigadier implements BrigadierProvider { + @Override + public ArgumentBuilder get(ArgumentBuilder parent) { + return parent.then(LiteralArgumentBuilder.literal("public")) + .then(LiteralArgumentBuilder.literal("mod")) + .then(LiteralArgumentBuilder.literal("alliance")) + .then(LiteralArgumentBuilder.literal("faction")) + .then(LiteralArgumentBuilder.literal("truce")); + } + } + } \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdChatSpy.java b/src/main/java/com/massivecraft/factions/cmd/CmdChatSpy.java index 97231e66..7e56bbc4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdChatSpy.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdChatSpy.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -12,26 +12,21 @@ public class CmdChatSpy extends FCommand { this.optionalArgs.put("on/off", "flip"); - this.permission = Permission.CHATSPY.node; - this.disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CHATSPY) + .playerOnly() + .build(); } @Override - public void perform() { - fme.setSpyingChat(this.argAsBool(0, !fme.isSpyingChat())); + public void perform(CommandContext context) { + context.fPlayer.setSpyingChat(context.argAsBool(0, !context.fPlayer.isSpyingChat())); - if (fme.isSpyingChat()) { - fme.msg(TL.COMMAND_CHATSPY_ENABLE); - P.p.log(fme.getName() + TL.COMMAND_CHATSPY_ENABLELOG.toString()); + if (context.fPlayer.isSpyingChat()) { + context.msg(TL.COMMAND_CHATSPY_ENABLE); + FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CHATSPY_ENABLELOG.toString()); } else { - fme.msg(TL.COMMAND_CHATSPY_DISABLE); - P.p.log(fme.getName() + TL.COMMAND_CHATSPY_DISABLELOG.toString()); + context.msg(TL.COMMAND_CHATSPY_DISABLE); + FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CHATSPY_DISABLELOG.toString()); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdCheckpoint.java b/src/main/java/com/massivecraft/factions/cmd/CmdCheckpoint.java index da55d25b..20e08ad6 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdCheckpoint.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdCheckpoint.java @@ -14,46 +14,45 @@ public class CmdCheckpoint extends FCommand { this.optionalArgs.put("set", ""); - this.permission = Permission.CHECKPOINT.node; - this.disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CHECKPOINT) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("checkpoints.Enabled")) { - fme.msg(TL.COMMAND_CHECKPOINT_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("checkpoints.Enabled")) { + context.msg(TL.COMMAND_CHECKPOINT_DISABLED); return; } - if (args.size() == 1) { - FLocation myLocation = new FLocation(fme.getPlayer().getLocation()); + if (context.args.size() == 1) { + FLocation myLocation = new FLocation(context.player.getLocation()); Faction myLocFaction = Board.getInstance().getFactionAt(myLocation); - if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == fme.getFaction()) { - fme.getFaction().setCheckpoint(fme.getPlayer().getLocation()); - fme.msg(TL.COMMAND_CHECKPOINT_SET); + if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == context.faction) { + context.faction.setCheckpoint(context.player.getLocation()); + context.msg(TL.COMMAND_CHECKPOINT_SET); return; } else { - fme.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION); + context.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION); return; } } - if (fme.getFaction().getCheckpoint() == null) { - fme.msg(TL.COMMAND_CHECKPOINT_NOT_SET); + if (context.faction.getCheckpoint() == null) { + context.msg(TL.COMMAND_CHECKPOINT_NOT_SET); return; } - FLocation checkLocation = new FLocation(fme.getFaction().getCheckpoint()); + FLocation checkLocation = new FLocation(context.faction.getCheckpoint()); Faction checkfaction = Board.getInstance().getFactionAt(checkLocation); - if (checkfaction.getId().equals(Factions.getInstance().getWilderness().getId()) || checkfaction.getId().equals(fme.getFaction().getId())) { - fme.msg(TL.COMMAND_CHECKPOINT_GO); - this.doWarmUp(WarmUpUtil.Warmup.CHECKPOINT, TL.WARMUPS_NOTIFY_TELEPORT, "Checkpoint", () -> fme.getPlayer().teleport(fme.getFaction().getCheckpoint()), this.p.getConfig().getLong("warmups.f-checkpoint", 0)); + if (checkfaction.getId().equals(Factions.getInstance().getWilderness().getId()) || checkfaction.getId().equals(context.faction.getId())) { + context.msg(TL.COMMAND_CHECKPOINT_GO); + + context.doWarmUp(WarmUpUtil.Warmup.CHECKPOINT, TL.WARMUPS_NOTIFY_TELEPORT, "Checkpoint", () -> { + context.player.teleport(context.faction.getCheckpoint()); + }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-checkpoint", 0)); } else { - fme.msg(TL.COMMAND_CHECKPOINT_CLAIMED); + context.msg(TL.COMMAND_CHECKPOINT_CLAIMED); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdColeader.java b/src/main/java/com/massivecraft/factions/cmd/CmdColeader.java index 0a16ab94..d19f84a3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdColeader.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdColeader.java @@ -18,61 +18,51 @@ public class CmdColeader extends FCommand { this.aliases.add("setco"); this.optionalArgs.put("player name", "name"); - //this.optionalArgs.put("", ""); - this.permission = Permission.COLEADER.node; - this.disableOnLock = true; - - - senderMustBePlayer = false; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = true; + this.requirements = new CommandRequirements.Builder(Permission.COLEADER) + .memberOnly() + .withRole(Role.LEADER) + .build(); } @Override - public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + public void perform(CommandContext context) { + FPlayer you = context.argAsBestFPlayerMatch(0); if (you == null) { FancyMessage msg = new FancyMessage(TL.COMMAND_COLEADER_CANDIDATES.toString()).color(ChatColor.GOLD); - for (FPlayer player : myFaction.getFPlayersWhereRole(Role.NORMAL)) { + for (FPlayer player : context.faction.getFPlayersWhereRole(Role.NORMAL)) { String s = player.getName(); msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " coleader " + s); } - for (FPlayer player : myFaction.getFPlayersWhereRole(Role.MODERATOR)) { + for (FPlayer player : context.faction.getFPlayersWhereRole(Role.MODERATOR)) { String s = player.getName(); msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " coleader " + s); } - sendFancyMessage(msg); + context.sendFancyMessage(msg); return; } - boolean permAny = Permission.COLEADER_ANY.has(sender, false); + boolean permAny = Permission.COLEADER_ANY.has(context.sender, false); Faction targetFaction = you.getFaction(); - if (you.isAlt()) { - msg(ChatColor.RED + "You can not promote alt accounts."); + if (targetFaction != context.faction && !permAny) { + context.msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(context.fPlayer, true)); return; } - if (targetFaction != myFaction && !permAny) { - msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(fme, true)); + if (context.fPlayer != null && context.fPlayer.getRole() != Role.LEADER && !permAny) { + context.msg(TL.COMMAND_COLEADER_NOTADMIN); return; } - if (fme != null && fme.getRole() != Role.LEADER && !permAny) { - msg(TL.COMMAND_COLEADER_NOTADMIN); - return; - } - - if (you == fme && !permAny) { - msg(TL.COMMAND_COLEADER_SELF); + if (you == context.fPlayer && !permAny) { + context.msg(TL.COMMAND_COLEADER_SELF); return; } if (you.getRole() == Role.LEADER) { - msg(TL.COMMAND_COLEADER_TARGETISADMIN); + context.msg(TL.COMMAND_COLEADER_TARGETISADMIN); return; } @@ -80,12 +70,12 @@ public class CmdColeader extends FCommand { // Revoke you.setRole(Role.MODERATOR); targetFaction.msg(TL.COMMAND_COLEADER_REVOKED, you.describeTo(targetFaction, true)); - msg(TL.COMMAND_COLEADER_REVOKES, you.describeTo(fme, true)); + context.msg(TL.COMMAND_COLEADER_REVOKES, you.describeTo(context.fPlayer, true)); } else { // Give you.setRole(Role.COLEADER); targetFaction.msg(TL.COMMAND_COLEADER_PROMOTED, you.describeTo(targetFaction, true)); - msg(TL.COMMAND_COLEADER_PROMOTES, you.describeTo(fme, true)); + context.msg(TL.COMMAND_COLEADER_PROMOTES, you.describeTo(context.fPlayer, true)); } } @@ -94,3 +84,4 @@ public class CmdColeader extends FCommand { return TL.COMMAND_COLEADER_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdConfig.java b/src/main/java/com/massivecraft/factions/cmd/CmdConfig.java index 8cf6179e..ea1a9824 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdConfig.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdConfig.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.ChatColor; @@ -24,20 +24,14 @@ public class CmdConfig extends FCommand { this.requiredArgs.add("setting"); this.requiredArgs.add("value"); - this.errorOnToManyArgs = false; - this.permission = Permission.CONFIG.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CONFIG) + .noErrorOnManyArgs() + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // store a lookup map of lowercase field names paired with proper capitalization field names // that way, if the person using this command messes up the capitalization, we can fix that if (properFieldNames.isEmpty()) { @@ -47,22 +41,22 @@ public class CmdConfig extends FCommand { } } - String field = this.argAsString(0).toLowerCase(); + String field = context.argAsString(0).toLowerCase(); if (field.startsWith("\"") && field.endsWith("\"")) { field = field.substring(1, field.length() - 1); } String fieldName = properFieldNames.get(field); if (fieldName == null || fieldName.isEmpty()) { - msg(TL.COMMAND_CONFIG_NOEXIST, field); + context.msg(TL.COMMAND_CONFIG_NOEXIST, field); return; } String success; - StringBuilder value = new StringBuilder(args.get(1)); - for (int i = 2; i < args.size(); i++) { - value.append(' ').append(args.get(i)); + StringBuilder value = new StringBuilder(context.args.get(1)); + for (int i = 2; i < context.args.size(); i++) { + value.append(' ').append(context.args.get(i)); } try { @@ -70,7 +64,7 @@ public class CmdConfig extends FCommand { // boolean if (target.getType() == boolean.class) { - boolean targetValue = this.strAsBool(value.toString()); + boolean targetValue = context.strAsBool(value.toString()); target.setBoolean(null, targetValue); if (targetValue) { @@ -87,7 +81,7 @@ public class CmdConfig extends FCommand { target.setInt(null, intVal); success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + intVal + "."; } catch (NumberFormatException ex) { - sendMessage(TL.COMMAND_CONFIG_INTREQUIRED.format(fieldName)); + context.sendMessage(TL.COMMAND_CONFIG_INTREQUIRED.format(fieldName)); return; } } @@ -99,7 +93,7 @@ public class CmdConfig extends FCommand { target.setLong(null, longVal); success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + longVal + "."; } catch (NumberFormatException ex) { - sendMessage(TL.COMMAND_CONFIG_LONGREQUIRED.format(fieldName)); + context.sendMessage(TL.COMMAND_CONFIG_LONGREQUIRED.format(fieldName)); return; } } @@ -111,7 +105,7 @@ public class CmdConfig extends FCommand { target.setDouble(null, doubleVal); success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + doubleVal + "."; } catch (NumberFormatException ex) { - sendMessage(TL.COMMAND_CONFIG_DOUBLEREQUIRED.format(fieldName)); + context.sendMessage(TL.COMMAND_CONFIG_DOUBLEREQUIRED.format(fieldName)); return; } } @@ -123,7 +117,7 @@ public class CmdConfig extends FCommand { target.setFloat(null, floatVal); success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + floatVal + "."; } catch (NumberFormatException ex) { - sendMessage(TL.COMMAND_CONFIG_FLOATREQUIRED.format(fieldName)); + context.sendMessage(TL.COMMAND_CONFIG_FLOATREQUIRED.format(fieldName)); return; } } @@ -143,7 +137,7 @@ public class CmdConfig extends FCommand { } if (newColor == null) { - sendMessage(TL.COMMAND_CONFIG_INVALID_COLOUR.format(fieldName, value.toString().toUpperCase())); + context.sendMessage(TL.COMMAND_CONFIG_INVALID_COLOUR.format(fieldName, value.toString().toUpperCase())); return; } target.set(null, newColor); @@ -157,7 +151,7 @@ public class CmdConfig extends FCommand { // not a Set, somehow, and that should be the only collection we're using in Conf.java if (targSet.getRawType() != Set.class) { - sendMessage(TL.COMMAND_CONFIG_INVALID_COLLECTION.format(fieldName)); + context.sendMessage(TL.COMMAND_CONFIG_INVALID_COLLECTION.format(fieldName)); return; } @@ -170,7 +164,7 @@ public class CmdConfig extends FCommand { } if (newMat == null) { - sendMessage(TL.COMMAND_CONFIG_INVALID_MATERIAL.format(fieldName, value.toString().toUpperCase())); + context.sendMessage(TL.COMMAND_CONFIG_INVALID_MATERIAL.format(fieldName, value.toString().toUpperCase())); return; } @@ -210,31 +204,31 @@ public class CmdConfig extends FCommand { // Set of unknown type else { - sendMessage(TL.COMMAND_CONFIG_INVALID_TYPESET.format(fieldName)); + context.sendMessage(TL.COMMAND_CONFIG_INVALID_TYPESET.format(fieldName)); return; } } // unknown type else { - sendMessage(TL.COMMAND_CONFIG_ERROR_TYPE.format(fieldName, target.getClass().getName())); + context.sendMessage(TL.COMMAND_CONFIG_ERROR_TYPE.format(fieldName, target.getClass().getName())); return; } } catch (NoSuchFieldException ex) { - sendMessage(TL.COMMAND_CONFIG_ERROR_MATCHING.format(fieldName)); + context.sendMessage(TL.COMMAND_CONFIG_ERROR_MATCHING.format(fieldName)); return; } catch (IllegalAccessException ex) { - sendMessage(TL.COMMAND_CONFIG_ERROR_SETTING.format(fieldName, value.toString())); + context.sendMessage(TL.COMMAND_CONFIG_ERROR_SETTING.format(fieldName, value.toString())); return; } if (!success.isEmpty()) { - if (sender instanceof Player) { - sendMessage(success); - P.p.log(success + TL.COMMAND_CONFIG_LOG.format((Player) sender)); - } else // using P.p.log() instead of sendMessage if run from server console so that "[Factions v#.#.#]" is prepended in server log + if (context.sender instanceof Player) { + context.sendMessage(success); + FactionsPlugin.getInstance().log(success + TL.COMMAND_CONFIG_LOG.format((Player) context.sender)); + } else // using FactionsPlugin.getInstance().log() instead of sendMessage if run from server console so that "[Factions v#.#.#]" is prepended in server log { - P.p.log(success); + FactionsPlugin.getInstance().log(success); } } // save change to disk diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdConvert.java b/src/main/java/com/massivecraft/factions/cmd/CmdConvert.java index f2b780c9..b7a55a2e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdConvert.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdConvert.java @@ -11,26 +11,26 @@ public class CmdConvert extends FCommand { public CmdConvert() { this.aliases.add("convert"); - - this.permission = Permission.CONVERT.node; - this.requiredArgs.add("[MYSQL|JSON]"); + + this.requirements = new CommandRequirements.Builder(Permission.CONVERT) + .build(); } @Override - public void perform() { - if (!(this.sender instanceof ConsoleCommandSender)) { - this.sender.sendMessage(TL.GENERIC_CONSOLEONLY.toString()); + public void perform(CommandContext context) { + if (!(context.sender instanceof ConsoleCommandSender)) { + context.sender.sendMessage(TL.GENERIC_CONSOLEONLY.toString()); } - Backend nb = Backend.valueOf(this.argAsString(0).toUpperCase()); + Backend nb = Backend.valueOf(context.argAsString(0).toUpperCase()); if (nb == Conf.backEnd) { - this.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_RUNNING.toString()); + context.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_RUNNING.toString()); return; } if (nb == Backend.JSON) { FactionsJSON.convertTo(); } else { - this.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_INVALID.toString()); + context.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_INVALID.toString()); return; } Conf.backEnd = nb; @@ -41,4 +41,4 @@ public class CmdConvert extends FCommand { return TL.COMMAND_CONVERT_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdCoords.java b/src/main/java/com/massivecraft/factions/cmd/CmdCoords.java index e6b3bad3..33aae200 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdCoords.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdCoords.java @@ -12,23 +12,18 @@ public class CmdCoords extends FCommand { this.aliases.add("coords"); this.aliases.add("coord"); - this.permission = Permission.COORD.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.COORD) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - Location location = fme.getPlayer().getLocation(); - String message = TL.COMMAND_COORDS_MESSAGE.toString().replace("{player}", fme.getPlayer().getDisplayName()).replace("{x}", (int) location.getX() + "") + public void perform(CommandContext context) { + Location location = context.player.getLocation(); + String message = TL.COMMAND_COORDS_MESSAGE.toString().replace("{player}", context.player.getDisplayName()).replace("{x}", (int) location.getX() + "") .replace("{y}", (int) location.getY() + "").replace("{z}", (int) location.getZ() + "").replace("{world}", location.getWorld().getName()); - for (FPlayer fPlayer : fme.getFaction().getFPlayers()) { + for (FPlayer fPlayer : context.faction.getFPlayers()) { fPlayer.sendMessage(message); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java b/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java index 85513e51..a38b5833 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java @@ -20,58 +20,46 @@ public class CmdCreate extends FCommand { this.aliases.add("create"); this.requiredArgs.add("faction tag"); - //this.optionalArgs.put("", ""); - this.permission = Permission.CREATE.node; - this.disableOnLock = true; - this.disableOnSpam = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CREATE) + .playerOnly() + .build(); } @Override - public void perform() { - String tag = this.argAsString(0); + public void perform(CommandContext context) { + String tag = context.argAsString(0); - if (fme.hasFaction()) { - msg(TL.COMMAND_CREATE_MUSTLEAVE); - return; - } - - if (!fme.isCooldownEnded("create")) { - fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("create")); + if (context.fPlayer.hasFaction()) { + context.msg(TL.COMMAND_CREATE_MUSTLEAVE); return; } if (Factions.getInstance().isTagTaken(tag)) { - msg(TL.COMMAND_CREATE_INUSE); + context.msg(TL.COMMAND_CREATE_INUSE); return; } ArrayList tagValidationErrors = MiscUtil.validateTag(tag); if (tagValidationErrors.size() > 0) { - sendMessage(tagValidationErrors); + context.sendMessage(tagValidationErrors); return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay - if (!canAffordCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE.toString())) { + if (!context.canAffordCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE.toString())) { return; } // trigger the faction creation event (cancellable) - FactionCreateEvent createEvent = new FactionCreateEvent(me, tag); + FactionCreateEvent createEvent = new FactionCreateEvent(context.player, tag); Bukkit.getServer().getPluginManager().callEvent(createEvent); if (createEvent.isCancelled()) { return; } // then make 'em pay (if applicable) - if (!payForCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE, TL.COMMAND_CREATE_FORCREATE)) { + if (!context.payForCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE, TL.COMMAND_CREATE_FORCREATE)) { return; } @@ -79,7 +67,7 @@ public class CmdCreate extends FCommand { // TODO: Why would this even happen??? Auto increment clash?? if (faction == null) { - msg(TL.COMMAND_CREATE_ERROR); + context.msg(TL.COMMAND_CREATE_ERROR); return; } @@ -87,39 +75,29 @@ public class CmdCreate extends FCommand { faction.setTag(tag); // trigger the faction join event for the creator - FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(me), faction, FPlayerJoinEvent.PlayerJoinReason.CREATE); + FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), faction, FPlayerJoinEvent.PlayerJoinReason.CREATE); Bukkit.getServer().getPluginManager().callEvent(joinEvent); // join event cannot be cancelled or you'll have an empty faction // finish setting up the FPlayer - fme.setFaction(faction, false); + context.fPlayer.setFaction(faction, false); // We should consider adding the role just AFTER joining the faction. // That way we don't have to mess up deleting more stuff. // And prevent the user from being returned to NORMAL after deleting his old faction. - fme.setRole(Role.LEADER); - if (P.p.getConfig().getBoolean("faction-creation-broadcast", true)) { + context.fPlayer.setRole(Role.LEADER); + if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-creation-broadcast", true)) { for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) { - follower.msg(TL.COMMAND_CREATE_CREATED, fme.describeTo(follower, true), faction.getTag(follower)); + follower.msg(TL.COMMAND_CREATE_CREATED, context.fPlayer.getName(), faction.getTag(follower)); } } - msg(TL.COMMAND_CREATE_YOUSHOULD, p.cmdBase.cmdDescription.getUseageTemplate()); - - if (Conf.econEnabled) - Econ.setBalance(faction.getAccountId(), Conf.econFactionStartingBalance); - - + context.msg(TL.COMMAND_CREATE_YOUSHOULD, FactionsPlugin.getInstance().cmdBase.cmdDescription.getUseageTemplate(context)); + if (Conf.econEnabled) Econ.setBalance(faction.getAccountId(), Conf.econFactionStartingBalance); if (Conf.logFactionCreate) - P.p.log(fme.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag); - - if (P.p.getConfig().getBoolean("fpaypal.Enabled")) - this.fme.msg(TL.COMMAND_PAYPALSET_CREATED); - + FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag); + if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) + context.msg(TL.COMMAND_PAYPALSET_CREATED); if (Conf.useCustomDefaultPermissions) faction.setDefaultPerms(); - if (Conf.usePermissionHints) fme.msg(TL.COMMAND_HINT_PERMISSION); - - - fme.setCooldown("create", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-create") * 1000)); - + if (Conf.usePermissionHints) context.msg(TL.COMMAND_HINT_PERMISSION); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java index 62c2b72e..284e5283 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; @@ -19,51 +20,59 @@ public class CmdDeinvite extends FCommand { this.aliases.add("deinv"); this.optionalArgs.put("player name", "name"); - //this.optionalArgs.put("", ""); - this.permission = Permission.DEINVITE.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = true; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.DEINVITE) + .memberOnly() + .build(); } @Override - public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.INVITE); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites"); - return; - } - } - if (you == null) { + public void perform(CommandContext context) { + + // Check if arg 0 == null do you don't have + // `No player "null" could be found.` message. + if (context.args.get(0) == null) { FancyMessage msg = new FancyMessage(TL.COMMAND_DEINVITE_CANDEINVITE.toString()).color(ChatColor.GOLD); - for (String id : myFaction.getInvites()) { + for (String id : context.faction.getInvites()) { FPlayer fp = FPlayers.getInstance().getById(id); String name = fp != null ? fp.getName() : id; msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_DEINVITE_CLICKTODEINVITE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name); } - sendFancyMessage(msg); + context.sendFancyMessage(msg); return; } - if (you.getFaction() == myFaction) { - msg(TL.COMMAND_DEINVITE_ALREADYMEMBER, you.getName(), myFaction.getTag()); - msg(TL.COMMAND_DEINVITE_MIGHTWANT, p.cmdBase.cmdKick.getUseageTemplate(false)); + FPlayer you = context.argAsBestFPlayerMatch(0); + if (!context.fPlayer.isAdminBypassing()) { + Access access = context.faction.getAccess(context.fPlayer, PermissableAction.INVITE); + if (access != Access.ALLOW && context.fPlayer.getRole() != Role.LEADER) { + context.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites"); + return; + } + } + + if (you == null) { + FancyMessage msg = new FancyMessage(TL.COMMAND_DEINVITE_CANDEINVITE.toString()).color(ChatColor.GOLD); + for (String id : context.faction.getInvites()) { + FPlayer fp = FPlayers.getInstance().getById(id); + String name = fp != null ? fp.getName() : id; + msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_DEINVITE_CLICKTODEINVITE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name); + } + context.sendFancyMessage(msg); return; } - myFaction.deinvite(you); + if (you.getFaction() == context.faction) { + context.msg(TL.COMMAND_DEINVITE_ALREADYMEMBER, you.getName(), context.faction.getTag()); + context.msg(TL.COMMAND_DEINVITE_MIGHTWANT, FactionsPlugin.getInstance().cmdBase.cmdKick.getUseageTemplate(context)); + return; + } - you.msg(TL.COMMAND_DEINVITE_REVOKED, fme.describeTo(you), myFaction.describeTo(you)); + context.faction.deinvite(you); - myFaction.msg(TL.COMMAND_DEINVITE_REVOKES, fme.describeTo(myFaction), you.describeTo(myFaction)); + you.msg(TL.COMMAND_DEINVITE_REVOKED, context.fPlayer.describeTo(you), context.faction.describeTo(you)); + + context.faction.msg(TL.COMMAND_DEINVITE_REVOKES, context.fPlayer.describeTo(context.faction), you.describeTo(context.faction)); } @Override @@ -72,3 +81,4 @@ public class CmdDeinvite extends FCommand { } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDelFWarp.java b/src/main/java/com/massivecraft/factions/cmd/CmdDelFWarp.java index 3103fef2..7f9f2b4f 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDelFWarp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDelFWarp.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -13,29 +13,29 @@ public class CmdDelFWarp extends FCommand { this.aliases.add("dw"); this.aliases.add("deletewarp"); this.requiredArgs.add("warp name"); - this.senderMustBeMember = true; - this.senderMustBeModerator = true; - this.senderMustBePlayer = true; - this.permission = Permission.SETWARP.node; + this.requirements = new CommandRequirements.Builder(Permission.SETWARP) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - String warp = argAsString(0); - if (myFaction.isWarp(warp)) { - if (!transact(fme)) { + public void perform(CommandContext context) { + String warp = context.argAsString(0); + if (context.faction.isWarp(warp)) { + if (!transact(context.fPlayer, context)) { return; } - myFaction.removeWarp(warp); - fme.msg(TL.COMMAND_DELFWARP_DELETED, warp); + context.faction.removeWarp(warp); + context.msg(TL.COMMAND_DELFWARP_DELETED, warp); } else { - fme.msg(TL.COMMAND_DELFWARP_INVALID, warp); + context.msg(TL.COMMAND_DELFWARP_INVALID, warp); } } - private boolean transact(FPlayer player) { - return !P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(P.p.getConfig().getDouble("warp-cost.delwarp", 5), TL.COMMAND_DELFWARP_TODELETE.toString(), TL.COMMAND_DELFWARP_FORDELETE.toString()); + private boolean transact(FPlayer player, CommandContext context) { + return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.delwarp", 5), TL.COMMAND_DELFWARP_TODELETE.toString(), TL.COMMAND_DELFWARP_FORDELETE.toString()); } @Override @@ -43,3 +43,4 @@ public class CmdDelFWarp extends FCommand { return TL.COMMAND_DELFWARP_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDescription.java b/src/main/java/com/massivecraft/factions/cmd/CmdDescription.java index a0e6d00a..c8142268 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDescription.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDescription.java @@ -15,41 +15,35 @@ public class CmdDescription extends FCommand { this.aliases.add("description"); this.requiredArgs.add("desc"); - this.errorOnToManyArgs = false; - //this.optionalArgs - this.permission = Permission.DESCRIPTION.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.DESCRIPTION) + .playerOnly() + .memberOnly() + .noErrorOnManyArgs() + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostDesc, TL.COMMAND_DESCRIPTION_TOCHANGE, TL.COMMAND_DESCRIPTION_FORCHANGE)) { + if (!context.payForCommand(Conf.econCostDesc, TL.COMMAND_DESCRIPTION_TOCHANGE, TL.COMMAND_DESCRIPTION_FORCHANGE)) { return; } // 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. - myFaction.setDescription(TextUtil.implode(args, " ").replaceAll("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2")); + context.faction.setDescription(TextUtil.implode(context.args, " ").replaceAll("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2")); if (!Conf.broadcastDescriptionChanges) { - fme.msg(TL.COMMAND_DESCRIPTION_CHANGED, myFaction.describeTo(fme)); - fme.sendMessage(myFaction.getDescription()); + context.msg(TL.COMMAND_DESCRIPTION_CHANGED, context.faction.describeTo(context.fPlayer)); + context.sendMessage(context.faction.getDescription()); return; } // Broadcast the description to everyone for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { - fplayer.msg(TL.COMMAND_DESCRIPTION_CHANGES, myFaction.describeTo(fplayer)); - fplayer.sendMessage(myFaction.getDescription()); // players can inject "&" or "`" or "" or whatever in their description; &k is particularly interesting looking + fplayer.msg(TL.COMMAND_DESCRIPTION_CHANGES, context.faction.describeTo(fplayer)); + fplayer.sendMessage(context.faction.getDescription()); // players can inject "&" or "`" or "" or whatever in their description; &k is particularly interesting looking } } @@ -58,4 +52,4 @@ public class CmdDescription extends FCommand { return TL.COMMAND_DESCRIPTION_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java index 4c113bec..68b783cd 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java @@ -9,6 +9,7 @@ import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; +import org.bukkit.command.ConsoleCommandSender; import java.util.HashMap; @@ -23,87 +24,71 @@ public class CmdDisband extends FCommand { super(); this.aliases.add("disband"); - //this.requiredArgs.add(""); this.optionalArgs.put("faction tag", "yours"); - this.permission = Permission.DISBAND.node; - this.disableOnLock = true; - this.disableOnSpam = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.DISBAND) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // The faction, default to your own.. but null if console sender. - Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); - if (faction == null) { - return; - } + Faction faction = context.argAsFaction(0, context.fPlayer == null ? null : context.faction); + if (faction == null) return; + boolean isMyFaction = context.fPlayer != null && faction == context.faction; - if (!fme.isCooldownEnded("disband")) { - fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("disband")); - return; - } - - boolean isMyFaction = fme != null && faction == myFaction; - - if (isMyFaction) { - if (!assertMinRole(Role.LEADER)) { - return; - } - } else { - if (!Permission.DISBAND_ANY.has(sender, true)) { + if (!isMyFaction) { + if (!Permission.DISBAND_ANY.has(context.sender, true)) { return; } } - if (fme != null && !fme.isAdminBypassing()) { - Access access = faction.getAccess(fme, PermissableAction.DISBAND); - if (fme.getRole() != Role.LEADER && faction.getFPlayerLeader() != fme && access != Access.ALLOW) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag()); + if (context.fPlayer != null && !context.fPlayer.isAdminBypassing()) { + Access access = faction.getAccess(context.fPlayer, PermissableAction.DISBAND); + if (context.fPlayer.getRole() != Role.LEADER && faction.getFPlayerLeader() != context.fPlayer && access != Access.ALLOW) { + context.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag()); return; } } if (!faction.isNormal()) { - msg(TL.COMMAND_DISBAND_IMMUTABLE.toString()); + context.msg(TL.COMMAND_DISBAND_IMMUTABLE.toString()); return; } if (faction.isPermanent()) { - msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString()); + context.msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString()); + return; + } + + // THis means they are a console command sender. + if (context.player == null) { + faction.disband(null, PlayerDisbandReason.PLUGIN); return; } // check for tnt before disbanding. - - if ((fme != null && !disbandMap.containsKey(me.getUniqueId().toString())) && faction.getTnt() > 0) { - msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + "")); - disbandMap.put(me.getUniqueId().toString(), faction.getId()); - Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> disbandMap.remove(me.getUniqueId().toString()), 200L); - } else if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) { - if (P.p.getConfig().getBoolean("faction-disband-broadcast", true)) { + if (!disbandMap.containsKey(context.player.getUniqueId().toString()) && faction.getTnt() > 0) { + context.msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + "")); + disbandMap.put(context.player.getUniqueId().toString(), faction.getId()); + Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> disbandMap.remove(context.player.getUniqueId().toString()), 200L); + } else if (faction.getId().equals(disbandMap.get(context.player.getUniqueId().toString())) || faction.getTnt() == 0) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast", true)) { for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) { - String amountString = senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(follower); - UtilFly.checkFly(this.fme, Board.getInstance().getFactionAt(new FLocation(follower))); + String amountString = context.sender instanceof ConsoleCommandSender ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(follower); + UtilFly.checkFly(context.fPlayer, Board.getInstance().getFactionAt(new FLocation(follower))); if (follower.getFaction() == faction) { follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString); - fme.setCooldown("disband", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-disband") * 1000)); } else { follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower)); } } - faction.disband(me, PlayerDisbandReason.COMMAND); + faction.disband(context.player, PlayerDisbandReason.COMMAND); } else { - faction.disband(me, PlayerDisbandReason.COMMAND); - me.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER)); + faction.disband(context.player, PlayerDisbandReason.COMMAND); + context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER)); } } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFGlobal.java b/src/main/java/com/massivecraft/factions/cmd/CmdFGlobal.java index 1a796ebb..8fee8817 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFGlobal.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFGlobal.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; -import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; @@ -12,36 +12,28 @@ public class CmdFGlobal extends FCommand { public static List toggled = new ArrayList<>(); public CmdFGlobal() { - super(); this.aliases.add("gchat"); this.aliases.add("global"); this.aliases.add("globalchat"); - this.disableOnLock = false; - this.disableOnSpam = false; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.GLOBALCHAT) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - - Player p = (Player) sender; - + public void perform(CommandContext context) { // /f global - if (toggled.contains(p.getUniqueId())) { - toggled.remove(p.getUniqueId()); + if (toggled.contains(context.player.getUniqueId())) { + toggled.remove(context.player.getUniqueId()); } else { - toggled.add(p.getUniqueId()); + toggled.add(context.player.getUniqueId()); } - fme.msg(TL.COMMAND_F_GLOBAL_TOGGLE, toggled.contains(p.getUniqueId()) ? "disabled" : "enabled"); + context.msg(TL.COMMAND_F_GLOBAL_TOGGLE, toggled.contains(context.player.getUniqueId()) ? "disabled" : "enabled"); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java b/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java index 8f3b5ec8..19c38699 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java @@ -1,12 +1,10 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.FactionWarpsFrame; import com.massivecraft.factions.util.WarmUpUtil; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; @@ -23,63 +21,56 @@ public class CmdFWarp extends FCommand { this.optionalArgs.put("warpname", "warpname"); this.optionalArgs.put("password", "password"); - - this.permission = Permission.WARP.node; - this.senderMustBeMember = true; - this.senderMustBeModerator = false; + this.requirements = new CommandRequirements.Builder(Permission.WARP) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.WARP) + .build(); } @Override - public void perform() { - //TODO: check if in combat. - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.WARP); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use warps"); - return; - } - } + public void perform(CommandContext context) { - - if (args.size() == 0) { - new FactionWarpsFrame(fme.getFaction()).buildGUI(fme); - } else if (args.size() > 2) { - fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT); + if (context.args.size() == 0) { + new FactionWarpsFrame(context.faction).buildGUI(context.fPlayer); + } else if (context.args.size() > 2) { + context.msg(TL.COMMAND_FWARP_COMMANDFORMAT); } else { - final String warpName = argAsString(0); - final String passwordAttempt = argAsString(1); + final String warpName = context.argAsString(0); + final String passwordAttempt = context.argAsString(1); - if (myFaction.isWarp(argAsString(0))) { + if (context.faction.isWarp(context.argAsString(0))) { // Check if requires password and if so, check if valid. CASE SENSITIVE - if (myFaction.hasWarpPassword(warpName) && !myFaction.isWarpPassword(warpName, passwordAttempt)) { - fme.msg(TL.COMMAND_FWARP_INVALID_PASSWORD); + if (context.faction.hasWarpPassword(warpName) && !context.faction.isWarpPassword(warpName, passwordAttempt)) { + context.faction.msg(TL.COMMAND_FWARP_INVALID_PASSWORD); return; } // Check transaction AFTER password check. - if (!transact(fme)) return; - final FPlayer fPlayer = fme; - final UUID uuid = fme.getPlayer().getUniqueId(); - this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> { + if (!transact(context.fPlayer, context)) return; + + final FPlayer fPlayer = context.fPlayer; + final UUID uuid = context.player.getUniqueId(); + context.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> { Player player = Bukkit.getPlayer(uuid); if (player != null) { player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation()); fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName); } - }, this.p.getConfig().getLong("warmups.f-warp", 0)); + }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-warp", 0)); } else { - fme.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName); + context.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName); } } } - private boolean transact(FPlayer player) { - return !P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(P.p.getConfig().getDouble("warp-cost.warp", 5), TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString()); + private boolean transact(FPlayer player, CommandContext context) { + return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.warp", 5), TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString()); } @Override public TL getUsageTranslation() { return TL.COMMAND_FWARP_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java index 529ba870..a5df7056 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java @@ -4,14 +4,12 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.*; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; -import com.massivecraft.factions.util.Particles.ParticleEffect; import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; import org.bukkit.GameMode; -import org.bukkit.Particle; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -28,52 +26,27 @@ public class CmdFly extends FCommand { public CmdFly() { super(); this.aliases.add("fly"); - this.optionalArgs.put("on/off", "flip"); - - this.permission = Permission.FLY.node; - this.senderMustBeMember = true; - this.senderMustBeModerator = false; + this.requirements = new CommandRequirements.Builder(Permission.FLY) + .playerOnly() + .memberOnly() + .build(); } public static void startParticles() { - // Just a secondary check. - if (!P.p.getConfig().getBoolean("ffly.Particles.Enabled")) { - return; - } - id = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { + id = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { for (String name : flyMap.keySet()) { Player player = Bukkit.getPlayer(name); - if (player == null) { - continue; - } - if (!player.isFlying()) { - continue; - } - if (!P.p.mc17) { - if (player.getGameMode() == GameMode.SPECTATOR) { - continue; - } + if (player == null) continue; + if (!player.isFlying()) continue; + if (!FactionsPlugin.getInstance().mc17) { + if (player.getGameMode() == GameMode.SPECTATOR) continue; } - if (FPlayers.getInstance().getByPlayer(player).isVanished()) { - // Actually, vanished players (such as admins) should not display particles to prevent others from knowing their vanished assistance for moderation. - // But we can keep it as a config. - if (P.p.getConfig().getBoolean("ffly.Particles.Enable-While-Vanished")) { - return; - } - continue; - } - if (P.p.useNonPacketParticles) { - // 1.9+ based servers will use the built in particleAPI instead of packet based. - // any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working. - // So setting the amount to 0 spawns 1 in the precise location - player.getWorld().spawnParticle(Particle.CLOUD, player.getLocation().add(0, -0.35, 0), 0); - } else { - ParticleEffect.CLOUD.display((float) 0, (float) 0, (float) 0, (float) 0, 3, player.getLocation().add(0, -0.35, 0), 16); - } + FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); + fplayer.isVanished(); } if (flyMap.keySet().size() == 0) { @@ -84,7 +57,7 @@ public class CmdFly extends FCommand { } public static void startFlyCheck() { - flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { //threw the exception for now, until I recode fly :( Cringe. + flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { //threw the exception for now, until I recode fly :( Cringe. checkTaskState(); if (flyMap.keySet().size() != 0) { for (String name : flyMap.keySet()) { @@ -95,7 +68,7 @@ public class CmdFly extends FCommand { if (player == null || !player.isFlying() || player.getGameMode() == GameMode.CREATIVE - || !P.p.mc17 && player.getGameMode() == GameMode.SPECTATOR) { + || !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) { continue; } FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); @@ -105,7 +78,7 @@ public class CmdFly extends FCommand { flyMap.remove(name); continue; } - if (fPlayer.checkIfNearbyEnemies()) { + if (player.hasPermission("factions.fly.bypassnearbyenemycheck") || fPlayer.checkIfNearbyEnemies()) { continue; } FLocation myFloc = new FLocation(player.getLocation()); @@ -174,57 +147,53 @@ public class CmdFly extends FCommand { } @Override - public void perform() { + public void perform(CommandContext context) { // Disabled by default. - if (!P.p.getConfig().getBoolean("enable-faction-flight", false)) { - fme.msg(TL.COMMAND_FLY_DISABLED); + if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) { + context.fPlayer.msg(TL.COMMAND_FLY_DISABLED); return; } - FLocation myfloc = new FLocation(me.getLocation()); + FLocation myfloc = new FLocation(context.player.getLocation()); Faction toFac = Board.getInstance().getFactionAt(myfloc); - if (!checkBypassPerms(fme, me, toFac)) return; - List entities = this.me.getNearbyEntities(16.0D, 256.0D, 16.0D); + if (!checkBypassPerms(context.fPlayer, context.player, toFac)) return; + List entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D); for (int i = 0; i <= entities.size() - 1; ++i) { if (entities.get(i) instanceof Player) { Player eplayer = (Player) entities.get(i); FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer); - if (efplayer.getRelationTo(this.fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) { - this.fme.msg(TL.COMMAND_FLY_CHECK_ENEMY); + if (efplayer.getRelationTo(context.fPlayer) == Relation.ENEMY && !efplayer.isStealthEnabled()) { + context.msg(TL.COMMAND_FLY_CHECK_ENEMY); return; } } } - if (args.size() == 0) { - toggleFlight(fme.isFlying(), me); - } else if (args.size() == 1) { - toggleFlight(argAsBool(0), me); + if (context.args.size() == 0) { + toggleFlight(context.fPlayer.isFlying(), context.fPlayer, context); + } else if (context.args.size() == 1) { + toggleFlight(context.argAsBool(0), context.fPlayer, context); } } - private void toggleFlight(final boolean toggle, final Player player) { + private void toggleFlight(final boolean toggle, final FPlayer fme, CommandContext context) { if (toggle) { fme.setFlying(false); - flyMap.remove(player.getName()); + flyMap.remove(fme.getPlayer().getName()); return; } + if (fme.canFlyAtLocation()) - this.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> { + context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> { fme.setFlying(true); - flyMap.put(player.getName(), true); - if (id == -1) { - if (P.p.getConfig().getBoolean("ffly.Particles.Enabled")) { - startParticles(); - } - } + flyMap.put(fme.getPlayer().getName(), true); if (flyid == -1) { startFlyCheck(); } - }, this.p.getConfig().getLong("warmups.f-fly", 0)); + }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0)); } @Override @@ -232,4 +201,4 @@ public class CmdFly extends FCommand { return TL.COMMAND_FLY_DESCRIPTION; } -} \ No newline at end of file +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFocus.java b/src/main/java/com/massivecraft/factions/cmd/CmdFocus.java index e17b5661..56ce1f18 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFocus.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFocus.java @@ -1,49 +1,45 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.scoreboards.FTeamWrapper; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; -public class CmdFocus - extends FCommand { +public class CmdFocus extends FCommand { public CmdFocus() { aliases.add("focus"); requiredArgs.add("player"); - permission = Permission.FOCUS.node; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = true; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.FOCUS) + .playerOnly() + .memberOnly() + .build(); } - public void perform() { - if (!P.p.getConfig().getBoolean("ffocus.Enabled")) { - fme.msg(TL.GENERIC_DISABLED); + @Override + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled")) { + context.msg(TL.GENERIC_DISABLED); return; } - FPlayer target = argAsFPlayer(0); + FPlayer target = context.argAsFPlayer(0); if (target == null) { return; } - if (target.getFaction().getId().equalsIgnoreCase(myFaction.getId())) { - fme.msg(TL.COMMAND_FOCUS_SAMEFACTION); + if (target.getFaction().getId().equalsIgnoreCase(context.faction.getId())) { + context.msg(TL.COMMAND_FOCUS_SAMEFACTION); return; } - if ((myFaction.getFocused() != null) && (myFaction.getFocused().equalsIgnoreCase(target.getName()))) { - myFaction.setFocused(null); - myFaction.msg(TL.COMMAND_FOCUS_NO_LONGER, target.getName()); + if ((context.faction.getFocused() != null) && (context.faction.getFocused().equalsIgnoreCase(target.getName()))) { + context.faction.setFocused(null); + context.faction.msg(TL.COMMAND_FOCUS_NO_LONGER, target.getName()); FTeamWrapper.updatePrefixes(target.getFaction()); return; } - myFaction.msg(TL.COMMAND_FOCUS_FOCUSING, target.getName()); - myFaction.setFocused(target.getName()); + context.faction.msg(TL.COMMAND_FOCUS_FOCUSING, target.getName()); + context.faction.setFocused(target.getName()); FTeamWrapper.updatePrefixes(target.getFaction()); } @@ -51,4 +47,3 @@ public class CmdFocus return TL.COMMAND_FOCUS_DESCRIPTION; } } - diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdGetVault.java b/src/main/java/com/massivecraft/factions/cmd/CmdGetVault.java index 937b4dc9..eaf6c798 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdGetVault.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdGetVault.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Location; @@ -11,48 +11,42 @@ import org.bukkit.inventory.ItemStack; public class CmdGetVault extends FCommand { public CmdGetVault() { super(); - this.aliases.add("getvault"); - this.permission = Permission.GETVAULT.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.GETVAULT) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("fvault.Enabled")) { - fme.sendMessage("This command is disabled!"); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fvault.Enabled")) { + context.fPlayer.sendMessage("This command is disabled!"); return; } - Location vaultLocation = fme.getFaction().getVault(); - ItemStack vault = P.p.createItem(Material.CHEST, 1, (short) 0, P.p.color(P.p.getConfig().getString("fvault.Item.Name")), P.p.colorList(P.p.getConfig().getStringList("fvault.Item.Lore"))); + Location vaultLocation = context.faction.getVault(); + ItemStack vault = FactionsPlugin.getInstance().createItem(Material.CHEST, 1, (short) 0, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fvault.Item.Name")), FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fvault.Item.Lore"))); //check if vault is set if (vaultLocation != null) { - fme.msg(TL.COMMAND_GETVAULT_ALREADYSET); + context.msg(TL.COMMAND_GETVAULT_ALREADYSET); return; } //has enough money? - int amount = P.p.getConfig().getInt("fvault.Price"); - if (!fme.hasMoney(amount)) { + int amount = FactionsPlugin.getInstance().getConfig().getInt("fvault.Price"); + if (!context.fPlayer.hasMoney(amount)) { return; } //success :) - fme.takeMoney(amount); - me.getInventory().addItem(vault); - fme.msg(TL.COMMAND_GETVAULT_RECEIVE); + context.fPlayer.takeMoney(amount); + context.player.getInventory().addItem(vault); + context.fPlayer.msg(TL.COMMAND_GETVAULT_RECEIVE); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHelp.java b/src/main/java/com/massivecraft/factions/cmd/CmdHelp.java index ad4f741f..e1081b04 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHelp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHelp.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -24,14 +24,8 @@ public class CmdHelp extends FCommand { //this.requiredArgs.add(""); this.optionalArgs.put("page", "1"); - this.permission = Permission.HELP.node; - this.disableOnLock = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.HELP) + .build(); } //----------------------------------------------// @@ -39,80 +33,80 @@ public class CmdHelp extends FCommand { //----------------------------------------------// @Override - public void perform() { - if (P.p.getConfig().getBoolean("use-old-help", true)) { + public void perform(CommandContext context) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("use-old-help", true)) { if (helpPages == null) { - updateHelp(); + updateHelp(context); } - int page = this.argAsInt(0, 1); - sendMessage(p.txt.titleize("Factions Help (" + page + "/" + helpPages.size() + ")")); + int page = context.argAsInt(0, 1); + context.sendMessage(FactionsPlugin.getInstance().txt.titleize("Factions Help (" + page + "/" + helpPages.size() + ")")); page -= 1; if (page < 0 || page >= helpPages.size()) { - msg(TL.COMMAND_HELP_404.format(String.valueOf(page))); + context.msg(TL.COMMAND_HELP_404.format(String.valueOf(page))); return; } - sendMessage(helpPages.get(page)); + context.sendMessage(helpPages.get(page)); return; } - ConfigurationSection help = P.p.getConfig().getConfigurationSection("help"); + ConfigurationSection help = FactionsPlugin.getInstance().getConfig().getConfigurationSection("help"); if (help == null) { - help = P.p.getConfig().createSection("help"); // create new help section + help = FactionsPlugin.getInstance().getConfig().createSection("help"); // create new help section List error = new ArrayList<>(); error.add("&cUpdate help messages in config.yml!"); error.add("&cSet use-old-help for legacy help messages"); help.set("'1'", error); // add default error messages } - String pageArg = this.argAsString(0, "1"); + String pageArg = context.argAsString(0, "1"); List page = help.getStringList(pageArg); if (page == null || page.isEmpty()) { - msg(TL.COMMAND_HELP_404.format(pageArg)); + context.msg(TL.COMMAND_HELP_404.format(pageArg)); return; } for (String helpLine : page) { - sendMessage(P.p.txt.parse(helpLine)); + context.sendMessage(FactionsPlugin.getInstance().txt.parse(helpLine)); } } - public void updateHelp() { + public void updateHelp(CommandContext context) { helpPages = new ArrayList<>(); ArrayList pageLines; pageLines = new ArrayList<>(); - pageLines.add(p.cmdBase.cmdHelp.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdList.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdShow.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdPower.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdJoin.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdLeave.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdChat.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdToggleAllianceChat.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdHome.getUseageTemplate(true)); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_NEXTCREATE.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdHelp.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdList.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdShow.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPower.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdJoin.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdLeave.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdChat.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdToggleAllianceChat.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdHome.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_NEXTCREATE.toString())); helpPages.add(pageLines); pageLines = new ArrayList<>(); - pageLines.add(p.cmdBase.cmdCreate.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdDescription.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdTag.getUseageTemplate(true)); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_INVITATIONS.toString())); - pageLines.add(p.cmdBase.cmdOpen.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdInvite.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdDeinvite.getUseageTemplate(true)); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_HOME.toString())); - pageLines.add(p.cmdBase.cmdSethome.getUseageTemplate(true)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdCreate.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdDescription.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdTag.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_INVITATIONS.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdOpen.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdInvite.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdDeinvite.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_HOME.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSethome.getUseageTemplate(context)); helpPages.add(pageLines); if (Econ.isSetup() && Conf.econEnabled && Conf.bankEnabled) { pageLines = new ArrayList<>(); pageLines.add(""); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_BANK_1.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_BANK_2.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_BANK_3.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_BANK_1.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_BANK_2.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_BANK_3.toString())); pageLines.add(""); - pageLines.add(p.cmdBase.cmdMoney.getUseageTemplate(true)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdMoney.getUseageTemplate(context)); pageLines.add(""); pageLines.add(""); pageLines.add(""); @@ -120,94 +114,94 @@ public class CmdHelp extends FCommand { } pageLines = new ArrayList<>(); - pageLines.add(p.cmdBase.cmdClaim.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdAutoClaim.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdUnclaim.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdUnclaimall.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdKick.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdMod.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdAdmin.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdTitle.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdSB.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdSeeChunk.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdStatus.getUseageTemplate(true)); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PLAYERTITLES.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdClaim.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdAutoClaim.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdUnclaim.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdUnclaimall.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdKick.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdMod.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdAdmin.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdTitle.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSB.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSeeChunk.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdStatus.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PLAYERTITLES.toString())); helpPages.add(pageLines); pageLines = new ArrayList<>(); - pageLines.add(p.cmdBase.cmdMap.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdBoom.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdOwner.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdOwnerList.getUseageTemplate(true)); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_OWNERSHIP_1.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_OWNERSHIP_2.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_OWNERSHIP_3.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdMap.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdBoom.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdOwner.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdOwnerList.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_OWNERSHIP_1.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_OWNERSHIP_2.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_OWNERSHIP_3.toString())); helpPages.add(pageLines); pageLines = new ArrayList<>(); - pageLines.add(p.cmdBase.cmdDisband.getUseageTemplate(true)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdDisband.getUseageTemplate(context)); pageLines.add(""); - pageLines.add(p.cmdBase.cmdRelationAlly.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdRelationNeutral.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdRelationEnemy.getUseageTemplate(true)); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_1.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_2.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_3.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_4.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdRelationAlly.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdRelationNeutral.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdRelationEnemy.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_1.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_2.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_3.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_4.toString())); helpPages.add(pageLines); pageLines = new ArrayList<>(); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_5.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_6.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_7.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_5.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_6.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_7.toString())); pageLines.add(TL.COMMAND_HELP_RELATIONS_8.toString()); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_9.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_10.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_11.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_12.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_13.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_9.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_10.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_11.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_12.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_13.toString())); helpPages.add(pageLines); pageLines = new ArrayList<>(); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_1.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_2.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_3.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_1.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_2.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_3.toString())); pageLines.add(TL.COMMAND_HELP_PERMISSIONS_4.toString()); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_5.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_6.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_7.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_8.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_9.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_5.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_6.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_7.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_8.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_9.toString())); helpPages.add(pageLines); pageLines = new ArrayList<>(); pageLines.add(TL.COMMAND_HELP_MOAR_1.toString()); - pageLines.add(p.cmdBase.cmdBypass.getUseageTemplate(true)); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_ADMIN_1.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_ADMIN_2.toString())); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_ADMIN_3.toString())); - pageLines.add(p.cmdBase.cmdSafeunclaimall.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdWarunclaimall.getUseageTemplate(true)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdBypass.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_ADMIN_1.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_ADMIN_2.toString())); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_ADMIN_3.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSafeunclaimall.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdWarunclaimall.getUseageTemplate(context)); //TODO:TL - pageLines.add(p.txt.parse("Note: " + p.cmdBase.cmdUnclaim.getUseageTemplate(false) + P.p.txt.parse("") + " works on safe/war zones as well.")); - pageLines.add(p.cmdBase.cmdPeaceful.getUseageTemplate(true)); + pageLines.add(FactionsPlugin.getInstance().txt.parse("Note: " + FactionsPlugin.getInstance().cmdBase.cmdUnclaim.getUseageTemplate(context) + FactionsPlugin.getInstance().txt.parse("") + " works on safe/war zones as well.")); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPeaceful.getUseageTemplate(context)); helpPages.add(pageLines); pageLines = new ArrayList<>(); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_MOAR_2.toString())); - pageLines.add(p.cmdBase.cmdChatSpy.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdPermanent.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdPermanentPower.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdPowerBoost.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdConfig.getUseageTemplate(true)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_MOAR_2.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdChatSpy.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPermanent.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPermanentPower.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPowerBoost.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdConfig.getUseageTemplate(context)); helpPages.add(pageLines); pageLines = new ArrayList<>(); - pageLines.add(p.txt.parse(TL.COMMAND_HELP_MOAR_3.toString())); - pageLines.add(p.cmdBase.cmdLock.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdReload.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdSaveAll.getUseageTemplate(true)); - pageLines.add(p.cmdBase.cmdVersion.getUseageTemplate(true)); + pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_MOAR_3.toString())); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdLock.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdReload.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSaveAll.getUseageTemplate(context)); + pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdVersion.getUseageTemplate(context)); helpPages.add(pageLines); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java index 0379f4b4..36d838ad 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.*; +import com.massivecraft.factions.integration.Essentials; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; @@ -23,106 +24,68 @@ public class CmdHome extends FCommand { super(); this.aliases.add("home"); - this.optionalArgs.put("faction", "yours"); - //this.requiredArgs.add(""); - //this.optionalArgs.put("", ""); - - this.permission = Permission.HOME.node; - this.disableOnLock = false; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.HOME) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.HOME) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // TODO: Hide this command on help also. - - if (!Conf.homesEnabled) { - fme.msg(TL.COMMAND_HOME_DISABLED); + context.msg(TL.COMMAND_HOME_DISABLED); return; } if (!Conf.homesTeleportCommandEnabled) { - fme.msg(TL.COMMAND_HOME_TELEPORTDISABLED); + context.msg(TL.COMMAND_HOME_TELEPORTDISABLED); return; } - Faction factionArg; - - if (args.isEmpty()) - factionArg = myFaction; - else - factionArg = argAsFaction(0); - - - if (factionArg.isSystemFaction()) { - fme.msg(TL.GENERIC_NOPERMISSION, "teleport to system faction home"); + if (!context.faction.hasHome()) { + context.msg(TL.COMMAND_HOME_NOHOME.toString() + (context.fPlayer.getRole().value < Role.MODERATOR.value ? TL.GENERIC_ASKYOURLEADER.toString() : TL.GENERIC_YOUSHOULD.toString())); + context.sendMessage(FactionsPlugin.getInstance().cmdBase.cmdSethome.getUseageTemplate(context)); return; } - myFaction = factionArg; - - - if (myFaction.isWilderness()) + if (!Conf.homesTeleportAllowedFromEnemyTerritory && context.fPlayer.isInEnemyTerritory()) { + context.msg(TL.COMMAND_HOME_INENEMY); return; + } - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.HOME); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home"); + if (!Conf.homesTeleportAllowedFromDifferentWorld && context.player.getWorld().getUID() != context.faction.getHome().getWorld().getUID()) { + context.msg(TL.COMMAND_HOME_WRONGWORLD); + return; + } + + if (!context.fPlayer.isAdminBypassing()) { + Access access = context.faction.getAccess(context.fPlayer, PermissableAction.HOME); + if (access != Access.ALLOW && context.fPlayer.getRole() != Role.LEADER) { + context.fPlayer.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home"); return; } } - if (!myFaction.hasHome()) { - fme.msg(TL.COMMAND_HOME_NOHOME.toString() + (fme.getRole().value < Role.MODERATOR.value ? TL.GENERIC_ASKYOURLEADER.toString() : TL.GENERIC_YOUSHOULD.toString())); - fme.sendMessage(p.cmdBase.cmdSethome.getUseageTemplate()); - return; - } - - - if (!Conf.homesTeleportAllowedFromEnemyTerritory && fme.isInEnemyTerritory()) { - fme.msg(TL.COMMAND_HOME_INENEMY); - return; - } - - if (!Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID()) { - fme.msg(TL.COMMAND_HOME_WRONGWORLD); - return; - } - - if (!fme.isAdminBypassing()) { - Access access = fme.getFaction().getAccess(fme, PermissableAction.HOME); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home"); - return; - } - } - - Faction faction = Board.getInstance().getFactionAt(new FLocation(me.getLocation())); - final Location loc = me.getLocation().clone(); + Faction faction = Board.getInstance().getFactionAt(new FLocation(context.player.getLocation())); + 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() && (!fme.isInOwnTerritory() || !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)) { + if (Conf.homesTeleportAllowedEnemyDistance > 0 && !faction.isSafeZone() && (!context.fPlayer.isInOwnTerritory() || !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)) { World w = loc.getWorld(); double x = loc.getX(); double y = loc.getY(); double z = loc.getZ(); - for (Player p : me.getServer().getOnlinePlayers()) { - if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) { + for (Player p : context.player.getServer().getOnlinePlayers()) { + if (p == null || !p.isOnline() || p.isDead() || p == context.player || p.getWorld() != w) { continue; } FPlayer fp = FPlayers.getInstance().getByPlayer(p); - if (fme.getRelationTo(fp) != Relation.ENEMY || fp.isVanished()) { + if (context.fPlayer.getRelationTo(fp) != Relation.ENEMY || fp.isVanished()) { continue; } @@ -137,37 +100,33 @@ public class CmdHome extends FCommand { continue; } - fme.msg(TL.COMMAND_HOME_ENEMYNEAR, String.valueOf(Conf.homesTeleportAllowedEnemyDistance)); + context.msg(TL.COMMAND_HOME_ENEMYNEAR, String.valueOf(Conf.homesTeleportAllowedEnemyDistance)); return; } } - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostHome, TL.COMMAND_HOME_TOTELEPORT.toString(), TL.COMMAND_HOME_FORTELEPORT.toString())) { + if (!context.payForCommand(Conf.econCostHome, TL.COMMAND_HOME_TOTELEPORT.toString(), TL.COMMAND_HOME_FORTELEPORT.toString())) { return; } - // TODO: Need to document this better confusing everyone, removed for now. -// // if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown) -// if (Essentials.handleTeleport(me, myFaction.getHome())) { -// return; -// } + // if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown) + if (Essentials.handleTeleport(context.player, context.faction.getHome())) { + return; + } - - this.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", () -> { + context.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", () -> { // Create a smoke effect if (Conf.homesTeleportCommandSmokeEffectEnabled) { List smokeLocations = new ArrayList<>(); smokeLocations.add(loc); smokeLocations.add(loc.add(0, 1, 0)); - smokeLocations.add(CmdHome.this.myFaction.getHome()); - smokeLocations.add(CmdHome.this.myFaction.getHome().clone().add(0, 1, 0)); + smokeLocations.add(context.faction.getHome()); + smokeLocations.add(context.faction.getHome().clone().add(0, 1, 0)); SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness); } - - CmdHome.this.me.teleport(CmdHome.this.myFaction.getHome()); - }, this.p.getConfig().getLong("warmups.f-home", 0)); + context.player.teleport(context.faction.getHome()); + }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-home", 0)); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInspect.java b/src/main/java/com/massivecraft/factions/cmd/CmdInspect.java index 5e465e4a..4972bed0 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInspect.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInspect.java @@ -9,26 +9,21 @@ public class CmdInspect extends FCommand { this.aliases.add("inspect"); this.aliases.add("ins"); - this.permission = Permission.INSPECT.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.INSPECT) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (fme.isInspectMode()) { - fme.setInspectMode(false); - msg(TL.COMMAND_INSPECT_DISABLED_MSG); + public void perform(CommandContext context) { + if (context.fPlayer.isInspectMode()) { + context.fPlayer.setInspectMode(false); + context.msg(TL.COMMAND_INSPECT_DISABLED_MSG); } else { - fme.setInspectMode(true); - msg(TL.COMMAND_INSPECT_ENABLED); + context.fPlayer.setInspectMode(true); + context.msg(TL.COMMAND_INSPECT_ENABLED); } } @@ -38,3 +33,4 @@ public class CmdInspect extends FCommand { return TL.COMMAND_INSPECT_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInventorySee.java b/src/main/java/com/massivecraft/factions/cmd/CmdInventorySee.java index 668e301f..fce45aa7 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInventorySee.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInventorySee.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; @@ -24,44 +24,38 @@ public class CmdInventorySee extends FCommand { this.requiredArgs.add("member name"); - this.permission = Permission.INVSEE.node; - this.disableOnLock = true; - this.disableOnSpam = false; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.INVSEE) + .playerOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("f-inventory-see.Enabled")) { - fme.msg(TL.GENERIC_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled")) { + context.msg(TL.GENERIC_DISABLED); return; } - Access use = myFaction.getAccess(fme, PermissableAction.TERRITORY); - if (use == Access.DENY || (use == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) { - fme.msg(TL.GENERIC_NOPERMISSION, "territory"); + Access use = context.fPlayer.getFaction().getAccess(context.fPlayer, PermissableAction.TERRITORY); + if (use == Access.DENY || (use == Access.UNDEFINED && !context.assertMinRole(Role.MODERATOR))) { + context.msg(TL.GENERIC_NOPERMISSION, "territory"); return; } - ArrayList fplayers = myFaction.getOnlinePlayers(); + ArrayList fplayers = context.fPlayer.getFaction().getOnlinePlayers(); - FPlayer targetInv = argAsFPlayer(0); + FPlayer targetInv = context.argAsFPlayer(0); if (targetInv == null || !fplayers.contains(targetInv.getPlayer())) { - fme.msg(TL.PLAYER_NOT_FOUND, Objects.requireNonNull(targetInv).toString()); + context.msg(TL.PLAYER_NOT_FOUND, Objects.requireNonNull(targetInv).toString()); return; } - Inventory inventory = Bukkit.createInventory(me, 36, targetInv.getName() + "'s Inventory"); + Inventory inventory = Bukkit.createInventory(context.player, 36, targetInv.getName() + "'s Inventory"); for (int i = 0; i < 36; i++) if (targetInv.getPlayer().getInventory().getItem(i) != null) inventory.setItem(i, targetInv.getPlayer().getInventory().getItem(i)); - me.openInventory(inventory); + context.player.openInventory(inventory); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java index a177d8f7..fdaf6e57 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java @@ -2,9 +2,8 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import mkremins.fanciful.FancyMessage; @@ -18,72 +17,58 @@ public class CmdInvite extends FCommand { this.aliases.add("inv"); this.requiredArgs.add("player name"); - //this.optionalArgs.put("", ""); - this.permission = Permission.INVITE.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.INVITE) + .playerOnly() + .withAction(PermissableAction.INVITE) + .build(); } @Override - public void perform() { - FPlayer target = this.argAsBestFPlayerMatch(0); + public void perform(CommandContext context) { + FPlayer target = context.argAsBestFPlayerMatch(0); if (target == null) { return; } - if (target.getFaction() == myFaction) { - msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), myFaction.getTag()); - msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdKick.getUseageTemplate(false)); + if (target.getFaction() == context.faction) { + context.msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), context.faction.getTag()); + context.msg(TL.GENERIC_YOUMAYWANT.toString() + FactionsPlugin.getInstance().cmdBase.cmdKick.getUseageTemplate(context)); return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostInvite, TL.COMMAND_INVITE_TOINVITE.toString(), TL.COMMAND_INVITE_FORINVITE.toString())) { + if (!context.payForCommand(Conf.econCostInvite, TL.COMMAND_INVITE_TOINVITE.toString(), TL.COMMAND_INVITE_FORINVITE.toString())) { return; } - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.INVITE); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites"); - return; - } - } - - if (myFaction.isInvited(target)) { - fme.msg(TL.COMMAND_INVITE_ALREADYINVITED, target.getName()); + if (context.faction.isInvited(target)) { + context.msg(TL.COMMAND_INVITE_ALREADYINVITED, target.getName()); return; } - if (myFaction.isBanned(target)) { - fme.msg(TL.COMMAND_INVITE_BANNED, target.getName()); + if (context.faction.isBanned(target)) { + context.msg(TL.COMMAND_INVITE_BANNED, target.getName()); return; } - myFaction.invite(target); + context.faction.invite(target); // Send the invitation to the target player when online, otherwise just ignore if (target.isOnline()) { // Tooltips, colors, and commands only apply to the string immediately before it. - FancyMessage message = new FancyMessage(fme.describeTo(target, true)) + FancyMessage message = new FancyMessage(context.fPlayer.describeTo(target, true)) .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) - .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()) + .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag()) .then(TL.COMMAND_INVITE_INVITEDYOU.toString()) .color(ChatColor.YELLOW) .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) - .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()) - .then(myFaction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) - .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()); + .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag()) + .then(context.faction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) + .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag()); message.send(target.getPlayer()); } - myFaction.msg(TL.COMMAND_INVITE_INVITED, fme.describeTo(myFaction, true), target.describeTo(myFaction)); + context.faction.msg(TL.COMMAND_INVITE_INVITED, context.fPlayer.describeTo(context.faction, true), target.describeTo(context.faction)); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdJoin.java b/src/main/java/com/massivecraft/factions/cmd/CmdJoin.java index bfc4ddcb..1fb9718c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdJoin.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdJoin.java @@ -12,120 +12,96 @@ public class CmdJoin extends FCommand { public CmdJoin() { super(); this.aliases.add("join"); - this.requiredArgs.add("faction name"); this.optionalArgs.put("player", "you"); - this.permission = Permission.JOIN.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.JOIN) + .playerOnly() + .build(); } @Override - public void perform() { - Faction faction = this.argAsFaction(0); + public void perform(CommandContext context) { + Faction faction = context.argAsFaction(0); if (faction == null) { return; } - FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false); - boolean samePlayer = fplayer == fme; + FPlayer fplayer = context.argAsBestFPlayerMatch(1, context.fPlayer, false); + boolean samePlayer = fplayer == context.fPlayer; - if (!samePlayer && !Permission.JOIN_OTHERS.has(sender, false)) { - msg(TL.COMMAND_JOIN_CANNOTFORCE); + if (!samePlayer && !Permission.JOIN_OTHERS.has(context.sender, false)) { + context.msg(TL.COMMAND_JOIN_CANNOTFORCE); return; } if (!faction.isNormal()) { - msg(TL.COMMAND_JOIN_SYSTEMFACTION); + context.msg(TL.COMMAND_JOIN_SYSTEMFACTION); return; } if (faction == fplayer.getFaction()) { - //TODO:TL - msg(TL.COMMAND_JOIN_ALREADYMEMBER, fplayer.describeTo(fme, true), (samePlayer ? "are" : "is"), faction.getTag(fme)); + context.msg(TL.COMMAND_JOIN_ALREADYMEMBER, fplayer.describeTo(context.fPlayer, true), (samePlayer ? "are" : "is"), faction.getTag(context.fPlayer)); return; } - if (Conf.factionMemberLimit > 0 && faction.getFPlayers().size() >= Conf.factionMemberLimit) { - msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(fme), Conf.factionMemberLimit, fplayer.describeTo(fme, false)); + if (Conf.factionMemberLimit > 0 && faction.getFPlayers().size() >= getFactionMemberLimit(faction)) { + context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), getFactionMemberLimit(faction), fplayer.describeTo(context.fPlayer, false)); return; } if (fplayer.hasFaction()) { - //TODO:TL - msg(TL.COMMAND_JOIN_INOTHERFACTION, fplayer.describeTo(fme, true), (samePlayer ? "your" : "their")); + context.msg(TL.COMMAND_JOIN_INOTHERFACTION, fplayer.describeTo(context.fPlayer, true), (samePlayer ? "your" : "their")); return; } if (!Conf.canLeaveWithNegativePower && fplayer.getPower() < 0) { - msg(TL.COMMAND_JOIN_NEGATIVEPOWER, fplayer.describeTo(fme, true)); + context.msg(TL.COMMAND_JOIN_NEGATIVEPOWER, fplayer.describeTo(context.fPlayer, true)); return; } - if (!(faction.getOpen() || faction.isInvited(fplayer) || fme.isAdminBypassing() || Permission.JOIN_ANY.has(sender, false))) { - msg(TL.COMMAND_JOIN_REQUIRESINVITATION); + if (!(faction.getOpen() || faction.isInvited(fplayer) || context.fPlayer.isAdminBypassing() || Permission.JOIN_ANY.has(context.sender, false))) { + context.msg(TL.COMMAND_JOIN_REQUIRESINVITATION); if (samePlayer) { faction.msg(TL.COMMAND_JOIN_ATTEMPTEDJOIN, fplayer.describeTo(faction, true)); } return; } - int level = faction.getUpgrade(UpgradeType.MEMBERS); - - int limit = 0; - - if (level == 0) { - limit = Conf.factionMemberLimit; - } else { - limit = P.p.getConfig().getInt("fupgrades.MainMenu.Members.Members-Limit.level-" + level); - } - - if (limit > 0 && faction.getFPlayers().size() >= limit && !faction.altInvited(fme)) { - msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(fme), limit, fplayer.describeTo(fme, false)); - return; - } int altLimit = Conf.factionAltMemberLimit; - if (altLimit > 0 && faction.getAltPlayers().size() >= altLimit && !faction.altInvited(fme)) { - msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(fme), altLimit, fplayer.describeTo(fme, false)); + if (altLimit > 0 && faction.getAltPlayers().size() >= altLimit && !faction.altInvited(context.fPlayer)) { + context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), altLimit, fplayer.describeTo(context.fPlayer, false)); return; } - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay - if (samePlayer && !canAffordCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString())) { + if (samePlayer && !context.canAffordCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString())) { return; } // Check for ban - if (!fme.isAdminBypassing() && faction.isBanned(fme)) { - fme.msg(TL.COMMAND_JOIN_BANNED, faction.getTag(fme)); + if (!context.fPlayer.isAdminBypassing() && faction.isBanned(context.fPlayer)) { + context.msg(TL.COMMAND_JOIN_BANNED, faction.getTag(context.fPlayer)); return; } // trigger the join event (cancellable) - FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(me), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND); + FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND); Bukkit.getServer().getPluginManager().callEvent(joinEvent); if (joinEvent.isCancelled()) { return; } // then make 'em pay (if applicable) - if (samePlayer && !payForCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString(), TL.COMMAND_JOIN_FORJOIN.toString())) { + if (samePlayer && !context.payForCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString(), TL.COMMAND_JOIN_FORJOIN.toString())) { return; } - fme.msg(TL.COMMAND_JOIN_SUCCESS, fplayer.describeTo(fme, true), faction.getTag(fme)); + context.msg(TL.COMMAND_JOIN_SUCCESS, fplayer.describeTo(context.fPlayer, true), faction.getTag(context.fPlayer)); if (!samePlayer) { - fplayer.msg(TL.COMMAND_JOIN_MOVED, fme.describeTo(fplayer, true), faction.getTag(fplayer)); + fplayer.msg(TL.COMMAND_JOIN_MOVED, context.fPlayer.describeTo(fplayer, true), faction.getTag(fplayer)); } faction.msg(TL.COMMAND_JOIN_JOINED, fplayer.describeTo(faction, true)); @@ -140,18 +116,25 @@ public class CmdJoin extends FCommand { } faction.deinvite(fplayer); - fplayer.setRole(faction.getDefaultRole()); + context.fPlayer.setRole(faction.getDefaultRole()); + if (Conf.logFactionJoin) { if (samePlayer) { - P.p.log(TL.COMMAND_JOIN_JOINEDLOG.toString(), fplayer.getName(), faction.getTag()); + FactionsPlugin.getInstance().log(TL.COMMAND_JOIN_JOINEDLOG.toString(), fplayer.getName(), faction.getTag()); } else { - P.p.log(TL.COMMAND_JOIN_MOVEDLOG.toString(), fme.getName(), fplayer.getName(), faction.getTag()); + FactionsPlugin.getInstance().log(TL.COMMAND_JOIN_MOVEDLOG.toString(), context.fPlayer.getName(), fplayer.getName(), faction.getTag()); } } } + private int getFactionMemberLimit(Faction f) { + if (f.getUpgrade(UpgradeType.MEMBERS) == 0) return Conf.factionMemberLimit; + return Conf.factionMemberLimit + FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Members.Member-Boost.level-" + f.getUpgrade(UpgradeType.MEMBERS)); + } + @Override public TL getUsageTranslation() { return TL.COMMAND_JOIN_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdKick.java b/src/main/java/com/massivecraft/factions/cmd/CmdKick.java index cd4ad712..b7662261 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdKick.java @@ -3,80 +3,69 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import mkremins.fanciful.FancyMessage; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.command.ConsoleCommandSender; public class CmdKick extends FCommand { public CmdKick() { super(); this.aliases.add("kick"); - this.optionalArgs.put("player name", "player name"); - //this.optionalArgs.put("", ""); - this.permission = Permission.KICK.node; - this.disableOnLock = false; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.KICK) + .playerOnly() + .withAction(PermissableAction.KICK) + .memberOnly() + .build(); } @Override - public void perform() { - FPlayer toKick = this.argIsSet(0) ? this.argAsBestFPlayerMatch(0) : null; + public void perform(CommandContext context) { + FPlayer toKick = context.argIsSet(0) ? context.argAsBestFPlayerMatch(0) : null; if (toKick == null) { FancyMessage msg = new FancyMessage(TL.COMMAND_KICK_CANDIDATES.toString()).color(ChatColor.GOLD); - for (FPlayer player : myFaction.getFPlayersWhereRole(Role.NORMAL)) { + for (FPlayer player : context.faction.getFPlayersWhereRole(Role.NORMAL)) { String s = player.getName(); msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s); } - if (fme.getRole().isAtLeast(Role.COLEADER)) { + if (context.fPlayer.getRole().isAtLeast(Role.COLEADER)) { // For both coleader and admin, add mods. - for (FPlayer player : myFaction.getFPlayersWhereRole(Role.MODERATOR)) { + for (FPlayer player : context.faction.getFPlayersWhereRole(Role.MODERATOR)) { String s = player.getName(); msg.then(s + " ").color(ChatColor.GRAY).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s); } - if (fme.getRole() == Role.LEADER) { + if (context.fPlayer.getRole() == Role.LEADER) { // Only add coleader to this for the leader. - for (FPlayer player : myFaction.getFPlayersWhereRole(Role.COLEADER)) { + for (FPlayer player : context.faction.getFPlayersWhereRole(Role.COLEADER)) { String s = player.getName(); msg.then(s + " ").color(ChatColor.RED).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s); } } } - sendFancyMessage(msg); + context.sendFancyMessage(msg); return; } - if (fme == toKick) { - msg(TL.COMMAND_KICK_SELF); - msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdLeave.getUseageTemplate(false)); - return; - } - - if (toKick.isAlt()) { - msg(P.p.color("&cToo few arguments, &eUse like this:")); - msg(P.p.color("&b/f alts,alt kick &3")); + if (context.fPlayer == toKick) { + context.msg(TL.COMMAND_KICK_SELF); + context.msg(TL.GENERIC_YOUMAYWANT.toString() + FactionsPlugin.getInstance().cmdBase.cmdLeave.getUseageTemplate(context)); return; } Faction toKickFaction = toKick.getFaction(); if (toKickFaction.isWilderness()) { - sender.sendMessage(TL.COMMAND_KICK_NONE.toString()); + context.sender.sendMessage(TL.COMMAND_KICK_NONE.toString()); return; } @@ -85,28 +74,23 @@ public class CmdKick extends FCommand { // - Check for the kick permission. // - Make sure the player is in the faction. // - Make sure the kicked player has lower rank than the kicker. - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.KICK); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_NOPERMISSION, "kick"); + if (!context.fPlayer.isAdminBypassing()) { + if (toKickFaction != context.faction) { + context.msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(context.fPlayer, true), context.faction.describeTo(context.fPlayer)); return; } - if (toKickFaction != myFaction) { - msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(fme, true), myFaction.describeTo(fme)); - return; - } - if (toKick.getRole().value >= fme.getRole().value) { - msg(TL.COMMAND_KICK_INSUFFICIENTRANK); + if (toKick.getRole().value >= context.fPlayer.getRole().value) { + context.msg(TL.COMMAND_KICK_INSUFFICIENTRANK); return; } if (!Conf.canLeaveWithNegativePower && toKick.getPower() < 0) { - msg(TL.COMMAND_KICK_NEGATIVEPOWER); + context.msg(TL.COMMAND_KICK_NEGATIVEPOWER); return; } } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay - if (!canAffordCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString())) { + if (!context.canAffordCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString())) { return; } @@ -118,18 +102,18 @@ public class CmdKick extends FCommand { } // then make 'em pay (if applicable) - if (!payForCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString(), TL.COMMAND_KICK_FORKICK.toString())) { + if (!context.payForCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString(), TL.COMMAND_KICK_FORKICK.toString())) { return; } - toKickFaction.msg(TL.COMMAND_KICK_FACTION, fme.describeTo(toKickFaction, true), toKick.describeTo(toKickFaction, true)); + toKickFaction.msg(TL.COMMAND_KICK_FACTION, context.fPlayer.describeTo(toKickFaction, true), toKick.describeTo(toKickFaction, true)); - toKick.msg(TL.COMMAND_KICK_KICKED, fme.describeTo(toKick, true), toKickFaction.describeTo(toKick)); - if (toKickFaction != myFaction) { - fme.msg(TL.COMMAND_KICK_KICKS, toKick.describeTo(fme), toKickFaction.describeTo(fme)); + toKick.msg(TL.COMMAND_KICK_KICKED, context.fPlayer.describeTo(toKick, true), toKickFaction.describeTo(toKick)); + if (toKickFaction != context.faction) { + context.fPlayer.msg(TL.COMMAND_KICK_KICKS, toKick.describeTo(context.fPlayer), toKickFaction.describeTo(context.fPlayer)); } if (Conf.logFactionKick) { - P.p.log((senderIsConsole ? "A console command" : fme.getName()) + " kicked " + toKick.getName() + " from the faction: " + toKickFaction.getTag()); + FactionsPlugin.getInstance().log((context.sender instanceof ConsoleCommandSender ? "A console command" : context.fPlayer.getName()) + " kicked " + toKick.getName() + " from the faction: " + toKickFaction.getTag()); } if (toKick.getRole() == Role.LEADER) { toKickFaction.promoteNewLeader(); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdKillHolograms.java b/src/main/java/com/massivecraft/factions/cmd/CmdKillHolograms.java index 0ee95a2b..3b1d7ceb 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdKillHolograms.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdKillHolograms.java @@ -6,25 +6,18 @@ import com.massivecraft.factions.zcore.util.TL; public class CmdKillHolograms extends FCommand { public CmdKillHolograms() { super(); - this.aliases.add("killholos"); - this.requiredArgs.add("radius"); - this.permission = Permission.KILLHOLOS.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.KILLHOLOS) + .playerOnly() + .build(); } @Override - public void perform() { - me.sendMessage("Killing Invisible Armor Stands.."); - me.chat("/minecraft:kill @e[type=ArmorStand,r=" + argAsInt(0) + "]"); + public void perform(CommandContext context) { + context.player.sendMessage("Killing Invisible Armor Stands.."); + context.player.chat("/minecraft:kill @e[type=ArmorStand,r=" + context.argAsInt(0) + "]"); } @@ -33,3 +26,4 @@ public class CmdKillHolograms extends FCommand { return TL.COMMAND_KILLHOLOGRAMS_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdLeave.java b/src/main/java/com/massivecraft/factions/cmd/CmdLeave.java index b28f4ab6..a7a1d9c9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdLeave.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdLeave.java @@ -9,23 +9,15 @@ public class CmdLeave extends FCommand { super(); this.aliases.add("leave"); - //this.requiredArgs.add(""); - //this.optionalArgs.put("", ""); - - this.permission = Permission.LEAVE.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.LEAVE) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - fme.leave(true); + public void perform(CommandContext context) { + context.fPlayer.leave(true); } @Override @@ -33,4 +25,4 @@ public class CmdLeave extends FCommand { return TL.LEAVE_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdList.java b/src/main/java/com/massivecraft/factions/cmd/CmdList.java index 54504e88..2daffc04 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdList.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdList.java @@ -3,13 +3,12 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TagUtil; import java.util.ArrayList; -import java.util.Collections; import java.util.List; @@ -30,20 +29,15 @@ public class CmdList extends FCommand { //this.requiredArgs.add(""); this.optionalArgs.put("page", "1"); - this.permission = Permission.LIST.node; - this.disableOnLock = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.LIST) + .playerOnly() + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) + if (!context.payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) return; ArrayList factionList = Factions.getInstance().getAllFactions(); @@ -52,14 +46,14 @@ public class CmdList extends FCommand { factionList.remove(Factions.getInstance().getWarZone()); // remove exempt factions - if (fme != null && fme.getPlayer() != null && !fme.getPlayer().hasPermission("factions.show.bypassexempt")) { - List exemptFactions = P.p.getConfig().getStringList("show-exempt"); + if (context.fPlayer != null && context.fPlayer.getPlayer() != null && !context.fPlayer.getPlayer().hasPermission("factions.show.bypassexempt")) { + List exemptFactions = FactionsPlugin.getInstance().getConfig().getStringList("show-exempt"); factionList.removeIf(next -> exemptFactions.contains(next.getTag())); } // Sort by total followers first - Collections.sort(factionList, (f1, f2) -> { + factionList.sort((f1, f2) -> { int f1Size = f1.getFPlayers().size(); int f2Size = f2.getFPlayers().size(); if (f1Size < f2Size) { @@ -87,7 +81,7 @@ public class CmdList extends FCommand { factionList.add(0, Factions.getInstance().getWilderness()); final int pageheight = 9; - int pagenumber = this.argAsInt(0, 1); + int pagenumber = context.argAsInt(0, 1); int pagecount = (factionList.size() / pageheight) + 1; if (pagenumber > pagecount) { pagenumber = pagecount; @@ -101,18 +95,18 @@ public class CmdList extends FCommand { } - String header = p.getConfig().getString("list.header", defaults[0]); + String header = FactionsPlugin.getInstance().getConfig().getString("list.header", defaults[0]); header = header.replace("{pagenumber}", String.valueOf(pagenumber)).replace("{pagecount}", String.valueOf(pagecount)); - lines.add(p.txt.parse(header)); + lines.add(FactionsPlugin.getInstance().txt.parse(header)); for (Faction faction : factionList.subList(start, end)) { if (faction.isWilderness()) { - lines.add(p.txt.parse(TagUtil.parsePlain(faction, p.getConfig().getString("list.factionless", defaults[1])))); + lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, FactionsPlugin.getInstance().getConfig().getString("list.factionless", defaults[1])))); continue; } - lines.add(p.txt.parse(TagUtil.parsePlain(faction, fme, p.getConfig().getString("list.entry", defaults[2])))); + lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, context.fPlayer, FactionsPlugin.getInstance().getConfig().getString("list.entry", defaults[2])))); } - sendMessage(lines); + context.sendMessage(lines); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdLock.java b/src/main/java/com/massivecraft/factions/cmd/CmdLock.java index 37c1bdac..d0fe8b5e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdLock.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdLock.java @@ -1,5 +1,6 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -15,25 +16,17 @@ public class CmdLock extends FCommand { public CmdLock() { super(); this.aliases.add("lock"); - - //this.requiredArgs.add(""); this.optionalArgs.put("on/off", "flip"); - this.permission = Permission.LOCK.node; - this.disableOnLock = false; - - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.LOCK) + .playerOnly() + .build(); } @Override - public void perform() { - p.setLocked(this.argAsBool(0, !p.getLocked())); - msg(p.getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED); + public void perform(CommandContext context) { + FactionsPlugin.getInstance().setLocked(context.argAsBool(0, !FactionsPlugin.getInstance().getLocked())); + context.msg(FactionsPlugin.getInstance().getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED); } @Override @@ -42,3 +35,4 @@ public class CmdLock extends FCommand { } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdLogins.java b/src/main/java/com/massivecraft/factions/cmd/CmdLogins.java index b310cbd0..8176fd7e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdLogins.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdLogins.java @@ -11,17 +11,18 @@ public class CmdLogins extends FCommand { this.aliases.add("logins"); this.aliases.add("logout"); this.aliases.add("logouts"); - this.senderMustBePlayer = true; - this.senderMustBeMember = true; - this.permission = Permission.MONITOR_LOGINS.node; + this.requirements = new CommandRequirements.Builder(Permission.MONITOR_LOGINS) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - boolean monitor = fme.isMonitoringJoins(); - fme.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor)); - fme.setMonitorJoins(!monitor); + public void perform(CommandContext context) { + boolean monitor = context.fPlayer.isMonitoringJoins(); + context.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor)); + context.fPlayer.setMonitorJoins(!monitor); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdLowPower.java b/src/main/java/com/massivecraft/factions/cmd/CmdLowPower.java index 9d40fbe6..88fbf29d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdLowPower.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdLowPower.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; public class CmdLowPower extends FCommand { @@ -10,26 +11,21 @@ public class CmdLowPower extends FCommand { super(); this.aliases.add("lowpower"); - - this.disableOnLock = false; - - senderMustBePlayer = true; - - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.POWER_ANY) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { double maxPower = Conf.powerPlayerMax; String format = TL.COMMAND_LOWPOWER_FORMAT.toString(); - msg(TL.COMMAND_LOWPOWER_HEADER.toString().replace("{maxpower}", (int) maxPower + "")); - for (FPlayer fPlayer : fme.getFaction().getFPlayers()) { + context.msg(TL.COMMAND_LOWPOWER_HEADER.toString().replace("{maxpower}", (int) maxPower + "")); + for (FPlayer fPlayer : context.faction.getFPlayers()) { if (fPlayer.getPower() < maxPower) { - sendMessage(format.replace("{player}", fPlayer.getName()).replace("{player_power}", (int) fPlayer.getPower() + "").replace("{maxpower}", (int) maxPower + "")); + context.sendMessage(format.replace("{player}", fPlayer.getName()).replace("{player_power}", (int) fPlayer.getPower() + "").replace("{maxpower}", (int) maxPower + "")); } } } @@ -40,4 +36,4 @@ public class CmdLowPower extends FCommand { } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdMap.java b/src/main/java/com/massivecraft/factions/cmd/CmdMap.java index 14ec1fce..3c86e48c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdMap.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdMap.java @@ -12,54 +12,47 @@ public class CmdMap extends FCommand { public CmdMap() { super(); this.aliases.add("map"); - - //this.requiredArgs.add(""); this.optionalArgs.put("on/off", "once"); - this.permission = Permission.MAP.node; - this.disableOnLock = false; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MAP) + .playerOnly() + .build(); } @Override - public void perform() { - if (this.argIsSet(0)) { - if (this.argAsBool(0, !fme.isMapAutoUpdating())) { + public void perform(CommandContext context) { + if (context.argIsSet(0)) { + if (context.argAsBool(0, !context.fPlayer.isMapAutoUpdating())) { // Turn on // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) { + if (!context.payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) { return; } - fme.setMapAutoUpdating(true); - msg(TL.COMMAND_MAP_UPDATE_ENABLED); + context.fPlayer.setMapAutoUpdating(true); + context.msg(TL.COMMAND_MAP_UPDATE_ENABLED); // And show the map once - showMap(); + showMap(context); } else { // Turn off - fme.setMapAutoUpdating(false); - msg(TL.COMMAND_MAP_UPDATE_DISABLED); + context.fPlayer.setMapAutoUpdating(false); + context.msg(TL.COMMAND_MAP_UPDATE_DISABLED); + } } else { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostMap, TL.COMMAND_MAP_TOSHOW, TL.COMMAND_MAP_FORSHOW)) { + if (!context.payForCommand(Conf.econCostMap, TL.COMMAND_MAP_TOSHOW, TL.COMMAND_MAP_FORSHOW)) { return; } - showMap(); + showMap(context); } } - public void showMap() { - sendFancyMessage(Board.getInstance().getMap(fme, new FLocation(fme), fme.getPlayer().getLocation().getYaw())); + public void showMap(CommandContext context) { + context.sendFancyMessage(Board.getInstance().getMap(context.fPlayer, new FLocation(context.fPlayer), context.player.getLocation().getYaw())); } @Override @@ -67,4 +60,4 @@ public class CmdMap extends FCommand { return TL.COMMAND_MAP_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdMapHeight.java b/src/main/java/com/massivecraft/factions/cmd/CmdMapHeight.java index eac2f9b2..c09157bd 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdMapHeight.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdMapHeight.java @@ -10,26 +10,24 @@ public class CmdMapHeight extends FCommand { this.aliases.add("mapheight"); this.aliases.add("mh"); - this.optionalArgs.put("height", "height"); - this.permission = Permission.MAPHEIGHT.node; - - - this.senderMustBePlayer = true; + this.requirements = new CommandRequirements.Builder(Permission.MAPHEIGHT) + .playerOnly() + .build(); } @Override - public void perform() { - if (args.size() == 0) { - fme.sendMessage(TL.COMMAND_MAPHEIGHT_CURRENT.format(fme.getMapHeight())); + public void perform(CommandContext context) { + if (context.args.size() == 0) { + context.fPlayer.sendMessage(TL.COMMAND_MAPHEIGHT_CURRENT.format(context.fPlayer.getMapHeight())); return; } - int height = argAsInt(0); + int height = context.argAsInt(0); - fme.setMapHeight(height); - fme.sendMessage(TL.COMMAND_MAPHEIGHT_SET.format(fme.getMapHeight())); + context.fPlayer.setMapHeight(height); + context.msg(TL.COMMAND_MAPHEIGHT_SET.format(context.fPlayer.getMapHeight())); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdMod.java b/src/main/java/com/massivecraft/factions/cmd/CmdMod.java index a14a81f7..d325119d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdMod.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdMod.java @@ -19,58 +19,46 @@ public class CmdMod extends FCommand { this.aliases.add("setofficer"); this.optionalArgs.put("player name", "name"); - //this.optionalArgs.put("", ""); - this.permission = Permission.MOD.node; - this.disableOnLock = true; - - - senderMustBePlayer = false; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MOD) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + public void perform(CommandContext context) { + FPlayer you = context.argAsBestFPlayerMatch(0); if (you == null) { FancyMessage msg = new FancyMessage(TL.COMMAND_MOD_CANDIDATES.toString()).color(ChatColor.GOLD); - for (FPlayer player : myFaction.getFPlayersWhereRole(Role.NORMAL)) { + for (FPlayer player : context.faction.getFPlayersWhereRole(Role.NORMAL)) { String s = player.getName(); msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " mod " + s); } - sendFancyMessage(msg); + context.sendFancyMessage(msg); return; } - boolean permAny = Permission.MOD_ANY.has(sender, false); + boolean permAny = Permission.MOD_ANY.has(context.sender, false); Faction targetFaction = you.getFaction(); - - if (you.isAlt()) { - msg(ChatColor.RED + "You can not promote alt accounts."); + if (targetFaction != context.faction && !permAny) { + context.msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(context.fPlayer, true)); return; } - if (targetFaction != myFaction && !permAny) { - msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(fme, true)); + if (context.fPlayer != null && context.fPlayer.getRole() != Role.LEADER && !permAny) { + context.msg(TL.COMMAND_MOD_NOTADMIN); return; } - if (fme != null && fme.getRole() != Role.LEADER && !permAny) { - msg(TL.COMMAND_MOD_NOTADMIN); - return; - } - - if (you == fme && !permAny) { - msg(TL.COMMAND_MOD_SELF); + if (you == context.fPlayer && !permAny) { + context.msg(TL.COMMAND_MOD_SELF); return; } if (you.getRole() == Role.LEADER) { - msg(TL.COMMAND_MOD_TARGETISADMIN); + context.msg(TL.COMMAND_MOD_TARGETISADMIN); return; } @@ -78,12 +66,12 @@ public class CmdMod extends FCommand { // Revoke you.setRole(Role.NORMAL); targetFaction.msg(TL.COMMAND_MOD_REVOKED, you.describeTo(targetFaction, true)); - msg(TL.COMMAND_MOD_REVOKES, you.describeTo(fme, true)); + context.msg(TL.COMMAND_MOD_REVOKES, you.describeTo(context.fPlayer, true)); } else { // Give you.setRole(Role.MODERATOR); targetFaction.msg(TL.COMMAND_MOD_PROMOTED, you.describeTo(targetFaction, true)); - msg(TL.COMMAND_MOD_PROMOTES, you.describeTo(fme, true)); + context.msg(TL.COMMAND_MOD_PROMOTES, you.describeTo(context.fPlayer, true)); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdModifyPower.java b/src/main/java/com/massivecraft/factions/cmd/CmdModifyPower.java index 361e632f..4e5e18d2 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdModifyPower.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdModifyPower.java @@ -17,30 +17,24 @@ public class CmdModifyPower extends FCommand { this.requiredArgs.add("name"); this.requiredArgs.add("power"); - this.permission = Permission.MODIFY_POWER.node; // admin only perm. - - // Let's not require anything and let console modify this as well. - this.senderMustBeAdmin = false; - this.senderMustBePlayer = false; - this.senderMustBeMember = false; - senderMustBeColeader = false; - this.senderMustBeModerator = false; + this.requirements = new CommandRequirements.Builder(Permission.MODIFY_POWER) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // /f modify # - FPlayer player = argAsBestFPlayerMatch(0); - Double number = argAsDouble(1); // returns null if not a Double. + FPlayer player = context.argAsBestFPlayerMatch(0); + Double number = context.argAsDouble(1); // returns null if not a Double. if (player == null || number == null) { - sender.sendMessage(getHelpShort()); + context.sender.sendMessage(getHelpShort()); return; } player.alterPower(number); int newPower = player.getPowerRounded(); // int so we don't have super long doubles. - msg(TL.COMMAND_MODIFYPOWER_ADDED, number, player.getName(), newPower); + context.msg(TL.COMMAND_MODIFYPOWER_ADDED, number, player.getName(), newPower); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdNear.java b/src/main/java/com/massivecraft/factions/cmd/CmdNear.java index 2feeab45..3317f8ef 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdNear.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdNear.java @@ -2,7 +2,8 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -10,37 +11,32 @@ import org.bukkit.entity.Player; public class CmdNear extends FCommand { public CmdNear() { super(); - this.aliases.add("near"); this.aliases.add("nearby"); - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.NEAR) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("fnear.Enabled")) { - fme.msg(TL.COMMAND_NEAR_DISABLED_MSG); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fnear.Enabled")) { + context.msg(TL.COMMAND_NEAR_DISABLED_MSG); return; } - double range = P.p.getConfig().getInt("fnear.Radius"); + double range = FactionsPlugin.getInstance().getConfig().getInt("fnear.Radius"); String format = TL.COMMAND_NEAR_FORMAT.toString(); - fme.msg(TL.COMMAND_NEAR_USE_MSG); - for (Entity e : me.getNearbyEntities(range, 255, range)) { + context.msg(TL.COMMAND_NEAR_USE_MSG); + for (Entity e : context.player.getNearbyEntities(range, 255, range)) { if (e instanceof Player) { Player player = (((Player) e).getPlayer()); FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); - if (fme.getFaction() == fplayer.getFaction()) { - double distance = me.getLocation().distance(player.getLocation()); - fme.sendMessage(format.replace("{playername}", player.getDisplayName()).replace("{distance}", (int) distance + "")); + if (context.faction == fplayer.getFaction()) { + double distance = context.player.getLocation().distance(player.getLocation()); + context.sendMessage(format.replace("{playername}", player.getDisplayName()).replace("{distance}", (int) distance + "")); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdNotifications.java b/src/main/java/com/massivecraft/factions/cmd/CmdNotifications.java deleted file mode 100644 index a80d5d91..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdNotifications.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.zcore.util.TL; - -public class CmdNotifications extends FCommand { - - public CmdNotifications() { - this.aliases.add("notifications"); - this.aliases.add("messages"); - this.optionalArgs.put("on/off", "flip"); - this.senderMustBeMember = true; - this.senderMustBeModerator = false; - } - - @Override - public void perform() { - if (args.size() == 0) { - toggleNotifications(!fme.hasNotificationsEnabled()); - } else if (args.size() == 1) { - toggleNotifications(argAsBool(0)); - } - } - - private void toggleNotifications(boolean toggle) { - fme.setNotificationsEnabled(toggle); - if (toggle) { - fme.msg(TL.COMMAND_NOTIFICATIONS_TOGGLED_ON); - } else { - fme.msg(TL.COMMAND_NOTIFICATIONS_TOGGLED_OFF); - } - } - - @Override - public TL getUsageTranslation() { - return TL.COMMAND_NOTIFICATIONS_DESCRIPTION; - } -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdOpen.java b/src/main/java/com/massivecraft/factions/cmd/CmdOpen.java index b7587b9e..373ed801 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdOpen.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdOpen.java @@ -3,8 +3,8 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.util.TL; public class CmdOpen extends FCommand { @@ -12,47 +12,34 @@ public class CmdOpen extends FCommand { public CmdOpen() { super(); this.aliases.add("open"); - - //this.requiredArgs.add(""); this.optionalArgs.put("yes/no", "flip"); - this.permission = Permission.OPEN.node; - this.disableOnLock = false; - this.disableOnSpam = true; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.OPEN) + .withRole(Role.COLEADER) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostOpen, TL.COMMAND_OPEN_TOOPEN, TL.COMMAND_OPEN_FOROPEN)) { + if (!context.payForCommand(Conf.econCostOpen, TL.COMMAND_OPEN_TOOPEN, TL.COMMAND_OPEN_FOROPEN)) { return; } - if (!fme.isCooldownEnded("open")) { - fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("open")); - return; - } + context.faction.setOpen(context.argAsBool(0, !context.faction.getOpen())); - myFaction.setOpen(this.argAsBool(0, !myFaction.getOpen())); - - String open = myFaction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString(); + String open = context.faction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString(); // Inform for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { - if (fplayer.getFactionId().equals(myFaction.getId())) { - fplayer.msg(TL.COMMAND_OPEN_CHANGES, fme.getName(), open); + if (fplayer.getFactionId().equals(context.faction.getId())) { + fplayer.msg(TL.COMMAND_OPEN_CHANGES, context.fPlayer.getName(), open); continue; } - fplayer.msg(TL.COMMAND_OPEN_CHANGED, myFaction.getTag(fplayer.getFaction()), open); + fplayer.msg(TL.COMMAND_OPEN_CHANGED, context.faction.getTag(fplayer.getFaction()), open); } - fme.setCooldown("open", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-open") * 1000)); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdOwner.java b/src/main/java/com/massivecraft/factions/cmd/CmdOwner.java index 9811f02c..05c3ec14 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdOwner.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdOwner.java @@ -11,93 +11,87 @@ public class CmdOwner extends FCommand { public CmdOwner() { super(); this.aliases.add("owner"); - - //this.requiredArgs.add(""); this.optionalArgs.put("player name", "you"); - this.permission = Permission.OWNER.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.OWNER) + .withRole(Role.LEADER) + .playerOnly() + .memberOnly() + .build(); } // TODO: Fix colors! @Override - public void perform() { - boolean hasBypass = fme.isAdminBypassing(); + public void perform(CommandContext context) { + boolean hasBypass = context.fPlayer.isAdminBypassing(); - if (!hasBypass && !assertHasFaction()) { + if (!hasBypass && !context.assertHasFaction()) { return; } if (!Conf.ownedAreasEnabled) { - fme.msg(TL.COMMAND_OWNER_DISABLED); + context.msg(TL.COMMAND_OWNER_DISABLED); return; } - if (!hasBypass && Conf.ownedAreasLimitPerFaction > 0 && myFaction.getCountOfClaimsWithOwners() >= Conf.ownedAreasLimitPerFaction) { - fme.msg(TL.COMMAND_OWNER_LIMIT, Conf.ownedAreasLimitPerFaction); + if (!hasBypass && Conf.ownedAreasLimitPerFaction > 0 && context.faction.getCountOfClaimsWithOwners() >= Conf.ownedAreasLimitPerFaction) { + context.msg(TL.COMMAND_OWNER_LIMIT, Conf.ownedAreasLimitPerFaction); return; } - if (!hasBypass && !assertMinRole(Conf.ownedAreasModeratorsCanSet ? Role.MODERATOR : Role.LEADER)) { + if (!hasBypass && !context.assertMinRole(Conf.ownedAreasModeratorsCanSet ? Role.MODERATOR : Role.LEADER)) { return; } - FLocation flocation = new FLocation(fme); + FLocation flocation = new FLocation(context.fPlayer); Faction factionHere = Board.getInstance().getFactionAt(flocation); - if (factionHere != myFaction) { + if (factionHere != context.faction) { if (!factionHere.isNormal()) { - fme.msg(TL.COMMAND_OWNER_NOTCLAIMED); + context.msg(TL.COMMAND_OWNER_NOTCLAIMED); return; } if (!hasBypass) { - fme.msg(TL.COMMAND_OWNER_WRONGFACTION); + context.msg(TL.COMMAND_OWNER_WRONGFACTION); return; } } - FPlayer target = this.argAsBestFPlayerMatch(0, fme); + FPlayer target = context.argAsBestFPlayerMatch(0, context.fPlayer); if (target == null) { return; } String playerName = target.getName(); - if (target.getFaction() != myFaction) { - fme.msg(TL.COMMAND_OWNER_NOTMEMBER, playerName); + if (target.getFaction() != context.faction) { + context.msg(TL.COMMAND_OWNER_NOTMEMBER, playerName); return; } // if no player name was passed, and this claim does already have owners set, clear them - if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation)) { - myFaction.clearClaimOwnership(flocation); - fme.msg(TL.COMMAND_OWNER_CLEARED); + if (context.args.isEmpty() && context.faction.doesLocationHaveOwnersSet(flocation)) { + context.faction.clearClaimOwnership(flocation); + context.msg(TL.COMMAND_OWNER_CLEARED); return; } - if (myFaction.isPlayerInOwnerList(target, flocation)) { - myFaction.removePlayerAsOwner(target, flocation); - fme.msg(TL.COMMAND_OWNER_REMOVED, playerName); + if (context.faction.isPlayerInOwnerList(target, flocation)) { + context.faction.removePlayerAsOwner(target, flocation); + context.msg(TL.COMMAND_OWNER_REMOVED, playerName); return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostOwner, TL.COMMAND_OWNER_TOSET, TL.COMMAND_OWNER_FORSET)) { + if (!context.payForCommand(Conf.econCostOwner, TL.COMMAND_OWNER_TOSET, TL.COMMAND_OWNER_FORSET)) { return; } - myFaction.setPlayerAsOwner(target, flocation); + context.faction.setPlayerAsOwner(target, flocation); - fme.msg(TL.COMMAND_OWNER_ADDED, playerName); + context.msg(TL.COMMAND_OWNER_ADDED, playerName); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdOwnerList.java b/src/main/java/com/massivecraft/factions/cmd/CmdOwnerList.java index ee49571e..94ce0830 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdOwnerList.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdOwnerList.java @@ -13,60 +13,52 @@ public class CmdOwnerList extends FCommand { super(); this.aliases.add("ownerlist"); - //this.requiredArgs.add(""); - //this.optionalArgs.put("", ""); - - this.permission = Permission.OWNERLIST.node; - this.disableOnLock = false; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.OWNERLIST) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - boolean hasBypass = fme.isAdminBypassing(); + public void perform(CommandContext context) { + boolean hasBypass = context.fPlayer.isAdminBypassing(); - if (!hasBypass && !assertHasFaction()) { + if (!hasBypass && !context.assertHasFaction()) { return; } if (!Conf.ownedAreasEnabled) { - fme.msg(TL.COMMAND_OWNERLIST_DISABLED); + context.msg(TL.COMMAND_OWNERLIST_DISABLED); return; } - FLocation flocation = new FLocation(fme); + FLocation flocation = new FLocation(context.fPlayer); - if (Board.getInstance().getFactionAt(flocation) != myFaction) { + if (Board.getInstance().getFactionAt(flocation) != context.faction) { if (!hasBypass) { - fme.msg(TL.COMMAND_OWNERLIST_WRONGFACTION); + context.msg(TL.COMMAND_OWNERLIST_WRONGFACTION); return; } //TODO: This code won't ever be called. - myFaction = Board.getInstance().getFactionAt(flocation); - if (!myFaction.isNormal()) { - fme.msg(TL.COMMAND_OWNERLIST_NOTCLAIMED); + context.faction = Board.getInstance().getFactionAt(flocation); + if (!context.faction.isNormal()) { + context.msg(TL.COMMAND_OWNERLIST_NOTCLAIMED); return; } } - String owners = myFaction.getOwnerListString(flocation); + String owners = context.faction.getOwnerListString(flocation); if (owners == null || owners.isEmpty()) { - fme.msg(TL.COMMAND_OWNERLIST_NONE); + context.msg(TL.COMMAND_OWNERLIST_NONE); return; } - fme.msg(TL.COMMAND_OWNERLIST_OWNERS, owners); + context.msg(TL.COMMAND_OWNERLIST_OWNERS, owners); } @Override public TL getUsageTranslation() { return TL.COMMAND_OWNERLIST_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSee.java b/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSee.java index 672d2088..cf06d90a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSee.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSee.java @@ -1,57 +1,50 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; public class CmdPaypalSee extends FCommand { public CmdPaypalSee() { - aliases.add("seepaypal"); - aliases.add("paypal"); + this.aliases.add("seepaypal"); + this.aliases.add("paypal"); - optionalArgs.put("faction", "yours"); - - permission = Permission.PAYPAL.node; - - disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = true; + this.optionalArgs.put("faction", "yours"); + this.requirements = new CommandRequirements.Builder(Permission.PAYPAL) + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("fpaypal.Enabled")) { - fme.msg(TL.GENERIC_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) { + context.msg(TL.GENERIC_DISABLED); return; } - if (args.size() == 0) { - if (myFaction.getPaypal().isEmpty()) { - msg(TL.COMMAND_PAYPAL_NOTSET); + if (context.args.size() == 0) { + if (context.fPlayer.getFaction().getPaypal().isEmpty()) { + context.msg(TL.COMMAND_PAYPAL_NOTSET); } else { - msg(TL.PAYPALSEE_PLAYER_PAYPAL, myFaction.getPaypal()); + context.msg(TL.PAYPALSEE_PLAYER_PAYPAL, context.fPlayer.getFaction().getPaypal()); } - } else if (args.size() == 1) { - if (fme.isAdminBypassing()) { - Faction faction = argAsFaction(0); + } else if (context.args.size() == 1) { + if (context.fPlayer.isAdminBypassing()) { + Faction faction = context.argAsFaction(0); if (faction != null) { if (faction.getPaypal().isEmpty()) { - msg(TL.COMMAND_PAYPALSEE_FACTION_NOTSET, faction.getTag()); + context.msg(TL.COMMAND_PAYPALSEE_FACTION_NOTSET, faction.getTag()); } else { - msg(TL.COMMAND_PAYPALSEE_FACTION_PAYPAL.toString(), faction.getTag(), faction.getPaypal()); + context.msg(TL.COMMAND_PAYPALSEE_FACTION_PAYPAL.toString(), faction.getTag(), faction.getPaypal()); } } } else { - msg(TL.GENERIC_NOPERMISSION, "see another factions paypal."); + context.msg(TL.GENERIC_NOPERMISSION, "see another factions paypal."); } } else { - msg(P.p.cmdBase.cmdPaypalSee.getUseageTemplate()); + context.msg(FactionsPlugin.getInstance().cmdBase.cmdPaypalSee.getUseageTemplate(context)); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSet.java index 661518c3..0fd58f83 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSet.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSet.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -14,47 +14,43 @@ public class CmdPaypalSet extends FCommand { this.requiredArgs.add("email"); - this.permission = Permission.PAYPALSET.node; - - this.disableOnLock = false; - this.senderMustBePlayer = true; - this.senderMustBeMember = true; - this.senderMustBeModerator = false; - this.senderMustBeColeader = false; - this.senderMustBeAdmin = true; + this.requirements = new CommandRequirements.Builder(Permission.PAYPALSET) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("fpaypal.Enabled")) { - fme.msg(TL.GENERIC_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) { + context.fPlayer.msg(TL.GENERIC_DISABLED); return; } - if (args.size() == 1) { - if (isEmail(argAsString(0))) { - myFaction.paypalSet(argAsString(0)); - msg(TL.COMMAND_PAYPALSET_SUCCESSFUL, argAsString(0)); + if (context.args.size() == 1) { + if (isEmail(context.argAsString(0))) { + context.fPlayer.getFaction().paypalSet(context.argAsString(0)); + context.msg(TL.COMMAND_PAYPALSET_SUCCESSFUL, context.argAsString(0)); } else { - msg(TL.COMMAND_PAYPALSET_NOTEMAIL, argAsString(0)); + context.msg(TL.COMMAND_PAYPALSET_NOTEMAIL, context.argAsString(0)); } - } else if (args.size() == 2) { - if (fme.isAdminBypassing()) { - Faction faction = argAsFaction(1); + } else if (context.args.size() == 2) { + if (context.fPlayer.isAdminBypassing()) { + Faction faction = context.argAsFaction(1); if (faction != null) { - if (isEmail(argAsString(0))) { - myFaction.paypalSet(argAsString(0)); - msg(TL.COMMAND_PAYPALSET_ADMIN_SUCCESSFUL, faction.getTag(), argAsString(0)); + if (isEmail(context.argAsString(0))) { + context.fPlayer.getFaction().paypalSet(context.argAsString(0)); + context.msg(TL.COMMAND_PAYPALSET_ADMIN_SUCCESSFUL, faction.getTag(), context.argAsString(0)); } else { - msg(TL.COMMAND_PAYPALSET_ADMIN_FAILED, argAsString(0)); + context.msg(TL.COMMAND_PAYPALSET_ADMIN_FAILED, context.argAsString(0)); } } } else { - msg(TL.GENERIC_NOPERMISSION, "set another factions paypal!"); + context.msg(TL.GENERIC_NOPERMISSION, "set another factions paypal!"); } } else { - msg(P.p.cmdBase.cmdPaypalSet.getUseageTemplate()); + context.msg(FactionsPlugin.getInstance().cmdBase.cmdPaypalSet.getUseageTemplate(context)); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPeaceful.java b/src/main/java/com/massivecraft/factions/cmd/CmdPeaceful.java index 02f6bb29..967b7023 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPeaceful.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPeaceful.java @@ -11,24 +11,16 @@ public class CmdPeaceful extends FCommand { public CmdPeaceful() { super(); this.aliases.add("peaceful"); - this.requiredArgs.add("faction tag"); - //this.optionalArgs.put("", ""); - this.permission = Permission.SET_PEACEFUL.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.SET_PEACEFUL) + .build(); } @Override - public void perform() { - Faction faction = this.argAsFaction(0); + public void perform(CommandContext context) { + Faction faction = context.argAsFaction(0); if (faction == null) { return; } @@ -44,7 +36,7 @@ public class CmdPeaceful extends FCommand { // Inform all players for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { - String blame = (fme == null ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true)); + String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true)); if (fplayer.getFaction() == faction) { fplayer.msg(TL.COMMAND_PEACEFUL_YOURS, blame, change); } else { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java index 8ec4856b..608cc55a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; @@ -27,46 +28,43 @@ public class CmdPerm extends FCommand { this.optionalArgs.put("action", "action"); this.optionalArgs.put("access", "access"); - - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = true; - + this.requirements = new CommandRequirements.Builder(Permission.PERMISSIONS) + .playerOnly() + .memberOnly() + .withRole(Role.LEADER) + .build(); } @Override - public void perform() { - if (args.size() == 0) { - new PermissableRelationFrame(fme.getFaction()).buildGUI(fme); + public void perform(CommandContext context) { + + if (context.args.size() == 0) { + new PermissableRelationFrame(context.faction).buildGUI(context.fPlayer); return; - } else if (args.size() == 1 && getPermissable(argAsString(0)) != null) { - new PermissableActionFrame(fme.getFaction()).buildGUI(fme, getPermissable(argAsString(0))); + } else if (context.args.size() == 1 && getPermissable(context.argAsString(0)) != null) { + new PermissableActionFrame(context.faction).buildGUI(context.fPlayer, getPermissable(context.argAsString(0))); return; } // If not opening GUI, then setting the permission manually. - if (args.size() != 3) { - fme.msg(TL.COMMAND_PERM_DESCRIPTION); + if (context.args.size() != 3) { + context.msg(TL.COMMAND_PERM_DESCRIPTION); return; } Set permissables = new HashSet<>(); Set permissableActions = new HashSet<>(); - boolean allRelations = argAsString(0).equalsIgnoreCase("all"); - boolean allActions = argAsString(1).equalsIgnoreCase("all"); + boolean allRelations = context.argAsString(0).equalsIgnoreCase("all"); + boolean allActions = context.argAsString(1).equalsIgnoreCase("all"); if (allRelations) { - permissables.addAll(myFaction.getPermissions().keySet()); + permissables.addAll(context.faction.getPermissions().keySet()); } else { - Permissable permissable = getPermissable(argAsString(0)); + Permissable permissable = getPermissable(context.argAsString(0)); if (permissable == null) { - fme.msg(TL.COMMAND_PERM_INVALID_RELATION); + context.msg(TL.COMMAND_PERM_INVALID_RELATION); return; } @@ -76,29 +74,30 @@ public class CmdPerm extends FCommand { if (allActions) { permissableActions.addAll(Arrays.asList(PermissableAction.values())); } else { - PermissableAction permissableAction = PermissableAction.fromString(argAsString(1)); + PermissableAction permissableAction = PermissableAction.fromString(context.argAsString(1)); if (permissableAction == null) { - fme.msg(TL.COMMAND_PERM_INVALID_ACTION); + context.msg(TL.COMMAND_PERM_INVALID_ACTION); return; } permissableActions.add(permissableAction); } - Access access = Access.fromString(argAsString(2)); + Access access = Access.fromString(context.argAsString(2)); if (access == null) { - fme.msg(TL.COMMAND_PERM_INVALID_ACCESS); + context.msg(TL.COMMAND_PERM_INVALID_ACCESS); return; } for (Permissable permissable : permissables) { for (PermissableAction permissableAction : permissableActions) { - fme.getFaction().setPermission(permissable, permissableAction, access); + context.faction.setPermission(permissable, permissableAction, access); } } - fme.msg(TL.COMMAND_PERM_SET, argAsString(1), access.name(), argAsString(0)); - P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), argAsString(1), access.name(), argAsString(0)) + " for faction " + fme.getTag()); + + context.msg(TL.COMMAND_PERM_SET, context.argAsString(1), access.name(), context.argAsString(0)); + FactionsPlugin.getInstance().log(String.format(TL.COMMAND_PERM_SET.toString(), context.argAsString(1), access.name(), context.argAsString(0)) + " for faction " + context.fPlayer.getTag()); } private Permissable getPermissable(String name) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPermanent.java b/src/main/java/com/massivecraft/factions/cmd/CmdPermanent.java index b6cd5d22..58084ca8 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPermanent.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPermanent.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -13,23 +13,15 @@ public class CmdPermanent extends FCommand { public CmdPermanent() { super(); this.aliases.add("permanent"); - this.requiredArgs.add("faction tag"); - //this.optionalArgs.put("", ""); - this.permission = Permission.SET_PERMANENT.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.SET_PERMANENT) + .build(); } @Override - public void perform() { - Faction faction = this.argAsFaction(0); + public void perform(CommandContext context) { + Faction faction = context.argAsFaction(0); if (faction == null) { return; } @@ -43,11 +35,11 @@ public class CmdPermanent extends FCommand { faction.setPermanent(true); } - P.p.log((fme == null ? "A server admin" : fme.getName()) + " " + change + " the faction \"" + faction.getTag() + "\"."); + FactionsPlugin.getInstance().log((context.fPlayer == null ? "A server admin" : context.fPlayer.getName()) + " " + change + " the faction \"" + faction.getTag() + "\"."); // Inform all players for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { - String blame = (fme == null ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true)); + String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true)); if (fplayer.getFaction() == faction) { fplayer.msg(TL.COMMAND_PERMANENT_YOURS, blame, change); } else { @@ -61,3 +53,4 @@ public class CmdPermanent extends FCommand { return TL.COMMAND_PERMANENT_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPermanentPower.java b/src/main/java/com/massivecraft/factions/cmd/CmdPermanentPower.java index fdcd607c..8b39c60e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPermanentPower.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPermanentPower.java @@ -9,28 +9,21 @@ public class CmdPermanentPower extends FCommand { public CmdPermanentPower() { super(); this.aliases.add("permanentpower"); - this.requiredArgs.add("faction"); this.requiredArgs.add("power"); - this.permission = Permission.SET_PERMANENTPOWER.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.SET_PERMANENTPOWER) + .build(); } @Override - public void perform() { - Faction targetFaction = this.argAsFaction(0); + public void perform(CommandContext context) { + Faction targetFaction = context.argAsFaction(0); if (targetFaction == null) { return; } - Integer targetPower = this.argAsInt(1); + Integer targetPower = context.argAsInt(1); targetFaction.setPermanentPower(targetPower); @@ -40,14 +33,14 @@ public class CmdPermanentPower extends FCommand { } // Inform sender - msg(TL.COMMAND_PERMANENTPOWER_SUCCESS, change, targetFaction.describeTo(fme)); + context.msg(TL.COMMAND_PERMANENTPOWER_SUCCESS, change, targetFaction.describeTo(context.fPlayer)); // Inform all other players for (FPlayer fplayer : targetFaction.getFPlayersWhereOnline(true)) { - if (fplayer == fme) { + if (fplayer == context.fPlayer) { continue; } - String blame = (fme == null ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true)); + String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true)); fplayer.msg(TL.COMMAND_PERMANENTPOWER_FACTION, blame, change); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPower.java b/src/main/java/com/massivecraft/factions/cmd/CmdPower.java index 985d8770..1807df3a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPower.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPower.java @@ -11,41 +11,33 @@ public class CmdPower extends FCommand { super(); this.aliases.add("power"); this.aliases.add("pow"); - - //this.requiredArgs.add("faction tag"); this.optionalArgs.put("player name", "you"); - this.permission = Permission.POWER.node; - this.disableOnLock = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.POWER) + .build(); } @Override - public void perform() { - FPlayer target = this.argAsBestFPlayerMatch(0, fme); + public void perform(CommandContext context) { + FPlayer target = context.argAsBestFPlayerMatch(0, context.fPlayer); if (target == null) { return; } - if (target != fme && !Permission.POWER_ANY.has(sender, true)) { + if (target != context.fPlayer && !Permission.POWER_ANY.has(context.sender, true)) { return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostPower, TL.COMMAND_POWER_TOSHOW, TL.COMMAND_POWER_FORSHOW)) { + if (!context.payForCommand(Conf.econCostPower, TL.COMMAND_POWER_TOSHOW, TL.COMMAND_POWER_FORSHOW)) { return; } double powerBoost = target.getPowerBoost(); String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_POWER_BONUS.toString() : TL.COMMAND_POWER_PENALTY.toString()) + powerBoost + ")"; - msg(TL.COMMAND_POWER_POWER, target.describeTo(fme, true), target.getPowerRounded(), target.getPowerMaxRounded(), boost); + context.msg(TL.COMMAND_POWER_POWER, target.describeTo(context.fPlayer, true), target.getPowerRounded(), target.getPowerMaxRounded(), boost); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPowerBoost.java b/src/main/java/com/massivecraft/factions/cmd/CmdPowerBoost.java index 4a423812..3872bf76 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPowerBoost.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPowerBoost.java @@ -2,48 +2,42 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; +import org.bukkit.command.ConsoleCommandSender; public class CmdPowerBoost extends FCommand { public CmdPowerBoost() { super(); this.aliases.add("powerboost"); - this.requiredArgs.add("plugin|f|player|faction"); this.requiredArgs.add("name"); this.requiredArgs.add("# or reset"); - this.permission = Permission.POWERBOOST.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.POWERBOOST) + .build(); } @Override - public void perform() { - String type = this.argAsString(0).toLowerCase(); + public void perform(CommandContext context) { + String type = context.argAsString(0).toLowerCase(); boolean doPlayer = true; if (type.equals("f") || type.equals("faction")) { doPlayer = false; } else if (!type.equals("plugin") && !type.equals("player")) { - msg(TL.COMMAND_POWERBOOST_HELP_1); - msg(TL.COMMAND_POWERBOOST_HELP_2); + context.msg(TL.COMMAND_POWERBOOST_HELP_1); + context.msg(TL.COMMAND_POWERBOOST_HELP_2); return; } - Double targetPower = this.argAsDouble(2); + Double targetPower = context.argAsDouble(2); if (targetPower == null) { - if (this.argAsString(2).equalsIgnoreCase("reset")) { + if (context.argAsString(2).equalsIgnoreCase("reset")) { targetPower = 0D; } else { - msg(TL.COMMAND_POWERBOOST_INVALIDNUM); + context.msg(TL.COMMAND_POWERBOOST_INVALIDNUM); return; } } @@ -51,7 +45,7 @@ public class CmdPowerBoost extends FCommand { String target; if (doPlayer) { - FPlayer targetPlayer = this.argAsBestFPlayerMatch(1); + FPlayer targetPlayer = context.argAsBestFPlayerMatch(1); if (targetPlayer == null) { return; } @@ -62,7 +56,7 @@ public class CmdPowerBoost extends FCommand { targetPlayer.setPowerBoost(targetPower); target = TL.COMMAND_POWERBOOST_PLAYER.format(targetPlayer.getName()); } else { - Faction targetFaction = this.argAsFaction(1); + Faction targetFaction = context.argAsFaction(1); if (targetFaction == null) { return; } @@ -75,9 +69,9 @@ public class CmdPowerBoost extends FCommand { } int roundedPower = (int) Math.round(targetPower); - msg(TL.COMMAND_POWERBOOST_BOOST, target, roundedPower); - if (!senderIsConsole) { - P.p.log(TL.COMMAND_POWERBOOST_BOOSTLOG.toString(), fme.getName(), target, roundedPower); + context.msg(TL.COMMAND_POWERBOOST_BOOST, target, roundedPower); + if (!(context.sender instanceof ConsoleCommandSender)) { + FactionsPlugin.getInstance().log(TL.COMMAND_POWERBOOST_BOOSTLOG.toString(), context.fPlayer.getName(), target, roundedPower); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdReload.java b/src/main/java/com/massivecraft/factions/cmd/CmdReload.java index 4ba583c9..0ae7517e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdReload.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdReload.java @@ -1,8 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; -import com.massivecraft.factions.shop.ShopConfig; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -12,36 +11,28 @@ public class CmdReload extends FCommand { super(); this.aliases.add("reload"); - this.permission = Permission.RELOAD.node; - this.disableOnLock = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.RELOAD).build(); } @Override - public void perform() { + public void perform(CommandContext context) { long timeInitStart = System.currentTimeMillis(); Conf.load(); Conf.save(); - P.p.reloadConfig(); - P.p.loadLang(); - ShopConfig.loadShop(); + FactionsPlugin.getInstance().reloadConfig(); + FactionsPlugin.getInstance().loadLang(); - if (P.p.getConfig().getBoolean("enable-faction-flight")) { - P.p.factionsFlight = true; + if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) { + FactionsPlugin.getInstance().factionsFlight = true; } long timeReload = (System.currentTimeMillis() - timeInitStart); - msg(TL.COMMAND_RELOAD_TIME, timeReload); + context.msg(TL.COMMAND_RELOAD_TIME, timeReload); } @Override public TL getUsageTranslation() { return TL.COMMAND_RELOAD_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdRules.java b/src/main/java/com/massivecraft/factions/cmd/CmdRules.java index ee9a2edd..0fce2952 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdRules.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdRules.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -15,69 +15,65 @@ public class CmdRules extends FCommand { aliases.add("rules"); this.optionalArgs.put("add/remove/set/clear", ""); - this.errorOnToManyArgs = false; - - permission = Permission.RULES.node; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.RULES) + .playerOnly() + .memberOnly() + .noErrorOnManyArgs() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("frules.Enabled")) { - fme.msg(TL.COMMAND_RULES_DISABLED_MSG); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("frules.Enabled")) { + context.msg(TL.COMMAND_RULES_DISABLED_MSG); return; } - if (this.args.size() == 0) { - HashMap rules = fme.getFaction().getRulesMap(); + if (context.args.size() == 0) { + HashMap rules = context.faction.getRulesMap(); if (rules.size() == 0) { - List ruleList = P.p.getConfig().getStringList("frules.default-rules"); - fme.sendMessage(P.p.colorList(ruleList)); + List ruleList = FactionsPlugin.getInstance().getConfig().getStringList("frules.default-rules"); + context.sendMessage(FactionsPlugin.getInstance().colorList(ruleList)); } else { for (int i = 0; i <= rules.size() - 1; i++) { - fme.sendMessage(P.p.color(rules.get(i))); + context.sendMessage(FactionsPlugin.getInstance().color(rules.get(i))); } } } - if (this.args.size() == 1) { - if (args.get(0).equalsIgnoreCase("add")) { - fme.msg(TL.COMMAND_RULES_ADD_INVALIDARGS); + if (context.args.size() == 1) { + if (context.args.get(0).equalsIgnoreCase("add")) { + context.msg(TL.COMMAND_RULES_ADD_INVALIDARGS); } - if (args.get(0).equalsIgnoreCase("set")) { - fme.msg(TL.COMMAND_RULES_SET_INVALIDARGS); + if (context.args.get(0).equalsIgnoreCase("set")) { + context.msg(TL.COMMAND_RULES_SET_INVALIDARGS); } - if (args.get(0).equalsIgnoreCase("remove")) { - fme.msg(TL.COMMAND_RULES_REMOVE_INVALIDARGS); + if (context.args.get(0).equalsIgnoreCase("remove")) { + context.msg(TL.COMMAND_RULES_REMOVE_INVALIDARGS); } - if (args.get(0).equalsIgnoreCase("clear")) { - fme.getFaction().clearRules(); - fme.msg(TL.COMMAND_RULES_CLEAR_SUCCESS); + if (context.args.get(0).equalsIgnoreCase("clear")) { + context.faction.clearRules(); + context.msg(TL.COMMAND_RULES_CLEAR_SUCCESS); } } - if (this.args.size() >= 2) { - if (args.get(0).equalsIgnoreCase("add")) { + if (context.args.size() >= 2) { + if (context.args.get(0).equalsIgnoreCase("add")) { String message = ""; StringBuilder string = new StringBuilder(message); - for (int i = 1; i <= args.size() - 1; i++) { - string.append(" ").append(args.get(i)); + for (int i = 1; i <= context.args.size() - 1; i++) { + string.append(" " + context.args.get(i)); } - fme.getFaction().addRule(string.toString()); - fme.msg(TL.COMMAND_RULES_ADD_SUCCESS); + context.faction.addRule(string.toString()); + context.msg(TL.COMMAND_RULES_ADD_SUCCESS); } - if (this.args.size() == 2) { - if (args.get(0).equalsIgnoreCase("remove")) { - int index = argAsInt(1); - fme.getFaction().removeRule(index - 1); - fme.msg(TL.COMMAND_RULES_REMOVE_SUCCESS); + if (context.args.size() == 2) { + if (context.args.get(0).equalsIgnoreCase("remove")) { + int index = context.argAsInt(1); + context.faction.removeRule(index - 1); + context.msg(TL.COMMAND_RULES_REMOVE_SUCCESS); } } @@ -88,4 +84,4 @@ public class CmdRules extends FCommand { public TL getUsageTranslation() { return TL.COMMAND_RULES_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSB.java b/src/main/java/com/massivecraft/factions/cmd/CmdSB.java index e0f18a3b..513bd35e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSB.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSB.java @@ -9,25 +9,27 @@ public class CmdSB extends FCommand { public CmdSB() { this.aliases.add("sb"); this.aliases.add("scoreboard"); - this.permission = Permission.SCOREBOARD.node; - this.senderMustBePlayer = true; + + this.requirements = new CommandRequirements.Builder(Permission.SCOREBOARD) + .playerOnly() + .build(); } @Override - public void perform() { - boolean toggleTo = !fme.showScoreboard(); - FScoreboard board = FScoreboard.get(fme); + public void perform(CommandContext context) { + boolean toggleTo = !context.fPlayer.showScoreboard(); + FScoreboard board = FScoreboard.get(context.fPlayer); if (board == null) { - me.sendMessage(TL.COMMAND_TOGGLESB_DISABLED.toString()); + context.msg(TL.COMMAND_TOGGLESB_DISABLED.toString()); } else { - me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggleTo))); + context.msg(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggleTo))); board.setSidebarVisibility(toggleTo); } - fme.setShowScoreboard(toggleTo); + context.fPlayer.setShowScoreboard(toggleTo); } @Override public TL getUsageTranslation() { return TL.COMMAND_SCOREBOARD_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSaveAll.java b/src/main/java/com/massivecraft/factions/cmd/CmdSaveAll.java index 2a0de381..32f56822 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSaveAll.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSaveAll.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.shop.ShopConfig; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -14,26 +15,18 @@ public class CmdSaveAll extends FCommand { this.aliases.add("saveall"); this.aliases.add("save"); - //this.requiredArgs.add(""); - //this.optionalArgs.put("", ""); - - this.permission = Permission.SAVE.node; - this.disableOnLock = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.SAVE) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { FPlayers.getInstance().forceSave(false); Factions.getInstance().forceSave(false); Board.getInstance().forceSave(false); Conf.save(); - msg(TL.COMMAND_SAVEALL_SUCCESS); + ShopConfig.saveShop(); + context.msg(TL.COMMAND_SAVEALL_SUCCESS); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSeeChunk.java b/src/main/java/com/massivecraft/factions/cmd/CmdSeeChunk.java index 68ba23ed..5c930be5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSeeChunk.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSeeChunk.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FLocation; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.util.Particles.ParticleEffect; import com.massivecraft.factions.util.VisualizeUtil; @@ -17,7 +17,7 @@ public class CmdSeeChunk extends FCommand { //Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn. public static HashMap seeChunkMap = new HashMap<>(); - Long interval; + private long interval; private boolean useParticles; private ParticleEffect effect; private int taskID = -1; @@ -31,30 +31,26 @@ public class CmdSeeChunk extends FCommand { aliases.add("seechunk"); aliases.add("sc"); - permission = Permission.SEECHUNK.node; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; - - - this.useParticles = p.getConfig().getBoolean("see-chunk.particles", true); - interval = P.p.getConfig().getLong("see-chunk.interval", 10L); + this.useParticles = FactionsPlugin.getInstance().getConfig().getBoolean("see-chunk.particles", true); + interval = FactionsPlugin.getInstance().getConfig().getLong("see-chunk.interval", 10L); if (effect == null) { effect = ParticleEffect.REDSTONE; } + this.requirements = new CommandRequirements.Builder(Permission.SEECHUNK) + .playerOnly() + .build(); + } @Override - public void perform() { - if (seeChunkMap.containsKey(me.getName())) { - seeChunkMap.remove(me.getName()); - msg(TL.COMMAND_SEECHUNK_DISABLED); + public void perform(CommandContext context) { + if (seeChunkMap.containsKey(context.player.getName())) { + seeChunkMap.remove(context.player.getName()); + context.msg(TL.COMMAND_SEECHUNK_DISABLED); } else { - seeChunkMap.put(me.getName(), true); - msg(TL.COMMAND_SEECHUNK_ENABLED); + seeChunkMap.put(context.player.getName(), true); + context.msg(TL.COMMAND_SEECHUNK_ENABLED); manageTask(); } } @@ -71,7 +67,7 @@ public class CmdSeeChunk extends FCommand { } private void startTask() { - taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { + taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { for (Object nameObject : seeChunkMap.keySet()) { String name = nameObject + ""; Player player = Bukkit.getPlayer(name); @@ -115,10 +111,10 @@ public class CmdSeeChunk extends FCommand { continue; } if (useParticles) { - if (P.p.useNonPacketParticles) { + if (FactionsPlugin.getInstance().useNonPacketParticles) { // Dust options only exists in the 1.13 API, so we use an // alternative method to achieve this in lower versions. - if (P.p.mc113) { + if (FactionsPlugin.getInstance().mc113 || FactionsPlugin.getInstance().mc114) { player.spawnParticle(Particle.REDSTONE, loc, 0, new Particle.DustOptions(Color.RED, 1)); } else { player.getWorld().spawnParticle(Particle.REDSTONE, loc, 0, 255, 0, 0, 1); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSetBanner.java b/src/main/java/com/massivecraft/factions/cmd/CmdSetBanner.java index 1558b54d..e5003b77 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSetBanner.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSetBanner.java @@ -9,24 +9,20 @@ public class CmdSetBanner extends FCommand { super(); aliases.add("setbanner"); - permission = Permission.BANNER.node; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = true; - - + this.requirements = new CommandRequirements.Builder(Permission.BANNER) + .playerOnly() + .build(); } - public void perform() { - if (!me.getItemInHand().getType().toString().contains("BANNER")) { - fme.msg(TL.COMMAND_SETBANNER_NOTBANNER); + @Override + public void perform(CommandContext context) { + if (!context.player.getItemInHand().getType().toString().contains("BANNER")) { + context.msg(TL.COMMAND_SETBANNER_NOTBANNER); return; } - fme.getFaction().setBannerPattern(me.getItemInHand()); - fme.msg(TL.COMMAND_SETBANNER_SUCCESS); + context.faction.setBannerPattern(context.player.getItemInHand()); + context.msg(TL.COMMAND_SETBANNER_SUCCESS); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java b/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java index 9735f1c0..ec5464e7 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java @@ -15,30 +15,28 @@ public class CmdSetDefaultRole extends FCommand { this.aliases.add("def"); this.requiredArgs.add("role"); - this.senderMustBeAdmin = true; - this.senderMustBePlayer = true; - senderMustBeColeader = false; - - - this.permission = Permission.DEFAULTRANK.node; + this.requirements = new CommandRequirements.Builder(Permission.DEFAULTRANK) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - Role target = Role.fromString(argAsString(0).toUpperCase()); + public void perform(CommandContext context) { + Role target = Role.fromString(context.argAsString(0).toUpperCase()); if (target == null) { - msg(TL.COMMAND_SETDEFAULTROLE_INVALIDROLE, argAsString(0)); + context.msg(TL.COMMAND_SETDEFAULTROLE_INVALIDROLE, context.argAsString(0)); return; } if (target == Role.LEADER) { - msg(TL.COMMAND_SETDEFAULTROLE_NOTTHATROLE, argAsString(0)); + context.msg(TL.COMMAND_SETDEFAULTROLE_NOTTHATROLE, context.argAsString(0)); return; } - myFaction.setDefaultRole(target); - msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename); + context.faction.setDefaultRole(target); + context.msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java b/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java index 085b4be7..4986ac9d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java @@ -1,12 +1,10 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; -import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.LazyLocation; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; @@ -17,63 +15,51 @@ public class CmdSetFWarp extends FCommand { this.aliases.add("setwarp"); this.aliases.add("sw"); - this.requiredArgs.add("warp name"); this.optionalArgs.put("password", "password"); - this.senderMustBeMember = true; - this.senderMustBeModerator = false; - - this.senderMustBePlayer = true; - - this.permission = Permission.SETWARP.node; + this.requirements = new CommandRequirements.Builder(Permission.SETWARP) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.SETWARP) + .build(); } @Override - public void perform() { - if (!(fme.getRelationToLocation() == Relation.MEMBER)) { - fme.msg(TL.COMMAND_SETFWARP_NOTCLAIMED); + public void perform(CommandContext context) { + if (!(context.fPlayer.getRelationToLocation() == Relation.MEMBER)) { + context.msg(TL.COMMAND_SETFWARP_NOTCLAIMED); return; } - // This statement allows us to check if they've specifically denied it, or default to - // the old setting of allowing moderators to set warps. - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.SETWARP); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps"); - return; - } - } - - String warp = argAsString(0); + String warp = context.argAsString(0); // Checks if warp with same name already exists and ignores maxWarp check if it does. - boolean warpExists = myFaction.isWarp(warp); + boolean warpExists = context.faction.isWarp(warp); - int maxWarps = P.p.getConfig().getInt("max-warps", 5); - boolean tooManyWarps = maxWarps <= myFaction.getWarps().size(); + int maxWarps = FactionsPlugin.getInstance().getConfig().getInt("max-warps", 5); + boolean tooManyWarps = maxWarps <= context.faction.getWarps().size(); if (tooManyWarps && !warpExists) { - fme.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps); + context.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps); return; } - if (!transact(fme)) { + if (!transact(context.fPlayer, context)) { return; } - String password = argAsString(1); + String password = context.argAsString(1); - LazyLocation loc = new LazyLocation(fme.getPlayer().getLocation()); - myFaction.setWarp(warp, loc); + LazyLocation loc = new LazyLocation(context.player.getLocation()); + context.faction.setWarp(warp, loc); if (password != null) { - myFaction.setWarpPassword(warp, password); + context.faction.setWarpPassword(warp, password); } - fme.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : ""); + context.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : ""); } - private boolean transact(FPlayer player) { - return !P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(P.p.getConfig().getDouble("warp-cost.setwarp", 5), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString()); + private boolean transact(FPlayer player, CommandContext context) { + return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.setwarp", 5), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString()); } @Override @@ -81,3 +67,4 @@ public class CmdSetFWarp extends FCommand { return TL.COMMAND_SETFWARP_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSetMaxVaults.java b/src/main/java/com/massivecraft/factions/cmd/CmdSetMaxVaults.java index 1f3a98f9..0a1e1793 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSetMaxVaults.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSetMaxVaults.java @@ -10,37 +10,29 @@ public class CmdSetMaxVaults extends FCommand { public CmdSetMaxVaults() { this.aliases.add("setmaxvaults"); this.aliases.add("smv"); - this.requiredArgs.add("faction"); this.requiredArgs.add("number"); - this.permission = Permission.SETMAXVAULTS.node; - this.disableOnLock = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.SETMAXVAULTS) + .build(); } @Override - public void perform() { - Faction targetFaction = argAsFaction(0); - int value = argAsInt(1, -1); + public void perform(CommandContext context) { + Faction targetFaction = context.argAsFaction(0); + int value = context.argAsInt(1, -1); if (value < 0) { - sender.sendMessage(ChatColor.RED + "Number must be greater than 0."); + context.sender.sendMessage(ChatColor.RED + "Number must be greater than 0."); return; } if (targetFaction == null) { - sender.sendMessage(ChatColor.RED + "Couldn't find Faction: " + ChatColor.YELLOW + argAsString(0)); + context.sender.sendMessage(ChatColor.RED + "Couldn't find Faction: " + ChatColor.YELLOW + context.argAsString(0)); return; } targetFaction.setMaxVaults(value); - sender.sendMessage(TL.COMMAND_SETMAXVAULTS_SUCCESS.format(targetFaction.getTag(), value)); + context.sender.sendMessage(TL.COMMAND_SETMAXVAULTS_SUCCESS.format(targetFaction.getTag(), value)); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java index b9440e05..4e9785c8 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java @@ -1,12 +1,7 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.Board; -import com.massivecraft.factions.Conf; -import com.massivecraft.factions.FLocation; -import com.massivecraft.factions.Faction; +import com.massivecraft.factions.*; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; @@ -14,60 +9,46 @@ public class CmdSethome extends FCommand { public CmdSethome() { this.aliases.add("sethome"); - - //this.requiredArgs.add(""); this.optionalArgs.put("faction tag", "mine"); - this.permission = Permission.SETHOME.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.SETHOME) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.SETHOME) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { if (!Conf.homesEnabled) { - fme.msg(TL.COMMAND_SETHOME_DISABLED); + context.msg(TL.COMMAND_SETHOME_DISABLED); return; } - Faction faction = this.argAsFaction(0, myFaction); + Faction faction = context.argAsFaction(0, context.faction); if (faction == null) { return; } - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.SETHOME); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER && !Permission.SETHOME_ANY.has(sender, true)) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set home"); - return; - } - } - // Can the player set the faction home HERE? - if (!Permission.BYPASS.has(me) && + if (!Permission.BYPASS.has(context.player) && Conf.homesMustBeInClaimedTerritory && - Board.getInstance().getFactionAt(new FLocation(me)) != faction) { - fme.msg(TL.COMMAND_SETHOME_NOTCLAIMED); + Board.getInstance().getFactionAt(new FLocation(context.player)) != faction) { + context.msg(TL.COMMAND_SETHOME_NOTCLAIMED); return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostSethome, TL.COMMAND_SETHOME_TOSET, TL.COMMAND_SETHOME_FORSET)) { + if (!context.payForCommand(Conf.econCostSethome, TL.COMMAND_SETHOME_TOSET, TL.COMMAND_SETHOME_FORSET)) { return; } - faction.setHome(me.getLocation()); + faction.setHome(context.player.getLocation()); - faction.msg(TL.COMMAND_SETHOME_SET, fme.describeTo(myFaction, true)); - faction.sendMessage(p.cmdBase.cmdHome.getUseageTemplate()); - if (faction != myFaction) { - fme.msg(TL.COMMAND_SETHOME_SETOTHER, faction.getTag(fme)); + faction.msg(TL.COMMAND_SETHOME_SET, context.fPlayer.describeTo(context.faction, true)); + faction.sendMessage(FactionsPlugin.getInstance().cmdBase.cmdHome.getUseageTemplate(context)); + if (faction != context.faction) { + context.msg(TL.COMMAND_SETHOME_SETOTHER, faction.getTag(context.fPlayer)); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java index 268a2abd..d3a6e3f1 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TagReplacer; @@ -19,14 +19,12 @@ public class CmdShow extends FCommand { public CmdShow() { this.aliases.add("show"); this.aliases.add("who"); - this.aliases.add("f"); // add defaults to /f show in case config doesnt have it defaults.add("{header}"); defaults.add("Description: {description}"); defaults.add("Joining: {joining} {peaceful}"); defaults.add("Land / Power / Maxpower: {chunks} / {power} / {maxPower}"); - defaults.add("Faction Strikes: {strikes}"); defaults.add("Founded: {create-date}"); defaults.add("This faction is permanent, remaining even with no members."); defaults.add("Land value: {land-value} {land-refund}"); @@ -34,69 +32,63 @@ public class CmdShow extends FCommand { defaults.add("Allies({allies}/{max-allies}): {allies-list}"); defaults.add("Online: ({online}/{members}): {online-list}"); defaults.add("Offline: ({offline}/{members}): {offline-list}"); - defaults.add("Alt List: {alts}"); // this.requiredArgs.add(""); this.optionalArgs.put("faction tag", "yours"); - this.permission = Permission.SHOW.node; - this.disableOnLock = false; - - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.SHOW).build(); } @Override - public void perform() { - Faction faction = myFaction; - if (this.argIsSet(0)) - faction = this.argAsFaction(0); + public void perform(CommandContext context) { + Faction faction = context.faction; + if (context.argIsSet(0)) + faction = context.argAsFaction(0); if (faction == null) return; - if (fme != null && !fme.getPlayer().hasPermission("factions.show.bypassexempt") - && P.p.getConfig().getStringList("show-exempt").contains(faction.getTag())) { - msg(TL.COMMAND_SHOW_EXEMPT); + if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt") + && FactionsPlugin.getInstance().getConfig().getStringList("show-exempt").contains(faction.getTag())) { + context.msg(TL.COMMAND_SHOW_EXEMPT); return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) { + if (!context.payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) { return; } - List show = P.p.getConfig().getStringList("show"); + List show = FactionsPlugin.getInstance().getConfig().getStringList("show"); if (show == null || show.isEmpty()) show = defaults; if (!faction.isNormal()) { - String tag = faction.getTag(fme); + String tag = faction.getTag(context.fPlayer); // send header and that's all String header = show.get(0); if (TagReplacer.HEADER.contains(header)) { - msg(p.txt.titleize(tag)); + context.msg(FactionsPlugin.getInstance().txt.titleize(tag)); } else { - msg(p.txt.parse(TagReplacer.FACTION.replace(header, tag))); + context.msg(FactionsPlugin.getInstance().txt.parse(TagReplacer.FACTION.replace(header, tag))); } return; // we only show header for non-normal factions } for (String raw : show) { - String parsed = TagUtil.parsePlain(faction, fme, raw); // use relations + String parsed = TagUtil.parsePlain(faction, context.fPlayer, raw); // use relations if (parsed == null) { continue; // Due to minimal f show. } - if (fme != null) { - parsed = TagUtil.parsePlaceholders(fme.getPlayer(), parsed); + if (context.fPlayer != null) { + parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed); } if (TagUtil.hasFancy(parsed)) { - List fancy = TagUtil.parseFancy(faction, fme, parsed); + List fancy = TagUtil.parseFancy(faction, context.fPlayer, parsed); if (fancy != null) - sendFancyMessage(fancy); + context.sendFancyMessage(fancy); continue; } @@ -108,7 +100,7 @@ public class CmdShow extends FCommand { if (parsed.contains("%")) { parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. } - msg(p.txt.parse(parsed)); + context.msg(FactionsPlugin.getInstance().txt.parse(parsed)); } } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShowClaims.java b/src/main/java/com/massivecraft/factions/cmd/CmdShowClaims.java index fc6b685e..9b444895 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShowClaims.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShowClaims.java @@ -9,39 +9,37 @@ import com.massivecraft.factions.zcore.util.TL; public class CmdShowClaims extends FCommand { public CmdShowClaims() { - this.aliases.add("showclaims"); this.aliases.add("showclaim"); - permission = Permission.SHOWCLAIMS.node; - - this.senderMustBePlayer = true; - this.senderMustBeMember = true; - this.senderMustBeModerator = false; + this.requirements = new CommandRequirements.Builder(Permission.SHOWCLAIMS) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}", fme.getFaction().describeTo(fme))); + public void perform(CommandContext context) { + context.sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}", context.faction.describeTo(context.fPlayer))); ListMultimap chunkMap = ArrayListMultimap.create(); String format = TL.COMMAND_SHOWCLAIMS_CHUNKSFORMAT.toString(); - for (FLocation fLocation : fme.getFaction().getAllClaims()) { + for (FLocation fLocation : context.faction.getAllClaims()) { chunkMap.put(fLocation.getWorldName(), format.replace("{x}", fLocation.getX() + "").replace("{z}", fLocation.getZ() + "")); } for (String world : chunkMap.keySet()) { String message = TL.COMMAND_SHOWCLAIMS_FORMAT.toString().replace("{world}", world); // made {chunks} blank as I removed the placeholder and people wont update their config :shrug: - sendMessage(message.replace("{chunks}", "")); + context.sendMessage(message.replace("{chunks}", "")); StringBuilder chunks = new StringBuilder(); for (String chunkString : chunkMap.get(world)) { chunks.append(chunkString).append(", "); if (chunks.toString().length() >= 2000) { - sendMessage(chunks.toString()); + context.sendMessage(chunks.toString()); chunks.setLength(0); } } - if (chunks.length() != 0) sendMessage(chunks.toString()); - sendMessage(""); + if (chunks.length() != 0) context.sendMessage(chunks.toString()); + context.sendMessage(""); } @@ -54,3 +52,4 @@ public class CmdShowClaims extends FCommand { } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java b/src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java index 4666ff03..fec89067 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java @@ -13,23 +13,24 @@ public class CmdShowInvites extends FCommand { public CmdShowInvites() { super(); aliases.add("showinvites"); - permission = Permission.SHOW_INVITES.node; - senderMustBePlayer = true; - senderMustBeMember = true; + this.requirements = new CommandRequirements.Builder(Permission.SHOW_INVITES) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { FancyMessage msg = new FancyMessage(TL.COMMAND_SHOWINVITES_PENDING.toString()).color(ChatColor.GOLD); - for (String id : myFaction.getInvites()) { + for (String id : context.faction.getInvites()) { FPlayer fp = FPlayers.getInstance().getById(id); String name = fp != null ? fp.getName() : id; msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_SHOWINVITES_CLICKTOREVOKE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name); } - sendFancyMessage(msg); + context.sendFancyMessage(msg); } @Override @@ -39,3 +40,4 @@ public class CmdShowInvites extends FCommand { } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSpam.java b/src/main/java/com/massivecraft/factions/cmd/CmdSpam.java deleted file mode 100644 index 49a10a7e..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSpam.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.zcore.util.TL; - -public class CmdSpam extends FCommand { - - public CmdSpam() { - this.aliases.add("spam"); - - this.optionalArgs.put("on/off", "flip"); - - this.permission = Permission.SPAM.node; - this.disableOnLock = false; - this.disableOnSpam = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; - } - - @Override - public void perform() { - p.setSpam(this.argAsBool(0, !p.getSpam())); - msg(p.getSpam() ? TL.COMMAND_SPAM_ENABLED : TL.COMMAND_SPAM_DISABLED); - } - - @Override - public TL getUsageTranslation() { - return TL.COMMAND_SPAM_DESCRIPTION; - } -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStatus.java b/src/main/java/com/massivecraft/factions/cmd/CmdStatus.java index 4dfec779..c961fcce 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdStatus.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStatus.java @@ -15,25 +15,22 @@ public class CmdStatus extends FCommand { this.aliases.add("status"); this.aliases.add("s"); - this.permission = Permission.STATUS.node; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.STATUS) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { ArrayList ret = new ArrayList<>(); - for (FPlayer fp : myFaction.getFPlayers()) { + for (FPlayer fp : context.faction.getFPlayers()) { String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX; String last = fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized); String power = ChatColor.YELLOW + String.valueOf(fp.getPowerRounded()) + " / " + fp.getPowerMaxRounded() + ChatColor.RESET; ret.add(String.format(TL.COMMAND_STATUS_FORMAT.toString(), ChatColor.GOLD + fp.getRole().getPrefix() + fp.getName() + ChatColor.RESET, power, last).trim()); } - fme.sendMessage(ret); + context.fPlayer.sendMessage(ret); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java b/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java index 277828e6..89c560dd 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -8,31 +7,23 @@ public class CmdStealth extends FCommand { public CmdStealth() { this.aliases.add("ninja"); this.aliases.add("stealth"); - this.permission = Permission.STEALTH.node; - - this.disableOnLock = true; - - this.senderMustBePlayer = true; - this.senderMustBeMember = false; - this.senderMustBeModerator = false; - this.senderMustBeColeader = false; - this.senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.STEALTH) + .playerOnly() + .build(); } - public void perform() { - - - Faction faction = fme.getFaction(); - if (faction != null && !faction.getId().equalsIgnoreCase("0") && !faction.getId().equalsIgnoreCase("none") && !faction.getId().equalsIgnoreCase("safezone") && !faction.getId().equalsIgnoreCase("warzone")) { - fme.setStealth(!fme.isStealthEnabled()); - fme.msg(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE); + @Override + public void perform(CommandContext context) { + if (context.faction != null && !context.faction.getId().equalsIgnoreCase("0") && !context.faction.getId().equalsIgnoreCase("none") && !context.faction.getId().equalsIgnoreCase("safezone") && !context.faction.getId().equalsIgnoreCase("warzone")) { + context.fPlayer.setStealth(!context.fPlayer.isStealthEnabled()); + context.msg(context.fPlayer.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE); } else { - fme.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER); + context.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER); } } public TL getUsageTranslation() { return TL.COMMAND_STEALTH_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStrike.java b/src/main/java/com/massivecraft/factions/cmd/CmdStrike.java deleted file mode 100644 index 25677b87..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdStrike.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.zcore.util.TL; - -public class CmdStrike extends FCommand { - - public CmdStrike() { - super(); - - this.aliases.add("strike"); - this.aliases.add("strikes"); - - this.optionalArgs.put("faction", "tag"); - - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; - } - - - @Override - public void perform() { - if (args.size() == 0) { - if (myFaction.isWilderness()) { - fme.msg(TL.COMMAND_STRIKE_NEEDFACTION); - return; - } - fme.msg(TL.COMMAND_STRIKE_MESSAGE.toString().replace("{faction}", fme.getFaction().getTag()).replace("{strikes}", fme.getFaction().getStrikes() + "")); - return; - } - Faction faction = Factions.getInstance().getByTag(args.get(0)); - if (faction != null) { - fme.msg(TL.COMMAND_STRIKE_MESSAGE.toString().replace("{faction}", faction.getTag()).replace("{strikes}", faction.getStrikes() + "")); - } else { - fme.msg(TL.COMMAND_STRIKE_NOTFOUND.toString().replace("{faction}", args.get(0))); - } - } - - - @Override - public TL getUsageTranslation() { - return TL.COMMAND_STUCK_DESCRIPTION; - } - - -} - diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStrikeSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdStrikeSet.java deleted file mode 100644 index de045df3..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdStrikeSet.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.zcore.util.TL; - -public class CmdStrikeSet extends FCommand { - - - public CmdStrikeSet() { - super(); - this.aliases.add("setstrikes"); - this.aliases.add("setstrike"); - - this.requiredArgs.add("set,give,remove"); - this.requiredArgs.add("faction"); - this.requiredArgs.add("# of strikes"); - this.requiredArgs.add("reason"); - - - this.errorOnToManyArgs = false; - //this.optionalArgs - - this.permission = Permission.SETSTRIKES.node; - - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; - } - - - @Override - public void perform() { - Faction faction = Factions.getInstance().getByTag(args.get(1)); - boolean success = false; - if (faction == null) { - fme.msg(TL.COMMAND_SETSTRIKES_FAILURE.toString().replace("{faction}", args.get(1))); - } - - if (faction != null) { - if (args.get(0).equalsIgnoreCase("set")) { - faction.setStrikes(argAsInt(2)); - success = true; - } else if (args.get(0).equalsIgnoreCase("give")) { - faction.setStrikes(faction.getStrikes() + argAsInt(2)); - success = true; - } else if (args.get(0).equalsIgnoreCase("take")) { - faction.setStrikes(faction.getStrikes() - argAsInt(2)); - success = true; - } - if (success) { - for (FPlayer fPlayer : FPlayers.getInstance().getOnlinePlayers()) { - fPlayer.msg(TL.COMMAND_SETSTRIKES_BROADCAST.toString() - .replace("{faction}", faction.getTag()) - .replace("{reason}", getReason())); - } - fme.msg(TL.COMMAND_SETSTRIKES_SUCCESS.toString() - .replace("{faction}", faction.getTag()) - .replace("{strikes}", faction.getStrikes() + "")); - } - } - } - - private String getReason() { - StringBuilder reason = new StringBuilder(); - for (int i = 3; i < args.size(); i++) { - reason.append(args.get(i)).append(" "); - } - return reason.toString(); - } - - - @Override - public TL getUsageTranslation() { - return TL.COMMAND_SETSTRIKES_DESCRIPTION; - } - - -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStrikes.java b/src/main/java/com/massivecraft/factions/cmd/CmdStrikes.java new file mode 100644 index 00000000..27f8589c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStrikes.java @@ -0,0 +1,41 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdStrikes extends FCommand { + + + public CmdStrikesGive cmdStrikesGive = new CmdStrikesGive(); + public CmdStrikesInfo cmdStrikesInfo = new CmdStrikesInfo(); + public CmdStrikesSet cmdStrikesSet = new CmdStrikesSet(); + public CmdStrikesTake cmdStrikesTake = new CmdStrikesTake(); + + public CmdStrikes() { + super(); + + this.aliases.add("strikes"); + + this.addSubCommand(cmdStrikesGive); + this.addSubCommand(cmdStrikesInfo); + this.addSubCommand(cmdStrikesSet); + this.addSubCommand(cmdStrikesTake); + + this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES) + .playerOnly() + .build(); + } + + @Override + public void perform(CommandContext context) { + context.commandChain.add(this); + FactionsPlugin.getInstance().cmdAutoHelp.execute(context); + } + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_STRIKES_DESCRIPTION; + } + +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStrikesGive.java b/src/main/java/com/massivecraft/factions/cmd/CmdStrikesGive.java new file mode 100644 index 00000000..dff72694 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStrikesGive.java @@ -0,0 +1,37 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdStrikesGive extends FCommand { + + + public CmdStrikesGive() { + super(); + this.aliases.add("give"); + this.requiredArgs.add(0, "faction"); + + this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES) + .playerOnly() + .build(); + } + + @Override + public void perform(CommandContext context) { + Faction target = context.argAsFaction(0); + if (target == null || target.isSystemFaction()) { + context.msg(TL.COMMAND_STRIKES_TARGET_INVALID, context.argAsString(0)); + return; + } + target.setStrikes(target.getStrikes() + 1); + context.msg(TL.COMMAND_STRIKES_CHANGED, target.getTag(), target.getStrikes()); + } + + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_STRIKESGIVE_DESCRIPTION; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStrikesInfo.java b/src/main/java/com/massivecraft/factions/cmd/CmdStrikesInfo.java new file mode 100644 index 00000000..f6d61a5b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStrikesInfo.java @@ -0,0 +1,37 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdStrikesInfo extends FCommand { + + public CmdStrikesInfo() { + super(); + this.aliases.add("info"); + this.optionalArgs.put("target", "faction"); + + this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES) + .playerOnly() + .build(); + } + + @Override + public void perform(CommandContext context) { + Faction target = context.argAsFaction(0); + if (target == null) target = context.faction; + if (target.isSystemFaction()) { + context.msg(TL.COMMAND_STRIKES_TARGET_INVALID, context.argAsString(0)); + return; + } + context.msg(TL.COMMAND_STRIKES_INFO, target.getTag(), target.getStrikes()); + } + + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_STRIKESINFO_DESCRIPTION; + } + + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStrikesSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdStrikesSet.java new file mode 100644 index 00000000..e7937a8c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStrikesSet.java @@ -0,0 +1,37 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdStrikesSet extends FCommand { + + public CmdStrikesSet() { + super(); + this.aliases.add("set"); + this.requiredArgs.add(0, "faction"); + this.requiredArgs.add(1, "amount"); + + this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES) + .playerOnly() + .build(); + } + + @Override + public void perform(CommandContext context) { + Faction target = context.argAsFaction(0); + if (target == null || target.isSystemFaction()) { + context.msg(TL.COMMAND_STRIKES_TARGET_INVALID, context.argAsString(0)); + return; + } + target.setStrikes(context.argAsInt(1)); + context.msg(TL.COMMAND_STRIKES_CHANGED, target.getTag(), target.getStrikes()); + } + + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_STRIKESET_DESCRIPTION; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStrikesTake.java b/src/main/java/com/massivecraft/factions/cmd/CmdStrikesTake.java new file mode 100644 index 00000000..e405a37b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStrikesTake.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdStrikesTake extends FCommand { + + + public CmdStrikesTake() { + super(); + this.aliases.add("take"); + this.requiredArgs.add(0, "faction"); + this.requiredArgs.add(1, "number of strikes"); + + this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES) + .playerOnly() + .build(); + } + + @Override + public void perform(CommandContext context) { + Faction target = context.argAsFaction(0); + if (target == null || target.isSystemFaction()) { + context.msg(TL.COMMAND_STRIKES_TARGET_INVALID, context.argAsString(0)); + return; + } + target.setStrikes(target.getStrikes() - context.argAsInt(1)); + context.msg(TL.COMMAND_STRIKES_CHANGED, target.getTag(), target.getStrikes()); + } + + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_STRIKETAKE_DESCRIPTION; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStuck.java b/src/main/java/com/massivecraft/factions/cmd/CmdStuck.java index 827acf64..a0a3b9ef 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdStuck.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStuck.java @@ -10,87 +10,75 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; public class CmdStuck extends FCommand { public CmdStuck() { super(); - this.aliases.add("stuck"); this.aliases.add("halp!"); // halp!c: - this.permission = Permission.STUCK.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.STUCK) + .playerOnly() + .build(); } @Override - public void perform() { - final Player player = fme.getPlayer(); + public void perform(CommandContext context) { + final Player player = context.player; final Location sentAt = player.getLocation(); - final FLocation chunk = fme.getLastStoodAt(); - final long delay = P.p.getConfig().getLong("hcf.stuck.delay", 30); - final int radius = P.p.getConfig().getInt("hcf.stuck.radius", 10); + final FLocation chunk = context.fPlayer.getLastStoodAt(); + final long delay = FactionsPlugin.getInstance().getConfig().getLong("hcf.stuck.delay", 30); + final int radius = FactionsPlugin.getInstance().getConfig().getInt("hcf.stuck.radius", 10); - if (P.p.getStuckMap().containsKey(player.getUniqueId())) { - long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis(); + if (FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) { + long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis(); String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true); - msg(TL.COMMAND_STUCK_EXISTS, time); + context.msg(TL.COMMAND_STUCK_EXISTS, time); } else { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostStuck, TL.COMMAND_STUCK_TOSTUCK.format(fme.getName()), TL.COMMAND_STUCK_FORSTUCK.format(fme.getName()))) { + if (!context.payForCommand(Conf.econCostStuck, TL.COMMAND_STUCK_TOSTUCK.format(context.fPlayer.getName()), TL.COMMAND_STUCK_FORSTUCK.format(context.fPlayer.getName()))) { return; } - final int id = Bukkit.getScheduler().runTaskLater(P.p, new BukkitRunnable() { + final int id = Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), new Runnable() { @Override public void run() { - if (!P.p.getStuckMap().containsKey(player.getUniqueId())) { + if (!FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) { return; } // check for world difference or radius exceeding final World world = chunk.getWorld(); if (world.getUID() != player.getWorld().getUID() || sentAt.distance(player.getLocation()) > radius) { - msg(TL.COMMAND_STUCK_OUTSIDE.format(radius)); - P.p.getTimers().remove(player.getUniqueId()); - P.p.getStuckMap().remove(player.getUniqueId()); + context.msg(TL.COMMAND_STUCK_OUTSIDE.format(radius)); + FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId()); + FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId()); return; } final Board board = Board.getInstance(); // spiral task to find nearest wilderness chunk - new SpiralTask(new FLocation(me), radius * 2) { - - final int buffer = P.p.getConfig().getInt("world-border.buffer", 0); - + new SpiralTask(new FLocation(context.player), radius * 2) { @Override public boolean work() { FLocation chunk = currentFLocation(); - if (chunk.isOutsideWorldBorder(buffer)) { - return true; - } Faction faction = board.getFactionAt(chunk); - int buffer = P.p.getConfig().getInt("world-border.buffer", 0); + int buffer = FactionsPlugin.getInstance().getConfig().getInt("world-border.buffer", 0) - 1; if (faction.isWilderness() && !chunk.isOutsideWorldBorder(buffer)) { int cx = FLocation.chunkToBlock((int) chunk.getX()); int cz = FLocation.chunkToBlock((int) chunk.getZ()); int y = world.getHighestBlockYAt(cx, cz); Location tp = new Location(world, cx, y, cz); - msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ()); - P.p.getTimers().remove(player.getUniqueId()); - P.p.getStuckMap().remove(player.getUniqueId()); + context.msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ()); + FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId()); + FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId()); if (!Essentials.handleTeleport(player, tp)) { player.teleport(tp); - P.p.debug("/f stuck used regular teleport, not essentials!"); + FactionsPlugin.getInstance().debug("/f stuck used regular teleport, not essentials!"); } this.stop(); return false; @@ -101,11 +89,11 @@ public class CmdStuck extends FCommand { } }, delay * 20).getTaskId(); - P.p.getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000)); - long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis(); + FactionsPlugin.getInstance().getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000)); + long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis(); String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true); - msg(TL.COMMAND_STUCK_START, time); - P.p.getStuckMap().put(player.getUniqueId(), id); + context.msg(TL.COMMAND_STUCK_START, time); + FactionsPlugin.getInstance().getStuckMap().put(player.getUniqueId(), id); } } @@ -114,3 +102,4 @@ public class CmdStuck extends FCommand { return TL.COMMAND_STUCK_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdTag.java b/src/main/java/com/massivecraft/factions/cmd/CmdTag.java index c8da8382..5c5ab560 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdTag.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdTag.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.event.FactionRenameEvent; import com.massivecraft.factions.scoreboards.FTeamWrapper; import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; @@ -17,77 +18,65 @@ public class CmdTag extends FCommand { this.aliases.add("rename"); this.requiredArgs.add("faction tag"); - //this.optionalArgs.put("", ""); - - this.permission = Permission.TAG.node; - this.disableOnLock = true; - this.disableOnSpam = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.TAG) + .withRole(Role.COLEADER) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - String tag = this.argAsString(0); - - - if (!fme.isCooldownEnded("tag")) { - fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("tag")); - return; - } - + public void perform(CommandContext context) { + String tag = context.argAsString(0); // TODO does not first test cover selfcase? - if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) { - msg(TL.COMMAND_TAG_TAKEN); + if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(context.faction.getComparisonTag())) { + context.msg(TL.COMMAND_TAG_TAKEN); return; } ArrayList errors = MiscUtil.validateTag(tag); if (errors.size() > 0) { - sendMessage(errors); + context.sendMessage(errors); return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay - if (!canAffordCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE.toString())) { + if (!context.canAffordCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE.toString())) { return; } // trigger the faction rename event (cancellable) - FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag); + FactionRenameEvent renameEvent = new FactionRenameEvent(context.fPlayer, tag); Bukkit.getServer().getPluginManager().callEvent(renameEvent); if (renameEvent.isCancelled()) { return; } // then make 'em pay (if applicable) - if (!payForCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE, TL.COMMAND_TAG_FORCHANGE)) { + if (!context.payForCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE, TL.COMMAND_TAG_FORCHANGE)) { return; } - String oldtag = myFaction.getTag(); - myFaction.setTag(tag); + String oldtag = context.faction.getTag(); + context.faction.setTag(tag); // Inform for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { - if (fplayer.getFactionId().equals(myFaction.getId())) { - fplayer.msg(TL.COMMAND_TAG_FACTION, fme.describeTo(myFaction, true), myFaction.getTag(myFaction)); + if (fplayer.getFactionId().equals(context.faction.getId())) { + fplayer.msg(TL.COMMAND_TAG_FACTION, context.fPlayer.describeTo(context.faction, true), context.faction.getTag(context.faction)); continue; } // Broadcast the tag change (if applicable) if (Conf.broadcastTagChanges) { Faction faction = fplayer.getFaction(); - fplayer.msg(TL.COMMAND_TAG_CHANGED, fme.getColorTo(faction) + oldtag, myFaction.getTag(faction)); + fplayer.msg(TL.COMMAND_TAG_CHANGED, context.fPlayer.getColorTo(faction) + oldtag, context.faction.getTag(faction)); } } - fme.setCooldown("tag", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-tag") * 1000)); - FTeamWrapper.updatePrefixes(myFaction); + + FTeamWrapper.updatePrefixes(context.faction); } @Override @@ -95,4 +84,4 @@ public class CmdTag extends FCommand { return TL.COMMAND_TAG_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdTitle.java b/src/main/java/com/massivecraft/factions/cmd/CmdTitle.java index 7202927c..1afcda0d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdTitle.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdTitle.java @@ -10,45 +10,26 @@ public class CmdTitle extends FCommand { public CmdTitle() { this.aliases.add("title"); - this.requiredArgs.add("player name"); this.optionalArgs.put("title", ""); - this.permission = Permission.TITLE.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = true; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.TITLE) + .playerOnly() + .build(); } @Override - public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); - if (you == null) { - return; - } - - - args.remove(0); - String title = TextUtil.implode(args, " "); - title = title.replaceAll(",", ""); - - if (!canIAdministerYou(fme, you)) { - return; - } - + public void perform(CommandContext context) { + FPlayer you = context.argAsBestFPlayerMatch(0); + if (you == null) return; + context.args.remove(0); + String title = TextUtil.implode(context.args, " "); + if (!context.canIAdministerYou(context.fPlayer, you)) return; // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostTitle, TL.COMMAND_TITLE_TOCHANGE, TL.COMMAND_TITLE_FORCHANGE)) { - return; - } - - you.setTitle(sender, title); - + if (!context.payForCommand(Conf.econCostTitle, TL.COMMAND_TITLE_TOCHANGE, TL.COMMAND_TITLE_FORCHANGE)) return; + you.setTitle(context.sender, title); // Inform - myFaction.msg(TL.COMMAND_TITLE_CHANGED, fme.describeTo(myFaction, true), you.describeTo(myFaction, true)); + context.faction.msg(TL.COMMAND_TITLE_CHANGED, context.fPlayer.describeTo(context.faction, true), you.describeTo(context.faction, true)); } @Override @@ -56,4 +37,4 @@ public class CmdTitle extends FCommand { return TL.COMMAND_TITLE_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdToggleAllianceChat.java b/src/main/java/com/massivecraft/factions/cmd/CmdToggleAllianceChat.java index 95664b6d..490ac8cd 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdToggleAllianceChat.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdToggleAllianceChat.java @@ -12,16 +12,10 @@ public class CmdToggleAllianceChat extends FCommand { this.aliases.add("togglealliancechat"); this.aliases.add("ac"); - this.disableOnLock = false; - - this.permission = Permission.TOGGLE_ALLIANCE_CHAT.node; - this.disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.TOGGLE_ALLIANCE_CHAT) + .playerOnly() + .memberOnly() + .build(); } @Override @@ -30,15 +24,16 @@ public class CmdToggleAllianceChat extends FCommand { } @Override - public void perform() { + public void perform(CommandContext context) { if (!Conf.factionOnlyChat) { - msg(TL.COMMAND_CHAT_DISABLED.toString()); + context.msg(TL.COMMAND_CHAT_DISABLED.toString()); return; } - boolean ignoring = fme.isIgnoreAllianceChat(); + boolean ignoring = context.fPlayer.isIgnoreAllianceChat(); - msg(ignoring ? TL.COMMAND_TOGGLEALLIANCECHAT_UNIGNORE : TL.COMMAND_TOGGLEALLIANCECHAT_IGNORE); - fme.setIgnoreAllianceChat(!ignoring); + context.msg(ignoring ? TL.COMMAND_TOGGLEALLIANCECHAT_UNIGNORE : TL.COMMAND_TOGGLEALLIANCECHAT_IGNORE); + context.fPlayer.setIgnoreAllianceChat(!ignoring); } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdTop.java b/src/main/java/com/massivecraft/factions/cmd/CmdTop.java index 1ae8c5bb..cdd20d0c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdTop.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdTop.java @@ -16,24 +16,16 @@ public class CmdTop extends FCommand { super(); this.aliases.add("top"); this.aliases.add("t"); - - //this.requiredArgs.add(""); this.requiredArgs.add("criteria"); this.optionalArgs.put("page", "1"); - this.permission = Permission.TOP.node; - this.disableOnLock = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.TOP) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // Can sort by: money, members, online, allies, enemies, power, land. // Get all Factions and remove non player ones. ArrayList factionList = Factions.getInstance().getAllFactions(); @@ -41,7 +33,7 @@ public class CmdTop extends FCommand { factionList.remove(Factions.getInstance().getSafeZone()); factionList.remove(Factions.getInstance().getWarZone()); - String criteria = argAsString(0); + String criteria = context.argAsString(0); // TODO: Better way to sort? if (criteria.equalsIgnoreCase("members")) { @@ -119,14 +111,13 @@ public class CmdTop extends FCommand { return 0; }); } else { - msg(TL.COMMAND_TOP_INVALID, criteria); - return; + context.msg(TL.COMMAND_TOP_INVALID, criteria); } ArrayList lines = new ArrayList<>(); final int pageheight = 9; - int pagenumber = this.argAsInt(1, 1); + int pagenumber = context.argAsInt(1, 1); int pagecount = (factionList.size() / pageheight) + 1; if (pagenumber > pagecount) { pagenumber = pagecount; @@ -144,12 +135,12 @@ public class CmdTop extends FCommand { int rank = 1; for (Faction faction : factionList.subList(start, end)) { // Get the relation color if player is executing this. - String fac = sender instanceof Player ? faction.getRelationTo(fme).getColor() + faction.getTag() : faction.getTag(); + String fac = context.sender instanceof Player ? faction.getRelationTo(context.fPlayer).getColor() + faction.getTag() : faction.getTag(); lines.add(TL.COMMAND_TOP_LINE.format(rank, fac, getValue(faction, criteria))); rank++; } - sendMessage(lines); + context.sendMessage(lines); } private String getValue(Faction faction, String criteria) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdTpBanner.java b/src/main/java/com/massivecraft/factions/cmd/CmdTpBanner.java index 0e6c739f..713b5aac 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdTpBanner.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdTpBanner.java @@ -1,39 +1,39 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.listeners.FactionsBlockListener; +import com.massivecraft.factions.listeners.FactionsPlayerListener; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.zcore.util.TL; public class CmdTpBanner extends FCommand { + public CmdTpBanner() { super(); - this.aliases.add("tpbanner"); - this.permission = Permission.TPBANNER.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.TPBANNER) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("fbanners.Enabled")) { + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Enabled")) { return; } - if (FactionsBlockListener.bannerLocations.containsKey(fme.getTag())) { - fme.msg(TL.COMMAND_TPBANNER_SUCCESS); - this.doWarmUp(WarmUpUtil.Warmup.BANNER, TL.WARMUPS_NOTIFY_TELEPORT, "Banner", () -> me.teleport(FactionsBlockListener.bannerLocations.get(fme.getTag())), this.p.getConfig().getLong("warmups.f-banner", 0)); + final FactionsPlayerListener fpl = new FactionsPlayerListener(); + + 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)); } else { - fme.msg(TL.COMMAND_TPBANNER_NOTSET); + 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 86ba4be7..fc293630 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java @@ -2,7 +2,6 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; @@ -12,44 +11,40 @@ public class CmdUnban extends FCommand { public CmdUnban() { super(); this.aliases.add("unban"); - this.requiredArgs.add("target"); - this.permission = Permission.BAN.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.BAN) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.BAN) + .build(); } @Override - public void perform() { - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.BAN); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER && !Permission.BAN.has(sender, true)) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage bans"); - return; - } - } - + public void perform(CommandContext context) { // Good on permission checks. Now lets just ban the player. - FPlayer target = argAsFPlayer(0); + FPlayer target = context.argAsFPlayer(0); if (target == null) { return; // the above method sends a message if fails to find someone. } - if (!myFaction.isBanned(target)) { - fme.msg(TL.COMMAND_UNBAN_NOTBANNED, target.getName()); + if (target.getFaction() != context.fPlayer.getFaction()) { + if (target.getFaction().getAccess(context.fPlayer, PermissableAction.BAN) != Access.ALLOW) { + if (!context.fPlayer.isAdminBypassing()) { + context.fPlayer.msg(TL.COMMAND_UNBAN_TARGET_IN_OTHER_FACTION); + } + } + } + + if (!context.faction.isBanned(target)) { + context.msg(TL.COMMAND_UNBAN_NOTBANNED, target.getName()); return; } - myFaction.unban(target); + context.faction.unban(target); - myFaction.msg(TL.COMMAND_UNBAN_UNBANNED, fme.getName(), target.getName()); - target.msg(TL.COMMAND_UNBAN_TARGET, myFaction.getTag(target)); + context.msg(TL.COMMAND_UNBAN_UNBANNED, context.fPlayer.getName(), target.getName()); + target.msg(TL.COMMAND_UNBAN_TARGET, context.faction.getTag(target)); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdUpgrades.java b/src/main/java/com/massivecraft/factions/cmd/CmdUpgrades.java index 70ae131d..898eccf9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdUpgrades.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdUpgrades.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.fupgrades.FUpgradesGUI; import com.massivecraft.factions.zcore.util.TL; @@ -11,26 +11,20 @@ public class CmdUpgrades extends FCommand { this.aliases.add("upgrades"); this.aliases.add("upgrade"); - //this.requiredArgs.add(""); - this.optionalArgs.put("mobs/crops/exp/power", ""); - - this.permission = Permission.UPGRADES.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.UPGRADES) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("fupgrades.Enabled")) { - fme.sendMessage("This command is disabled!"); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fupgrades.Enabled")) { + context.fPlayer.sendMessage("This command is disabled!"); return; } - new FUpgradesGUI().openMainMenu(fme); + new FUpgradesGUI().openMainMenu(context.fPlayer); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdVault.java b/src/main/java/com/massivecraft/factions/cmd/CmdVault.java index ba5cf284..716b0b7b 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdVault.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdVault.java @@ -2,9 +2,8 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Location; @@ -17,57 +16,48 @@ public class CmdVault extends FCommand { public CmdVault() { this.aliases.add("vault"); - //this.requiredArgs.add(""); - - - this.permission = Permission.VAULT.node; - this.disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.VAULT) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.VAULT) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { - if (!P.p.getConfig().getBoolean("fvault.Enabled")) { - fme.sendMessage("This command is disabled!"); - return; - } - Access access = fme.getFaction().getAccess(fme, PermissableAction.VAULT); - if (access.equals(Access.DENY)) { - fme.msg(TL.GENERIC_NOPERMISSION, "vault"); + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fvault.Enabled")) { + context.fPlayer.sendMessage("This command is disabled!"); return; } - if (fme.isInVault()) { - me.closeInventory(); + if (context.fPlayer.isInVault()) { + context.player.closeInventory(); return; } - fme.setInVault(true); - Location vaultLocation = fme.getFaction().getVault(); + + context.fPlayer.setInVault(true); + Location vaultLocation = context.faction.getVault(); if (vaultLocation == null) { - fme.msg(TL.COMMAND_VAULT_INVALID); + context.msg(TL.COMMAND_VAULT_INVALID); return; } FLocation vaultFLocation = new FLocation(vaultLocation); - if (Board.getInstance().getFactionAt(vaultFLocation) != fme.getFaction()) { - fme.getFaction().setVault(null); - fme.msg(TL.COMMAND_VAULT_INVALID); + if (Board.getInstance().getFactionAt(vaultFLocation) != context.faction) { + context.faction.setVault(null); + context.msg(TL.COMMAND_VAULT_INVALID); return; } if (vaultLocation.getBlock().getType() != Material.CHEST) { - fme.getFaction().setVault(null); - fme.msg(TL.COMMAND_VAULT_INVALID); + context.faction.setVault(null); + context.msg(TL.COMMAND_VAULT_INVALID); return; } Chest chest = (Chest) vaultLocation.getBlock().getState(); Inventory chestInv = chest.getBlockInventory(); - fme.msg(TL.COMMAND_VAULT_OPENING); - me.openInventory(chestInv); + context.msg(TL.COMMAND_VAULT_OPENING); + context.player.openInventory(chestInv); } @@ -76,4 +66,5 @@ public class CmdVault extends FCommand { public TL getUsageTranslation() { return TL.COMMAND_VAULT_DESCRIPTION; } -} + +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdVersion.java b/src/main/java/com/massivecraft/factions/cmd/CmdVersion.java index 376ddd66..3943a863 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdVersion.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdVersion.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -11,26 +11,18 @@ public class CmdVersion extends FCommand { this.aliases.add("version"); this.aliases.add("ver"); - //this.requiredArgs.add(""); - //this.optionalArgs.put("", ""); - - this.permission = Permission.VERSION.node; - this.disableOnLock = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.VERSION) + .build(); } @Override - public void perform() { - msg(TL.COMMAND_VERSION_NAME); // Did this so people can differentiate between P and FactionsUUID (( Requested Feature )) - msg(TL.COMMAND_VERSION_VERSION, P.p.getDescription().getFullName()); + public void perform(CommandContext context) { + context.msg(TL.COMMAND_VERSION_NAME); // Did this so people can differentiate between SavageFactions and FactionsUUID (( Requested Feature )) + context.msg(TL.COMMAND_VERSION_VERSION, FactionsPlugin.getInstance().getDescription().getFullName()); } @Override public TL getUsageTranslation() { return TL.COMMAND_VERSION_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdViewChest.java b/src/main/java/com/massivecraft/factions/cmd/CmdViewChest.java index bfc7323c..d7af8c36 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdViewChest.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdViewChest.java @@ -1,40 +1,38 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; public class CmdViewChest extends FCommand { public CmdViewChest() { + super(); this.aliases.add("viewchest"); this.aliases.add("viewpv"); this.requiredArgs.add("faction name"); - - this.permission = Permission.VIEWCHEST.node; - this.disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.VIEWCHEST) + .playerOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("fchest.Enabled")) { - fme.msg(TL.GENERIC_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fchest.Enabled")) { + context.msg(TL.GENERIC_DISABLED); return; } - Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); + Faction myFaction = context.fPlayer.getFaction(); + + Faction faction = context.argAsFaction(0, context.fPlayer == null ? null : myFaction); if (faction == null) { return; } - me.openInventory(faction.getChestInventory()); + context.player.openInventory(context.faction.getChestInventory()); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CommandContext.java b/src/main/java/com/massivecraft/factions/cmd/CommandContext.java new file mode 100644 index 00000000..b438b997 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CommandContext.java @@ -0,0 +1,418 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.*; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.util.WarmUpUtil; +import com.massivecraft.factions.zcore.util.TL; +import mkremins.fanciful.FancyMessage; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +/* + Object that contains information about a command being executed, + args, player, faction + */ +public class CommandContext { + + public CommandSender sender; + + public Player player; + public FPlayer fPlayer; + public Faction faction; + + public List args; + public String alias; + + public List commandChain = new ArrayList<>(); // The command chain used to execute this command + + public CommandContext(CommandSender sender, List args, String alias) { + this.sender = sender; + this.args = args; + this.alias = alias; + + if (sender instanceof Player) { + this.player = (Player) sender; + this.fPlayer = FPlayers.getInstance().getByPlayer(player); + this.faction = fPlayer.getFaction(); + } + } + + // -------------------------------------------- // + // Message Sending Helpers + // -------------------------------------------- // + + public void msg(String str, Object... args) { + sender.sendMessage(FactionsPlugin.getInstance().txt.parse(str, args)); + } + + public void msg(TL translation, Object... args) { + sender.sendMessage(FactionsPlugin.getInstance().txt.parse(translation.toString(), args)); + } + + public void sendMessage(String msg) { + sender.sendMessage(msg); + } + + public void sendMessage(List msgs) { + for (String msg : msgs) { + this.sendMessage(msg); + } + } + + public void sendFancyMessage(FancyMessage message) { + message.send(sender); + } + + public void sendFancyMessage(List messages) { + for (FancyMessage m : messages) { + sendFancyMessage(m); + } + } + + // TODO: Clean this UP + // -------------------------------------------- // + // Argument Readers + // -------------------------------------------- // + + // Is set? ====================== + public boolean argIsSet(int idx) { + return args.size() >= idx + 1; + } + + // STRING ====================== + public String argAsString(int idx, String def) { + if (args.size() < idx + 1) { + return def; + } + return args.get(idx); + } + + public String argAsString(int idx) { + return argAsString(idx, null); + } + + // INT ====================== + public Integer strAsInt(String str, Integer def) { + if (str == null) { + return def; + } + try { + return Integer.parseInt(str); + } catch (Exception e) { + return def; + } + } + + public Integer argAsInt(int idx, Integer def) { + return strAsInt(argAsString(idx), def); + } + + public Integer argAsInt(int idx) { + return argAsInt(idx, null); + } + + // Double ====================== + public Double strAsDouble(String str, Double def) { + if (str == null) { + return def; + } + try { + return Double.parseDouble(str); + } catch (Exception e) { + return def; + } + } + + public Double argAsDouble(int idx, Double def) { + return strAsDouble(argAsString(idx), def); + } + + public Double argAsDouble(int idx) { + return argAsDouble(idx, null); + } + + // TODO: Go through the str conversion for the other arg-readers as well. + // Boolean ====================== + public Boolean strAsBool(String str) { + str = str.toLowerCase(); + return str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1"); + } + + public Boolean argAsBool(int idx, boolean def) { + String str = argAsString(idx); + if (str == null) { + return def; + } + + return strAsBool(str); + } + + public Boolean argAsBool(int idx) { + return argAsBool(idx, false); + } + + // PLAYER ====================== + public Player strAsPlayer(String name, Player def, boolean msg) { + Player ret = def; + + if (name != null) { + Player player = Bukkit.getServer().getPlayer(name); + if (player != null) { + ret = player; + } + } + + if (msg && ret == null) { + sender.sendMessage(TL.GENERIC_NOPLAYERFOUND.format(name)); + } + + return ret; + } + + public Player argAsPlayer(int idx, Player def, boolean msg) { + return this.strAsPlayer(argAsString(idx), def, msg); + } + + public Player argAsPlayer(int idx, Player def) { + return argAsPlayer(idx, def, true); + } + + public Player argAsPlayer(int idx) { + return argAsPlayer(idx, null); + } + + // BEST PLAYER MATCH ====================== + public Player strAsBestPlayerMatch(String name, Player def, boolean msg) { + Player ret = def; + + if (name != null) { + List players = Bukkit.getServer().matchPlayer(name); + if (players.size() > 0) { + ret = players.get(0); + } + } + + if (msg && ret == null) { + sender.sendMessage(TL.GENERIC_NOPLAYERMATCH.format(name)); + } + + return ret; + } + + public Player argAsBestPlayerMatch(int idx, Player def, boolean msg) { + return this.strAsBestPlayerMatch(argAsString(idx), def, msg); + } + + public Player argAsBestPlayerMatch(int idx, Player def) { + return argAsBestPlayerMatch(idx, def, true); + } + + public Player argAsBestPlayerMatch(int idx) { + return argAsPlayer(idx, null); + } + + + // -------------------------------------------- // + // Faction Argument Readers + // -------------------------------------------- // + + // FPLAYER ====================== + public FPlayer strAsFPlayer(String name, FPlayer def, boolean msg) { + FPlayer ret = def; + + if (name != null) { + for (FPlayer fplayer : FPlayers.getInstance().getAllFPlayers()) { + if (fplayer.getName().equalsIgnoreCase(name)) { + ret = fplayer; + break; + } + } + } + + if (msg && ret == null) { + msg(TL.GENERIC_NOPLAYERFOUND, name); + } + + return ret; + } + + public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) { + return this.strAsFPlayer(argAsString(idx), def, msg); + } + + public FPlayer argAsFPlayer(int idx, FPlayer def) { + return argAsFPlayer(idx, def, true); + } + + public FPlayer argAsFPlayer(int idx) { + return argAsFPlayer(idx, null); + } + + // BEST FPLAYER MATCH ====================== + public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg) { + return strAsFPlayer(name, def, msg); + } + + public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg) { + return this.strAsBestFPlayerMatch(argAsString(idx), def, msg); + } + + public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) { + return argAsBestFPlayerMatch(idx, def, true); + } + + public FPlayer argAsBestFPlayerMatch(int idx) { + return argAsBestFPlayerMatch(idx, null); + } + + // FACTION ====================== + public Faction strAsFaction(String name, Faction def, boolean msg) { + Faction ret = def; + + if (name != null) { + // First we try an exact match + Faction faction = Factions.getInstance().getByTag(name); // Checks for faction name match. + + // Now lets try for warzone / safezone. Helpful for custom warzone / safezone names. + // Do this after we check for an exact match in case they rename the warzone / safezone + // and a player created faction took one of the names. + if (faction == null) { + if (name.equalsIgnoreCase("warzone")) { + faction = Factions.getInstance().getWarZone(); + } else if (name.equalsIgnoreCase("safezone")) { + faction = Factions.getInstance().getSafeZone(); + } + } + + // Next we match faction tags + if (faction == null) { + faction = Factions.getInstance().getBestTagMatch(name); + } + + // Next we match player names + if (faction == null) { + FPlayer fplayer = strAsFPlayer(name, null, false); + if (fplayer != null) { + faction = fplayer.getFaction(); + } + } + + if (faction != null) { + ret = faction; + } + } + + if (msg && ret == null) { + sender.sendMessage(TL.GENERIC_NOFACTION_FOUND.format(name)); + } + + return ret; + } + + public Faction argAsFaction(int idx, Faction def, boolean msg) { + return this.strAsFaction(argAsString(idx), def, msg); + } + + public Faction argAsFaction(int idx, Faction def) { + return argAsFaction(idx, def, true); + } + + public Faction argAsFaction(int idx) { + return argAsFaction(idx, null); + } + + /* + Assertions + */ + + public boolean assertHasFaction() { + if (player == null) { + return true; + } + + if (!fPlayer.hasFaction()) { + sendMessage("You are not member of any faction."); + return false; + } + return true; + } + + public boolean assertMinRole(Role role) { + if (player == null) { + return true; + } + + if (fPlayer.getRole().value < role.value) { + msg("You must be " + role); + return false; + } + return true; + } + + /* + Common Methods + */ + public boolean canIAdministerYou(FPlayer i, FPlayer you) { + if (!i.getFaction().equals(you.getFaction())) { + i.msg(TL.COMMAND_CONTEXT_ADMINISTER_DIF_FACTION, you.describeTo(i, true)); + return false; + } + + if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.LEADER)) return true; + + if (you.getRole().equals(Role.LEADER)) i.msg(TL.COMMAND_CONTEXT_ADMINISTER_ADMIN_REQUIRED); + + else if (i.getRole().equals(Role.MODERATOR)) { + + if (i == you) return true; //Moderators can control themselves + else i.msg(TL.COMMAND_CONTEXT_ADMINISTER_SAME_RANK_CONTROL); + + } else i.msg(TL.COMMAND_CONTEXT_ADMINISTER_MOD_REQUIRED); + + return false; + } + + // if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost + public boolean payForCommand(double cost, String toDoThis, String forDoingThis) { + if (!Econ.shouldBeUsed() || this.fPlayer == null || cost == 0.0 || fPlayer.isAdminBypassing()) { + return true; + } + + if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fPlayer.hasFaction()) { + return Econ.modifyMoney(faction, -cost, toDoThis, forDoingThis); + } else { + return Econ.modifyMoney(fPlayer, -cost, toDoThis, forDoingThis); + } + } + + public boolean payForCommand(double cost, TL toDoThis, TL forDoingThis) { + return payForCommand(cost, toDoThis.toString(), forDoingThis.toString()); + } + + // like above, but just make sure they can pay; returns true unless person can't afford the cost + public boolean canAffordCommand(double cost, String toDoThis) { + if (!Econ.shouldBeUsed() || fPlayer == null || cost == 0.0 || fPlayer.isAdminBypassing()) { + return true; + } + + if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fPlayer.hasFaction()) { + return Econ.hasAtLeast(faction, cost, toDoThis); + } else { + return Econ.hasAtLeast(fPlayer, cost, toDoThis); + } + } + + public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) { + this.doWarmUp(fPlayer, warmup, translationKey, action, runnable, delay); + } + + public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) { + WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CommandRequirements.java b/src/main/java/com/massivecraft/factions/cmd/CommandRequirements.java new file mode 100644 index 00000000..bc75c6c6 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CommandRequirements.java @@ -0,0 +1,155 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.zcore.fperms.Access; +import com.massivecraft.factions.zcore.fperms.PermissableAction; +import com.massivecraft.factions.zcore.util.TL; + +public class CommandRequirements { + + // Permission required to execute command + public Permission permission; + + // Must be player + public boolean playerOnly; + // Must be member of faction + public boolean memberOnly; + + // Must be atleast this role + public Role role; + + // PermissableAction check if the player has allow for this before checking the role + public PermissableAction action; + + // Commodore stuffs + public Class brigadier; + + // Edge case handling + public boolean errorOnManyArgs; + public boolean disableOnLock; + + private CommandRequirements(Permission permission, boolean playerOnly, boolean memberOnly, Role role, PermissableAction action, Class brigadier) { + this.permission = permission; + this.playerOnly = playerOnly; + this.memberOnly = memberOnly; + this.role = role; + this.action = action; + this.brigadier = brigadier; + } + + public boolean computeRequirements(CommandContext context, boolean informIfNot) { + // Did not modify CommandRequirements return true + if (permission == null) { + return true; + } + + if (context.player != null) { + // Is Player + if (!context.fPlayer.hasFaction() && memberOnly) { + if (informIfNot) context.msg(TL.GENERIC_MEMBERONLY); + return false; + } + + if (!FactionsPlugin.getInstance().perm.has(context.sender, permission.node, informIfNot)) return false; + + // Permissable Action provided compute that before role + if (action != null) { + if (context.fPlayer.getRole() == Role.LEADER) return true; + Access access = context.faction.getAccess(context.fPlayer, action); + if (access == Access.DENY) { + if (informIfNot) context.msg(TL.GENERIC_FPERM_NOPERMISSION, action.getName()); + 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; + } + } + // They have been explicitly allowed + return true; + } else { + if ((role != null && !context.fPlayer.getRole().isAtLeast(role)) && informIfNot) { + context.msg(TL.GENERIC_YOUMUSTBE, role.translation); + } + return role == null || context.fPlayer.getRole().isAtLeast(role); + } + } else { + if (playerOnly) { + if (informIfNot) context.sender.sendMessage(TL.GENERIC_PLAYERONLY.toString()); + return false; + } + return context.sender.hasPermission(permission.node); + } + } + + public static class Builder { + + private Permission permission; + + private boolean playerOnly = false; + private boolean memberOnly = false; + + private Role role = null; + private PermissableAction action; + + private Class brigadier; + + private boolean errorOnManyArgs = true; + private boolean disableOnLock = true; + + public Builder(Permission permission) { + this.permission = permission; + } + + public Builder playerOnly() { + playerOnly = true; + return this; + } + + public Builder memberOnly() { + playerOnly = true; + memberOnly = true; + return this; + } + + public Builder withRole(Role role) { + this.role = role; + return this; + } + + public Builder withAction(PermissableAction action) { + this.action = action; + return this; + } + + public Builder brigadier(Class brigadier) { + this.brigadier = brigadier; + return this; + } + + public CommandRequirements build() { + CommandRequirements requirements = new CommandRequirements(permission, playerOnly, memberOnly, role, action, brigadier); + requirements.errorOnManyArgs = errorOnManyArgs; + requirements.disableOnLock = disableOnLock; + return requirements; + } + + public Builder noErrorOnManyArgs() { + errorOnManyArgs = false; + return this; + } + + public Builder noDisableOnLock() { + disableOnLock = false; + return this; + } + + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index f1effd00..fe5cef15 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.cmd.alts.CmdAlts; import com.massivecraft.factions.cmd.check.CmdCheck; import com.massivecraft.factions.cmd.check.CmdWeeWoo; @@ -22,12 +22,20 @@ import com.massivecraft.factions.cmd.tnt.CmdTntFill; import com.massivecraft.factions.missions.CmdMissions; import com.massivecraft.factions.shop.CmdShop; import com.massivecraft.factions.zcore.util.TL; +import me.lucko.commodore.CommodoreProvider; import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.logging.Level; -public class FCmdRoot extends FCommand { +public class FCmdRoot extends FCommand implements CommandExecutor { + + public BrigadierManager brigadierManager; public CmdAdmin cmdAdmin = new CmdAdmin(); public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim(); @@ -124,43 +132,33 @@ public class FCmdRoot extends FCommand { public CmdTntFill cmdTntFill = new CmdTntFill(); public CmdChest cmdChest = new CmdChest(); public CmdSetBanner cmdSetBanner = new CmdSetBanner(); - public CmdStrike cmdStrike = new CmdStrike(); - public CmdStrikeSet cmdStrikeSet = new CmdStrikeSet(); public CmdAlts cmdAlts = new CmdAlts(); - public CmdSpam cmdSpam = new CmdSpam(); public CmdCorner cmdCorner = new CmdCorner(); public CmdInventorySee cmdInventorySee = new CmdInventorySee(); public CmdFGlobal cmdFGlobal = new CmdFGlobal(); public CmdViewChest cmdViewChest = new CmdViewChest(); public CmdPoints cmdPoints = new CmdPoints(); public CmdLogout cmdLogout = new CmdLogout(); - public CmdNotifications cmdNotifications = new CmdNotifications(); public CmdShop cmdShop = new CmdShop(); public CmdMissions cmdMissions = new CmdMissions(); + public CmdStrikes cmdStrikes = new CmdStrikes(); public CmdCheck cmdCheck = new CmdCheck(); public CmdWeeWoo cmdWeeWoo = new CmdWeeWoo(); public FCmdRoot() { super(); + + if (CommodoreProvider.isSupported()) brigadierManager = new BrigadierManager(); + + this.aliases.addAll(Conf.baseCommandAliases); - this.aliases.removeAll(Collections.singletonList(null)); // remove any nulls from extra commas - this.allowNoSlashAccess = Conf.allowNoSlashCommand; - - //this.requiredArgs.add(""); - //this.optionalArgs.put("","") - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; - - this.disableOnLock = false; + this.aliases.removeAll(Collections.singletonList(null)); this.setHelpShort("The faction base command"); - this.helpLong.add(p.txt.parseTags("This command contains all faction stuff.")); + this.helpLong.add(FactionsPlugin.getInstance().txt.parseTags("This command contains all faction stuff.")); - //this.subCommands.add(plugin.cmdHelp); + if (CommodoreProvider.isSupported()) brigadierManager = new BrigadierManager(); this.addSubCommand(this.cmdAdmin); this.addSubCommand(this.cmdAutoClaim); @@ -175,7 +173,6 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdDeinvite); this.addSubCommand(this.cmdDescription); this.addSubCommand(this.cmdDisband); - this.addSubCommand(this.cmdStrike); this.addSubCommand(this.cmdHelp); this.addSubCommand(this.cmdHome); this.addSubCommand(this.cmdInvite); @@ -187,7 +184,6 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdMap); this.addSubCommand(this.cmdMod); this.addSubCommand(this.cmdMoney); - this.addSubCommand(this.cmdNotifications); this.addSubCommand(this.cmdOpen); this.addSubCommand(this.cmdOwner); this.addSubCommand(this.cmdOwnerList); @@ -253,9 +249,8 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdTntFill); this.addSubCommand(this.cmdChest); this.addSubCommand(this.cmdSetBanner); - this.addSubCommand(this.cmdStrikeSet); - this.addSubCommand(this.cmdSpam); this.addSubCommand(this.cmdCorner); + this.addSubCommand(this.cmdStrikes); this.addSubCommand(this.cmdFGlobal); this.addSubCommand(this.cmdViewChest); @@ -264,61 +259,77 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdWeeWoo); } - if (P.p.getConfig().getBoolean("Missions-Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("Missions-Enabled")) { this.addSubCommand(this.cmdMissions); } - if (P.p.getConfig().getBoolean("F-Shop.Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) { this.addSubCommand(this.cmdShop); } - if (P.p.getConfig().getBoolean("f-inventory-see.Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled")) { this.addSubCommand(this.cmdInventorySee); } - if (P.p.getConfig().getBoolean("f-points.Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled")) { this.addSubCommand(this.cmdPoints); } - if (P.p.getConfig().getBoolean("f-alts.Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled")) { this.addSubCommand(this.cmdAlts); } - if (P.p.getConfig().getBoolean("f-grace.Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) { this.addSubCommand(this.cmdGrace); } if (Bukkit.getServer().getPluginManager().getPlugin("CoreProtect") != null) { - P.p.log("Found CoreProtect, enabling Inspect"); + FactionsPlugin.getInstance().log("Found CoreProtect, enabling Inspect"); this.addSubCommand(this.cmdInspect); } else { - P.p.log("CoreProtect not found, disabling Inspect"); + FactionsPlugin.getInstance().log("CoreProtect not found, disabling Inspect"); } - if (P.p.getConfig().getBoolean("ffocus.Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled")) { addSubCommand(this.cmdFocus); } - if (P.p.getConfig().getBoolean("enable-faction-flight", false)) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) { this.addSubCommand(this.cmdFly); } if (Bukkit.getServer().getPluginManager().getPlugin("FactionsTop") != null || Bukkit.getServer().getPluginManager().getPlugin("SavageFTOP") != null || Bukkit.getServer().getPluginManager().getPlugin("SaberFTOP") != null) { - P.p.log(Level.INFO, "Found FactionsTop plugin. Disabling our own /f top command."); + FactionsPlugin.getInstance().log(Level.INFO, "Found FactionsTop plugin. Disabling our own /f top command."); } else { - P.p.log(Level.INFO, "Enabling FactionsTop command, this is a very basic /f top please get a dedicated /f top resource if you want land calculation etc."); + FactionsPlugin.getInstance().log(Level.INFO, "Enabling FactionsTop command, this is a very basic /f top please get a dedicated /f top resource if you want land calculation etc."); this.addSubCommand(this.cmdTop); } - if (P.p.getConfig().getBoolean("fpaypal.Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) { this.addSubCommand(this.cmdPaypalSet); this.addSubCommand(this.cmdPaypalSee); } + if (CommodoreProvider.isSupported()) brigadierManager.build(); } @Override - public void perform() { - this.commandChain.add(this); - this.cmdHelp.execute(this.sender, this.args, this.commandChain); + public void perform(CommandContext context) { + context.commandChain.add(this); + this.cmdHelp.execute(context); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + this.execute(new CommandContext(sender, new ArrayList<>(Arrays.asList(args)), label)); + return true; + } + + @Override + public void addSubCommand(FCommand subCommand) { + super.addSubCommand(subCommand); + // People were getting NPE's as somehow CommodoreProvider#isSupported returned true on legacy versions. + if (CommodoreProvider.isSupported()) { + brigadierManager.addSubCommand(subCommand); + } } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/FCommand.java b/src/main/java/com/massivecraft/factions/cmd/FCommand.java index ac716da8..f2553930 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCommand.java @@ -1,351 +1,248 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.*; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.integration.Econ; -import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.util.WarmUpUtil; -import com.massivecraft.factions.zcore.MCommand; +import com.massivecraft.factions.zcore.CommandVisibility; import com.massivecraft.factions.zcore.util.TL; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import com.massivecraft.factions.zcore.util.TextUtil; +import org.apache.commons.lang.time.DurationFormatUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import java.text.SimpleDateFormat; -import java.util.List; +import java.util.*; -public abstract class FCommand extends MCommand

    { +public abstract class FCommand { - public static final SimpleDateFormat sdf = new SimpleDateFormat(TL.DATE_FORMAT.toString()); + public SimpleDateFormat sdf = new SimpleDateFormat(TL.DATE_FORMAT.toString()); - public boolean disableOnLock; - public boolean disableOnSpam; + // Command Aliases + public List aliases; - public FPlayer fme; - public Faction myFaction; - public boolean senderMustBeMember; - public boolean senderMustBeModerator; - public boolean senderMustBeAdmin; - public boolean senderMustBeColeader; + // Information on the args + public List requiredArgs; + public LinkedHashMap optionalArgs; - - public boolean isMoneyCommand; + // Requirements to execute this command + public CommandRequirements requirements; + /* + Subcommands + */ + public List subCommands; + /* + Help + */ + public List helpLong; + public CommandVisibility visibility; + private String helpShort; public FCommand() { - super(P.p); - // Due to safety reasons it defaults to disable on lock. - disableOnLock = true; - disableOnSpam = false; + requirements = new CommandRequirements.Builder(null).build(); - // The money commands must be disabled if money should not be used. - isMoneyCommand = false; + this.subCommands = new ArrayList<>(); + this.aliases = new ArrayList<>(); - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requiredArgs = new ArrayList<>(); + this.optionalArgs = new LinkedHashMap<>(); + + this.helpShort = null; + this.helpLong = new ArrayList<>(); + this.visibility = CommandVisibility.VISIBLE; } - @Override - public void setCommandSender(CommandSender sender) { - super.setCommandSender(sender); - if (sender instanceof Player) { - this.fme = FPlayers.getInstance().getByPlayer((Player) sender); - this.myFaction = this.fme.getFaction(); - } else { - this.fme = null; - this.myFaction = null; - } - } + public abstract void perform(CommandContext context); - @Override - public void execute(CommandSender sender, List args, List> commandChain) { - setCommandSender(sender); - super.execute(sender, args, commandChain); - } - - @Override - public boolean isEnabled() { - if (p.getLocked() && this.disableOnLock) { - msg("Factions was locked by an admin. Please try again later."); - return false; - } - - if (p.getSpam() && this.disableOnSpam) { - msg("Anti-Spam is currently enabled! Please try again later."); - return false; - } - - if (this.isMoneyCommand && !Conf.econEnabled) { - msg("Faction economy features are disabled on this server."); - return false; - } - - if (this.isMoneyCommand && !Conf.bankEnabled) { - msg("The faction bank system is disabled on this server."); - return false; - } - - return true; - } - - @Override - public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) { - boolean superValid = super.validSenderType(sender, informSenderIfNot); - if (!superValid) { - return false; - } - - if (!(this.senderMustBeMember || this.senderMustBeModerator || this.senderMustBeAdmin || this.senderMustBeColeader)) { - return true; - } - - if (!(sender instanceof Player)) { - return false; - } - - if (!fme.hasFaction()) { - if (informSenderIfNot) { - sender.sendMessage(p.txt.parse(TL.ACTIONS_NOFACTION.toString())); - } - return false; - } - - - if (this.senderMustBeModerator && !fme.getRole().isAtLeast(Role.MODERATOR)) { - if (informSenderIfNot) { - sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "moderator").replace("{action}", this.getHelpShort()))); - } - return false; - } - - if (this.senderMustBeColeader && !fme.getRole().isAtLeast(Role.COLEADER)) { - if (informSenderIfNot) { - sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "coleader").replace("{action}", this.getHelpShort()))); - } - return false; - } - - if (this.senderMustBeAdmin && !fme.getRole().isAtLeast(Role.LEADER)) { - if (informSenderIfNot) { - sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "admin").replace("{action}", this.getHelpShort()))); - } - return false; - } - - - return true; - } - - // -------------------------------------------- // - // Assertions - // -------------------------------------------- // - - public boolean assertHasFaction() { - if (me == null) { - return true; - } - - if (!fme.hasFaction()) { - msg(TL.ACTIONS_NOFACTION); - return false; - } - return true; - } - - public boolean assertMinRole(Role role) { - if (me == null) { - return true; - } - - if (fme.getRole().value < role.value) { - msg(TL.ACTIONS_MUSTBE.toString().replace("{role}", role.nicename).replace("{action}", this.getHelpShort())); - return false; - } - return true; - } - - // -------------------------------------------- // - // Argument Readers - // -------------------------------------------- // - - // FPLAYER ====================== - public FPlayer strAsFPlayer(String name, FPlayer def, boolean msg) { - FPlayer ret = def; - - if (name != null) { - for (FPlayer fplayer : FPlayers.getInstance().getAllFPlayers()) { - if (fplayer.getName().equalsIgnoreCase(name)) { - ret = fplayer; - break; + public void execute(CommandContext context) { + // Is there a matching sub command? + if (context.args.size() > 0) { + for (FCommand subCommand : this.subCommands) { + if (subCommand.aliases.contains(context.args.get(0).toLowerCase())) { + context.args.remove(0); + context.commandChain.add(this); + subCommand.execute(context); + return; } } } - if (msg && ret == null) { - this.msg("No player \"%s\" could be found.", name); + if (!validCall(context)) { + return; } - return ret; - } - - public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) { - return this.strAsFPlayer(this.argAsString(idx), def, msg); - } - - public FPlayer argAsFPlayer(int idx, FPlayer def) { - return this.argAsFPlayer(idx, def, true); - } - - public FPlayer argAsFPlayer(int idx) { - return this.argAsFPlayer(idx, null); - } - - // BEST FPLAYER MATCH ====================== - public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg) { - return strAsFPlayer(name, def, msg); - } - - public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg) { - return this.strAsBestFPlayerMatch(this.argAsString(idx), def, msg); - } - - public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) { - return this.argAsBestFPlayerMatch(idx, def, true); - } - - public FPlayer argAsBestFPlayerMatch(int idx) { - return this.argAsBestFPlayerMatch(idx, null); - } - - // FACTION ====================== - public Faction strAsFaction(String name, Faction def, boolean msg) { - Faction ret = def; - - if (name != null) { - // First we try an exact match - Faction faction = Factions.getInstance().getByTag(name); // Checks for faction name match. - - // Now lets try for warzone / safezone. Helpful for custom warzone / safezone names. - // Do this after we check for an exact match in case they rename the warzone / safezone - // and a player created faction took one of the names. - if (faction == null) { - if (name.equalsIgnoreCase("warzone")) { - faction = Factions.getInstance().getWarZone(); - } else if (name.equalsIgnoreCase("safezone")) { - faction = Factions.getInstance().getSafeZone(); - } - } - - // Next we match faction tags - if (faction == null) { - faction = Factions.getInstance().getBestTagMatch(name); - } - - // Next we match player names - if (faction == null) { - FPlayer fplayer = strAsFPlayer(name, null, false); - if (fplayer != null) { - faction = fplayer.getFaction(); - } - } - - if (faction != null) { - ret = faction; - } + if (!this.isEnabled(context)) { + return; } - if (msg && ret == null) { - this.msg("The faction or player \"%s\" could not be found.", name); + perform(context); + } + + public boolean validCall(CommandContext context) { + return requirements.computeRequirements(context, true) && validArgs(context); + } + + public boolean isEnabled(CommandContext context) { + if (FactionsPlugin.getInstance().getLocked() && requirements.disableOnLock) { + context.msg("Factions was locked by an admin. Please try again later."); + return false; } - - return ret; + return true; } - public Faction argAsFaction(int idx, Faction def, boolean msg) { - return this.strAsFaction(this.argAsString(idx), def, msg); - } - - public Faction argAsFaction(int idx, Faction def) { - return this.argAsFaction(idx, def, true); - } - - public Faction argAsFaction(int idx) { - return this.argAsFaction(idx, null); - } - - // -------------------------------------------- // - // Commonly used logic - // -------------------------------------------- // - - public boolean canIAdministerYou(FPlayer i, FPlayer you) { - if (!i.getFaction().equals(you.getFaction())) { - i.sendMessage(p.txt.parse("%s is not in the same faction as you.", you.describeTo(i, true))); + public boolean validArgs(CommandContext context) { + if (context.args.size() < this.requiredArgs.size()) { + if (context.sender != null) { + context.msg(TL.GENERIC_ARGS_TOOFEW); + context.sender.sendMessage(this.getUseageTemplate(context)); + } return false; } - if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.LEADER)) { - return true; + if (context.args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.requirements.errorOnManyArgs) { + if (context.sender != null) { + // Get the to many string slice + List theToMany = context.args.subList(this.requiredArgs.size() + this.optionalArgs.size(), context.args.size()); + context.msg(TL.GENERIC_ARGS_TOOMANY, TextUtil.implode(theToMany, " ")); + context.sender.sendMessage(this.getUseageTemplate(context)); + } + return false; + } + return true; + } + + public void addSubCommand(FCommand subCommand) { + this.subCommands.add(subCommand); + } + + public String getHelpShort() { + if (this.helpShort == null) { + return getUsageTranslation().toString(); } - if (you.getRole().equals(Role.LEADER)) { - i.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "leader").replace("{action}", "do that"))); + return this.helpShort; + } - } else if ((you.getRole().equals(Role.COLEADER))) { - if (i == you) { - return true; + public void setHelpShort(String val) { + this.helpShort = val; + } + + public abstract TL getUsageTranslation(); + + + /* + Common Logic + */ + public List getToolTips(FPlayer player) { + List lines = new ArrayList<>(); + for (String s : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.show")) { + lines.add(ChatColor.translateAlternateColorCodes('&', replaceFPlayerTags(s, player))); + } + return lines; + } + + public List getToolTips(Faction faction) { + List lines = new ArrayList<>(); + for (String s : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.list")) { + lines.add(ChatColor.translateAlternateColorCodes('&', replaceFactionTags(s, faction))); + } + return lines; + } + + public String replaceFPlayerTags(String s, FPlayer player) { + if (s.contains("{balance}")) { + String balance = Econ.isSetup() ? Econ.getFriendlyBalance(player) : "no balance"; + s = s.replace("{balance}", balance); + } + if (s.contains("{lastSeen}")) { + String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - player.getLastLoginTime(), true, true) + " ago"; + String lastSeen = player.isOnline() ? ChatColor.GREEN + "Online" : (System.currentTimeMillis() - player.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized); + s = s.replace("{lastSeen}", lastSeen); + } + if (s.contains("{power}")) { + String power = player.getPowerRounded() + "/" + player.getPowerMaxRounded(); + s = s.replace("{power}", power); + } + if (s.contains("{group}")) { + String group = FactionsPlugin.getInstance().getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(player.getId()))); + s = s.replace("{group}", group); + } + return s; + } + + public String replaceFactionTags(String s, Faction faction) { + if (s.contains("{power}")) { + s = s.replace("{power}", String.valueOf(faction.getPowerRounded())); + } + if (s.contains("{maxPower}")) { + s = s.replace("{maxPower}", String.valueOf(faction.getPowerMaxRounded())); + } + if (s.contains("{leader}")) { + FPlayer fLeader = faction.getFPlayerAdmin(); + String leader = fLeader == null ? "Server" : fLeader.getName().substring(0, fLeader.getName().length() > 14 ? 13 : fLeader.getName().length()); + s = s.replace("{leader}", leader); + } + if (s.contains("{chunks}")) { + s = s.replace("{chunks}", String.valueOf(faction.getLandRounded())); + } + if (s.contains("{members}")) { + s = s.replace("{members}", String.valueOf(faction.getSize())); + + } + if (s.contains("{online}")) { + s = s.replace("{online}", String.valueOf(faction.getOnlinePlayers().size())); + } + return s; + } + + /* + Help and Usage information + */ + public String getUseageTemplate(CommandContext context, boolean addShortHelp) { + StringBuilder ret = new StringBuilder(); + ret.append(FactionsPlugin.getInstance().color(TL.COMMAND_USEAGE_TEMPLATE_COLOR.toString())); + ret.append('/'); + + for (FCommand fc : context.commandChain) { + ret.append(TextUtil.implode(fc.aliases, ",")); + ret.append(' '); + } + + ret.append(TextUtil.implode(this.aliases, ",")); + + List args = new ArrayList<>(); + + for (String requiredArg : this.requiredArgs) { + args.add("<" + requiredArg + ">"); + } + + for (Map.Entry optionalArg : this.optionalArgs.entrySet()) { + String val = optionalArg.getValue(); + if (val == null) { + val = ""; } else { - i.sendMessage(p.txt.parse(TL.ACTIONS_NOSAMEROLE.toString().replace("{role}", i.getRole().nicename))); + val = "=" + val; } - - } else if (i.getRole().equals(Role.MODERATOR)) { - if (i == you) { - return true; //Moderators can control themselves - } else { - i.sendMessage(p.txt.parse(TL.ACTIONS_NOSAMEROLE.toString().replace("{role}", i.getRole().nicename))); - } - } else { - i.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "moderator").replace("{action}", "do that"))); + args.add("[" + optionalArg.getKey() + val + "]"); } - return false; - } - - // if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost - public boolean payForCommand(double cost, String toDoThis, String forDoingThis) { - if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) { - return true; + if (args.size() > 0) { + ret.append(FactionsPlugin.getInstance().txt.parseTags(" ")); + ret.append(TextUtil.implode(args, " ")); } - if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) { - return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis); - } else { - return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis); - } - } - - public boolean payForCommand(double cost, TL toDoThis, TL forDoingThis) { - return payForCommand(cost, toDoThis.toString(), forDoingThis.toString()); - } - - // like above, but just make sure they can pay; returns true unless person can't afford the cost - public boolean canAffordCommand(double cost, String toDoThis) { - if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) { - return true; + if (addShortHelp) { + ret.append(FactionsPlugin.getInstance().txt.parseTags(" ")); + ret.append(this.getHelpShort()); } - if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) { - return Econ.hasAtLeast(myFaction, cost, toDoThis); - } else { - return Econ.hasAtLeast(fme, cost, toDoThis); - } + return ret.toString(); } - public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) { - this.doWarmUp(this.fme, warmup, translationKey, action, runnable, delay); + public String getUseageTemplate(CommandContext context) { + return getUseageTemplate(context, false); } - public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) { - WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay); - } } diff --git a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAlts.java b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAlts.java index 537560b7..1a2232b2 100644 --- a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAlts.java +++ b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAlts.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd.alts; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -18,29 +20,24 @@ public class CmdAlts extends FCommand { this.aliases.add("alts"); this.aliases.add("alt"); - this.permission = Permission.ALTS.node; - this.disableOnLock = false; - this.disableOnSpam = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; - - this.addSubCommand(this.cmdInviteAlt); this.addSubCommand(this.cmdAltsList); + + this.requirements = new CommandRequirements.Builder(Permission.ALTS) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("f-alts.Enabled", false)) { - fme.msg(TL.GENERIC_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled", false)) { + context.msg(TL.GENERIC_DISABLED); return; } - this.commandChain.add(this); - P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain); + context.commandChain.add(this); + FactionsPlugin.getInstance().cmdAutoHelp.execute(context); } @Override 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 a6d1a061..57151ebd 100644 --- a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java +++ b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java @@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.alts; import com.google.common.base.Joiner; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -19,37 +21,33 @@ public class CmdAltsList extends FCommand { this.optionalArgs.put("faction", "yours"); - this.permission = Permission.LIST.node; - this.disableOnLock = false; - this.disableOnSpam = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.LIST) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - Faction faction = myFaction; - if (argIsSet(0)) { - faction = argAsFaction(0); + public void perform(CommandContext context) { + Faction faction = context.faction; + if (context.argIsSet(0)) { + faction = context.argAsFaction(0); } if (faction == null) return; - if (faction != myFaction && !fme.isAdminBypassing()) { + if (faction != context.faction && !context.fPlayer.isAdminBypassing()) { return; } if (faction.getAltPlayers().size() == 0) { - msg(TL.COMMAND_ALTS_LIST_NOALTS, faction.getTag()); + context.msg(TL.COMMAND_ALTS_LIST_NOALTS, faction.getTag()); return; } - msg("There are " + faction.getAltPlayers().size() + " alts in " + faction.getTag() + ":"); - msg(Joiner.on(", ").join(faction.getAltPlayers().stream().map(FPlayer::getName).collect(Collectors.toList()))); + context.msg("There are " + faction.getAltPlayers().size() + " alts in " + faction.getTag() + ":"); + context.msg(Joiner.on(", ").join(faction.getAltPlayers().stream().map(FPlayer::getName).collect(Collectors.toList()))); } diff --git a/src/main/java/com/massivecraft/factions/cmd/alts/CmdInviteAlt.java b/src/main/java/com/massivecraft/factions/cmd/alts/CmdInviteAlt.java index ff8e9492..8bd44283 100644 --- a/src/main/java/com/massivecraft/factions/cmd/alts/CmdInviteAlt.java +++ b/src/main/java/com/massivecraft/factions/cmd/alts/CmdInviteAlt.java @@ -2,7 +2,9 @@ package com.massivecraft.factions.cmd.alts; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -17,75 +19,69 @@ public class CmdInviteAlt extends FCommand { public CmdInviteAlt() { super(); this.aliases.add("invite"); - this.requiredArgs.add("player name"); - // this.optionalArgs.put("", ""); - this.permission = Permission.INVITE.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.INVITE) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("f-alts.Enabled", false)) { - fme.msg(TL.GENERIC_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled", false)) { + context.fPlayer.msg(TL.GENERIC_DISABLED); return; } - FPlayer target = this.argAsBestFPlayerMatch(0); + FPlayer target = context.argAsBestFPlayerMatch(0); if (target == null) { return; } - if (target.getFaction() == myFaction) { - msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), myFaction.getTag()); + if (target.getFaction() == context.faction) { + context.msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), context.faction.getTag()); return; } // if economy is enabled, they're not on the bypass list, and this // command has a cost set, make 'em pay - if (!payForCommand(Conf.econCostInvite, TL.COMMAND_INVITE_TOINVITE.toString(), TL.COMMAND_INVITE_FORINVITE.toString())) { + if (!context.payForCommand(Conf.econCostInvite, TL.COMMAND_INVITE_TOINVITE.toString(), TL.COMMAND_INVITE_FORINVITE.toString())) { return; } - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.INVITE); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites"); + if (!context.fPlayer.isAdminBypassing()) { + Access access = context.faction.getAccess(context.fPlayer, PermissableAction.INVITE); + if (access != Access.ALLOW && context.fPlayer.getRole() != Role.LEADER) { + context.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites"); return; } } - if (myFaction.isBanned(target)) { - fme.msg(TL.COMMAND_INVITE_BANNED, target.getName()); + if (context.faction.isBanned(target)) { + context.msg(TL.COMMAND_INVITE_BANNED, target.getName()); return; } - myFaction.deinvite(target); - myFaction.altInvite(target); + context.faction.deinvite(target); + context.faction.altInvite(target); if (!target.isOnline()) { return; } - FancyMessage message = new FancyMessage(fme.describeTo(target, true)) + FancyMessage message = new FancyMessage(context.fPlayer.describeTo(target, true)) .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) - .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()) + .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag()) .then(TL.COMMAND_INVITE_INVITEDYOU.toString()) .color(ChatColor.YELLOW) .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) - .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()) - .then(myFaction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) - .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()); + .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag()) + .then(context.faction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) + .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag()); message.send(target.getPlayer()); - myFaction.msg(TL.COMMAND_ALTINVITE_INVITED_ALT, fme.describeTo(myFaction, true), target.describeTo(myFaction)); + context.faction.msg(TL.COMMAND_ALTINVITE_INVITED_ALT, context.fPlayer.describeTo(context.faction, true), target.describeTo(context.faction)); } @Override 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 25a96b58..5a883892 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.cmd.check; import com.google.common.collect.Lists; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.FactionGUI; import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.zcore.util.TL; @@ -18,12 +18,12 @@ import java.text.SimpleDateFormat; import java.util.*; public class CheckHistoryFrame implements FactionGUI { - private P plugin; + private FactionsPlugin plugin; private Faction faction; private Inventory inventory; private SimpleDateFormat simpleDateFormat; - public CheckHistoryFrame(P plugin, Faction faction) { + public CheckHistoryFrame(FactionsPlugin plugin, Faction faction) { this.simpleDateFormat = new SimpleDateFormat(Conf.dateFormat); this.plugin = plugin; this.faction = faction; 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 2e198fff..858d9244 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd.check; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.FactionGUI; import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.zcore.util.TL; @@ -16,11 +16,11 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.Collections; public class CheckSettingsFrame implements InventoryHolder, FactionGUI { - private P plugin; + private FactionsPlugin plugin; private FPlayer fPlayer; private Inventory inventory; - public CheckSettingsFrame(P plugin, FPlayer fPlayer) { + public CheckSettingsFrame(FactionsPlugin plugin, FPlayer fPlayer) { this.plugin = plugin; this.fPlayer = fPlayer; this.inventory = plugin.getServer().createInventory(this, plugin.getConfig().getInt("f-check.gui-rows") * 9, TL.CHECK_SETTINGS_GUI_TITLE.toString()); @@ -28,16 +28,16 @@ public class CheckSettingsFrame implements InventoryHolder, FactionGUI { public void onClick(int slot, ClickType action) { Faction faction = this.fPlayer.getFaction(); - if (slot == P.p.getConfig().getInt("f-check.wall-check.slot")) { + if (slot == FactionsPlugin.getInstance().getConfig().getInt("f-check.wall-check.slot")) { faction.setWallCheckMinutes(getNext(faction.getWallCheckMinutes())); } else { - if (slot == P.p.getConfig().getInt("f-check.history.slot")) { + if (slot == FactionsPlugin.getInstance().getConfig().getInt("f-check.history.slot")) { CheckHistoryFrame checkHistoryFrame = new CheckHistoryFrame(plugin, fPlayer.getFaction()); checkHistoryFrame.build(); fPlayer.getPlayer().openInventory(checkHistoryFrame.getInventory()); return; } - if (slot == P.p.getConfig().getInt("f-check.buffer-check.slot")) { + if (slot == FactionsPlugin.getInstance().getConfig().getInt("f-check.buffer-check.slot")) { faction.setBufferCheckMinutes(getNext(faction.getBufferCheckMinutes())); } } @@ -47,23 +47,23 @@ public class CheckSettingsFrame implements InventoryHolder, FactionGUI { public void build() { Faction faction = fPlayer.getFaction(); - ItemStack wallsStack = XMaterial.matchXMaterial(P.p.getConfig().getString("f-check.wall-check.Type")).parseItem(); + ItemStack wallsStack = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("f-check.wall-check.Type")).parseItem(); ItemMeta wallsMeta = wallsStack.getItemMeta(); wallsMeta.setDisplayName(TL.CHECK_WALL_CHECK_GUI_ICON.toString()); wallsMeta.setLore(Collections.singletonList(TL.CHECK_CHECK_LORE_LINE.format(getFormatted(faction.getWallCheckMinutes())))); wallsStack.setItemMeta(wallsMeta); - inventory.setItem(P.p.getConfig().getInt("f-check.wall-check.slot"), wallsStack); - ItemStack bufferStack = XMaterial.matchXMaterial(P.p.getConfig().getString("f-check.buffer-check.Type")).parseItem(); + inventory.setItem(FactionsPlugin.getInstance().getConfig().getInt("f-check.wall-check.slot"), wallsStack); + ItemStack bufferStack = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("f-check.buffer-check.Type")).parseItem(); ItemMeta bufferMeta = bufferStack.getItemMeta(); bufferMeta.setDisplayName(TL.CHECK_BUFFER_CHECK_GUI_ICON.toString()); bufferMeta.setLore(Collections.singletonList(TL.CHECK_CHECK_LORE_LINE.format(getFormatted(faction.getBufferCheckMinutes())))); bufferStack.setItemMeta(bufferMeta); - inventory.setItem(P.p.getConfig().getInt("f-check.buffer-check.slot"), bufferStack); - ItemStack historyStack = XMaterial.matchXMaterial(P.p.getConfig().getString("f-check.history.Type")).parseItem(); + inventory.setItem(FactionsPlugin.getInstance().getConfig().getInt("f-check.buffer-check.slot"), bufferStack); + ItemStack historyStack = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("f-check.history.Type")).parseItem(); ItemMeta historyMeta = historyStack.getItemMeta(); historyMeta.setDisplayName(TL.CHECK_HISTORY_GUI_ICON.toString()); historyStack.setItemMeta(historyMeta); - inventory.setItem(P.p.getConfig().getInt("f-check.history.slot"), historyStack); + inventory.setItem(FactionsPlugin.getInstance().getConfig().getInt("f-check.history.slot"), historyStack); } public Inventory getInventory() { diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CheckTask.java b/src/main/java/com/massivecraft/factions/cmd/check/CheckTask.java index bcbac60e..7d5a895c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/CheckTask.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/CheckTask.java @@ -4,7 +4,7 @@ import com.google.common.collect.Lists; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; import java.text.SimpleDateFormat; @@ -16,10 +16,10 @@ public class CheckTask implements Runnable { private static List wallChecks = new CopyOnWriteArrayList<>(); private static List bufferChecks = new CopyOnWriteArrayList<>(); private SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Conf.dateFormat); - private P plugin; + private FactionsPlugin plugin; private int minute; - public CheckTask(P plugin, int minute) { + public CheckTask(FactionsPlugin plugin, int minute) { this.plugin = plugin; this.minute = minute; } diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CmdCheck.java b/src/main/java/com/massivecraft/factions/cmd/check/CmdCheck.java index e42caa72..36e7bd8a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/CmdCheck.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/CmdCheck.java @@ -1,9 +1,12 @@ package com.massivecraft.factions.cmd.check; import com.massivecraft.factions.Conf; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.OfflinePlayer; @@ -20,34 +23,28 @@ public class CmdCheck extends FCommand { this.aliases.add("check"); this.requiredArgs.add("walls/buffers/settings/leaderboard"); - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CHECK) + .playerOnly() + .withAction(PermissableAction.CHECK) + .memberOnly() + .build(); } - public void perform() { - if (myFaction == null || !myFaction.isNormal()) { - return; - } - String subCommand = argAsString(0, null); - Access access = myFaction.getAccess(fme, PermissableAction.CHECK); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_NOPERMISSION, "check"); + public void perform(CommandContext context) { + if (context.faction == null || !context.faction.isNormal()) { return; } + String subCommand = context.argAsString(0, null); + long currentTime = System.currentTimeMillis(); if (subCommand.equalsIgnoreCase("leaderboard")) { - msg(TL.CHECK_LEADERBOARD_HEADER); + context.msg(TL.CHECK_LEADERBOARD_HEADER); Map players = new HashMap<>(); - for (Map.Entry entry : myFaction.getPlayerWallCheckCount().entrySet()) { + for (Map.Entry entry : context.faction.getPlayerWallCheckCount().entrySet()) { players.put(entry.getKey(), entry.getValue()); } - for (Map.Entry entry : myFaction.getPlayerBufferCheckCount().entrySet()) { + for (Map.Entry entry : context.faction.getPlayerBufferCheckCount().entrySet()) { if (players.containsKey(entry.getKey())) { players.replace(entry.getKey(), players.get(entry.getKey()) + entry.getValue()); } else { @@ -57,54 +54,54 @@ public class CmdCheck extends FCommand { List> entryList = players.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList()); for (int max = (entryList.size() > 10) ? 10 : entryList.size(), current = 0; current < max; ++current) { Map.Entry entry = entryList.get(current); - OfflinePlayer offlinePlayer = p.getServer().getOfflinePlayer(entry.getKey()); - msg(TL.CHECK_LEADERBOARD_LINE.format(current + 1, offlinePlayer.getName(), entry.getValue(), myFaction.getPlayerBufferCheckCount().getOrDefault(entry.getKey(), 0), myFaction.getPlayerWallCheckCount().getOrDefault(entry.getKey(), 0))); + OfflinePlayer offlinePlayer = FactionsPlugin.getInstance().getServer().getOfflinePlayer(entry.getKey()); + context.msg(TL.CHECK_LEADERBOARD_LINE.format(current + 1, offlinePlayer.getName(), entry.getValue(), context.faction.getPlayerBufferCheckCount().getOrDefault(entry.getKey(), 0), context.faction.getPlayerWallCheckCount().getOrDefault(entry.getKey(), 0))); } if (entryList.isEmpty()) { - msg(TL.CHECK_LEADERBOARD_NO_DATA); + context.msg(TL.CHECK_LEADERBOARD_NO_DATA); } } else if (subCommand.equalsIgnoreCase("walls")) { - if (!CheckTask.wallCheck(myFaction.getId())) { - if (myFaction.getChecks().isEmpty()) { - msg(TL.CHECK_NO_CHECKS); + if (!CheckTask.wallCheck(context.faction.getId())) { + if (context.faction.getChecks().isEmpty()) { + context.msg(TL.CHECK_NO_CHECKS); return; } - msg(TL.CHECK_ALREADY_CHECKED); + context.msg(TL.CHECK_ALREADY_CHECKED); } else { - int current = myFaction.getPlayerWallCheckCount().getOrDefault(me.getUniqueId(), 0); + int current = context.faction.getPlayerWallCheckCount().getOrDefault(context.player.getUniqueId(), 0); if (current == 0) { - myFaction.getPlayerWallCheckCount().put(me.getUniqueId(), 1); + context.faction.getPlayerWallCheckCount().put(context.player.getUniqueId(), 1); } else { - myFaction.getPlayerWallCheckCount().replace(me.getUniqueId(), current + 1); + context.faction.getPlayerWallCheckCount().replace(context.player.getUniqueId(), current + 1); } - myFaction.getChecks().put(currentTime, "U" + fme.getNameAndTag()); - msg(TL.CHECK_WALLS_MARKED_CHECKED); + context.faction.getChecks().put(currentTime, "U" + context.fPlayer.getNameAndTag()); + context.msg(TL.CHECK_WALLS_MARKED_CHECKED); } } else if (subCommand.equalsIgnoreCase("buffers")) { - if (!CheckTask.bufferCheck(myFaction.getId())) { - if (myFaction.getChecks().isEmpty()) { - msg(TL.CHECK_NO_CHECKS); + if (!CheckTask.bufferCheck(context.faction.getId())) { + if (context.faction.getChecks().isEmpty()) { + context.msg(TL.CHECK_NO_CHECKS); return; } - msg(TL.CHECK_ALREADY_CHECKED); + context.msg(TL.CHECK_ALREADY_CHECKED); } else { - int current = myFaction.getPlayerBufferCheckCount().getOrDefault(me.getUniqueId(), 0); + int current = context.faction.getPlayerBufferCheckCount().getOrDefault(context.player.getUniqueId(), 0); if (current == 0) { - myFaction.getPlayerBufferCheckCount().put(me.getUniqueId(), 1); + context.faction.getPlayerBufferCheckCount().put(context.player.getUniqueId(), 1); } else { - myFaction.getPlayerBufferCheckCount().replace(me.getUniqueId(), current + 1); + context.faction.getPlayerBufferCheckCount().replace(context.player.getUniqueId(), current + 1); } - myFaction.getChecks().put(System.currentTimeMillis(), "Y" + fme.getNameAndTag()); - msg(TL.CHECK_BUFFERS_MARKED_CHECKED); + context.faction.getChecks().put(System.currentTimeMillis(), "Y" + context.fPlayer.getNameAndTag()); + context.msg(TL.CHECK_BUFFERS_MARKED_CHECKED); } } else if (subCommand.equalsIgnoreCase("settings")) { - if (!fme.getRole().isAtLeast(Role.COLEADER)) { - msg(TL.CHECK_MUST_BE_ATLEAST_COLEADER); + if (!context.fPlayer.getRole().isAtLeast(Role.COLEADER)) { + context.msg(TL.CHECK_MUST_BE_ATLEAST_COLEADER); return; } - CheckSettingsFrame checkGUI = new CheckSettingsFrame(p, fme); + CheckSettingsFrame checkGUI = new CheckSettingsFrame(FactionsPlugin.getInstance(), context.fPlayer); checkGUI.build(); - fme.getPlayer().openInventory(checkGUI.getInventory()); + context.fPlayer.getPlayer().openInventory(checkGUI.getInventory()); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CmdWeeWoo.java b/src/main/java/com/massivecraft/factions/cmd/check/CmdWeeWoo.java index 20695df1..f52c6c2a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/CmdWeeWoo.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/CmdWeeWoo.java @@ -1,6 +1,9 @@ package com.massivecraft.factions.cmd.check; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; public class CmdWeeWoo extends FCommand { @@ -8,38 +11,35 @@ public class CmdWeeWoo extends FCommand { this.aliases.add("weewoo"); this.requiredArgs.add("start/stop"); - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CHECK) + .playerOnly() + .memberOnly() + .build(); } - public void perform() { - if (myFaction == null || !myFaction.isNormal()) { + public void perform(CommandContext context) { + if (context.faction == null || !context.faction.isNormal()) { return; } - String argument = argAsString(0); - boolean weewoo = myFaction.isWeeWoo(); + String argument = context.argAsString(0); + boolean weewoo = context.faction.isWeeWoo(); if (argument.equalsIgnoreCase("start")) { if (weewoo) { - msg(TL.COMMAND_WEEWOO_ALREADY_STARTED); + context.msg(TL.COMMAND_WEEWOO_ALREADY_STARTED); return; } - myFaction.setWeeWoo(true); - msg(TL.COMMAND_WEEWOO_STARTED, fme.getNameAndTag()); + context.faction.setWeeWoo(true); + context.msg(TL.COMMAND_WEEWOO_STARTED, context.fPlayer.getNameAndTag()); } else if (argument.equalsIgnoreCase("stop")) { if (!weewoo) { - msg(TL.COMMAND_WEEWOO_ALREADY_STOPPED); + context.msg(TL.COMMAND_WEEWOO_ALREADY_STOPPED); return; } - myFaction.setWeeWoo(false); - msg(TL.COMMAND_WEEWOO_STOPPED, fme.getNameAndTag()); + context.faction.setWeeWoo(false); + context.msg(TL.COMMAND_WEEWOO_STOPPED, context.fPlayer.getNameAndTag()); } else { - msg("/f weewoo "); + context.msg("/f weewoo "); } } 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 68a12c95..ffce2553 100644 --- a/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java +++ b/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java @@ -2,14 +2,14 @@ package com.massivecraft.factions.cmd.check; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; public class WeeWooTask implements Runnable { - private P plugin; + private FactionsPlugin plugin; - public WeeWooTask(P plugin) { + public WeeWooTask(FactionsPlugin plugin) { this.plugin = plugin; } diff --git a/src/main/java/com/massivecraft/factions/cmd/chest/CmdChest.java b/src/main/java/com/massivecraft/factions/cmd/chest/CmdChest.java index b952a326..5c970910 100644 --- a/src/main/java/com/massivecraft/factions/cmd/chest/CmdChest.java +++ b/src/main/java/com/massivecraft/factions/cmd/chest/CmdChest.java @@ -1,10 +1,10 @@ package com.massivecraft.factions.cmd.chest; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; @@ -14,36 +14,23 @@ public class CmdChest extends FCommand { this.aliases.add("chest"); this.aliases.add("pv"); - //this.requiredArgs.add(""); - - - this.permission = Permission.CHEST.node; - this.disableOnLock = false; - - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CHEST) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.CHEST) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { - if (!P.p.getConfig().getBoolean("fchest.Enabled")) { - fme.sendMessage("This command is disabled!"); + if (!FactionsPlugin.getInstance().getConfig().getBoolean("fchest.Enabled")) { + context.fPlayer.sendMessage("This command is disabled!"); return; } // This permission check is way too explicit but it's clean - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.CHEST); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "access chest"); - return; - } - } - me.openInventory(fme.getFaction().getChestInventory()); + context.player.openInventory(context.faction.getChestInventory()); } @Override 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 fb9296ee..74ecd1d8 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java @@ -1,9 +1,13 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.zcore.fperms.Access; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; public class CmdAutoClaim extends FCommand { @@ -15,39 +19,45 @@ public class CmdAutoClaim extends FCommand { //this.requiredArgs.add(""); this.optionalArgs.put("faction", "your"); - this.permission = Permission.AUTOCLAIM.node; - this.disableOnLock = true; - this.disableOnSpam = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.AUTOCLAIM) + .playerOnly() + .withAction(PermissableAction.TERRITORY) + .build(); } @Override - public void perform() { - Faction forFaction = this.argAsFaction(0, myFaction); - if (forFaction == null || forFaction == fme.getAutoClaimFor()) { - fme.setAutoClaimFor(null); - msg(TL.COMMAND_AUTOCLAIM_DISABLED); + 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 == null || forFaction == context.fPlayer.getAutoClaimFor()) { + context.fPlayer.setAutoClaimFor(null); + context.msg(TL.COMMAND_AUTOCLAIM_DISABLED); return; } - if (!fme.canClaimForFaction(forFaction)) { - if (myFaction == forFaction) { - msg(TL.COMMAND_AUTOCLAIM_REQUIREDRANK, Role.MODERATOR.getTranslation()); + if (!context.fPlayer.canClaimForFaction(forFaction)) { + if (context.faction == forFaction) { + context.msg(TL.COMMAND_AUTOCLAIM_REQUIREDRANK, Role.MODERATOR.getTranslation()); } else { - msg(TL.COMMAND_AUTOCLAIM_OTHERFACTION, forFaction.describeTo(fme)); + context.msg(TL.COMMAND_AUTOCLAIM_OTHERFACTION, forFaction.describeTo(context.fPlayer)); } return; } - fme.setAutoClaimFor(forFaction); + context.fPlayer.setAutoClaimFor(forFaction); - msg(TL.COMMAND_AUTOCLAIM_ENABLED, forFaction.describeTo(fme)); - fme.attemptClaim(forFaction, me.getLocation(), true); + context.msg(TL.COMMAND_AUTOCLAIM_ENABLED, forFaction.describeTo(context.fPlayer)); + context.fPlayer.attemptClaim(forFaction, context.fPlayer.getPlayer().getLocation(), true); } @Override 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 0bb79b65..26cc7b04 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java @@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -22,59 +24,56 @@ public class CmdClaim extends FCommand { this.optionalArgs.put("radius", "1"); this.optionalArgs.put("faction", "your"); - this.permission = Permission.CLAIM.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CLAIM) + .playerOnly() + .build(); } @Override - public void perform() { - // Read and validate input - int radius = this.argAsInt(0, 1); // Default to 1 - final Faction forFaction = this.argAsFaction(1, myFaction); // Default to own + public void perform(CommandContext context) { - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.TERRITORY); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_NOPERMISSION, "change faction territory"); - return; + // Read and validate input + 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 (radius < 1) { - msg(TL.COMMAND_CLAIM_INVALIDRADIUS); + context.msg(TL.COMMAND_CLAIM_INVALIDRADIUS); return; } if (radius < 2) { // single chunk - fme.attemptClaim(forFaction, me.getLocation(), true); + context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true); } else { // radius claim - if (!Permission.CLAIM_RADIUS.has(sender, false)) { - msg(TL.COMMAND_CLAIM_DENIED); + if (!Permission.CLAIM_RADIUS.has(context.sender, true)) { return; } - new SpiralTask(new FLocation(me), radius) { + new SpiralTask(new FLocation(context.player), radius) { private final int limit = Conf.radiusClaimFailureLimit - 1; private int failCount = 0; @Override public boolean work() { - boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true); + boolean success = context.fPlayer.attemptClaim(forFaction, this.currentLocation(), true); if (success) { failCount = 0; } else if (failCount++ >= limit) { this.stop(); return false; } + return true; } }; diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimAt.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimAt.java index b489faa5..b3759607 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimAt.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimAt.java @@ -2,8 +2,11 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FLocation; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; public class CmdClaimAt extends FCommand { @@ -16,28 +19,26 @@ public class CmdClaimAt extends FCommand { this.requiredArgs.add("x"); this.requiredArgs.add("z"); - this.permission = Permission.CLAIMAT.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CLAIMAT) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.TERRITORY) + .build(); } @Override - public void perform() { - int x = argAsInt(1); - int z = argAsInt(2); - FLocation location = new FLocation(argAsString(0), x, z); - if (!((fme.getPlayer().getLocation().getX() + (x * 16)) > (fme.getPlayer().getLocation().getX() + (Conf.mapWidth * 16))) && - !((fme.getPlayer().getLocation().getZ() + (z * 16)) > (fme.getPlayer().getLocation().getZ() + (Conf.mapHeight * 16)))) { - fme.attemptClaim(myFaction, location, true); - } else fme.msg(TL.COMMAND_CLAIM_DENIED); + public void perform(CommandContext context) { + int x = context.argAsInt(1); + int z = context.argAsInt(2); + FLocation location = new FLocation(context.argAsString(0), x, z); + if (!((context.player.getLocation().getX() + (x * 16)) > (context.player.getLocation().getX() + (Conf.mapWidth * 16))) && + !((context.player.getLocation().getZ() + (z * 16)) > (context.player.getLocation().getZ() + (Conf.mapHeight * 16))) && + !context.argAsString(0).equals(context.player.getLocation().getWorld().getName())) { + context.fPlayer.attemptClaim(context.faction, location, true); + } else context.fPlayer.msg(TL.COMMAND_CLAIM_DENIED); } + @Override public TL getUsageTranslation() { return null; 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 32b234a9..6f153d79 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java @@ -2,8 +2,12 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.fperms.Access; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Location; import org.bukkit.block.BlockFace; @@ -23,32 +27,28 @@ public class CmdClaimLine extends FCommand { this.optionalArgs.put("direction", "facing"); this.optionalArgs.put("faction", "you"); - this.permission = Permission.CLAIM_LINE.node; - this.disableOnLock = true; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CLAIM_LINE) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.TERRITORY) + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { // Args - Integer amount = this.argAsInt(0, 1); // Default to 1 + Integer amount = context.argAsInt(0, 1); // Default to 1 if (amount > Conf.lineClaimLimit) { - fme.msg(TL.COMMAND_CLAIMLINE_ABOVEMAX, Conf.lineClaimLimit); + context.fPlayer.msg(TL.COMMAND_CLAIMLINE_ABOVEMAX, Conf.lineClaimLimit); return; } - String direction = this.argAsString(1); + String direction = context.argAsString(1); BlockFace blockFace; if (direction == null) { - blockFace = axis[Math.round(me.getLocation().getYaw() / 90f) & 0x3]; + blockFace = axis[Math.round(context.player.getLocation().getYaw() / 90f) & 0x3]; } else if (direction.equalsIgnoreCase("north")) { blockFace = BlockFace.NORTH; } else if (direction.equalsIgnoreCase("east")) { @@ -58,16 +58,26 @@ public class CmdClaimLine extends FCommand { } else if (direction.equalsIgnoreCase("west")) { blockFace = BlockFace.WEST; } else { - fme.msg(TL.COMMAND_CLAIMLINE_NOTVALID, direction); + context.msg(TL.COMMAND_CLAIMLINE_NOTVALID, direction); return; } - final Faction forFaction = this.argAsFaction(2, myFaction); - Location location = me.getLocation(); + final Faction forFaction = context.argAsFaction(2, 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; + } + } + } + + Location location = context.player.getLocation(); // TODO: make this a task like claiming a radius? for (int i = 0; i < amount; i++) { - fme.attemptClaim(forFaction, location, true); + context.fPlayer.attemptClaim(forFaction, location, true); location = location.add(blockFace.getModX() * 16, 0, blockFace.getModZ() * 16); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdCorner.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdCorner.java index 75ed7754..e1641790 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdCorner.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdCorner.java @@ -2,9 +2,12 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.*; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.util.CornerTask; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import java.util.ArrayList; @@ -16,29 +19,29 @@ public class CmdCorner extends FCommand { public CmdCorner() { this.aliases.add("corner"); - this.permission = Permission.CLAIM_RADIUS.node; - this.senderMustBePlayer = true; - this.senderMustBeMember = true; - this.senderMustBeModerator = false; - this.senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.CORNER) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.TERRITORY) + .build(); } @Override - public void perform() { - FLocation to = new FLocation(me.getLocation()); - if (P.p.getFactionsPlayerListener().getCorners().contains(to)) { + public void perform(CommandContext context) { + FLocation to = new FLocation(context.player.getLocation()); + if (FactionsPlugin.getInstance().getFactionsPlayerListener().getCorners().contains(to)) { Faction cornerAt = Board.getInstance().getFactionAt(to); - if (cornerAt != null && cornerAt.isNormal() && !cornerAt.equals(fme.getFaction())) { - msg(TL.COMMAND_CORNER_CANT_CLAIM); + if (cornerAt != null && cornerAt.isNormal() && !cornerAt.equals(context.fPlayer.getFaction())) { + context.msg(TL.COMMAND_CORNER_CANT_CLAIM); } else { - msg(TL.COMMAND_CORNER_ATTEMPTING_CLAIM); + context.msg(TL.COMMAND_CORNER_ATTEMPTING_CLAIM); List surrounding = new ArrayList<>(400); for (int x = 0; x < Conf.factionBufferSize; ++x) { for (int z = 0; z < Conf.factionBufferSize; ++z) { int newX = (int) ((to.getX() > 0L) ? (to.getX() - x) : (to.getX() + x)); int newZ = (int) ((to.getZ() > 0L) ? (to.getZ() - z) : (to.getZ() + z)); - FLocation location = new FLocation(me.getWorld().getName(), newX, newZ); + FLocation location = new FLocation(context.player.getWorld().getName(), newX, newZ); Faction at = Board.getInstance().getFactionAt(location); if (at == null || !at.isNormal()) { surrounding.add(location); @@ -47,13 +50,13 @@ public class CmdCorner extends FCommand { } surrounding.sort(Comparator.comparingInt(fLocation -> (int) fLocation.getDistanceTo(to))); if (surrounding.isEmpty()) { - msg(TL.COMMAND_CORNER_CANT_CLAIM); + context.msg(TL.COMMAND_CORNER_CANT_CLAIM); } else { - new CornerTask(fme, surrounding).runTaskTimer(P.p, 1L, 1L); + new CornerTask(context.fPlayer, surrounding).runTaskTimer(FactionsPlugin.getInstance(), 1L, 1L); } } } else { - msg(TL.COMMAND_CORNER_NOT_CORNER); + context.msg(TL.COMMAND_CORNER_NOT_CORNER); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdSafeunclaimall.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdSafeunclaimall.java index d19c2b73..bb210593 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdSafeunclaimall.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdSafeunclaimall.java @@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -15,25 +17,15 @@ public class CmdSafeunclaimall extends FCommand { public CmdSafeunclaimall() { this.aliases.add("safeunclaimall"); this.aliases.add("safedeclaimall"); - - //this.requiredArgs.add(""); this.optionalArgs.put("world", "all"); - this.permission = Permission.MANAGE_SAFE_ZONE.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; - - + this.requirements = new CommandRequirements.Builder(Permission.MANAGE_SAFE_ZONE) + .build(); } @Override - public void perform() { - String worldName = argAsString(0); + public void perform(CommandContext context) { + String worldName = context.argAsString(0); World world = null; if (worldName != null) { @@ -48,10 +40,10 @@ public class CmdSafeunclaimall extends FCommand { Board.getInstance().unclaimAllInWorld(id, world); } - msg(TL.COMMAND_SAFEUNCLAIMALL_UNCLAIMED); + context.msg(TL.COMMAND_SAFEUNCLAIMALL_UNCLAIMED); if (Conf.logLandUnclaims) { - P.p.log(TL.COMMAND_SAFEUNCLAIMALL_UNCLAIMEDLOG.format(sender.getName())); + FactionsPlugin.getInstance().log(TL.COMMAND_SAFEUNCLAIMALL_UNCLAIMEDLOG.format(context.sender.getName())); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaim.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaim.java index dcf45518..01bb5ad6 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaim.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.*; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.event.LandUnclaimEvent; import com.massivecraft.factions.integration.Econ; @@ -19,51 +21,54 @@ public class CmdUnclaim extends FCommand { this.aliases.add("declaim"); this.optionalArgs.put("radius", "1"); + this.optionalArgs.put("faction", "yours"); - this.permission = Permission.UNCLAIM.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.UNCLAIM) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.TERRITORY) + .build(); } @Override - public void perform() { - // Read and validate input - int radius = this.argAsInt(0, 1); // Default to 1 + public void perform(CommandContext context) { - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.TERRITORY); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage faction territory"); + if (context.args.size() == 2) { + Faction target = context.argAsFaction(1); + // Dont have to say anything since the argsAsFaction method will tell the player for me. + if (target == null) return; + context.faction = target; + if (context.faction != context.fPlayer.getFaction() && !context.fPlayer.isAdminBypassing()) { + context.msg(TL.COMMAND_UNCLAIM_WRONGFACTION); return; } } + // Read and validate input + int radius = context.argAsInt(0, 1); // Default to 1 + if (radius < 1) { - msg(TL.COMMAND_CLAIM_INVALIDRADIUS); + context.msg(TL.COMMAND_CLAIM_INVALIDRADIUS); return; } - if (radius < 2) { + if (radius == 1) { // single chunk - unClaim(new FLocation(me)); + unClaim(new FLocation(context.player), context); } else { // radius claim - if (!Permission.CLAIM_RADIUS.has(sender, false)) { - msg(TL.COMMAND_CLAIM_DENIED); + if (!Permission.CLAIM_RADIUS.has(context.sender, false)) { + context.msg(TL.COMMAND_CLAIM_DENIED); return; } - new SpiralTask(new FLocation(me), radius) { + new SpiralTask(new FLocation(context.player), radius) { private final int limit = Conf.radiusClaimFailureLimit - 1; private int failCount = 0; @Override public boolean work() { - boolean success = unClaim(this.currentFLocation()); + boolean success = unClaim(currentFLocation(), context); if (success) { failCount = 0; } else if (failCount++ >= limit) { @@ -77,101 +82,101 @@ public class CmdUnclaim extends FCommand { } } - private boolean unClaim(FLocation target) { + private boolean unClaim(FLocation target, CommandContext context) { Faction targetFaction = Board.getInstance().getFactionAt(target); if (targetFaction.isSafeZone()) { - if (Permission.MANAGE_SAFE_ZONE.has(sender)) { + if (Permission.MANAGE_SAFE_ZONE.has(context.sender)) { Board.getInstance().removeAt(target); - msg(TL.COMMAND_UNCLAIM_SAFEZONE_SUCCESS); + context.msg(TL.COMMAND_UNCLAIM_SAFEZONE_SUCCESS); if (Conf.logLandUnclaims) { - P.p.log(TL.COMMAND_UNCLAIM_LOG.format(fme.getName(), target.getCoordString(), targetFaction.getTag())); + FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag())); } return true; } else { - msg(TL.COMMAND_UNCLAIM_SAFEZONE_NOPERM); + context.msg(TL.COMMAND_UNCLAIM_SAFEZONE_NOPERM); return false; } } else if (targetFaction.isWarZone()) { - if (Permission.MANAGE_WAR_ZONE.has(sender)) { + if (Permission.MANAGE_WAR_ZONE.has(context.sender)) { Board.getInstance().removeAt(target); - msg(TL.COMMAND_UNCLAIM_WARZONE_SUCCESS); + context.msg(TL.COMMAND_UNCLAIM_WARZONE_SUCCESS); if (Conf.logLandUnclaims) { - P.p.log(TL.COMMAND_UNCLAIM_LOG.format(fme.getName(), target.getCoordString(), targetFaction.getTag())); + FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag())); } return true; } else { - msg(TL.COMMAND_UNCLAIM_WARZONE_NOPERM); + context.msg(TL.COMMAND_UNCLAIM_WARZONE_NOPERM); return false; } } - if (fme.isAdminBypassing()) { - LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(target, targetFaction, fme); - Bukkit.getScheduler().runTask(P.p, () -> Bukkit.getServer().getPluginManager().callEvent(unclaimEvent)); + if (context.fPlayer.isAdminBypassing()) { + LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(target, targetFaction, context.fPlayer); + Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); if (unclaimEvent.isCancelled()) { return false; } Board.getInstance().removeAt(target); - targetFaction.msg(TL.COMMAND_UNCLAIM_UNCLAIMED, fme.describeTo(targetFaction, true)); - msg(TL.COMMAND_UNCLAIM_UNCLAIMS); + targetFaction.msg(TL.COMMAND_UNCLAIM_UNCLAIMED, context.fPlayer.describeTo(targetFaction, true)); + context.msg(TL.COMMAND_UNCLAIM_UNCLAIMS); if (Conf.logLandUnclaims) { - P.p.log(TL.COMMAND_UNCLAIM_LOG.format(fme.getName(), target.getCoordString(), targetFaction.getTag())); + FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag())); } return true; } + if (targetFaction.getClaimOwnership().containsKey(target) && !targetFaction.isPlayerInOwnerList(context.fPlayer, target)) { + context.msg(TL.GENERIC_FPERM_OWNER_NOPERMISSION, "unclaim"); + return false; + } - if (targetFaction.getAccess(fme, PermissableAction.TERRITORY) == Access.DENY) { + if (targetFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) == Access.DENY && context.fPlayer.getRole() != Role.LEADER) { + context.msg(TL.GENERIC_FPERM_NOPERMISSION, "unclaim"); + return false; + } + + if (!context.assertHasFaction()) { + context.msg(TL.ACTIONS_NOFACTION); + return false; + } + + if (context.faction != targetFaction) { + context.msg(TL.COMMAND_UNCLAIM_WRONGFACTION); return false; } - if (!assertHasFaction()) { - return false; - } - - if (targetFaction.getAccess(fme, PermissableAction.TERRITORY) != Access.ALLOW && !assertMinRole(Role.MODERATOR)) { - return false; - } - - - if (myFaction != targetFaction) { - msg(TL.COMMAND_UNCLAIM_WRONGFACTION); - return false; - } - - - LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(target, targetFaction, fme); - Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); + LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(target, targetFaction, context.fPlayer); + Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(unclaimEvent)); if (unclaimEvent.isCancelled()) { return false; } if (Econ.shouldBeUsed()) { - double refund = Econ.calculateClaimRefund(myFaction.getLandRounded()); + double refund = Econ.calculateClaimRefund(context.faction.getLandRounded()); if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts) { - if (!Econ.modifyMoney(myFaction, refund, TL.COMMAND_UNCLAIM_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIM_FORUNCLAIM.toString())) { + if (!Econ.modifyMoney(context.faction, refund, TL.COMMAND_UNCLAIM_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIM_FORUNCLAIM.toString())) { return false; } } else { - if (!Econ.modifyMoney(fme, refund, TL.COMMAND_UNCLAIM_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIM_FORUNCLAIM.toString())) { + if (!Econ.modifyMoney(context.fPlayer, refund, TL.COMMAND_UNCLAIM_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIM_FORUNCLAIM.toString())) { return false; } } } Board.getInstance().removeAt(target); - myFaction.msg(TL.COMMAND_UNCLAIM_FACTIONUNCLAIMED, fme.describeTo(myFaction, true)); + context.faction.msg(TL.COMMAND_UNCLAIM_FACTIONUNCLAIMED, context.fPlayer.describeTo(context.faction, true)); if (Conf.logLandUnclaims) { - P.p.log(TL.COMMAND_UNCLAIM_LOG.format(fme.getName(), target.getCoordString(), targetFaction.getTag())); + FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag())); } return true; diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaimall.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaimall.java index 48de06c5..8df9fba8 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaimall.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaimall.java @@ -2,11 +2,15 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.event.LandUnclaimAllEvent; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; @@ -16,45 +20,61 @@ public class CmdUnclaimall extends FCommand { this.aliases.add("unclaimall"); this.aliases.add("declaimall"); - //this.requiredArgs.add(""); - //this.optionalArgs.put("", ""); - - this.permission = Permission.UNCLAIM_ALL.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = true; - senderMustBeAdmin = false; + this.optionalArgs.put("faction", "yours"); + this.requirements = new CommandRequirements.Builder(Permission.UNCLAIM_ALL) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.TERRITORY) //TODO: Add Unclaimall PermissableAction + .build(); } @Override - public void perform() { + public void perform(CommandContext context) { + Faction target = context.faction; + if (context.args.size() == 1) { + target = context.argAsFaction(0); + if (target == null) { + context.msg(TL.GENERIC_NOFACTION_FOUND); + return; + } + + if (!context.fPlayer.isAdminBypassing()) { + context.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", target.getTag()).replace("{action}", "unclaimall land")); + return; + } + + Board.getInstance().unclaimAll(target.getId()); + context.faction.msg(TL.COMMAND_UNCLAIMALL_LOG, context.fPlayer.describeTo(target, true), target.getTag()); + if (Conf.logLandUnclaims) + FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIMALL_LOG.format(context.fPlayer.getName(), context.faction.getTag())); + return; + + } if (Econ.shouldBeUsed()) { - double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded()); + double refund = Econ.calculateTotalLandRefund(target.getLandRounded()); if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts) { - if (!Econ.modifyMoney(myFaction, refund, TL.COMMAND_UNCLAIMALL_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIMALL_FORUNCLAIM.toString())) { + if (!Econ.modifyMoney(target, refund, TL.COMMAND_UNCLAIMALL_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIMALL_FORUNCLAIM.toString())) { return; } } else { - if (!Econ.modifyMoney(fme, refund, TL.COMMAND_UNCLAIMALL_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIMALL_FORUNCLAIM.toString())) { + if (!Econ.modifyMoney(target, refund, TL.COMMAND_UNCLAIMALL_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIMALL_FORUNCLAIM.toString())) { return; } } } - LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(myFaction, fme); - Bukkit.getScheduler().runTask(P.p, () -> Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent)); + LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(target, context.fPlayer); + Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent)); if (unclaimAllEvent.isCancelled()) { return; } - Board.getInstance().unclaimAll(myFaction.getId()); - myFaction.msg(TL.COMMAND_UNCLAIMALL_UNCLAIMED, fme.describeTo(myFaction, true)); + Board.getInstance().unclaimAll(target.getId()); + context.faction.msg(TL.COMMAND_UNCLAIMALL_UNCLAIMED, context.fPlayer.describeTo(context.faction, true)); if (Conf.logLandUnclaims) { - P.p.log(TL.COMMAND_UNCLAIMALL_LOG.format(fme.getName(), myFaction.getTag())); + FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIMALL_LOG.format(context.fPlayer.getName(), context.faction.getTag())); } } @@ -64,3 +84,4 @@ public class CmdUnclaimall extends FCommand { } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdWarunclaimall.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdWarunclaimall.java index 99d6e0ba..5c15eca4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdWarunclaimall.java +++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdWarunclaimall.java @@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd.claim; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -15,28 +17,18 @@ public class CmdWarunclaimall extends FCommand { public CmdWarunclaimall() { this.aliases.add("warunclaimall"); this.aliases.add("wardeclaimall"); - - //this.requiredArgs.add(""); this.optionalArgs.put("world", "all"); - this.permission = Permission.MANAGE_WAR_ZONE.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.MANAGE_WAR_ZONE) + .build(); } @Override - public void perform() { - String worldName = argAsString(0); + public void perform(CommandContext context) { + String worldName = context.argAsString(0); World world = null; - if (worldName != null) { - world = Bukkit.getWorld(worldName); - } + if (worldName != null) world = Bukkit.getWorld(worldName); String id = Factions.getInstance().getWarZone().getId(); @@ -46,12 +38,9 @@ public class CmdWarunclaimall extends FCommand { Board.getInstance().unclaimAllInWorld(id, world); } - fme.msg(TL.COMMAND_WARUNCLAIMALL_SUCCESS); - - - if (Conf.logLandUnclaims) { - P.p.log(TL.COMMAND_WARUNCLAIMALL_LOG.format(fme.getName())); - } + context.msg(TL.COMMAND_WARUNCLAIMALL_SUCCESS); + if (Conf.logLandUnclaims) + FactionsPlugin.getInstance().log(TL.COMMAND_WARUNCLAIMALL_LOG.format(context.fPlayer.getName())); } @Override @@ -60,3 +49,4 @@ public class CmdWarunclaimall extends FCommand { } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoney.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoney.java index 7bec6639..3b3380b7 100644 --- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoney.java +++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoney.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd.econ; -import com.massivecraft.factions.P; +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.zcore.util.TL; @@ -21,15 +23,7 @@ public class CmdMoney extends FCommand { //this.requiredArgs.add(""); //this.optionalArgs.put("","") - this.isMoneyCommand = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; - - this.helpLong.add(p.txt.parseTags(TL.COMMAND_MONEY_LONG.toString())); + this.helpLong.add(FactionsPlugin.getInstance().txt.parseTags(TL.COMMAND_MONEY_LONG.toString())); this.addSubCommand(this.cmdMoneyBalance); this.addSubCommand(this.cmdMoneyDeposit); @@ -37,13 +31,16 @@ public class CmdMoney extends FCommand { this.addSubCommand(this.cmdMoneyTransferFf); this.addSubCommand(this.cmdMoneyTransferFp); this.addSubCommand(this.cmdMoneyTransferPf); - } @Override - public void perform() { - this.commandChain.add(this); - P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain); + public void perform(CommandContext context) { + if (!Conf.econEnabled) { + context.msg(TL.ECON_OFF, "economy option is enabled, please set \'econEnabled\' to true in conf.json"); + return; + } + context.commandChain.add(this); + FactionsPlugin.getInstance().cmdAutoHelp.execute(context); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyBalance.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyBalance.java index f314026a..cde68cd3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyBalance.java +++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyBalance.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd.econ; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; @@ -16,36 +18,30 @@ public class CmdMoneyBalance extends FCommand { //this.requiredArgs.add(""); this.optionalArgs.put("faction", "yours"); - this.isMoneyCommand = true; - this.permission = Permission.MONEY_BALANCE.node; this.setHelpShort(TL.COMMAND_MONEYBALANCE_SHORT.toString()); - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MONEY_BALANCE).build(); } @Override - public void perform() { - Faction faction = myFaction; - if (this.argIsSet(0)) { - faction = this.argAsFaction(0); + public void perform(CommandContext context) { + Faction faction = context.faction; + if (context.argIsSet(0)) { + faction = context.argAsFaction(0); } if (faction == null) { return; } - if (faction != myFaction && !Permission.MONEY_BALANCE_ANY.has(sender, true)) { + if (faction != context.faction && !Permission.MONEY_BALANCE_ANY.has(context.sender, true)) { return; } - if (fme != null) { - Econ.sendBalanceInfo((CommandSender) fme, faction); + if (context.fPlayer != null) { + Econ.sendBalanceInfo((CommandSender) context.fPlayer, faction); } else { - Econ.sendBalanceInfo(sender, faction); + Econ.sendBalanceInfo(context.sender, faction); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyDeposit.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyDeposit.java index f4742f1a..24becf24 100644 --- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyDeposit.java +++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyDeposit.java @@ -1,7 +1,9 @@ package com.massivecraft.factions.cmd.econ; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.integration.Econ; @@ -20,29 +22,22 @@ public class CmdMoneyDeposit extends FCommand { this.requiredArgs.add("amount"); this.optionalArgs.put("faction", "yours"); - this.isMoneyCommand = true; - - this.permission = Permission.MONEY_DEPOSIT.node; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MONEY_DEPOSIT) + .memberOnly() + .build(); } @Override - public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator faction = this.argAsFaction(1, myFaction); + public void perform(CommandContext context) { + double amount = context.argAsDouble(0, 0d); + EconomyParticipator faction = context.argAsFaction(1, context.faction); if (faction == null) { return; } - boolean success = Econ.transferMoney(fme, fme, faction, amount); + boolean success = Econ.transferMoney(context.fPlayer, context.fPlayer, faction, amount); if (success && Conf.logMoneyTransactions) { - P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYDEPOSIT_DEPOSITED.toString(), fme.getName(), Econ.moneyString(amount), faction.describeTo(null)))); + FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYDEPOSIT_DEPOSITED.toString(), context.fPlayer.getName(), Econ.moneyString(amount), faction.describeTo(null)))); } } @@ -52,3 +47,4 @@ public class CmdMoneyDeposit extends FCommand { } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFf.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFf.java index 169dc61e..9da896b5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFf.java +++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFf.java @@ -1,7 +1,9 @@ package com.massivecraft.factions.cmd.econ; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.integration.Econ; @@ -13,6 +15,7 @@ import org.bukkit.entity.Player; public class CmdMoneyTransferFf extends FCommand { + public CmdMoneyTransferFf() { this.aliases.add("ff"); @@ -20,45 +23,32 @@ public class CmdMoneyTransferFf extends FCommand { this.requiredArgs.add("faction"); this.requiredArgs.add("faction"); - //this.optionalArgs.put("", ""); - - this.permission = Permission.MONEY_F2F.node; - - this.isMoneyCommand = true; - - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MONEY_F2F).build(); } @Override - public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsFaction(1); + public void perform(CommandContext context) { + double amount = context.argAsDouble(0, 0d); + EconomyParticipator from = context.argAsFaction(1); if (from == null) { return; } - EconomyParticipator to = this.argAsFaction(2); + EconomyParticipator to = context.argAsFaction(2); if (to == null) { return; } - if (Conf.econFactionStartingBalance != 0 && (System.currentTimeMillis() - myFaction.getFoundedDate()) <= (Conf.econDenyWithdrawWhenMinutesAgeLessThan * 6000)) { - msg("Your faction is too young to transfer money like this"); - return; - } - boolean success = Econ.transferMoney(fme, from, to, amount); + + boolean success = Econ.transferMoney(context.fPlayer, from, to, amount); if (success && Conf.logMoneyTransactions) { - String name = sender instanceof Player ? fme.getName() : sender.getName(); - P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYTRANSFERFF_TRANSFER.toString(), name, Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); + String name = context.sender instanceof Player ? context.fPlayer.getName() : context.sender.getName(); + FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYTRANSFERFF_TRANSFER.toString(), name, Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); } } + @Override public TL getUsageTranslation() { return TL.COMMAND_MONEYTRANSFERFF_DESCRIPTION; } -} +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFp.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFp.java index aae46aea..2eac623b 100644 --- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFp.java +++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFp.java @@ -1,7 +1,9 @@ package com.massivecraft.factions.cmd.econ; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.integration.Econ; @@ -11,7 +13,6 @@ import org.bukkit.ChatColor; public class CmdMoneyTransferFp extends FCommand { - public CmdMoneyTransferFp() { this.aliases.add("fp"); @@ -19,39 +20,25 @@ public class CmdMoneyTransferFp extends FCommand { this.requiredArgs.add("faction"); this.requiredArgs.add("player"); - //this.optionalArgs.put("", ""); - - this.permission = Permission.MONEY_F2P.node; - - this.isMoneyCommand = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MONEY_F2P).build(); } @Override - public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsFaction(1); + public void perform(CommandContext context) { + double amount = context.argAsDouble(0, 0d); + EconomyParticipator from = context.argAsFaction(1); if (from == null) { return; } - EconomyParticipator to = this.argAsBestFPlayerMatch(2); + EconomyParticipator to = context.argAsBestFPlayerMatch(2); if (to == null) { return; } - if (Conf.econFactionStartingBalance != 0 && (System.currentTimeMillis() - myFaction.getFoundedDate()) <= (Conf.econDenyWithdrawWhenMinutesAgeLessThan * 6000)) { - msg("Your faction is too young to transfer money like this"); - return; - } - boolean success = Econ.transferMoney(fme, from, to, amount); + boolean success = Econ.transferMoney(context.fPlayer, from, to, amount); if (success && Conf.logMoneyTransactions) { - P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYTRANSFERFP_TRANSFER.toString(), fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); + FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYTRANSFERFP_TRANSFER.toString(), context.fPlayer.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); } } @@ -60,3 +47,4 @@ public class CmdMoneyTransferFp extends FCommand { return TL.COMMAND_MONEYTRANSFERFP_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferPf.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferPf.java index 1efabe96..ab67d6be 100644 --- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferPf.java +++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferPf.java @@ -1,7 +1,9 @@ package com.massivecraft.factions.cmd.econ; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.integration.Econ; @@ -19,39 +21,25 @@ public class CmdMoneyTransferPf extends FCommand { this.requiredArgs.add("player"); this.requiredArgs.add("faction"); - //this.optionalArgs.put("", ""); - - this.permission = Permission.MONEY_P2F.node; - this.isMoneyCommand = true; - - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MONEY_P2F).build(); } @Override - public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsBestFPlayerMatch(1); + public void perform(CommandContext context) { + double amount = context.argAsDouble(0, 0d); + EconomyParticipator from = context.argAsBestFPlayerMatch(1); if (from == null) { return; } - EconomyParticipator to = this.argAsFaction(2); + EconomyParticipator to = context.argAsFaction(2); if (to == null) { return; } - if (Conf.econFactionStartingBalance != 0 && (System.currentTimeMillis() - myFaction.getFoundedDate()) <= (Conf.econDenyWithdrawWhenMinutesAgeLessThan * 6000)) { - msg("Your faction is too young to transfer money like this"); - return; - } - boolean success = Econ.transferMoney(fme, from, to, amount); + boolean success = Econ.transferMoney(context.fPlayer, from, to, amount); if (success && Conf.logMoneyTransactions) { - P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYTRANSFERPF_TRANSFER.toString(), fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); + FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYTRANSFERPF_TRANSFER.toString(), context.fPlayer.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); } } 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 97df7d48..a3cc0686 100644 --- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java +++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java @@ -1,11 +1,14 @@ package com.massivecraft.factions.cmd.econ; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; @@ -21,41 +24,30 @@ public class CmdMoneyWithdraw extends FCommand { this.requiredArgs.add("amount"); this.optionalArgs.put("faction", "yours"); - this.permission = Permission.MONEY_WITHDRAW.node; - this.isMoneyCommand = true; - - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MONEY_F2P) + .playerOnly() + .build(); } @Override - public void perform() { - - double amount = this.argAsDouble(0, 0d); - EconomyParticipator faction = this.argAsFaction(1, myFaction); + public void perform(CommandContext context) { + double amount = context.argAsDouble(0, 0d); + EconomyParticipator faction = context.argAsFaction(1, context.faction); if (faction == null) { return; } - Access access = myFaction.getAccess(fme, PermissableAction.WITHDRAW); - if (access == Access.DENY) { - fme.msg(TL.GENERIC_NOPERMISSION, "withdraw"); - 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 (Conf.econFactionStartingBalance != 0 && (System.currentTimeMillis() - myFaction.getFoundedDate()) <= (Conf.econDenyWithdrawWhenMinutesAgeLessThan * 6000)) { - msg("Your faction is too young to withdraw money like this"); - return; - } - - boolean success = Econ.transferMoney(fme, faction, fme, amount); + boolean success = Econ.transferMoney(context.fPlayer, faction, context.fPlayer, amount); if (success && Conf.logMoneyTransactions) { - P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYWITHDRAW_WITHDRAW.toString(), fme.getName(), Econ.moneyString(amount), faction.describeTo(null)))); + FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYWITHDRAW_WITHDRAW.toString(), context.fPlayer.getName(), Econ.moneyString(amount), faction.describeTo(null)))); } } 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 dc4d2911..d64a456e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java +++ b/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java @@ -1,7 +1,8 @@ package com.massivecraft.factions.cmd.grace; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -9,37 +10,24 @@ import com.massivecraft.factions.zcore.util.TL; public class CmdGrace extends FCommand { public CmdGrace() { - super(); this.aliases.add("grace"); - this.permission = Permission.GRACE.node; - this.disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.GRACE) + .playerOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("f-grace.Enabled")) { - fme.msg(TL.GENERIC_DISABLED); - return; - } - - boolean gracePeriod = Conf.gracePeriod; - - if (args.size() == 0) { - Conf.gracePeriod = !gracePeriod; - } - fme.msg(TL.COMMAND_GRACE_TOGGLE, gracePeriod ? "enabled" : "disabled"); + public void perform(CommandContext context) { + Conf.gracePeriod = !Conf.gracePeriod; + context.msg(TL.COMMAND_GRACE_TOGGLE, Conf.gracePeriod ? TL.GENERIC_ENABLED : TL.GENERIC_DISABLED); } + @Override public TL getUsageTranslation() { return TL.COMMAND_GRACE_DESCRIPTION; } + } diff --git a/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java b/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java index 04362fca..e1ed15c4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java +++ b/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd.logout; import com.massivecraft.factions.Conf; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -11,27 +13,22 @@ public class CmdLogout extends FCommand { super(); this.aliases.add("logout"); - this.permission = Permission.LOGOUT.node; - this.disableOnLock = true; - this.disableOnSpam = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.LOGOUT) + .playerOnly() + .build(); } @Override - public void perform() { - LogoutHandler handler = LogoutHandler.getByName(fme.getPlayer().getName()); + public void perform(CommandContext context) { + LogoutHandler handler = LogoutHandler.getByName(context.player.getName()); - if (handler.isLogoutActive(fme.getPlayer())) { - fme.msg(TL.COMMAND_LOGOUT_ACTIVE); + if (handler.isLogoutActive(context.player)) { + context.msg(TL.COMMAND_LOGOUT_ACTIVE); return; } - handler.applyLogoutCooldown(fme.getPlayer()); - fme.msg(TL.COMMAND_LOGOUT_LOGGING, Conf.logoutCooldown); + handler.applyLogoutCooldown(context.player); + context.msg(TL.COMMAND_LOGOUT_LOGGING, Conf.logoutCooldown); } @Override 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 1cf724e9..0596e2c6 100644 --- a/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java +++ b/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd.logout; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -38,9 +38,9 @@ public class LogoutHandler { public void applyLogoutCooldown(Player player) { logoutCooldown.put(player.getUniqueId(), System.currentTimeMillis() + (30 * 1000)); - Bukkit.getScheduler().runTaskLater(P.p, () -> { + Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> { if (isLogoutActive(player)) { - player.setMetadata("Logout", new FixedMetadataValue(P.p, true)); + player.setMetadata("Logout", new FixedMetadataValue(FactionsPlugin.getInstance(), true)); player.kickPlayer(String.valueOf(TL.COMMAND_LOGOUT_KICK_MESSAGE)); cancelLogout(player); } diff --git a/src/main/java/com/massivecraft/factions/cmd/points/CmdPoints.java b/src/main/java/com/massivecraft/factions/cmd/points/CmdPoints.java index 2db4ca02..762a06d8 100644 --- a/src/main/java/com/massivecraft/factions/cmd/points/CmdPoints.java +++ b/src/main/java/com/massivecraft/factions/cmd/points/CmdPoints.java @@ -1,7 +1,10 @@ package com.massivecraft.factions.cmd.points; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; public class CmdPoints extends FCommand { @@ -14,13 +17,9 @@ public class CmdPoints extends FCommand { super(); this.aliases.add("points"); - this.disableOnLock = false; - this.disableOnSpam = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.POINTS) + .playerOnly() + .build(); this.addSubCommand(this.cmdPointsAdd); @@ -30,13 +29,13 @@ public class CmdPoints extends FCommand { @Override - public void perform() { - if (!P.p.getConfig().getBoolean("f-points.Enabled", true)) { - msg(TL.GENERIC_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled", true)) { + context.msg(TL.GENERIC_DISABLED); return; } - this.commandChain.add(this); - P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain); + context.commandChain.add(this); + FactionsPlugin.getInstance().cmdAutoHelp.execute(context); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsAdd.java b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsAdd.java index e999ae99..f1964ae3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsAdd.java +++ b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsAdd.java @@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.points; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -17,44 +19,34 @@ public class CmdPointsAdd extends FCommand { this.requiredArgs.add("# of points"); - this.errorOnToManyArgs = false; - //this.optionalArgs - - this.permission = Permission.ADDPOINTS.node; - - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.ADDPOINTS) + .build(); } @Override - public void perform() { - Faction faction = Factions.getInstance().getByTag(args.get(0)); + public void perform(CommandContext context) { + Faction faction = Factions.getInstance().getByTag(context.args.get(0)); if (faction == null) { - FPlayer fPlayer = this.argAsFPlayer(0); + FPlayer fPlayer = context.argAsFPlayer(0); if (fPlayer != null) { faction = fPlayer.getFaction(); } } if (faction == null || faction.isWilderness()) { - msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0))); + context.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", context.args.get(0))); return; } - if (argAsInt(1) <= 0) { - msg(TL.COMMAND_POINTS_INSUFFICIENT); + if (context.argAsInt(1) <= 0) { + context.msg(TL.COMMAND_POINTS_INSUFFICIENT); return; } - faction.setPoints(faction.getPoints() + argAsInt(1)); + faction.setPoints(faction.getPoints() + context.argAsInt(1)); - msg(TL.COMMAND_POINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints()); + context.msg(TL.COMMAND_POINTS_SUCCESSFUL, context.argAsInt(1), faction.getTag(), faction.getPoints()); } diff --git a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsRemove.java b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsRemove.java index 10fe5e0c..6320a256 100644 --- a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsRemove.java +++ b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsRemove.java @@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.points; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -16,44 +18,34 @@ public class CmdPointsRemove extends FCommand { this.requiredArgs.add("faction/player"); this.requiredArgs.add("# of points"); + this.requirements = new CommandRequirements.Builder(Permission.REMOVEPOINTS) + .build(); - this.errorOnToManyArgs = false; - //this.optionalArgs - - this.permission = Permission.REMOVEPOINTS.node; - - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; } @Override - public void perform() { - Faction faction = Factions.getInstance().getByTag(args.get(0)); + public void perform(CommandContext context) { + Faction faction = Factions.getInstance().getByTag(context.args.get(0)); - FPlayer fPlayer = this.argAsFPlayer(0); + FPlayer fPlayer = context.argAsFPlayer(0); if (fPlayer != null) { faction = fPlayer.getFaction(); } if (faction == null || faction.isWilderness()) { - msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0))); + context.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", context.args.get(0))); return; } - if (argAsInt(1) <= 0) { - msg(TL.COMMAND_POINTS_INSUFFICIENT); + if (context.argAsInt(1) <= 0) { + context.msg(TL.COMMAND_POINTS_INSUFFICIENT); return; } - faction.setPoints(faction.getPoints() - argAsInt(1)); - msg(TL.COMMAND_REMOVEPOINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints()); + faction.setPoints(faction.getPoints() - context.argAsInt(1)); + context.msg(TL.COMMAND_REMOVEPOINTS_SUCCESSFUL, context.argAsInt(1), faction.getTag(), faction.getPoints()); } diff --git a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsSet.java b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsSet.java index d8a304a2..e3fde0f5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsSet.java +++ b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsSet.java @@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.points; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -17,42 +19,32 @@ public class CmdPointsSet extends FCommand { this.requiredArgs.add("# of points"); - this.errorOnToManyArgs = false; - //this.optionalArgs - - this.permission = Permission.SETPOINTS.node; - - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.SETPOINTS) + .build(); } @Override - public void perform() { - Faction faction = Factions.getInstance().getByTag(args.get(0)); + public void perform(CommandContext context) { + Faction faction = Factions.getInstance().getByTag(context.args.get(0)); - FPlayer fPlayer = this.argAsFPlayer(0); + FPlayer fPlayer = context.argAsFPlayer(0); if (fPlayer != null) { faction = fPlayer.getFaction(); } if (faction == null || faction.isWilderness()) { - msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0))); + context.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", context.args.get(0))); return; } - if (argAsInt(1) < 0) { - msg(TL.COMMAND_POINTS_INSUFFICIENT); + if (context.argAsInt(1) < 0) { + context.msg(TL.COMMAND_POINTS_INSUFFICIENT); return; } - faction.setPoints(argAsInt(1)); - msg(TL.COMMAND_SETPOINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints()); + faction.setPoints(context.argAsInt(1)); + context.msg(TL.COMMAND_SETPOINTS_SUCCESSFUL, context.argAsInt(1), faction.getTag(), faction.getPoints()); } 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 fdc979b9..4e5e21a3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java @@ -2,13 +2,16 @@ package com.massivecraft.factions.cmd.relational; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.event.FactionRelationEvent; import com.massivecraft.factions.event.FactionRelationWishEvent; import com.massivecraft.factions.scoreboards.FTeamWrapper; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -20,99 +23,96 @@ public abstract class FRelationCommand extends FCommand { public FRelationCommand() { super(); this.requiredArgs.add("faction tag"); - //this.optionalArgs.put("player name", "you"); - this.permission = Permission.RELATION.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = true; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.RELATION) + .withRole(Role.MODERATOR) + .playerOnly() + .memberOnly() + .build(); } @Override - public void perform() { - Faction them = this.argAsFaction(0); + public void perform(CommandContext context) { + Faction them = context.argAsFaction(0); if (them == null) { return; } if (!them.isNormal()) { - msg(TL.COMMAND_RELATIONS_ALLTHENOPE); + context.msg(TL.COMMAND_RELATIONS_ALLTHENOPE); return; } - if (them == myFaction) { - msg(TL.COMMAND_RELATIONS_MORENOPE); + if (them == context.faction) { + context.msg(TL.COMMAND_RELATIONS_MORENOPE); return; } - if (myFaction.getRelationWish(them) == targetRelation) { - msg(TL.COMMAND_RELATIONS_ALREADYINRELATIONSHIP, them.getTag()); + if (context.faction.getRelationWish(them) == targetRelation) { + context.msg(TL.COMMAND_RELATIONS_ALREADYINRELATIONSHIP, them.getTag()); return; } - if (hasMaxRelations(them, targetRelation)) { + if (hasMaxRelations(context.faction, them, targetRelation)) { // We message them down there with the count. return; } - Relation oldRelation = myFaction.getRelationTo(them, true); - FactionRelationWishEvent wishEvent = new FactionRelationWishEvent(fme, myFaction, them, oldRelation, targetRelation); + Relation oldRelation = context.faction.getRelationTo(them, true); + FactionRelationWishEvent wishEvent = new FactionRelationWishEvent(context.fPlayer, context.faction, them, oldRelation, targetRelation); Bukkit.getPluginManager().callEvent(wishEvent); if (wishEvent.isCancelled()) { return; } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(targetRelation.getRelationCost(), TL.COMMAND_RELATIONS_TOMARRY, TL.COMMAND_RELATIONS_FORMARRY)) { + if (!context.payForCommand(targetRelation.getRelationCost(), TL.COMMAND_RELATIONS_TOMARRY, TL.COMMAND_RELATIONS_FORMARRY)) { return; } // try to set the new relation - myFaction.setRelationWish(them, targetRelation); - Relation currentRelation = myFaction.getRelationTo(them, true); + context.faction.setRelationWish(them, targetRelation); + Relation currentRelation = context.faction.getRelationTo(them, true); ChatColor currentRelationColor = currentRelation.getColor(); // if the relation change was successful if (targetRelation.value == currentRelation.value) { // trigger the faction relation event - FactionRelationEvent relationEvent = new FactionRelationEvent(myFaction, them, oldRelation, currentRelation); + FactionRelationEvent relationEvent = new FactionRelationEvent(context.faction, them, oldRelation, currentRelation); Bukkit.getServer().getPluginManager().callEvent(relationEvent); - them.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + myFaction.getTag()); - myFaction.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + them.getTag()); + them.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + context.faction.getTag()); + context.faction.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + them.getTag()); } else { // inform the other faction of your request - them.msg(TL.COMMAND_RELATIONS_PROPOSAL_1, currentRelationColor + myFaction.getTag(), targetRelation.getColor() + targetRelation.getTranslation()); - them.msg(TL.COMMAND_RELATIONS_PROPOSAL_2, Conf.baseCommandAliases.get(0), targetRelation, myFaction.getTag()); - myFaction.msg(TL.COMMAND_RELATIONS_PROPOSAL_SENT, currentRelationColor + them.getTag(), "" + targetRelation.getColor() + targetRelation); + them.msg(TL.COMMAND_RELATIONS_PROPOSAL_1, currentRelationColor + context.faction.getTag(), targetRelation.getColor() + targetRelation.getTranslation()); + them.msg(TL.COMMAND_RELATIONS_PROPOSAL_2, Conf.baseCommandAliases.get(0), targetRelation, context.faction.getTag()); + context.faction.msg(TL.COMMAND_RELATIONS_PROPOSAL_SENT, currentRelationColor + them.getTag(), "" + targetRelation.getColor() + targetRelation); } if (!targetRelation.isNeutral() && them.isPeaceful()) { them.msg(TL.COMMAND_RELATIONS_PEACEFUL); - myFaction.msg(TL.COMMAND_RELATIONS_PEACEFULOTHER); + context.faction.msg(TL.COMMAND_RELATIONS_PEACEFULOTHER); } - if (!targetRelation.isNeutral() && myFaction.isPeaceful()) { + if (!targetRelation.isNeutral() && context.faction.isPeaceful()) { them.msg(TL.COMMAND_RELATIONS_PEACEFULOTHER); - myFaction.msg(TL.COMMAND_RELATIONS_PEACEFUL); + context.faction.msg(TL.COMMAND_RELATIONS_PEACEFUL); } - FTeamWrapper.updatePrefixes(myFaction); + FTeamWrapper.updatePrefixes(context.faction); FTeamWrapper.updatePrefixes(them); } - private boolean hasMaxRelations(Faction them, Relation targetRelation) { - int max = P.p.getConfig().getInt("max-relations." + targetRelation.toString(), -1); - if (P.p.getConfig().getBoolean("max-relations.enabled", false)) { + 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 (myFaction.getRelationCount(targetRelation) >= max) { - msg(TL.COMMAND_RELATIONS_EXCEEDS_ME, max, targetRelation.getPluralTranslation()); + if (us.getRelationCount(targetRelation) >= max) { + us.msg(TL.COMMAND_RELATIONS_EXCEEDS_ME, max, targetRelation.getPluralTranslation()); return true; } if (them.getRelationCount(targetRelation) >= max) { - msg(TL.COMMAND_RELATIONS_EXCEEDS_THEY, max, targetRelation.getPluralTranslation()); + them.msg(TL.COMMAND_RELATIONS_EXCEEDS_THEY, max, targetRelation.getPluralTranslation()); return true; } } @@ -125,3 +125,4 @@ public abstract class FRelationCommand extends FCommand { return TL.COMMAND_RELATIONS_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java b/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java index 7899a1a5..360f2d3c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java @@ -1,13 +1,13 @@ package com.massivecraft.factions.cmd.roles; import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; -import org.bukkit.ChatColor; public class FPromoteCommand extends FCommand { @@ -15,33 +15,25 @@ public class FPromoteCommand extends FCommand { public FPromoteCommand() { super(); - this.requiredArgs.add("player"); - this.permission = Permission.PROMOTE.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.PROMOTE) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.PROMOTE) + .build(); } @Override - public void perform() { - FPlayer target = this.argAsBestFPlayerMatch(0); + public void perform(CommandContext context) { + FPlayer target = context.argAsBestFPlayerMatch(0); if (target == null) { - msg(TL.GENERIC_NOPLAYERFOUND, this.argAsString(0)); + context.msg(TL.GENERIC_NOPLAYERFOUND, context.argAsString(0)); return; } - if (!target.getFaction().equals(myFaction)) { - msg(TL.COMMAND_PROMOTE_WRONGFACTION, target.getName()); - return; - } - - if (target.isAlt()) { - msg(ChatColor.RED + "You can not edit the rank of alt accounts."); + if (!target.getFaction().equals(context.faction)) { + context.msg(TL.COMMAND_PROMOTE_WRONGFACTION, target.getName()); return; } @@ -49,36 +41,31 @@ public class FPromoteCommand extends FCommand { Role promotion = Role.getRelative(current, +relative); // Now it ain't that messy - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.PROMOTE); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_NOPERMISSION, "manage ranks"); - return; - } - if (target == fme) { - fme.msg(TL.COMMAND_PROMOTE_NOTSELF); + if (!context.fPlayer.isAdminBypassing()) { + if (target == context.fPlayer) { + context.msg(TL.COMMAND_PROMOTE_NOTSELF); return; } // Don't allow people to manage role of their same rank - if (fme.getRole() == current) { - fme.msg(TL.COMMAND_PROMOTE_NOT_SAME); + if (context.fPlayer.getRole() == current) { + context.msg(TL.COMMAND_PROMOTE_NOT_SAME); return; } // Don't allow people to promote people to their same or higher rank. - if (fme.getRole().value <= promotion.value) { - fme.msg(TL.COMMAND_PROMOTE_NOT_ALLOWED); + if (context.fPlayer.getRole().value <= promotion.value) { + context.msg(TL.COMMAND_PROMOTE_NOT_ALLOWED); return; } } if (promotion == null) { - fme.msg(TL.COMMAND_PROMOTE_NOTTHATPLAYER); + context.msg(TL.COMMAND_PROMOTE_NOTTHATPLAYER); return; } // Don't allow people to promote people to their same or higher rnak. - if (fme.getRole().value <= promotion.value) { - fme.msg(TL.COMMAND_PROMOTE_NOT_ALLOWED); + if (context.fPlayer.getRole().value <= promotion.value) { + context.msg(TL.COMMAND_PROMOTE_NOT_ALLOWED); return; } @@ -90,7 +77,7 @@ public class FPromoteCommand extends FCommand { target.msg(TL.COMMAND_PROMOTE_TARGET, action, promotion.nicename); } - fme.msg(TL.COMMAND_PROMOTE_SUCCESS, action, target.getName(), promotion.nicename); + context.msg(TL.COMMAND_PROMOTE_SUCCESS, action, target.getName(), promotion.nicename); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java index 35bad43b..cbb091e5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java +++ b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java @@ -1,11 +1,11 @@ package com.massivecraft.factions.cmd.tnt; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.XMaterial; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Material; @@ -14,54 +14,40 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; public class CmdTnt extends FCommand { - public CmdTnt() { super(); this.aliases.add("tnt"); - this.optionalArgs.put("add/take", ""); this.optionalArgs.put("amount", "number"); - - this.permission = Permission.TNT.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeModerator = true; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.TNT) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.TNTBANK) + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("ftnt.Enabled")) { - fme.msg(TL.COMMAND_TNT_DISABLED_MSG); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("ftnt.Enabled")) { + context.msg(TL.COMMAND_TNT_DISABLED_MSG); return; } - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.TNTBANK); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use tnt bank"); - return; - } - } - - if (args.size() == 2) { - if (args.get(0).equalsIgnoreCase("add") || args.get(0).equalsIgnoreCase("a")) { + if (context.args.size() == 2) { + if (context.args.get(0).equalsIgnoreCase("add") || context.args.get(0).equalsIgnoreCase("a")) { try { - Integer.parseInt(args.get(1)); + Integer.parseInt(context.args.get(1)); } catch (NumberFormatException e) { - fme.msg(TL.COMMAND_TNT_INVALID_NUM); + context.msg(TL.COMMAND_TNT_INVALID_NUM); return; } - int amount = Integer.parseInt(args.get(1)); + int amount = Integer.parseInt(context.args.get(1)); if (amount < 0) { - fme.msg(TL.COMMAND_TNT_POSITIVE); + context.msg(TL.COMMAND_TNT_POSITIVE); return; } - Inventory inv = me.getInventory(); + Inventory inv = context.player.getInventory(); int invTnt = 0; for (int i = 0; i <= inv.getSize(); i++) { if (inv.getItem(i) == null) { @@ -72,69 +58,83 @@ public class CmdTnt extends FCommand { } } if (amount > invTnt) { - fme.msg(TL.COMMAND_TNT_DEPOSIT_NOTENOUGH); + context.msg(TL.COMMAND_TNT_DEPOSIT_NOTENOUGH); return; } ItemStack tnt = new ItemStack(Material.TNT, amount); - if (fme.getFaction().getTnt() + amount > P.p.getConfig().getInt("ftnt.Bank-Limit")) { - msg(TL.COMMAND_TNT_EXCEEDLIMIT); + if (context.faction.getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) { + context.msg(TL.COMMAND_TNT_EXCEEDLIMIT); return; } - removeFromInventory(me.getInventory(), tnt); - me.updateInventory(); + removeFromInventory(context.player.getInventory(), tnt); + context.player.updateInventory(); - fme.getFaction().addTnt(amount); - fme.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS); - fme.sendMessage(P.p.color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", fme.getFaction().getTnt() + ""))); + context.faction.addTnt(amount); + context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS); + context.fPlayer.sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + ""))); return; } - if (args.get(0).equalsIgnoreCase("take") || args.get(0).equalsIgnoreCase("t")) { + if (context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t")) { try { - Integer.parseInt(args.get(1)); + Integer.parseInt(context.args.get(1)); } catch (NumberFormatException e) { - fme.msg(TL.COMMAND_TNT_INVALID_NUM); + context.msg(TL.COMMAND_TNT_INVALID_NUM); return; } - int amount = Integer.parseInt(args.get(1)); + int amount = Integer.parseInt(context.args.get(1)); if (amount < 0) { - fme.msg(TL.COMMAND_TNT_POSITIVE); + context.msg(TL.COMMAND_TNT_POSITIVE); return; } - if (fme.getFaction().getTnt() < amount) { - fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH); + if (context.faction.getTnt() < amount) { + context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString()); return; } - int fullStacks = Math.round(amount / 6); + int fullStacks = Math.round(amount / 64); int remainderAmt = amount - (fullStacks * 64); - if ((remainderAmt == 0 && !hasAvaliableSlot(me, fullStacks))) { - fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE); + if ((remainderAmt == 0 && !hasAvaliableSlot(context.player, fullStacks))) { + context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE); return; } - if (!hasAvaliableSlot(me, fullStacks + 1)) { - fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE); + if (!hasAvaliableSlot(context.player, fullStacks + 1)) { + context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE); return; } for (int i = 0; i <= fullStacks - 1; i++) - me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64)); + context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64)); if (remainderAmt != 0) - me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt)); + context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt)); - fme.getFaction().takeTnt(amount); - me.updateInventory(); - fme.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS); + context.faction.takeTnt(amount); + context.player.updateInventory(); + context.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS); } - } else if (args.size() == 1) { - fme.msg(TL.GENERIC_ARGS_TOOFEW); - fme.msg(args.get(0).equalsIgnoreCase("take") || args.get(0).equalsIgnoreCase("t") ? TL.COMMAND_TNT_TAKE_DESCRIPTION : TL.COMMAND_TNT_ADD_DESCRIPTION); + } else if (context.args.size() == 1) { + context.msg(TL.GENERIC_ARGS_TOOFEW); + context.msg(context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t") ? TL.COMMAND_TNT_TAKE_DESCRIPTION : TL.COMMAND_TNT_ADD_DESCRIPTION); } - fme.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", fme.getFaction().getTnt() + "")); + context.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.faction.getTnt() + "")); } + public boolean inventoryContains(Inventory inventory, ItemStack item) { + int count = 0; + ItemStack[] items = inventory.getContents(); + for (int i = 0; i < items.length; i++) { + if (items[i] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) { + count += items[i].getAmount(); + } + if (count >= item.getAmount()) { + return true; + } + } + return false; + } + public boolean hasAvaliableSlot(Player player, int howmany) { - int check = 0; + Integer check = 0; for (ItemStack item : player.getInventory().getContents()) { if (item == null) { check++; @@ -168,3 +168,4 @@ public class CmdTnt extends FCommand { return TL.COMMAND_TNT_DESCRIPTION; } } + diff --git a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java index 7377ac24..edd9f749 100644 --- a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java +++ b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java @@ -1,20 +1,27 @@ package com.massivecraft.factions.cmd.tnt; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; -import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.Dispenser; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + public class CmdTntFill extends FCommand { public CmdTntFill() { @@ -24,146 +31,137 @@ public class CmdTntFill extends FCommand { this.requiredArgs.add("radius"); this.requiredArgs.add("amount"); - this.permission = Permission.TNTFILL.node; - this.disableOnLock = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = false; - + this.requirements = new CommandRequirements.Builder(Permission.TNTFILL) + .playerOnly() + .memberOnly() + .withAction(PermissableAction.TNTFILL) + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("Tntfill.enabled")) { - this.fme.msg(TL.GENERIC_DISABLED); + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("Tntfill.enabled")) { + context.msg(TL.GENERIC_DISABLED); return; } - if (!fme.isAdminBypassing()) { - Access access = myFaction.getAccess(fme, PermissableAction.TNTFILL); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use tnt fill"); + + // Don't do I/O unless necessary + try { + Integer.parseInt(context.args.get(0)); + Integer.parseInt(context.args.get(1)); + } catch (NumberFormatException e) { + context.msg(TL.COMMAND_TNT_INVALID_NUM); + return; + } + + context.msg(TL.COMMAND_TNTFILL_HEADER); + int radius = context.argAsInt(0, 0); // We don't know the max yet, so let's not assume. + int amount = context.argAsInt(1, 0); // We don't know the max yet, so let's not assume. + + if (amount < 0) { + context.msg(TL.COMMAND_TNT_POSITIVE); + return; + } + if (radius > FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-radius")) { + context.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-radius") + "")); + return; + } + if (amount > FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-amount")) { + context.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-amount") + "")); + return; + } + + // How many dispensers are we to fill in? + + Location start = context.player.getLocation(); + // Keep it on the stack for CPU saving. + List opDispensers = new ArrayList<>(); + + Block startBlock = start.getBlock(); + for (int x = -radius; x <= radius; x++) + for (int y = -radius; y <= radius; y++) + for (int z = -radius; z <= radius; z++) { + Block block = startBlock.getRelative(x, y, z); + if (block == null) continue; + BlockState blockState = block.getState(); + if (!(blockState instanceof Dispenser)) continue; + opDispensers.add((Dispenser) blockState); + } + if (opDispensers.isEmpty()) { + context.fPlayer.msg(TL.COMMAND_TNTFILL_NODISPENSERS.toString().replace("{radius}", radius + "")); + return; + } + + // What's the required amount of resources + int requiredTnt = (opDispensers.size() * amount); + + // Do I have enough tnt in my inventory? + int playerTnt = inventoryItemCount(context.player.getInventory(), Material.TNT); + if (playerTnt < requiredTnt) { + // How much TNT will I take from bank? + int getFactionTnt = requiredTnt - playerTnt; + + // Do I have enough tnt in bank? + if ((context.faction.getTnt() < getFactionTnt)) { + context.fPlayer.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString()); return; } - } - - msg(TL.COMMAND_TNTFILL_HEADER); - int radius = argAsInt(0, 16); - int amount = argAsInt(1, 16); - if (radius > P.p.getConfig().getInt("Tntfill.max-radius")) { - fme.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", P.p.getConfig().getInt("Tntfill.max-radius") + "")); - return; + // Take TNT from the bank. + removeFromBank(context, getFactionTnt); } - if (amount > P.p.getConfig().getInt("Tntfill.max-amount")) { - fme.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", P.p.getConfig().getInt("Tntfill.max-amount") + "")); - return; - } - - try { - Integer.parseInt(args.get(1)); - } catch (NumberFormatException e) { - fme.msg(TL.COMMAND_TNT_INVALID_NUM); - return; - } - if (amount < 0) { - fme.msg(TL.COMMAND_TNT_POSITIVE); - return; - } - boolean bankMode = fme.getRole().isAtLeast(Role.MODERATOR); - Location start = me.getLocation(); - int counter = 0; - for (double x = start.getX() - radius; x <= start.getX() + radius; x++) { - for (double y = start.getY() - radius; y <= start.getY() + radius; y++) { - for (double z = start.getZ() - radius; z <= start.getZ() + radius; z++) { - Location blockLoc = new Location(start.getWorld(), x, y, z); - if (blockLoc.getBlock().getState() instanceof Dispenser) { - Dispenser disp = (Dispenser) blockLoc.getBlock().getState(); - Inventory dispenser = disp.getInventory(); - if (canHold(dispenser, amount)) { - int fullStacks = amount / 64; - int remainderAmt = amount % 64; - if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT, amount))) { - if (!fme.getRole().isAtLeast(Role.MODERATOR)) { - fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString()); - sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + "")); - me.updateInventory(); - return; - } else if (bankMode) { - //msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}",fme.getRole().nicename)); - bankMode = true; - removeFromBank(amount); - if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT, amount))) { - fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString()); - sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + "")); - me.updateInventory(); - return; - } - } - } - ItemStack tnt64 = new ItemStack(Material.TNT, 64); - for (int i = 0; i <= fullStacks - 1; i++) { - dispenser.addItem(tnt64); - takeTnt(64); - } - if (remainderAmt != 0) { - ItemStack tnt = new ItemStack(Material.TNT, remainderAmt); - dispenser.addItem(tnt); - takeTnt(remainderAmt); - } - counter++; - } - } - } - } - } - if (bankMode) { - msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}", fme.getRole().nicename)); - } - sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + "")); - me.updateInventory(); + fillDispensers(context.fPlayer, opDispensers, amount); + // Remove used TNT from player inventory. + context.sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", requiredTnt + "").replace("{dispensers}", opDispensers.size() + "")); } - private void removeFromBank(int amount) { + // Actually fill every dispenser with the precise amount. + private void fillDispensers(FPlayer fPlayer, List dispensers, int count) { + for (Dispenser dispenser : dispensers) { + takeTnt(fPlayer, count); + dispenser.getInventory().addItem(new ItemStack(Material.TNT, count)); + } + } + + private void removeFromBank(CommandContext context, int amount) { try { - Integer.parseInt(args.get(1)); + Integer.parseInt(context.args.get(1)); } catch (NumberFormatException e) { - fme.msg(TL.COMMAND_TNT_INVALID_NUM); + context.fPlayer.msg(TL.COMMAND_TNT_INVALID_NUM.toString()); return; } if (amount < 0) { - fme.msg(TL.COMMAND_TNT_POSITIVE); + context.fPlayer.msg(TL.COMMAND_TNT_POSITIVE.toString()); return; } - if (fme.getFaction().getTnt() < amount) { - fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH); + if (context.faction.getTnt() < amount) { + context.fPlayer.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString()); return; } int fullStacks = amount / 64; int remainderAmt = amount % 64; - if ((remainderAmt == 0 && getEmptySlots(me) <= fullStacks)) { - fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH); + if ((remainderAmt == 0 && getEmptySlots(context.player) <= fullStacks)) { + context.fPlayer.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString()); return; } - if (getEmptySlots(me) + 1 <= fullStacks) { - fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH); + if (getEmptySlots(context.player) + 1 <= fullStacks) { + context.fPlayer.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString()); return; } ItemStack tnt64 = new ItemStack(Material.TNT, 64); for (int i = 0; i <= fullStacks - 1; i++) { - me.getInventory().addItem(tnt64); + context.player.getInventory().addItem(tnt64); } if (remainderAmt != 0) { ItemStack tnt = new ItemStack(Material.TNT, remainderAmt); - me.getInventory().addItem(tnt); + context.player.getInventory().addItem(tnt); } - fme.getFaction().takeTnt(amount); - me.updateInventory(); + context.faction.takeTnt(amount); + context.player.updateInventory(); } - public void takeTnt(int amount) { - Inventory inv = me.getInventory(); + private void takeTnt(FPlayer fme, int amount) { + Inventory inv = fme.getPlayer().getInventory(); int invTnt = 0; for (int i = 0; i <= inv.getSize(); i++) { if (inv.getItem(i) == null) { @@ -174,46 +172,27 @@ public class CmdTntFill extends FCommand { } } if (amount > invTnt) { - fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH); + fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString()); return; } ItemStack tnt = new ItemStack(Material.TNT, amount); - if (fme.getFaction().getTnt() + amount > P.p.getConfig().getInt("ftnt.Bank-Limit")) { - msg(TL.COMMAND_TNT_EXCEEDLIMIT); + if (fme.getFaction().getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) { + fme.msg(TL.COMMAND_TNT_EXCEEDLIMIT.toString()); return; } - removeFromInventory(me.getInventory(), tnt); + removeFromInventory(fme.getPlayer().getInventory(), tnt); } - public boolean canHold(Inventory inventory, int amount) { - int fullStacks = amount / 64; - int remainderAmt = amount % 64; - if ((remainderAmt == 0 && getEmptySlots(me) <= fullStacks)) { - return false; - } - if (getEmptySlots(me) + 1 <= fullStacks) { - fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH); - return false; - } - return true; - } - - public boolean inventoryContains(Inventory inventory, ItemStack item) { + // Counts the item type available in the inventory. + private int inventoryItemCount(Inventory inventory, Material mat) { int count = 0; - ItemStack[] items = inventory.getContents(); - for (int i = 0; i < items.length; i++) { - if (items[i] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) { - count += items[i].getAmount(); - } - if (count >= item.getAmount()) { - return true; - } - } - return false; + HashMap items = inventory.all(mat); + for (int item : items.keySet()) + count += inventory.getItem(item).getAmount(); + return count; } - - public void removeFromInventory(Inventory inventory, ItemStack item) { + private void removeFromInventory(Inventory inventory, ItemStack item) { int amt = item.getAmount(); ItemStack[] items = inventory.getContents(); for (int i = 0; i < items.length; i++) { @@ -233,7 +212,7 @@ public class CmdTntFill extends FCommand { inventory.setContents(items); } - public int getEmptySlots(Player p) { + private int getEmptySlots(Player p) { PlayerInventory inventory = p.getInventory(); ItemStack[] cont = inventory.getContents(); int i = 0; @@ -248,4 +227,5 @@ public class CmdTntFill extends FCommand { public TL getUsageTranslation() { return TL.COMMAND_TNTFILL_DESCRIPTION; } + } \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/integration/Econ.java b/src/main/java/com/massivecraft/factions/integration/Econ.java index 216163a3..d499542b 100644 --- a/src/main/java/com/massivecraft/factions/integration/Econ.java +++ b/src/main/java/com/massivecraft/factions/integration/Econ.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.integration; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -35,24 +35,24 @@ public class Econ { String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" "; if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) { - P.p.log(integrationFail + "is not installed."); + FactionsPlugin.getInstance().log(integrationFail + "is not installed."); return; } RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) { - P.p.log(integrationFail + "is not hooked into an economy plugin."); + FactionsPlugin.getInstance().log(integrationFail + "is not hooked into an economy plugin."); return; } econ = rsp.getProvider(); - P.p.log("Economy integration through Vault plugin successful."); + FactionsPlugin.getInstance().log("Economy integration through Vault plugin successful."); if (!Conf.econEnabled) { - P.p.log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true"); + FactionsPlugin.getInstance().log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true"); } - P.p.cmdBase.cmdHelp.updateHelp(); + //FactionsPlugin.getInstance().cmdBase.cmdHelp.updateHelp(); } public static boolean shouldBeUsed() { @@ -83,7 +83,7 @@ public class Econ { public static void sendBalanceInfo(CommandSender to, Faction about) { if (!shouldBeUsed()) { - P.p.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin."); + FactionsPlugin.getInstance().log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin."); return; } to.sendMessage(String.format("%s's balance is %s.", about.getTag(), Econ.moneyString(econ.getBalance(about.getAccountId())))); diff --git a/src/main/java/com/massivecraft/factions/integration/Worldguard.java b/src/main/java/com/massivecraft/factions/integration/Worldguard.java index 2718b3c5..457f2a7d 100644 --- a/src/main/java/com/massivecraft/factions/integration/Worldguard.java +++ b/src/main/java/com/massivecraft/factions/integration/Worldguard.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.integration; import com.massivecraft.factions.FLocation; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; @@ -38,11 +38,11 @@ public class Worldguard { if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) { enabled = false; wg = null; - P.p.log("Could not hook to WorldGuard. WorldGuard checks are disabled."); + FactionsPlugin.getInstance().log("Could not hook to WorldGuard. WorldGuard checks are disabled."); } else { wg = (WorldGuardPlugin) wgplug; enabled = true; - P.p.log("Successfully hooked to WorldGuard."); + FactionsPlugin.getInstance().log("Successfully hooked to WorldGuard."); } } 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 a4774969..120c8564 100644 --- a/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java @@ -113,7 +113,7 @@ public class EngineDynmap { } // Shedule non thread safe sync at the end! - Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { + Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { final Map homes = createHomes(); final Map areas = createAreas(); diff --git a/src/main/java/com/massivecraft/factions/listeners/EssentialsHomeHandler.java b/src/main/java/com/massivecraft/factions/listeners/EssentialsHomeHandler.java index fa173c14..61ea94f5 100644 --- a/src/main/java/com/massivecraft/factions/listeners/EssentialsHomeHandler.java +++ b/src/main/java/com/massivecraft/factions/listeners/EssentialsHomeHandler.java @@ -5,7 +5,7 @@ import com.earth2me.essentials.User; import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.event.FPlayerLeaveEvent; import org.bukkit.Location; import org.bukkit.event.EventHandler; @@ -37,7 +37,7 @@ public class EssentialsHomeHandler implements Listener { Faction factionAt = Board.getInstance().getFactionAt(floc); if (factionAt.equals(faction) && factionAt.isNormal()) { user.delHome(homeName); - P.p.log(Level.INFO, "FactionLeaveEvent: Removing home %s, player %s, in territory of %s", homeName, event.getfPlayer().getName(), faction.getTag()); + FactionsPlugin.getInstance().log(Level.INFO, "FactionLeaveEvent: Removing home %s, player %s, in territory of %s", homeName, event.getfPlayer().getName(), faction.getTag()); } } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index 7d87b692..62366bcf 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -87,7 +87,7 @@ public class FactionsBlockListener implements Listener { return false; } else if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own - if (P.p.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) + if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) return true; // Get faction pain build access relation to me boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; @@ -215,7 +215,7 @@ public class FactionsBlockListener implements Listener { @EventHandler public void onVaultPlace(BlockPlaceEvent e) { if (e.getItemInHand().getType() == Material.CHEST) { - ItemStack vault = P.p.createItem(Material.CHEST, 1, (short) 0, P.p.color(P.p.getConfig().getString("fvault.Item.Name")), P.p.colorList(P.p.getConfig().getStringList("fvault.Item.Lore"))); + ItemStack vault = FactionsPlugin.getInstance().createItem(Material.CHEST, 1, (short) 0, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fvault.Item.Name")), FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fvault.Item.Lore"))); if (e.getItemInHand().isSimilar(vault)) { FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); if (fme.getFaction().getVault() != null) { @@ -241,7 +241,7 @@ public class FactionsBlockListener implements Listener { Material blockMaterial = blockLoc.getBlock().getType(); - if (blockMaterial == Material.CHEST || (P.p.getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) { + if (blockMaterial == Material.CHEST || (FactionsPlugin.getInstance().getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) { e.setCancelled(true); fme.msg(TL.COMMAND_GETVAULT_CHESTNEAR); return; @@ -260,7 +260,7 @@ public class FactionsBlockListener implements Listener { @EventHandler public void onHopperPlace(BlockPlaceEvent e) { - if (e.getItemInHand().getType() != Material.HOPPER && !P.p.getConfig().getBoolean("fvault.No-Hoppers-near-vault")) { + if (e.getItemInHand().getType() != Material.HOPPER && !FactionsPlugin.getInstance().getConfig().getBoolean("fvault.No-Hoppers-near-vault")) { return; } @@ -310,7 +310,7 @@ public class FactionsBlockListener implements Listener { Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(targetLoc)); // Check if the piston is moving in a faction's territory. This disables pistons entirely in faction territory. - if (otherFaction.isNormal() && P.p.getConfig().getBoolean("disable-pistons-in-territory", false)) { + if (otherFaction.isNormal() && FactionsPlugin.getInstance().getConfig().getBoolean("disable-pistons-in-territory", false)) { event.setCancelled(true); return; } @@ -329,88 +329,86 @@ public class FactionsBlockListener implements Listener { @EventHandler public void onBannerPlace(BlockPlaceEvent e) { - if (P.p.mc17) { + if (FactionsPlugin.getInstance().mc17) { return; } - - if (e.getItemInHand().getType() == XMaterial.BLACK_BANNER.parseMaterial()) { + if (e.getItemInHand().getType().name().contains("BANNER")) { ItemStack bannerInHand = e.getItemInHand(); FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); ItemStack warBanner = fme.getFaction().getBanner(); - if (warBanner != null) { - ItemMeta warmeta = warBanner.getItemMeta(); - warmeta.setDisplayName(P.p.color(P.p.getConfig().getString("fbanners.Item.Name"))); - warmeta.setLore(P.p.colorList(P.p.getConfig().getStringList("fbanners.Item.Lore"))); - warBanner.setItemMeta(warmeta); - } else { - warBanner = P.p.createItem(XMaterial.BLACK_BANNER.parseMaterial(), 1, (short) 1, P.p.getConfig().getString("fbanners.Item.Name"), P.p.getConfig().getStringList("fbanners.Item.Lore")); + if (warBanner == null) { + return; } + ItemMeta warmeta = warBanner.getItemMeta(); + warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"))); + warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore"))); + warBanner.setItemMeta(warmeta); if (warBanner.isSimilar(bannerInHand)) { if (fme.getFaction().isWilderness()) { fme.msg(TL.WARBANNER_NOFACTION); e.setCancelled(true); return; } - int bannerTime = P.p.getConfig().getInt("fbanners.Banner-Time") * 20; - + int bannerTime = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Time") * 20; Location placedLoc = e.getBlockPlaced().getLocation(); FLocation fplacedLoc = new FLocation(placedLoc); - if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && P.p.getConfig().getBoolean("fbanners.Placeable.Warzone")) - || (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY) && P.p.getConfig().getBoolean("fbanners.Placeable.Enemy")) { + if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Warzone")) || (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Enemy"))) { if (bannerCooldownMap.containsKey(fme.getTag())) { fme.msg(TL.WARBANNER_COOLDOWN); e.setCancelled(true); return; } for (FPlayer fplayer : fme.getFaction().getFPlayers()) { - // if (fplayer == fme) { continue; } //Idk if I wanna not send the title to the player - fplayer.getPlayer().sendTitle(P.p.color(fme.getTag() + " Placed A WarBanner!"), P.p.color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20); + if (XMaterial.isVersionOrHigher(XMaterial.MinecraftVersion.VERSION_1_9)) { + fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20); + } else { + fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!")); + } } - bannerCooldownMap.put(fme.getTag(), true); - bannerLocations.put(fme.getTag(), e.getBlockPlaced().getLocation()); - int bannerCooldown = P.p.getConfig().getInt("fbanners.Banner-Place-Cooldown"); - ArmorStand as = (ArmorStand) e.getBlockPlaced().getLocation().add(0.5, 1, 0.5).getWorld().spawnEntity(e.getBlockPlaced().getLocation().add(0.5, 1, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand - as.setVisible(false); //Makes the ArmorStand invisible - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName(P.p.color(P.p.getConfig().getString("fbanners.BannerHolo").replace("{Faction}", fme.getTag()))); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + FactionsBlockListener.bannerLocations.put(fme.getTag(), e.getBlockPlaced().getLocation()); + int bannerCooldown = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Place-Cooldown"); + ArmorStand as = (ArmorStand) e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5).getWorld().spawnEntity(e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5), EntityType.ARMOR_STAND); + as.setVisible(false); + as.setGravity(false); + as.setCanPickupItems(false); + as.setCustomName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.BannerHolo").replace("{Faction}", fme.getTag()))); + as.setCustomNameVisible(true); String tag = fme.getTag(); - Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + "")); + Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + "")); Block banner = e.getBlockPlaced(); Material bannerType = banner.getType(); Faction bannerFaction = fme.getFaction(); banner.getWorld().strikeLightningEffect(banner.getLocation()); - // e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ENTITY_LIGHTNING_IMPACT,2.0F,0.5F); - int radius = P.p.getConfig().getInt("fbanners.Banner-Effect-Radius"); - List effects = P.p.getConfig().getStringList("fbanners.Effects"); - int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { - for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), radius, 255, radius)) { + int radius = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Effect-Radius"); + List effects = FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Effects"); + int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { + for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), (double) radius, 255.0, (double) radius)) { if (e1 instanceof Player) { Player player = (Player) e1; FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); - if (fplayer.getFaction() == bannerFaction) { - for (String effect : effects) { - String[] components = effect.split(":"); - player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1]))); - } - ParticleEffect.LAVA.display(1, 1, 1, 1, 10, banner.getLocation(), 16); - ParticleEffect.FLAME.display(1, 1, 1, 1, 10, banner.getLocation(), 16); - - if (banner.getType() != bannerType) { - banner.setType(bannerType); - } + if (fplayer.getFaction() != bannerFaction) { + continue; } + for (String effect : effects) { + String[] components = effect.split(":"); + player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1]))); + } + ParticleEffect.LAVA.display(1.0f, 1.0f, 1.0f, 1.0f, 10, banner.getLocation(), 16.0); + ParticleEffect.FLAME.display(1.0f, 1.0f, 1.0f, 1.0f, 10, banner.getLocation(), 16.0); + if (banner.getType() == bannerType) { + continue; + } + banner.setType(bannerType); } } }, 0L, 20L); - Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> { + Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> { banner.setType(Material.AIR); as.remove(); banner.getWorld().strikeLightningEffect(banner.getLocation()); Bukkit.getScheduler().cancelTask(affectorTask); - bannerLocations.remove(bannerFaction.getTag()); + FactionsBlockListener.bannerLocations.remove(bannerFaction.getTag()); }, Long.parseLong(bannerTime + "")); } else { fme.msg(TL.WARBANNER_INVALIDLOC); @@ -444,7 +442,7 @@ public class FactionsBlockListener implements Listener { @EventHandler public void onFallingBlock(EntityChangeBlockEvent event) { - if (!P.p.getConfig().getBoolean("Falling-Block-Fix.Enabled")) + if (!FactionsPlugin.getInstance().getConfig().getBoolean("Falling-Block-Fix.Enabled")) return; Faction faction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); @@ -457,7 +455,7 @@ public class FactionsBlockListener implements Listener { //Grace @EventHandler public void onBreak(EntityExplodeEvent e) { - if (!P.p.getConfig().getBoolean("f-grace.Enabled")) + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) return; if (!graceisEnabled()) { @@ -467,7 +465,7 @@ public class FactionsBlockListener implements Listener { @EventHandler public void entityDamage(EntityDamageEvent e) { - if (!P.p.getConfig().getBoolean("f-grace.Enabled")) + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) return; if (!graceisEnabled()) { @@ -482,7 +480,7 @@ public class FactionsBlockListener implements Listener { @EventHandler public void onTNTPlace(BlockPlaceEvent e1) { FPlayer fp = FPlayers.getInstance().getByPlayer(e1.getPlayer()); - if (!P.p.getConfig().getBoolean("f-grace.Enabled")) + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) return; if (!graceisEnabled() && !fp.isAdminBypassing()) { diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java index 8a25f56f..4b8227cb 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java @@ -180,9 +180,9 @@ public class FactionsChatListener implements Listener { listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg)); } catch (UnknownFormatConversionException ex) { Conf.chatTagInsertIndex = 0; - P.p.log(Level.SEVERE, "Critical error in chat message formatting!"); - P.p.log(Level.SEVERE, "NOTE: This has been automatically fixed right now by setting chatTagInsertIndex to 0."); - P.p.log(Level.SEVERE, "For a more proper fix, please read this regarding chat configuration: http://massivecraft.com/plugins/factions/config#Chat_configuration"); + FactionsPlugin.getInstance().log(Level.SEVERE, "Critical error in chat message formatting!"); + FactionsPlugin.getInstance().log(Level.SEVERE, "NOTE: This has been automatically fixed right now by setting chatTagInsertIndex to 0."); + FactionsPlugin.getInstance().log(Level.SEVERE, "For a more proper fix, please read this regarding chat configuration: http://massivecraft.com/plugins/factions/config#Chat_configuration"); return; } } @@ -202,7 +202,7 @@ public class FactionsChatListener implements Listener { player.teleport(fme.getFaction().getWarp(warp).getLocation()); fme.msg(TL.COMMAND_FWARP_WARPED, warp); } - }, P.p.getConfig().getLong("warmups.f-warp", 0)); + }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-warp", 0)); } } \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java index e1d709ed..1d8daa28 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -226,9 +226,9 @@ public class FactionsEntityListener implements Listener { return; } UUID uuid = player.getUniqueId(); - if (P.p.getStuckMap().containsKey(uuid)) { + if (FactionsPlugin.getInstance().getStuckMap().containsKey(uuid)) { FPlayers.getInstance().getByPlayer(player).msg(TL.COMMAND_STUCK_CANCELLED); - P.p.getStuckMap().remove(uuid); + FactionsPlugin.getInstance().getStuckMap().remove(uuid); } } @@ -644,7 +644,7 @@ public class FactionsEntityListener implements Listener { @EventHandler public void onTravel(PlayerPortalEvent event) { - if (!P.p.getConfig().getBoolean("portals.limit", false)) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("portals.limit", false)) { return; // Don't do anything if they don't want us to. } @@ -663,7 +663,7 @@ public class FactionsEntityListener implements Listener { } FPlayer fp = FPlayers.getInstance().getByPlayer(event.getPlayer()); - String mininumRelation = P.p.getConfig().getString("portals.minimum-relation", "MEMBER"); // Defaults to Neutral if typed wrong. + 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); } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsExploitListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsExploitListener.java index 30081750..7804cc73 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsExploitListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsExploitListener.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.listeners; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.XMaterial; import org.bukkit.Location; import org.bukkit.Material; @@ -30,7 +30,7 @@ public class FactionsExploitListener implements Listener { Block block = event.getToBlock(); // Added this so it wont die on 1.14 :) - if (P.p.mc114) { + if (FactionsPlugin.getInstance().mc114) { Material source = event.getBlock().getType(); Material target = block.getType(); if ((target == Material.REDSTONE_WIRE || target == Material.TRIPWIRE) && (source == Material.AIR || source == Material.LEGACY_STATIONARY_LAVA || source == Material.LEGACY_LAVA)) { diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 8e3a07bf..047b03f4 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -55,10 +55,10 @@ public class FactionsPlayerListener implements Listener { public FactionsPlayerListener() { this.corners = new HashSet<>(); - for (Player player : P.p.getServer().getOnlinePlayers()) { + for (Player player : FactionsPlugin.getInstance().getServer().getOnlinePlayers()) { initPlayer(player); } - for (World world : P.p.getServer().getWorlds()) { + for (World world : FactionsPlugin.getInstance().getServer().getWorlds()) { WorldBorder border = world.getWorldBorder(); if (border != null) { int cornerCoord = (int) ((border.getSize() - 1.0) / 2.0); @@ -103,7 +103,7 @@ public class FactionsPlayerListener implements Listener { if (me.getFaction() == otherFaction) return true; - if (P.p.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) { return true; } @@ -185,7 +185,7 @@ public class FactionsPlayerListener implements Listener { return false; } - if (P.p.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) + if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) return true; if (otherFaction.getId().equals(myFaction.getId()) && me.getRole() == Role.LEADER) return true; @@ -345,7 +345,7 @@ public class FactionsPlayerListener implements Listener { return PermissableAction.DOOR; if (material.name().toUpperCase().contains("BUTTON") || material.name().toUpperCase().contains("PRESSURE")) return PermissableAction.BUTTON; - if (P.p.mc113) { + if (FactionsPlugin.getInstance().mc113) { switch (material) { case LEVER: return PermissableAction.LEVER; @@ -477,15 +477,15 @@ public class FactionsPlayerListener implements Listener { me.login(); // set kills / deaths // Check for Faction announcements. Let's delay this so they actually see it. - Bukkit.getScheduler().runTaskLater(P.p, () -> { + Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> { if (me.isOnline()) { me.getFaction().sendUnreadAnnouncements(me); } }, 33L); // Don't ask me why. - if (P.p.getConfig().getBoolean("scoreboard.default-enabled", false)) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-enabled", false)) { FScoreboard.init(me); - FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar(), P.p.getConfig().getInt("scoreboard.default-update-interval", 20)); + FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar(), FactionsPlugin.getInstance().getConfig().getInt("scoreboard.default-update-interval", 20)); FScoreboard.get(me).setSidebarVisibility(me.showScoreboard()); } @@ -500,17 +500,17 @@ public class FactionsPlayerListener implements Listener { fallMap.put(me.getPlayer(), false); - Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> fallMap.remove(me.getPlayer()), 180L); + Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> fallMap.remove(me.getPlayer()), 180L); if (me.isSpyingChat() && !player.hasPermission(Permission.CHATSPY.node)) { me.setSpyingChat(false); - P.p.log(Level.INFO, "Found %s spying chat without permission on login. Disabled their chat spying.", player.getName()); + FactionsPlugin.getInstance().log(Level.INFO, "Found %s spying chat without permission on login. Disabled their chat spying.", player.getName()); } if (me.isAdminBypassing() && !player.hasPermission(Permission.BYPASS.node)) { me.setIsAdminBypassing(false); - P.p.log(Level.INFO, "Found %s on admin Bypass without permission on login. Disabled it for them.", player.getName()); + FactionsPlugin.getInstance().log(Level.INFO, "Found %s on admin Bypass without permission on login. Disabled it for them.", player.getName()); } @@ -544,10 +544,10 @@ public class FactionsPlayerListener implements Listener { me.logout(); // cache kills / deaths // if player is waiting for fstuck teleport but leaves, remove - if (P.p.getStuckMap().containsKey(me.getPlayer().getUniqueId())) { + if (FactionsPlugin.getInstance().getStuckMap().containsKey(me.getPlayer().getUniqueId())) { FPlayers.getInstance().getByPlayer(me.getPlayer()).msg(TL.COMMAND_STUCK_CANCELLED); - P.p.getStuckMap().remove(me.getPlayer().getUniqueId()); - P.p.getTimers().remove(me.getPlayer().getUniqueId()); + FactionsPlugin.getInstance().getStuckMap().remove(me.getPlayer().getUniqueId()); + FactionsPlugin.getInstance().getTimers().remove(me.getPlayer().getUniqueId()); } Faction myFaction = me.getFaction(); @@ -584,11 +584,11 @@ public class FactionsPlayerListener implements Listener { public void enableFly(FPlayer me) { if (!me.getPlayer().hasPermission("factions.fly")) return; - if (P.p.getConfig().getBoolean("ffly.AutoEnable")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("ffly.AutoEnable")) { me.setFlying(true); CmdFly.flyMap.put(me.getName(), true); if (CmdFly.id == -1) { - if (P.p.getConfig().getBoolean("ffly.Particles.Enabled")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("ffly.Particles.Enabled")) { CmdFly.startParticles(); } } @@ -702,25 +702,25 @@ public class FactionsPlayerListener implements Listener { if (changedFaction) { Bukkit.getServer().getPluginManager().callEvent(new FPlayerEnteredFactionEvent(factionTo, factionFrom, me)); - if (P.p.getConfig().getBoolean("Title.Show-Title")) { - String title = P.p.getConfig().getString("Title.Format.Title"); + if (FactionsPlugin.getInstance().getConfig().getBoolean("Title.Show-Title")) { + String title = FactionsPlugin.getInstance().getConfig().getString("Title.Format.Title"); title = title.replace("{Faction}", factionTo.getColorTo(me) + factionTo.getTag()); title = parseAllPlaceholders(title, factionTo, player); - String subTitle = P.p.getConfig().getString("Title.Format.Subtitle").replace("{Description}", factionTo.getDescription()).replace("{Faction}", factionTo.getColorTo(me) + factionTo.getTag()); + String subTitle = FactionsPlugin.getInstance().getConfig().getString("Title.Format.Subtitle").replace("{Description}", factionTo.getDescription()).replace("{Faction}", factionTo.getColorTo(me) + factionTo.getTag()); subTitle = parseAllPlaceholders(subTitle, factionTo, player); - if (!P.p.mc17) { - if (!P.p.mc18) { - me.getPlayer().sendTitle(P.p.color(title), P.p.color(subTitle), P.p.getConfig().getInt("Title.Options.FadeInTime"), - P.p.getConfig().getInt("Title.Options.ShowTime"), - P.p.getConfig().getInt("Title.Options.FadeOutTime")); + if (!FactionsPlugin.getInstance().mc17) { + if (!FactionsPlugin.getInstance().mc18) { + me.getPlayer().sendTitle(FactionsPlugin.getInstance().color(title), FactionsPlugin.getInstance().color(subTitle), FactionsPlugin.getInstance().getConfig().getInt("Title.Options.FadeInTime"), + FactionsPlugin.getInstance().getConfig().getInt("Title.Options.ShowTime"), + FactionsPlugin.getInstance().getConfig().getInt("Title.Options.FadeOutTime")); } else { - me.getPlayer().sendTitle(P.p.color(title), P.p.color(subTitle)); + me.getPlayer().sendTitle(FactionsPlugin.getInstance().color(title), FactionsPlugin.getInstance().color(subTitle)); } } } // enable fly :) - if (P.p.factionsFlight && me.hasFaction() && !me.isFlying()) { + if (FactionsPlugin.getInstance().factionsFlight && me.hasFaction() && !me.isFlying()) { if (factionTo == me.getFaction()) enableFly(me); // bypass checks Relation relationTo = factionTo.getRelationTo(me); @@ -761,12 +761,12 @@ public class FactionsPlayerListener implements Listener { if (me.isMapAutoUpdating()) { if (showTimes.containsKey(player.getUniqueId()) && (showTimes.get(player.getUniqueId()) > System.currentTimeMillis())) { - if (P.p.getConfig().getBoolean("findfactionsexploit.log", false)) { - P.p.log(Level.WARNING, "%s tried to show a faction map too soon and triggered exploit blocker.", player.getName()); + if (FactionsPlugin.getInstance().getConfig().getBoolean("findfactionsexploit.log", false)) { + FactionsPlugin.getInstance().log(Level.WARNING, "%s tried to show a faction map too soon and triggered exploit blocker.", player.getName()); } } else { me.sendFancyMessage(Board.getInstance().getMap(me, to, player.getLocation().getYaw())); - showTimes.put(player.getUniqueId(), System.currentTimeMillis() + P.p.getConfig().getLong("findfactionsexploit.cooldown", 2000)); + showTimes.put(player.getUniqueId(), System.currentTimeMillis() + FactionsPlugin.getInstance().getConfig().getLong("findfactionsexploit.cooldown", 2000)); } } else { Faction myFaction = me.getFaction(); diff --git a/src/main/java/com/massivecraft/factions/missions/CmdMissions.java b/src/main/java/com/massivecraft/factions/missions/CmdMissions.java index 1513e63a..6b816121 100644 --- a/src/main/java/com/massivecraft/factions/missions/CmdMissions.java +++ b/src/main/java/com/massivecraft/factions/missions/CmdMissions.java @@ -1,5 +1,8 @@ package com.massivecraft.factions.missions; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; @@ -12,28 +15,24 @@ public class CmdMissions extends FCommand { this.aliases.add("objectives"); this.aliases.add("objective"); - this.permission = Permission.MISSIONS.node; - - this.disableOnLock = true; - this.disableOnSpam = true; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.MISSIONS) + .memberOnly() + .playerOnly() + .build(); } @Override - public void perform() { - if (myFaction == null) { + public void perform(CommandContext context) { + if (context.faction == null) { return; } - final MissionGUI missionsGUI = new MissionGUI(p, fme); + final MissionGUI missionsGUI = new MissionGUI(FactionsPlugin.getInstance(), context.fPlayer); missionsGUI.build(); - fme.getPlayer().openInventory(missionsGUI.getInventory()); + context.player.openInventory(missionsGUI.getInventory()); } + @Override public TL getUsageTranslation() { return TL.COMMAND_MISSION_DESCRIPTION; diff --git a/src/main/java/com/massivecraft/factions/missions/MissionGUI.java b/src/main/java/com/massivecraft/factions/missions/MissionGUI.java index fde9db12..3e5163a6 100644 --- a/src/main/java/com/massivecraft/factions/missions/MissionGUI.java +++ b/src/main/java/com/massivecraft/factions/missions/MissionGUI.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.missions; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.FactionGUI; import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.zcore.util.TL; @@ -20,12 +20,12 @@ import java.util.List; import java.util.Map; public class MissionGUI implements FactionGUI { - private P plugin; + private FactionsPlugin plugin; private FPlayer fPlayer; private Inventory inventory; private Map slots; - public MissionGUI(P plugin, FPlayer fPlayer) { + public MissionGUI(FactionsPlugin plugin, FPlayer fPlayer) { this.slots = new HashMap<>(); this.plugin = plugin; this.fPlayer = fPlayer; diff --git a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java index 771e3c61..cc8d348f 100644 --- a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java +++ b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.missions; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.EventHandler; @@ -19,9 +19,9 @@ import java.util.stream.Collectors; public class MissionHandler implements Listener { - private P plugin; + private FactionsPlugin plugin; - public MissionHandler(P plugin) { + public MissionHandler(FactionsPlugin plugin) { this.plugin = plugin; } @@ -121,7 +121,7 @@ public class MissionHandler implements Listener { return; } for (String command : section.getConfigurationSection("Reward").getStringList("Commands")) { - P.p.getServer().dispatchCommand(P.p.getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag())); + FactionsPlugin.getInstance().getServer().dispatchCommand(FactionsPlugin.getInstance().getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag())); } fPlayer.getFaction().getMissions().remove(mission.getName()); fPlayer.getFaction().msg(TL.MISSION_MISSION_FINISHED, plugin.color(section.getString("Name"))); diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java b/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java index 2225137a..58c5d269 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.scoreboards; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -109,7 +109,7 @@ public class FScoreboard { updateObjective(); } } - }.runTaskTimer(P.p, updateInterval, updateInterval); + }.runTaskTimer(FactionsPlugin.getInstance(), updateInterval, updateInterval); } public void setTemporarySidebar(final FSidebarProvider provider) { @@ -132,7 +132,7 @@ public class FScoreboard { updateObjective(); } } - }.runTaskLater(P.p, P.p.getConfig().getInt("scoreboard.expiration", 7) * 20); + }.runTaskLater(FactionsPlugin.getInstance(), FactionsPlugin.getInstance().getConfig().getInt("scoreboard.expiration", 7) * 20); } private void updateObjective() { diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FSidebarProvider.java b/src/main/java/com/massivecraft/factions/scoreboards/FSidebarProvider.java index 1a71af86..720df2ac 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FSidebarProvider.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FSidebarProvider.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.scoreboards; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TagUtil; @@ -37,6 +37,6 @@ public abstract class FSidebarProvider { // we assume it's broken up into two lines, so returning our tl will suffice. return TL.COMMAND_SHOW_NOHOME.toString(); } - return P.p.txt.parse(line); // finally add color :) + return FactionsPlugin.getInstance().txt.parse(line); // finally add color :) } } \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java b/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java index 8cde29fa..c91501b0 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java @@ -39,13 +39,13 @@ public class FTeamWrapper { return; } - if (!P.p.getConfig().getBoolean("scoreboard.default-prefixes", false) || P.p.getConfig().getBoolean("See-Invisible-Faction-Members")) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false) || FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members")) { return; } if (updating.add(faction)) { - Bukkit.getScheduler().runTask(P.p, () -> { + Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> { updating.remove(faction); applyUpdates(faction); }); @@ -61,7 +61,7 @@ public class FTeamWrapper { return; } - if (!P.p.getConfig().getBoolean("scoreboard.default-prefixes", false) || P.p.getConfig().getBoolean("See-Invisible-Faction-Members")) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false) || FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members")) { return; } @@ -153,7 +153,7 @@ public class FTeamWrapper { } private void updatePrefixes() { - if (P.p.getConfig().getBoolean("scoreboard.default-prefixes", false)) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) { for (FScoreboard fboard : teams.keySet()) { updatePrefix(fboard); } @@ -161,19 +161,19 @@ public class FTeamWrapper { } private void updatePrefix(FScoreboard fboard) { - if (P.p.getConfig().getBoolean("scoreboard.default-prefixes", false)) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) { FPlayer fplayer = fboard.getFPlayer(); Team team = teams.get(fboard); boolean focused = false; - if (P.p.getConfig().getBoolean("See-Invisible-Faction-Members", false)) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members", false)) { team.setCanSeeFriendlyInvisibles(true); } - if ((P.p.getConfig().getBoolean("ffocus.Enabled")) && (fplayer.getFaction() != null) && (fplayer.getFaction().getFocused() != null)) { + 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('&', P.p.getConfig().getString("ffocus.Prefix", "&7»&b"))); + team.setPrefix(ChatColor.translateAlternateColorCodes('&', FactionsPlugin.getInstance().getConfig().getString("ffocus.Prefix", "&7»&b"))); focused = true; } } diff --git a/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FDefaultSidebar.java b/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FDefaultSidebar.java index 55e16938..40903582 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FDefaultSidebar.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FDefaultSidebar.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.scoreboards.sidebar; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.scoreboards.FSidebarProvider; import java.util.ArrayList; @@ -12,21 +12,21 @@ public class FDefaultSidebar extends FSidebarProvider { @Override public String getTitle(FPlayer fplayer) { - return replaceTags(fplayer, P.p.getConfig().getString("scoreboard.default-title", "{name}")); + return replaceTags(fplayer, FactionsPlugin.getInstance().getConfig().getString("scoreboard.default-title", "{name}")); } @Override public List getLines(FPlayer fplayer) { if (fplayer.hasFaction()) { return getOutput(fplayer, "scoreboard.default"); - } else if (P.p.getConfig().getBoolean("scoreboard.factionless-enabled", false)) { + } else if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.factionless-enabled", false)) { return getOutput(fplayer, "scoreboard.factionless"); } return getOutput(fplayer, "scoreboard.default"); // no faction, factionless-board disabled } public List getOutput(FPlayer fplayer, String list) { - List lines = P.p.getConfig().getStringList(list); + List lines = FactionsPlugin.getInstance().getConfig().getStringList(list); if (lines == null || lines.isEmpty()) { return new ArrayList<>(); diff --git a/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FInfoSidebar.java b/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FInfoSidebar.java index d3752728..56ccbb5f 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FInfoSidebar.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FInfoSidebar.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.scoreboards.sidebar; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.scoreboards.FSidebarProvider; import java.util.List; @@ -22,7 +22,7 @@ public class FInfoSidebar extends FSidebarProvider { @Override public List getLines(FPlayer fplayer) { - List lines = P.p.getConfig().getStringList("scoreboard.finfo"); + List lines = FactionsPlugin.getInstance().getConfig().getStringList("scoreboard.finfo"); ListIterator it = lines.listIterator(); while (it.hasNext()) { diff --git a/src/main/java/com/massivecraft/factions/shop/CmdShop.java b/src/main/java/com/massivecraft/factions/shop/CmdShop.java index 3010502b..a795308d 100644 --- a/src/main/java/com/massivecraft/factions/shop/CmdShop.java +++ b/src/main/java/com/massivecraft/factions/shop/CmdShop.java @@ -1,7 +1,10 @@ package com.massivecraft.factions.shop; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; import com.massivecraft.factions.cmd.FCommand; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; public class CmdShop extends FCommand { @@ -9,22 +12,19 @@ public class CmdShop extends FCommand { public CmdShop() { super(); this.aliases.add("shop"); - this.disableOnLock = false; - - senderMustBePlayer = true; - senderMustBeMember = true; - senderMustBeModerator = false; - senderMustBeColeader = false; - senderMustBeAdmin = false; + this.requirements = new CommandRequirements.Builder(Permission.SHOP) + .memberOnly() + .playerOnly() + .build(); } @Override - public void perform() { - if (!P.p.getConfig().getBoolean("F-Shop.Enabled")) { + public void perform(CommandContext context) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) { return; } - ShopGUI.openShop(fme); + ShopGUI.openShop(context.fPlayer); } @Override diff --git a/src/main/java/com/massivecraft/factions/shop/ShopClickPersistence.java b/src/main/java/com/massivecraft/factions/shop/ShopClickPersistence.java index 9f874e22..9387b0c9 100644 --- a/src/main/java/com/massivecraft/factions/shop/ShopClickPersistence.java +++ b/src/main/java/com/massivecraft/factions/shop/ShopClickPersistence.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.shop; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -41,7 +41,7 @@ public class ShopClickPersistence implements Listener { public void click(InventoryClickEvent e) { Inventory i = e.getClickedInventory(); Player p = (Player) e.getWhoClicked(); - FileConfiguration config = P.p.getConfig(); + FileConfiguration config = FactionsPlugin.getInstance().getConfig(); FPlayer fplayer = FPlayers.getInstance().getByPlayer(p); if (e.getView().getTitle().equalsIgnoreCase(color(config.getString("F-Shop.GUI.Name")))) { diff --git a/src/main/java/com/massivecraft/factions/shop/ShopGUI.java b/src/main/java/com/massivecraft/factions/shop/ShopGUI.java index 449427e7..d5db5891 100644 --- a/src/main/java/com/massivecraft/factions/shop/ShopGUI.java +++ b/src/main/java/com/massivecraft/factions/shop/ShopGUI.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.shop; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.XMaterial; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -23,16 +23,16 @@ public class ShopGUI { */ public static void openShop(FPlayer p) { - FileConfiguration config = P.p.getConfig(); + FileConfiguration config = FactionsPlugin.getInstance().getConfig(); Faction fac = p.getFaction(); - Inventory i = Bukkit.createInventory(null, P.p.getConfig().getInt("F-Shop.GUI.Size"), color(config.getString("F-Shop.GUI.Name"))); + Inventory i = Bukkit.createInventory(null, FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Size"), color(config.getString("F-Shop.GUI.Name"))); ItemStack glass = new ItemStack(XMaterial.BLACK_STAINED_GLASS_PANE.parseMaterial(), 1, (short) 7); ItemMeta glassmeta = glass.getItemMeta(); glassmeta.setDisplayName(ChatColor.GOLD + " "); glass.setItemMeta(glassmeta); - for (int fill = 0; fill < P.p.getConfig().getInt("F-Shop.GUI.Size"); ++fill) { + for (int fill = 0; fill < FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Size"); ++fill) { i.setItem(fill, glass); } @@ -59,7 +59,7 @@ public class ShopGUI { } countmeta.setLore(colorList(PointInfo)); count.setItemMeta(countmeta); - i.setItem(P.p.getConfig().getInt("F-Shop.GUI.Information.slot"), count); + i.setItem(FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Information.slot"), count); ItemStack item = new ItemStack(material); ItemMeta meta = item.getItemMeta(); @@ -77,7 +77,7 @@ public class ShopGUI { if (lore.contains("")) { meta.setLore(null); } else { - meta.setLore(P.p.colorList(lore)); + meta.setLore(FactionsPlugin.getInstance().colorList(lore)); } item.setItemMeta(meta); i.setItem(slot, item); diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index b27c07ad..45a6a97d 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.struct; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.command.CommandSender; public enum Permission { @@ -35,6 +35,7 @@ public enum Permission { DISBAND_ANY("disband.any"), FLY("fly"), FOCUS("focus"), + GLOBALCHAT("globalchat"), GRACE("grace"), HELP("help"), HOME("home"), @@ -66,6 +67,7 @@ public enum Permission { MONEY_F2P("money.f2p"), MONEY_P2F("money.p2f"), MONITOR_LOGINS("monitorlogins"), + NEAR("near"), NO_BOOM("noboom"), OPEN("open"), OWNER("owner"), @@ -77,6 +79,7 @@ public enum Permission { PAYPAL("paypal"), PAYPALSET("setpaypal"), PERMISSIONS("permissions"), + POINTS("points"), POWERBOOST("powerboost"), POWER("power"), POWER_ANY("power.any"), @@ -103,6 +106,7 @@ public enum Permission { SCOREBOARD("scoreboard"), SEECHUNK("seechunk"), SETWARP("setwarp"), + SHOP("shop"), TOP("top"), VIEWCHEST("viewchest"), ADDPOINTS("addpoints"), @@ -131,7 +135,7 @@ public enum Permission { } public boolean has(CommandSender sender, boolean informSenderIfNot) { - return P.p.perm.has(sender, this.node, informSenderIfNot); + return FactionsPlugin.getInstance().perm.has(sender, this.node, informSenderIfNot); } public boolean has(CommandSender sender) { diff --git a/src/main/java/com/massivecraft/factions/struct/Relation.java b/src/main/java/com/massivecraft/factions/struct/Relation.java index 10d81048..7f32cb04 100644 --- a/src/main/java/com/massivecraft/factions/struct/Relation.java +++ b/src/main/java/com/massivecraft/factions/struct/Relation.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.struct; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.util.TL; @@ -199,7 +199,7 @@ public enum Relation implements Permissable { // Utility method to build items for F Perm GUI @Override public ItemStack buildItem() { - final ConfigurationSection RELATION_CONFIG = P.p.getConfig().getConfigurationSection("fperm-gui.relation"); + final ConfigurationSection RELATION_CONFIG = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.relation"); String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", "")); List lore = new ArrayList<>(); diff --git a/src/main/java/com/massivecraft/factions/struct/Role.java b/src/main/java/com/massivecraft/factions/struct/Role.java index 45048fc3..cbf33bde 100644 --- a/src/main/java/com/massivecraft/factions/struct/Role.java +++ b/src/main/java/com/massivecraft/factions/struct/Role.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.struct; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.util.TL; @@ -113,7 +113,7 @@ public enum Role implements Permissable { // Utility method to build items for F Perm GUI @Override public ItemStack buildItem() { - final ConfigurationSection RELATION_CONFIG = P.p.getConfig().getConfigurationSection("fperm-gui.relation"); + final ConfigurationSection RELATION_CONFIG = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.relation"); String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", "")); List lore = new ArrayList<>(); @@ -132,7 +132,7 @@ public enum Role implements Permissable { itemMeta.setDisplayName(displayName); itemMeta.setLore(lore); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); } diff --git a/src/main/java/com/massivecraft/factions/tag/FactionTag.java b/src/main/java/com/massivecraft/factions/tag/FactionTag.java new file mode 100644 index 00000000..1224444e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/tag/FactionTag.java @@ -0,0 +1,135 @@ +package com.massivecraft.factions.tag; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.zcore.util.TL; + +import java.util.function.BiFunction; +import java.util.function.Function; + +public enum FactionTag implements Tag { + 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) -> { + 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) -> { + 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())), + 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) -> { + 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(); + if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.dtr", false)) { + int dtr = raidable ? 0 : (int) Math.ceil(((double) (fac.getPowerRounded() - fac.getLandRounded())) / Conf.powerPerDeath); + str += ' ' + TL.COMMAND_SHOW_DEATHS_TIL_RAIDABLE.format(dtr); + } + return str; + } + return null; + }), + 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) -> { + 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"); + }), + 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()); + } else { + // Only console should ever get here. + return String.valueOf(fac.getFPlayersWhereOnline(true).size()); + } + }), + OFFLINE_COUNT("{offline}", (fac) -> String.valueOf(fac.getFPlayers().size() - fac.getOnlinePlayers().size())), + 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; + private final BiFunction biFunction; + private final Function function; + + FactionTag(String tag, BiFunction function) { + this.tag = tag; + this.biFunction = function; + this.function = null; + } + + FactionTag(String tag, Function function) { + this.tag = tag; + this.biFunction = null; + this.function = function; + } + + public static String parse(String text, Faction faction, FPlayer player) { + for (FactionTag tag : FactionTag.values()) { + text = tag.replace(text, faction, player); + } + return text; + } + + public static String parse(String text, Faction faction) { + for (FactionTag tag : FactionTag.values()) { + text = tag.replace(text, faction); + } + return text; + } + + @Override + public String getTag() { + return this.tag; + } + + @Override + public boolean foundInString(String test) { + return test != null && test.contains(this.tag); + } + + public String replace(String text, Faction faction, FPlayer player) { + if (!this.foundInString(text)) { + return text; + } + if (this.biFunction == null) { + return this.replace(text, faction); + } + String result = this.biFunction.apply(faction, player); + return result == null ? null : text.replace(this.tag, result); + } + + public String replace(String text, Faction faction) { + if (this.function == null || !this.foundInString(text)) { + return text; + } + String result = this.function.apply(faction); + return result == null ? null : text.replace(this.tag, result); + } +} diff --git a/src/main/java/com/massivecraft/factions/tag/FancyTag.java b/src/main/java/com/massivecraft/factions/tag/FancyTag.java new file mode 100644 index 00000000..49e6beaf --- /dev/null +++ b/src/main/java/com/massivecraft/factions/tag/FancyTag.java @@ -0,0 +1,178 @@ +package com.massivecraft.factions.tag; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.util.MiscUtil; +import com.massivecraft.factions.util.QuadFunction; +import mkremins.fanciful.FancyMessage; +import org.bukkit.ChatColor; + +import java.util.*; + +public enum FancyTag implements Tag { + ALLIES_LIST("{allies-list}", (target, fme, prefix, gm) -> processRelation(prefix, target, fme, Relation.ALLY)), + ENEMIES_LIST("{enemies-list}", (target, fme, prefix, gm) -> processRelation(prefix, target, fme, Relation.ENEMY)), + TRUCES_LIST("{truces-list}", (target, fme, prefix, gm) -> processRelation(prefix, target, fme, Relation.TRUCE)), + ONLINE_LIST("{online-list}", (target, fme, prefix, gm) -> { + List fancyMessages = new ArrayList<>(); + FancyMessage currentOnline = FactionsPlugin.getInstance().txt.parseFancy(prefix); + boolean firstOnline = true; + for (FPlayer p : MiscUtil.rankOrder(target.getFPlayersWhereOnline(true, fme))) { + if (fme.getPlayer() != null && !fme.getPlayer().canSee(p.getPlayer())) { + continue; // skip + } + String name = p.getNameAndTitle(); + currentOnline.then(firstOnline ? name : ", " + name); + currentOnline.tooltip(tipPlayer(p, gm)).color(fme.getColorTo(p)); + firstOnline = false; + if (currentOnline.toJSONString().length() > ARBITRARY_LIMIT) { + fancyMessages.add(currentOnline); + currentOnline = new FancyMessage(""); + } + } + fancyMessages.add(currentOnline); + return firstOnline && Tag.isMinimalShow() ? null : fancyMessages; + }), + OFFLINE_LIST("{offline-list}", (target, fme, prefix, gm) -> { + List fancyMessages = new ArrayList<>(); + FancyMessage currentOffline = FactionsPlugin.getInstance().txt.parseFancy(prefix); + boolean firstOffline = true; + for (FPlayer p : MiscUtil.rankOrder(target.getFPlayers())) { + String name = p.getNameAndTitle(); + // Also make sure to add players that are online BUT can't be seen. + if (!p.isOnline() || (fme.getPlayer() != null && p.isOnline() && !fme.getPlayer().canSee(p.getPlayer()))) { + currentOffline.then(firstOffline ? name : ", " + name); + currentOffline.tooltip(tipPlayer(p, gm)).color(fme.getColorTo(p)); + firstOffline = false; + if (currentOffline.toJSONString().length() > ARBITRARY_LIMIT) { + fancyMessages.add(currentOffline); + currentOffline = new FancyMessage(""); + } + } + } + fancyMessages.add(currentOffline); + return firstOffline && Tag.isMinimalShow() ? null : fancyMessages; + }), + ; + + private final String tag; + private final QuadFunction, List> function; + + FancyTag(String tag, QuadFunction, List> function) { + this.tag = tag; + this.function = function; + } + + private static List processRelation(String prefix, Faction faction, FPlayer fPlayer, Relation relation) { + List fancyMessages = new ArrayList<>(); + FancyMessage message = FactionsPlugin.getInstance().txt.parseFancy(prefix); + boolean first = true; + for (Faction otherFaction : Factions.getInstance().getAllFactions()) { + if (otherFaction == faction) { + continue; + } + String s = otherFaction.getTag(fPlayer); + if (otherFaction.getRelationTo(faction) == relation) { + message.then(first ? s : ", " + s); + message.tooltip(tipFaction(otherFaction, fPlayer)).color(fPlayer.getColorTo(otherFaction)); + first = false; + if (message.toJSONString().length() > ARBITRARY_LIMIT) { + fancyMessages.add(message); + message = new FancyMessage(""); + } + } + } + fancyMessages.add(message); + return first && Tag.isMinimalShow() ? null : fancyMessages; + } + + public static List parse(String text, Faction faction, FPlayer player, Map groupMap) { + for (FancyTag tag : FancyTag.values()) { + if (tag.foundInString(text)) { + return tag.getMessage(text, faction, player, groupMap); + } + } + return Collections.EMPTY_LIST; // We really shouldn't be here. + } + + public static boolean anyMatch(String text) { + return getMatch(text) != null; + } + + public static FancyTag getMatch(String text) { + for (FancyTag tag : FancyTag.values()) { + if (tag.foundInString(text)) { + return tag; + } + } + return null; + } + + /** + * Parses tooltip variables from config
    Supports variables for factions only (type 2) + * + * @param faction faction to tooltip for + * @return list of tooltips for a fancy message + */ + private static List tipFaction(Faction faction, FPlayer player) { + List lines = new ArrayList<>(); + for (String line : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.list")) { + String string = Tag.parsePlain(faction, player, line); + if (string == null) { + continue; + } + lines.add(ChatColor.translateAlternateColorCodes('&', string)); + } + return lines; + } + + /** + * Parses tooltip variables from config
    Supports variables for players and factions (types 1 and 2) + * + * @param fplayer player to tooltip for + * @return list of tooltips for a fancy message + */ + private static List tipPlayer(FPlayer fplayer, Map groupMap) { + List lines = new ArrayList<>(); + for (String line : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.show")) { + String newLine = line; + everythingOnYourWayOut: + if (line.contains("{group}")) { + if (groupMap != null) { + String group = groupMap.get(UUID.fromString(fplayer.getId())); + if (!group.trim().isEmpty()) { + newLine = newLine.replace("{group}", group); + break everythingOnYourWayOut; + } + } + continue; + } + String string = Tag.parsePlain(fplayer, newLine); + if (string == null) { + continue; + } + lines.add(ChatColor.translateAlternateColorCodes('&', string)); + } + return lines; + } + + @Override + public String getTag() { + return this.tag; + } + + @Override + public boolean foundInString(String test) { + return test != null && test.contains(this.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 this.function.apply(faction, player, text.replace(this.getTag(), ""), groupMap); + } +} diff --git a/src/main/java/com/massivecraft/factions/tag/GeneralTag.java b/src/main/java/com/massivecraft/factions/tag/GeneralTag.java new file mode 100644 index 00000000..36d22286 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/tag/GeneralTag.java @@ -0,0 +1,58 @@ +package com.massivecraft.factions.tag; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.zcore.util.TL; +import org.bukkit.Bukkit; + +import java.util.function.Supplier; + +public enum GeneralTag implements Tag { + MAX_WARPS("{max-warps}", () -> String.valueOf(FactionsPlugin.getInstance().getConfig().getInt("max-warps", 5))), + MAX_ALLIES("{max-allies}", () -> getRelation("ally")), + MAX_ENEMIES("{max-enemies}", () -> getRelation("enemy")), + MAX_TRUCES("{max-truces}", () -> getRelation("truce")), + FACTIONLESS("{factionless}", () -> String.valueOf(Factions.getInstance().getNone().getFPlayersWhereOnline(true).size())), + TOTAL_ONLINE("{total-online}", () -> String.valueOf(Bukkit.getOnlinePlayers().size())), + ; + + private final String tag; + private final Supplier supplier; + + GeneralTag(String tag, Supplier supplier) { + this.tag = tag; + this.supplier = supplier; + } + + private static String getRelation(String relation) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("max-relations.enabled", true)) { + return String.valueOf(FactionsPlugin.getInstance().getConfig().getInt("max-relations." + relation, 10)); + } + return TL.GENERIC_INFINITY.toString(); + } + + public static String parse(String text) { + for (GeneralTag tag : GeneralTag.values()) { + text = tag.replace(text); + } + return text; + } + + @Override + public String getTag() { + return this.tag; + } + + @Override + public boolean foundInString(String test) { + return test != null && test.contains(this.tag); + } + + public String replace(String text) { + if (!this.foundInString(text)) { + return text; + } + String result = this.supplier.get(); + return result == null ? null : text.replace(this.tag, result); + } +} diff --git a/src/main/java/com/massivecraft/factions/tag/PlayerTag.java b/src/main/java/com/massivecraft/factions/tag/PlayerTag.java new file mode 100644 index 00000000..d51cca19 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/tag/PlayerTag.java @@ -0,0 +1,56 @@ +package com.massivecraft.factions.tag; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.zcore.util.TL; +import org.apache.commons.lang.time.DurationFormatUtils; +import org.bukkit.ChatColor; + +import java.util.function.Function; + +public enum PlayerTag implements Tag { + LAST_SEEN("{lastSeen}", (fp) -> { + String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX; + return fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized); + }), + PLAYER_BALANCE("{balance}", (fp) -> Econ.isSetup() ? Econ.getFriendlyBalance(fp) : (Tag.isMinimalShow() ? null : TL.ECON_OFF.format("balance"))), + PLAYER_POWER("{player-power}", (fp) -> String.valueOf(fp.getPowerRounded())), + PLAYER_MAXPOWER("{player-maxpower}", (fp) -> String.valueOf(fp.getPowerMaxRounded())), + PLAYER_KILLS("{player-kills}", (fp) -> String.valueOf(fp.getKills())), + PLAYER_DEATHS("{player-deaths}", (fp) -> String.valueOf(fp.getDeaths())), + PLAYER_NAME("{name}", FPlayer::getName), + ; + + private final String tag; + private final Function function; + + PlayerTag(String tag, Function function) { + this.tag = tag; + this.function = function; + } + + public static String parse(String text, FPlayer player) { + for (PlayerTag tag : PlayerTag.values()) { + text = tag.replace(text, player); + } + return text; + } + + @Override + public String getTag() { + return this.tag; + } + + @Override + public boolean foundInString(String test) { + return test != null && test.contains(this.tag); + } + + public String replace(String text, FPlayer player) { + if (!this.foundInString(text)) { + return text; + } + String result = this.function.apply(player); + return result == null ? null : text.replace(this.tag, result); + } +} diff --git a/src/main/java/com/massivecraft/factions/tag/Tag.java b/src/main/java/com/massivecraft/factions/tag/Tag.java new file mode 100644 index 00000000..39b573e5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/tag/Tag.java @@ -0,0 +1,80 @@ +package com.massivecraft.factions.tag; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FactionsPlugin; +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.entity.Player; + +public interface Tag { + int ARBITRARY_LIMIT = 25000; + + /** + * Replaces all variables in a plain raw line for a faction + * + * @param faction for faction + * @param line raw line from config with variables to replace for + * @return clean line + */ + static String parsePlain(Faction faction, String line) { + return GeneralTag.parse(FactionTag.parse(line, faction)); + } + + /** + * Replaces all variables in a plain raw line for a player + * + * @param fplayer for player + * @param line raw line from config with variables to replace for + * @return clean line + */ + static String parsePlain(FPlayer fplayer, String line) { + return parsePlain(fplayer.getFaction(), fplayer, line); + } + + /** + * Replaces all variables in a plain raw line for a faction, using relations from fplayer + * + * @param faction for faction + * @param fplayer from player + * @param line raw line from config with variables to replace for + * @return clean line + */ + static String parsePlain(Faction faction, FPlayer fplayer, String line) { + return GeneralTag.parse(PlayerTag.parse(FactionTag.parse(line, faction, fplayer), fplayer)); + } + + static String parsePlaceholders(Player player, String line) { + if (player == null || line == null) { + return line; + } + + if (FactionsPlugin.getInstance().isClipPlaceholderAPIHooked() && player.isOnline()) { + line = PlaceholderAPI.setPlaceholders(player, line); + } + + if (FactionsPlugin.getInstance().isMVdWPlaceholderAPIHooked() && player.isOnline()) { + line = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, line); + } + + return line; + } + + static boolean isMinimalShow() { + return FactionsPlugin.getInstance().getConfig().getBoolean("minimal-show", false); + } + + /** + * Gets the Tag's string representation. + * + * @return tag + */ + String getTag(); + + /** + * Gets if the Tag can be found in the given String. + * + * @param test string to test + * @return true if the tag is found in this string + */ + boolean foundInString(String test); +} diff --git a/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java b/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java index e9946a1e..33ca2fd2 100644 --- a/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java +++ b/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java @@ -50,13 +50,13 @@ public class AutoLeaveProcessTask extends BukkitRunnable { // Check if they should be exempt from this. if (!fplayer.willAutoLeave()) { - P.p.debug(Level.INFO, fplayer.getName() + " was going to be auto-removed but was set not to."); + FactionsPlugin.getInstance().debug(Level.INFO, fplayer.getName() + " was going to be auto-removed but was set not to."); continue; } if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis) { if (Conf.logFactionLeave || Conf.logFactionKick) { - P.p.log("Player " + fplayer.getName() + " was auto-removed due to inactivity."); + FactionsPlugin.getInstance().log("Player " + fplayer.getName() + " was auto-removed due to inactivity."); } // if player is faction admin, sort out the faction since he's going away diff --git a/src/main/java/com/massivecraft/factions/util/AutoLeaveTask.java b/src/main/java/com/massivecraft/factions/util/AutoLeaveTask.java index 6a1bda45..c24be121 100644 --- a/src/main/java/com/massivecraft/factions/util/AutoLeaveTask.java +++ b/src/main/java/com/massivecraft/factions/util/AutoLeaveTask.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.util; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; public class AutoLeaveTask implements Runnable { @@ -18,11 +18,11 @@ public class AutoLeaveTask implements Runnable { } task = new AutoLeaveProcessTask(); - task.runTaskTimer(P.p, 1, 1); + task.runTaskTimer(FactionsPlugin.getInstance(), 1, 1); // maybe setting has been changed? if so, restart this task at new rate if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) { - P.p.startAutoLeaveTask(true); + FactionsPlugin.getInstance().startAutoLeaveTask(true); } } } diff --git a/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java b/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java index b7117dc8..13b59e6f 100644 --- a/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java +++ b/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java @@ -35,7 +35,7 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R // Return the plugin version since this expansion is bundled with the dependency @Override public String getVersion() { - return P.p.getDescription().getVersion(); + return FactionsPlugin.getInstance().getDescription().getVersion(); } @Override @@ -84,7 +84,7 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fPlayer.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX; return fPlayer.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fPlayer.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized); case "player_group": - return P.p.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fPlayer.getId()))); + return FactionsPlugin.getInstance().getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fPlayer.getId()))); case "player_balance": return Econ.isSetup() ? Econ.getFriendlyBalance(fPlayer) : TL.ECON_OFF.format("balance"); case "player_power": @@ -131,7 +131,7 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R case "faction_warps": return String.valueOf(faction.getWarps().size()); case "faction_raidable": - boolean raid = P.p.getConfig().getBoolean("hcf.raidable", false) && faction.getLandRounded() >= faction.getPowerRounded(); + boolean raid = FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && faction.getLandRounded() >= faction.getPowerRounded(); return raid ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString(); case "faction_home_world": return faction.hasHome() ? faction.getHome().getWorld().getName() : ""; diff --git a/src/main/java/com/massivecraft/factions/util/FactionWarpsFrame.java b/src/main/java/com/massivecraft/factions/util/FactionWarpsFrame.java index e4790637..1aa83f3f 100644 --- a/src/main/java/com/massivecraft/factions/util/FactionWarpsFrame.java +++ b/src/main/java/com/massivecraft/factions/util/FactionWarpsFrame.java @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.pane.PaginatedPane; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; @@ -25,8 +25,8 @@ public class FactionWarpsFrame { private ConfigurationSection section; public FactionWarpsFrame(final Faction f) { - this.section = P.p.getConfig().getConfigurationSection("fwarp-gui"); - this.gui = new Gui(P.p, section.getInt("rows", 3), P.p.color(this.section.getString("name").replace("{faction}", f.getTag()))); + this.section = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fwarp-gui"); + this.gui = new Gui(FactionsPlugin.getInstance(), section.getInt("rows", 3), FactionsPlugin.getInstance().color(this.section.getString("name").replace("{faction}", f.getTag()))); } public void buildGUI(final FPlayer fplayer) { @@ -50,12 +50,12 @@ public class FactionWarpsFrame { } else { fplayer.setEnteringPassword(true, warp.getKey()); fplayer.msg(TL.COMMAND_FWARP_PASSWORD_REQUIRED); - Bukkit.getScheduler().runTaskLater(P.p, () -> { + Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> { if (fplayer.isEnteringPassword()) { fplayer.msg(TL.COMMAND_FWARP_PASSWORD_TIMEOUT); fplayer.setEnteringPassword(false, ""); } - }, P.p.getConfig().getInt("fwarp-gui.password-timeout", 5) * 20); + }, FactionsPlugin.getInstance().getConfig().getInt("fwarp-gui.password-timeout", 5) * 20); } })); ++count; @@ -70,8 +70,8 @@ public class FactionWarpsFrame { final ConfigurationSection config = this.section.getConfigurationSection("warp-item"); final ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem(); final ItemMeta meta = item.getItemMeta(); - meta.setLore(P.p.colorList(P.p.replacePlaceholders(config.getStringList("Lore"), new Placeholder("{warp-protected}", faction.hasWarpPassword(warp.getKey()) ? "Enabled" : "Disabled"), new Placeholder("{warp-cost}", P.p.getConfig().getBoolean("warp-cost.enabled", false) ? Integer.toString(P.p.getConfig().getInt("warp-cost.warp", 5)) : "Disabled")))); - meta.setDisplayName(P.p.color(config.getString("Name").replace("{warp}", warp.getKey()))); + meta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().replacePlaceholders(config.getStringList("Lore"), new Placeholder("{warp-protected}", faction.hasWarpPassword(warp.getKey()) ? "Enabled" : "Disabled"), new Placeholder("{warp-cost}", FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) ? Integer.toString(FactionsPlugin.getInstance().getConfig().getInt("warp-cost.warp", 5)) : "Disabled")))); + meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name").replace("{warp}", warp.getKey()))); item.setItemMeta(meta); return item; } @@ -80,8 +80,8 @@ public class FactionWarpsFrame { final ConfigurationSection config = this.section.getConfigurationSection("dummy-item"); final ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem(); final ItemMeta meta = item.getItemMeta(); - meta.setLore(P.p.colorList(config.getStringList("Lore"))); - meta.setDisplayName(P.p.color(config.getString("Name"))); + meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore"))); + meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name"))); item.setItemMeta(meta); return item; } @@ -93,12 +93,13 @@ public class FactionWarpsFrame { player.teleport(fme.getFaction().getWarp(warp).getLocation()); fme.msg(TL.COMMAND_FWARP_WARPED, warp); } - }, P.p.getConfig().getLong("warmups.f-warp", 0)); + }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-warp", 0)); } private boolean transact(FPlayer player) { - if (!P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing()) return true; - double cost = P.p.getConfig().getDouble("warp-cost.warp", 5); + if (!FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing()) + return true; + double cost = FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.warp", 5); if (!Econ.shouldBeUsed() || cost == 0.0 || player.isAdminBypassing()) return true; if (Conf.bankEnabled && Conf.bankFactionPaysCosts && player.hasFaction()) { diff --git a/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java index a5862681..d04383a0 100644 --- a/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java +++ b/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.util; import com.google.gson.*; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -21,7 +21,7 @@ public class LocationTypeAdapter implements JsonSerializer, JsonDeseri return object; } catch (Exception ex) { ex.printStackTrace(); - P.p.log(Level.WARNING, "Error encountered while serializing a Location."); + FactionsPlugin.getInstance().log(Level.WARNING, "Error encountered while serializing a Location."); return object; } } @@ -38,7 +38,7 @@ public class LocationTypeAdapter implements JsonSerializer, JsonDeseri object.get("z").getAsDouble()); } catch (Exception ex) { ex.printStackTrace(); - P.p.log(Level.WARNING, "Error encountered while" + + FactionsPlugin.getInstance().log(Level.WARNING, "Error encountered while" + " deserializing a Location."); return null; } diff --git a/src/main/java/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java index d70d2cba..2006a898 100644 --- a/src/main/java/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java +++ b/src/main/java/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.util; import com.google.gson.*; import com.massivecraft.factions.FLocation; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import java.lang.reflect.Type; import java.util.HashSet; @@ -50,7 +50,7 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer errors = new ArrayList<>(); if (getComparisonString(str).length() < Conf.factionTagLengthMin) { - errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_TOOSHORT.toString(), Conf.factionTagLengthMin)); + errors.add(FactionsPlugin.getInstance().txt.parse(TL.GENERIC_FACTIONTAG_TOOSHORT.toString(), Conf.factionTagLengthMin)); } if (str.length() > Conf.factionTagLengthMax) { - errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_TOOLONG.toString(), Conf.factionTagLengthMax)); + errors.add(FactionsPlugin.getInstance().txt.parse(TL.GENERIC_FACTIONTAG_TOOLONG.toString(), Conf.factionTagLengthMax)); } for (char c : str.toCharArray()) { if (!substanceChars.contains(String.valueOf(c))) { - errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_ALPHANUMERIC.toString(), c)); + errors.add(FactionsPlugin.getInstance().txt.parse(TL.GENERIC_FACTIONTAG_ALPHANUMERIC.toString(), c)); } } @@ -96,7 +96,7 @@ public class MiscUtil { // Fix for some data being broken when we added the recruit rank. if (player.getRole() == null) { player.setRole(Role.NORMAL); - P.p.log(Level.WARNING, String.format("Player %s had null role. Setting them to normal. This isn't good D:", player.getName())); + FactionsPlugin.getInstance().log(Level.WARNING, String.format("Player %s had null role. Setting them to normal. This isn't good D:", player.getName())); } switch (player.getRole()) { diff --git a/src/main/java/com/massivecraft/factions/util/MyLocationTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/MyLocationTypeAdapter.java index c68fca6b..8ce59598 100644 --- a/src/main/java/com/massivecraft/factions/util/MyLocationTypeAdapter.java +++ b/src/main/java/com/massivecraft/factions/util/MyLocationTypeAdapter.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.util; import com.google.gson.*; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import java.lang.reflect.Type; import java.util.logging.Level; @@ -32,7 +32,7 @@ public class MyLocationTypeAdapter implements JsonDeserializer, Js } catch (Exception ex) { ex.printStackTrace(); - P.p.log(Level.WARNING, "Error encountered while deserializing a LazyLocation."); + FactionsPlugin.getInstance().log(Level.WARNING, "Error encountered while deserializing a LazyLocation."); return null; } } @@ -52,7 +52,7 @@ public class MyLocationTypeAdapter implements JsonDeserializer, Js return obj; } catch (Exception ex) { ex.printStackTrace(); - P.p.log(Level.WARNING, "Error encountered while serializing a LazyLocation."); + FactionsPlugin.getInstance().log(Level.WARNING, "Error encountered while serializing a LazyLocation."); return obj; } } diff --git a/src/main/java/com/massivecraft/factions/util/Particles/Particles.java b/src/main/java/com/massivecraft/factions/util/Particles/Particles.java index b79304c0..2d7177a1 100644 --- a/src/main/java/com/massivecraft/factions/util/Particles/Particles.java +++ b/src/main/java/com/massivecraft/factions/util/Particles/Particles.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.util.Particles; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle; @@ -24,7 +24,7 @@ public enum Particles { public void displayAtLocation(Location location, int amt) { - if (P.p.useNonPacketParticles) { + if (FactionsPlugin.getInstance().useNonPacketParticles) { // 1.9+ based servers will use the built in particleAPI instead of packet based. // any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working. // So setting the amount to 0 spawns 1 in the precise location @@ -35,15 +35,15 @@ public enum Particles { } public void displayAtLocation(Location location, int amt, ParticleEffect.OrdinaryColor color) { - if (P.p.useNonPacketParticles) { + if (FactionsPlugin.getInstance().useNonPacketParticles) { // 1.9-1.11 & 1.13+ based servers will use the built in particleAPI instead of packet based. // any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working. // So setting the amount to 0 spawns 1 in the precise location - // Gotta do this so colorable ones have their data :P + // Gotta do this so colorable ones have their data :FactionsPlugin if (this == Particles.REDSTONE || this == Particles.CLOUD || this == Particles.NOTE) { - if (P.p.mc112) { + if (FactionsPlugin.getInstance().mc112) { location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0); } else { location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0, new Particle.DustOptions(Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), 1)); diff --git a/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java index fe5e160d..d5a7f661 100644 --- a/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java +++ b/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.util; import com.google.gson.*; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; @@ -62,7 +62,7 @@ public class PermissionsMapTypeAdapter implements JsonDeserializer { + R apply(T t, U u, V v, W w); +} diff --git a/src/main/java/com/massivecraft/factions/util/SpiralTask.java b/src/main/java/com/massivecraft/factions/util/SpiralTask.java index 6cde74f2..2733a423 100644 --- a/src/main/java/com/massivecraft/factions/util/SpiralTask.java +++ b/src/main/java/com/massivecraft/factions/util/SpiralTask.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.util; import com.massivecraft.factions.FLocation; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -45,7 +45,7 @@ public abstract class SpiralTask implements Runnable { this.world = Bukkit.getWorld(fLocation.getWorldName()); if (this.world == null) { - P.p.log(Level.WARNING, "[SpiralTask] A valid world must be specified!"); + FactionsPlugin.getInstance().log(Level.WARNING, "[SpiralTask] A valid world must be specified!"); this.stop(); return; } @@ -56,7 +56,7 @@ public abstract class SpiralTask implements Runnable { this.readyToGo = true; // get this party started - this.setTaskID(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, this, 2, 2)); + this.setTaskID(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), this, 2, 2)); } private static long now() { @@ -187,7 +187,7 @@ public abstract class SpiralTask implements Runnable { // for successful completion public void finish() { -// P.p.log("SpiralTask successfully completed!"); +// FactionsPlugin.getInstance().log("SpiralTask successfully completed!"); this.stop(); } diff --git a/src/main/java/com/massivecraft/factions/util/UtilFly.java b/src/main/java/com/massivecraft/factions/util/UtilFly.java index c6ed94f0..5422ab77 100644 --- a/src/main/java/com/massivecraft/factions/util/UtilFly.java +++ b/src/main/java/com/massivecraft/factions/util/UtilFly.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.util; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; @@ -12,19 +12,19 @@ import org.bukkit.Bukkit; public class UtilFly { public static void run() { - if (!P.p.getConfig().getBoolean("enable-faction-flight")) + if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) return; - Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { + Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { for (FPlayer fp : FPlayers.getInstance().getOnlinePlayers()) { if (fp.isFlying()) fp.checkIfNearbyEnemies(); } - }, 0, P.p.getConfig().getInt("fly-task-interval", 10)); + }, 0, FactionsPlugin.getInstance().getConfig().getInt("fly-task-interval", 10)); } public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) { - if (!P.p.getConfig().getBoolean("enable-faction-flight")) + if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) return; fp.getPlayer().setAllowFlight(fly); @@ -44,7 +44,7 @@ public class UtilFly { } public static void checkFly(FPlayer me, Faction factionTo) { - if (!P.p.getConfig().getBoolean("enable-faction-flight")) + if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) return; if (me.isAdminBypassing() && me.isFlying() && me.getPlayer().hasPermission("factions.fly.enemy-bypass")) @@ -82,13 +82,13 @@ public class UtilFly { public static void setFallDamage(FPlayer fp, boolean fly, boolean damage) { if (!fly) { if (!damage) { - fp.sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", P.p.getConfig().getInt("fly-falldamage-cooldown", 3) + "")); + fp.sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + "")); } - int cooldown = P.p.getConfig().getInt("fly-falldamage-cooldown", 3); + int cooldown = FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3); if (cooldown > 0) { fp.setTakeFallDamage(false); - Bukkit.getScheduler().runTaskLater(P.p, () -> fp.setTakeFallDamage(true), 20L * cooldown); + Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> fp.setTakeFallDamage(true), 20L * cooldown); } } } diff --git a/src/main/java/com/massivecraft/factions/util/WarmUpUtil.java b/src/main/java/com/massivecraft/factions/util/WarmUpUtil.java index 965e7095..3ddd57da 100644 --- a/src/main/java/com/massivecraft/factions/util/WarmUpUtil.java +++ b/src/main/java/com/massivecraft/factions/util/WarmUpUtil.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.util; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; public class WarmUpUtil { @@ -21,7 +21,7 @@ public class WarmUpUtil { player.msg(TL.WARMUPS_ALREADY); } else { player.msg(translationKey.format(action, delay)); - int id = P.p.getServer().getScheduler().runTaskLater(P.p, () -> { + int id = FactionsPlugin.getInstance().getServer().getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> { player.stopWarmup(); runnable.run(); }, delay * 20).getTaskId(); diff --git a/src/main/java/com/massivecraft/factions/zcore/MCommand.java b/src/main/java/com/massivecraft/factions/zcore/MCommand.java index 5a3012a9..7dfeba74 100644 --- a/src/main/java/com/massivecraft/factions/zcore/MCommand.java +++ b/src/main/java/com/massivecraft/factions/zcore/MCommand.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.zcore; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TextUtil; @@ -311,7 +311,7 @@ public abstract class MCommand { s = s.replace("{power}", power); } if (s.contains("{group}")) { - String group = P.p.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(player.getId()))); + String group = FactionsPlugin.getInstance().getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(player.getId()))); s = s.replace("{group}", group); } return s; diff --git a/src/main/java/com/massivecraft/factions/zcore/MPlugin.java b/src/main/java/com/massivecraft/factions/zcore/MPlugin.java index faa241c2..2e688f0e 100644 --- a/src/main/java/com/massivecraft/factions/zcore/MPlugin.java +++ b/src/main/java/com/massivecraft/factions/zcore/MPlugin.java @@ -242,7 +242,7 @@ public abstract class MPlugin extends JavaPlugin { // COMMAND HANDLING // -------------------------------------------- // - // can be overridden by P method, to provide option + // can be overridden by FactionsPlugin method, to provide option public boolean logPlayerCommands() { return true; } diff --git a/src/main/java/com/massivecraft/factions/zcore/MPluginSecretPlayerListener.java b/src/main/java/com/massivecraft/factions/zcore/MPluginSecretPlayerListener.java index 7df5d34c..e1d9f132 100644 --- a/src/main/java/com/massivecraft/factions/zcore/MPluginSecretPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/zcore/MPluginSecretPlayerListener.java @@ -40,7 +40,7 @@ public class MPluginSecretPlayerListener implements Listener { /* Should be handled by stuff in FactionsChatListener Player speaker = event.getPlayer(); String format = event.getFormat(); - format = format.replace(Conf.chatTagReplaceString, P.p.getPlayerFactionTag(speaker)).replace("[FACTION_TITLE]", P.p.getPlayerTitle(speaker)); + format = format.replace(Conf.chatTagReplaceString, FactionsPlugin.getInstance().getPlayerFactionTag(speaker)).replace("[FACTION_TITLE]", FactionsPlugin.getInstance().getPlayerTitle(speaker)); event.setFormat(format); */ } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/Access.java b/src/main/java/com/massivecraft/factions/zcore/fperms/Access.java index fcc8efc7..c4c778d1 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/Access.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/Access.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.zcore.fperms; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; public enum Access { ALLOW("Allow"), @@ -41,6 +41,6 @@ public enum Access { } public String getColor() { - return P.p.getConfig().getString("fperm-gui.action.Access-Colors." + this.name); + return FactionsPlugin.getInstance().getConfig().getString("fperm-gui.action.Access-Colors." + this.name); } } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java index eb5f60cb..3c721c27 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.zcore.fperms; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.Placeholder; import com.massivecraft.factions.util.XMaterial; import org.bukkit.configuration.ConfigurationSection; @@ -80,7 +80,7 @@ public enum PermissableAction { } public int getSlot() { - return P.p.getConfig().getInt("fperm-gui.action.slots." + this.name.toLowerCase()); + return FactionsPlugin.getInstance().getConfig().getInt("fperm-gui.action.slots." + this.name.toLowerCase()); } /** @@ -98,18 +98,18 @@ public enum PermissableAction { } public ItemStack buildAsset(FPlayer fme, Permissable perm) { - ConfigurationSection section = P.p.getConfig().getConfigurationSection("fperm-gui.action"); + ConfigurationSection section = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.action"); ItemStack item = XMaterial.matchXMaterial(section.getString("Materials." + this.name)).parseItem(); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(P.p.color(section.getString("placeholder-item.name").replace("{action}", this.name))); + meta.setDisplayName(FactionsPlugin.getInstance().color(section.getString("placeholder-item.name").replace("{action}", this.name))); List lore = section.getStringList("placeholder-item.lore"); - lore = P.p.replacePlaceholders(lore, + lore = FactionsPlugin.getInstance().replacePlaceholders(lore, new Placeholder("{action-access-color}", fme.getFaction().getPermissions().get(perm).get(this).getColor()), new Placeholder("{action-access}", fme.getFaction().getPermissions().get(perm).get(this).getName())); - meta.setLore(P.p.colorList(lore)); + meta.setLore(FactionsPlugin.getInstance().colorList(lore)); item.setItemMeta(meta); return item; } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableActionFrame.java b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableActionFrame.java index 65867482..fe31f632 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableActionFrame.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableActionFrame.java @@ -5,7 +5,7 @@ import com.github.stefvanschie.inventoryframework.GuiItem; import com.github.stefvanschie.inventoryframework.pane.PaginatedPane; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Permissable; @@ -23,10 +23,10 @@ public class PermissableActionFrame { private Gui gui; public PermissableActionFrame(Faction f) { - ConfigurationSection section = P.p.getConfig().getConfigurationSection("fperm-gui.action"); - gui = new Gui(P.p, + ConfigurationSection section = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.action"); + gui = new Gui(FactionsPlugin.getInstance(), section.getInt("rows", 3), - P.p.color(P.p.getConfig().getString("fperm-gui.action.name").replace("{faction}", f.getTag()))); + FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fperm-gui.action.name").replace("{faction}", f.getTag()))); } public void buildGUI(FPlayer fplayer, Permissable perm) { @@ -60,14 +60,14 @@ public class PermissableActionFrame { } if (success) fplayer.msg(TL.COMMAND_PERM_SET, action.name(), access.name(), perm.name()); else fplayer.msg(TL.COMMAND_PERM_LOCKED); - P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), action.name(), access.name(), perm.name()) + " for faction " + fplayer.getTag()); + FactionsPlugin.getInstance().log(String.format(TL.COMMAND_PERM_SET.toString(), action.name(), access.name(), perm.name()) + " for faction " + fplayer.getTag()); // Closing and opening resets the cursor. // fplayer.getPlayer().closeInventory(); buildGUI(fplayer, perm); } })); } - GUIItems.set(P.p.getConfig().getInt("fperm-gui.action.slots.back"), new GuiItem(buildBackItem(), event -> { + GUIItems.set(FactionsPlugin.getInstance().getConfig().getInt("fperm-gui.action.slots.back"), new GuiItem(buildBackItem(), event -> { event.setCancelled(true); // Closing and opening resets the cursor. // fplayer.getPlayer().closeInventory(); @@ -81,21 +81,21 @@ public class PermissableActionFrame { private ItemStack buildDummyItem() { - ConfigurationSection config = P.p.getConfig().getConfigurationSection("fperm-gui.dummy-item"); + ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.dummy-item"); ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem(); ItemMeta meta = item.getItemMeta(); - meta.setLore(P.p.colorList(config.getStringList("Lore"))); - meta.setDisplayName(P.p.color(config.getString("Name"))); + meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore"))); + meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name"))); item.setItemMeta(meta); return item; } private ItemStack buildBackItem() { - ConfigurationSection config = P.p.getConfig().getConfigurationSection("fperm-gui.back-item"); + ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.back-item"); ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem(); ItemMeta meta = item.getItemMeta(); - meta.setLore(P.p.colorList(config.getStringList("Lore"))); - meta.setDisplayName(P.p.color(config.getString("Name"))); + meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore"))); + meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name"))); item.setItemMeta(meta); return item; } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationFrame.java b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationFrame.java index 3863b185..db7dc7e3 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationFrame.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationFrame.java @@ -5,7 +5,7 @@ import com.github.stefvanschie.inventoryframework.GuiItem; import com.github.stefvanschie.inventoryframework.pane.PaginatedPane; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.XMaterial; @@ -22,10 +22,10 @@ public class PermissableRelationFrame { private Gui gui; public PermissableRelationFrame(Faction f) { - ConfigurationSection section = P.p.getConfig().getConfigurationSection("fperm-gui.relation"); - gui = new Gui(P.p, + ConfigurationSection section = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.relation"); + gui = new Gui(FactionsPlugin.getInstance(), section.getInt("rows", 3), - P.p.color(P.p.getConfig().getString("fperm-gui.relation.name").replace("{faction}", f.getTag()))); + FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fperm-gui.relation.name").replace("{faction}", f.getTag()))); } public void buildGUI(FPlayer fplayer) { @@ -34,7 +34,7 @@ public class PermissableRelationFrame { ItemStack dumby = buildDummyItem(); // Fill background of GUI with dumbyitem & replace GUI assets after for (int x = 0; x <= (gui.getRows() * 9) - 1; x++) GUIItems.add(new GuiItem(dumby, e -> e.setCancelled(true))); - ConfigurationSection sec = P.p.getConfig().getConfigurationSection("fperm-gui.relation"); + ConfigurationSection sec = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.relation"); for (String key : sec.getConfigurationSection("slots").getKeys(false)) { GUIItems.set(sec.getInt("slots." + key), new GuiItem(buildAsset("fperm-gui.relation.materials." + key, key), e -> { e.setCancelled(true); @@ -50,19 +50,19 @@ public class PermissableRelationFrame { } private ItemStack buildAsset(String loc, String relation) { - ItemStack item = XMaterial.matchXMaterial(P.p.getConfig().getString(loc)).parseItem(); + ItemStack item = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString(loc)).parseItem(); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(P.p.color(P.p.getConfig().getString("fperm-gui.relation.Placeholder-Item.Name").replace("{relation}", relation))); + meta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fperm-gui.relation.Placeholder-Item.Name").replace("{relation}", relation))); item.setItemMeta(meta); return item; } private ItemStack buildDummyItem() { - ConfigurationSection config = P.p.getConfig().getConfigurationSection("fperm-gui.dummy-item"); + ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.dummy-item"); ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem(); ItemMeta meta = item.getItemMeta(); - meta.setLore(P.p.colorList(config.getStringList("Lore"))); - meta.setDisplayName(P.p.color(config.getString("Name"))); + meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore"))); + meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name"))); item.setItemMeta(meta); return item; } diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/CropUpgrades.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/CropUpgrades.java index 11ee10bf..0385caf7 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/CropUpgrades.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/CropUpgrades.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.zcore.fupgrades; import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.XMaterial; import org.bukkit.CropState; import org.bukkit.Material; @@ -30,13 +30,13 @@ public class CropUpgrades implements Listener { switch (level) { case 1: - chance = P.p.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-1"); + chance = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-1"); break; case 2: - chance = P.p.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-2"); + chance = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-2"); break; case 3: - chance = P.p.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-3"); + chance = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-3"); break; } diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/EXPUpgrade.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/EXPUpgrade.java index 4006ff72..87bf37ff 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/EXPUpgrade.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/EXPUpgrade.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.zcore.fupgrades; import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -29,13 +29,13 @@ public class EXPUpgrade implements Listener { switch (level) { case 1: - multiplier = P.p.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-1"); + multiplier = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-1"); break; case 2: - multiplier = P.p.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-2"); + multiplier = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-2"); break; case 3: - multiplier = P.p.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-3"); + multiplier = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-3"); break; } diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java index 01f7eb94..fbc4d4c1 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.zcore.fupgrades; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.util.XMaterial; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -22,25 +22,25 @@ import java.util.List; public class FUpgradesGUI implements Listener { public void openMainMenu(FPlayer fme) { - Inventory inventory = Bukkit.createInventory(null, P.p.getConfig().getInt("fupgrades.MainMenu.DummyItem.rows") * 9, P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.Title").replace("{faction}", fme.getFaction().getTag()))); - ItemStack dummyItem = XMaterial.matchXMaterial(P.p.getConfig().getString("fupgrades.MainMenu.DummyItem.Type")).parseItem(); + Inventory inventory = Bukkit.createInventory(null, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DummyItem.rows") * 9, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Title").replace("{faction}", fme.getFaction().getTag()))); + ItemStack dummyItem = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.DummyItem.Type")).parseItem(); ItemMeta meta = dummyItem.getItemMeta(); - meta.setLore(P.p.colorList(P.p.getConfig().getStringList("fupgrades.MainMenu.DummyItem.Lore"))); - meta.setDisplayName(P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.DummyItem.Name"))); + meta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.DummyItem.Lore"))); + meta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.DummyItem.Name"))); dummyItem.setItemMeta(meta); - for (int fill = 0; fill < P.p.getConfig().getInt("fupgrades.MainMenu.DummyItem.rows") * 9; ++fill) { + for (int fill = 0; fill < FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DummyItem.rows") * 9; ++fill) { inventory.setItem(fill, dummyItem); } ItemStack[] items = buildItems(fme); - List cropSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Crops.CropItem.slots"); - List spawnerSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Spawners.SpawnerItem.slots"); - List expSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.EXP.EXPItem.slots"); - List chestSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Chest.ChestItem.slots"); - List powerSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Power.PowerItem.slots"); - List redSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Redstone.RedstoneItem.slots"); - List memberSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Members.MembersItem.slots"); + List cropSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Crops.CropItem.slots"); + List spawnerSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Spawners.SpawnerItem.slots"); + List expSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.EXP.EXPItem.slots"); + List chestSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Chest.ChestItem.slots"); + List powerSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Power.PowerItem.slots"); + List redSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Redstone.RedstoneItem.slots"); + List memberSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Members.MembersItem.slots"); for (Integer cropSlot : cropSlots) if (cropSlot != -1) inventory.setItem(cropSlot, items[2]); @@ -65,7 +65,7 @@ public class FUpgradesGUI implements Listener { return; FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked()); - if (e.getView().getTitle().equalsIgnoreCase(P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.Title").replace("{faction}", fme.getFaction().getTag())))) { + if (e.getView().getTitle().equalsIgnoreCase(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Title").replace("{faction}", fme.getFaction().getTag())))) { e.setCancelled(true); ItemStack[] items = buildItems(fme); ItemStack cropItem = items[2]; @@ -82,13 +82,13 @@ public class FUpgradesGUI implements Listener { case 3: return; case 2: - upgradeItem(fme, UpgradeType.CROP, 3, P.p.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-3")); + upgradeItem(fme, UpgradeType.CROP, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-3")); break; case 1: - upgradeItem(fme, UpgradeType.CROP, 2, P.p.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-2")); + upgradeItem(fme, UpgradeType.CROP, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-2")); break; case 0: - upgradeItem(fme, UpgradeType.CROP, 1, P.p.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-1")); + upgradeItem(fme, UpgradeType.CROP, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-1")); break; } } else if (e.getCurrentItem().equals(powerItem)) { @@ -97,15 +97,15 @@ public class FUpgradesGUI implements Listener { case 3: return; case 2: - upgradeItem(fme, UpgradeType.POWER, 3, P.p.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-3")); + upgradeItem(fme, UpgradeType.POWER, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-3")); updatePower(fme.getFaction()); break; case 1: - upgradeItem(fme, UpgradeType.POWER, 2, P.p.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-2")); + upgradeItem(fme, UpgradeType.POWER, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-2")); updatePower(fme.getFaction()); break; case 0: - upgradeItem(fme, UpgradeType.POWER, 1, P.p.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-1")); + upgradeItem(fme, UpgradeType.POWER, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-1")); updatePower(fme.getFaction()); break; } @@ -115,13 +115,13 @@ public class FUpgradesGUI implements Listener { case 3: return; case 2: - upgradeItem(fme, UpgradeType.SPAWNER, 3, P.p.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-3")); + upgradeItem(fme, UpgradeType.SPAWNER, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-3")); break; case 1: - upgradeItem(fme, UpgradeType.SPAWNER, 2, P.p.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-2")); + upgradeItem(fme, UpgradeType.SPAWNER, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-2")); break; case 0: - upgradeItem(fme, UpgradeType.SPAWNER, 1, P.p.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-1")); + upgradeItem(fme, UpgradeType.SPAWNER, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-1")); break; } } else if (e.getCurrentItem().equals(expItem)) { @@ -131,13 +131,13 @@ public class FUpgradesGUI implements Listener { case 3: return; case 2: - upgradeItem(fme, UpgradeType.EXP, 3, P.p.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-3")); + upgradeItem(fme, UpgradeType.EXP, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-3")); break; case 1: - upgradeItem(fme, UpgradeType.EXP, 2, P.p.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-2")); + upgradeItem(fme, UpgradeType.EXP, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-2")); break; case 0: - upgradeItem(fme, UpgradeType.EXP, 1, P.p.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-1")); + upgradeItem(fme, UpgradeType.EXP, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-1")); break; } } else if (e.getCurrentItem().equals(redItem)) { @@ -146,7 +146,7 @@ public class FUpgradesGUI implements Listener { case 1: return; case 0: - upgradeItem(fme, UpgradeType.REDSTONE, 1, P.p.getConfig().getInt("fupgrades.MainMenu.Redstone.Cost")); + upgradeItem(fme, UpgradeType.REDSTONE, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.Cost")); break; } } else if (e.getCurrentItem().equals(chestitem)) { @@ -155,27 +155,27 @@ public class FUpgradesGUI implements Listener { case 3: return; case 2: { - if (upgradeItem(fme, UpgradeType.CHEST, 3, P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-3"))) + if (upgradeItem(fme, UpgradeType.CHEST, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-3"))) updateChests(fme.getFaction()); break; } case 1: { - if (upgradeItem(fme, UpgradeType.CHEST, 2, P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-2"))) + if (upgradeItem(fme, UpgradeType.CHEST, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-2"))) updateChests(fme.getFaction()); break; } case 0: { - if (upgradeItem(fme, UpgradeType.CHEST, 1, P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-1"))) + if (upgradeItem(fme, UpgradeType.CHEST, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-1"))) updateChests(fme.getFaction()); break; } } } else if (e.getCurrentItem().equals(memberItem)) { int memberLevel = fme.getFaction().getUpgrade(UpgradeType.MEMBERS) + 1; - if (!P.p.getConfig().isSet("fupgrades.MainMenu.Members.Cost.level-" + memberLevel)) { + if (!FactionsPlugin.getInstance().getConfig().isSet("fupgrades.MainMenu.Members.Cost.level-" + memberLevel)) { return; } - int cost = P.p.getConfig().getInt("fupgrades.MainMenu.Members.Cost.level-" + memberLevel); + int cost = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Members.Cost.level-" + memberLevel); if (hasMoney(fme, cost)) { fme.getFaction().setUpgrade(UpgradeType.MEMBERS, memberLevel); fme.getPlayer().closeInventory(); @@ -186,7 +186,7 @@ public class FUpgradesGUI implements Listener { } private void updateChests(Faction faction) { - String invName = P.p.color(P.p.getConfig().getString("fchest.Inventory-Title")); + String invName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")); for (Player player : faction.getOnlinePlayers()) { if (player.getInventory().getTitle() != null && player.getInventory().getTitle().equalsIgnoreCase(invName)) @@ -198,13 +198,13 @@ public class FUpgradesGUI implements Listener { switch (level) { case 1: - size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-1"); + size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-1"); break; case 2: - size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-2"); + size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-2"); break; case 3: - size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3"); + size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3"); break; } faction.setChestSize(size * 9); @@ -216,13 +216,13 @@ public class FUpgradesGUI implements Listener { switch (level) { case 1: - power = P.p.getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-1"); + power = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-1"); break; case 2: - power = P.p.getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-2"); + power = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-2"); break; case 3: - power = P.p.getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-3"); + power = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-3"); break; } faction.setPowerBoost(power); @@ -230,21 +230,21 @@ public class FUpgradesGUI implements Listener { @SuppressWarnings("Duplicates") private ItemStack[] buildItems(FPlayer fme) { - Material expMaterial = Material.getMaterial(P.p.getConfig().getString("fupgrades.MainMenu.EXP.EXPItem.Type")); - int expAmt = P.p.getConfig().getInt("fupgrades.MainMenu.EXP.EXPItem.Amount"); - short expData = Short.parseShort(P.p.getConfig().getInt("fupgrades.MainMenu.EXP.EXPItem.Damage") + ""); - String expName = P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.EXP.EXPItem.Name")); - List expLore = P.p.colorList(P.p.getConfig().getStringList("fupgrades.MainMenu.EXP.EXPItem.Lore")); + Material expMaterial = Material.getMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.EXP.EXPItem.Type")); + int expAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.EXPItem.Amount"); + short expData = Short.parseShort(FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.EXPItem.Damage") + ""); + String expName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.EXP.EXPItem.Name")); + List expLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.EXP.EXPItem.Lore")); int expLevel = fme.getFaction().getUpgrade(UpgradeType.EXP); for (int i = 0; i <= expLore.size() - 1; i++) expLore.set(i, expLore.get(i).replace("{level}", expLevel + "")); - ItemStack expItem = P.p.createItem(expMaterial, expAmt, expData, expName, expLore); + ItemStack expItem = FactionsPlugin.getInstance().createItem(expMaterial, expAmt, expData, expName, expLore); if (expLevel >= 1) { ItemMeta itemMeta = expItem.getItemMeta(); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); @@ -253,11 +253,11 @@ public class FUpgradesGUI implements Listener { expItem.setAmount(expLevel); } - Material spawnerMaterial = Material.getMaterial(P.p.getConfig().getString("fupgrades.MainMenu.Spawners.SpawnerItem.Type")); - int spawnerAmt = P.p.getConfig().getInt("fupgrades.MainMenu.Spawners.SpawnerItem.Amount"); - short spawnerData = Short.parseShort(P.p.getConfig().getInt("fupgrades.MainMenu.Spawners.SpawnerItem.Damage") + ""); - String spawnerName = P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.Spawners.SpawnerItem.Name")); - List spawnerLore = P.p.colorList(P.p.getConfig().getStringList("fupgrades.MainMenu.Spawners.SpawnerItem.Lore")); + Material spawnerMaterial = Material.getMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Spawners.SpawnerItem.Type")); + int spawnerAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.SpawnerItem.Amount"); + short spawnerData = Short.parseShort(FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.SpawnerItem.Damage") + ""); + String spawnerName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Spawners.SpawnerItem.Name")); + List spawnerLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Spawners.SpawnerItem.Lore")); int spawnerLevel = fme.getFaction().getUpgrade(UpgradeType.SPAWNER); for (int i = 0; i <= spawnerLore.size() - 1; i++) { @@ -265,11 +265,11 @@ public class FUpgradesGUI implements Listener { } - Material cropMaterial = Material.getMaterial(P.p.getConfig().getString("fupgrades.MainMenu.Crops.CropItem.Type")); - int cropAmt = P.p.getConfig().getInt("fupgrades.MainMenu.Crops.CropItem.Amount"); - short cropData = Short.parseShort(P.p.getConfig().getInt("fupgrades.MainMenu.Crops.CropItem.Damage") + ""); - String cropName = P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.Crops.CropItem.Name")); - List cropLore = P.p.colorList(P.p.getConfig().getStringList("fupgrades.MainMenu.Crops.CropItem.Lore")); + Material cropMaterial = Material.getMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Crops.CropItem.Type")); + int cropAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.CropItem.Amount"); + short cropData = Short.parseShort(FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.CropItem.Damage") + ""); + String cropName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Crops.CropItem.Name")); + List cropLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Crops.CropItem.Lore")); int cropLevel = fme.getFaction().getUpgrade(UpgradeType.CROP); for (int i = 0; i <= cropLore.size() - 1; i++) { @@ -278,12 +278,12 @@ public class FUpgradesGUI implements Listener { cropLore.set(i, line); } - ItemStack cropItem = P.p.createItem(cropMaterial, cropAmt, cropData, cropName, cropLore); + ItemStack cropItem = FactionsPlugin.getInstance().createItem(cropMaterial, cropAmt, cropData, cropName, cropLore); cropItem.getItemMeta().setLore(cropLore); if (cropLevel >= 1) { ItemMeta itemMeta = cropItem.getItemMeta(); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); @@ -292,11 +292,11 @@ public class FUpgradesGUI implements Listener { cropItem.setAmount(cropLevel); } - ItemStack spawnerItem = P.p.createItem(spawnerMaterial, spawnerAmt, spawnerData, spawnerName, spawnerLore); + ItemStack spawnerItem = FactionsPlugin.getInstance().createItem(spawnerMaterial, spawnerAmt, spawnerData, spawnerName, spawnerLore); spawnerItem.getItemMeta().setLore(spawnerLore); if (spawnerLevel >= 1) { ItemMeta itemMeta = spawnerItem.getItemMeta(); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); @@ -305,11 +305,11 @@ public class FUpgradesGUI implements Listener { spawnerItem.setAmount(spawnerLevel); } - Material chestMaterial = Material.getMaterial(P.p.getConfig().getString("fupgrades.MainMenu.Chest.ChestItem.Type")); - int chesttAmt = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.ChestItem.Amount"); - short chestData = Short.parseShort(P.p.getConfig().getInt("fupgrades.MainMenu.Chest.ChestItem.Damage") + ""); - String chestName = P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.Chest.ChestItem.Name", "&e&lUpgrade Chest Size")); - List chestLore = P.p.colorList(P.p.getConfig().getStringList("fupgrades.MainMenu.Chest.ChestItem.Lore")); + Material chestMaterial = Material.getMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Chest.ChestItem.Type")); + int chesttAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.ChestItem.Amount"); + short chestData = Short.parseShort(FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.ChestItem.Damage") + ""); + String chestName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Chest.ChestItem.Name", "&e&lUpgrade Chest Size")); + List chestLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Chest.ChestItem.Lore")); int chestlevel = fme.getFaction().getUpgrade(UpgradeType.CHEST); for (int i = 0; i <= chestLore.size() - 1; i++) { @@ -318,11 +318,11 @@ public class FUpgradesGUI implements Listener { chestLore.set(i, line); } - ItemStack chestItem = P.p.createItem(chestMaterial, chesttAmt, chestData, chestName, chestLore); + ItemStack chestItem = FactionsPlugin.getInstance().createItem(chestMaterial, chesttAmt, chestData, chestName, chestLore); if (chestlevel >= 1) { ItemMeta itemMeta = chestItem.getItemMeta(); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); @@ -331,11 +331,11 @@ public class FUpgradesGUI implements Listener { chestItem.setAmount(chestlevel); } - Material memberMaterial = Material.getMaterial(P.p.getConfig().getString("fupgrades.MainMenu.Members.MembersItem.Type")); - int memberAmt = P.p.getConfig().getInt("fupgrades.MainMenu.Members.MembersItem.Amount"); - short memberData = Short.parseShort(P.p.getConfig().getInt("fupgrades.MainMenu.Members.MembersItem.Damage") + ""); - String memberName = P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.Members.MembersItem.Name", "&e&lUpgrade Member Size")); - List memberLore = P.p.colorList(P.p.getConfig().getStringList("fupgrades.MainMenu.Members.MembersItem.Lore")); + Material memberMaterial = Material.getMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Members.MembersItem.Type")); + int memberAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Members.MembersItem.Amount"); + short memberData = Short.parseShort(FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Members.MembersItem.Damage") + ""); + String memberName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Members.MembersItem.Name", "&e&lUpgrade Member Size")); + List memberLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Members.MembersItem.Lore")); int memberlevel = fme.getFaction().getUpgrade(UpgradeType.MEMBERS); for (int i = 0; i <= memberLore.size() - 1; i++) { @@ -344,11 +344,11 @@ public class FUpgradesGUI implements Listener { memberLore.set(i, line); } - ItemStack memberItem = P.p.createItem(memberMaterial, memberAmt, memberData, memberName, memberLore); + ItemStack memberItem = FactionsPlugin.getInstance().createItem(memberMaterial, memberAmt, memberData, memberName, memberLore); if (memberlevel >= 1) { ItemMeta itemMeta = memberItem.getItemMeta(); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); @@ -357,11 +357,11 @@ public class FUpgradesGUI implements Listener { memberItem.setAmount(memberlevel); } - Material powerMaterial = Material.getMaterial(P.p.getConfig().getString("fupgrades.MainMenu.Power.PowerItem.Type")); - int powerAmt = P.p.getConfig().getInt("fupgrades.MainMenu.Power.PowerItem.Amount"); - short powerData = Short.parseShort(P.p.getConfig().getInt("fupgrades.MainMenu.Power.PowerItem.Damage") + ""); - String powerName = P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.Power.PowerItem.Name")); - List powerLore = P.p.colorList(P.p.getConfig().getStringList("fupgrades.MainMenu.Power.PowerItem.Lore")); + Material powerMaterial = Material.getMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Power.PowerItem.Type")); + int powerAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.PowerItem.Amount"); + short powerData = Short.parseShort(FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.PowerItem.Damage") + ""); + String powerName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Power.PowerItem.Name")); + List powerLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Power.PowerItem.Lore")); int powerLevel = fme.getFaction().getUpgrade(UpgradeType.POWER); for (int i = 0; i <= powerLore.size() - 1; i++) { @@ -370,12 +370,12 @@ public class FUpgradesGUI implements Listener { powerLore.set(i, line); } - ItemStack powerItem = P.p.createItem(powerMaterial, powerAmt, powerData, powerName, powerLore); + ItemStack powerItem = FactionsPlugin.getInstance().createItem(powerMaterial, powerAmt, powerData, powerName, powerLore); powerItem.getItemMeta().setLore(powerLore); if (powerLevel >= 1) { ItemMeta itemMeta = powerItem.getItemMeta(); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); @@ -384,11 +384,11 @@ public class FUpgradesGUI implements Listener { powerItem.setAmount(powerLevel); } - Material redMaterial = Material.getMaterial(P.p.getConfig().getString("fupgrades.MainMenu.Redstone.RedstoneItem.Type")); - int redAmt = P.p.getConfig().getInt("fupgrades.MainMenu.Redstone.RedstoneItem.Amount"); - short redData = Short.parseShort(P.p.getConfig().getInt("fupgrades.MainMenu.Redstone.RedstoneItem.Damage") + ""); - String redName = P.p.color(P.p.getConfig().getString("fupgrades.MainMenu.Redstone.RedstoneItem.Name")); - List redLore = P.p.colorList(P.p.getConfig().getStringList("fupgrades.MainMenu.Redstone.RedstoneItem.Lore")); + Material redMaterial = Material.getMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Redstone.RedstoneItem.Type")); + int redAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.RedstoneItem.Amount"); + short redData = Short.parseShort(FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.RedstoneItem.Damage") + ""); + String redName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Redstone.RedstoneItem.Name")); + List redLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Redstone.RedstoneItem.Lore")); int redLevel = fme.getFaction().getUpgrade(UpgradeType.REDSTONE); for (int i = 0; i <= redLore.size() - 1; i++) { @@ -397,12 +397,12 @@ public class FUpgradesGUI implements Listener { redLore.set(i, line); } - ItemStack redItem = P.p.createItem(redMaterial, redAmt, redData, redName, redLore); + ItemStack redItem = FactionsPlugin.getInstance().createItem(redMaterial, redAmt, redData, redName, redLore); redItem.getItemMeta().setLore(redLore); if (redLevel >= 1) { ItemMeta itemMeta = redItem.getItemMeta(); - if (!P.p.mc17) { + if (!FactionsPlugin.getInstance().mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/RedstoneUpgrade.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/RedstoneUpgrade.java index 4c3f876c..7727345b 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/RedstoneUpgrade.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/RedstoneUpgrade.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.zcore.fupgrades; import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockFromToEvent; @@ -14,7 +14,7 @@ public class RedstoneUpgrade implements Listener { @EventHandler public void onWaterRedstone(BlockFromToEvent e) { - List unbreakable = P.p.getConfig().getStringList("no-water-destroy.Item-List"); + List unbreakable = FactionsPlugin.getInstance().getConfig().getStringList("no-water-destroy.Item-List"); String block = e.getToBlock().getType().toString(); FLocation floc = new FLocation(e.getToBlock().getLocation()); Faction factionAtLoc = Board.getInstance().getFactionAt(floc); @@ -23,7 +23,7 @@ public class RedstoneUpgrade implements Listener { int level = factionAtLoc.getUpgrade(UpgradeType.REDSTONE); if (level != 0) { if (level == 1) { - P.p.getConfig().getInt("fupgrades.MainMenu.Redstone.Cost"); + FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.Cost"); } if (unbreakable.contains(block)) { e.setCancelled(true); diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/SpawnerUpgrades.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/SpawnerUpgrades.java index 3eb284c0..f3a8735a 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/SpawnerUpgrades.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/SpawnerUpgrades.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.zcore.fupgrades; import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.SpawnerSpawnEvent; @@ -20,13 +20,13 @@ public class SpawnerUpgrades implements Listener { if (level != 0) { switch (level) { case 1: - lowerSpawnerDelay(e, P.p.getConfig().getInt("fupgrades.MainMenu.Spawners.Spawner-Boost.level-1")); + lowerSpawnerDelay(e, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Spawner-Boost.level-1")); break; case 2: - lowerSpawnerDelay(e, P.p.getConfig().getInt("fupgrades.MainMenu.Spawners.Spawner-Boost.level-2")); + lowerSpawnerDelay(e, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Spawner-Boost.level-2")); break; case 3: - lowerSpawnerDelay(e, P.p.getConfig().getInt("fupgrades.MainMenu.Spawners.Spawner-Boost.level-3")); + lowerSpawnerDelay(e, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Spawner-Boost.level-3")); break; } } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java index 13e15096..04bad776 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -152,7 +152,7 @@ public abstract class MemoryBoard extends Board { while (iter.hasNext()) { Entry entry = iter.next(); if (!Factions.getInstance().isValidFactionId(entry.getValue())) { - P.p.log("Board cleaner removed " + entry.getValue() + " from " + entry.getKey()); + FactionsPlugin.getInstance().log("Board cleaner removed " + entry.getValue() + " from " + entry.getKey()); iter.remove(); } } @@ -194,12 +194,12 @@ public abstract class MemoryBoard extends Board { Faction faction = fplayer.getFaction(); ArrayList ret = new ArrayList<>(); Faction factionLoc = getFactionAt(flocation); - ret.add(new FancyMessage(ChatColor.DARK_GRAY + P.p.txt.titleize("(" + flocation.getCoordString() + ") " + factionLoc.getTag(fplayer)))); - int buffer = P.p.getConfig().getInt("world-border.buffer", 0); + ret.add(new FancyMessage(ChatColor.DARK_GRAY + FactionsPlugin.getInstance().txt.titleize("(" + flocation.getCoordString() + ") " + factionLoc.getTag(fplayer)))); + int buffer = FactionsPlugin.getInstance().getConfig().getInt("world-border.buffer", 0); // Get the compass - ArrayList asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.DARK_GREEN, P.p.txt.parse("")); + ArrayList asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.DARK_GREEN, FactionsPlugin.getInstance().txt.parse("")); int halfWidth = Conf.mapWidth / 2; // Use player's value for height @@ -286,16 +286,16 @@ public abstract class MemoryBoard extends Board { @SuppressWarnings("unused") private List getToolTip(Faction faction, FPlayer to) { List ret = new ArrayList<>(); - List show = P.p.getConfig().getStringList("map"); + List show = FactionsPlugin.getInstance().getConfig().getStringList("map"); if (!faction.isNormal()) { String tag = faction.getTag(to); // send header and that's all String header = show.get(0); if (TagReplacer.HEADER.contains(header)) { - ret.add(P.p.txt.titleize(tag)); + ret.add(FactionsPlugin.getInstance().txt.titleize(tag)); } else { - ret.add(P.p.txt.parse(TagReplacer.FACTION.replace(header, tag))); + ret.add(FactionsPlugin.getInstance().txt.parse(TagReplacer.FACTION.replace(header, tag))); } return ret; // we only show header for non-normal factions } @@ -315,7 +315,7 @@ public abstract class MemoryBoard extends Board { List fancy = TagUtil.parseFancy(faction, to, parsed); if (fancy != null) { for (FancyMessage msg : fancy) { - ret.add((P.p.txt.parse(msg.toOldMessageFormat()))); + ret.add((FactionsPlugin.getInstance().txt.parse(msg.toOldMessageFormat()))); } } continue; @@ -329,7 +329,7 @@ public abstract class MemoryBoard extends Board { if (parsed.contains("%")) { parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. } - ret.add(P.p.txt.parse(parsed)); + ret.add(FactionsPlugin.getInstance().txt.parse(parsed)); } } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index afa7366d..a78e2b6d 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -98,7 +98,7 @@ public abstract class MemoryFPlayer implements FPlayer { this.powerBoost = 0.0; this.getKills(); this.getDeaths(); - this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", false); + this.showScoreboard = FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-enabled", false); this.mapHeight = Conf.mapHeight; if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.getInstance().isValidFactionId(Conf.newPlayerStartingFactionID)) { @@ -127,7 +127,7 @@ public abstract class MemoryFPlayer implements FPlayer { this.getDeaths(); this.isAdminBypassing = other.isAdminBypassing; this.notificationsEnabled = other.notificationsEnabled; - this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", true); + this.showScoreboard = FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-enabled", true); this.mapHeight = Conf.mapHeight; } @@ -268,7 +268,7 @@ public abstract class MemoryFPlayer implements FPlayer { public void setAutoLeave(boolean willLeave) { this.willAutoLeave = willLeave; - P.p.debug(name + " set autoLeave to " + willLeave); + FactionsPlugin.getInstance().debug(name + " set autoLeave to " + willLeave); } public long getLastFrostwalkerMessage() { @@ -620,7 +620,7 @@ public abstract class MemoryFPlayer implements FPlayer { } PowerRegenEvent powerRegenEvent = new PowerRegenEvent(getFaction(), this); - Bukkit.getScheduler().runTask(P.p, () -> Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent)); + Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent)); if (!powerRegenEvent.isCancelled()) this.alterPower(millisPassed * Conf.powerPerMinute / 60000); // millisPerMinute : 60 * 1000 @@ -677,10 +677,10 @@ public abstract class MemoryFPlayer implements FPlayer { boolean showChat = true; if (showInfoBoard(toShow)) { FScoreboard.get(this).setTemporarySidebar(new FInfoSidebar(toShow)); - showChat = P.p.getConfig().getBoolean("scoreboard.also-send-chat", true); + showChat = FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.also-send-chat", true); } if (showChat) { - this.sendMessage(P.p.txt.parse(TL.FACTION_LEAVE.format(from.getTag(this), toShow.getTag(this)))); + this.sendMessage(FactionsPlugin.getInstance().txt.parse(TL.FACTION_LEAVE.format(from.getTag(this), toShow.getTag(this)))); } } @@ -695,7 +695,7 @@ public abstract class MemoryFPlayer implements FPlayer { * @return true if should show, otherwise false. */ public boolean showInfoBoard(Faction toShow) { - return showScoreboard && !toShow.isWarZone() && !toShow.isWilderness() && !toShow.isSafeZone() && P.p.getConfig().contains("scoreboard.finfo") && P.p.getConfig().getBoolean("scoreboard.finfo-enabled", false) && FScoreboard.get(this) != null; + return showScoreboard && !toShow.isWarZone() && !toShow.isWilderness() && !toShow.isSafeZone() && FactionsPlugin.getInstance().getConfig().contains("scoreboard.finfo") && FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.finfo-enabled", false) && FScoreboard.get(this) != null; } @Override @@ -759,7 +759,7 @@ public abstract class MemoryFPlayer implements FPlayer { } if (Conf.logFactionLeave) { - P.p.log(TL.LEAVE_LEFT.format(this.getName(), myFaction.getTag())); + FactionsPlugin.getInstance().log(TL.LEAVE_LEFT.format(this.getName(), myFaction.getTag())); } } @@ -784,7 +784,7 @@ public abstract class MemoryFPlayer implements FPlayer { Factions.getInstance().removeFaction(myFaction.getId()); if (Conf.logFactionDisband) { - P.p.log(TL.LEAVE_DISBANDEDLOG.format(myFaction.getTag(), myFaction.getId(), this.getName())); + FactionsPlugin.getInstance().log(TL.LEAVE_DISBANDEDLOG.format(myFaction.getTag(), myFaction.getId(), this.getName())); } } } @@ -802,16 +802,16 @@ public abstract class MemoryFPlayer implements FPlayer { Faction myFaction = getFaction(); Faction currentFaction = Board.getInstance().getFactionAt(flocation); int ownedLand = forFaction.getLandRounded(); - int factionBuffer = P.p.getConfig().getInt("hcf.buffer-zone", 0); - int worldBuffer = P.p.getConfig().getInt("world-border.buffer", 0); + int factionBuffer = FactionsPlugin.getInstance().getConfig().getInt("hcf.buffer-zone", 0); + int worldBuffer = FactionsPlugin.getInstance().getConfig().getInt("world-border.buffer", 0); if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(flocation)) { // Checks for WorldGuard regions in the chunk attempting to be claimed - error = P.p.txt.parse(TL.CLAIM_PROTECTED.toString()); - } else if (flocation.isOutsideWorldBorder(P.p.getConfig().getInt("world-border.buffer", 0))) { - error = P.p.txt.parse(TL.CLAIM_OUTSIDEWORLDBORDER.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_PROTECTED.toString()); + } else if (flocation.isOutsideWorldBorder(FactionsPlugin.getInstance().getConfig().getInt("world-border.buffer", 0))) { + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_OUTSIDEWORLDBORDER.toString()); } else if (Conf.useWorldConfigurationsAsWhitelist != Conf.worldsNoClaiming.contains(flocation.getWorldName())) { - error = P.p.txt.parse(TL.CLAIM_DISABLED.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_DISABLED.toString()); } else if (this.isAdminBypassing()) { return true; } else if (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) { @@ -821,50 +821,50 @@ public abstract class MemoryFPlayer implements FPlayer { } else if (currentFaction.getAccess(this, PermissableAction.TERRITORY) == Access.ALLOW) { return true; } else if (myFaction != forFaction) { - error = P.p.txt.parse(TL.CLAIM_CANTCLAIM.toString(), forFaction.describeTo(this)); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_CANTCLAIM.toString(), forFaction.describeTo(this)); } else if (forFaction == currentFaction) { - error = P.p.txt.parse(TL.CLAIM_ALREADYOWN.toString(), forFaction.describeTo(this, true)); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_ALREADYOWN.toString(), forFaction.describeTo(this, true)); } else if (this.getRole().value < Role.MODERATOR.value) { - error = P.p.txt.parse(TL.CLAIM_MUSTBE.toString(), Role.MODERATOR.getTranslation()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_MUSTBE.toString(), Role.MODERATOR.getTranslation()); } else if (forFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers) { - error = P.p.txt.parse(TL.CLAIM_MEMBERS.toString(), Conf.claimsRequireMinFactionMembers); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_MEMBERS.toString(), Conf.claimsRequireMinFactionMembers); } else if (currentFaction.isSafeZone()) { - error = P.p.txt.parse(TL.CLAIM_SAFEZONE.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_SAFEZONE.toString()); } else if (currentFaction.isWarZone()) { - error = P.p.txt.parse(TL.CLAIM_WARZONE.toString()); - } else if (P.p.getConfig().getBoolean("hcf.allow-overclaim", true) && ownedLand >= forFaction.getPowerRounded()) { - error = P.p.txt.parse(TL.CLAIM_POWER.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_WARZONE.toString()); + } else if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.allow-overclaim", true) && ownedLand >= forFaction.getPowerRounded()) { + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_POWER.toString()); } else if (Conf.claimedLandsMax != 0 && ownedLand >= Conf.claimedLandsMax && forFaction.isNormal()) { - error = P.p.txt.parse(TL.CLAIM_LIMIT.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_LIMIT.toString()); } else if (currentFaction.getRelationTo(forFaction) == Relation.ALLY) { - error = P.p.txt.parse(TL.CLAIM_ALLY.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_ALLY.toString()); } else if (Conf.claimsMustBeConnected && !this.isAdminBypassing() && myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.getInstance().isConnectedLocation(flocation, myFaction) && (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())) { if (Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction) { - error = P.p.txt.parse(TL.CLAIM_CONTIGIOUS.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_CONTIGIOUS.toString()); } else { - error = P.p.txt.parse(TL.CLAIM_FACTIONCONTIGUOUS.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_FACTIONCONTIGUOUS.toString()); } } else if (factionBuffer > 0 && Board.getInstance().hasFactionWithin(flocation, myFaction, factionBuffer)) { - error = P.p.txt.parse(TL.CLAIM_TOOCLOSETOOTHERFACTION.format(factionBuffer)); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_TOOCLOSETOOTHERFACTION.format(factionBuffer)); } else if (flocation.isOutsideWorldBorder(worldBuffer)) { if (worldBuffer > 0) { - error = P.p.txt.parse(TL.CLAIM_OUTSIDEBORDERBUFFER.format(worldBuffer)); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_OUTSIDEBORDERBUFFER.format(worldBuffer)); } else { - error = P.p.txt.parse(TL.CLAIM_OUTSIDEWORLDBORDER.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_OUTSIDEWORLDBORDER.toString()); } } else if (currentFaction.isNormal()) { if (myFaction.isPeaceful()) { - error = P.p.txt.parse(TL.CLAIM_PEACEFUL.toString(), currentFaction.getTag(this)); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_PEACEFUL.toString(), currentFaction.getTag(this)); } else if (currentFaction.isPeaceful()) { - error = P.p.txt.parse(TL.CLAIM_PEACEFULTARGET.toString(), currentFaction.getTag(this)); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_PEACEFULTARGET.toString(), currentFaction.getTag(this)); } else if (!currentFaction.hasLandInflation()) { // TODO more messages WARN current faction most importantly - error = P.p.txt.parse(TL.CLAIM_THISISSPARTA.toString(), currentFaction.getTag(this)); - } else if (currentFaction.hasLandInflation() && !P.p.getConfig().getBoolean("hcf.allow-overclaim", true)) { + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_THISISSPARTA.toString(), currentFaction.getTag(this)); + } else if (currentFaction.hasLandInflation() && !FactionsPlugin.getInstance().getConfig().getBoolean("hcf.allow-overclaim", true)) { // deny over claim when it normally would be allowed. - error = P.p.txt.parse(TL.CLAIM_OVERCLAIM_DISABLED.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_OVERCLAIM_DISABLED.toString()); } else if (!Board.getInstance().isBorderLocation(flocation)) { - error = P.p.txt.parse(TL.CLAIM_BORDER.toString()); + error = FactionsPlugin.getInstance().txt.parse(TL.CLAIM_BORDER.toString()); } } // TODO: Add more else if statements. @@ -885,7 +885,7 @@ public abstract class MemoryFPlayer implements FPlayer { } public void msg(String str, Object... args) { - this.sendMessage(P.p.txt.parse(str, args)); + this.sendMessage(FactionsPlugin.getInstance().txt.parse(str, args)); } public void msg(TL translation, Object... args) { @@ -928,7 +928,7 @@ public abstract class MemoryFPlayer implements FPlayer { if (!damage) { msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled"); if (!fly) { - sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", P.p.getConfig().getInt("fly-falldamage-cooldown", 3) + "")); + sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + "")); } } else { @@ -937,7 +937,7 @@ public abstract class MemoryFPlayer implements FPlayer { // If leaving fly mode, don't let them take fall damage for x seconds. if (!fly) { - int cooldown = P.p.getConfig().getInt("fly-falldamage-cooldown", 3); + int cooldown = FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3); CmdFly.flyMap.remove(player.getName()); // If the value is 0 or lower, make them take fall damage. @@ -945,7 +945,7 @@ public abstract class MemoryFPlayer implements FPlayer { // Short task so we're just doing it in method. Not clean but eh. if (cooldown > 0) { setTakeFallDamage(false); - Bukkit.getScheduler().runTaskLater(P.p, () -> setTakeFallDamage(true), 20L * cooldown); + Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> setTakeFallDamage(true), 20L * cooldown); } } @@ -1226,7 +1226,7 @@ public abstract class MemoryFPlayer implements FPlayer { } LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this); - Bukkit.getScheduler().runTask(P.p, () -> Bukkit.getPluginManager().callEvent(claimEvent)); + Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(claimEvent)); if (claimEvent.isCancelled()) { return false; } @@ -1253,7 +1253,7 @@ public abstract class MemoryFPlayer implements FPlayer { Board.getInstance().setFactionAt(forFaction, flocation); if (Conf.logLandClaims) { - P.p.log(TL.CLAIM_CLAIMEDLOG.toString(), this.getName(), flocation.getCoordString(), forFaction.getTag()); + FactionsPlugin.getInstance().log(TL.CLAIM_CLAIMEDLOG.toString(), this.getName(), flocation.getCoordString(), forFaction.getTag()); } return true; @@ -1281,7 +1281,7 @@ public abstract class MemoryFPlayer implements FPlayer { @Override public boolean hasMoney(int amt) { - Economy econ = P.p.getEcon(); + Economy econ = FactionsPlugin.getInstance().getEcon(); if (econ.getBalance(getPlayer()) >= amt) { return true; } else { @@ -1299,7 +1299,7 @@ public abstract class MemoryFPlayer implements FPlayer { @Override public void takeMoney(int amt) { if (hasMoney(amt)) { - Economy econ = P.p.getEcon(); + Economy econ = FactionsPlugin.getInstance().getEcon(); econ.withdrawPlayer(getPlayer(), amt); sendMessage(TL.GENERIC_MONEYTAKE.toString().replace("{amount}", commas(amt))); } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayers.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayers.java index 708baf32..3999de39 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayers.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayers.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.zcore.persist; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -17,7 +17,7 @@ public abstract class MemoryFPlayers extends FPlayers { public void clean() { for (FPlayer fplayer : this.fPlayers.values()) { if (!Factions.getInstance().isValidFactionId(fplayer.getFactionId())) { - P.p.log("Reset faction data (invalid faction:" + fplayer.getFactionId() + ") for player " + fplayer.getName()); + FactionsPlugin.getInstance().log("Reset faction data (invalid faction:" + fplayer.getFactionId() + ") for player " + fplayer.getName()); fplayer.resetFactionData(false); } } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index d7ec42c6..58e51761 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -325,7 +325,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { if (Conf.logFactionDisband) { //TODO: Format this correctly and translate. - P.p.log("The faction " + this.getTag() + " (" + this.getId() + ") was disbanded by " + (disbanderIsConsole ? "console command" : fdisbander.getName()) + "."); + FactionsPlugin.getInstance().log("The faction " + this.getTag() + " (" + this.getId() + ") was disbanded by " + (disbanderIsConsole ? "console command" : fdisbander.getName()) + "."); } if (Econ.shouldBeUsed() && !disbanderIsConsole) { @@ -341,7 +341,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { String amountString = Econ.moneyString(amount); msg(TL.COMMAND_DISBAND_HOLDINGS, amountString); //TODO: Format this correctly and translate - P.p.log(fdisbander.getName() + " has been given bank holdings of " + amountString + " from disbanding " + this.getTag() + "."); + FactionsPlugin.getInstance().log(fdisbander.getName() + " has been given bank holdings of " + amountString + " from disbanding " + this.getTag() + "."); } } } @@ -425,16 +425,16 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { int size = 9; switch (getUpgrade(UpgradeType.CHEST)) { case 1: - size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-1") * 9; + size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-1") * 9; break; case 2: - size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-2") * 9; + size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-2") * 9; break; case 3: - size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3") * 9; + size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3") * 9; break; } - chest = Bukkit.createInventory(null, size, P.p.color(P.p.getConfig().getString("fchest.Inventory-Title"))); + chest = Bukkit.createInventory(null, size, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title"))); return chest; } @@ -442,7 +442,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { @Override public void setChestSize(int chestSize) { ItemStack[] contents = this.getChestInventory().getContents(); - chest = Bukkit.createInventory(null, chestSize, P.p.color(P.p.getConfig().getString("fchest.Inventory-Title"))); + chest = Bukkit.createInventory(null, chestSize, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title"))); chest.setContents(contents); } @@ -658,7 +658,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { } public boolean isPowerFrozen() { - int freezeSeconds = P.p.getConfig().getInt("hcf.powerfreeze", 0); + int freezeSeconds = FactionsPlugin.getInstance().getConfig().getInt("hcf.powerfreeze", 0); return freezeSeconds != 0 && System.currentTimeMillis() - lastDeath < freezeSeconds * 1000; } @@ -743,7 +743,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { } public void resetPerms() { - P.p.log(Level.WARNING, "Resetting permissions for Faction: " + tag); + FactionsPlugin.getInstance().log(Level.WARNING, "Resetting permissions for Faction: " + tag); permissions.clear(); @@ -880,7 +880,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { if (this.relationWish.containsKey(otherFaction.getId())) { return this.relationWish.get(otherFaction.getId()); } - return Relation.fromString(P.p.getConfig().getString("default-relation", "neutral")); // Always default to old behavior. + return Relation.fromString(FactionsPlugin.getInstance().getConfig().getString("default-relation", "neutral")); // Always default to old behavior. } public void setRelationWish(Faction otherFaction, Relation relation) { @@ -1086,7 +1086,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { return ret; } - for (Player player : P.p.getServer().getOnlinePlayers()) { + for (Player player : FactionsPlugin.getInstance().getServer().getOnlinePlayers()) { FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); if (fplayer.getFaction() == this && !fplayer.isAlt()) { ret.add(player); @@ -1104,7 +1104,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { return false; } - for (Player player : P.p.getServer().getOnlinePlayers()) { + for (Player player : FactionsPlugin.getInstance().getServer().getOnlinePlayers()) { FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); if (fplayer != null && fplayer.getFaction() == this) { return true; @@ -1156,7 +1156,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { // no members left and faction isn't permanent, so disband it if (Conf.logFactionDisband) { - P.p.log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left" + (autoLeave ? " and by inactivity" : "") + "."); + FactionsPlugin.getInstance().log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left" + (autoLeave ? " and by inactivity" : "") + "."); } for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { @@ -1174,7 +1174,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { replacements.get(0).setRole(Role.LEADER); //TODO:TL this.msg("Faction admin %s has been removed. %s has been promoted as the new faction admin.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName()); - P.p.log("Faction " + this.getTag() + " (" + this.getId() + ") admin was removed. Replacement admin: " + replacements.get(0).getName()); + FactionsPlugin.getInstance().log("Faction " + this.getTag() + " (" + this.getId() + ") admin was removed. Replacement admin: " + replacements.get(0).getName()); } } @@ -1182,7 +1182,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { // Messages // ----------------------------------------------// public void msg(String message, Object... args) { - message = P.p.txt.parse(message, args); + message = FactionsPlugin.getInstance().txt.parse(message, args); for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) { fplayer.sendMessage(message); diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/json/FactionsJSON.java b/src/main/java/com/massivecraft/factions/zcore/persist/json/FactionsJSON.java index 2cc1c833..442514bc 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/json/FactionsJSON.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/json/FactionsJSON.java @@ -23,7 +23,7 @@ public class FactionsJSON { new BukkitRunnable() { @Override public void run() { - Logger logger = P.p.getLogger(); + Logger logger = FactionsPlugin.getInstance().getLogger(); logger.info("Beginning Board conversion to JSON"); new JSONBoard().convertFrom((MemoryBoard) Board.getInstance()); logger.info("Board Converted"); @@ -40,6 +40,6 @@ public class FactionsJSON { } logger.info("Conversion Complete"); } - }.runTaskAsynchronously(P.p); + }.runTaskAsynchronously(FactionsPlugin.getInstance()); } } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONBoard.java b/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONBoard.java index 53b40aad..b0baaf3e 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONBoard.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.zcore.persist.json; import com.google.gson.reflect.TypeToken; import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.persist.MemoryBoard; import com.massivecraft.factions.zcore.util.DiscUtil; @@ -16,7 +16,7 @@ import java.util.TreeMap; public class JSONBoard extends MemoryBoard { - private static transient File file = new File(P.p.getDataFolder(), "board.json"); + private static transient File file = new File(FactionsPlugin.getInstance().getDataFolder(), "board.json"); // -------------------------------------------- // // Persistance @@ -67,14 +67,14 @@ public class JSONBoard extends MemoryBoard { } public void forceSave(boolean sync) { - DiscUtil.writeCatch(file, P.p.gson.toJson(dumpAsSaveFormat()), sync); + DiscUtil.writeCatch(file, FactionsPlugin.getInstance().gson.toJson(dumpAsSaveFormat()), sync); } public boolean load() { - P.p.log("Loading board from disk"); + FactionsPlugin.getInstance().log("Loading board from disk"); if (!file.exists()) { - P.p.log("No board to load from disk. Creating new file."); + FactionsPlugin.getInstance().log("No board to load from disk. Creating new file."); forceSave(); return true; } @@ -82,12 +82,12 @@ public class JSONBoard extends MemoryBoard { try { Type type = new TypeToken>>() { }.getType(); - Map> worldCoordIds = P.p.gson.fromJson(DiscUtil.read(file), type); + Map> worldCoordIds = FactionsPlugin.getInstance().gson.fromJson(DiscUtil.read(file), type); loadFromSaveFormat(worldCoordIds); - P.p.log("Loaded " + flocationIds.size() + " board locations"); + FactionsPlugin.getInstance().log("Loaded " + flocationIds.size() + " board locations"); } catch (Exception e) { e.printStackTrace(); - P.p.log("Failed to load the board from disk."); + FactionsPlugin.getInstance().log("Failed to load the board from disk."); return false; } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFPlayers.java b/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFPlayers.java index 292f01f2..677c062e 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFPlayers.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFPlayers.java @@ -6,7 +6,7 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.persist.MemoryFPlayer; import com.massivecraft.factions.zcore.persist.MemoryFPlayers; import com.massivecraft.factions.zcore.util.DiscUtil; @@ -26,8 +26,8 @@ public class JSONFPlayers extends MemoryFPlayers { private File file; public JSONFPlayers() { - file = new File(P.p.getDataFolder(), "players.json"); - gson = P.p.gson; + file = new File(FactionsPlugin.getInstance().getDataFolder(), "players.json"); + gson = FactionsPlugin.getInstance().gson; } public Gson getGson() { @@ -75,7 +75,7 @@ public class JSONFPlayers extends MemoryFPlayers { } this.fPlayers.clear(); this.fPlayers.putAll(fplayers); - P.p.log("Loaded " + fPlayers.size() + " players"); + FactionsPlugin.getInstance().log("Loaded " + fPlayers.size() + " players"); } private Map loadCore() { diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFactions.java b/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFactions.java index 8cdd06c3..a3bfe2a5 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFactions.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/json/JSONFactions.java @@ -7,7 +7,7 @@ import com.google.gson.reflect.TypeToken; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.persist.MemoryFaction; import com.massivecraft.factions.zcore.persist.MemoryFactions; import com.massivecraft.factions.zcore.util.DiscUtil; @@ -26,8 +26,8 @@ public class JSONFactions extends MemoryFactions { private final File file; public JSONFactions() { - this.file = new File(P.p.getDataFolder(), "factions.json"); - this.gson = P.p.gson; + this.file = new File(FactionsPlugin.getInstance().getDataFolder(), "factions.json"); + this.gson = FactionsPlugin.getInstance().gson; this.nextId = 1; } @@ -68,7 +68,7 @@ public class JSONFactions extends MemoryFactions { this.factions.putAll(factions); super.load(); - P.p.log("Loaded " + factions.size() + " Factions"); + FactionsPlugin.getInstance().log("Loaded " + factions.size() + " Factions"); } private Map loadCore() { diff --git a/src/main/java/com/massivecraft/factions/zcore/util/DiscUtil.java b/src/main/java/com/massivecraft/factions/zcore/util/DiscUtil.java index 9485f166..ffb83178 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/DiscUtil.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/DiscUtil.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.zcore.util; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import org.bukkit.Bukkit; import java.io.*; @@ -80,7 +80,7 @@ public class DiscUtil { lock.unlock(); } } else { - Bukkit.getScheduler().runTaskAsynchronously(P.p, () -> { + Bukkit.getScheduler().runTaskAsynchronously(FactionsPlugin.getInstance(), () -> { lock.lock(); try { write(file, content); diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index bb146989..a009d7f2 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -59,6 +59,7 @@ public enum TL { /** * Command translations */ + COMMAND_USEAGE_TEMPLATE_COLOR("&c"), /** * Messsges for /f help @@ -113,6 +114,11 @@ public enum TL { * Messsges for Faction Admins/Mods */ + COMMAND_CONTEXT_ADMINISTER_DIF_FACTION("&c[!] %1$s is not in the same faction as you."), + COMMAND_CONTEXT_ADMINISTER_ADMIN_REQUIRED("&c[!] Only the faction admin can do that."), + COMMAND_CONTEXT_ADMINISTER_SAME_RANK_CONTROL("&c[!] Moderators can't control each other..."), + COMMAND_CONTEXT_ADMINISTER_MOD_REQUIRED("&c[!] You must be a faction moderator to do that."), + COMMAND_UPGRADES_DESCRIPTION("&cOpen the Upgrades Menu"), COMMAND_CORNER_CANT_CLAIM("&c&l[!] &cYou may not claim this corner!"), COMMAND_CORNER_CLAIMED("\n&2&l[!] &aYou have claimed the corner successfully, totalling in &b%1$d &achunks!\n"), @@ -139,7 +145,6 @@ public enum TL { COMMAND_ANNOUNCE_DESCRIPTION("Announce a message to players in faction."), COMMAND_ALTS_DESCRIPTION("Faction Alts Commands"), - COMMAND_STRIKE_DESCRIPTION("Faction Strike Commands"), COMMAND_ALTS_LIST_DESCRIPTION("List all alts in your faction"), @@ -689,25 +694,24 @@ public enum TL { COMMAND_SETHOME_SET("&c&l[!]&c %1$s&7 set the home for your faction. You can now use:"), COMMAND_SETHOME_SETOTHER("&c&l[!]&7 You have set the home for the &c%1$s&7 faction."), COMMAND_SETHOME_DESCRIPTION("Set the faction home"), - COMMAND_STRIKE_FACTION("View Factions Strikes"), COMMAND_SETMAXVAULTS_DESCRIPTION("Set max vaults for a Faction."), COMMAND_SETMAXVAULTS_SUCCESS("&aSet max vaults for &e%s &ato &b%d"), COMMAND_ONCOOOLDOWN("&c&l[!] &7You cannot use this command for another &b%1$s &7seconds."), - COMMAND_SETSTRIKES_FAILURE("&c&l[!]&7 &c{faction} does not exist."), - COMMAND_SETSTRIKES_BROADCAST("&c&l[!]&7 &c{faction} has received a strike for {reason}"), - COMMAND_SETSTRIKES_SUCCESS("&c&l[!]&7 &c{faction}'s&7 new strikes are &c{strikes}"), - COMMAND_SETSTRIKES_DESCRIPTION("Set a faction's strikes"), - COMMAND_STRIKEREMOVE_DESCRIPTION("Remove a faction's strikes"), - COMMAND_STRIKE_MESSAGE("&c&l[!] &7{faction} has {strikes} strikes."), - COMMAND_STRIKE_NOTFOUND("&c&l[!] &7{faction} does not exist."), - COMMAND_STRIKE_NEEDFACTION("&c&l[!] &7&cYou need to join a faction to view your own!"), + COMMAND_STRIKES_CHANGED("&c&l[!] &7You have set &c%1$s's &7strikes to &c%2$s"), + COMMAND_STRIKES_INFO("&c&l[!] &7%1$s has %2$s strikes"), + COMMAND_STRIKES_TARGET_INVALID("&c&l[!] &7The faction %1$s is invalid."), + COMMAND_STRIKES_STRUCK("&c&l[!] &7Your faction strikes have changed by &c%1$s &7strike(s)! Your faction now has &c%2$s/%3$s"), + COMMAND_STRIKES_DESCRIPTION("Set strikes on factions to warn them"), + COMMAND_STRIKESGIVE_DESCRIPTION("Give a faction 1 strike"), + COMMAND_STRIKETAKE_DESCRIPTION("Take a strike from a faction"), + COMMAND_STRIKESET_DESCRIPTION("Set a faction's strikes explicitly."), + COMMAND_STRIKESINFO_DESCRIPTION("Get a faction's strikes"), SHOP_NOT_ENOUGH_POINTS("&c&l[!] &7Your faction does not have enough points to purchase this!"), SHOP_BOUGHT_BROADCAST_FACTION("\n&c&l[!] &e&lFactionShop » &b{player} &7bought &b{item}&7!\n"), - COMMAND_STRIKEGIVE_DESCRIPTION("Give a faction strikes"), COMMAND_VIEWCHEST_DESCRIPTION("view a factions chest/pv"), @@ -826,6 +830,8 @@ public enum TL { COMMAND_TNT_DISABLED_MSG("&cThis command is disabled!"), COMMAND_TNT_INVALID_NUM("The amount needs to be a number!"), + COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT("&cNot enough tnt in bank."), + COMMAND_TNTFILL_NODISPENSERS("&c&l[!] &7No dispensers were found in a radius of {radius} blocks."), COMMAND_TNT_DEPOSIT_SUCCESS("&cSuccessfully deposited tnt."), COMMAND_TNT_EXCEEDLIMIT("&cThis exceeds the bank limit!"), COMMAND_TNT_WIDTHDRAW_SUCCESS("&cSuccessfully withdrew tnt."), @@ -848,6 +854,7 @@ public enum TL { COMMAND_UNBAN_DESCRIPTION("Unban someone from your Faction"), COMMAND_UNBAN_NOTBANNED("&7%s &cisn't banned. Not doing anything."), + COMMAND_UNBAN_TARGET_IN_OTHER_FACTION("&c%1$s is not in your faction!"), COMMAND_UNBAN_UNBANNED("&e%1$s &cunbanned &7%2$s"), COMMAND_UNBAN_TARGET("&aYou were unbanned from &r%s"), @@ -974,6 +981,10 @@ public enum TL { GENERIC_PLACEHOLDER(""), GENERIC_NOTENOUGHMONEY("&cYou dont have enough money!"), GENERIC_MONEYTAKE("&c{amount} has been taken from your account."), + GENERIC_FPERM_OWNER_NOPERMISSION("&7This land is ownerclaimed, you need to be an owner to %1$s it."), + GENERIC_NOFACTION_FOUND("&cCouldn't find a faction with that name!"), + GENERIC_YOUMUSTBE("&cYour must be atleast %1$s to do this!"), + GENERIC_MEMBERONLY("&cYou must be in a faction to do this!"), MISSION_MISSION_STARTED("&f%1$s &dstarted the %2$s &fmission"), diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java b/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java index 1324b020..72ee09c7 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java @@ -126,22 +126,22 @@ public enum TagReplacer { case FACTIONLESS: return String.valueOf(FPlayers.getInstance().getAllFPlayers().stream().filter(p -> !p.hasFaction()).count()); case MAX_ALLIES: - if (P.p.getConfig().getBoolean("max-relations.enabled", true)) { - return String.valueOf(P.p.getConfig().getInt("max-relations.ally", 10)); + if (FactionsPlugin.getInstance().getConfig().getBoolean("max-relations.enabled", true)) { + return String.valueOf(FactionsPlugin.getInstance().getConfig().getInt("max-relations.ally", 10)); } return TL.GENERIC_INFINITY.toString(); case MAX_ENEMIES: - if (P.p.getConfig().getBoolean("max-relations.enabled", true)) { - return String.valueOf(P.p.getConfig().getInt("max-relations.enemy", 10)); + if (FactionsPlugin.getInstance().getConfig().getBoolean("max-relations.enabled", true)) { + return String.valueOf(FactionsPlugin.getInstance().getConfig().getInt("max-relations.enemy", 10)); } return TL.GENERIC_INFINITY.toString(); case MAX_TRUCES: - if (P.p.getConfig().getBoolean("max-relations.enabled", true)) { - return String.valueOf(P.p.getConfig().getInt("max-relations.truce", 10)); + if (FactionsPlugin.getInstance().getConfig().getBoolean("max-relations.enabled", true)) { + return String.valueOf(FactionsPlugin.getInstance().getConfig().getInt("max-relations.truce", 10)); } return TL.GENERIC_INFINITY.toString(); case MAX_WARPS: - return String.valueOf(P.p.getConfig().getInt("max-warps", 5)); + return String.valueOf(FactionsPlugin.getInstance().getConfig().getInt("max-warps", 5)); default: } return null; @@ -159,12 +159,12 @@ public enum TagReplacer { return getValue(); } - boolean minimal = P.p.getConfig().getBoolean("minimal-show", false); + boolean minimal = FactionsPlugin.getInstance().getConfig().getBoolean("minimal-show", false); if (fp != null) { switch (this) { case HEADER: - return P.p.txt.titleize(fac.getTag(fp)); + return FactionsPlugin.getInstance().txt.titleize(fac.getTag(fp)); case PLAYER_NAME: return fp.getName(); case FACTION: @@ -173,7 +173,7 @@ public enum TagReplacer { String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX; return fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized); case PLAYER_GROUP: - return P.p.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fp.getId()))); + return FactionsPlugin.getInstance().getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fp.getId()))); case PLAYER_BALANCE: return Econ.isSetup() ? Econ.getFriendlyBalance(fp) : TL.ECON_OFF.format("balance"); case PLAYER_POWER: @@ -216,7 +216,7 @@ public enum TagReplacer { case CREATE_DATE: return TL.sdf.format(fac.getFoundedDate()); case RAIDABLE: - boolean raid = P.p.getConfig().getBoolean("hcf.raidable", false) && fac.getLandRounded() >= fac.getPowerRounded(); + boolean raid = FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && fac.getLandRounded() >= fac.getPowerRounded(); return raid ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString(); case HOME_WORLD: return fac.hasHome() ? fac.getHome().getWorld().getName() : minimal ? null : "{ig}"; diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java b/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java index 8469a6ce..bfa4e215 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java @@ -4,7 +4,7 @@ package com.massivecraft.factions.zcore.util; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.P; +import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.MiscUtil; import me.clip.placeholderapi.PlaceholderAPI; @@ -98,11 +98,11 @@ public class TagUtil { } public static String parsePlaceholders(Player player, String line) { - if (P.p.isClipPlaceholderAPIHooked() && player.isOnline()) { + if (FactionsPlugin.getInstance().isClipPlaceholderAPIHooked() && player.isOnline()) { line = PlaceholderAPI.setPlaceholders(player, line); } - if (P.p.isMVdWPlaceholderAPIHooked() && player.isOnline()) { + if (FactionsPlugin.getInstance().isMVdWPlaceholderAPIHooked() && player.isOnline()) { line = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, line); } @@ -134,11 +134,11 @@ public class TagUtil { */ protected static List getFancy(Faction target, FPlayer fme, TagReplacer type, String prefix) { List fancyMessages = new ArrayList<>(); - boolean minimal = P.p.getConfig().getBoolean("minimal-show", false); + boolean minimal = FactionsPlugin.getInstance().getConfig().getBoolean("minimal-show", false); switch (type) { case ALLIES_LIST: - FancyMessage currentAllies = P.p.txt.parseFancy(prefix); + FancyMessage currentAllies = FactionsPlugin.getInstance().txt.parseFancy(prefix); boolean firstAlly = true; for (Faction otherFaction : Factions.getInstance().getAllFactions()) { if (otherFaction == target) { @@ -158,7 +158,7 @@ public class TagUtil { fancyMessages.add(currentAllies); return firstAlly && minimal ? null : fancyMessages; // we must return here and not outside the switch case ENEMIES_LIST: - FancyMessage currentEnemies = P.p.txt.parseFancy(prefix); + FancyMessage currentEnemies = FactionsPlugin.getInstance().txt.parseFancy(prefix); boolean firstEnemy = true; for (Faction otherFaction : Factions.getInstance().getAllFactions()) { if (otherFaction == target) { @@ -178,7 +178,7 @@ public class TagUtil { fancyMessages.add(currentEnemies); return firstEnemy && minimal ? null : fancyMessages; // we must return here and not outside the switch case TRUCES_LIST: - FancyMessage currentTruces = P.p.txt.parseFancy(prefix); + FancyMessage currentTruces = FactionsPlugin.getInstance().txt.parseFancy(prefix); boolean firstTruce = true; for (Faction otherFaction : Factions.getInstance().getAllFactions()) { if (otherFaction == target) { @@ -198,7 +198,7 @@ public class TagUtil { fancyMessages.add(currentTruces); return firstTruce && minimal ? null : fancyMessages; // we must return here and not outside the switch case ONLINE_LIST: - FancyMessage currentOnline = P.p.txt.parseFancy(prefix); + FancyMessage currentOnline = FactionsPlugin.getInstance().txt.parseFancy(prefix); boolean firstOnline = true; for (FPlayer p : MiscUtil.rankOrder(target.getFPlayersWhereOnline(true, fme))) { if (fme != null && fme.getPlayer() != null && !fme.getPlayer().canSee(p.getPlayer())) { @@ -216,7 +216,7 @@ public class TagUtil { fancyMessages.add(currentOnline); return firstOnline && minimal ? null : fancyMessages; // we must return here and not outside the switch case OFFLINE_LIST: - FancyMessage currentOffline = P.p.txt.parseFancy(prefix); + FancyMessage currentOffline = FactionsPlugin.getInstance().txt.parseFancy(prefix); boolean firstOffline = true; for (FPlayer p : MiscUtil.rankOrder(target.getFPlayers())) { String name = p.getNameAndTitle(); @@ -234,7 +234,7 @@ public class TagUtil { fancyMessages.add(currentOffline); return firstOffline && minimal ? null : fancyMessages; // we must return here and not outside the switch case ALTS: - FancyMessage alts = P.p.txt.parseFancy(prefix); + FancyMessage alts = FactionsPlugin.getInstance().txt.parseFancy(prefix); boolean firstAlt = true; for (FPlayer p : target.getAltPlayers()) { String name = p.getName(); @@ -271,7 +271,7 @@ public class TagUtil { */ private static List tipFaction(Faction faction) { List lines = new ArrayList<>(); - for (String line : P.p.getConfig().getStringList("tooltips.list")) { + for (String line : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.list")) { lines.add(ChatColor.translateAlternateColorCodes('&', TagUtil.parsePlain(faction, line))); } return lines; @@ -285,7 +285,7 @@ public class TagUtil { */ private static List tipPlayer(FPlayer fplayer) { List lines = new ArrayList<>(); - for (String line : P.p.getConfig().getStringList("tooltips.show")) { + for (String line : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.show")) { lines.add(ChatColor.translateAlternateColorCodes('&', TagUtil.parsePlain(fplayer, line))); } return lines; diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TextUtil.java b/src/main/java/com/massivecraft/factions/zcore/util/TextUtil.java index 74df651c..6c4fe525 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TextUtil.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TextUtil.java @@ -106,7 +106,7 @@ public class TextUtil { // -------------------------------------------- // public static String parseColorAcc(String string) { - return string.replace("`e", "").replace("`r", ChatColor.RED.toString()).replace("`R", ChatColor.DARK_RED.toString()).replace("`y", ChatColor.YELLOW.toString()).replace("`Y", ChatColor.GOLD.toString()).replace("`g", ChatColor.GREEN.toString()).replace("`G", ChatColor.DARK_GREEN.toString()).replace("`a", ChatColor.AQUA.toString()).replace("`A", ChatColor.DARK_AQUA.toString()).replace("`b", ChatColor.BLUE.toString()).replace("`B", ChatColor.DARK_BLUE.toString()).replace("`plugin", ChatColor.LIGHT_PURPLE.toString()).replace("`P", ChatColor.DARK_PURPLE.toString()).replace("`k", ChatColor.BLACK.toString()).replace("`s", ChatColor.GRAY.toString()).replace("`S", ChatColor.DARK_GRAY.toString()).replace("`w", ChatColor.WHITE.toString()); + return string.replace("`e", "").replace("`r", ChatColor.RED.toString()).replace("`R", ChatColor.DARK_RED.toString()).replace("`y", ChatColor.YELLOW.toString()).replace("`Y", ChatColor.GOLD.toString()).replace("`g", ChatColor.GREEN.toString()).replace("`G", ChatColor.DARK_GREEN.toString()).replace("`a", ChatColor.AQUA.toString()).replace("`A", ChatColor.DARK_AQUA.toString()).replace("`b", ChatColor.BLUE.toString()).replace("`B", ChatColor.DARK_BLUE.toString()).replace("`plugin", ChatColor.LIGHT_PURPLE.toString()).replace("`FactionsPlugin", ChatColor.DARK_PURPLE.toString()).replace("`k", ChatColor.BLACK.toString()).replace("`s", ChatColor.GRAY.toString()).replace("`S", ChatColor.DARK_GRAY.toString()).replace("`w", ChatColor.WHITE.toString()); } public static String parseColorTags(String string) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3ceba768..cfa00f06 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1040,17 +1040,22 @@ fupgrades: slots: - 22 +############################################################ +# +------------------------------------------------------+ # +# | Faction Banners | # +# +------------------------------------------------------+ # +############################################################ fbanners: - Enabled: false + Enabled: true Item: - Name: '&e&l*&f&l*&e&l* &c&lWar Banner &7(Place) &e&l*&f&l*&e&l*' + Name: '&c&l*&f&l*&c&l* &c&lWar Banner &7(Place) &c&l*&f&l*&c&l*' Lore: - '&7Place this banner in the &nWarzone.&7 This' - '&7will create a &nWarp Point&7 for your faction members.' - '' - - '&c&lEffects' - - '&c&l* &fStrength II' - - '&c&l* &fSpeed II' + - '&e&lEffects' + - '&e&l* &fStrength II' + - '&e&l* &fSpeed II' Banner-Cost: 5000 #The amount charged to change a banner into a War Banner Banner-Time: 60 #IN SECONDS - This is how long the banner will last. Banner-Place-Cooldown: 300 diff --git a/src/main/resources/lang/it_IT.yml b/src/main/resources/lang/it_IT.yml index f389a1c4..ad9e911a 100644 --- a/src/main/resources/lang/it_IT.yml +++ b/src/main/resources/lang/it_IT.yml @@ -1,4 +1,4 @@ -# Lang file for P by drtshock & Driftay +# Lang file for FactionsPlugin by drtshock & Driftay # Use & for color codes. # Made with love <3 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1062f419..a264af81 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Factions version: ${project.version} api-version: 1.13 -main: com.massivecraft.factions.P +main: com.massivecraft.factions.FactionsPlugin authors: [Olof Larsson, Brett Flannigan, drtshock, ProSavage, SvenjaReißaus, FroggyKnight, Driftay] softdepend: [Skript, CoreProtect, PlayerVaults, PlaceholderAPI, MVdWPlaceholderAPI, PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Vault, Spout, WorldEdit, WorldGuard, AuthDB, CaptureThePoints, CombatTag, dynmap, FactionsTop] From db9c95128305807e4ac9283d2465be4a17d65494 Mon Sep 17 00:00:00 2001 From: Driftay Date: Sat, 14 Sep 2019 15:33:49 -0400 Subject: [PATCH 4/7] Version Change --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bbce7640..09591c4a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.massivecraft Factions - 1.6.9.5-U0.2.1-1.8.1-BETA + 1.6.9.5-U0.2.1-1.9.0-BETA jar SaberFactions From 804160429d9a083406fb77f11d1f72449928f03b Mon Sep 17 00:00:00 2001 From: Driftay Date: Sat, 14 Sep 2019 15:51:30 -0400 Subject: [PATCH 5/7] Fixed Fly Disable For People In Creative --- .../massivecraft/factions/listeners/FactionsPlayerListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 047b03f4..918b5e77 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -736,7 +736,7 @@ public class FactionsPlayerListener implements Listener { } if (me.getAutoClaimFor() != null) { me.attemptClaim(me.getAutoClaimFor(), event.getTo(), true); - if (Conf.disableFlightOnFactionClaimChange) CmdFly.disableFlight(me); + if (Conf.disableFlightOnFactionClaimChange && event.getPlayer().getGameMode() != GameMode.CREATIVE) CmdFly.disableFlight(me); } else if (me.isAutoSafeClaimEnabled()) { if (!Permission.MANAGE_SAFE_ZONE.has(player)) { me.setIsAutoSafeClaimEnabled(false); From 58efba39b054bc4b5573c81750fa6819d1b5e80a Mon Sep 17 00:00:00 2001 From: Driftay Date: Sat, 14 Sep 2019 16:04:20 -0400 Subject: [PATCH 6/7] Config Converter Added (DroppingAnvil) --- .../massivecraft/factions/cmd/FCmdRoot.java | 4 +- .../cmd/configsf/CmdConvertConfig.java | 29 ++++ .../cmd/configsf/ConvertConfigHandler.java | 142 ++++++++++++++++++ .../factions/struct/Permission.java | 1 + .../massivecraft/factions/zcore/util/TL.java | 15 +- src/main/resources/plugin.yml | 1 + 6 files changed, 186 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/configsf/CmdConvertConfig.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/configsf/ConvertConfigHandler.java diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index fe5cef15..f43d274d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -7,6 +7,7 @@ import com.massivecraft.factions.cmd.check.CmdCheck; import com.massivecraft.factions.cmd.check.CmdWeeWoo; import com.massivecraft.factions.cmd.chest.CmdChest; import com.massivecraft.factions.cmd.claim.*; +import com.massivecraft.factions.cmd.configsf.CmdConvertConfig; import com.massivecraft.factions.cmd.econ.CmdMoney; import com.massivecraft.factions.cmd.grace.CmdGrace; import com.massivecraft.factions.cmd.logout.CmdLogout; @@ -144,7 +145,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor { public CmdStrikes cmdStrikes = new CmdStrikes(); public CmdCheck cmdCheck = new CmdCheck(); public CmdWeeWoo cmdWeeWoo = new CmdWeeWoo(); - + public CmdConvertConfig cmdConvertConfig = new CmdConvertConfig(); public FCmdRoot() { super(); @@ -253,6 +254,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor { this.addSubCommand(this.cmdStrikes); this.addSubCommand(this.cmdFGlobal); this.addSubCommand(this.cmdViewChest); + this.addSubCommand(this.cmdConvertConfig); if (Conf.useCheckSystem) { this.addSubCommand(this.cmdCheck); diff --git a/src/main/java/com/massivecraft/factions/cmd/configsf/CmdConvertConfig.java b/src/main/java/com/massivecraft/factions/cmd/configsf/CmdConvertConfig.java new file mode 100644 index 00000000..73ada76e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/configsf/CmdConvertConfig.java @@ -0,0 +1,29 @@ +package com.massivecraft.factions.cmd.configsf; + +import com.massivecraft.factions.cmd.CommandContext; +import com.massivecraft.factions.cmd.CommandRequirements; +import com.massivecraft.factions.cmd.FCommand; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdConvertConfig extends FCommand { + + public CmdConvertConfig() { + super(); + this.aliases.add("convertconfig"); + + this.requirements = new CommandRequirements.Builder(Permission.CONVERTCONFIG) + .playerOnly() + .build(); + } + + @Override + public void perform(CommandContext context) { + ConvertConfigHandler.convertconfig(context.player); + } + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_CONVERTCONFIG_DESCRIPTION; + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/configsf/ConvertConfigHandler.java b/src/main/java/com/massivecraft/factions/cmd/configsf/ConvertConfigHandler.java new file mode 100644 index 00000000..e176682c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/configsf/ConvertConfigHandler.java @@ -0,0 +1,142 @@ +package com.massivecraft.factions.cmd.configsf; + +import com.massivecraft.factions.FactionsPlugin; +import com.massivecraft.factions.zcore.util.TL; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitScheduler; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; + +public class ConvertConfigHandler { + + static File savageConfigFile = new File("plugins/Factions/SavageFactions/config.yml"); + static FileConfiguration sv = YamlConfiguration.loadConfiguration(savageConfigFile); + static File configFile = new File("plugins/Factions/config.yml"); + static FileConfiguration sb = YamlConfiguration.loadConfiguration(configFile); + public static void setString(String s){ + sb.set(s, sv.getString(s)); + } + public static void setInt(String s){ + sb.set(s, sv.getInt(s)); + } + public static void setConfigSec(String s){ + ConfigurationSection cs = sv.getConfigurationSection(s); + sb.set(s, cs); + } + static JavaPlugin plugin = JavaPlugin.getProvidingPlugin(FactionsPlugin.class); + public static void setBoolean(String s){ + sb.set(s, sv.getBoolean(s)); + } + public static void convertconfig(Player player) { + if (new File("plugins/Factions/SavageFactions/config.yml").exists()) { + BukkitScheduler scheduler = plugin.getServer().getScheduler(); + scheduler.scheduleAsyncDelayedTask(plugin, () -> { + File savageConfigFile = new File("plugins/Factions/SavageFactions/config.yml"); + FileConfiguration sv = YamlConfiguration.loadConfiguration(savageConfigFile); + File configFile = new File("plugins/Factions/config.yml"); + FileConfiguration sb = YamlConfiguration.loadConfiguration(configFile); + sb.set("ConfigConvertedFromSavageFactions", true); + sb.set("debug", sv.getBoolean("debug")); + ConfigurationSection ffe = sv.getConfigurationSection("findfactionsexploit"); + sb.set("findfactionsexploit", ffe); + setString("default-relation"); + ConfigurationSection pC = sv.getConfigurationSection("portals"); + sb.set("portals", pC); + sb.set("maxwarps", sv.getInt("maxwarps")); + setConfigSec("warp-cost"); + setBoolean("enable-faction-flight"); + setBoolean("ffly.AutoEnable"); + setInt("fly-falldamage-cooldown"); + setBoolean("disable-pistons-in-territory"); + setConfigSec("tooltips"); + setConfigSec("scoreboard"); + sb.set("scoreboard.also-send-chat", true); + setConfigSec("warmups"); + setConfigSec("max-relations"); + setInt("world-border.buffer"); + setConfigSec("hcf"); + sb.set("show", sv.getStringList("show")); + setBoolean("show-exempt"); + sb.set("map", sv.getStringList("map")); + setConfigSec("list"); + setBoolean("use-old-help"); + setConfigSec("help"); + setConfigSec("fperm-gui"); + sb.set("fperm-gui.action.slots.check", 50); + setConfigSec("fwarp-gui"); + setBoolean("faction-creation-broadcast"); + setBoolean("faction-disband-broadcast"); + setBoolean("See-Invisible-Faction-Members"); + setConfigSec("frules"); + setConfigSec("ftnt"); + setBoolean("fpaypal.Enabled"); + setBoolean("checkpoints.Enabled"); + setConfigSec("fnear"); + setConfigSec("ffocus"); + setConfigSec("fvualt"); + setString("fupgrades.MainMenu.Title"); + setString("fupgrades.MainMenu.DummyItem.Name"); + setString("fupgrades.MainMenu.DummyItem.Type"); + List l = sv.getStringList("fupgrades.MainMenu.DummyItem.Lore"); + sb.set("fupgrades.MainMenu.DummyItem.Lore", l); + setConfigSec("fupgrades.MainMenu.Crops.Crop-Boost"); + setConfigSec("fupgrades.MainMenu.Crops.Cost"); + sb.set("fupgrades.MainMenu.Crops.CropItem", sv.getConfigurationSection("fupgrades.MainMenu.Crops.DisplayItem")); + setConfigSec("fupgrades.MainMenu.EXP.EXP-Boost"); + setConfigSec("fupgrades.MainMenu.EXP.Cost"); + sb.set("fupgrades.MainMenu.EXP.EXPItem", sv.getConfigurationSection("fupgrades.MainMenu.EXP.DisplayItem")); + setConfigSec("fupgrades.MainMenu.Power.Power-Boost"); + setConfigSec("fupgrades.MainMenu.Power.Cost"); + sb.set("fupgrades.MainMenu.Power.PowerItem", sv.getConfigurationSection("fupgrades.MainMenu.Power.DisplayItem")); + List p = new ArrayList(); + p.add(sv.getInt("fupgrades.MainMenu.Power.DisplayItem.Slot")); + sb.set("fupgrades.MainMenu.Power.PowerItem.slots", p); + sb.set("fupgrades.MainMenu.Power.PowerItem.Amount", 1); + sb.set("fupgrades.MainMenu.Power.PowerItem.Damage", 0); + sb.set("fupgrades.MainMenu.Power.PowerItem.Slot", null); + sb.set("fupgrades.MainMenu.Members.Members-Limit", sv.getConfigurationSection("fupgrades.MainMenu.Members.Members-Boost")); + setConfigSec("fupgrades.MainMenu.Spawners.Spawner-Boost"); + setConfigSec("fupgrades.MainMenu.Spawners.Cost"); + sb.set("fupgrades.MainMenu.Spawners.SpawnerItem", sv.getConfigurationSection("fupgrades.MainMenu.Spawners.DisplayItem")); + setConfigSec("fupgrades.MainMenu.Chest.Chest-Size"); + setConfigSec("fupgrades.MainMenu.Chest.Cost"); + sb.set("fupgrades.MainMenu.Chest.ChestItem", sv.getConfigurationSection("fupgrades.MainMenu.Chest.DisplayItem")); + setConfigSec("fupgrades.MainMenu.Members.Cost"); + sb.set("fupgrades.MainMenu.Members.MembersItem", sv.getConfigurationSection("fupgrades.MainMenu.Members.DisplayItem")); + sb.set("fupgrades.MainMenu.Members.MembersItem.Amount", 1); + sb.set("fupgrades.MainMenu.Members.MembersItem.Damage", 0); + if (sv.getString("fupgrades.MainMenu.Members.DisplayItem.Type").equalsIgnoreCase("PLAYER_HEAD")) + sb.set("fupgrades.MainMenu.Members.MembersItem.Type", "PAPER"); + List x = new ArrayList(); + x.add(sv.getInt("fupgrades.MainMenu.Members.DisplayItem.Slot")); + sb.set("fupgrades.MainMenu.Members.MembersItem.slots", x); + sb.set("fupgrades.MainMenu.Members.MembersItem.Slot", null); + sb.set("fupgrades.MainMenu.Members.Members-Limit", sv.getConfigurationSection("fupgrades.MainMenu.Members.Members-Boost")); + setConfigSec("fbanners"); + setConfigSec("see-chunk"); + setConfigSec("Tntfill"); + try { + sb.save(configFile); + plugin.reloadConfig(); + } catch (IOException e) { + player.sendMessage(TL.COMMAND_CONVERTCONFIG_FAIL.toString()); + Bukkit.getLogger().log(Level.SEVERE, Arrays.toString(e.getStackTrace())); + } + player.sendMessage(TL.COMMAND_CONVERTCONFIG_SUCCESS.toString()); + }, 0L); + } else { + player.sendMessage(TL.COMMAND_CONVERTCONFIG_FAILCONFIGMISSING.toString()); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index 45a6a97d..38311d80 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -25,6 +25,7 @@ public enum Permission { CLAIM_RADIUS("claim.radius"), CONFIG("config"), CONVERT("convert"), + CONVERTCONFIG("convertconfig"), CREATE("create"), CORNER("corner"), DEFAULTRANK("defaultrank"), diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index a009d7f2..2cd18ad1 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -506,6 +506,11 @@ public enum TL { COMMAND_COLEADER_PROMOTED("&c&l[!]&7 You have &cpromoted &7%1$s to &ccoleader."), COMMAND_COLEADER_DESCRIPTION("Give or revoke coleader rights"), + COMMAND_CONVERTCONFIG_DESCRIPTION("Convert your SavageFactions config to SaberFactions"), + COMMAND_CONVERTCONFIG_SUCCESS("&cConfiguration successfully converted"), + COMMAND_CONVERTCONFIG_FAIL("&cConfiguration conversion failed!"), + COMMAND_CONVERTCONFIG_FAILCONFIGMISSING("&cPlease ensure you have placed SavageFactions files in a folder called SavageFactions"), + COMMAND_MODIFYPOWER_ADDED("&c&l[!]&7 Added &c%1$f &7power to &c%2$s. &7New total rounded power: &c%3$d"), COMMAND_MODIFYPOWER_DESCRIPTION("Modify the power of a faction/player"), @@ -1046,11 +1051,11 @@ public enum TL { /** * Roles */ - ROLE_LEADER("leader"), - ROLE_COLEADER("coleader"), - ROLE_MODERATOR("moderator"), - ROLE_NORMAL("normal member"), - ROLE_RECRUIT("recruit"), + ROLE_LEADER("Leader"), + ROLE_COLEADER("Co-Leader"), + ROLE_MODERATOR("Moderator"), + ROLE_NORMAL("Normal Member"), + ROLE_RECRUIT("Recruit"), /** * Region types. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a264af81..0110ed1d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -25,6 +25,7 @@ permissions: factions.*: description: This is just an alias for factions.kit.admin children: + factions.convertconfig: true factions.kit.admin: true factions.kit.mod: description: All faction permissions but configuration and persistance. From ed0e17e2a012ebd6a20871c7ec642dc552e2bf79 Mon Sep 17 00:00:00 2001 From: Driftay Date: Sun, 15 Sep 2019 03:48:25 -0400 Subject: [PATCH 7/7] Missions Fix --- .../listeners/FactionsPlayerListener.java | 1 + .../factions/missions/MissionHandler.java | 21 +------------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 918b5e77..7f5c8ae2 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -824,6 +824,7 @@ public class FactionsPlayerListener implements Listener { return; } } + if (event.getItem() == null) return; if (!playerCanUseItemHere(player, block.getLocation(), event.getItem().getType(), false)) { event.setCancelled(true); diff --git a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java index cc8d348f..c756c14e 100644 --- a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java +++ b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; +import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -25,26 +26,6 @@ public class MissionHandler implements Listener { this.plugin = plugin; } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityBreed(EntityBreedEvent event) { - if (event.getEntity() == null) { - return; - } - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getEntity().getKiller()); - if (fPlayer == null) { - return; - } - List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("breed")).collect(Collectors.toList()); - for (Mission mission2 : missions) { - ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); - if (!event.getEntityType().toString().equals(section.getConfigurationSection("Mission").getString("EntityType"))) { - continue; - } - mission2.incrementProgress(); - checkIfDone(fPlayer, mission2, section); - } - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { if (event.getEntity() == null || event.getEntity().getKiller() == null) {