From 442e90759d1958d3773082724cb22a7e1848506e Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Sun, 27 Jan 2019 17:29:28 +0100 Subject: [PATCH] Semi-rename home/warp MPerms So the names for MPerms have been renamed, but their id's have not --- .../factions/cmd/CmdFactionsWarpAdd.java | 2 +- .../factions/cmd/CmdFactionsWarpGo.java | 2 +- .../factions/cmd/CmdFactionsWarpList.java | 2 +- .../factions/cmd/CmdFactionsWarpRemove.java | 2 +- .../massivecraft/factions/entity/MPerm.java | 24 +++++++---- .../migrator/MigratorMPerm001Warps.java | 43 +++++++++++++++++++ 6 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 src/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java index 97068272..ba25f69e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java @@ -46,7 +46,7 @@ public class CmdFactionsWarpAdd extends FactionsCommandWarp Warp warp = new Warp(name, ps); // MPerm - if ( ! MPerm.getPermSethome().has(msender, faction, true)) return; + if ( ! MPerm.getPermSetwarp().has(msender, faction, true)) return; if (faction.getWarps().getAll().stream().map(Warp::getName).anyMatch(s -> s.equalsIgnoreCase(name))) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java index fcde63ef..48aebd1a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java @@ -54,7 +54,7 @@ public class CmdFactionsWarpGo extends FactionsCommandWarp String warpDesc = Txt.parse("%s in %s.", warp.getName(), faction.describeTo(msender, false)); // Any and MPerm - if ( ! MPerm.getPermHome().has(msender, faction, true)) return; + if ( ! MPerm.getPermWarp().has(msender, faction, true)) return; if ( ! MConf.get().warpsTeleportAllowedFromEnemyTerritory && msender.isInEnemyTerritory()) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java index 9d42f263..28801e56 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java @@ -36,7 +36,7 @@ public class CmdFactionsWarpList extends FactionsCommandWarp int idx = this.readArg(); // Any and MPerm - if ( ! MPerm.getPermHome().has(msender, faction, true)) return; + if ( ! MPerm.getPermWarp().has(msender, faction, true)) return; Pager pager = new Pager<>(this, "Warps for " + faction.getName(), idx, faction.getWarps().getAll()); pager.setMsonifier((Stringifier) (warp, i) -> diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java index 2140b13e..8f6aebf1 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java @@ -33,7 +33,7 @@ public class CmdFactionsWarpRemove extends FactionsCommandWarp Warp warp = TypeWarp.get(faction).read(this.argAt(0), sender); // Any and MPerm - if ( ! MPerm.getPermSethome().has(msender, faction, true)) return; + if ( ! MPerm.getPermSetwarp().has(msender, faction, true)) return; // Event EventFactionsWarpRemove event = new EventFactionsWarpRemove(sender, faction, warp); diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index 270f8a59..6de15a8c 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -46,8 +46,8 @@ public class MPerm extends Entity implements Prioritized, Registerable, N public final static transient String ID_KICK = "kick"; public final static transient String ID_RANK = "rank"; public final static transient String ID_TITLE = "title"; - public final static transient String ID_HOME = "home"; - public final static transient String ID_SETHOME = "sethome"; + public final static transient String ID_WARP = "home"; + public final static transient String ID_SETWARP = "sethome"; public final static transient String ID_DEPOSIT = "deposit"; public final static transient String ID_WITHDRAW = "withdraw"; public final static transient String ID_TERRITORY = "territory"; @@ -72,8 +72,8 @@ public class MPerm extends Entity implements Prioritized, Registerable, N public final static transient int PRIORITY_KICK = 11000; public final static transient int PRIORITY_RANK = 11500; public final static transient int PRIORITY_TITLE = 12000; - public final static transient int PRIORITY_HOME = 13000; - public final static transient int PRIORITY_SETHOME = 14000; + public final static transient int PRIORITY_WARP = 13000; + public final static transient int PRIORITY_SETWARP = 14000; public final static transient int PRIORITY_DEPOSIT = 15000; public final static transient int PRIORITY_WITHDRAW = 16000; public final static transient int PRIORITY_TERRITORY = 17000; @@ -122,8 +122,8 @@ public class MPerm extends Entity implements Prioritized, Registerable, N getPermKick(); getPermRank(); getPermTitle(); - getPermHome(); - getPermSethome(); + getPermWarp(); + getPermSetwarp(); getPermDeposit(); getPermWithdraw(); getPermTerritory(); @@ -149,8 +149,8 @@ public class MPerm extends Entity implements Prioritized, Registerable, N 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 getPermHome() { return getCreative(PRIORITY_HOME, ID_HOME, ID_HOME, "teleport home", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), false, true, true); } - public static MPerm getPermSethome() { return getCreative(PRIORITY_SETHOME, ID_SETHOME, ID_SETHOME, "set the home", MUtil.set("LEADER", "OFFICER"), false, true, true); } + public static MPerm getPermWarp() { return getCreative(PRIORITY_WARP, ID_WARP, "warp", "teleport to warp", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), false, true, true); } + public static MPerm getPermSetwarp() { return getCreative(PRIORITY_SETWARP, ID_SETWARP, "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); } @@ -203,7 +203,13 @@ public class MPerm extends Entity implements Prioritized, Registerable, N private transient boolean registered = false; public boolean isRegistered() { return this.registered; } public void setRegistered(boolean registered) { this.registered = registered; } - + // -------------------------------------------- // + // VERSION + // -------------------------------------------- // + + public int version = 1; + + // -------------------------------------------- // // FIELDS // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java b/src/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java new file mode 100644 index 00000000..4f709908 --- /dev/null +++ b/src/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java @@ -0,0 +1,43 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +public class MigratorMPerm001Warps extends MigratorRoot +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMPerm001Warps i = new MigratorMPerm001Warps(); + public static MigratorMPerm001Warps get() { return i; } + private MigratorMPerm001Warps() + { + super(MPerm.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) + { + JsonElement jsonName = entity.get("name"); + String name = jsonName.getAsString(); + if (name.equalsIgnoreCase("home")) name = "warp"; + if (name.equalsIgnoreCase("sethome")) name = "setwarp"; + + entity.addProperty("name", name); + + JsonElement jsonDesc = entity.get("desc"); + String desc = jsonDesc.getAsString(); + if (desc.equalsIgnoreCase("teleport home")) desc = "teleport to warp"; + if (desc.equalsIgnoreCase("set the home")) desc = "set warps"; + + entity.addProperty("desc", desc); + } + +}