v1.0.0 Release - Asset Push as well.

This commit is contained in:
WildInterloper 2024-03-13 12:57:44 -04:00
parent 94c7ce9619
commit 25083e2b13
14 changed files with 255 additions and 67 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 KiB

After

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 496 KiB

After

Width:  |  Height:  |  Size: 579 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -6,7 +6,7 @@
<groupId>me.NVus</groupId>
<artifactId>NVus_Prison</artifactId>
<version>0.9.8</version>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>NVus_PrisonSetup</name>

View File

@ -22,17 +22,6 @@ public class AutoSellListener implements Listener {
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
}
});
sellManager.sellItems(player);
}
}

View File

@ -3,14 +3,18 @@ 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.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -26,7 +30,6 @@ public class SellManager implements CommandExecutor {
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.");
@ -35,6 +38,26 @@ public class SellManager implements CommandExecutor {
Player player = (Player) sender;
// Admin Commands:
if ("setprice".equalsIgnoreCase(command.getName())) {
if (player.hasPermission("nvus.admin")) {
if (args.length != 1) {
player.sendMessage(ChatColor.RED + "Usage: /setprice <price>");
return true;
}
try {
double price = Double.parseDouble(args[0]);
setPrice(player, price);
} catch (NumberFormatException e) {
player.sendMessage(ChatColor.RED + "Please provide a valid price.");
}
} else {
player.sendMessage(ChatColor.RED + "You do not have permission to set prices.");
}
return true;
}
// Player/Prisoner Commands:
switch (command.getName().toLowerCase()) {
case "autosell":
toggleAutoSell(player);
@ -49,23 +72,58 @@ public class SellManager implements CommandExecutor {
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");
ConfigurationSection pricesSection = itemPricesConfig.getConfigurationSection("Prices");
if (pricesSection == null) {
System.err.println("Prices section not found in item_prices.yml");
return;
}
for (String key : pricesSection.getKeys(false)) {
Material material = Material.matchMaterial(key);
double price = pricesSection.getDouble(key + ".Sell");
if (material != null) {
prices.put(material, price);
} else {
System.err.println("Invalid material in item_prices.yml: " + materialName);
System.err.println("Invalid material in item_prices.yml: " + key);
}
}
}
public void reloadPrices() {
prices.clear(); // Clear existing prices to avoid duplicates
loadPrices(); // Reload prices
}
private void setPrice(Player player, double price) {
ItemStack itemInHand = player.getInventory().getItemInMainHand();
if (itemInHand == null || itemInHand.getType() == Material.AIR) {
player.sendMessage(ChatColor.RED + "You must be holding an item to set its price!");
return;
}
Material material = itemInHand.getType();
String materialName = material.name();
FileConfiguration itemPricesConfig = configManager.getItemPricesConfig();
itemPricesConfig.set("Prices." + materialName + ".Sell", price);
try {
itemPricesConfig.save(new File(configManager.getDataFolder(), "item_prices.yml"));
player.sendMessage(ChatColor.GREEN + "The price of " + materialName + " has been set to $" + price + ".");
configManager.reloadConfig("item_prices.yml");
configManager.reorderItemPrices();
reloadPrices();
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "There was a problem saving the price.");
e.printStackTrace();
}
}
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!"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format("&a&lAutoSell is now %s!", (autoSellStatus.get(player.getUniqueId()) ? "&a&lenabled" : "&c&ldisabled"))));
//player.sendMessage("AutoSell is now " + (autoSellStatus.get(player.getUniqueId()) ? "enabled!" : "disabled!"));
}
public boolean isAutoSellEnabled(Player player) {
@ -75,45 +133,67 @@ public class SellManager implements CommandExecutor {
public void sellItems(Player player) {
if (!player.hasPermission("nvus.prisoner")) {
player.sendMessage("You do not have permission to use this command.");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lYou do not have permission to use this command."));
return;
}
double totalSale = 0;
ItemStack[] items = player.getInventory().getContents();
for (ItemStack item : items) {
Map<Material, Integer> soldItems = new HashMap<>();
// Loop through the player's inventory and collect sellable items
for (ItemStack item : player.getInventory().getContents()) {
if (item != null && prices.containsKey(item.getType())) {
double pricePerItem = prices.get(item.getType());
totalSale += pricePerItem * item.getAmount();
soldItems.merge(item.getType(), item.getAmount(), Integer::sum);
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.");
}
// Sell the items that we just removed from their inventory
soldItems.forEach((material, quantity) -> {
double totalSale = prices.get(material) * quantity;
giveMoney(player, material, quantity, totalSale);
});
}
private void giveMoney(Player player, double amount) {
private void giveMoney(Player player, Material material, int quantity, double amount) {
Economy economy = PrisonSetup.getEconomy();
economy.depositPlayer(player, amount);
player.sendMessage(String.format("You've been given $%.2f", amount));
player.sendMessage(ChatColor.translateAlternateColorCodes('&',
String.format("&a&lSold &d%dx &3%s &a&lfor $%.2f", quantity, material.toString().toLowerCase().replaceAll("_", " "), 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 void sellItems(Player player) {
// if (!player.hasPermission("nvus.prisoner")) {
// player.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format("&c&lYou do not have permission to use this command.")));
// //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 the amount earned in the giveMoney method now!!
// //player.sendMessage(String.format("Sold items for $%.2f", totalSale));
// } else {
// //player.sendMessage("No eligible items to sell."); // For debug purposes only. Comment out when done.
// }
// }
//
// private void giveMoney(Player player, double amount) {
// Economy economy = PrisonSetup.getEconomy();
// economy.depositPlayer(player, amount);
// player.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format("&a&lYou've earned: $%.2f", amount)));
// }
public boolean isSellable(Material material) {
return prices.containsKey(material);

View File

@ -8,6 +8,8 @@ import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class ConfigManager {
private final JavaPlugin plugin;
@ -86,6 +88,41 @@ public class ConfigManager {
itemPricesConfig = YamlConfiguration.loadConfiguration(file);
}
public void reorderItemPrices() {
File itemPricesFile = new File(getDataFolder(), "item_prices.yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(itemPricesFile);
FileConfiguration newConfig = new YamlConfiguration();
// Using TreeMap to automatically sort the keys in natural order
Map<String, Object> sortedMap = new TreeMap<>();
// Assuming your structure is directly under the root
if (config.getConfigurationSection("Prices") != null) {
for (String key : config.getConfigurationSection("Prices").getKeys(false)) {
double price = config.getDouble("Prices." + key + ".Sell");
// Storing in a sorted map
sortedMap.put(key, price);
}
// Clear the existing "Prices" section
config.set("Prices", null);
// Repopulate the "Prices" section in sorted order
for (Map.Entry<String, Object> entry : sortedMap.entrySet()) {
config.set("Prices." + entry.getKey() + ".Sell", entry.getValue());
}
// Save the sorted configuration back to the file
try {
config.save(itemPricesFile);
System.out.println("Saved item_prices.yml with materials in alphabetical order.");
} catch (IOException e) {
e.printStackTrace();
System.err.println("Failed to save item_prices.yml in alphabetical order.");
}
}
}
public FileConfiguration getItemPricesConfig() {
return itemPricesConfig;
}

View File

@ -31,17 +31,23 @@ public class SettingsMenu implements Listener {
}
public void openSettingsMenu(Player player) {
Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GREEN + "NVus Prison Settings");
Inventory inv = Bukkit.createInventory(null, 18, ChatColor.DARK_GREEN + "NVus Prison Settings");
FileConfiguration config = configManager.getConfig("config.yml");
inv.setItem(0, createToggleItem(Material.LEATHER_CHESTPLATE, "Toggle PrisonerArmor", config.getBoolean("PrisonerArmor", true)));
inv.setItem(1, createToggleItem(Material.IRON_CHESTPLATE, "Toggle RestrictArmor", config.getBoolean("RestrictArmor", true)));
inv.setItem(3, createToggleItem(Material.HOPPER, "Toggle AutoPickup", config.getBoolean("AutoPickup", true)));
inv.setItem(4, createToggleItem(Material.LEVER, "Toggle AutoSwitch", config.getBoolean("AutoSwitch", false)));
inv.setItem(3, createToggleItem(Material.HOPPER, "Toggle AutoPickup", config.getBoolean("AutoPickup", false)));
inv.setItem(4, createToggleItem(Material.LEVER, "Toggle AutoSwitch", config.getBoolean("AutoSwitch", true)));
inv.setItem(5, createToggleItem(Material.IRON_PICKAXE, "Toggle ToolDamage", config.getBoolean("ToolDamage", false)));
inv.setItem(6, createToggleItem(Material.IRON_PICKAXE, "Toggle ToolDamage", config.getBoolean("ToolDamage", false)));
inv.setItem(7, createToggleItem(Material.BOOK, "Reload Configs", false));
inv.setItem(8, createToggleItem(Material.BOOK, "Reload Configs", false));
// Second Row
inv.setItem(9, createToggleItem(Material.GOLD_INGOT, "Toggle AutoSell", config.getBoolean("AutoSell", true)));
inv.setItem(10, createToggleItem(Material.GOLD_BLOCK, "Toggle SellAll", config.getBoolean("SellAll", true)));
inv.setItem(11, createToggleItem(Material.OAK_SAPLING, "Toggle TreeFarm", config.getBoolean("TreeFarm", true)));
player.openInventory(inv);
}
@ -94,6 +100,12 @@ public class SettingsMenu implements Listener {
toggleConfigOption(player, "AutoPickup");
} else if (displayName.contains("Toggle AutoSwitch")) {
toggleConfigOption(player, "AutoSwitch");
} else if (displayName.contains("Toggle AutoSell")) {
toggleConfigOption(player, "AutoSell");
} else if (displayName.contains("Toggle SellAll")) {
toggleConfigOption(player, "SellAll");
} else if (displayName.contains("Toggle TreeFarm")) {
toggleConfigOption(player, "TreeFarm");
} else if (displayName.contains("Reload Configs")) {
reloadConfigs(player);
}

View File

@ -104,6 +104,27 @@ public class CommandListener implements CommandExecutor {
}
handleToggleConfigCommand(sender, "ToolDamage", args[1]);
break;
case "treefarm": // New case for toggling RestrictArmor
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: /nvus treefarm <true|false>");
return true;
}
handleToggleConfigCommand(sender, "TreeFarm", args[1]);
break;
case "autosell": // New case for toggling RestrictArmor
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: /nvus autosell <true|false>");
return true;
}
handleToggleConfigCommand(sender, "AutoSell", args[1]);
break;
case "sellall": // New case for toggling RestrictArmor
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: /nvus sellall <true|false>");
return true;
}
handleToggleConfigCommand(sender, "SellAll", args[1]);
break;
default:
sender.sendMessage(ChatColor.RED + "Invalid command. Use /nvus for help.");
return true;
@ -116,6 +137,7 @@ public class CommandListener implements CommandExecutor {
configManager.reloadConfig("config.yml");
configManager.reloadConfig("auto_switch.yml");
configManager.reloadConfig("banned_items.yml");
configManager.reloadConfig("item_prices.yml");
sender.sendMessage(ChatColor.GREEN + "Configuration files reloaded.");
}

View File

@ -14,6 +14,7 @@ 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;
import me.nvus.nvus_prison_setup.AutoSell.Listeners.AutoSellListener;
// Database
import me.nvus.nvus_prison_setup.Database.DatabaseManager;
// Gangs
@ -72,6 +73,8 @@ public final class PrisonSetup extends JavaPlugin {
configManager.saveDefaultConfig("auto_switch.yml");
configManager.saveDefaultConfig("item_prices.yml");
configManager.loadItemPricesConfig(this.getDataFolder());
// 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()));
@ -79,8 +82,6 @@ public final class PrisonSetup extends JavaPlugin {
return;
}
//FileConfiguration config = configManager.getConfig("config.yml");
// Register Event Listeners
getServer().getPluginManager().registerEvents(new PlayerSpawn(configManager), this);
getServer().getPluginManager().registerEvents(new PlayerArmor(configManager), this);
@ -96,15 +97,20 @@ 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);
this.getCommand("setprice").setExecutor(sellManager);
// If they are true, register the commands.
if (autoSellEnabled) {
// Register the autosell command.
this.getCommand("autosell").setExecutor(sellManager);
// Register AutoSell Listener then too!
getServer().getPluginManager().registerEvents(new AutoSellListener(sellManager), this);
}
// If they are true, register the commands.
if (sellAllEnabled) {
@ -120,7 +126,7 @@ public final class PrisonSetup extends JavaPlugin {
getServer().getPluginManager().registerEvents(toolDamageListener, this);
// TreeFarm Boolean Check
if (configManager.getBoolean("config.yml", "TreeFarm", false)) {
if (configManager.getBoolean("config.yml", "TreeFarm", true)) {
getServer().getPluginManager().registerEvents(new TreeFarmListener(this), this);
}
@ -130,13 +136,27 @@ public final class PrisonSetup extends JavaPlugin {
// UPDATE CHECKER
new UpdateChecker(this, 12345).getVersion(version -> {
if (!this.getDescription().getVersion().equals(version)) {
getLogger().info("There is a new update available for NVus Prison Setup! Grab it from SpigotMC here: https://www.spigotmc.org/resources/nvus-prison-setup.115441/");
getLogger().info(" ");
getLogger().info("=====================================================");
getLogger().info(" ");
getLogger().info("An update for NVus Prison Lite is available! Grab it from:");
getLogger().info("SpigotMC: https://www.spigotmc.org/resources/nvus-prison-setup.115441/");
getLogger().info("BuiltByBit: https://builtbybit.com/resources/nvus-prison-lite.40514/");
getLogger().info(" ");
getLogger().info("=====================================================");
getLogger().info(" ");
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.isOp() || player.hasPermission("nvus.admin")) {
player.sendMessage(ChatColor.RED + " ");
player.sendMessage(ChatColor.RED + "=====================================================");
player.sendMessage(ChatColor.YELLOW + "An update for NVus Prison Setup is available! Grab it from SpigotMC here: https://www.spigotmc.org/resources/nvus-prison-setup.115441/");
player.sendMessage(ChatColor.RED + " ");
player.sendMessage(ChatColor.YELLOW + "An update for NVus Prison Lite is available! Grab it from:");
player.sendMessage(ChatColor.YELLOW + "SpigotMC: https://www.spigotmc.org/resources/nvus-prison-setup.115441/");
player.sendMessage(ChatColor.YELLOW + "BuiltByBit: https://builtbybit.com/resources/nvus-prison-lite.40514/");
player.sendMessage(ChatColor.RED + " ");
player.sendMessage(ChatColor.RED + "=====================================================");
player.sendMessage(ChatColor.RED + " ");
}
}
}, 20L * 60);

View File

@ -17,12 +17,22 @@ public class TreeFarmListener implements Listener {
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
// Check if the block being broken is a sapling and protect it unless player has admin permission
if (block.getType() == Material.OAK_SAPLING || block.getType() == Material.SPRUCE_SAPLING || block.getType() == Material.BIRCH_SAPLING || block.getType() == Material.JUNGLE_SAPLING || block.getType() == Material.ACACIA_SAPLING || block.getType() == Material.DARK_OAK_SAPLING) {
if (!event.getPlayer().hasPermission("nvus.admin")) {
event.setCancelled(true);
event.getPlayer().sendMessage("§cYou do not have permission to break saplings!");
return;
}
}
// Check if the block being broken is a log
if (TreeType.isLog(block.getType())) {
// Get the block directly beneath the log block
Block blockBelow = block.getRelative(0, -1, 0);
// Check if the block below is either grass or dirt, indicating this could be the base of a tree
if (blockBelow.getType() == Material.GRASS_BLOCK || blockBelow.getType() == Material.DIRT) {
if (blockBelow.getType() == Material.GRASS_BLOCK || blockBelow.getType() == Material.DIRT || blockBelow.getType() == Material.PODZOL || blockBelow.getType() == Material.MYCELIUM || (blockBelow.getType() == Material.SAND)) {
// Check if the player has the required permission
if (event.getPlayer().hasPermission("nvus.prisoner")) {
event.setCancelled(true); // Cancel the event to handle block breaking manually

View File

@ -6,21 +6,21 @@
#======================================================================================#
Prices:
- Material: OAK_PLANKS
OAK_PLANKS:
Sell: 1.0
- Material: SPRUCE_PLANKS
SPRUCE_PLANKS:
Sell: 1.0
- Material: BIRCH_PLANKS
BIRCH_PLANKS:
Sell: 1.0
- Material: JUNGLE_PLANKS
JUNGLE_PLANKS:
Sell: 1.0
- Material: ACACIA_PLANKS
ACACIA_PLANKS:
Sell: 1.0
- Material: DARK_OAK_PLANKS
Dark_OAK_PLANKS:
Sell: 1.0
- Material: Cobblestone
COBBLESTONE:
Sell: 1.0
- Material: Stone
STONE:
Sell: 2.0
- Material: Coal
Sell: 0.50
COAL:
Sell: 1.5

View File

@ -27,6 +27,8 @@ commands:
/nvus prisonerarmor <true|false> - Toggles giving prisoners armor on join.
/nvus restrictarmor <true|false> - Toggles the restriction on changing prisoner armor.
/nvus tooldamage <true|false> - Toggle if prisoner tools receive damage. FALSE = No Damage.
/nvus autosell <true|false> - Toggle if prisoners can auto toggle auto selling of items as they are mined.
/nvus sellall <true|false> - Toggle if prisoners can use /sellall to manually sell items form inventory.
aliases: [prison]
gang:
@ -53,3 +55,19 @@ commands:
usage: |
/autosell - Toggle auto selling all eligible items in your inventory.
aliases: [ automaticsell ]
setprice:
description: Set the price of the block being held in item_prices.yml.
usage: |
/setprice <price> - Set the price of the block being held in item_prices.yml.
aliases: [ setblockprice ]
permissions:
nvus.admin:
description: Allows access to NVus Prison admin commands.
default: op
nvus.gang.create:
description: Allows creating a gang.
default: true
nvus.prisoner:
description: Allows access to NVus Prison prisoner features ie AutoSwitch,AutoSell,Restricting Armor etc.
default: true