diff --git a/README.md b/README.md index eeabdd5..9ef0e25 100644 --- a/README.md +++ b/README.md @@ -75,4 +75,16 @@ Removes a registered paid sign * paidsigns.* - Grants all paid signs permissions * paidsigns.manage - Grants the permission to add/remove a paid sign * paidsigns.reload - Grants the permissions to reload the plugin -* paidsigns.paymentexempt - Makes this player exempt from the cost of paid signs \ No newline at end of file +* paidsigns.paymentexempt - Makes this player exempt from the cost of paid signs + +## Configuration options + +* ignoreCase - Whether to ignore the case (lowercase/uppercase) of the paid sign text. The option can be set on a + per-sign basis, but this value is used if not specified. The correct value depends on whether the plugin signs it + should match are case-sensitive or not. +* ignoreColor - Whether to ignore any color or formatting applied to the text when trying to match a paid sign's text. + The option can be set on a per-sign basis, but this value is used if not specified. The correct value depends on + whether the plugin signs it should match allow coloring or not. +* enableRefunds - Whether to enable refunds to the sign creator when a sign detected as a paid sign is broken (payment + will always go to the original creator) +* refundPercentage - The percentage of the paid sign cost to refund (0-100) \ No newline at end of file diff --git a/src/main/java/net/knarcraft/paidsigns/PaidSigns.java b/src/main/java/net/knarcraft/paidsigns/PaidSigns.java index 71171ad..33866df 100644 --- a/src/main/java/net/knarcraft/paidsigns/PaidSigns.java +++ b/src/main/java/net/knarcraft/paidsigns/PaidSigns.java @@ -10,6 +10,7 @@ import net.knarcraft.paidsigns.command.ReloadTabCommand; import net.knarcraft.paidsigns.command.RemoveConditionCommand; import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter; import net.knarcraft.paidsigns.command.RemoveTabCommand; +import net.knarcraft.paidsigns.listener.BlockBreakListener; import net.knarcraft.paidsigns.listener.SignListener; import net.knarcraft.paidsigns.manager.EconomyManager; import net.knarcraft.paidsigns.manager.PaidSignManager; @@ -63,6 +64,7 @@ public final class PaidSigns extends JavaPlugin { PluginManager pluginManager = getServer().getPluginManager(); pluginManager.registerEvents(new SignListener(), this); + pluginManager.registerEvents(new BlockBreakListener(), this); registerCommands(); } diff --git a/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java b/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java index 7e24b59..500efe8 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java @@ -18,7 +18,8 @@ public class ReloadTabCommand implements TabExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { PaidSigns.getInstance().reload(); - return false; + sender.sendMessage("PaidSigns reloaded"); + return true; } @Override diff --git a/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java b/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java index 807b3aa..930ebc6 100644 --- a/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java +++ b/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java @@ -8,6 +8,7 @@ import org.bukkit.OfflinePlayer; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; @@ -20,11 +21,15 @@ import java.util.logging.Level; /** * A manager for keeping track of plugin-signs created by players */ -public class TrackedSignManager { +public final class TrackedSignManager { private static Map trackedSigns = new HashMap<>(); private static final File signsFile = new File(PaidSigns.getInstance().getDataFolder(), "data.yml"); + private TrackedSignManager() { + + } + /** * Adds a tracked sign to the manager * @@ -47,15 +52,18 @@ public class TrackedSignManager { if (!trackedSigns.containsKey(signLocation)) { return; } + TrackedSign trackedSign = trackedSigns.get(signLocation); trackedSigns.remove(signLocation); saveTrackedSigns(); if (!PaidSigns.getInstance().areRefundsEnabled()) { return; } - TrackedSign trackedSign = trackedSigns.get(signLocation); - OfflinePlayer player = Bukkit.getOfflinePlayer(trackedSign.getPlayerId()); + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(trackedSign.getPlayerId()); double refundSum = trackedSign.getCost() / 100 * PaidSigns.getInstance().getRefundPercentage(); - EconomyManager.withdraw(player, refundSum); + EconomyManager.withdraw(offlinePlayer, -refundSum); + if (offlinePlayer instanceof Player player) { + player.sendMessage("You were refunded " + refundSum + " for your broken sign"); + } } /** @@ -67,7 +75,7 @@ public class TrackedSignManager { trackedSigns = new HashMap<>(); if (signSection == null) { - PaidSigns.getInstance().getLogger().log(Level.WARNING, "Signs section not found in data.yml"); + PaidSigns.getInstance().getLogger().log(Level.WARNING, "Tracked signs section not found in data.yml"); return; } @@ -120,7 +128,7 @@ public class TrackedSignManager { String locationString = Objects.requireNonNull(signLocation.getWorld()).getUID() + "," + signLocation.getBlockX() + "," + signLocation.getBlockY() + "," + signLocation.getBlockZ(); signSection.set(locationString + ".cost", sign.getCost()); - signSection.set(locationString + ".playerId", sign.getPlayerId()); + signSection.set(locationString + ".playerId", sign.getPlayerId().toString()); } configuration.save(signsFile); }