From 41bdc25441871353d35ffd41193f95c053a51100 Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Mon, 5 Feb 2018 20:46:43 -0700 Subject: [PATCH] Fix permission persistence --- .../java/com/massivecraft/factions/P.java | 3 +- .../util/PermissionsMapTypeAdapter.java | 34 +++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index cdca6a9c..95c7b04d 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -14,6 +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.Permissable; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TextUtil; import net.milkbowl.vault.permission.Permission; @@ -171,7 +172,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/util/PermissionsMapTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java index 9975d7c2..69fdd79f 100644 --- a/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java +++ b/src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java @@ -3,7 +3,9 @@ package com.massivecraft.factions.util; import com.google.gson.*; import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Relation; +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 java.lang.reflect.Type; @@ -12,10 +14,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,11 +25,15 @@ public class PermissionsMapTypeAdapter implements JsonDeserializer> permissionsMap = new ConcurrentHashMap<>(); + Map> permissionsMap = new ConcurrentHashMap<>(); // Top level is Relation for (Map.Entry entry : obj.entrySet()) { - Relation relation = Relation.fromString(entry.getKey()); + Permissable permissable = getPermissable(entry.getKey()); + + if (permissable == null) { + continue; + } // Second level is the map between action -> access for (Map.Entry entry2 : entry.getValue().getAsJsonObject().entrySet()) { @@ -36,16 +42,32 @@ public class PermissionsMapTypeAdapter implements JsonDeserializer