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