diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 5d33d31..3ecf549 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -6,6 +6,11 @@
+
+
+
+
+
diff --git a/README.MD b/README.MD
index 2c3791b..8e33458 100644
--- a/README.MD
+++ b/README.MD
@@ -49,6 +49,8 @@ Currently, the plugin implements the following features, so far:
- [X] Additional Gang Commands (kick, promote, disband) **
- [X] Tree Farm **
- [x] Gang PlaceholderAPI support (display Gang Name for chat etc)
+ - [x] AutoSell Toggle (Toggable)
+ - [x] SellAll Command (Toggable)
- [ ] Spawn with Prisoner Tools (Toggable)
- [ ] Restrict Prisoner Tools from moving in inventory and dropping? (Toggable)
- [ ] Prisoner Tokens or Gems (Tied into Vault?)\
diff --git a/pom.xml b/pom.xml
index 3df6caf..317b025 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.NVus
NVus_Prison
- 0.9.7
+ 0.9.8
jar
NVus_PrisonSetup
@@ -101,6 +101,11 @@
placeholderapi
https://repo.extendedclip.com/content/repositories/placeholderapi/
+
+
+ jitpack.io
+ https://jitpack.io
+
@@ -135,7 +140,15 @@
2.11.4
provided
-
+
+
+ com.github.MilkBowl
+ VaultAPI
+ 1.7
+ provided
+
+
+
com.sk89q.worldguard
worldguard-bukkit
diff --git a/src/main/java/me/nvus/nvus_prison_setup/AutoSell/Listeners/AutoSellListener.java b/src/main/java/me/nvus/nvus_prison_setup/AutoSell/Listeners/AutoSellListener.java
new file mode 100644
index 0000000..6e7ac63
--- /dev/null
+++ b/src/main/java/me/nvus/nvus_prison_setup/AutoSell/Listeners/AutoSellListener.java
@@ -0,0 +1,38 @@
+package me.nvus.nvus_prison_setup.AutoSell.Listeners;
+
+import me.nvus.nvus_prison_setup.AutoSell.SellManager;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+public class AutoSellListener implements Listener {
+ private final SellManager sellManager;
+
+ public AutoSellListener(SellManager sellManager) {
+ this.sellManager = sellManager;
+ }
+
+ @EventHandler
+ public void onBlockBreak(BlockBreakEvent event) {
+ Player player = event.getPlayer();
+ if (!player.hasPermission("nvus.prisoner") || !sellManager.isAutoSellEnabled(player)) {
+ return;
+ }
+
+ Block block = event.getBlock();
+ ItemStack tool = player.getInventory().getItemInMainHand();
+
+ block.getDrops(tool).forEach(drop -> {
+ Material dropType = drop.getType();
+ if (sellManager.isSellable(dropType)) {
+ sellManager.sellBlockDrop(player, dropType, drop.getAmount());
+ block.setType(Material.AIR); // Remove the block after "selling" its drop
+ event.setDropItems(false); // Prevent dropping the item
+ }
+ });
+ }
+}
diff --git a/src/main/java/me/nvus/nvus_prison_setup/AutoSell/Listeners/SellAllListener.java b/src/main/java/me/nvus/nvus_prison_setup/AutoSell/Listeners/SellAllListener.java
new file mode 100644
index 0000000..1c54f0c
--- /dev/null
+++ b/src/main/java/me/nvus/nvus_prison_setup/AutoSell/Listeners/SellAllListener.java
@@ -0,0 +1,4 @@
+package me.nvus.nvus_prison_setup.AutoSell.Listeners;
+
+public class SellAllListener {
+}
diff --git a/src/main/java/me/nvus/nvus_prison_setup/AutoSell/SellManager.java b/src/main/java/me/nvus/nvus_prison_setup/AutoSell/SellManager.java
new file mode 100644
index 0000000..de860a5
--- /dev/null
+++ b/src/main/java/me/nvus/nvus_prison_setup/AutoSell/SellManager.java
@@ -0,0 +1,128 @@
+package me.nvus.nvus_prison_setup.AutoSell;
+
+import me.nvus.nvus_prison_setup.Configs.ConfigManager;
+import me.nvus.nvus_prison_setup.PrisonSetup;
+import net.milkbowl.vault.economy.Economy;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+public class SellManager implements CommandExecutor {
+
+ private final HashMap autoSellStatus = new HashMap<>();
+ private final HashMap prices = new HashMap<>();
+ private final ConfigManager configManager;
+
+ public SellManager(ConfigManager configManager) {
+ this.configManager = configManager;
+ loadPrices();
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage("Only players can use this command.");
+ return true;
+ }
+
+ Player player = (Player) sender;
+
+ switch (command.getName().toLowerCase()) {
+ case "autosell":
+ toggleAutoSell(player);
+ break;
+ case "sellall":
+ sellItems(player);
+ break;
+ }
+
+ return true;
+ }
+
+ private void loadPrices() {
+ FileConfiguration itemPricesConfig = configManager.getItemPricesConfig();
+ for (String key : itemPricesConfig.getConfigurationSection("Prices").getKeys(false)) {
+ String materialName = itemPricesConfig.getString("Prices." + key + ".Material");
+ Material material = Material.matchMaterial(materialName);
+ double price = itemPricesConfig.getDouble("Prices." + key + ".Sell");
+
+ if (material != null) {
+ prices.put(material, price);
+ } else {
+ System.err.println("Invalid material in item_prices.yml: " + materialName);
+ }
+ }
+ }
+
+ private void toggleAutoSell(Player player) {
+ boolean currentStatus = autoSellStatus.getOrDefault(player.getUniqueId(), false);
+ autoSellStatus.put(player.getUniqueId(), !currentStatus); // Toggle the status
+ player.sendMessage("AutoSell is now " + (autoSellStatus.get(player.getUniqueId()) ? "enabled!" : "disabled!"));
+ }
+
+ public boolean isAutoSellEnabled(Player player) {
+ // Get the AutoSell status for this player. Defaults to FALSE if not set!!!!!
+ return autoSellStatus.getOrDefault(player.getUniqueId(), false);
+ }
+
+ public void sellItems(Player player) {
+ if (!player.hasPermission("nvus.prisoner")) {
+ player.sendMessage("You do not have permission to use this command.");
+ return;
+ }
+
+ double totalSale = 0;
+ ItemStack[] items = player.getInventory().getContents();
+ for (ItemStack item : items) {
+ if (item != null && prices.containsKey(item.getType())) {
+ double pricePerItem = prices.get(item.getType());
+ totalSale += pricePerItem * item.getAmount();
+ player.getInventory().remove(item);
+ }
+ }
+
+ if (totalSale > 0) {
+ giveMoney(player, totalSale);
+ // We send the message of amount give in the giveMoney method now!!
+ //player.sendMessage(String.format("Sold items for $%.2f", totalSale));
+ } else {
+ player.sendMessage("No eligible items to sell.");
+ }
+ }
+
+ private void giveMoney(Player player, double amount) {
+ Economy economy = PrisonSetup.getEconomy();
+ economy.depositPlayer(player, amount);
+ player.sendMessage(String.format("You've been given $%.2f", amount));
+ }
+
+ public void sellBlockDrop(Player player, Material material, int amount) {
+ if (!isSellable(material)) {
+ return;
+ }
+ double price = getPrice(material) * amount;
+ if (price > 0) {
+ giveMoney(player, price);
+ player.sendMessage(String.format("Sold %s x%d for $%.2f", material.toString(), amount, price));
+ }
+ }
+
+ public boolean isSellable(Material material) {
+ return prices.containsKey(material);
+ }
+
+ public double getPrice(Material material) {
+ return prices.getOrDefault(material, 0.0);
+ }
+
+
+
+}
diff --git a/src/main/java/me/nvus/nvus_prison_setup/Configs/ConfigManager.java b/src/main/java/me/nvus/nvus_prison_setup/Configs/ConfigManager.java
index 3adbfb2..50c50a4 100644
--- a/src/main/java/me/nvus/nvus_prison_setup/Configs/ConfigManager.java
+++ b/src/main/java/me/nvus/nvus_prison_setup/Configs/ConfigManager.java
@@ -14,6 +14,8 @@ public class ConfigManager {
private final Map configs;
private final Map configFiles;
+ private FileConfiguration itemPricesConfig;
+
public ConfigManager(JavaPlugin plugin) {
this.plugin = plugin;
this.configs = new HashMap<>();
@@ -70,4 +72,21 @@ public class ConfigManager {
}
return configFiles.get(configName);
}
+
+ // ITEM CONFIGURATION
+ public void loadItemPricesConfig(File dataFolder) {
+ File file = new File(dataFolder, "item_prices.yml");
+ if (!file.exists()) {
+ try {
+ file.createNewFile(); // Create the file if it doesn't exist
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ itemPricesConfig = YamlConfiguration.loadConfiguration(file);
+ }
+
+ public FileConfiguration getItemPricesConfig() {
+ return itemPricesConfig;
+ }
}
diff --git a/src/main/java/me/nvus/nvus_prison_setup/PrisonSetup.java b/src/main/java/me/nvus/nvus_prison_setup/PrisonSetup.java
index abdbd9a..35b0443 100644
--- a/src/main/java/me/nvus/nvus_prison_setup/PrisonSetup.java
+++ b/src/main/java/me/nvus/nvus_prison_setup/PrisonSetup.java
@@ -13,12 +13,17 @@ import me.nvus.nvus_prison_setup.Placeholders.GangPlaceholders;
import me.nvus.nvus_prison_setup.Updater.UpdateChecker;
import me.nvus.nvus_prison_setup.Listeners.ToolDamageListener;
import me.nvus.nvus_prison_setup.TreeFarm.TreeFarmListener;
+import me.nvus.nvus_prison_setup.AutoSell.SellManager;
// Database
import me.nvus.nvus_prison_setup.Database.DatabaseManager;
// Gangs
import me.nvus.nvus_prison_setup.Gangs.GangCommands;
import me.nvus.nvus_prison_setup.Gangs.GangManager;
+// Vault
+import net.milkbowl.vault.economy.Economy;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
// Bukkit
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
@@ -38,6 +43,8 @@ public final class PrisonSetup extends JavaPlugin {
private DatabaseManager dbManager;
private GangManager gangManager; // Added reference to GangManager
+ private static Economy econ = null; // Vault / Economy
+
@Override
public void onEnable() {
@@ -64,6 +71,13 @@ public final class PrisonSetup extends JavaPlugin {
configManager.saveDefaultConfig("banned_items.yml");
configManager.saveDefaultConfig("auto_switch.yml");
+ // Check if Vault is installed, it's a hard dependency so disable plugin if not installed!
+ if (!setupEconomy()) {
+ getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
+ getServer().getPluginManager().disablePlugin(this);
+ return;
+ }
+
//FileConfiguration config = configManager.getConfig("config.yml");
// Register Event Listeners
@@ -81,6 +95,22 @@ public final class PrisonSetup extends JavaPlugin {
new GangPlaceholders(gangManager).register();
}
+ // Register the Auto Sell and Sell All Listeners
+ boolean autoSellEnabled = configManager.getConfig("config.yml").getBoolean("AutoSell", true);
+ boolean sellAllEnabled = configManager.getConfig("config.yml").getBoolean("SellAll", true);
+ SellManager sellManager = new SellManager(configManager);
+
+ // If they are true, register the commands.
+ if (autoSellEnabled) {
+ // Register the autosell command.
+ this.getCommand("autosell").setExecutor(sellManager);
+ }
+ // If they are true, register the commands.
+ if (sellAllEnabled) {
+ // Register the sellall command.
+ this.getCommand("sellall").setExecutor(sellManager);
+ }
+
// Settings Menu
getServer().getPluginManager().registerEvents(new SettingsMenu(this, configManager), this);
@@ -126,6 +156,23 @@ public final class PrisonSetup extends JavaPlugin {
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&c&lNVus Prison Setup has been successfully disabled!"));
}
+ // Vault Stuff
+ private boolean setupEconomy() {
+ if (getServer().getPluginManager().getPlugin("Vault") == null) {
+ return false;
+ }
+ RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class);
+ if (rsp == null) {
+ return false;
+ }
+ econ = rsp.getProvider();
+ return econ != null;
+ }
+
+ public static Economy getEconomy() {
+ return econ;
+ }
+
public ConfigManager getConfigManager() {
return configManager;
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index e043cd6..44ab3f2 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -9,7 +9,7 @@
# players that are not or no longer considered a prisoner.
########################################################################################
-# AUTO PICKUP & SWITCH SETTINGS #
+# AUTO SETTINGS #
########################################################################################
# Should prisoners auto pickup blocks they have mined?
@@ -25,6 +25,14 @@ AutoPickup: false
# Use /nvus autoswitch true|false to toggle this in-game! (Requires permission: nvus.admin)
AutoSwitch: true
+# Allow players to auto sell items as they are mining them
+AutoSell: true
+# Allows players to use /sellall to manually sell all elgible items in their inventory, regardless if AutoSell is enabled.
+# Setting this to false will disable the feature & command completely.
+SellAll: true
+# You can see material prices in the item_pricing.yml file or in-game using /sellprice with an item in your hand.
+# Only players/prisoners with the permission nvus.prisoner can use the /sellprice command and autosell toggle.
+
########################################################################################
# ARMOR SETTINGS #
########################################################################################
diff --git a/src/main/resources/item_prices.yml b/src/main/resources/item_prices.yml
new file mode 100644
index 0000000..d38714d
--- /dev/null
+++ b/src/main/resources/item_prices.yml
@@ -0,0 +1,26 @@
+#======================================================================================#
+# NVus PRISON GOLD EDITION #
+# by never2nv #
+# www.FNGnation.net #
+# Discord: FNGnation.net/discord #
+#======================================================================================#
+
+Prices:
+ - Material: OAK_PLANKS
+ Sell: 1.0
+ - Material: SPRUCE_PLANKS
+ Sell: 1.0
+ - Material: BIRCH_PLANKS
+ Sell: 1.0
+ - Material: JUNGLE_PLANKS
+ Sell: 1.0
+ - Material: ACACIA_PLANKS
+ Sell: 1.0
+ - Material: DARK_OAK_PLANKS
+ Sell: 1.0
+ - Material: Cobblestone
+ Sell: 1.0
+ - Material: Stone
+ Sell: 2.0
+ - Material: Coal
+ Sell: 0.50
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 0e57aa9..4b78f4b 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -8,6 +8,7 @@ website: https://FNGnation.net
depend:
- WorldGuard
+ - Vault
softdepend:
- PlaceholderAPI