From f51701b7567c7eddba82383d3ecdaa6437ed0d96 Mon Sep 17 00:00:00 2001 From: destro174 <40720638+destro174@users.noreply.github.com> Date: Mon, 14 Feb 2022 10:20:53 +0100 Subject: [PATCH] Update Todo --- todo/0008-Add-claimlistsextra-command.patch | 122 +++++ ...17-Add-alternative-claim-expiriation.patch | 291 ++++++++++++ todo/0018-Add-pl3xmap.patch | 422 ++++++++++++++++++ ...age-if-ignore-claims-remains-enabled.patch | 148 ++++++ 4 files changed, 983 insertions(+) create mode 100644 todo/0008-Add-claimlistsextra-command.patch create mode 100644 todo/0017-Add-alternative-claim-expiriation.patch create mode 100644 todo/0018-Add-pl3xmap.patch create mode 100644 todo/0019-Add-warning-message-if-ignore-claims-remains-enabled.patch diff --git a/todo/0008-Add-claimlistsextra-command.patch b/todo/0008-Add-claimlistsextra-command.patch new file mode 100644 index 0000000..4712acd --- /dev/null +++ b/todo/0008-Add-claimlistsextra-command.patch @@ -0,0 +1,122 @@ +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 ++ 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 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 + aliases: [claimlist, listclaims] + permission: griefprevention.claims ++ claimslistextra: ++ description: Lists information about a player's claim blocks and claims. ++ usage: /ClaimsList or /ClaimsList ++ aliases: [claimlistall] ++ permission: griefprevention.claimslistother + claimexplosions: + description: Toggles whether explosives may be used in a specific land claim. + usage: /ClaimExplosions +-- +2.33.1 + diff --git a/todo/0017-Add-alternative-claim-expiriation.patch b/todo/0017-Add-alternative-claim-expiriation.patch new file mode 100644 index 0000000..f39611c --- /dev/null +++ b/todo/0017-Add-alternative-claim-expiriation.patch @@ -0,0 +1,291 @@ +From 5776cb9ef52839ac02c90408afbd3971ba73d330 Mon Sep 17 00:00:00 2001 +From: destro174 <40720638+destro174@users.noreply.github.com> +Date: Sat, 20 Nov 2021 18:33:37 +0100 +Subject: [PATCH] Add alternative claim expiriation + + +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java +index ce3f1c6..3888956 100644 +--- a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java +@@ -18,6 +18,7 @@ + + package me.ryanhamshire.GriefPrevention; + ++import me.ryanhamshire.GriefPrevention.alttd.config.Config; + import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; + import org.bukkit.Bukkit; + import org.bukkit.OfflinePlayer; +@@ -31,12 +32,19 @@ class CleanupUnusedClaimTask implements Runnable + Claim claim; + PlayerData ownerData; + OfflinePlayer ownerInfo; ++ boolean forced; + + CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo) ++ { ++ this(claim, ownerData, ownerInfo, false); ++ } ++ ++ CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo, boolean forced) + { + this.claim = claim; + this.ownerData = ownerData; + this.ownerInfo = ownerInfo; ++ this.forced = forced; + } + + @Override +@@ -80,13 +88,35 @@ class CleanupUnusedClaimTask implements Runnable + Calendar earliestPermissibleLastLogin = Calendar.getInstance(); + earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays); + +- if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed()))) ++ if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())) || forced) + { + if (expireEventCanceled()) + return; + //make a copy of this player's claim list + Vector claims = new Vector<>(ownerData.getClaims()); + ++ // Alternative logic for deleting claims ++ if(Config.alternativeClaimExpiring) { ++ for (Claim claim : claims) ++ { ++ // remove all subclaims a claim has ++ for (int j = 1; (j - 1) < claim.children.size(); j++) ++ { ++ GriefPrevention.instance.dataStore.deleteClaim(claim.children.get(j - 1), true); ++ } ++ // remove all trusted players ++ claim.clearPermissions(); ++ // public trust ++ claim.setPermission("public", ClaimPermission.Build); ++ // make the claim an (expiring) admin claim ++ GriefPrevention.instance.dataStore.changeClaimOwner(claim, null); ++ Config.addExpiringClaim(claim.id); ++ } ++ GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired and converted to a temp claim.", CustomLogEntryTypes.AdminActivity); ++ GriefPrevention.AddLogEntry("earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin.getTime(), CustomLogEntryTypes.Debug, true); ++ GriefPrevention.AddLogEntry("ownerInfo#getLastPlayed: " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true); ++ return; ++ } + //delete them + GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true); + GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired.", CustomLogEntryTypes.AdminActivity); +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +index 5bd74d8..475e82e 100644 +--- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +@@ -19,6 +19,7 @@ + package me.ryanhamshire.GriefPrevention; + + import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException; ++import me.ryanhamshire.GriefPrevention.alttd.ClaimExpireTask; + import me.ryanhamshire.GriefPrevention.alttd.config.Config; + import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent; + import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent; +@@ -66,6 +67,7 @@ import java.util.ArrayList; + import java.util.Collection; + import java.util.EnumSet; + import java.util.HashMap; ++import java.util.Iterator; + import java.util.List; + import java.util.Map.Entry; + import java.util.Set; +@@ -357,6 +359,9 @@ public class GriefPrevention extends JavaPlugin + FindUnusedClaimsTask task2 = new FindUnusedClaimsTask(); + this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task2, 20L * 60, 20L * config_advanced_claim_expiration_check_rate); + ++ // start task to clean up temporary admin claims ++ ClaimExpireTask claimExpireTask = new ClaimExpireTask(this); ++ claimExpireTask.init(); + //register for events + PluginManager pluginManager = this.getServer().getPluginManager(); + +@@ -1271,7 +1276,52 @@ public class GriefPrevention extends JavaPlugin + { + return this.abandonClaimHandler(player, true); + } ++ //forceabandonclaim ++ if (cmd.getName().equalsIgnoreCase("forceabandonclaim") && player != null) ++ { ++ Claim claim = this.dataStore.getClaimAt(player.getLocation(), true /*ignore height*/, true, null); ++ if (claim == null) ++ { ++ GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AbandonClaimMissing); ++ return true; ++ } ++ PlayerData ownerData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(claim.ownerID); ++ OfflinePlayer ownerInfo = Bukkit.getServer().getOfflinePlayer(claim.ownerID); ++ Bukkit.getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new CleanupUnusedClaimTask(claim, ownerData, ownerInfo, true), 0); ++ return true; ++ } ++ //abandonsubclaim - remove all subclaims in this claim. ++ if (cmd.getName().equalsIgnoreCase("abandonsubclaims") && player != null) ++ { ++ //which claim is being abandoned? ++ Claim claim = this.dataStore.getClaimAt(player.getLocation(), true /*ignore height*/, true, null); ++ if (claim == null) ++ { ++ GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AbandonClaimMissing); ++ return true; ++ } + ++ //verify ownership ++ else if (claim.checkPermission(player, ClaimPermission.Edit, null) != null) ++ { ++ GriefPrevention.sendMessage(player, TextMode.Err, Messages.NotYourClaim); ++ return true; ++ } ++ ++ if (claim.children.isEmpty()) { ++ GriefPrevention.sendMessage(player, TextMode.Err, "This claim does not have any subclaims."); ++ return true; ++ } ++ ++ // remove all subclaims ++ for (int j = 0; j < claim.children.size(); j++) ++ { ++ GriefPrevention.instance.dataStore.deleteClaim(claim.children.get(j), false); ++ } ++ GriefPrevention.sendMessage(player, TextMode.Instr, "Subclaims have been removed."); ++ Visualization.Revert(player); ++ return true; ++ } + //ignoreclaims + if (cmd.getName().equalsIgnoreCase("ignoreclaims") && player != null) + { +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/ClaimExpireTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/ClaimExpireTask.java +new file mode 100644 +index 0000000..402a52d +--- /dev/null ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/ClaimExpireTask.java +@@ -0,0 +1,37 @@ ++package me.ryanhamshire.GriefPrevention.alttd; ++ ++import me.ryanhamshire.GriefPrevention.GriefPrevention; ++import me.ryanhamshire.GriefPrevention.alttd.config.Config; ++import org.bukkit.scheduler.BukkitRunnable; ++ ++import java.util.Iterator; ++import java.util.Map; ++ ++public class ClaimExpireTask extends BukkitRunnable ++{ ++ private GriefPrevention plugin; ++ ++ public ClaimExpireTask(GriefPrevention plugin) ++ { ++ this.plugin = plugin; ++ } ++ ++ public void init() ++ { ++ runTaskTimer(plugin, 0, Config.expireCheckRate); ++ } ++ ++ @Override ++ public void run() ++ { ++ //Config.expiringClaims.entrySet().removeIf(entry -> System.currentTimeMillis() >= entry.getValue()); ++ for(Iterator> it = Config.expiringClaims.entrySet().iterator(); it.hasNext(); ) { ++ Map.Entry entry = it.next(); ++ if(System.currentTimeMillis() >= entry.getValue()) { ++ it.remove(); ++ plugin.getLogger().info("Removed temporary admin claim with id " + entry.getKey()); ++ } ++ } ++ ++ } ++} +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java +index a74a9e6..958cd91 100644 +--- a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java +@@ -75,6 +75,7 @@ abstract class AbstractConfig { + } + + void set(String path, Object val) { ++ yaml.addDefault(path, val); + yaml.addDefault(path, val); + yaml.set(path, val); + } +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java +index fe296b6..6e00e16 100644 +--- a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java +@@ -1,7 +1,15 @@ + package me.ryanhamshire.GriefPrevention.alttd.config; + ++import me.ryanhamshire.GriefPrevention.alttd.config.util.Logger; ++ ++import java.io.IOException; ++import java.util.HashMap; ++import java.util.Map; ++import java.util.concurrent.TimeUnit; ++ + @SuppressWarnings("unused") + public class Config extends AbstractConfig { ++ + private Config() { + super("alttdconfig.yml"); + } +@@ -19,8 +27,35 @@ public class Config extends AbstractConfig { + } + + public static boolean DEBUG_MODE = false; ++ public static boolean alternativeClaimExpiring = false; ++ public static int alternativeClaimExpireDays = 1; ++ public static int expireCheckRate = 1200; ++ public static HashMap expiringClaims = new HashMap<>(); + private static void settings() { ++ String node = "alternative-claim-expiring"; + DEBUG_MODE = config.getBoolean("debug-mode", DEBUG_MODE); ++ alternativeClaimExpiring = config.getBoolean(node + ".enabled", alternativeClaimExpiring); ++ alternativeClaimExpireDays = config.getInt(node + ".days", alternativeClaimExpireDays); ++ expireCheckRate = config.getInt(node + ".expire-check-rate", expireCheckRate); ++ // todo create an alternative way of loading these in ++ expiringClaims.clear(); ++ config.getMap(node + ".claims", new HashMap()) ++ .forEach((key, value) -> { ++ try { ++ expiringClaims.put(Long.parseLong(key), value); ++ } catch (NumberFormatException ignored) {} ++ }); ++ } ++ ++ public static void addExpiringClaim(Long id) { ++ expiringClaims.put(id, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(alternativeClaimExpireDays)); ++ config.set("alternative-claim-expiring.claims", expiringClaims); ++ try { ++ config.yaml.save(config.file); ++ } catch (IOException ex) { ++ Logger.severe("Could not save " + config.file.getName()); ++ ex.printStackTrace(); ++ } + } + + } +diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml +index b1d0fc1..dae38bd 100644 +--- a/src/main/resources/plugin.yml ++++ b/src/main/resources/plugin.yml +@@ -19,6 +19,14 @@ commands: + description: Deletes ALL your claims. + usage: /AbandonAllClaims + permission: griefprevention.claims ++ abandonsubclaims: ++ description: Deletes ALL subclaims in the claim you are standing in. ++ usage: /abandonsubclaims ++ permission: griefprevention.claims ++ forceabandonclaim: ++ description: Forces the claim you are standing in to abandon. ++ usage: /forceabandonclaim ++ permission: griefprevention.forceabandonclaim + trust: + description: Grants a player full access to your claim(s). + usage: /Trust Grants a player permission to build. See also /UnTrust, /ContainerTrust, /AccessTrust, and /PermissionTrust. +-- +2.34.1 + diff --git a/todo/0018-Add-pl3xmap.patch b/todo/0018-Add-pl3xmap.patch new file mode 100644 index 0000000..03e4941 --- /dev/null +++ b/todo/0018-Add-pl3xmap.patch @@ -0,0 +1,422 @@ +From e8845cafebdc4f182897d90acdb64628ee0ab8ba Mon Sep 17 00:00:00 2001 +From: destro174 <40720638+destro174@users.noreply.github.com> +Date: Mon, 13 Dec 2021 18:15:17 +0100 +Subject: [PATCH] Add pl3xmap + + +diff --git a/pom.xml b/pom.xml +index 015aeb7..18f6fec 100644 +--- a/pom.xml ++++ b/pom.xml +@@ -56,6 +56,10 @@ + Altitude Maven Repo + https://repo.destro.xyz/snapshots + ++ ++ jitpack.io ++ https://jitpack.io ++ + + + +@@ -204,6 +208,12 @@ + mypet + 3.11-SNAPSHOT + ++ ++ ++ com.github.NeumimTo ++ Pl3xMap ++ 1.18-2 ++ + + + +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +index 475e82e..381107c 100644 +--- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +@@ -21,6 +21,7 @@ package me.ryanhamshire.GriefPrevention; + import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException; + import me.ryanhamshire.GriefPrevention.alttd.ClaimExpireTask; + import me.ryanhamshire.GriefPrevention.alttd.config.Config; ++import me.ryanhamshire.GriefPrevention.alttd.map.hook.Pl3xMapHook; + import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent; + import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent; + import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent; +@@ -246,6 +247,7 @@ public class GriefPrevention extends JavaPlugin + private String databaseUserName; + private String databasePassword; + ++ private Pl3xMapHook pl3xmapHook; + + //how far away to search from a tree trunk for its branch blocks + public static final int TREE_RADIUS = 5; +@@ -400,6 +402,9 @@ public class GriefPrevention extends JavaPlugin + } + + new AltitudeListener(this.dataStore, this); ++ if (getServer().getPluginManager().isPluginEnabled("Pl3xMap")) { ++ pl3xmapHook = new Pl3xMapHook(this); ++ } + AddLogEntry("Boot finished."); + + try +@@ -3362,6 +3367,10 @@ public class GriefPrevention extends JavaPlugin + //dump any remaining unwritten log entries + this.customLogger.WriteEntries(); + ++ if (pl3xmapHook != null) { ++ pl3xmapHook.disable(); ++ } ++ + AddLogEntry("GriefPrevention disabled."); + } + +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java +index 958cd91..b55619f 100644 +--- a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java +@@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack; + import org.checkerframework.checker.nullness.qual.NonNull; + import org.checkerframework.checker.nullness.qual.Nullable; + ++import java.awt.*; + import java.io.File; + import java.io.IOException; + import java.lang.reflect.InvocationTargetException; +@@ -154,4 +155,22 @@ abstract class AbstractConfig { + return locations; + } + ++ Color getColor(String path, Color def) { ++ yaml.addDefault(path, colorToHex(def)); ++ return hexToColor(yaml.getString(path, yaml.getString(path))); ++ } ++ ++ String colorToHex(final Color color) { ++ return Integer.toHexString(color.getRGB() & 0x00FFFFFF); ++ } ++ ++ Color hexToColor(final String hex) { ++ if (hex == null) { ++ return Color.RED; ++ } ++ String stripped = hex.replace("#", ""); ++ int rgb = (int) Long.parseLong(stripped, 16); ++ return new Color(rgb); ++ } ++ + } +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java +index 6e00e16..f3fcabf 100644 +--- a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java +@@ -2,6 +2,7 @@ package me.ryanhamshire.GriefPrevention.alttd.config; + + import me.ryanhamshire.GriefPrevention.alttd.config.util.Logger; + ++import java.awt.*; + import java.io.IOException; + import java.util.HashMap; + import java.util.Map; +@@ -58,4 +59,79 @@ public class Config extends AbstractConfig { + } + } + ++ public static String CONTROL_LABEL = "GriefPrevention"; ++ public static boolean CONTROL_SHOW = true; ++ public static boolean CONTROL_HIDE = false; ++ public static String GRID_CONTROL_LABEL = "Gridlines"; ++ public static boolean GRID_CONTROL_SHOW = true; ++ public static boolean GRID_CONTROL_HIDE = true; ++ public static int UPDATE_INTERVAL = 300; ++ public static Color STROKE_COLOR = Color.GREEN; ++ public static int STROKE_WEIGHT = 1; ++ public static double STROKE_OPACITY = 1.0D; ++ public static Color FILL_COLOR = Color.GREEN; ++ public static double FILL_OPACITY = 0.2D; ++ ++ public static Color ADMIN_STROKE_COLOR = Color.BLUE; ++ public static int ADMIN_STROKE_WEIGHT = 1; ++ public static double ADMIN_STROKE_OPACITY = 1.0D; ++ public static Color ADMIN_FILL_COLOR = Color.BLUE; ++ public static double ADMIN_FILL_OPACITY = 0.2D; ++ ++ public static Color EXPIRING_STROKE_COLOR = Color.PINK; ++ public static int EXPIRING_STROKE_WEIGHT = 1; ++ public static double EXPIRING_STROKE_OPACITY = 1.0D; ++ public static Color EXPIRING_FILL_COLOR = Color.PINK; ++ public static double EXPIRING_FILL_OPACITY = 0.2D; ++ ++ public static String STRINGS_PUBLIC = "Public"; ++ public static String CLAIM_TOOLTIP = "Claim Owner: {owner}
" + ++ "Permission Trust: {managers}
" + ++ "Trust: {builders}
" + ++ "Container Trust: {containers}
" + ++ "Access Trust: {accessors}"; ++ public static String ADMIN_CLAIM_TOOLTIP = "Administrator Claim
" + ++ "Permission Trust: {managers}
" + ++ "Trust: {builders}
" + ++ "Container Trust: {containers}
" + ++ "Access Trust: {accessors}"; ++ public static String EXPIRING_CLAIM_TOOLTIP = "Temporary Claim
" + ++ "Permission Trust: {managers}
" + ++ "Trust: {builders}
" + ++ "Container Trust: {containers}
" + ++ "Access Trust: {accessors}
" + ++ "Expires: {expiretime}" ; ++ private static void mapSettings() { ++ CONTROL_LABEL = config.getString("settings.control.label", CONTROL_LABEL); ++ CONTROL_SHOW = config.getBoolean("settings.control.show", CONTROL_SHOW); ++ CONTROL_HIDE = config.getBoolean("settings.control.hide-by-default", CONTROL_HIDE); ++ GRID_CONTROL_LABEL = config.getString("settings.grid.label", GRID_CONTROL_LABEL); ++ GRID_CONTROL_SHOW = config.getBoolean("settings.grid.show", GRID_CONTROL_SHOW); ++ GRID_CONTROL_HIDE = config.getBoolean("settings.grid.hide-by-default", GRID_CONTROL_HIDE); ++ UPDATE_INTERVAL = config.getInt("settings.update-interval", UPDATE_INTERVAL); ++ ++ STROKE_COLOR = config.getColor("settings.style.regular-claim.stroke.color", STROKE_COLOR); ++ STROKE_WEIGHT = config.getInt("settings.style.regular-claim.stroke.weight", STROKE_WEIGHT); ++ STROKE_OPACITY = config.getDouble("settings.regular-claim.style.stroke.opacity", STROKE_OPACITY); ++ FILL_COLOR = config.getColor("settings.style.regular-claim.fill.color", FILL_COLOR); ++ FILL_OPACITY = config.getDouble("settings.style.regular-claim.fill.opacity", FILL_OPACITY); ++ ++ ADMIN_STROKE_COLOR = config.getColor("settings.style.admin-claim.stroke.color", ADMIN_STROKE_COLOR); ++ ADMIN_STROKE_WEIGHT = config.getInt("settings.style.admin-claim.stroke.weight", ADMIN_STROKE_WEIGHT); ++ ADMIN_STROKE_OPACITY = config.getDouble("settings.admin-claim.style.stroke.opacity", ADMIN_STROKE_OPACITY); ++ ADMIN_FILL_COLOR = config.getColor("settings.style.admin-claim.fill.color", ADMIN_FILL_COLOR); ++ ADMIN_FILL_OPACITY = config.getDouble("settings.style.admin-claim.fill.opacity", ADMIN_FILL_OPACITY); ++ ++ EXPIRING_STROKE_COLOR = config.getColor("settings.style.expiring-claim.stroke.color", EXPIRING_STROKE_COLOR); ++ EXPIRING_STROKE_WEIGHT = config.getInt("settings.style.expiring-claim.stroke.weight", EXPIRING_STROKE_WEIGHT); ++ EXPIRING_STROKE_OPACITY = config.getDouble("settings.expiring-claim.style.stroke.opacity", EXPIRING_STROKE_OPACITY); ++ EXPIRING_FILL_COLOR = config.getColor("settings.style.expiring-claim.fill.color", EXPIRING_FILL_COLOR); ++ EXPIRING_FILL_OPACITY = config.getDouble("settings.style.expiring-claim.fill.opacity", EXPIRING_FILL_OPACITY); ++ ++ STRINGS_PUBLIC = config.getString("settings.strings.public", STRINGS_PUBLIC); ++ CLAIM_TOOLTIP = config.getString("settings.region.tooltip.regular-claim", CLAIM_TOOLTIP); ++ ADMIN_CLAIM_TOOLTIP = config.getString("settings.region.tooltip.admin-claim", ADMIN_CLAIM_TOOLTIP); ++ EXPIRING_CLAIM_TOOLTIP = config.getString("settings.region.tooltip.expiring-claim", EXPIRING_CLAIM_TOOLTIP); ++ } ++ + } +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/hook/GPHook.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/hook/GPHook.java +new file mode 100644 +index 0000000..5977448 +--- /dev/null ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/hook/GPHook.java +@@ -0,0 +1,20 @@ ++package me.ryanhamshire.GriefPrevention.alttd.map.hook; ++ ++import me.ryanhamshire.GriefPrevention.Claim; ++import me.ryanhamshire.GriefPrevention.GriefPrevention; ++import org.bukkit.Bukkit; ++import org.bukkit.World; ++ ++import java.util.Collection; ++import java.util.UUID; ++ ++public class GPHook { ++ public static boolean isWorldEnabled(UUID uuid) { ++ World world = Bukkit.getWorld(uuid); ++ return GriefPrevention.instance.claimsEnabledForWorld(world); ++ } ++ ++ public static Collection getClaims() { ++ return GriefPrevention.instance.dataStore.getClaims(); ++ } ++} +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/hook/Pl3xMapHook.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/hook/Pl3xMapHook.java +new file mode 100644 +index 0000000..70476d4 +--- /dev/null ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/hook/Pl3xMapHook.java +@@ -0,0 +1,39 @@ ++package me.ryanhamshire.GriefPrevention.alttd.map.hook; ++ ++import me.ryanhamshire.GriefPrevention.alttd.config.Config; ++import me.ryanhamshire.GriefPrevention.alttd.map.task.Pl3xMapTask; ++import net.pl3x.map.api.Key; ++import net.pl3x.map.api.Pl3xMapProvider; ++import net.pl3x.map.api.SimpleLayerProvider; ++import org.bukkit.plugin.Plugin; ++ ++import java.util.HashMap; ++import java.util.Map; ++import java.util.UUID; ++ ++public class Pl3xMapHook { ++ private final Map provider = new HashMap<>(); ++ ++ public Pl3xMapHook(Plugin plugin) { ++ plugin.getLogger().info("Started Pl3xMapHook..."); ++ Pl3xMapProvider.get().mapWorlds().forEach(world -> { ++ if (GPHook.isWorldEnabled(world.uuid())) { ++ SimpleLayerProvider provider = SimpleLayerProvider ++ .builder(Config.CONTROL_LABEL) ++ .showControls(Config.CONTROL_SHOW) ++ .defaultHidden(Config.CONTROL_HIDE) ++ .build(); ++ world.layerRegistry().register(Key.of("griefprevention_" + world.uuid()), provider); ++ Pl3xMapTask task = new Pl3xMapTask(world, provider); ++ task.runTaskTimerAsynchronously(plugin, 0, 20L * Config.UPDATE_INTERVAL); ++ this.provider.put(world.uuid(), task); ++ } ++ }); ++ } ++ ++ public void disable() { ++ provider.values().forEach(Pl3xMapTask::disable); ++ provider.clear(); ++ } ++ ++} +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/task/Pl3xMapTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/task/Pl3xMapTask.java +new file mode 100644 +index 0000000..f59a50e +--- /dev/null ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/map/task/Pl3xMapTask.java +@@ -0,0 +1,128 @@ ++package me.ryanhamshire.GriefPrevention.alttd.map.task; ++ ++import me.ryanhamshire.GriefPrevention.Claim; ++import me.ryanhamshire.GriefPrevention.alttd.config.Config; ++import me.ryanhamshire.GriefPrevention.alttd.map.hook.GPHook; ++import net.pl3x.map.api.Key; ++import net.pl3x.map.api.MapWorld; ++import net.pl3x.map.api.Point; ++import net.pl3x.map.api.SimpleLayerProvider; ++import net.pl3x.map.api.marker.Marker; ++import net.pl3x.map.api.marker.MarkerOptions; ++import net.pl3x.map.api.marker.Rectangle; ++import org.bukkit.Location; ++import org.bukkit.scheduler.BukkitRunnable; ++ ++import java.awt.*; ++import java.text.DateFormat; ++import java.util.ArrayList; ++import java.util.Collection; ++import java.util.List; ++ ++public class Pl3xMapTask extends BukkitRunnable { ++ private final MapWorld world; ++ private final SimpleLayerProvider provider; ++ ++ private boolean stop; ++ ++ public Pl3xMapTask(MapWorld world, SimpleLayerProvider provider) { ++ this.world = world; ++ this.provider = provider; ++ } ++ ++ @Override ++ public void run() { ++ if (stop) { ++ cancel(); ++ } ++ updateClaims(); ++ } ++ ++ void updateClaims() { ++ provider.clearMarkers(); ++ Collection topLevelClaims = GPHook.getClaims(); ++ if (topLevelClaims != null) { ++ topLevelClaims.stream() ++ .filter(claim -> claim.getGreaterBoundaryCorner().getWorld().getUID().equals(this.world.uuid())) ++ .filter(claim -> claim.parent == null) ++ .forEach(this::handleClaim); ++ } ++ } ++ ++ private void handleClaim(Claim claim) { ++ Location min = claim.getLesserBoundaryCorner(); ++ Location max = claim.getGreaterBoundaryCorner(); ++ if (min == null) { ++ return; ++ } ++ ++ Rectangle rect = Marker.rectangle(Point.of(min.getBlockX(), min.getBlockZ()), Point.of(max.getBlockX() + 1, max.getBlockZ() + 1)); ++ ++ ArrayList builders = new ArrayList<>(); ++ ArrayList containers = new ArrayList<>(); ++ ArrayList accessors = new ArrayList<>(); ++ ArrayList managers = new ArrayList<>(); ++ claim.getPermissions(builders, containers, accessors, managers); ++ ++ String worldName = min.getWorld().getName(); ++ String toolTip = Config.CLAIM_TOOLTIP; ++ MarkerOptions.Builder options = MarkerOptions.builder() ++ .strokeColor(Config.STROKE_COLOR) ++ .strokeWeight(Config.STROKE_WEIGHT) ++ .strokeOpacity(Config.STROKE_OPACITY) ++ .fillColor(Config.FILL_COLOR) ++ .fillOpacity(Config.FILL_OPACITY) ++ .clickTooltip((claim.isAdminClaim() ? (Config.expiringClaims.containsKey(claim.getID()) ? Config.EXPIRING_CLAIM_TOOLTIP : Config.ADMIN_CLAIM_TOOLTIP) : Config.CLAIM_TOOLTIP) ++ .replace("{world}", worldName) ++ .replace("{id}", Long.toString(claim.getID())) ++ .replace("{owner}", claim.getOwnerName()) ++ .replace("{managers}", getNames(managers)) ++ .replace("{builders}", getNames(builders)) ++ .replace("{containers}", getNames(containers)) ++ .replace("{accessors}", getNames(accessors)) ++ .replace("{area}", Integer.toString(claim.getArea())) ++ .replace("{width}", Integer.toString(claim.getWidth())) ++ .replace("{height}", Integer.toString(claim.getHeight())) ++ .replace("{expiretime}", parseExpireTime(claim.getID())) ++ ); ++ ++ if (claim.isAdminClaim()) { ++ if (Config.expiringClaims.containsKey(claim.getID())) { ++ options.strokeColor(Config.EXPIRING_STROKE_COLOR) ++ .strokeWeight(Config.EXPIRING_STROKE_WEIGHT) ++ .strokeOpacity(Config.EXPIRING_STROKE_OPACITY) ++ .fillColor(Config.EXPIRING_FILL_COLOR) ++ .fillOpacity(Config.EXPIRING_FILL_OPACITY); ++ } else { ++ options.strokeColor(Config.ADMIN_STROKE_COLOR) ++ .strokeWeight(Config.ADMIN_STROKE_WEIGHT) ++ .strokeOpacity(Config.ADMIN_STROKE_OPACITY) ++ .fillColor(Config.ADMIN_FILL_COLOR) ++ .fillOpacity(Config.ADMIN_FILL_OPACITY); ++ } ++ } ++ ++ rect.markerOptions(options); ++ ++ String markerid = "griefprevention_" + worldName + "_region_" + Long.toHexString(claim.getID()); ++ this.provider.addMarker(Key.of(markerid), rect); ++ } ++ ++ private static String getNames(List list) { ++ return String.join(", ", list); ++ } ++ ++ public void disable() { ++ cancel(); ++ this.stop = true; ++ this.provider.clearMarkers(); ++ } ++ ++ private String parseExpireTime(Long claimId) { ++ if(Config.expiringClaims.containsKey(claimId)) { ++ return DateFormat.getInstance().format(Config.expiringClaims.get(claimId)); ++ } ++ return ""; ++ } ++} ++ +diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml +index dae38bd..34b23e8 100644 +--- a/src/main/resources/plugin.yml ++++ b/src/main/resources/plugin.yml +@@ -1,6 +1,6 @@ + name: GriefPrevention + main: me.ryanhamshire.GriefPrevention.GriefPrevention +-softdepend: [Vault, Multiverse-Core, My_Worlds, MystCraft, Transporter, TheUnderground, WorldGuard, WorldEdit, RoyalCommands, MultiWorld, Denizen] ++softdepend: [Vault, Multiverse-Core, My_Worlds, MystCraft, Transporter, TheUnderground, WorldGuard, WorldEdit, RoyalCommands, MultiWorld, Denizen, Pl3xMap] + dev-url: https://dev.bukkit.org/projects/grief-prevention + loadbefore: [TheUnderground] + version: '${git.commit.id.describe}' +-- +2.34.1 + diff --git a/todo/0019-Add-warning-message-if-ignore-claims-remains-enabled.patch b/todo/0019-Add-warning-message-if-ignore-claims-remains-enabled.patch new file mode 100644 index 0000000..c00182a --- /dev/null +++ b/todo/0019-Add-warning-message-if-ignore-claims-remains-enabled.patch @@ -0,0 +1,148 @@ +From 70ca78c5b565bc7bafb174785a1cae79ef1508cf Mon Sep 17 00:00:00 2001 +From: destro174 <40720638+destro174@users.noreply.github.com> +Date: Thu, 3 Feb 2022 09:15:35 +0100 +Subject: [PATCH] Add warning message if ignore claims remains enabled + + +diff --git a/pom.xml b/pom.xml +index 18f6fec..9fb0aac 100644 +--- a/pom.xml ++++ b/pom.xml +@@ -146,6 +146,12 @@ +
+ + ++ ++ ++ com.alttd ++ Galaxy-API ++ 1.18.1-R0.1-SNAPSHOT ++ + + + io.papermc.paper +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +index 381107c..ca7c451 100644 +--- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +@@ -20,6 +20,7 @@ package me.ryanhamshire.GriefPrevention; + + import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException; + import me.ryanhamshire.GriefPrevention.alttd.ClaimExpireTask; ++import me.ryanhamshire.GriefPrevention.alttd.IgnoreClaimWarningTask; + import me.ryanhamshire.GriefPrevention.alttd.config.Config; + import me.ryanhamshire.GriefPrevention.alttd.map.hook.Pl3xMapHook; + import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent; +@@ -248,7 +249,7 @@ public class GriefPrevention extends JavaPlugin + private String databasePassword; + + private Pl3xMapHook pl3xmapHook; +- ++ private HashMap ignoreClaimWarningTasks; + //how far away to search from a tree trunk for its branch blocks + public static final int TREE_RADIUS = 5; + +@@ -405,6 +406,7 @@ public class GriefPrevention extends JavaPlugin + if (getServer().getPluginManager().isPluginEnabled("Pl3xMap")) { + pl3xmapHook = new Pl3xMapHook(this); + } ++ ignoreClaimWarningTasks = new HashMap<>(); + AddLogEntry("Boot finished."); + + try +@@ -1333,15 +1335,18 @@ public class GriefPrevention extends JavaPlugin + PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId()); + + playerData.ignoreClaims = !playerData.ignoreClaims; +- ++ UUID uuid = player.getUniqueId(); + //toggle ignore claims mode on or off + if (!playerData.ignoreClaims) + { + GriefPrevention.sendMessage(player, TextMode.Success, Messages.RespectingClaims); ++ ignoreClaimWarningTasks.get(uuid).cancel(); ++ ignoreClaimWarningTasks.remove(uuid); + } + else + { + GriefPrevention.sendMessage(player, TextMode.Success, Messages.IgnoringClaims); ++ ignoreClaimWarningTasks.putIfAbsent(uuid, new IgnoreClaimWarningTask(this, uuid)); + } + + return true; +diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/IgnoreClaimWarningTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/IgnoreClaimWarningTask.java +new file mode 100644 +index 0000000..d8279cf +--- /dev/null ++++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/IgnoreClaimWarningTask.java +@@ -0,0 +1,50 @@ ++package me.ryanhamshire.GriefPrevention.alttd; ++ ++import me.ryanhamshire.GriefPrevention.GriefPrevention; ++import me.ryanhamshire.GriefPrevention.alttd.config.Config; ++import net.kyori.adventure.text.minimessage.MiniMessage; ++import net.kyori.adventure.text.minimessage.Template; ++import net.kyori.adventure.text.minimessage.template.TemplateResolver; ++import org.bukkit.Bukkit; ++import org.bukkit.entity.Player; ++import org.bukkit.scheduler.BukkitRunnable; ++ ++import java.time.LocalTime; ++import java.time.format.DateTimeFormatter; ++import java.util.ArrayList; ++import java.util.List; ++import java.util.UUID; ++ ++public class IgnoreClaimWarningTask extends BukkitRunnable ++{ ++ private GriefPrevention plugin; ++ private UUID uuid; ++ private String time; ++ ++ public IgnoreClaimWarningTask(GriefPrevention plugin, UUID uuid) ++ { ++ this.plugin = plugin; ++ this.uuid = uuid; ++ LocalTime localTime = LocalTime.now(); ++ this.time = localTime.format(DateTimeFormatter.ofPattern("HH:mm")); ++ this.init(); ++ } ++ ++ public void init() ++ { ++ runTaskLater(plugin, Config.ignoreClaimWarningDelay); ++ } ++ ++ @Override ++ public void run() ++ { ++ Player player = Bukkit.getPlayer(uuid); ++ if (player == null) return; ++ List