Compare commits
	
		
			3 Commits
		
	
	
		
			0.2.0-ALPH
			...
			0.3.0-ALPH
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 797020aa7f | |||
| 15426a46f3 | |||
| a1b1a5d112 | 
							
								
								
									
										12
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
									
									
									
									
								
							@@ -76,3 +76,15 @@ Removes a registered paid sign
 | 
				
			|||||||
* paidsigns.manage - Grants the permission to add/remove a paid sign
 | 
					* paidsigns.manage - Grants the permission to add/remove a paid sign
 | 
				
			||||||
* paidsigns.reload - Grants the permissions to reload the plugin
 | 
					* paidsigns.reload - Grants the permissions to reload the plugin
 | 
				
			||||||
* paidsigns.paymentexempt - Makes this player exempt from the cost of paid signs
 | 
					* 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)
 | 
				
			||||||
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@@ -6,7 +6,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <groupId>net.knarcraft</groupId>
 | 
					    <groupId>net.knarcraft</groupId>
 | 
				
			||||||
    <artifactId>paidsigns</artifactId>
 | 
					    <artifactId>paidsigns</artifactId>
 | 
				
			||||||
    <version>0.2.0-ALPHA</version>
 | 
					    <version>0.3.0-ALPHA</version>
 | 
				
			||||||
    <packaging>jar</packaging>
 | 
					    <packaging>jar</packaging>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <name>Paid Signs</name>
 | 
					    <name>Paid Signs</name>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,11 +10,15 @@ import net.knarcraft.paidsigns.command.ReloadTabCommand;
 | 
				
			|||||||
import net.knarcraft.paidsigns.command.RemoveConditionCommand;
 | 
					import net.knarcraft.paidsigns.command.RemoveConditionCommand;
 | 
				
			||||||
import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter;
 | 
					import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter;
 | 
				
			||||||
import net.knarcraft.paidsigns.command.RemoveTabCommand;
 | 
					import net.knarcraft.paidsigns.command.RemoveTabCommand;
 | 
				
			||||||
 | 
					import net.knarcraft.paidsigns.listener.BlockBreakListener;
 | 
				
			||||||
import net.knarcraft.paidsigns.listener.SignListener;
 | 
					import net.knarcraft.paidsigns.listener.SignListener;
 | 
				
			||||||
import net.knarcraft.paidsigns.manager.EconomyManager;
 | 
					import net.knarcraft.paidsigns.manager.EconomyManager;
 | 
				
			||||||
import net.knarcraft.paidsigns.manager.PaidSignManager;
 | 
					import net.knarcraft.paidsigns.manager.PaidSignManager;
 | 
				
			||||||
 | 
					import net.knarcraft.paidsigns.manager.TrackedSignManager;
 | 
				
			||||||
import net.milkbowl.vault.economy.Economy;
 | 
					import net.milkbowl.vault.economy.Economy;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandExecutor;
 | 
				
			||||||
import org.bukkit.command.PluginCommand;
 | 
					import org.bukkit.command.PluginCommand;
 | 
				
			||||||
 | 
					import org.bukkit.command.TabCompleter;
 | 
				
			||||||
import org.bukkit.command.TabExecutor;
 | 
					import org.bukkit.command.TabExecutor;
 | 
				
			||||||
import org.bukkit.configuration.file.FileConfiguration;
 | 
					import org.bukkit.configuration.file.FileConfiguration;
 | 
				
			||||||
import org.bukkit.plugin.PluginManager;
 | 
					import org.bukkit.plugin.PluginManager;
 | 
				
			||||||
