From a8ce60b457594f1b1677e702f25abae3b1c265fa Mon Sep 17 00:00:00 2001 From: Dariasc Date: Sun, 4 Mar 2018 00:12:14 -0300 Subject: [PATCH] Add rank check to /f ban (#1068) * Add rank check to /f ban * Fix incorrect f perm check at SetHome --- .../com/massivecraft/factions/cmd/CmdBan.java | 15 +++++++++++++-- .../com/massivecraft/factions/cmd/CmdSethome.java | 2 +- .../com/massivecraft/factions/zcore/util/TL.java | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdBan.java b/src/main/java/com/massivecraft/factions/cmd/CmdBan.java index c0970e24..ff8d8350 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdBan.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdBan.java @@ -6,6 +6,7 @@ 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.Permissable; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; @@ -37,10 +38,10 @@ public class CmdBan extends FCommand { return; } - // Can the player set the home for this faction? + // 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) && !(assertMinRole(Role.MODERATOR))) { + if (!Permission.BAN.has(sender, true) || !assertMinRole(Role.MODERATOR)) { return; } } else { @@ -55,6 +56,16 @@ public class CmdBan extends FCommand { return; // the above method sends a message if fails to find someone. } + if (fme == target) { + // You may not ban yourself + fme.msg(TL.COMMAND_BAN_SELF); + return; + } else if (target.getFaction() == myFaction && target.getRole().value >= fme.getRole().value) { + // You may not ban someone that has same or higher faction rank + fme.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName()); + return; + } + // Ban the user. myFaction.ban(target, fme); myFaction.deinvite(target); // can't hurt diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java index 94f7c231..1ebd4cec 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java @@ -48,7 +48,7 @@ public class CmdSethome extends FCommand { // Can the player set the home for this faction? // Check for ALLOW access as well before we check for role. if (faction == myFaction && access != Access.ALLOW) { - if (!Permission.SETHOME_ANY.has(sender) && !(assertMinRole(Role.MODERATOR))) { + if (!Permission.SETHOME_ANY.has(sender) || !assertMinRole(Role.MODERATOR)) { return; } } else { 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 d673d0cc..e536d86c 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -78,6 +78,8 @@ public enum TL { COMMAND_BAN_DESCRIPTION("Ban players from joining your Faction."), COMMAND_BAN_TARGET("&cYou were banned from &7%1$s"), // banned player perspective COMMAND_BAN_BANNED("&e%1$s &cbanned &7%2$s"), + COMMAND_BAN_SELF("&cYou may not ban yourself"), + COMMAND_BAN_INSUFFICIENTRANK("&cYour rank is too low to ban &7%1$s"), COMMAND_BANLIST_DESCRIPTION("View a Faction's ban list"), COMMAND_BANLIST_HEADER("&6There are &c%d&6 bans for %s"),