From c9c3dfcedf2c7bd153928a927ad66a56a4e5fbe2 Mon Sep 17 00:00:00 2001 From: Smudge <68658429+smuddgge@users.noreply.github.com> Date: Fri, 26 Jul 2024 19:21:34 +0100 Subject: [PATCH] Forgot to check if the treasure has been spawned in the location before giving rewards. --- pom.xml | 4 ++-- .../cozyplugins/cozytreasurehunt/CozyTreasureHunt.java | 2 -- .../cozytreasurehunt/command/subcommand/SetCommand.java | 5 ++--- .../inventory/editor/TreasureEditor.java | 1 + .../cozytreasurehunt/listener/EventListener.java | 9 ++++++++- .../cozytreasurehunt/storage/LocationStorage.java | 6 ++++-- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 85f198c..40383aa 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.cozyplugins CozyTreasureHunt - 1.3.1 + 1.3.4 jar CozyTreasureHunt @@ -44,7 +44,7 @@ org.spigotmc spigot-api - 1.20.1-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/github/cozyplugins/cozytreasurehunt/CozyTreasureHunt.java b/src/main/java/com/github/cozyplugins/cozytreasurehunt/CozyTreasureHunt.java index 89e5d8d..b2ddc6c 100644 --- a/src/main/java/com/github/cozyplugins/cozytreasurehunt/CozyTreasureHunt.java +++ b/src/main/java/com/github/cozyplugins/cozytreasurehunt/CozyTreasureHunt.java @@ -32,8 +32,6 @@ import com.github.cozyplugins.cozytreasurehunt.storage.DataStorage; import com.github.cozyplugins.cozytreasurehunt.storage.LocationStorage; import com.github.cozyplugins.cozytreasurehunt.storage.TreasureStorage; -import org.bukkit.Raid; -import org.checkerframework.checker.units.qual.A; import org.jetbrains.annotations.NotNull; import java.util.*; diff --git a/src/main/java/com/github/cozyplugins/cozytreasurehunt/command/subcommand/SetCommand.java b/src/main/java/com/github/cozyplugins/cozytreasurehunt/command/subcommand/SetCommand.java index a0da61d..8229e47 100644 --- a/src/main/java/com/github/cozyplugins/cozytreasurehunt/command/subcommand/SetCommand.java +++ b/src/main/java/com/github/cozyplugins/cozytreasurehunt/command/subcommand/SetCommand.java @@ -18,7 +18,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; import java.util.Objects; /** @@ -59,6 +58,7 @@ public class SetCommand implements CommandType { @Override public @Nullable CommandStatus onPlayer(@NotNull PlayerUser user, @NotNull ConfigurationSection section, @NotNull CommandArguments arguments) { + // Check if there is no treasure specified. if (arguments.getArguments().isEmpty() || Objects.equals(arguments.getArguments().get(0), "")) { user.sendMessage(section.getString("invalid_treasure", "&7Treasure type does not exist.")); @@ -66,8 +66,7 @@ public class SetCommand implements CommandType { } // Get the treasure type. - List treasureNameList = arguments.getArguments().subList(1, arguments.getArguments().size()); - String treasureName = String.join(" ", treasureNameList); + String treasureName = String.join(" ", arguments.getArguments()); Treasure treasure = TreasureStorage.getFirst(treasureName); // Check if the treasure exists. diff --git a/src/main/java/com/github/cozyplugins/cozytreasurehunt/inventory/editor/TreasureEditor.java b/src/main/java/com/github/cozyplugins/cozytreasurehunt/inventory/editor/TreasureEditor.java index df9acca..21deb4a 100644 --- a/src/main/java/com/github/cozyplugins/cozytreasurehunt/inventory/editor/TreasureEditor.java +++ b/src/main/java/com/github/cozyplugins/cozytreasurehunt/inventory/editor/TreasureEditor.java @@ -413,6 +413,7 @@ private void setPage0() { .setAction((value, user) -> { if (value != null) { try { + System.out.println(value.toUpperCase()); Particle particle = Particle.valueOf(value.toUpperCase()); treasure.setParticleType(particle); treasure.save(); diff --git a/src/main/java/com/github/cozyplugins/cozytreasurehunt/listener/EventListener.java b/src/main/java/com/github/cozyplugins/cozytreasurehunt/listener/EventListener.java index 05bc8a7..7f46f87 100644 --- a/src/main/java/com/github/cozyplugins/cozytreasurehunt/listener/EventListener.java +++ b/src/main/java/com/github/cozyplugins/cozytreasurehunt/listener/EventListener.java @@ -46,16 +46,23 @@ public class EventListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onClick(PlayerInteractEvent event) { + // Check if a treasure is clicked in the most efficient way. + // Did the player click a block. if (event.getClickedBlock() == null) return; + + // Check if the location is in storage. if (!LocationStorage.contains(event.getClickedBlock().getLocation())) return; // Get the treasure location. TreasureLocation treasureLocation = LocationStorage.get(event.getClickedBlock().getLocation()); if (treasureLocation == null) return; + // Is the treasure spawned? + if (!treasureLocation.isSpawned()) return; + // Check if the player is in the map. - // Meaning they have clicked most recently + // Meaning they have clicked most recently. if (playerMap.containsKey(event.getPlayer().getUniqueId())) { long lastTimeStamp = playerMap.get(event.getPlayer().getUniqueId()); diff --git a/src/main/java/com/github/cozyplugins/cozytreasurehunt/storage/LocationStorage.java b/src/main/java/com/github/cozyplugins/cozytreasurehunt/storage/LocationStorage.java index e37df69..26f98da 100644 --- a/src/main/java/com/github/cozyplugins/cozytreasurehunt/storage/LocationStorage.java +++ b/src/main/java/com/github/cozyplugins/cozytreasurehunt/storage/LocationStorage.java @@ -27,12 +27,14 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; -import org.checkerframework.checker.units.qual.A; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; /** * Represents the treasure location storage.