From f29efa116d8608d5fb610dc5790e018faa94c34f Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Mon, 12 Feb 2018 18:09:02 -0800 Subject: [PATCH] Clickable f map * New command /f claimat world x z * Permission: factions.claimat * Permission is not included in factions.halfplayer or anything for now. Will need to be granted manually. * If players don't have factions.claimat, they won't see the clickable f map --- .../com/massivecraft/factions/FPlayer.java | 4 ++ .../massivecraft/factions/cmd/CmdClaimAt.java | 38 +++++++++++++++++++ .../massivecraft/factions/cmd/CmdInvite.java | 10 ++++- .../massivecraft/factions/cmd/FCmdRoot.java | 2 + .../factions/struct/Permission.java | 1 + .../factions/zcore/persist/MemoryBoard.java | 10 ++++- .../factions/zcore/persist/MemoryFPlayer.java | 11 +++--- .../massivecraft/factions/zcore/util/TL.java | 3 ++ 8 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdClaimAt.java diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index c6f3afbe..3f0b77f9 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -226,8 +226,12 @@ public interface FPlayer extends EconomyParticipator { public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure); + public boolean canClaimForFactionAtLocation(Faction forFaction, FLocation location, boolean notifyFailure); + public boolean attemptClaim(Faction forFaction, Location location, boolean notifyFailure); + public boolean attemptClaim(Faction forFaction, FLocation location, boolean notifyFailure); + public void msg(String str, Object... args); public String getId(); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdClaimAt.java b/src/main/java/com/massivecraft/factions/cmd/CmdClaimAt.java new file mode 100644 index 00000000..eeba9054 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdClaimAt.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.FLocation; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdClaimAt extends FCommand { + + public CmdClaimAt() { + super(); + this.aliases.add("claimat"); + + this.requiredArgs.add("world"); + this.requiredArgs.add("x"); + this.requiredArgs.add("z"); + + this.permission = Permission.CLAIMAT.node; + this.disableOnLock = true; + + senderMustBePlayer = true; + senderMustBeMember = true; + senderMustBeModerator = false; + senderMustBeAdmin = false; + } + + @Override + public void perform() { + int x = argAsInt(1); + int z = argAsInt(2); + FLocation location = new FLocation(argAsString(0), x, z); + fme.attemptClaim(myFaction, location, true); + } + + @Override + public TL getUsageTranslation() { + return null; + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java index a1e42e21..0326d2bd 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java @@ -59,7 +59,15 @@ public class CmdInvite extends FCommand { } // Tooltips, colors, and commands only apply to the string immediately before it. - FancyMessage message = new FancyMessage(fme.describeTo(you, true)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()).command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()).then(TL.COMMAND_INVITE_INVITEDYOU.toString()).color(ChatColor.YELLOW).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()).command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()).then(myFaction.describeTo(you)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()).command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()); + FancyMessage message = new FancyMessage(fme.describeTo(you, true)) + .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) + .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()) + .then(TL.COMMAND_INVITE_INVITEDYOU.toString()) + .color(ChatColor.YELLOW) + .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) + .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()) + .then(myFaction.describeTo(you)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) + .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()); message.send(you.getPlayer()); diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 464f68c3..f2985886 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -75,6 +75,7 @@ public class FCmdRoot extends FCommand { public CmdDemote cmdDemote = new CmdDemote(); public CmdSetDefaultRole cmdSetDefaultRole = new CmdSetDefaultRole(); public CmdMapHeight cmdMapHeight = new CmdMapHeight(); + public CmdClaimAt cmdClaimAt = new CmdClaimAt(); public FCmdRoot() { super(); @@ -164,6 +165,7 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdDemote); this.addSubCommand(this.cmdSetDefaultRole); this.addSubCommand(this.cmdMapHeight); + this.addSubCommand(this.cmdClaimAt); if (P.p.isHookedPlayervaults()) { P.p.log("Found playervaults hook, adding /f vault and /f setmaxvault commands."); this.addSubCommand(new CmdSetMaxVaults()); diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index 37fe1d69..3c324798 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -17,6 +17,7 @@ public enum Permission { CHAT("chat"), CHATSPY("chatspy"), CLAIM("claim"), + CLAIMAT("claimat"), CLAIM_LINE("claim.line"), CLAIM_RADIUS("claim.radius"), CONFIG("config"), diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java index 7dacf3ee..0483ab53 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.zcore.persist; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.massivecraft.factions.*; +import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.util.LazyLocation; @@ -277,13 +278,18 @@ public abstract class MemoryBoard extends Board { } for (int dx = (dz < 3 ? 6 : 3); dx < width; dx++) { if (dx == halfWidth && dz == halfHeight) { - row.then("+").color(ChatColor.AQUA); + row.then("+").color(ChatColor.AQUA).tooltip(TL.CLAIM_YOUAREHERE.toString()); } else { FLocation flocationHere = topLeft.getRelative(dx, dz); Faction factionHere = getFactionAt(flocationHere); Relation relation = fplayer.getRelationTo(factionHere); if (factionHere.isWilderness()) { - row.then("-").color(ChatColor.GRAY); + row.then("-") .color(ChatColor.GRAY); + // Check for claimat position and if so, let them claim at ;D + if (fplayer.getPlayer().hasPermission(Permission.CLAIMAT.node)) { + row.tooltip(TL.CLAIM_CLICK_TO_CLAIM.format(dx, dz)) + .command(String.format("/f claimat %s %d %d", flocation.getWorldName(), dx, dz)); + } } else if (factionHere.isSafeZone()) { row.then("+").color(Conf.colorPeaceful); } else if (factionHere.isWarZone()) { diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index a199370a..fdfa70dd 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -691,9 +691,7 @@ public abstract class MemoryFPlayer implements FPlayer { } public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) { - FLocation flocation = new FLocation(location); - - return canClaimForFactionAtLocation(forFaction, flocation, notifyFailure); + return canClaimForFactionAtLocation(forFaction, new FLocation(location), notifyFailure); } public boolean canClaimForFactionAtLocation(Faction forFaction, FLocation flocation, boolean notifyFailure) { @@ -771,15 +769,18 @@ public abstract class MemoryFPlayer implements FPlayer { } public boolean attemptClaim(Faction forFaction, Location location, boolean notifyFailure) { + return attemptClaim(forFaction, new FLocation(location), notifyFailure); + } + + public boolean attemptClaim(Faction forFaction, FLocation flocation, boolean notifyFailure) { // notifyFailure is false if called by auto-claim; no need to notify on every failure for it // return value is false on failure, true on success - FLocation flocation = new FLocation(location); Faction currentFaction = Board.getInstance().getFactionAt(flocation); int ownedLand = forFaction.getLandRounded(); - if (!this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) { + if (!this.canClaimForFactionAtLocation(forFaction, flocation, notifyFailure)) { return false; } diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 79934948..2a373ee7 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -602,6 +602,9 @@ public enum TL { CLAIM_TOOCLOSETOOTHERFACTION("Your claim is too close to another Faction. Buffer required is %d"), CLAIM_OUTSIDEWORLDBORDER("Your claim is outside the border."), CLAIM_OUTSIDEBORDERBUFFER("Your claim is outside the border. %d chunks away world edge required."), + CLAIM_CLICK_TO_CLAIM("Click to try to claim &2(%1$d, %2$d)"), + CLAIM_YOUAREHERE("You are here"), + /** * More generic, or less easily categorisable translations, which may apply to more than one class */