diff --git a/src/main/java/net/knarcraft/paidsigns/listener/SignBreakListener.java b/src/main/java/net/knarcraft/paidsigns/listener/SignBreakListener.java index 137e762..f611779 100644 --- a/src/main/java/net/knarcraft/paidsigns/listener/SignBreakListener.java +++ b/src/main/java/net/knarcraft/paidsigns/listener/SignBreakListener.java @@ -2,8 +2,8 @@ package net.knarcraft.paidsigns.listener; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.manager.TrackedSignManager; +import net.knarcraft.paidsigns.utility.SignHelper; import org.bukkit.block.Block; -import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -92,7 +92,7 @@ public class SignBreakListener implements Listener { * @param refund

Whether to perform a refund after un-tracking the sign

*/ private void removeTrackedSign(Block block, boolean refund) { - if (block.getState() instanceof Sign) { + if (SignHelper.isSign(block)) { try { TrackedSignManager.removeTrackedSign(block.getLocation(), refund, false); } catch (IOException ignored) { diff --git a/src/main/java/net/knarcraft/paidsigns/listener/SignListener.java b/src/main/java/net/knarcraft/paidsigns/listener/SignListener.java index 1985514..fc36377 100644 --- a/src/main/java/net/knarcraft/paidsigns/listener/SignListener.java +++ b/src/main/java/net/knarcraft/paidsigns/listener/SignListener.java @@ -7,10 +7,10 @@ import net.knarcraft.paidsigns.container.PaidSignConditionMatch; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.manager.EconomyManager; import net.knarcraft.paidsigns.manager.TrackedSignManager; +import net.knarcraft.paidsigns.utility.SignHelper; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; -import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -127,7 +127,7 @@ public class SignListener implements Listener { //Immediately refund if a plugin destroyed the sign within 5 ticks of the creation Bukkit.getScheduler().scheduleSyncDelayedTask(PaidSigns.getInstance(), () -> { Block block = signLocation.getBlock(); - if (!(block.getState() instanceof Sign)) { + if (!SignHelper.isSign(block)) { try { TrackedSignManager.removeTrackedSign(block.getLocation(), true, true); } catch (IOException e) { diff --git a/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java b/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java index 4339ce9..abeef20 100644 --- a/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java +++ b/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java @@ -3,10 +3,10 @@ package net.knarcraft.paidsigns.manager; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.TrackedSign; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; +import net.knarcraft.paidsigns.utility.SignHelper; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; -import org.bukkit.block.Sign; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -110,7 +110,7 @@ public final class TrackedSignManager { TrackedSign trackedSign = new TrackedSign(playerId, cost); //Prevent destroyed signs from being tracked indefinitely - if (!(signLocation.getBlock().getState() instanceof Sign)) { + if (!SignHelper.isSign(signLocation.getBlock())) { Bukkit.getScheduler().scheduleSyncDelayedTask(PaidSigns.getInstance(), () -> { PaidSigns.getInstance().getLogger().log(Level.WARNING, "The sign at " + signLocation + " no longer exists. Removing from sign tracker. Refunding the player."); diff --git a/src/main/java/net/knarcraft/paidsigns/utility/SignHelper.java b/src/main/java/net/knarcraft/paidsigns/utility/SignHelper.java new file mode 100644 index 0000000..9a2fc81 --- /dev/null +++ b/src/main/java/net/knarcraft/paidsigns/utility/SignHelper.java @@ -0,0 +1,25 @@ +package net.knarcraft.paidsigns.utility; + +import org.bukkit.block.Block; +import org.bukkit.block.Sign; + +/** + * A helper class for dealing with signs + */ +public final class SignHelper { + + private SignHelper() { + + } + + /** + * Checks whether the given block is a sign + * + * @param block

The block to check

+ * @return

True if the block is a sign

+ */ + public static boolean isSign(Block block) { + return block.getState() instanceof Sign; + } + +}