AlttdGriefPrevention/todo/0008-Add-claimlistsextra-command.patch
2022-02-14 10:20:53 +01:00

123 lines
5.9 KiB
Diff

From 5cff52a9933c2cce6e655ec7cba557c36298477f Mon Sep 17 00:00:00 2001
From: len <40720638+destro174@users.noreply.github.com>
Date: Sun, 14 Mar 2021 21:24:57 +0100
Subject: [PATCH] Add /claimlistsextra command
diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
index acac585..3f0f1fd 100644
--- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
+++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
@@ -23,6 +23,11 @@ import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent;
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent;
import me.ryanhamshire.GriefPrevention.metrics.MetricsHandler;
+import net.md_5.bungee.api.chat.ClickEvent;
+import net.md_5.bungee.api.chat.ComponentBuilder;
+import net.md_5.bungee.api.chat.HoverEvent;
+import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.chat.ComponentSerializer;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.BanList;
import org.bukkit.BanList.Type;
@@ -2210,6 +2215,68 @@ public class GriefPrevention extends JavaPlugin
return true;
}
+ //claimslist or claimslist <player>
+ else if (cmd.getName().equalsIgnoreCase("claimslistextra"))
+ {
+ //at most one parameter
+ if (args.length > 1) return false;
+
+ //player whose claims will be listed
+ OfflinePlayer otherPlayer;
+
+ //if another player isn't specified, assume current player
+ if (args.length < 1)
+ {
+ if (player != null)
+ otherPlayer = player;
+ else
+ return false;
+ }
+
+ //otherwise if no permission to delve into another player's claims data
+ else if (player != null && !player.hasPermission("griefprevention.claimslistother"))
+ {
+ GriefPrevention.sendMessage(player, TextMode.Err, Messages.ClaimsListNoPermission);
+ return true;
+ }
+
+ //otherwise try to find the specified player
+ else
+ {
+ otherPlayer = this.resolvePlayerByName(args[0]);
+ if (otherPlayer == null)
+ {
+ GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2);
+ return true;
+ }
+ }
+
+ //load the target player's data
+ PlayerData playerData = this.dataStore.getPlayerData(otherPlayer.getUniqueId());
+ Vector<Claim> claims = playerData.getClaims();
+ GriefPrevention.sendMessage(player, TextMode.Instr, Messages.StartBlockMath,
+ String.valueOf(playerData.getAccruedClaimBlocks()),
+ String.valueOf((playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(otherPlayer.getUniqueId()))),
+ String.valueOf((playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(otherPlayer.getUniqueId()))));
+ if (claims.size() > 0)
+ {
+ GriefPrevention.sendMessage(player, TextMode.Instr, Messages.ClaimsListHeader);
+ claims.stream().forEach(claim -> {
+ TextComponent claimInfo = new TextComponent(getExtraLocationString(claim.getLesserBoundaryCorner(), claim.getGreaterBoundaryCorner()) + this.dataStore.getMessage(Messages.ContinueBlockMath, String.valueOf(claim.getArea())));
+ claimInfo.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Click here to visit this claim.").create()));
+ claimInfo.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tppos " + claim.getLesserBoundaryCorner().getBlockX() + " " + claim.getLesserBoundaryCorner().getBlockY() + " " + claim.getLesserBoundaryCorner().getBlockZ() + " "));
+ sender.sendMessage(claimInfo);
+ });
+ GriefPrevention.sendMessage(player, TextMode.Instr, Messages.EndBlockMath, String.valueOf(playerData.getRemainingClaimBlocks()));
+ }
+
+ //drop the data we just loaded, if the player isn't online
+ if (!otherPlayer.isOnline())
+ this.dataStore.clearCachedPlayerData(otherPlayer.getUniqueId());
+
+ return true;
+ }
+
//adminclaimslist
else if (cmd.getName().equalsIgnoreCase("adminclaimslist"))
{
@@ -2876,6 +2943,11 @@ public class GriefPrevention extends JavaPlugin
return location.getWorld().getName() + ": x" + location.getBlockX() + ", z" + location.getBlockZ();
}
+ public static String getExtraLocationString(Location location, Location location2)
+ {
+ return location.getWorld().getName() + ": x" + location.getBlockX() + ", z" + location.getBlockZ() + " to x" + location2.getBlockX() + ", z" + location2.getBlockZ();
+ }
+
private boolean abandonClaimHandler(Player player, boolean deleteTopLevelClaim)
{
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 3571777..b1d0fc1 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -171,6 +171,11 @@ commands:
usage: /ClaimsList or /ClaimsList <player>
aliases: [claimlist, listclaims]
permission: griefprevention.claims
+ claimslistextra:
+ description: Lists information about a player's claim blocks and claims.
+ usage: /ClaimsList or /ClaimsList <player>
+ aliases: [claimlistall]
+ permission: griefprevention.claimslistother
claimexplosions:
description: Toggles whether explosives may be used in a specific land claim.
usage: /ClaimExplosions
--
2.33.1