diff --git a/licenses/LICENCE.txt b/licenses/LICENCE.txt index 94a9ed02..93617c4d 100644 --- a/licenses/LICENCE.txt +++ b/licenses/LICENCE.txt @@ -439,7 +439,7 @@ run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do +modify any covered work. These permissableActions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 993b98dc..45d4328e 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -6,7 +6,7 @@ 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.Action; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.Permissable; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -139,11 +139,11 @@ public interface Faction extends EconomyParticipator { public int getDeaths(); - public Access getAccess(Permissable permissable, Action action); + public Access getAccess(Permissable permissable, PermissableAction permissableAction); - public Access getAccess(FPlayer player, Action action); + public Access getAccess(FPlayer player, PermissableAction permissableAction); - public void setPermission(Permissable permissable, Action action, Access access); + public void setPermission(Permissable permissable, PermissableAction permissableAction, Access access); public void resetPerms(); diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index 9f4c5aea..cdca6a9c 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -14,7 +14,7 @@ import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.*; import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.fperms.Access; -import com.massivecraft.factions.zcore.fperms.Action; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TextUtil; import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; @@ -171,7 +171,7 @@ public class P extends MPlugin { Type mapFLocToStringSetType = new TypeToken>>() { }.getType(); - Type accessTypeAdatper = new TypeToken>>() { + Type accessTypeAdatper = new TypeToken>>() { }.getType(); return new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE).registerTypeAdapter(accessTypeAdatper, new PermissionsMapTypeAdapter()).registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter()).registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()).registerTypeAdapterFactory(EnumTypeAdapter.ENUM_FACTORY); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java index f223dd47..ecb5a4e4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java @@ -4,7 +4,7 @@ import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.zcore.fperms.Access; -import com.massivecraft.factions.zcore.fperms.Action; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import java.util.Arrays; @@ -47,7 +47,7 @@ public class CmdPerm extends FCommand { } Set relations = new HashSet<>(); - Set actions = new HashSet<>(); + Set permissableActions = new HashSet<>(); boolean allRelations = argAsString(0).equalsIgnoreCase("all"); boolean allActions = argAsString(1).equalsIgnoreCase("all"); @@ -65,15 +65,15 @@ public class CmdPerm extends FCommand { } if (allActions) { - actions.addAll(Arrays.asList(Action.values())); + permissableActions.addAll(Arrays.asList(PermissableAction.values())); } else { - Action action = Action.fromString(argAsString(1)); - if (action == null) { + PermissableAction permissableAction = PermissableAction.fromString(argAsString(1)); + if (permissableAction == null) { fme.msg(TL.COMMAND_PERM_INVALID_ACTION); return; } - actions.add(action); + permissableActions.add(permissableAction); } Access access = Access.fromString(argAsString(2)); @@ -84,8 +84,8 @@ public class CmdPerm extends FCommand { } for (Relation relation : relations) { - for (Action action : actions) { - fme.getFaction().setPermission(relation, action, access); + for (PermissableAction permissableAction : permissableActions) { + fme.getFaction().setPermission(relation, permissableAction, access); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java b/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java index 3b9dc337..590767f5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java @@ -4,7 +4,7 @@ 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.Action; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; public class FPromoteCommand extends FCommand { @@ -38,7 +38,7 @@ public class FPromoteCommand extends FCommand { return; } - Access access = myFaction.getAccess(fme.getRole(), Action.PROMOTE); + Access access = myFaction.getAccess(fme.getRole(), PermissableAction.PROMOTE); // Well this is messy. if (access == null || access == Access.UNDEFINED) { diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index 908d5a2e..d939371e 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -5,7 +5,7 @@ import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.zcore.fperms.Access; -import com.massivecraft.factions.zcore.fperms.Action; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -252,7 +252,7 @@ public class FactionsBlockListener implements Listener { } } - Access access = otherFaction.getAccess(me, Action.fromString(action)); + Access access = otherFaction.getAccess(me, PermissableAction.fromString(action)); if (access != null && access != Access.UNDEFINED) { // TODO: Update this once new access values are added other than just allow / deny. return access == Access.ALLOW; diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 4707902b..88358485 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -11,6 +11,7 @@ import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.zcore.fperms.Access; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.persist.MemoryFPlayer; import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TextUtil; @@ -32,10 +33,9 @@ import java.util.Map; import java.util.UUID; import java.util.logging.Level; - public class FactionsPlayerListener implements Listener { - public P p; + private P p; public FactionsPlayerListener(P p) { this.p = p; @@ -355,7 +355,7 @@ public class FactionsPlayerListener implements Listener { Relation rel = myFaction.getRelationTo(otherFaction); - Access access = otherFaction.getAccess(me, com.massivecraft.factions.zcore.fperms.Action.ITEM); + Access access = otherFaction.getAccess(me, PermissableAction.ITEM); if (access != null && access != Access.UNDEFINED) { // TODO: Update this once new access values are added other than just allow / deny. return access == Access.ALLOW; @@ -422,10 +422,36 @@ public class FactionsPlayerListener implements Listener { } } - Access access = otherFaction.getAccess(me, com.massivecraft.factions.zcore.fperms.Action.BUILD); - if (access != null && access != Access.UNDEFINED) { - // TODO: Update this once new access values are added other than just allow / deny. - return access == Access.ALLOW; + PermissableAction action = null; + + switch (block.getType()) { + case LEVER: + action = PermissableAction.LEVER; + break; + case STONE_BUTTON: + case WOOD_BUTTON: + action = PermissableAction.BUTTON; + break; + case DARK_OAK_DOOR: + case ACACIA_DOOR: + case BIRCH_DOOR: + case IRON_DOOR: + case JUNGLE_DOOR: + case SPRUCE_DOOR: + case TRAP_DOOR: + case WOOD_DOOR: + case WOODEN_DOOR: + action = PermissableAction.DOOR; + break; + default: + break; + } + + // F PERM check runs through before other checks. + Access access = otherFaction.getAccess(me, action); + if (access == null || access == Access.DENY) { + me.msg(TL.GENERIC_NOPERMISSION, action); + return false; } // We only care about some material types. diff --git a/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java index 3cc73d5d..9975d7c2 100644 --- a/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java +++ b/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java @@ -4,7 +4,7 @@ import com.google.gson.*; import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.zcore.fperms.Access; -import com.massivecraft.factions.zcore.fperms.Action; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import java.lang.reflect.Type; import java.util.HashMap; @@ -12,10 +12,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; -public class PermissionsMapTypeAdapter implements JsonDeserializer>> { +public class PermissionsMapTypeAdapter implements JsonDeserializer>> { @Override - public Map> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { + public Map> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { try { JsonObject obj = json.getAsJsonObject(); @@ -23,7 +23,7 @@ public class PermissionsMapTypeAdapter implements JsonDeserializer> permissionsMap = new ConcurrentHashMap<>(); + Map> permissionsMap = new ConcurrentHashMap<>(); // Top level is Relation for (Map.Entry entry : obj.entrySet()) { @@ -31,10 +31,10 @@ public class PermissionsMapTypeAdapter implements JsonDeserializer access for (Map.Entry entry2 : entry.getValue().getAsJsonObject().entrySet()) { - Map accessMap = new HashMap<>(); - Action action = Action.fromString(entry2.getKey()); + Map accessMap = new HashMap<>(); + PermissableAction permissableAction = PermissableAction.fromString(entry2.getKey()); Access access = Access.fromString(entry2.getValue().getAsString()); - accessMap.put(action, access); + accessMap.put(permissableAction, access); permissionsMap.put(relation, accessMap); } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/Action.java b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java similarity index 76% rename from src/main/java/com/massivecraft/factions/zcore/fperms/Action.java rename to src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java index 2ba0c6e8..9818a654 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/Action.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.zcore.fperms; -public enum Action { +public enum PermissableAction { BUILD("build"), DESTROY("destroy"), FROST_WALK("frostwalk"), @@ -22,7 +22,7 @@ public enum Action { private String name; - Action(String name) { + PermissableAction(String name) { this.name = name; } @@ -41,10 +41,10 @@ public enum Action { * @param check * @return */ - public static Action fromString(String check) { - for (Action action : values()) { - if (action.name().equalsIgnoreCase(check)) { - return action; + public static PermissableAction fromString(String check) { + for (PermissableAction permissableAction : values()) { + if (permissableAction.name().equalsIgnoreCase(check)) { + return permissableAction; } } 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 586bdfe3..6ea81a90 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -11,7 +11,7 @@ import com.massivecraft.factions.util.LazyLocation; import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.zcore.fperms.Access; -import com.massivecraft.factions.zcore.fperms.Action; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; @@ -49,7 +49,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { private long lastDeath; protected int maxVaults; protected Role defaultRole; - protected Map> permissions = new HashMap<>(); + protected Map> permissions = new HashMap<>(); public HashMap> getAnnouncements() { return this.announcements; @@ -325,29 +325,29 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { // -------------------------------------------- // - public Access getAccess(Permissable permissable, Action action) { - if (permissable == null || action == null) { - return null; + public Access getAccess(Permissable permissable, PermissableAction permissableAction) { + if (permissable == null || permissableAction == null) { + return Access.UNDEFINED; } - Map accessMap = permissions.get(permissable); - if (accessMap != null && accessMap.containsKey(action)) { - return accessMap.get(action); + Map accessMap = permissions.get(permissable); + if (accessMap != null && accessMap.containsKey(permissableAction)) { + return accessMap.get(permissableAction); } - return null; + return Access.UNDEFINED; } /** * Get the Access of a player. Will use player's Role if they are a faction member. Otherwise, uses their Relation. * * @param player - * @param action + * @param permissableAction * @return */ - public Access getAccess(FPlayer player, Action action) { - if (player == null || action == null) { - return null; + public Access getAccess(FPlayer player, PermissableAction permissableAction) { + if (player == null || permissableAction == null) { + return Access.UNDEFINED; } Permissable perm; @@ -358,21 +358,21 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { perm = player.getFaction().getRelationTo(this); } - Map accessMap = permissions.get(perm); - if (accessMap != null && accessMap.containsKey(action)) { - return accessMap.get(action); + Map accessMap = permissions.get(perm); + if (accessMap != null && accessMap.containsKey(permissableAction)) { + return accessMap.get(permissableAction); } - return null; + return Access.UNDEFINED; } - public void setPermission(Permissable permissable, Action action, Access access) { - Map accessMap = permissions.get(permissable); + public void setPermission(Permissable permissable, PermissableAction permissableAction, Access access) { + Map accessMap = permissions.get(permissable); if (accessMap == null) { accessMap = new HashMap<>(); } - accessMap.put(action, access); + accessMap.put(permissableAction, access); } public void resetPerms() { @@ -381,9 +381,9 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { permissions.clear(); // First populate a map with undefined as the permission for each action. - Map freshMap = new HashMap<>(); - for (Action action : Action.values()) { - freshMap.put(action, Access.UNDEFINED); + Map freshMap = new HashMap<>(); + for (PermissableAction permissableAction : PermissableAction.values()) { + freshMap.put(permissableAction, Access.UNDEFINED); } // Put the map in there for each relation.