From c237667def5dc52c0783433d9839af23aa8e1486 Mon Sep 17 00:00:00 2001 From: Driftay Date: Thu, 2 Apr 2020 15:15:59 -0400 Subject: [PATCH] Added F Notifcations Command (Allows Players To Disable Notifications From Land Claiming) --- .../massivecraft/factions/cmd/Aliases.java | 1 + .../factions/cmd/CmdNotifications.java | 38 ++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 3 ++ .../factions/struct/Permission.java | 1 + .../massivecraft/factions/util/ItemUtil.java | 51 ------------------- .../com/massivecraft/factions/util/Pair.java | 26 ---------- .../factions/util/RomanNumber.java | 31 ----------- .../factions/zcore/persist/MemoryFPlayer.java | 8 ++- 8 files changed, 49 insertions(+), 110 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdNotifications.java delete mode 100644 src/main/java/com/massivecraft/factions/util/ItemUtil.java delete mode 100644 src/main/java/com/massivecraft/factions/util/Pair.java delete mode 100644 src/main/java/com/massivecraft/factions/util/RomanNumber.java diff --git a/src/main/java/com/massivecraft/factions/cmd/Aliases.java b/src/main/java/com/massivecraft/factions/cmd/Aliases.java index e7c3ff2a..7755d8ca 100644 --- a/src/main/java/com/massivecraft/factions/cmd/Aliases.java +++ b/src/main/java/com/massivecraft/factions/cmd/Aliases.java @@ -10,6 +10,7 @@ public class Aliases { /** * @author DroppingAnvil */ + public static ArrayList notifications = new ArrayList<>(Arrays.asList("notifications", "notis")); public static ArrayList alts_alts = new ArrayList<>(Arrays.asList("alts", "alt")); public static ArrayList alts_list = new ArrayList<>(Arrays.asList("list", "l")); public static ArrayList alts_invite = new ArrayList<>(Collections.singletonList("invite")); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdNotifications.java b/src/main/java/com/massivecraft/factions/cmd/CmdNotifications.java new file mode 100644 index 00000000..9adb3cbd --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdNotifications.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +/** + * Factions - Developed by Driftay. + * All rights reserved 2020. + * Creation Date: 4/2/2020 + */ +public class CmdNotifications extends FCommand { + + public CmdNotifications() { + super(); + this.aliases.addAll(Aliases.notifications); + this.requirements = new CommandRequirements.Builder(Permission.NOTIFICATIONS) + .playerOnly() + .memberOnly() + .build(); + } + + + @Override + public void perform(CommandContext context) { + if (context.fPlayer.hasNotificationsEnabled()) { + context.fPlayer.setNotificationsEnabled(false); + context.msg(TL.COMMAND_NOTIFICATIONS_TOGGLED_OFF); + } else { + context.fPlayer.setNotificationsEnabled(true); + context.msg(TL.COMMAND_NOTIFICATIONS_TOGGLED_ON); + } + } + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_NOTIFICATIONS_DESCRIPTION; + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 53117f57..44adfb74 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -170,6 +170,8 @@ public class FCmdRoot extends FCommand implements CommandExecutor { public CmdReserve cmdReserve = new CmdReserve(); public CmdDelHome cmdDelHome = new CmdDelHome(); public CmdClaimFill cmdClaimFill = new CmdClaimFill(); + public CmdNotifications cmdNotifications = new CmdNotifications(); + //Variables to know if we already setup certain sub commands public Boolean discordEnabled = false; public Boolean checkEnabled = false; @@ -303,6 +305,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor { this.addSubCommand(this.cmdSpawnerLock); this.addSubCommand(this.cmdDrain); this.addSubCommand(this.cmdLookup); + this.addSubCommand(this.cmdNotifications); addVariableCommands(); if (CommodoreProvider.isSupported()) brigadierManager.build(); } diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index e0356d97..dee0eb3a 100755 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -74,6 +74,7 @@ public enum Permission { MAP("map"), MAPHEIGHT("mapheight"), MOD("mod"), + NOTIFICATIONS("notifications"), COLEADER("coleader"), MOD_ANY("mod.any"), COLEADER_ANY("coleader.any"), diff --git a/src/main/java/com/massivecraft/factions/util/ItemUtil.java b/src/main/java/com/massivecraft/factions/util/ItemUtil.java deleted file mode 100644 index 5bfb2b05..00000000 --- a/src/main/java/com/massivecraft/factions/util/ItemUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.massivecraft.factions.util; - -/** - * @author Saser - */ - -import org.bukkit.Material; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -import java.util.HashMap; -import java.util.Map; - -public class ItemUtil { - private static Map cachedSkulls = new HashMap<>(); - - public ItemUtil() { - } - - public static int getItemCount(Inventory inventory) { - if (inventory == null) { - return 0; - } else { - int itemsFound = 0; - - for (int i = 0; i < inventory.getSize(); ++i) { - ItemStack item = inventory.getItem(i); - if (item != null && item.getType() != Material.AIR) { - ++itemsFound; - } - } - - return itemsFound; - } - } - - public static ItemStack createPlayerHead(String name) { - ItemStack skull = cachedSkulls.get(name); - if (skull != null) { - return skull.clone(); - } else { - skull = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial()); - SkullMeta sm = (SkullMeta) skull.getItemMeta(); - sm.setOwner(name); - skull.setItemMeta(sm); - cachedSkulls.put(name, skull.clone()); - return skull; - } - } -} diff --git a/src/main/java/com/massivecraft/factions/util/Pair.java b/src/main/java/com/massivecraft/factions/util/Pair.java deleted file mode 100644 index c5aec582..00000000 --- a/src/main/java/com/massivecraft/factions/util/Pair.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.massivecraft.factions.util; - -/** - * Factions - Developed by FactionsUUID Team. - */ -public class Pair { - - private final Left left; - private final Right right; - private Pair(Left left, Right right) { - this.left = left; - this.right = right; - } - - public static Pair of(Left left, Right right) { - return new Pair<>(left, right); - } - - public Left getLeft() { - return this.left; - } - - public Right getRight() { - return this.right; - } -} diff --git a/src/main/java/com/massivecraft/factions/util/RomanNumber.java b/src/main/java/com/massivecraft/factions/util/RomanNumber.java deleted file mode 100644 index 277b04bc..00000000 --- a/src/main/java/com/massivecraft/factions/util/RomanNumber.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.massivecraft.factions.util; - -import java.util.TreeMap; - -public class RomanNumber { - private static TreeMap map; - - static { - (map = new TreeMap<>()).put(1000, "M"); - RomanNumber.map.put(900, "CM"); - RomanNumber.map.put(500, "D"); - RomanNumber.map.put(400, "CD"); - RomanNumber.map.put(100, "C"); - RomanNumber.map.put(90, "XC"); - RomanNumber.map.put(50, "L"); - RomanNumber.map.put(40, "XL"); - RomanNumber.map.put(10, "X"); - RomanNumber.map.put(9, "IX"); - RomanNumber.map.put(5, "V"); - RomanNumber.map.put(4, "IV"); - RomanNumber.map.put(1, "I"); - } - - public static String toRoman(int number) { - int l = RomanNumber.map.floorKey(number); - if (number == l) { - return RomanNumber.map.get(number); - } - return RomanNumber.map.get(l) + toRoman(number - l); - } -} 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 9cd66d13..42329f40 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -86,7 +86,7 @@ public abstract class MemoryFPlayer implements FPlayer { protected transient long lastFrostwalkerMessage; protected transient boolean shouldTakeFallDamage = true; protected boolean isStealthEnabled = false; - protected boolean notificationsEnabled = true; + protected boolean notificationsEnabled; protected boolean titlesEnabled = true; protected boolean isAlt = false; boolean inspectMode = false; @@ -112,6 +112,7 @@ public abstract class MemoryFPlayer implements FPlayer { this.getDeaths(); this.showScoreboard = FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-enabled", false); this.mapHeight = Conf.mapHeight; + this.notificationsEnabled = true; if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.getInstance().isValidFactionId(Conf.newPlayerStartingFactionID)) { this.factionId = Conf.newPlayerStartingFactionID; @@ -141,6 +142,7 @@ public abstract class MemoryFPlayer implements FPlayer { this.notificationsEnabled = other.notificationsEnabled; this.showScoreboard = FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-enabled", true); this.mapHeight = Conf.mapHeight; + this.notificationsEnabled = true; } public boolean isAlt() { @@ -1255,8 +1257,10 @@ public abstract class MemoryFPlayer implements FPlayer { Set informTheseFPlayers = new HashSet<>(); informTheseFPlayers.add(this); informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true)); - for (FPlayer fp : informTheseFPlayers) + for (FPlayer fp : informTheseFPlayers) { + if (!fp.hasNotificationsEnabled()) continue; fp.msg(TL.CLAIM_CLAIMED, this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp)); + } Board.getInstance().setFactionAt(forFaction, flocation);