diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 83f8ceeb..2d8b965b 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -62,6 +62,7 @@ import com.massivecraft.factions.entity.migrator.MigratorMConf003CleanInactivity import com.massivecraft.factions.entity.migrator.MigratorMConf004Rank; import com.massivecraft.factions.entity.migrator.MigratorMConf005Warps; import com.massivecraft.factions.entity.migrator.MigratorMPerm001Warps; +import com.massivecraft.factions.entity.migrator.MigratorMPerm002MoveStandard; import com.massivecraft.factions.entity.migrator.MigratorMPlayer001Ranks; import com.massivecraft.factions.entity.migrator.MigratorMPlayer002UsingAdminMode; import com.massivecraft.factions.entity.migrator.MigratorTerritoryAccess001Restructure; @@ -154,6 +155,7 @@ public class Factions extends MassivePlugin MigratorMConf004Rank.class, MigratorMConf005Warps.class, MigratorMPerm001Warps.class, + MigratorMPerm002MoveStandard.class, MigratorMPlayer001Ranks.class, MigratorMPlayer002UsingAdminMode.class, MigratorTerritoryAccess001Restructure.class diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java index 410d30c0..c2bc270d 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.cmd.type.TypeFaction; import com.massivecraft.factions.cmd.type.TypeMPerm; import com.massivecraft.factions.cmd.type.TypeMPermable; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.event.EventFactionsPermChange; import com.massivecraft.massivecore.MassiveException; @@ -69,7 +70,7 @@ public class CmdFactionsPermSet extends FactionsCommand } // The following is to make sure the leader always has the right to change perms if that is our goal. - if (perm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains("LEADER")) + if (perm == MPerm.getPermPerms() && MConf.get().perm2default.get(MPerm.ID_PERMS).contains("LEADER")) { faction.setPermitted( faction.getLeaderRank(), MPerm.getPermPerms(), true); } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 1978da2c..a3eeab3b 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -803,7 +803,8 @@ public class Faction extends Entity implements FactionsParticipator, MP for (MPerm mperm : MPerm.getAll()) { String id = mperm.getId(); - MassiveSet value = new MassiveSet<>(mperm.getStandard()); + + MassiveSet value = new MassiveSet<>(MConf.get().perm2default.get(id)); if (value.remove("LEADER") && leaderId.isPresent()) value.add(leaderId.get()); if (value.remove("OFFICER") && officerId.isPresent()) value.add(officerId.get()); diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index ab321f4b..4a488dfb 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -543,7 +543,42 @@ public class MConf extends Entity // How often should the task be run? public long taxTaskPeriodMillis = TimeUnit.MILLIS_PER_DAY; + + // -------------------------------------------- // + // PERMISSIONS + // -------------------------------------------- // + + public Map> perm2default = MUtil.map( + MPerm.ID_BUILD, MUtil.set("LEADER", "OFFICER", "MEMBER"), + MPerm.ID_PAINBUILD, MUtil.set(), + MPerm.ID_DOOR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_BUTTON, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_LEVER, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_CONTAINER, MUtil.set("LEADER", "OFFICER", "MEMBER"), + MPerm.ID_NAME, MUtil.set("LEADER"), + MPerm.ID_DESC, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_MOTD, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_INVITE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_KICK, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_RANK, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_TITLE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_WARP, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_SETWARP, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_DEPOSIT, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY", "TRUCE", "NEUTRAL", "ENEMY"), + MPerm.ID_WITHDRAW, MUtil.set("LEADER"), + MPerm.ID_TERRITORY, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_ACCESS, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_VOTE, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT"), + MPerm.ID_CREATEVOTE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_CLAIMNEAR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_TAX, MUtil.set("LEADER"), + MPerm.ID_REL, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_DISBAND, MUtil.set("LEADER"), + MPerm.ID_FLAGS, MUtil.set("LEADER"), + MPerm.ID_PERMS, MUtil.set("LEADER") + ); + // -------------------------------------------- // // ENUMERATIONS // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index b8f361cb..d6dd1976 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -11,13 +11,11 @@ import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Prioritized; import com.massivecraft.massivecore.Registerable; import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.comparator.ComparatorSmart; import com.massivecraft.massivecore.predicate.PredicateIsRegistered; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; import org.bukkit.entity.Player; @@ -148,36 +146,36 @@ public class MPerm extends Entity implements Prioritized, Registerable, N getPermPerms(); } - public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", MUtil.set("LEADER", "OFFICER", "MEMBER"), true, true, true); } - public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", new MassiveSet<>(), true, true, true); } - public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), true, true, true); } - public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), true, true, true); } - public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), true, true, true); } - public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", MUtil.set("LEADER", "OFFICER", "MEMBER"), true, true, true); } + public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", true, true, true); } + public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", true, true, true); } + public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", true, true, true); } + public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", true, true, true); } + public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", true, true, true); } + public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", true, true, true); } - public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", MUtil.set("LEADER"), false, true, true); } - public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermRank() { return getCreative(PRIORITY_RANK, ID_RANK, ID_RANK, "change ranks", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermWarp() { return getCreative(PRIORITY_WARP, ID_WARP, ID_WARP, "teleport to warp", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), false, true, true); } - public static MPerm getPermSetwarp() { return getCreative(PRIORITY_SETWARP, ID_SETWARP, ID_SETWARP, "set warps", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY", "TRUCE", "NEUTRAL", "ENEMY"), false, false, false); } // non editable, non visible. - public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", MUtil.set("LEADER"), false, true, true); } - public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermVote() { return getCreative(PRIORITY_VOTE, ID_VOTE, ID_VOTE, "vote", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT"), false, true, true); } - public static MPerm getPermCreateVote() { return getCreative(PRIORITY_CREATEVOTE, ID_CREATEVOTE, ID_CREATEVOTE, "manage votes", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), false, false, false); } // non editable, non visible. - public static MPerm getPermTax() { return getCreative(PRIORITY_TAX, ID_TAX, ID_TAX, "set taxes", MUtil.set("LEADER"), false, true, true); } - public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", MUtil.set("LEADER", "OFFICER"), false, true, true); } - public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", MUtil.set("LEADER"), false, true, true); } - public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", MUtil.set("LEADER"), false, true, true); } - public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", MUtil.set("LEADER"), false, true, true); } + public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", false, true, true); } + public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", false, true, true); } + public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", false, true, true); } + public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", false, true, true); } + public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", false, true, true); } + public static MPerm getPermRank() { return getCreative(PRIORITY_RANK, ID_RANK, ID_RANK, "change ranks", false, true, true); } + public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", false, true, true); } + public static MPerm getPermWarp() { return getCreative(PRIORITY_WARP, ID_WARP, ID_WARP, "teleport to warp", false, true, true); } + public static MPerm getPermSetwarp() { return getCreative(PRIORITY_SETWARP, ID_SETWARP, ID_SETWARP, "set warps", false, true, true); } + public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", false, false, false); } // non editable, non visible. + public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", false, true, true); } + public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", false, true, true); } + public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", false, true, true); } + public static MPerm getPermVote() { return getCreative(PRIORITY_VOTE, ID_VOTE, ID_VOTE, "vote", false, true, true); } + public static MPerm getPermCreateVote() { return getCreative(PRIORITY_CREATEVOTE, ID_CREATEVOTE, ID_CREATEVOTE, "manage votes", false, true, true); } + public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", false, false, false); } // non editable, non visible. + public static MPerm getPermTax() { return getCreative(PRIORITY_TAX, ID_TAX, ID_TAX, "set taxes", false, true, true); } + public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", false, true, true); } + public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", false, true, true); } + public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", false, true, true); } + public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", false, true, true); } - public static MPerm getCreative(int priority, String id, String name, String desc, Set standard, boolean territory, boolean editable, boolean visible) + public static MPerm getCreative(int priority, String id, String name, String desc, boolean territory, boolean editable, boolean visible) { MPerm ret = MPermColl.get().get(id, false); if (ret != null) @@ -186,7 +184,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N return ret; } - ret = new MPerm(priority, name, desc, standard, territory, editable, visible); + ret = new MPerm(priority, name, desc, territory, editable, visible); MPermColl.get().attach(ret, id); ret.setRegistered(true); ret.sync(); @@ -201,14 +199,14 @@ public class MPerm extends Entity implements Prioritized, Registerable, N @Override public MPerm load(MPerm that) { + //System.out.println("Loading MPerm"); this.priority = that.priority; this.name = that.name; this.desc = that.desc; - this.standard = that.standard; this.territory = that.territory; this.editable = that.editable; this.visible = that.visible; - + return this; } @@ -224,7 +222,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N // VERSION // -------------------------------------------- // - public int version = 1; + public int version = 2; // -------------------------------------------- // // FIELDS @@ -258,10 +256,10 @@ public class MPerm extends Entity implements Prioritized, Registerable, N // What is the standard (aka default) perm value? // This value will be set for factions from the beginning. // Example: ... set of relations ... - @Deprecated - private Set standard = new MassiveSet<>(); - @Deprecated public Set getStandard() { return this.standard; } - @Deprecated public MPerm setStandard(Set standard) { this.standard = standard; this.changed(); return this; } + //@Deprecated + //private Set standard = null; + //@Deprecated public Set getStandard() { return this.standard; } + //@Deprecated public MPerm setStandard(Set standard) { this.standard = standard; this.changed(); return this; } // Is this a territory perm meaning it has to do with territory construction, modification or interaction? // True Examples: build, container, door, lever etc. @@ -299,12 +297,11 @@ public class MPerm extends Entity implements Prioritized, Registerable, N // No argument constructor for GSON } - public MPerm(int priority, String name, String desc, Set standard, boolean territory, boolean editable, boolean visible) + public MPerm(int priority, String name, String desc, boolean territory, boolean editable, boolean visible) { this.priority = priority; this.name = name; this.desc = desc; - this.standard = standard; this.territory = territory; this.editable = editable; this.visible = visible; diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java index 8a39e4fc..e6876410 100644 --- a/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java +++ b/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java @@ -4,6 +4,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.Rank; import com.massivecraft.massivecore.MassiveCore; @@ -68,7 +69,10 @@ public class MigratorFaction002Ranks extends MigratorRoot Map> ret = new MassiveMap<>(); for (MPerm mperm : MPerm.getAll()) { - Set value = new MassiveSet<>(mperm.getStandard()); + // This should work since MConf and MPerm is loaded /before/ Factions + //Set value = new MassiveSet<>(mperm.getStandard()); + Set value = new MassiveSet<>(MConf.get().perm2default.get(mperm.getId())); + if (value.remove("LEADER")) value.add(leaderId); if (value.remove("OFFICER")) value.add(officerId); if (value.remove("MEMBER")) value.add(memberId); diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java b/src/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java new file mode 100644 index 00000000..ec62b777 --- /dev/null +++ b/src/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java @@ -0,0 +1,47 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +import java.util.Set; + +public class MigratorMPerm002MoveStandard extends MigratorRoot +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMPerm002MoveStandard i = new MigratorMPerm002MoveStandard(); + public static MigratorMPerm002MoveStandard get() { return i; } + private MigratorMPerm002MoveStandard() + { + super(MPerm.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) + { + JsonElement jsonStandard = entity.remove("standard"); + if (jsonStandard == null || !jsonStandard.isJsonArray()) return; + + JsonArray jsonArray = jsonStandard.getAsJsonArray(); + Set result = new MassiveSet<>(); + jsonArray.forEach(e -> result.add(e.getAsString())); + + String id = entity.get("name").getAsString(); + + // This is hacky but we utilise that names and ids are the same + MConf.get().perm2default.put(id, result); + MConf.get().changed(); + } + +}