v1.0.0 Release - Asset Push as well.
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 1.9 MiB |
Before Width: | Height: | Size: 343 KiB After Width: | Height: | Size: 343 KiB |
Before Width: | Height: | Size: 496 KiB After Width: | Height: | Size: 579 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 25 KiB |
2
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.8</version>
|
<version>1.0.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>NVus_PrisonSetup</name>
|
<name>NVus_PrisonSetup</name>
|
||||||
|
|
|
@ -22,17 +22,6 @@ public class AutoSellListener implements Listener {
|
||||||
if (!player.hasPermission("nvus.prisoner") || !sellManager.isAutoSellEnabled(player)) {
|
if (!player.hasPermission("nvus.prisoner") || !sellManager.isAutoSellEnabled(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sellManager.sellItems(player);
|
||||||
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
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.Configs.ConfigManager;
|
||||||
import me.nvus.nvus_prison_setup.PrisonSetup;
|
import me.nvus.nvus_prison_setup.PrisonSetup;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -26,7 +30,6 @@ public class SellManager implements CommandExecutor {
|
||||||
loadPrices();
|
loadPrices();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage("Only players can use this command.");
|
sender.sendMessage("Only players can use this command.");
|
||||||
|
@ -35,6 +38,26 @@ public class SellManager implements CommandExecutor {
|
||||||
|
|
||||||
Player player = (Player) sender;
|
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()) {
|
switch (command.getName().toLowerCase()) {
|
||||||
case "autosell":
|
case "autosell":
|
||||||
toggleAutoSell(player);
|
toggleAutoSell(player);
|
||||||
|
@ -49,23 +72,58 @@ public class SellManager implements CommandExecutor {
|
||||||
|
|
||||||
private void loadPrices() {
|
private void loadPrices() {
|
||||||
FileConfiguration itemPricesConfig = configManager.getItemPricesConfig();
|
FileConfiguration itemPricesConfig = configManager.getItemPricesConfig();
|
||||||
for (String key : itemPricesConfig.getConfigurationSection("Prices").getKeys(false)) {
|
ConfigurationSection pricesSection = itemPricesConfig.getConfigurationSection("Prices");
|
||||||
String materialName = itemPricesConfig.getString("Prices." + key + ".Material");
|
if (pricesSection == null) {
|
||||||
Material material = Material.matchMaterial(materialName);
|
System.err.println("Prices section not found in item_prices.yml");
|
||||||
double price = itemPricesConfig.getDouble("Prices." + key + ".Sell");
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String key : pricesSection.getKeys(false)) {
|
||||||
|
Material material = Material.matchMaterial(key);
|
||||||
|
double price = pricesSection.getDouble(key + ".Sell");
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
prices.put(material, price);
|
prices.put(material, price);
|
||||||
} else {
|
} 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) {
|
private void toggleAutoSell(Player player) {
|
||||||
boolean currentStatus = autoSellStatus.getOrDefault(player.getUniqueId(), false);
|
boolean currentStatus = autoSellStatus.getOrDefault(player.getUniqueId(), false);
|
||||||
autoSellStatus.put(player.getUniqueId(), !currentStatus); // Toggle the status
|
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) {
|
public boolean isAutoSellEnabled(Player player) {
|
||||||
|
@ -75,45 +133,67 @@ public class SellManager implements CommandExecutor {
|
||||||
|
|
||||||
public void sellItems(Player player) {
|
public void sellItems(Player player) {
|
||||||
if (!player.hasPermission("nvus.prisoner")) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double totalSale = 0;
|
Map<Material, Integer> soldItems = new HashMap<>();
|
||||||
ItemStack[] items = player.getInventory().getContents();
|
|
||||||
for (ItemStack item : items) {
|
// Loop through the player's inventory and collect sellable items
|
||||||
|
for (ItemStack item : player.getInventory().getContents()) {
|
||||||
if (item != null && prices.containsKey(item.getType())) {
|
if (item != null && prices.containsKey(item.getType())) {
|
||||||
double pricePerItem = prices.get(item.getType());
|
soldItems.merge(item.getType(), item.getAmount(), Integer::sum);
|
||||||
totalSale += pricePerItem * item.getAmount();
|
|
||||||
player.getInventory().remove(item);
|
player.getInventory().remove(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalSale > 0) {
|
// Sell the items that we just removed from their inventory
|
||||||
giveMoney(player, totalSale);
|
soldItems.forEach((material, quantity) -> {
|
||||||
// We send the message of amount give in the giveMoney method now!!
|
double totalSale = prices.get(material) * quantity;
|
||||||
//player.sendMessage(String.format("Sold items for $%.2f", totalSale));
|
giveMoney(player, material, quantity, totalSale);
|
||||||
} else {
|
});
|
||||||
player.sendMessage("No eligible items to sell.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void giveMoney(Player player, double amount) {
|
private void giveMoney(Player player, Material material, int quantity, double amount) {
|
||||||
Economy economy = PrisonSetup.getEconomy();
|
Economy economy = PrisonSetup.getEconomy();
|
||||||
economy.depositPlayer(player, amount);
|
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;
|
// public void sellItems(Player player) {
|
||||||
}
|
// if (!player.hasPermission("nvus.prisoner")) {
|
||||||
double price = getPrice(material) * amount;
|
// player.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format("&c&lYou do not have permission to use this command.")));
|
||||||
if (price > 0) {
|
// //player.sendMessage("You do not have permission to use this command.");
|
||||||
giveMoney(player, price);
|
// return;
|
||||||
player.sendMessage(String.format("Sold %s x%d for $%.2f", material.toString(), amount, price));
|
// }
|
||||||
}
|
//
|
||||||
}
|
// 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) {
|
public boolean isSellable(Material material) {
|
||||||
return prices.containsKey(material);
|
return prices.containsKey(material);
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private final JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
|
@ -86,6 +88,41 @@ public class ConfigManager {
|
||||||
itemPricesConfig = YamlConfiguration.loadConfiguration(file);
|
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() {
|
public FileConfiguration getItemPricesConfig() {
|
||||||
return itemPricesConfig;
|
return itemPricesConfig;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,17 +31,23 @@ public class SettingsMenu implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openSettingsMenu(Player player) {
|
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");
|
FileConfiguration config = configManager.getConfig("config.yml");
|
||||||
|
|
||||||
inv.setItem(0, createToggleItem(Material.LEATHER_CHESTPLATE, "Toggle PrisonerArmor", config.getBoolean("PrisonerArmor", true)));
|
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(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(3, createToggleItem(Material.HOPPER, "Toggle AutoPickup", config.getBoolean("AutoPickup", false)));
|
||||||
inv.setItem(4, createToggleItem(Material.LEVER, "Toggle AutoSwitch", config.getBoolean("AutoSwitch", 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(8, createToggleItem(Material.BOOK, "Reload Configs", false));
|
||||||
inv.setItem(7, 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);
|
player.openInventory(inv);
|
||||||
}
|
}
|
||||||
|
@ -94,6 +100,12 @@ public class SettingsMenu implements Listener {
|
||||||
toggleConfigOption(player, "AutoPickup");
|
toggleConfigOption(player, "AutoPickup");
|
||||||
} else if (displayName.contains("Toggle AutoSwitch")) {
|
} else if (displayName.contains("Toggle AutoSwitch")) {
|
||||||
toggleConfigOption(player, "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")) {
|
} else if (displayName.contains("Reload Configs")) {
|
||||||
reloadConfigs(player);
|
reloadConfigs(player);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,27 @@ public class CommandListener implements CommandExecutor {
|
||||||
}
|
}
|
||||||
handleToggleConfigCommand(sender, "ToolDamage", args[1]);
|
handleToggleConfigCommand(sender, "ToolDamage", args[1]);
|
||||||
break;
|
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:
|
default:
|
||||||
sender.sendMessage(ChatColor.RED + "Invalid command. Use /nvus for help.");
|
sender.sendMessage(ChatColor.RED + "Invalid command. Use /nvus for help.");
|
||||||
return true;
|
return true;
|
||||||
|
@ -116,6 +137,7 @@ public class CommandListener implements CommandExecutor {
|
||||||
configManager.reloadConfig("config.yml");
|
configManager.reloadConfig("config.yml");
|
||||||
configManager.reloadConfig("auto_switch.yml");
|
configManager.reloadConfig("auto_switch.yml");
|
||||||
configManager.reloadConfig("banned_items.yml");
|
configManager.reloadConfig("banned_items.yml");
|
||||||
|
configManager.reloadConfig("item_prices.yml");
|
||||||
sender.sendMessage(ChatColor.GREEN + "Configuration files reloaded.");
|
sender.sendMessage(ChatColor.GREEN + "Configuration files reloaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.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;
|
import me.nvus.nvus_prison_setup.AutoSell.SellManager;
|
||||||
|
import me.nvus.nvus_prison_setup.AutoSell.Listeners.AutoSellListener;
|
||||||
// Database
|
// Database
|
||||||
import me.nvus.nvus_prison_setup.Database.DatabaseManager;
|
import me.nvus.nvus_prison_setup.Database.DatabaseManager;
|
||||||
// Gangs
|
// Gangs
|
||||||
|
@ -72,6 +73,8 @@ public final class PrisonSetup extends JavaPlugin {
|
||||||
configManager.saveDefaultConfig("auto_switch.yml");
|
configManager.saveDefaultConfig("auto_switch.yml");
|
||||||
configManager.saveDefaultConfig("item_prices.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!
|
// Check if Vault is installed, it's a hard dependency so disable plugin if not installed!
|
||||||
if (!setupEconomy()) {
|
if (!setupEconomy()) {
|
||||||
getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FileConfiguration config = configManager.getConfig("config.yml");
|
|
||||||
|
|
||||||
// Register Event Listeners
|
// Register Event Listeners
|
||||||
getServer().getPluginManager().registerEvents(new PlayerSpawn(configManager), this);
|
getServer().getPluginManager().registerEvents(new PlayerSpawn(configManager), this);
|
||||||
getServer().getPluginManager().registerEvents(new PlayerArmor(configManager), this);
|
getServer().getPluginManager().registerEvents(new PlayerArmor(configManager), this);
|
||||||
|
@ -96,15 +97,20 @@ public final class PrisonSetup extends JavaPlugin {
|
||||||
new GangPlaceholders(gangManager).register();
|
new GangPlaceholders(gangManager).register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Register the Auto Sell and Sell All Listeners
|
// Register the Auto Sell and Sell All Listeners
|
||||||
boolean autoSellEnabled = configManager.getConfig("config.yml").getBoolean("AutoSell", true);
|
boolean autoSellEnabled = configManager.getConfig("config.yml").getBoolean("AutoSell", true);
|
||||||
boolean sellAllEnabled = configManager.getConfig("config.yml").getBoolean("SellAll", true);
|
boolean sellAllEnabled = configManager.getConfig("config.yml").getBoolean("SellAll", true);
|
||||||
SellManager sellManager = new SellManager(configManager);
|
SellManager sellManager = new SellManager(configManager);
|
||||||
|
this.getCommand("setprice").setExecutor(sellManager);
|
||||||
|
|
||||||
// If they are true, register the commands.
|
// If they are true, register the commands.
|
||||||
if (autoSellEnabled) {
|
if (autoSellEnabled) {
|
||||||
// Register the autosell command.
|
// Register the autosell command.
|
||||||
this.getCommand("autosell").setExecutor(sellManager);
|
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 they are true, register the commands.
|
||||||
if (sellAllEnabled) {
|
if (sellAllEnabled) {
|
||||||
|
@ -120,7 +126,7 @@ public final class PrisonSetup extends JavaPlugin {
|
||||||
getServer().getPluginManager().registerEvents(toolDamageListener, this);
|
getServer().getPluginManager().registerEvents(toolDamageListener, this);
|
||||||
|
|
||||||
// TreeFarm Boolean Check
|
// TreeFarm Boolean Check
|
||||||
if (configManager.getBoolean("config.yml", "TreeFarm", false)) {
|
if (configManager.getBoolean("config.yml", "TreeFarm", true)) {
|
||||||
getServer().getPluginManager().registerEvents(new TreeFarmListener(this), this);
|
getServer().getPluginManager().registerEvents(new TreeFarmListener(this), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,13 +136,27 @@ public final class PrisonSetup extends JavaPlugin {
|
||||||
// UPDATE CHECKER
|
// UPDATE CHECKER
|
||||||
new UpdateChecker(this, 12345).getVersion(version -> {
|
new UpdateChecker(this, 12345).getVersion(version -> {
|
||||||
if (!this.getDescription().getVersion().equals(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, () -> {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (player.isOp() || player.hasPermission("nvus.admin")) {
|
if (player.isOp() || player.hasPermission("nvus.admin")) {
|
||||||
|
player.sendMessage(ChatColor.RED + " ");
|
||||||
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 + "=====================================================");
|
||||||
|
player.sendMessage(ChatColor.RED + " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 20L * 60);
|
}, 20L * 60);
|
||||||
|
|
|
@ -17,12 +17,22 @@ public class TreeFarmListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
Block block = event.getBlock();
|
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
|
// Check if the block being broken is a log
|
||||||
if (TreeType.isLog(block.getType())) {
|
if (TreeType.isLog(block.getType())) {
|
||||||
// Get the block directly beneath the log block
|
// Get the block directly beneath the log block
|
||||||
Block blockBelow = block.getRelative(0, -1, 0);
|
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
|
// 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
|
// Check if the player has the required permission
|
||||||
if (event.getPlayer().hasPermission("nvus.prisoner")) {
|
if (event.getPlayer().hasPermission("nvus.prisoner")) {
|
||||||
event.setCancelled(true); // Cancel the event to handle block breaking manually
|
event.setCancelled(true); // Cancel the event to handle block breaking manually
|
||||||
|
|
|
@ -6,21 +6,21 @@
|
||||||
#======================================================================================#
|
#======================================================================================#
|
||||||
|
|
||||||
Prices:
|
Prices:
|
||||||
- Material: OAK_PLANKS
|
OAK_PLANKS:
|
||||||
Sell: 1.0
|
Sell: 1.0
|
||||||
- Material: SPRUCE_PLANKS
|
SPRUCE_PLANKS:
|
||||||
Sell: 1.0
|
Sell: 1.0
|
||||||
- Material: BIRCH_PLANKS
|
BIRCH_PLANKS:
|
||||||
Sell: 1.0
|
Sell: 1.0
|
||||||
- Material: JUNGLE_PLANKS
|
JUNGLE_PLANKS:
|
||||||
Sell: 1.0
|
Sell: 1.0
|
||||||
- Material: ACACIA_PLANKS
|
ACACIA_PLANKS:
|
||||||
Sell: 1.0
|
Sell: 1.0
|
||||||
- Material: DARK_OAK_PLANKS
|
Dark_OAK_PLANKS:
|
||||||
Sell: 1.0
|
Sell: 1.0
|
||||||
- Material: Cobblestone
|
COBBLESTONE:
|
||||||
Sell: 1.0
|
Sell: 1.0
|
||||||
- Material: Stone
|
STONE:
|
||||||
Sell: 2.0
|
Sell: 2.0
|
||||||
- Material: Coal
|
COAL:
|
||||||
Sell: 0.50
|
Sell: 1.5
|
|
@ -27,6 +27,8 @@ commands:
|
||||||
/nvus prisonerarmor <true|false> - Toggles giving prisoners armor on join.
|
/nvus prisonerarmor <true|false> - Toggles giving prisoners armor on join.
|
||||||
/nvus restrictarmor <true|false> - Toggles the restriction on changing prisoner armor.
|
/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 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]
|
aliases: [prison]
|
||||||
|
|
||||||
gang:
|
gang:
|
||||||
|
@ -53,3 +55,19 @@ commands:
|
||||||
usage: |
|
usage: |
|
||||||
/autosell - Toggle auto selling all eligible items in your inventory.
|
/autosell - Toggle auto selling all eligible items in your inventory.
|
||||||
aliases: [ automaticsell ]
|
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
|