@@ -31,6 +35,8 @@ public final class PaidSigns extends JavaPlugin {
 | 
				
			|||||||
    private PaidSignManager signManager;
 | 
					    private PaidSignManager signManager;
 | 
				
			||||||
    private boolean ignoreCase;
 | 
					    private boolean ignoreCase;
 | 
				
			||||||
    private boolean ignoreColor;
 | 
					    private boolean ignoreColor;
 | 
				
			||||||
 | 
					    private boolean enableRefunds;
 | 
				
			||||||
 | 
					    private int refundPercentage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Instantiates a new paid signs object
 | 
					     * Instantiates a new paid signs object
 | 
				
			||||||
@@ -53,10 +59,12 @@ public final class PaidSigns extends JavaPlugin {
 | 
				
			|||||||
    public void onEnable() {
 | 
					    public void onEnable() {
 | 
				
			||||||
        setupVault();
 | 
					        setupVault();
 | 
				
			||||||
        signManager = new PaidSignManager(PaidSignManager.loadSigns());
 | 
					        signManager = new PaidSignManager(PaidSignManager.loadSigns());
 | 
				
			||||||
 | 
					        TrackedSignManager.loadTrackedSigns();
 | 
				
			||||||
        loadConfig();
 | 
					        loadConfig();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PluginManager pluginManager = getServer().getPluginManager();
 | 
					        PluginManager pluginManager = getServer().getPluginManager();
 | 
				
			||||||
        pluginManager.registerEvents(new SignListener(), this);
 | 
					        pluginManager.registerEvents(new SignListener(), this);
 | 
				
			||||||
 | 
					        pluginManager.registerEvents(new BlockBreakListener(), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        registerCommands();
 | 
					        registerCommands();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -72,6 +80,7 @@ public final class PaidSigns extends JavaPlugin {
 | 
				
			|||||||
        this.reloadConfig();
 | 
					        this.reloadConfig();
 | 
				
			||||||
        loadConfig();
 | 
					        loadConfig();
 | 
				
			||||||
        signManager = new PaidSignManager(PaidSignManager.loadSigns());
 | 
					        signManager = new PaidSignManager(PaidSignManager.loadSigns());
 | 
				
			||||||
 | 
					        TrackedSignManager.loadTrackedSigns();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -101,46 +110,56 @@ public final class PaidSigns extends JavaPlugin {
 | 
				
			|||||||
        return this.ignoreColor;
 | 
					        return this.ignoreColor;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Checks whether refunds are currently enabled
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return <p>Whether refunds are currently enabled</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public boolean areRefundsEnabled() {
 | 
				
			||||||
 | 
					        return this.enableRefunds;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the percentage of the initial cost to refund the sign creator
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return <p>The percentage of the cost to refund</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public int getRefundPercentage() {
 | 
				
			||||||
 | 
					        if (this.refundPercentage < 0) {
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        } else if (refundPercentage > 100) {
 | 
				
			||||||
 | 
					            return 100;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return this.refundPercentage;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Registers the commands used by this plugin
 | 
					     * Registers the commands used by this plugin
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private void registerCommands() {
 | 
					    private void registerCommands() {
 | 
				
			||||||
        PluginCommand addCommand = this.getCommand("addPaidSign");
 | 
					        registerCommand("addPaidSign", new AddCommand(), new AddTabCompleter());
 | 
				
			||||||
        if (addCommand != null) {
 | 
					        registerCommand("listPaidSigns", new ListCommand(), new ListTabCompleter());
 | 
				
			||||||
            addCommand.setExecutor(new AddCommand());
 | 
					        registerCommand("addPaidSignCondition", new AddConditionCommand(), new AddConditionTabCompleter());
 | 
				
			||||||
            addCommand.setTabCompleter(new AddTabCompleter());
 | 
					        registerCommand("removePaidSignCondition", new RemoveConditionCommand(), new RemoveConditionTabCompleter());
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PluginCommand listCommand = this.getCommand("listPaidSigns");
 | 
					        TabExecutor removeTabExecutor = new RemoveTabCommand();
 | 
				
			||||||
        if (listCommand != null) {
 | 
					        registerCommand("removePaidSign", removeTabExecutor, removeTabExecutor);
 | 
				
			||||||
            listCommand.setExecutor(new ListCommand());
 | 
					        TabExecutor reloadTabExecutor = new ReloadTabCommand();
 | 
				
			||||||
            listCommand.setTabCompleter(new ListTabCompleter());
 | 
					        registerCommand("reload", reloadTabExecutor, reloadTabExecutor);
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PluginCommand addConditionCommand = this.getCommand("addPaidSignCondition");
 | 
					    /**
 | 
				
			||||||
        if (addConditionCommand != null) {
 | 
					     * Registers a command if possible
 | 
				
			||||||
            addConditionCommand.setExecutor(new AddConditionCommand());
 | 
					     *
 | 
				
			||||||
            addConditionCommand.setTabCompleter(new AddConditionTabCompleter());
 | 
					     * @param command         <p>The command to register</p>
 | 
				
			||||||
        }
 | 
					     * @param commandExecutor <p>The command executor for executing the command</p>
 | 
				
			||||||
 | 
					     * @param tabCompleter    <p>The tab completer for tab-completing the command</p>
 | 
				
			||||||
        PluginCommand removeConditionCommand = this.getCommand("removePaidSignCondition");
 | 
					     */
 | 
				
			||||||
        if (removeConditionCommand != null) {
 | 
					    private void registerCommand(String command, CommandExecutor commandExecutor, TabCompleter tabCompleter) {
 | 
				
			||||||
            removeConditionCommand.setExecutor(new RemoveConditionCommand());
 | 
					        PluginCommand pluginCommand = this.getCommand(command);
 | 
				
			||||||
            removeConditionCommand.setTabCompleter(new RemoveConditionTabCompleter());
 | 
					        if (pluginCommand != null) {
 | 
				
			||||||
        }
 | 
					            pluginCommand.setExecutor(commandExecutor);
 | 
				
			||||||
 | 
					            pluginCommand.setTabCompleter(tabCompleter);
 | 
				
			||||||
        PluginCommand removeCommand = this.getCommand("removePaidSign");
 | 
					 | 
				
			||||||
        if (removeCommand != null) {
 | 
					 | 
				
			||||||
            TabExecutor removeTabExecutor = new RemoveTabCommand();
 | 
					 | 
				
			||||||
            removeCommand.setExecutor(removeTabExecutor);
 | 
					 | 
				
			||||||
            removeCommand.setTabCompleter(removeTabExecutor);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        PluginCommand reloadCommand = this.getCommand("reload");
 | 
					 | 
				
			||||||
        if (reloadCommand != null) {
 | 
					 | 
				
			||||||
            TabExecutor reloadTabExecutor = new ReloadTabCommand();
 | 
					 | 
				
			||||||
            reloadCommand.setExecutor(reloadTabExecutor);
 | 
					 | 
				
			||||||
            reloadCommand.setTabCompleter(reloadTabExecutor);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -153,6 +172,8 @@ public final class PaidSigns extends JavaPlugin {
 | 
				
			|||||||
        this.saveDefaultConfig();
 | 
					        this.saveDefaultConfig();
 | 
				
			||||||
        ignoreCase = config.getBoolean("ignoreCase", true);
 | 
					        ignoreCase = config.getBoolean("ignoreCase", true);
 | 
				
			||||||
        ignoreColor = config.getBoolean("ignoreColor", false);
 | 
					        ignoreColor = config.getBoolean("ignoreColor", false);
 | 
				
			||||||
 | 
					        enableRefunds = config.getBoolean("enableRefunds", true);
 | 
				
			||||||
 | 
					        refundPercentage = config.getInt("refundPercentage", 100);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,8 @@ public class ReloadTabCommand implements TabExecutor {
 | 
				
			|||||||
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
 | 
					    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
 | 
				
			||||||
                             @NotNull String[] args) {
 | 
					                             @NotNull String[] args) {
 | 
				
			||||||
        PaidSigns.getInstance().reload();
 | 
					        PaidSigns.getInstance().reload();
 | 
				
			||||||
        return false;
 | 
					        sender.sendMessage("PaidSigns reloaded");
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					package net.knarcraft.paidsigns.container;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A representation of a sign placed by a player that matched a paid sign
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class TrackedSign {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final UUID playerId;
 | 
				
			||||||
 | 
					    private final double cost;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Instantiates a new tracked sign
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param playerId <p>The unique id of the player that created the sign</p>
 | 
				
			||||||
 | 
					     * @param cost     <p>The cost the player paid for creating the sign</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public TrackedSign(UUID playerId, double cost) {
 | 
				
			||||||
 | 
					        this.playerId = playerId;
 | 
				
			||||||
 | 
					        this.cost = cost;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the id of the player that created this tracked sign
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return <p>The player that created this tracked sign</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public UUID getPlayerId() {
 | 
				
			||||||
 | 
					        return this.playerId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the cost the player paid for creating this paid sign
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return <p>The cost paid for creating this sign</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public double getCost() {
 | 
				
			||||||
 | 
					        return this.cost;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					package net.knarcraft.paidsigns.listener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import net.knarcraft.paidsigns.PaidSigns;
 | 
				
			||||||
 | 
					import net.knarcraft.paidsigns.manager.TrackedSignManager;
 | 
				
			||||||
 | 
					import org.bukkit.block.Sign;
 | 
				
			||||||
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
 | 
					import org.bukkit.event.EventPriority;
 | 
				
			||||||
 | 
					import org.bukkit.event.Listener;
 | 
				
			||||||
 | 
					import org.bukkit.event.block.BlockBreakEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					import java.util.Arrays;
 | 
				
			||||||
 | 
					import java.util.logging.Level;
 | 
				
			||||||
 | 
					import java.util.logging.Logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A listener that listens for any tracked signs being broken
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class BlockBreakListener implements Listener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @EventHandler(priority = EventPriority.MONITOR)
 | 
				
			||||||
 | 
					    public void onBlockBreak(BlockBreakEvent event) {
 | 
				
			||||||
 | 
					        if (event.getBlock().getState() instanceof Sign) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                TrackedSignManager.removeTrackedSign(event.getBlock().getLocation());
 | 
				
			||||||
 | 
					            } catch (IOException e) {
 | 
				
			||||||
 | 
					                e.printStackTrace();
 | 
				
			||||||
 | 
					                Logger logger = PaidSigns.getInstance().getLogger();
 | 
				
			||||||
 | 
					                logger.log(Level.SEVERE, "Exception encountered while trying to write to the data file");
 | 
				
			||||||
 | 
					                logger.log(Level.SEVERE, Arrays.toString(e.getStackTrace()));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -3,13 +3,18 @@ package net.knarcraft.paidsigns.listener;
 | 
				
			|||||||
import net.knarcraft.paidsigns.PaidSigns;
 | 
					import net.knarcraft.paidsigns.PaidSigns;
 | 
				
			||||||
import net.knarcraft.paidsigns.container.PaidSign;
 | 
					import net.knarcraft.paidsigns.container.PaidSign;
 | 
				
			||||||
import net.knarcraft.paidsigns.manager.EconomyManager;
 | 
					import net.knarcraft.paidsigns.manager.EconomyManager;
 | 
				
			||||||
 | 
					import net.knarcraft.paidsigns.manager.TrackedSignManager;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.event.EventHandler;
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
import org.bukkit.event.EventPriority;
 | 
					import org.bukkit.event.EventPriority;
 | 
				
			||||||
import org.bukkit.event.Listener;
 | 
					import org.bukkit.event.Listener;
 | 
				
			||||||
import org.bukkit.event.block.SignChangeEvent;
 | 
					import org.bukkit.event.block.SignChangeEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					import java.util.Arrays;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.logging.Level;
 | 
				
			||||||
 | 
					import java.util.logging.Logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * A listener for listening to registered paid signs
 | 
					 * A listener for listening to registered paid signs
 | 
				
			||||||
@@ -50,19 +55,38 @@ public class SignListener implements Listener {
 | 
				
			|||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            double cost = paidSign.getCost();
 | 
					            performPaidSignTransaction(paidSign, player, event);
 | 
				
			||||||
            boolean canAfford = EconomyManager.canAfford(player, cost);
 | 
					 | 
				
			||||||
            if (!canAfford) {
 | 
					 | 
				
			||||||
                player.sendMessage("[PaidSigns] You cannot afford to create this sign");
 | 
					 | 
				
			||||||
                event.setCancelled(true);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                String unit = EconomyManager.getCurrency(cost != 1);
 | 
					 | 
				
			||||||
                player.sendMessage(String.format("[PaidSigns] You paid %.2f %s to create the sign", cost, unit));
 | 
					 | 
				
			||||||
                EconomyManager.withdraw(player, cost);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Performs the transaction to pay for the paid sign
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param paidSign <p>The paid sign a match has been found for</p>
 | 
				
			||||||
 | 
					     * @param player   <p>The player that created the sign</p>
 | 
				
			||||||
 | 
					     * @param event    <p>The sign change event that caused the sign to be created</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private void performPaidSignTransaction(PaidSign paidSign, Player player, SignChangeEvent event) {
 | 
				
			||||||
 | 
					        double cost = paidSign.getCost();
 | 
				
			||||||
 | 
					        boolean canAfford = EconomyManager.canAfford(player, cost);
 | 
				
			||||||
 | 
					        if (!canAfford) {
 | 
				
			||||||
 | 
					            player.sendMessage("[PaidSigns] You cannot afford to create this sign");
 | 
				
			||||||
 | 
					            event.setCancelled(true);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            String unit = EconomyManager.getCurrency(cost != 1);
 | 
				
			||||||
 | 
					            player.sendMessage(String.format("[PaidSigns] You paid %.2f %s to create the sign", cost, unit));
 | 
				
			||||||
 | 
					            EconomyManager.withdraw(player, cost);
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                TrackedSignManager.addTrackedSign(event.getBlock().getLocation(), player.getUniqueId(), cost);
 | 
				
			||||||
 | 
					            } catch (IOException e) {
 | 
				
			||||||
 | 
					                e.printStackTrace();
 | 
				
			||||||
 | 
					                Logger logger = PaidSigns.getInstance().getLogger();
 | 
				
			||||||
 | 
					                logger.log(Level.SEVERE, "Exception encountered while trying to write to the data file");
 | 
				
			||||||
 | 
					                logger.log(Level.SEVERE, Arrays.toString(e.getStackTrace()));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,6 @@ package net.knarcraft.paidsigns.manager;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import net.milkbowl.vault.economy.Economy;
 | 
					import net.milkbowl.vault.economy.Economy;
 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * A manager that performs all Economy tasks
 | 
					 * A manager that performs all Economy tasks
 | 
				
			||||||
@@ -55,7 +54,7 @@ public final class EconomyManager {
 | 
				
			|||||||
     * @param player <p>The player to withdraw money from</p>
 | 
					     * @param player <p>The player to withdraw money from</p>
 | 
				
			||||||
     * @param cost   <p>The amount of money to withdraw</p>
 | 
					     * @param cost   <p>The amount of money to withdraw</p>
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public static void withdraw(Player player, double cost) {
 | 
					    public static void withdraw(OfflinePlayer player, double cost) {
 | 
				
			||||||
        economy.withdrawPlayer(player, cost);
 | 
					        economy.withdrawPlayer(player, cost);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,136 @@
 | 
				
			|||||||
 | 
					package net.knarcraft.paidsigns.manager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import net.knarcraft.paidsigns.PaidSigns;
 | 
				
			||||||
 | 
					import net.knarcraft.paidsigns.container.TrackedSign;
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.Location;
 | 
				
			||||||
 | 
					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;
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					import java.util.logging.Level;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A manager for keeping track of plugin-signs created by players
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public final class TrackedSignManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static Map<Location, TrackedSign> trackedSigns = new HashMap<>();
 | 
				
			||||||
 | 
					    private static final File signsFile = new File(PaidSigns.getInstance().getDataFolder(), "data.yml");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private TrackedSignManager() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Adds a tracked sign to the manager
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param signLocation <p>The location the sign was created at</p>
 | 
				
			||||||
 | 
					     * @param playerId     <p>The unique id of the player that created the sign</p>
 | 
				
			||||||
 | 
					     * @throws IOException <p>If unable to save the tracked signs</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static void addTrackedSign(Location signLocation, UUID playerId, double cost) throws IOException {
 | 
				
			||||||
 | 
					        trackedSigns.put(signLocation, new TrackedSign(playerId, cost));
 | 
				
			||||||
 | 
					        saveTrackedSigns();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Removes a tracked sign from the manager
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param signLocation <p>The location the sign was removed from</p>
 | 
				
			||||||
 | 
					     * @throws IOException <p>If unable to save the tracked signs</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static void removeTrackedSign(Location signLocation) throws IOException {
 | 
				
			||||||
 | 
					        if (!trackedSigns.containsKey(signLocation)) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        TrackedSign trackedSign = trackedSigns.get(signLocation);
 | 
				
			||||||
 | 
					        trackedSigns.remove(signLocation);
 | 
				
			||||||
 | 
					        saveTrackedSigns();
 | 
				
			||||||
 | 
					        if (!PaidSigns.getInstance().areRefundsEnabled()) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(trackedSign.getPlayerId());
 | 
				
			||||||
 | 
					        double refundSum = trackedSign.getCost() / 100 * PaidSigns.getInstance().getRefundPercentage();
 | 
				
			||||||
 | 
					        EconomyManager.withdraw(offlinePlayer, -refundSum);
 | 
				
			||||||
 | 
					        if (offlinePlayer instanceof Player player) {
 | 
				
			||||||
 | 
					            player.sendMessage("You were refunded " + refundSum + " for your broken sign");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Loads all tracked signs from the data file
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static void loadTrackedSigns() {
 | 
				
			||||||
 | 
					        YamlConfiguration configuration = YamlConfiguration.loadConfiguration(signsFile);
 | 
				
			||||||
 | 
					        ConfigurationSection signSection = configuration.getConfigurationSection("trackedSigns");
 | 
				
			||||||
 | 
					        trackedSigns = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (signSection == null) {
 | 
				
			||||||
 | 
					            PaidSigns.getInstance().getLogger().log(Level.WARNING, "Tracked signs section not found in data.yml");
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (String key : signSection.getKeys(false)) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                loadSign(signSection, key);
 | 
				
			||||||
 | 
					            } catch (InvalidConfigurationException e) {
 | 
				
			||||||
 | 
					                PaidSigns.getInstance().getLogger().log(Level.SEVERE, "Unable to load sign " + key + ": " +
 | 
				
			||||||
 | 
					                        e.getMessage());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Loads a sign from the save file
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param signSection <p>The configuration section containing signs</p>
 | 
				
			||||||
 | 
					     * @param key         <p>The sign key which is also the sign's location</p>
 | 
				
			||||||
 | 
					     * @throws InvalidConfigurationException <p>If unable to load the sign</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private static void loadSign(ConfigurationSection signSection, String key) throws InvalidConfigurationException {
 | 
				
			||||||
 | 
					        String[] locationParts = key.split(",");
 | 
				
			||||||
 | 
					        Location signLocation;
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            signLocation = new Location(Bukkit.getWorld(UUID.fromString(locationParts[0])),
 | 
				
			||||||
 | 
					                    Double.parseDouble(locationParts[1]), Double.parseDouble(locationParts[2]),
 | 
				
			||||||
 | 
					                    Double.parseDouble(locationParts[3]));
 | 
				
			||||||
 | 
					        } catch (NumberFormatException exception) {
 | 
				
			||||||
 | 
					            throw new InvalidConfigurationException("Invalid sign coordinates");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        double cost = signSection.getDouble(key + ".cost");
 | 
				
			||||||
 | 
					        UUID playerId = UUID.fromString(Objects.requireNonNull(signSection.getString(key + ".playerId")));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        TrackedSign trackedSign = new TrackedSign(playerId, cost);
 | 
				
			||||||
 | 
					        trackedSigns.put(signLocation, trackedSign);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Saves the managed tracked signs to the data file
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @throws IOException <p>If unable to write to the data file</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private static void saveTrackedSigns() throws IOException {
 | 
				
			||||||
 | 
					        YamlConfiguration configuration = YamlConfiguration.loadConfiguration(signsFile);
 | 
				
			||||||
 | 
					        ConfigurationSection signSection = configuration.createSection("trackedSigns");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (Location signLocation : trackedSigns.keySet()) {
 | 
				
			||||||
 | 
					            TrackedSign sign = trackedSigns.get(signLocation);
 | 
				
			||||||
 | 
					            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().toString());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        configuration.save(signsFile);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -15,23 +15,6 @@ public final class TabCompleteHelper {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Finds tab complete values that contain the typed text
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param values    <p>The values to filter</p>
 | 
					 | 
				
			||||||
     * @param typedText <p>The text the player has started typing</p>
 | 
					 | 
				
			||||||
     * @return <p>The given string values that contain the player's typed text</p>
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public static List<String> filterMatchingContains(List<String> values, String typedText) {
 | 
					 | 
				
			||||||
        List<String> configValues = new ArrayList<>();
 | 
					 | 
				
			||||||
        for (String value : values) {
 | 
					 | 
				
			||||||
            if (value.toLowerCase().contains(typedText.toLowerCase())) {
 | 
					 | 
				
			||||||
                configValues.add(value);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return configValues;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Finds tab complete values that match the start of the typed text
 | 
					     * Finds tab complete values that match the start of the typed text
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,16 @@
 | 
				
			|||||||
# Whether to ignore the case (lowercase/uppercase) of the paid sign text. The option can be set on a per-sign basis, but
 | 
					# 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.
 | 
					# this value is used if not specified. The correct value depends on whether the plugin signs it should match are
 | 
				
			||||||
 | 
					# case-sensitive or not.
 | 
				
			||||||
ignoreCase: true
 | 
					ignoreCase: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Whether to ignore any color or formatting applied to the text when trying to match a paid sign's text. The option can
 | 
					# 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
 | 
					# 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.
 | 
					# signs it should match allow coloring or not.
 | 
				
			||||||
ignoreColor: false
 | 
					ignoreColor: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 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)
 | 
				
			||||||
 | 
					enableRefunds: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# The percentage of the paid sign cost to refund (0-100)
 | 
				
			||||||
 | 
					refundPercentage: 100
 | 
				
			||||||
		Reference in New Issue
	
	Block a user