From 8eaf1215d2dd22e5497c7ab49e1fe21ce39e9d99 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 28 Aug 2015 09:00:24 +0200 Subject: [PATCH] Territory Titles Toggle Command --- plugin.yml | 3 + src/com/massivecraft/factions/Perm.java | 147 +++++++++--------- .../factions/cmd/CmdFactions.java | 2 + .../cmd/CmdFactionsTerritorytitles.java | 65 ++++++++ .../factions/engine/EngineMain.java | 15 +- .../massivecraft/factions/entity/MConf.java | 12 +- .../massivecraft/factions/entity/MPlayer.java | 33 ++++ 7 files changed, 187 insertions(+), 90 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java diff --git a/plugin.yml b/plugin.yml index e1ca5b44..25d183b3 100644 --- a/plugin.yml +++ b/plugin.yml @@ -72,6 +72,7 @@ permissions: factions.name: {description: set faction name, default: false} factions.title: {description: set player title, default: false} factions.title.color: {description: set player title with color, default: false} + factions.territorytitles: {description: toggle territory titles, default: false} factions.unclaim: {description: unclaim faction territory, default: false} factions.unclaim.one: {description: unclaim a single chunk, default: false} factions.unclaim.auto: {description: unclaim as you walk around, default: false} @@ -151,6 +152,7 @@ permissions: factions.name: true factions.title: true factions.title.color: true + factions.territorytitles: true factions.unclaim: true factions.unclaim.one: true factions.unclaim.auto: true @@ -251,6 +253,7 @@ permissions: factions.name: true factions.title: true factions.title.color: true + factions.territorytitles: true factions.unclaim: true factions.unclaim.one: true factions.unclaim.auto: true diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index cc1de352..84ed997d 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -10,77 +10,78 @@ public enum Perm // ENUM // -------------------------------------------- // - ACCESS("access"), - ACCESS_VIEW("access.view"), - ACCESS_PLAYER("access.player"), - ACCESS_FACTION("access.faction"), - ADMIN("admin"), - CLAIM("claim"), - CLAIM_ONE("claim.one"), - CLAIM_AUTO("claim.auto"), - CLAIM_FILL("claim.fill"), - CLAIM_SQUARE("claim.square"), - CLAIM_CIRCLE("claim.circle"), - CLAIM_ALL("claim.all"), - CREATE("create"), - DESCRIPTION("description"), - DISBAND("disband"), - EXPANSIONS("expansions"), - FACTION("faction"), - FLAG("flag"), - FLAG_LIST("flag.list"), - FLAG_SET("flag.set"), - FLAG_SHOW("flag.show"), - HOME("home"), - INVITE("invite"), - INVITE_LIST("invite.list"), - INVITE_LIST_OTHER("invite.list.other"), - INVITE_ADD("invite.add"), - INVITE_REMOVE("invite.remove"), - JOIN("join"), - JOIN_ANY("join.any"), - JOIN_OTHERS("join.others"), - KICK("kick"), - LEAVE("leave"), - LIST("list"), - MAP("map"), - MONEY("money"), - MONEY_BALANCE("money.balance"), - MONEY_BALANCE_ANY("money.balance.any"), - MONEY_DEPOSIT("money.deposit"), - MONEY_F2F("money.f2f"), - MONEY_F2P("money.f2p"), - MONEY_P2F("money.p2f"), - MONEY_WITHDRAW("money.withdraw"), - MOTD("motd"), - OPEN("open"), - PERM("perm"), - PERM_LIST("perm.list"), - PERM_SET("perm.set"), - PERM_SHOW("perm.show"), - PLAYER("player"), - POWERBOOST("powerboost"), - RANK("rank"), - RANK_SHOW("rank.show"), - RANK_ACTION("rank.action"), - RELATION("relation"), - SEECHUNK("seechunk"), - SEECHUNKOLD("seechunkold"), - SETHOME("sethome"), - SETPOWER("setpower"), - STATUS("status"), - NAME("name"), - TITLE("title"), - TITLE_COLOR("title.color"), - UNCLAIM("unclaim"), - UNCLAIM_ONE("unclaim.one"), - UNCLAIM_AUTO("unclaim.auto"), - UNCLAIM_FILL("unclaim.fill"), - UNCLAIM_SQUARE("unclaim.square"), - UNCLAIM_CIRCLE("unclaim.circle"), - UNCLAIM_ALL("unclaim.all"), - UNSETHOME("unsethome"), - VERSION("version"), + ACCESS, + ACCESS_VIEW, + ACCESS_PLAYER, + ACCESS_FACTION, + ADMIN, + CLAIM, + CLAIM_ONE, + CLAIM_AUTO, + CLAIM_FILL, + CLAIM_SQUARE, + CLAIM_CIRCLE, + CLAIM_ALL, + CREATE, + DESCRIPTION, + DISBAND, + EXPANSIONS, + FACTION, + FLAG, + FLAG_LIST, + FLAG_SET, + FLAG_SHOW, + HOME, + INVITE, + INVITE_LIST, + INVITE_LIST_OTHER, + INVITE_ADD, + INVITE_REMOVE, + JOIN, + JOIN_ANY, + JOIN_OTHERS, + KICK, + LEAVE, + LIST, + MAP, + MONEY, + MONEY_BALANCE, + MONEY_BALANCE_ANY, + MONEY_DEPOSIT, + MONEY_F2F, + MONEY_F2P, + MONEY_P2F, + MONEY_WITHDRAW, + MOTD, + OPEN, + PERM, + PERM_LIST, + PERM_SET, + PERM_SHOW, + PLAYER, + POWERBOOST, + RANK, + RANK_SHOW, + RANK_ACTION, + RELATION, + SEECHUNK, + SEECHUNKOLD, + SETHOME, + SETPOWER, + STATUS, + NAME, + TITLE, + TITLE_COLOR, + TERRITORYTITLES, + UNCLAIM, + UNCLAIM_ONE, + UNCLAIM_AUTO, + UNCLAIM_FILL, + UNCLAIM_SQUARE, + UNCLAIM_CIRCLE, + UNCLAIM_ALL, + UNSETHOME, + VERSION, // END OF LIST ; @@ -95,9 +96,9 @@ public enum Perm // CONSTRUCT // -------------------------------------------- // - Perm(final String node) + Perm() { - this.node = "factions."+node; + this.node = "factions." + this.name().toLowerCase().replace('_', '.'); } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index 2da2d058..16e2d706 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -39,6 +39,7 @@ public class CmdFactions extends FactionsCommand public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); + public CmdFactionsTerritorytitles cmdFactionsTerritorytitles = new CmdFactionsTerritorytitles(); public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus(); public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); @@ -91,6 +92,7 @@ public class CmdFactions extends FactionsCommand this.addSubCommand(this.cmdFactionsMoney); this.addSubCommand(this.cmdFactionsSeeChunk); this.addSubCommand(this.cmdFactionsSeeChunkOld); + this.addSubCommand(this.cmdFactionsTerritorytitles); this.addSubCommand(this.cmdFactionsClaim); this.addSubCommand(this.cmdFactionsUnclaim); this.addSubCommand(this.cmdFactionsAccess); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java b/src/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java new file mode 100644 index 00000000..4efa7157 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java @@ -0,0 +1,65 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.cmd.VisibilityMode; +import com.massivecraft.massivecore.cmd.arg.ARBoolean; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.cmd.req.ReqTitlesAvailable; +import com.massivecraft.massivecore.mixin.Mixin; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsTerritorytitles extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsTerritorytitles() + { + // Aliases + this.addAliases("tt", "territorytitles"); + + // Args + this.addArg(ARBoolean.get(), "on|off", "toggle"); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.TERRITORYTITLES.node)); + this.addRequirements(ReqTitlesAvailable.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public VisibilityMode getVisibilityMode() + { + // We hide the command if titles aren't available. + if ( ! Mixin.isTitlesAvailable()) return VisibilityMode.INVISIBLE; + return super.getVisibilityMode(); + } + + @Override + public void perform() throws MassiveException + { + // Args + boolean before = msender.isTerritoryInfoTitles(); + boolean after = this.readArg(!before); + String desc = Txt.parse(after ? "ON" : "OFF"); + + // NoChange + if (after == before) + { + msg("Territory titles is already %s.", desc); + return; + } + + // Apply + msender.setTerritoryInfoTitles(after); + + // Inform + msg("Territory titles is now %s.", desc); + } + +} diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index 80594a26..7059ef0a 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -695,11 +695,11 @@ public class EngineMain extends EngineAbstract } else if (factionFrom != factionTo) { - if (this.isTerritoryInfoUsingScreen()) + if (mplayer.isTerritoryInfoTitles()) { - String maintitle = parseTerritoryInfo(MConf.get().territoryInfoScreenMaintitle, mplayer, factionTo); - String subtitle = parseTerritoryInfo(MConf.get().territoryInfoScreenSubtitle, mplayer, factionTo); - Mixin.sendTitleMessage(player, MConf.get().territoryInfoScreenTicksIn, MConf.get().territoryInfoScreenTicksStay, MConf.get().territoryInfoScreenTicksOut, maintitle, subtitle); + String maintitle = parseTerritoryInfo(MConf.get().territoryInfoTitlesMain, mplayer, factionTo); + String subtitle = parseTerritoryInfo(MConf.get().territoryInfoTitlesSub, mplayer, factionTo); + Mixin.sendTitleMessage(player, MConf.get().territoryInfoTitlesTicksIn, MConf.get().territoryInfoTitlesTicksStay, MConf.get().territoryInfoTitleTicksOut, maintitle, subtitle); } else { @@ -743,13 +743,6 @@ public class EngineMain extends EngineAbstract return string; } - public boolean isTerritoryInfoUsingScreen() - { - if ( ! MConf.get().territoryInfoUseScreen) return false; - if ( ! Mixin.isTitlesAvailable()) return false; - return true; - } - // -------------------------------------------- // // CHUNK CHANGE: AUTO CLAIM // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index 8a733716..4c8bfd16 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -270,13 +270,13 @@ public class MConf extends Entity // TERRITORY INFO // -------------------------------------------- // - public boolean territoryInfoUseScreen = true; + public boolean territoryInfoTitlesDefault = true; - public String territoryInfoScreenMaintitle = "{relcolor}{name}"; - public String territoryInfoScreenSubtitle = "{desc}"; - public int territoryInfoScreenTicksIn = 5; - public int territoryInfoScreenTicksStay = 60; - public int territoryInfoScreenTicksOut = 5; + public String territoryInfoTitlesMain = "{relcolor}{name}"; + public String territoryInfoTitlesSub = "{desc}"; + public int territoryInfoTitlesTicksIn = 5; + public int territoryInfoTitlesTicksStay = 60; + public int territoryInfoTitleTicksOut = 5; public String territoryInfoChat = " ~ {relcolor}{name} {desc}"; diff --git a/src/com/massivecraft/factions/entity/MPlayer.java b/src/com/massivecraft/factions/entity/MPlayer.java index 2112db0e..e9cc53d0 100644 --- a/src/com/massivecraft/factions/entity/MPlayer.java +++ b/src/com/massivecraft/factions/entity/MPlayer.java @@ -58,6 +58,7 @@ public class MPlayer extends SenderEntity implements EconomyParticipato this.setPower(that.power); this.setMapAutoUpdating(that.mapAutoUpdating); this.setUsingAdminMode(that.usingAdminMode); + this.setTerritoryInfoTitles(that.territoryInfoTitles); return this; } @@ -73,6 +74,7 @@ public class MPlayer extends SenderEntity implements EconomyParticipato if (this.getPowerRounded() != (int) Math.round(MConf.get().defaultPlayerPower)) return false; // if (this.isMapAutoUpdating()) return false; // Just having an auto updating map is not in itself reason enough for database storage. if (this.isUsingAdminMode()) return false; + if (this.isTerritoryInfoTitles() != MConf.get().territoryInfoTitlesDefault) return false; return true; } @@ -158,6 +160,10 @@ public class MPlayer extends SenderEntity implements EconomyParticipato // Null means false private Boolean usingAdminMode = null; + // Does this player use titles for territory info? + // Null means default specified in MConf. + private Boolean territoryInfoTitles = null; + // The id for the faction this player is currently autoclaiming for. // Null means the player isn't auto claiming. // NOTE: This field will not be saved to the database ever. @@ -561,6 +567,33 @@ public class MPlayer extends SenderEntity implements EconomyParticipato this.changed(); } + // -------------------------------------------- // + // FIELD: territoryInfoTitles + // -------------------------------------------- // + + public boolean isTerritoryInfoTitles() + { + if ( ! Mixin.isTitlesAvailable()) return false; + if (this.territoryInfoTitles == null) return MConf.get().territoryInfoTitlesDefault; + return this.territoryInfoTitles; + } + + public void setTerritoryInfoTitles(Boolean territoryInfoTitles) + { + // Clean input + Boolean target = territoryInfoTitles; + if (MUtil.equals(target, MConf.get().territoryInfoTitlesDefault)) target = null; + + // Detect Nochange + if (MUtil.equals(this.territoryInfoTitles, target)) return; + + // Apply + this.territoryInfoTitles = target; + + // Mark as changed + this.changed(); + } + // -------------------------------------------- // // TITLE, NAME, FACTION NAME AND CHAT // -------------------------------------------- //