From 1b0f2d29f84116a6e89db5826b97f164e61747d1 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Fri, 1 Feb 2019 08:37:23 +0100 Subject: [PATCH] Add warp documentation command --- plugin.yml | 3 + src/com/massivecraft/factions/Perm.java | 1 + .../cmd/CmdFactionsDocumentation.java | 1 + .../cmd/CmdFactionsDocumentationWarps.java | 76 +++++++++++++++++++ .../factions/cmd/CmdFactionsPermShow.java | 18 +++++ .../massivecraft/factions/entity/Faction.java | 14 ++++ 6 files changed, 113 insertions(+) create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java diff --git a/plugin.yml b/plugin.yml index d730ffd8..a9b93010 100644 --- a/plugin.yml +++ b/plugin.yml @@ -32,6 +32,7 @@ permissions: factions.documentation.power: {description: show power documentation, default: false} factions.documentation.perms: {description: show perms documentation, default: false} factions.documentation.ranks: {description: show rank documentation, default: false} + factions.documentation.warps: {description: show warp documentation, default: false} factions.expansions: {description: list expansions, default: false} factions.faction: {description: show faction information, default: false} factions.flag: {description: manage faction flags, default: false} @@ -138,6 +139,7 @@ permissions: factions.documentation.perms: true factions.documentation.power: true factions.documentation.ranks: true + factions.documentation.warps: true factions.expansions: true factions.faction: true factions.flag: true @@ -279,6 +281,7 @@ permissions: factions.documentation.perms: true factions.documentation.power: true factions.documentation.ranks: true + factions.documentation.warps: true factions.expansions: true factions.faction: true factions.flag: true diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index 363f7620..54108df5 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -31,6 +31,7 @@ public enum Perm implements Identified DOCUMENTATION_PERMS, DOCUMENTATION_POWER, DOCUMENTATION_RANKS, + DOCUMENTATION_WARPS, EXPANSIONS, FACTION, FLAG, diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java index 6ef70ef1..e61abef5 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java @@ -21,6 +21,7 @@ public class CmdFactionsDocumentation extends FactionsCommand public CmdFactionsDocumentationPower cmdFactionsDocumentationPower = new CmdFactionsDocumentationPower(); public CmdFactionsDocumentationRanks cmdFactionsDocumentationRanks = new CmdFactionsDocumentationRanks(); + public CmdFactionsDocumentationWarps cmdFactionsDocumentationWarps = new CmdFactionsDocumentationWarps(); public CmdFactionsDocumentationFlags cmdFactionsDocumentationFlags = new CmdFactionsDocumentationFlags(); public CmdFactionsDocumentationPerms cmdFactionsDocumentationPerms = new CmdFactionsDocumentationPerms(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java new file mode 100644 index 00000000..b00664dd --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java @@ -0,0 +1,76 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.massivecore.MassiveException; + +import java.util.Set; + +public class CmdFactionsDocumentationWarps extends FactionsCommandDocumentation +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationWarps() + { + this.addRequirements(ReqFactionWarpsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException + { + msgDoc("A faction can have warps which allows it's members to easily go to important places within the faction."); + + if (MConf.get().warpsMax < 0) + { + msgDoc("There is no limit to how many warps a faction can have."); + } + else + { + msgDoc("There is no limit to how many warps a faction can have."); + } + + if (MConf.get().warpsMustBeInClaimedTerritory) + { + msgDoc("Warps must be within claimed territory."); + } + + if (MConf.get().warpsTeleportToOnDeathActive) + { + msgDoc("If your faction has a warp with the name %s you will teleport there after death.", MConf.get().warpsTeleportToOnDeathName); + } + + if (!MConf.get().warpsTeleportAllowedFromEnemyTerritory) + { + msgDoc("You can't use faction warps while in enemy territory."); + } + + if (!MConf.get().warpsTeleportAllowedFromDifferentWorld) + { + msgDoc("You can't teleporty to a warp from another world."); + } + + if (MConf.get().warpsTeleportAllowedEnemyDistance > 0) + { + String str = String.format("You can't teleport home if there is an enemy within %.1f blocks of you", MConf.get().warpsTeleportAllowedEnemyDistance); + if (MConf.get().warpsTeleportIgnoreEnemiesIfInOwnTerritory) str += " unless you are in your own territory."; + else str += "."; + msgDoc(str); + } + + if (msenderFaction.isNormal()) + { + Set set = msenderFaction.getPermittedPermables(MPerm.getPermWarp()); + String permables = CmdFactionsPermShow.permablesToDisplayString(set, msender); + msgDoc("In your faction warps can be used by: %s.", permables); + } + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java index 1307360c..09ee4f50 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java @@ -14,6 +14,7 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.util.Txt; +import java.util.Collection; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -82,5 +83,22 @@ public class CmdFactionsPermShow extends FactionsCommand throw new RuntimeException(id); } + + public static String permablesToDisplayString(Collection permables, Object watcherObject) + { + MPlayer mplayer = MPlayer.get(watcherObject); + Faction faction = mplayer.getFaction(); + + String removeString; + if (faction.isNone()) removeString = ""; + else removeString = Txt.parse(" of ") + faction.getDisplayName(mplayer); + + List permableList = permables.stream() + .map(permable -> permable.getDisplayName(mplayer)) + .map(s -> s.replace(removeString, "")) + .collect(Collectors.toList()); + + return Txt.implodeCommaAnd(permableList, Txt.parse("")); + } } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 99bc8483..2e588fec 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -6,6 +6,8 @@ import com.massivecraft.factions.FactionsIndex; import com.massivecraft.factions.FactionsParticipator; import com.massivecraft.factions.Rel; import com.massivecraft.factions.RelationParticipator; +import com.massivecraft.factions.cmd.CmdFactionsPermShow; +import com.massivecraft.factions.entity.MPerm.MPermable; import com.massivecraft.factions.predicate.PredicateCommandSenderFaction; import com.massivecraft.factions.predicate.PredicateMPlayerRank; import com.massivecraft.factions.util.MiscUtil; @@ -820,6 +822,18 @@ public class Faction extends Entity implements FactionsParticipator, MP return getPermitted(mperm.getId()); } + public Set getPermittedPermables(String permId) + { + return getPermitted(permId).stream() + .map(CmdFactionsPermShow::idToMPermable) + .collect(Collectors.toSet()); + } + + public Set getPermittedPermables(MPerm mperm) + { + return getPermittedPermables(mperm.getId()); + } + public boolean isPermitted(String permableId, String permId) { if (permableId == null) throw new NullPointerException("permableId");