From cbb7d478a7a40f7d4687d83378a58f7e152ce6ae Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 11:13:16 -0300 Subject: [PATCH 01/10] Fixed re invite spam to already invited member and enhanced kick permission check --- .../massivecraft/factions/cmd/CmdInvite.java | 13 +++++++--- .../massivecraft/factions/cmd/CmdKick.java | 25 ++++++------------- .../massivecraft/factions/zcore/util/TL.java | 1 + 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java index c024671d..a8adc2da 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java @@ -48,12 +48,17 @@ public class CmdInvite extends FCommand { return; } - Access access = myFaction.getAccess(fme, PermissableAction.INVITE); - if (access == Access.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "invite"); + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.INVITE); + if (access == Access.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "invite"); + return; + } + } + if (myFaction.isInvited(target)) { + fme.msg(TL.COMMAND_INVITE_ALREADYINVITED, target.getName()); return; } - if (myFaction.isBanned(target)) { fme.msg(TL.COMMAND_INVITE_BANNED, target.getName()); return; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdKick.java b/src/main/java/com/massivecraft/factions/cmd/CmdKick.java index 3d012d1f..13934a30 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdKick.java @@ -73,40 +73,31 @@ public class CmdKick extends FCommand { return; } - // players with admin-level "disband" permission can bypass these requirements - if (!Permission.KICK_ANY.has(sender)) { - + // This permission check has been cleaned to be more understandable and logical + // Unless is admin, + // - 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.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) { + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { fme.msg(TL.GENERIC_NOPERMISSION, "kick"); return; } - if (toKickFaction != myFaction) { msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(fme, true), myFaction.describeTo(fme)); return; } - - // Check for Access before we check for Role. - if (access != Access.ALLOW && toKick.getRole().value >= fme.getRole().value) { + if (toKick.getRole().value >= fme.getRole().value) { msg(TL.COMMAND_KICK_INSUFFICIENTRANK); return; } - if (!Conf.canLeaveWithNegativePower && toKick.getPower() < 0) { msg(TL.COMMAND_KICK_NEGATIVEPOWER); return; } } - Access access = myFaction.getAccess(fme, PermissableAction.KICK); - // This statement allows us to check if they've specifically denied it, or default to - // the old setting of allowing moderators to kick - if (access == Access.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) { - fme.msg(TL.GENERIC_NOPERMISSION, "kick"); - 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())) { return; 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 23fbab06..2af73b40 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -329,6 +329,7 @@ public enum TL { COMMAND_INVITE_INVITEDYOU("&chas invited you to join "), COMMAND_INVITE_INVITED("&c&l[!]&7 &c%1$s&7 invited &c%2$s&7 to your faction."), COMMAND_INVITE_ALREADYMEMBER("&c&l[!]&7 &c%1$s&7 is already a member of&c %2$s"), + COMMAND_INVITE_ALREADYINVITED("&c&l[!]&7 &c%1$s&7 has already been invited"), COMMAND_INVITE_DESCRIPTION("Invite a player to your faction"), COMMAND_INVITE_BANNED("&c&l[!]&7 &7%1$s &cis banned &7from your Faction. &cNot &7sending an invite."), From 6a3b4db565f907912db478ca6779cebf1e801d06 Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 11:29:41 -0300 Subject: [PATCH 02/10] Added config to allow vanished players to hide particles for moderation purposes --- src/main/java/com/massivecraft/factions/cmd/CmdFly.java | 8 ++++++++ src/main/resources/config.yml | 1 + 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java index f80e3a8a..9cecc206 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java @@ -58,6 +58,14 @@ public class CmdFly extends FCommand { 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. diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a1297935..d227629b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -65,6 +65,7 @@ enable-faction-flight: true ffly: Particles: Enabled: true + Enable-While-Vanished: true AutoEnable: true #If set to true, fly will automatically enable when walking into your own chunk. From 1ac9c123d0cffe755a741a592edb2ad820778f5a Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 11:32:53 -0300 Subject: [PATCH 03/10] Improved recent Stealth feature to use local variables (performance enchancing) --- .../com/massivecraft/factions/cmd/CmdStealth.java | 13 ++++--------- .../com/massivecraft/factions/zcore/util/TL.java | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java b/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java index 1c6fc8a7..1d12faac 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java @@ -21,20 +21,15 @@ public class CmdStealth extends FCommand { } public void perform() { - //Grabs Faction - Faction faction = fme.getFaction(); - - if (faction != null && !faction.getId().equalsIgnoreCase("0") && !faction.getId().equalsIgnoreCase("none") && !faction.getId().equalsIgnoreCase("safezone") && !faction.getId().equalsIgnoreCase("warzone")) { - //Grabs Boolean From FPlayer + if (myFaction != null && !myFaction.isWilderness() && !myFaction.isSafeZone() && !myFaction.isWarZone() && myFaction.isNormal()) { fme.setStealth(!fme.isStealthEnabled()); - //Sends Enable/Disable Message + // Sends Enable/Disable Message fme.msg(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE); - } else { - //Send "Needed Faction" Message - fme.sendMessage(ChatColor.RED + "You must be in a faction to use this command"); + fme.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER); } } + @Override public TL getUsageTranslation() { return TL.COMMAND_STEALTH_DESCRIPTION; 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 2af73b40..87393034 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -636,6 +636,7 @@ public enum TL { COMMAND_STEALTH_DESCRIPTION("Enable and Disable Stealth Mode"), COMMAND_STEALTH_ENABLE( "&2Stealth &8» &7You will no longer disable nearby players fly."), COMMAND_STEALTH_DISABLE("&2Stealth &8» &7You will now disable other nearby players fly."), + COMMAND_STEALTH_MUSTBEMEMBER("&2Stealth &8» &4You must be in a faction to use this command"), COMMAND_STUCK_TIMEFORMAT("m 'minutes', s 'seconds.'"), COMMAND_STUCK_CANCELLED("Teleport cancelled because you were damaged"), From d6d803180450274f5ea80696c386bacbb82237ed Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 11:54:39 -0300 Subject: [PATCH 04/10] Only mods and higher should use Mod Chat Channel --- src/main/java/com/massivecraft/factions/cmd/CmdChat.java | 6 +++++- .../factions/listeners/FactionsChatListener.java | 6 ++++++ src/main/java/com/massivecraft/factions/zcore/util/TL.java | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdChat.java b/src/main/java/com/massivecraft/factions/cmd/CmdChat.java index 7c220eaf..7b58c80e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdChat.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdChat.java @@ -37,8 +37,12 @@ public class CmdChat extends FCommand { if (modeString != null) { modeString = modeString.toLowerCase(); - if (modeString.startsWith("m")) { + // Only allow Mods and higher rank to switch to this channel. + if (modeString.startsWith("m") && fme.getRole().isAtLeast(Role.MODERATOR)) { modeTarget = ChatMode.MOD; + } else if (modeString.startsWith("m") && !fme.getRole().isAtLeast(Role.MODERATOR)) { + msg(TL.COMMAND_CHAT_MOD_ONLY); + return; } else if (modeString.startsWith("p")) { modeTarget = ChatMode.PUBLIC; } else if (modeString.startsWith("a")) { diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java index 2054164b..8f4b143c 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java @@ -63,8 +63,14 @@ public class FactionsChatListener implements Listener { fplayer.sendMessage("[MCspy]: " + message); } } + } else { + // Just in case player gets demoted while in faction chat. + me.msg(TL.COMMAND_CHAT_MOD_ONLY); + event.setCancelled(true); + return; } + Bukkit.getLogger().log(Level.INFO, ChatColor.stripColor("Mod Chat: " + message)); event.setCancelled(true); 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 87393034..cbe4d82b 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -188,6 +188,7 @@ public enum TL { COMMAND_CHAT_MODE_TRUCE("&c&l[!] &5Truce &7only chat mode."), COMMAND_CHAT_MODE_FACTION("&c&l[!] &aFaction&7 only chat mode."), COMMAND_CHAT_MODE_MOD("&c&l[!] &dMod &7only chat mode."), + COMMAND_CHAT_MOD_ONLY("&c&l[!] &7Only Mods can talk through this chat mode."), COMMAND_CHATSPY_ENABLE("&c&l[!] &7You have &cenabled &7chat spying mode."), COMMAND_CHATSPY_ENABLELOG(" has ENABLED chat spying mode."), From ea861d304d40612fc89fa5842aba9346faa2d92c Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 11:55:47 -0300 Subject: [PATCH 05/10] Fixed no confirmation message when inviting offline players --- .../massivecraft/factions/cmd/CmdInvite.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java index a8adc2da..2d6075e9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java @@ -65,24 +65,22 @@ public class CmdInvite extends FCommand { } myFaction.invite(target); - if (!target.isOnline()) { - return; + // 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)) + .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) + .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.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()); + + message.send(target.getPlayer()); } - - // Tooltips, colors, and commands only apply to the string immediately before it. - FancyMessage message = new FancyMessage(fme.describeTo(target, true)) - .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) - .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.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()); - - message.send(target.getPlayer()); - - //you.msg("%s invited you to %s", fme.describeTo(you, true), myFaction.describeTo(you)); + myFaction.msg(TL.COMMAND_INVITE_INVITED, fme.describeTo(myFaction, true), target.describeTo(myFaction)); } From 6d397b1caec07ffc6310184455e5c7a3a20ef841 Mon Sep 17 00:00:00 2001 From: Naman Date: Thu, 2 Aug 2018 10:16:55 -0500 Subject: [PATCH 06/10] Update CmdFly.java --- src/main/java/com/massivecraft/factions/cmd/CmdFly.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java index 9cecc206..924df7b5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java @@ -54,9 +54,7 @@ public class CmdFly extends FCommand { continue; } } - if (FPlayers.getInstance().getByPlayer(player).isVanished()) { - 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. From 40a0d7227021c6fb65545ea8a80e9b8f1eb8227a Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 12:33:51 -0300 Subject: [PATCH 07/10] Added /f home permission added to keep players from complaining --- src/main/java/com/massivecraft/factions/cmd/CmdHome.java | 8 ++++++++ .../factions/zcore/fperms/PermissableAction.java | 1 + 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java index 2d861b22..d710e89a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java @@ -47,6 +47,14 @@ public class CmdHome extends FCommand { fme.msg(TL.COMMAND_HOME_TELEPORTDISABLED); return; } + f (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.HOME); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.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())); 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 aa0e958d..0e00612e 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java @@ -29,6 +29,7 @@ public enum PermissableAction { SETHOME("sethome"), TERRITORY("territory"), ACCESS("access"), + HOME("home"), DISBAND("disband"), PROMOTE("promote"), SETWARP("setwarp"), From 85de278dc98a68e7671e7b199fa07f275467623f Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 13:57:57 -0300 Subject: [PATCH 08/10] Fixed permission check for /f vault --- src/main/java/com/massivecraft/factions/cmd/CmdChest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdChest.java b/src/main/java/com/massivecraft/factions/cmd/CmdChest.java index 9d207729..c8ad67b3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdChest.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdChest.java @@ -30,12 +30,12 @@ public class CmdChest extends FCommand { fme.sendMessage("This command is disabled!"); return; } - Access access = fme.getFaction().getAccess(fme, PermissableAction.CHEST); - if (access.equals(Access.DENY)) { + // This permission check is way too explicit but it's clean + Access access = myFaction.getAccess(fme, PermissableAction.CHEST); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { fme.msg(TL.GENERIC_NOPERMISSION, "chest"); + return; } - //debug Bukkit.broadcastMessage(fme.getFaction().getUpgrade("Chest") + ""); - me.openInventory(fme.getFaction().getChest()); From 5fe55afc681dbc30efd4ae08e25bef3a27ea25b6 Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 14:55:21 -0300 Subject: [PATCH 09/10] Explicit permission checks and more admin bypasses --- .../com/massivecraft/factions/cmd/CmdBan.java | 14 +++---- .../massivecraft/factions/cmd/CmdChest.java | 11 +++-- .../massivecraft/factions/cmd/CmdClaim.java | 7 ++-- .../factions/cmd/CmdDeinvite.java | 7 ++++ .../massivecraft/factions/cmd/CmdDisband.java | 11 ++--- .../massivecraft/factions/cmd/CmdFWarp.java | 14 +++---- .../com/massivecraft/factions/cmd/CmdFly.java | 1 - .../massivecraft/factions/cmd/CmdHome.java | 2 +- .../massivecraft/factions/cmd/CmdInvite.java | 5 ++- .../factions/cmd/CmdSetFWarp.java | 10 +++-- .../massivecraft/factions/cmd/CmdSethome.java | 21 +++------- .../com/massivecraft/factions/cmd/CmdTnt.java | 11 ++--- .../massivecraft/factions/cmd/CmdTntFill.java | 10 +++-- .../massivecraft/factions/cmd/CmdUnban.java | 19 ++------- .../massivecraft/factions/cmd/CmdUnclaim.java | 8 ++-- .../factions/cmd/FPromoteCommand.java | 40 +++++++++++++------ .../listeners/FactionsBlockListener.java | 11 ++--- .../listeners/FactionsPlayerListener.java | 4 -- 18 files changed, 105 insertions(+), 101 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBan.java b/src/main/java/com/massivecraft/factions/cmd/CmdBan.java index 10b351c7..19cfa071 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBan.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBan.java @@ -39,18 +39,16 @@ public class CmdBan extends FCommand { return; } - // Can the player ban for this faction? - // Check for ALLOW access as well before we check for role. - if (access != Access.ALLOW) { - if (!Permission.BAN.has(sender, true) || !assertMinRole(Role.MODERATOR)) { - return; - } - } else { - if (!Permission.BAN.has(sender, true)) { + // 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.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "ban"); return; } } + // Good on permission checks. Now lets just ban the player. FPlayer target = argAsFPlayer(0); if (target == null) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdChest.java b/src/main/java/com/massivecraft/factions/cmd/CmdChest.java index c8ad67b3..9f90454a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdChest.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdChest.java @@ -31,11 +31,14 @@ public class CmdChest extends FCommand { return; } // This permission check is way too explicit but it's clean - Access access = myFaction.getAccess(fme, PermissableAction.CHEST); - if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { - fme.msg(TL.GENERIC_NOPERMISSION, "chest"); - return; + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.CHEST); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "access chest"); + return; + } } + me.openInventory(fme.getFaction().getChest()); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdClaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdClaim.java index d70628ea..a729236a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdClaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdClaim.java @@ -37,14 +37,15 @@ public class CmdClaim extends FCommand { final Faction forFaction = this.argAsFaction(1, myFaction); // Default to own if (!fme.isAdminBypassing()) { - Access access = forFaction.getAccess(fme, PermissableAction.TERRITORY); - if (access == Access.DENY) { - fme.msg(TL.GENERIC_NOPERMISSION, "change faction territory!"); + Access access = myFaction.getAccess(fme, PermissableAction.TERRITORY); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "change faction territory"); return; } } + if (radius < 1) { msg(TL.COMMAND_CLAIM_INVALIDRADIUS); return; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java index d2fef309..24c3777d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java @@ -31,6 +31,13 @@ public class CmdDeinvite extends FCommand { @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.ADMIN) { + fme.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 : myFaction.getInvites()) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java index 78aead41..ab4975a0 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java @@ -44,16 +44,13 @@ public class CmdDisband extends FCommand { boolean isMyFaction = fme != null && faction == myFaction; - if (isMyFaction) { - if (!assertMinRole(Role.ADMIN)) { - return; - } - } else { - if (!Permission.DISBAND_ANY.has(sender, true)) { + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.DISBAND); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband faction"); return; } } - if (!faction.isNormal()) { msg(TL.COMMAND_DISBAND_IMMUTABLE.toString()); return; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java b/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java index 8f1a1cf9..eae26dd5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java @@ -30,15 +30,15 @@ public class CmdFWarp extends FCommand { @Override public void perform() { //TODO: check if in combat. - - // Check for access first. - Access access = myFaction.getAccess(fme, PermissableAction.WARP); - - if (access == Access.DENY) { - fme.msg(TL.GENERIC_NOPERMISSION, "warp"); - return; + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.WARP); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use warps"); + return; + } } + if (args.size() == 0) { WarpGUI warpGUI = new WarpGUI(fme); warpGUI.build(); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java index 924df7b5..b01c049f 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java @@ -55,7 +55,6 @@ public class CmdFly extends FCommand { } } - 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. diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java index d710e89a..1f4ffc6b 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java @@ -47,7 +47,7 @@ public class CmdHome extends FCommand { fme.msg(TL.COMMAND_HOME_TELEPORTDISABLED); return; } - f (!fme.isAdminBypassing()) { + if (!fme.isAdminBypassing()) { Access access = myFaction.getAccess(fme, PermissableAction.HOME); if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home"); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java index 2d6075e9..95f28619 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java @@ -50,11 +50,12 @@ public class CmdInvite extends FCommand { if (!fme.isAdminBypassing()) { Access access = myFaction.getAccess(fme, PermissableAction.INVITE); - if (access == Access.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "invite"); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites"); return; } } + if (myFaction.isInvited(target)) { fme.msg(TL.COMMAND_INVITE_ALREADYINVITED, target.getName()); return; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java b/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java index 9f066019..b0e57380 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java @@ -38,11 +38,15 @@ public class CmdSetFWarp extends FCommand { Access access = myFaction.getAccess(fme, PermissableAction.SETWARP); // 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 (access == Access.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) { - fme.msg(TL.GENERIC_NOPERMISSION, "set warp"); - return; + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.SETWARP); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps"); + return; + } } + int maxWarps = P.p.getConfig().getInt("max-warps", 5); if (maxWarps <= myFaction.getWarps().size()) { fme.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java index f4289b66..6ad7ecfb 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java @@ -40,22 +40,11 @@ public class CmdSethome extends FCommand { return; } - Access access = faction.getAccess(fme, PermissableAction.SETHOME); - if (access == Access.DENY) { - fme.msg(TL.GENERIC_NOPERMISSION, "sethome"); - return; - } - - // If player does not have allow run extra permission checks - if (access != Access.ALLOW) { - if (faction == myFaction) { - if (!assertMinRole(Role.MODERATOR)) { - return; - } - } else { - if (!Permission.SETHOME_ANY.has(sender, true)) { - return; - } + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.SETHOME); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN && !Permission.SETHOME_ANY.has(sender, true)) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set home"); + return; } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdTnt.java b/src/main/java/com/massivecraft/factions/cmd/CmdTnt.java index 53abe28a..399f4835 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdTnt.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdTnt.java @@ -36,13 +36,14 @@ public class CmdTnt extends FCommand { return; } - Access access = fme.getFaction().getAccess(fme, PermissableAction.TNTBANK); - if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { - fme.msg(TL.GENERIC_NOPERMISSION, "tntbank"); - return; + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.TNTBANK); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + 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")) { int testNumber = -1; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdTntFill.java b/src/main/java/com/massivecraft/factions/cmd/CmdTntFill.java index ef59ef0c..ee226b11 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdTntFill.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdTntFill.java @@ -34,12 +34,16 @@ public class CmdTntFill extends FCommand { @Override public void perform() { - Access access = fme.getFaction().getAccess(fme, PermissableAction.TNTFILL); - if (access.equals(Access.DENY)) { - fme.msg(TL.GENERIC_NOPERMISSION, "tntfill"); + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.TNTFILL); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use tnt fill"); + return; + } } + msg(TL.COMMAND_TNTFILL_HEADER); int radius = argAsInt(0, 16); int amount = argAsInt(1, 16); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java b/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java index 2060a43b..2af076ac 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdUnban.java @@ -26,21 +26,10 @@ public class CmdUnban extends FCommand { @Override public void perform() { - Access access = myFaction.getAccess(fme, PermissableAction.BAN); - if (access == Access.DENY) { - fme.msg(TL.GENERIC_NOPERMISSION, "ban"); - return; - } - - // Can the player set the home for this faction? - // Check for ALLOW access as well before we check for role. - // TODO: no more duplicate code :( - if (access != Access.ALLOW) { - if (!Permission.BAN.has(sender) && !(assertMinRole(Role.MODERATOR))) { - return; - } - } else { - if (!Permission.BAN.has(sender, true)) { + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.BAN); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN && !Permission.BAN.has(sender, true)) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage bans"); return; } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdUnclaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdUnclaim.java index 6be7cbae..2ebf8d58 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdUnclaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdUnclaim.java @@ -36,15 +36,13 @@ public class CmdUnclaim extends FCommand { final Faction forFaction = this.argAsFaction(1, myFaction); // Default to own if (!fme.isAdminBypassing()) { - Access access = forFaction.getAccess(fme, PermissableAction.TERRITORY); - if (access == Access.DENY) { - fme.msg(TL.GENERIC_NOPERMISSION, "change faction territory!"); + Access access = myFaction.getAccess(fme, PermissableAction.TERRITORY); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage faction territory"); return; } } - - if (radius < 1) { msg(TL.COMMAND_CLAIM_INVALIDRADIUS); return; diff --git a/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java b/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java index cc9eb38f..947dc90d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java @@ -38,21 +38,37 @@ public class FPromoteCommand extends FCommand { return; } - Access access = myFaction.getAccess(fme.getRole(), PermissableAction.PROMOTE); - - // Well this is messy. - if (access == null || access == Access.UNDEFINED) { - if (!assertMinRole(Role.MODERATOR)) { - return; - } - } else if (access == Access.DENY) { - msg(TL.COMMAND_NOACCESS); - return; - } - Role current = target.getRole(); 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.ADMIN) { + fme.msg(TL.GENERIC_NOPERMISSION, "manage ranks"); + return; + } + if (target == fme) { + fme.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); + 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); + return; + } + } + + if (promotion == null) { + fme.msg(TL.COMMAND_PROMOTE_NOTTHATPLAYER); + return; + } + if (promotion == null) { fme.msg(TL.COMMAND_PROMOTE_NOTTHATPLAYER); return; diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index ff18946d..b4517828 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -79,11 +79,12 @@ public class FactionsBlockListener implements Listener { return; } if (event.getBlock().getType() == Material.LEGACY_MOB_SPAWNER) { - Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER); - if (access.equals(Access.DENY)) { - fme.msg(TL.GENERIC_NOPERMISSION, "mine spawners"); - event.setCancelled(true); - + if (!fme.isAdminBypassing()) { + Access access = myFaction.getAccess(fme, PermissableAction.SPAWNER); + if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners"); + return; + } } } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 27300352..d4b22add 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -360,10 +360,6 @@ public class FactionsPlayerListener implements Listener { return false; } - - - - @EventHandler(priority = EventPriority.NORMAL) public void onPlayerJoin(PlayerJoinEvent event) { initPlayer(event.getPlayer()); From 640871d6964fb82ddb3adf31b9958800c0593fe9 Mon Sep 17 00:00:00 2001 From: Svenja Reissaus Date: Thu, 2 Aug 2018 15:05:39 -0300 Subject: [PATCH 10/10] Double check to prevent /f upgrades items showing up when disabled --- .../zcore/fupgrades/FUpgradesGUI.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) 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 d87eecac..4e269cdc 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java @@ -37,22 +37,29 @@ public class FUpgradesGUI implements Listener { inventory.setItem(dummySlots.get(i), dummyItem); } ItemStack[] items = buildItems(fme); - List cropSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Crops.CropItem.slots"); - for (int i = 0; i <= cropSlots.size() - 1; i++) { - inventory.setItem(cropSlots.get(i), items[2]); - } List spawnerSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Spawners.SpawnerItem.slots"); - for (int i = 0; i <= spawnerSlots.size() - 1; i++) { - inventory.setItem(spawnerSlots.get(i), items[1]); - } List expSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.EXP.EXPItem.slots"); - for (int i = 0; i <= expSlots.size() - 1; i++) { - inventory.setItem(expSlots.get(i), items[0]); - } List chestSlots = P.p.getConfig().getIntegerList("fupgrades.MainMenu.Chest.ChestItem.slots"); - for (int i = 0; i <= chestSlots.size() - 1; i++) { - inventory.setItem(chestSlots.get(i), items[3]); + if (cropSlots != -1) { + for (int i = 0; i <= cropSlots.size() - 1; i++) { + inventory.setItem(cropSlots.get(i), items[2]); + } + } + if (spawnerSlots != -1) { + for (int i = 0; i <= spawnerSlots.size() - 1; i++) { + inventory.setItem(spawnerSlots.get(i), items[1]); + } + } + if (expSlots != -1) { + for (int i = 0; i <= expSlots.size() - 1; i++) { + inventory.setItem(expSlots.get(i), items[0]); + } + } + if (chestSlots != -1) { + for (int i = 0; i <= chestSlots.size() - 1; i++) { + inventory.setItem(chestSlots.get(i), items[3]); + } } fme.getPlayer().openInventory(inventory); }