From 4dba9140de00ab52a674b7f969f3547d2b02cf43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Ulf=20J=C3=B8rgensen?= Date: Tue, 9 May 2017 10:59:38 +0200 Subject: [PATCH] Fix getters for motd and description --- .../factions/cmd/CmdFactionsDescription.java | 2 +- .../factions/cmd/CmdFactionsMotd.java | 16 ++++------- .../factions/engine/EngineMoveChunk.java | 2 +- .../factions/engine/EngineShow.java | 2 +- .../massivecraft/factions/entity/Faction.java | 28 +++++++++++++++---- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java index 73f7e1c5..3ccbdd5a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java @@ -48,7 +48,7 @@ public class CmdFactionsDescription extends FactionsCommand // Inform for (MPlayer follower : msenderFaction.getMPlayers()) { - follower.msg("%s set your faction description to:\n%s", MixinDisplayName.get().getDisplayName(sender, follower), msenderFaction.getDescription()); + follower.msg("%s set your faction description to:\n%s", MixinDisplayName.get().getDisplayName(sender, follower), msenderFaction.getDescriptionDesc()); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java b/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java index a6b1c567..ba608ae8 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.event.EventFactionsMotdChange; @@ -42,22 +41,17 @@ public class CmdFactionsMotd extends FactionsCommand // Args String target = this.readArg(); - - // Clean input - target = Faction.clean(target); + + target = target.trim(); target = Txt.parse(target); // Get Old - String old = null; - if (msenderFaction.hasMotd()) - { - old = msenderFaction.getMotd(); - } + String old = msenderFaction.getMotd(); // NoChange if (MUtil.equals(old, target)) { - msg("The motd for %s is already: %s", msenderFaction.describeTo(msender, true), old == null ? Txt.parse("none") : old); + msg("The motd for %s is already: %s", msenderFaction.describeTo(msender, true), msenderFaction.getMotdDesc()); return; } @@ -73,7 +67,7 @@ public class CmdFactionsMotd extends FactionsCommand // Inform for (MPlayer follower : msenderFaction.getMPlayers()) { - follower.msg("%s set your faction motd to:\n%s", MixinDisplayName.get().getDisplayName(sender, follower), msenderFaction.getMotd()); + follower.msg("%s set your faction motd to:\n%s", MixinDisplayName.get().getDisplayName(sender, follower), msenderFaction.getMotdDesc()); } } diff --git a/src/com/massivecraft/factions/engine/EngineMoveChunk.java b/src/com/massivecraft/factions/engine/EngineMoveChunk.java index f34630a3..1a42194d 100644 --- a/src/com/massivecraft/factions/engine/EngineMoveChunk.java +++ b/src/com/massivecraft/factions/engine/EngineMoveChunk.java @@ -114,7 +114,7 @@ public class EngineMoveChunk extends Engine string = string.replace("{name}", faction.getName()); string = string.replace("{relcolor}", faction.getColorTo(mplayer).toString()); - string = string.replace("{desc}", faction.getDescription()); + string = string.replace("{desc}", faction.getDescriptionDesc()); return string; } diff --git a/src/com/massivecraft/factions/engine/EngineShow.java b/src/com/massivecraft/factions/engine/EngineShow.java index da88a545..5f5caab2 100644 --- a/src/com/massivecraft/factions/engine/EngineShow.java +++ b/src/com/massivecraft/factions/engine/EngineShow.java @@ -59,7 +59,7 @@ public class EngineShow extends Engine } // DESCRIPTION - show(idPriorityLiness, Const.SHOW_ID_FACTION_DESCRIPTION, Const.SHOW_PRIORITY_FACTION_DESCRIPTION, "Description", faction.getDescription()); + show(idPriorityLiness, Const.SHOW_ID_FACTION_DESCRIPTION, Const.SHOW_PRIORITY_FACTION_DESCRIPTION, "Description", faction.getDescriptionDesc()); // SECTION: NORMAL if (normal) diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 57b39ce7..dc01c1b1 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -237,8 +237,7 @@ public class Faction extends Entity implements FactionsParticipator public String getDescription() { - if (this.hasDescription()) return this.description; - return NODESCRIPTION; + return this.description; } public void setDescription(String description) @@ -256,6 +255,15 @@ public class Faction extends Entity implements FactionsParticipator this.changed(); } + // FINER + + public String getDescriptionDesc() + { + String motd = this.getDescription(); + if (motd == null) motd = NODESCRIPTION; + return motd; + } + // -------------------------------------------- // // FIELD: motd // -------------------------------------------- // @@ -269,8 +277,7 @@ public class Faction extends Entity implements FactionsParticipator public String getMotd() { - if (this.hasMotd()) return this.motd; - return NOMOTD; + return this.motd; } public void setMotd(String motd) @@ -290,6 +297,17 @@ public class Faction extends Entity implements FactionsParticipator // FINER + public String getMotdDesc() + { + return getMotdDesc(this.getMotd()); + } + + private static String getMotdDesc(String motd) + { + if (motd == null) motd = NOMOTD; + return motd; + } + public List getMotdMessages() { // Create @@ -300,7 +318,7 @@ public class Faction extends Entity implements FactionsParticipator title = Txt.titleize(title); ret.add(title); - String motd = Txt.parse("" + this.getMotd()); + String motd = Txt.parse("") + this.getMotdDesc(); ret.add(motd); ret.add("");