forked from never2nv/NVus_Prison
v0.9.8 - Added AutoSell and SellAll Features. Either of which can be turned on/off in the config.yml. Added an item_prices.yml file which is used to dictate which blocks can be sold and for what price. I used doubles for prices, just in case.
This commit is contained in:
parent
cffe7ae97d
commit
73d12a71b7
|
@ -6,6 +6,11 @@
|
||||||
<option name="name" value="Central Repository" />
|
<option name="name" value="Central Repository" />
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jitpack.io" />
|
||||||
|
<option name="name" value="jitpack.io" />
|
||||||
|
<option name="url" value="https://jitpack.io" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="sonatype" />
|
<option name="id" value="sonatype" />
|
||||||
<option name="name" value="sonatype" />
|
<option name="name" value="sonatype" />
|
||||||
|
|
|
@ -49,6 +49,8 @@ Currently, the plugin implements the following features, so far:
|
||||||
- [X] Additional Gang Commands (kick, promote, disband) **
|
- [X] Additional Gang Commands (kick, promote, disband) **
|
||||||
- [X] Tree Farm **
|
- [X] Tree Farm **
|
||||||
- [x] Gang PlaceholderAPI support (display Gang Name for chat etc)
|
- [x] Gang PlaceholderAPI support (display Gang Name for chat etc)
|
||||||
|
- [x] AutoSell Toggle (Toggable)
|
||||||
|
- [x] SellAll Command (Toggable)
|
||||||
- [ ] Spawn with Prisoner Tools (Toggable)
|
- [ ] Spawn with Prisoner Tools (Toggable)
|
||||||
- [ ] Restrict Prisoner Tools from moving in inventory and dropping? (Toggable)
|
- [ ] Restrict Prisoner Tools from moving in inventory and dropping? (Toggable)
|
||||||
- [ ] Prisoner Tokens or Gems (Tied into Vault?)\
|
- [ ] Prisoner Tokens or Gems (Tied into Vault?)\
|
||||||
|
|
15
pom.xml
15
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>me.NVus</groupId>
|
<groupId>me.NVus</groupId>
|
||||||
<artifactId>NVus_Prison</artifactId>
|
<artifactId>NVus_Prison</artifactId>
|
||||||
<version>0.9.7</version>
|
<version>0.9.8</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>NVus_PrisonSetup</name>
|
<name>NVus_PrisonSetup</name>
|
||||||
|
@ -101,6 +101,11 @@
|
||||||
<id>placeholderapi</id>
|
<id>placeholderapi</id>
|
||||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<!-- Jitpack for Vault etc-->
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -135,6 +140,14 @@
|
||||||
<version>2.11.4</version>
|
<version>2.11.4</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Vault-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- WorldGuard-->
|
<!-- WorldGuard-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package me.nvus.nvus_prison_setup.AutoSell.Listeners;
|
||||||
|
|
||||||
|
public class SellAllListener {
|
||||||
|
}
|
|
@ -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<UUID, Boolean> autoSellStatus = new HashMap<>();
|
||||||
|
private final HashMap<Material, Double> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -14,6 +14,8 @@ public class ConfigManager {
|
||||||
private final Map<String, FileConfiguration> configs;
|
private final Map<String, FileConfiguration> configs;
|
||||||
private final Map<String, File> configFiles;
|
private final Map<String, File> configFiles;
|
||||||
|
|
||||||
|
private FileConfiguration itemPricesConfig;
|
||||||
|
|
||||||
public ConfigManager(JavaPlugin plugin) {
|
public ConfigManager(JavaPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.configs = new HashMap<>();
|
this.configs = new HashMap<>();
|
||||||
|
@ -70,4 +72,21 @@ public class ConfigManager {
|
||||||
}
|
}
|
||||||
return configFiles.get(configName);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.Updater.UpdateChecker;
|
||||||
import me.nvus.nvus_prison_setup.Listeners.ToolDamageListener;
|
import me.nvus.nvus_prison_setup.Listeners.ToolDamageListener;
|
||||||
import me.nvus.nvus_prison_setup.TreeFarm.TreeFarmListener;
|
import me.nvus.nvus_prison_setup.TreeFarm.TreeFarmListener;
|
||||||
|
import me.nvus.nvus_prison_setup.AutoSell.SellManager;
|
||||||
// Database
|
// Database
|
||||||
import me.nvus.nvus_prison_setup.Database.DatabaseManager;
|
import me.nvus.nvus_prison_setup.Database.DatabaseManager;
|
||||||
// Gangs
|
// Gangs
|
||||||
import me.nvus.nvus_prison_setup.Gangs.GangCommands;
|
import me.nvus.nvus_prison_setup.Gangs.GangCommands;
|
||||||
import me.nvus.nvus_prison_setup.Gangs.GangManager;
|
import me.nvus.nvus_prison_setup.Gangs.GangManager;
|
||||||
|
|
||||||
|
// Vault
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
// Bukkit
|
// Bukkit
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
@ -38,6 +43,8 @@ public final class PrisonSetup extends JavaPlugin {
|
||||||
private DatabaseManager dbManager;
|
private DatabaseManager dbManager;
|
||||||
private GangManager gangManager; // Added reference to GangManager
|
private GangManager gangManager; // Added reference to GangManager
|
||||||
|
|
||||||
|
private static Economy econ = null; // Vault / Economy
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
|
@ -64,6 +71,13 @@ public final class PrisonSetup extends JavaPlugin {
|
||||||
configManager.saveDefaultConfig("banned_items.yml");
|
configManager.saveDefaultConfig("banned_items.yml");
|
||||||
configManager.saveDefaultConfig("auto_switch.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");
|
//FileConfiguration config = configManager.getConfig("config.yml");
|
||||||
|
|
||||||
// Register Event Listeners
|
// Register Event Listeners
|
||||||
|
@ -81,6 +95,22 @@ public final class PrisonSetup extends JavaPlugin {
|
||||||
new GangPlaceholders(gangManager).register();
|
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
|
// Settings Menu
|
||||||
getServer().getPluginManager().registerEvents(new SettingsMenu(this, configManager), this);
|
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!"));
|
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<Economy> 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() {
|
public ConfigManager getConfigManager() {
|
||||||
return configManager;
|
return configManager;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
# players that are not or no longer considered a prisoner.
|
# players that are not or no longer considered a prisoner.
|
||||||
|
|
||||||
########################################################################################
|
########################################################################################
|
||||||
# AUTO PICKUP & SWITCH SETTINGS #
|
# AUTO SETTINGS #
|
||||||
########################################################################################
|
########################################################################################
|
||||||
|
|
||||||
# Should prisoners auto pickup blocks they have mined?
|
# 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)
|
# Use /nvus autoswitch true|false to toggle this in-game! (Requires permission: nvus.admin)
|
||||||
AutoSwitch: true
|
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 <price> with an item in your hand.
|
||||||
|
# Only players/prisoners with the permission nvus.prisoner can use the /sellprice command and autosell toggle.
|
||||||
|
|
||||||
########################################################################################
|
########################################################################################
|
||||||
# ARMOR SETTINGS #
|
# ARMOR SETTINGS #
|
||||||
########################################################################################
|
########################################################################################
|
||||||
|
|
|
@ -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
|
|
@ -8,6 +8,7 @@ website: https://FNGnation.net
|
||||||
|
|
||||||
depend:
|
depend:
|
||||||
- WorldGuard
|
- WorldGuard
|
||||||
|
- Vault
|
||||||
|
|
||||||
softdepend:
|
softdepend:
|
||||||
- PlaceholderAPI
|
- PlaceholderAPI
|
||||||
|
|
Loading…
Reference in New Issue