From 819cb542cdb82ff1c4bba10d9cd22449cdf3aa12 Mon Sep 17 00:00:00 2001 From: Dariasc Date: Fri, 9 Mar 2018 15:22:15 -0300 Subject: [PATCH] Major f perm fix; Fix sethome permission check (#1079) --- .../massivecraft/factions/cmd/CmdPerm.java | 15 ++++++--------- .../massivecraft/factions/cmd/CmdSethome.java | 19 ++++++++++--------- .../massivecraft/factions/struct/Role.java | 3 +-- .../fperms/gui/PermissableRelationGUI.java | 15 ++++++--------- .../factions/zcore/persist/MemoryFaction.java | 4 +++- src/main/resources/config.yml | 4 ++-- 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java index 2ca2e814..b0e317cc 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java @@ -108,16 +108,13 @@ public class CmdPerm extends FCommand { } private Permissable getPermissable(String name) { - try { - return Relation.valueOf(name.toUpperCase()); - } catch (Exception e) { + if (Role.fromString(name.toUpperCase()) != null) { + return Role.fromString(name.toUpperCase()); + } else if (Relation.fromString(name.toUpperCase()) != null) { + return Relation.fromString(name.toUpperCase()); + } else { + return null; } - try { - return Role.valueOf(name.toUpperCase()); - } catch (Exception e) { - } - - return null; } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java index d1bdb022..eb574e39 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java @@ -45,15 +45,16 @@ public class CmdSethome extends FCommand { return; } - // 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, true) || !assertMinRole(Role.MODERATOR)) { - return; - } - } else { - if (!Permission.SETHOME_ANY.has(sender, true)) { - 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; + } } } diff --git a/src/main/java/com/massivecraft/factions/struct/Role.java b/src/main/java/com/massivecraft/factions/struct/Role.java index eb6a29e8..00fc0078 100644 --- a/src/main/java/com/massivecraft/factions/struct/Role.java +++ b/src/main/java/com/massivecraft/factions/struct/Role.java @@ -104,7 +104,6 @@ public enum Role implements Permissable { return ""; } - // Utility method to build items for F Perm GUI @Override public ItemStack buildItem() { @@ -113,7 +112,7 @@ public enum Role implements Permissable { String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", "")); List lore = new ArrayList<>(); - Material material = Material.matchMaterial(RELATION_CONFIG.getString("materials." + name().toLowerCase())); + Material material = Material.matchMaterial(RELATION_CONFIG.getString("materials." + name().toLowerCase(), "STAINED_CLAY")); if (material == null) { return null; } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationGUI.java b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationGUI.java index 8a994e10..a4c68959 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/gui/PermissableRelationGUI.java @@ -96,16 +96,13 @@ public class PermissableRelationGUI implements InventoryHolder, FactionGUI { } private Permissable getPermissable(String name) { - try { - return Relation.valueOf(name.toUpperCase()); - } catch (Exception e) { + if (Role.fromString(name.toUpperCase()) != null) { + return Role.fromString(name.toUpperCase()); + } else if (Relation.fromString(name.toUpperCase()) != null) { + return Relation.fromString(name.toUpperCase()); + } else { + return null; } - try { - return Role.valueOf(name.toUpperCase()); - } catch (Exception e) { - } - - return null; } private void buildItems() { 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 24c679b7..066ef12b 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -419,7 +419,9 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { // Put the map in there for each relation. for (Relation relation : Relation.values()) { - permissions.put(relation, new HashMap<>(freshMap)); + if (relation != Relation.MEMBER) { + permissions.put(relation, new HashMap<>(freshMap)); + } } // And each role. diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 527576ff..48303d9f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -379,7 +379,7 @@ fperm-gui: # Note: Slots start at 0 and end at one less that GUI size slots: recruit: 10 - member: 11 + normal: 11 moderator: 12 truce: 13 ally: 14 @@ -388,7 +388,7 @@ fperm-gui: # Material to be displayed materials: recruit: WOOD_SWORD - member: STONE_SWORD + normal: STONE_SWORD moderator: IRON_SWORD truce: IRON_AXE ally: DIAMOND_SWORD