mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-12-24 01:27:51 +01:00
Check for f perm in building
This commit is contained in:
parent
9384b0faa6
commit
182022fe5f
@ -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.
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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<Map<FLocation, Set<String>>>() {
|
||||
}.getType();
|
||||
|
||||
Type accessTypeAdatper = new TypeToken<Map<Relation, Map<Action, Access>>>() {
|
||||
Type accessTypeAdatper = new TypeToken<Map<Relation, Map<PermissableAction, Access>>>() {
|
||||
}.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);
|
||||
|
@ -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<Relation> relations = new HashSet<>();
|
||||
Set<Action> actions = new HashSet<>();
|
||||
Set<PermissableAction> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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<Map<Relation, Map<Action, Access>>> {
|
||||
public class PermissionsMapTypeAdapter implements JsonDeserializer<Map<Relation, Map<PermissableAction, Access>>> {
|
||||
|
||||
@Override
|
||||
public Map<Relation, Map<Action, Access>> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public Map<Relation, Map<PermissableAction, Access>> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
@ -23,7 +23,7 @@ public class PermissionsMapTypeAdapter implements JsonDeserializer<Map<Relation,
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<Relation, Map<Action, Access>> permissionsMap = new ConcurrentHashMap<>();
|
||||
Map<Relation, Map<PermissableAction, Access>> permissionsMap = new ConcurrentHashMap<>();
|
||||
|
||||
// Top level is Relation
|
||||
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
@ -31,10 +31,10 @@ public class PermissionsMapTypeAdapter implements JsonDeserializer<Map<Relation,
|
||||
|
||||
// Second level is the map between action -> access
|
||||
for (Map.Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
Map<Action, Access> accessMap = new HashMap<>();
|
||||
Action action = Action.fromString(entry2.getKey());
|
||||
Map<PermissableAction, Access> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<Permissable, Map<Action, Access>> permissions = new HashMap<>();
|
||||
protected Map<Permissable, Map<PermissableAction, Access>> permissions = new HashMap<>();
|
||||
|
||||
public HashMap<String, List<String>> 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<Action, Access> accessMap = permissions.get(permissable);
|
||||
if (accessMap != null && accessMap.containsKey(action)) {
|
||||
return accessMap.get(action);
|
||||
Map<PermissableAction, Access> 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<Action, Access> accessMap = permissions.get(perm);
|
||||
if (accessMap != null && accessMap.containsKey(action)) {
|
||||
return accessMap.get(action);
|
||||
Map<PermissableAction, Access> 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<Action, Access> accessMap = permissions.get(permissable);
|
||||
public void setPermission(Permissable permissable, PermissableAction permissableAction, Access access) {
|
||||
Map<PermissableAction, Access> 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<Action, Access> freshMap = new HashMap<>();
|
||||
for (Action action : Action.values()) {
|
||||
freshMap.put(action, Access.UNDEFINED);
|
||||
Map<PermissableAction, Access> freshMap = new HashMap<>();
|
||||
for (PermissableAction permissableAction : PermissableAction.values()) {
|
||||
freshMap.put(permissableAction, Access.UNDEFINED);
|
||||
}
|
||||
|
||||
// Put the map in there for each relation.
|
||||
|
Loading…
Reference in New Issue
Block a user