Add /claimlistsextra command

This commit is contained in:
destro174 2022-02-15 13:00:09 +01:00
parent f51701b756
commit 9a12797204
2 changed files with 76 additions and 0 deletions

View File

@ -24,6 +24,10 @@ import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent;
import me.ryanhamshire.GriefPrevention.alttd.listeners.AltitudeListener;
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.milkbowl.vault.economy.Economy;
import org.bukkit.BanList;
import org.bukkit.BanList.Type;
@ -2212,6 +2216,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"))
{
@ -2878,6 +2944,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());

View File

@ -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