v0.8.1 - Added ToolDamage, moved and renamed PrisonerTools from auto_switch.yml to config.yml. Added ToolDamage and reload config toggles to /nvus menu
This commit is contained in:
parent
900e2ca0ed
commit
a9f4e80094
|
@ -1,16 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" dumb="true">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea/copilot/chatSessions" />
|
||||
</content>
|
||||
</component>
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>PAPER</platformType>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>me.NVus</groupId>
|
||||
<artifactId>NVus_Prison_Setup</artifactId>
|
||||
<version>0.7.5</version>
|
||||
<version>0.8.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>NVus_PrisonSetup</name>
|
||||
|
|
|
@ -31,14 +31,17 @@ public class SettingsMenu implements Listener {
|
|||
}
|
||||
|
||||
public void openSettingsMenu(Player player) {
|
||||
Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GREEN + "Settings Menu");
|
||||
Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GREEN + "NVus Prison Settings");
|
||||
FileConfiguration config = configManager.getConfig("config.yml");
|
||||
|
||||
inv.setItem(0, createToggleItem(Material.LEATHER_CHESTPLATE, "Toggle PrisonerArmor", config.getBoolean("PrisonerArmor", false)));
|
||||
inv.setItem(1, createToggleItem(Material.IRON_DOOR, "Toggle RestrictArmor", config.getBoolean("RestrictArmor", false)));
|
||||
inv.setItem(3, createToggleItem(Material.HOPPER, "Toggle AutoPickup", config.getBoolean("AutoPickup", false)));
|
||||
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(7, createItem(Material.BOOK, ChatColor.GREEN + "Reload Configs"));
|
||||
|
||||
inv.setItem(6, createToggleItem(Material.IRON_PICKAXE, "Toggle ToolDamage", config.getBoolean("ToolDamage", false)));
|
||||
inv.setItem(7, createToggleItem(Material.BOOK, "Reload Configs", false));
|
||||
|
||||
player.openInventory(inv);
|
||||
}
|
||||
|
@ -46,22 +49,30 @@ public class SettingsMenu implements Listener {
|
|||
private ItemStack createToggleItem(Material material, String name, boolean isEnabled) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.GREEN + name + ": " + (isEnabled ? ChatColor.BLUE + "Enabled" : ChatColor.RED + "Disabled"));
|
||||
// Non-Toggable Items
|
||||
if (name.equals("Reload Configs")) {
|
||||
meta.setDisplayName(ChatColor.GREEN + name);
|
||||
}
|
||||
// Toggable Items
|
||||
else {
|
||||
meta.setDisplayName(ChatColor.GREEN + name + ": " + (isEnabled ? ChatColor.BLUE + "Enabled" : ChatColor.RED + "Disabled"));
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
private ItemStack createItem(Material material, String name) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
// private ItemStack createItem(Material material, String name) {
|
||||
// ItemStack item = new ItemStack(material);
|
||||
// ItemMeta meta = item.getItemMeta();
|
||||
// meta.setDisplayName(name);
|
||||
// item.setItemMeta(meta);
|
||||
// return item;
|
||||
// }
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!event.getView().getTitle().equals(ChatColor.DARK_GREEN + "Settings Menu")) return;
|
||||
if (!event.getView().getTitle().equals(ChatColor.DARK_GREEN + "NVus Prison Settings")) return;
|
||||
event.setCancelled(true);
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
@ -95,6 +106,7 @@ public class SettingsMenu implements Listener {
|
|||
} else if (displayName.contains("Reload Configs")) {
|
||||
reloadConfigs(player);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
playerTasks.put(playerUUID, task);
|
||||
|
@ -125,5 +137,6 @@ public class SettingsMenu implements Listener {
|
|||
configManager.reloadConfig("banned_items.yml");
|
||||
configManager.saveConfig("config.yml");
|
||||
player.sendMessage(ChatColor.GREEN + "Configuration files reloaded.");
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,15 +6,17 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ToolSwitchListener implements Listener {
|
||||
private ConfigManager configManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public ToolSwitchListener(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
|
@ -22,59 +24,49 @@ public class ToolSwitchListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
|
||||
if (event.getAction() != org.bukkit.event.block.Action.LEFT_CLICK_BLOCK || event.getClickedBlock() == null) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
FileConfiguration config = configManager.getConfig("config.yml");
|
||||
if (!config.getBoolean("AutoSwitch", true)) return;
|
||||
if (!player.hasPermission("nvus.prisoner")) return;
|
||||
|
||||
FileConfiguration autoSwitchConfig = configManager.getConfig("auto_switch.yml");
|
||||
Material blockType = event.getClickedBlock().getType();
|
||||
|
||||
// Determine the correct tool based on block type, pulled from auto_switch.yml
|
||||
Material bestTool = determineBestTool(blockType, player, autoSwitchConfig);
|
||||
if (!player.hasPermission("nvus.prisoner") || !config.getBoolean("AutoSwitch", true)) return;
|
||||
|
||||
Material blockType = event.getClickedBlock().getType();
|
||||
Material bestTool = determineBestToolForBlock(blockType, player, config, autoSwitchConfig);
|
||||
if (bestTool != null) {
|
||||
switchToTool(player, bestTool);
|
||||
}
|
||||
}
|
||||
|
||||
private Material determineBestTool(Material blockType, Player player, FileConfiguration autoSwitchConfig) {
|
||||
List<String> autoSwitchTools = autoSwitchConfig.getStringList("AutoSwitchTools");
|
||||
List<Material> pickaxeMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("PickaxeMaterials"));
|
||||
List<Material> axeMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("AxeMaterials"));
|
||||
List<Material> shovelMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("ShovelMaterials"));
|
||||
private Material determineBestToolForBlock(Material blockType, Player player, FileConfiguration config, FileConfiguration autoSwitchConfig) {
|
||||
List<Material> prisonerTools = config.getStringList("PrisonerTools").stream()
|
||||
.map(Material::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Material requiredTool = null;
|
||||
if (pickaxeMaterials.contains(blockType)) {
|
||||
requiredTool = Material.valueOf("IRON_PICKAXE");
|
||||
} else if (axeMaterials.contains(blockType)) {
|
||||
requiredTool = Material.valueOf("IRON_AXE");
|
||||
} else if (shovelMaterials.contains(blockType)) {
|
||||
requiredTool = Material.valueOf("IRON_SHOVEL");
|
||||
}
|
||||
|
||||
// Ensure the tool is in the list of tools that should auto switch
|
||||
if (requiredTool != null && autoSwitchTools.contains(requiredTool.name())) {
|
||||
return findBestToolInInventory(requiredTool, player);
|
||||
}
|
||||
Map<Material, List<Material>> toolEffectivenessMap = new HashMap<>();
|
||||
for (Material tool : prisonerTools) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Material findBestToolInInventory(Material toolType, Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
for (ItemStack item : inventory.getContents()) {
|
||||
if (item != null && item.getType() == toolType) {
|
||||
return toolType; // Further logic can be added to select the best tool if multiple are found
|
||||
if (tool.toString().endsWith("_PICKAXE")) {
|
||||
toolEffectivenessMap.put(tool, convertStringListToMaterial(autoSwitchConfig.getStringList("PickaxeMaterials")));
|
||||
} else if (tool.toString().endsWith("_AXE")) {
|
||||
toolEffectivenessMap.put(tool, convertStringListToMaterial(autoSwitchConfig.getStringList("AxeMaterials")));
|
||||
} else if (tool.toString().endsWith("_SHOVEL")) {
|
||||
toolEffectivenessMap.put(tool, convertStringListToMaterial(autoSwitchConfig.getStringList("ShovelMaterials")));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
for (Material tool : prisonerTools) {
|
||||
List<Material> effectiveBlocks = toolEffectivenessMap.getOrDefault(tool, List.of());
|
||||
if (effectiveBlocks.contains(blockType) && player.getInventory().contains(tool)) {
|
||||
return tool;
|
||||
}
|
||||
}
|
||||
|
||||
return null; // No suitable tool found
|
||||
}
|
||||
|
||||
private List<Material> convertStringListToMaterial(List<String> stringList) {
|
||||
return stringList.stream().map(Material::valueOf).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void switchToTool(Player player, Material tool) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
@ -83,4 +75,8 @@ public class ToolSwitchListener implements Listener {
|
|||
inventory.setHeldItemSlot(toolSlot);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Material> convertStringListToMaterial(List<String> stringList) {
|
||||
return stringList.stream().map(Material::valueOf).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
package me.nvus.nvus_prison_setup;
|
||||
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
import me.nvus.nvus_prison_setup.Listeners.CommandListener;
|
||||
import me.nvus.nvus_prison_setup.Listeners.*;
|
||||
import me.nvus.nvus_prison_setup.Configs.SettingsMenu;
|
||||
import me.nvus.nvus_prison_setup.Listeners.PlayerArmor;
|
||||
import me.nvus.nvus_prison_setup.Listeners.PlayerItems;
|
||||
import me.nvus.nvus_prison_setup.Listeners.PlayerSpawn;
|
||||
import me.nvus.nvus_prison_setup.Listeners.BlockListener;
|
||||
import me.nvus.nvus_prison_setup.Listeners.ToolSwitchListener;
|
||||
import me.nvus.nvus_prison_setup.Updater.UpdateChecker;
|
||||
import me.nvus.nvus_prison_setup.Listeners.ToolDamageListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public final class PrisonSetup extends JavaPlugin {
|
||||
|
||||
|
@ -28,6 +30,9 @@ public final class PrisonSetup extends JavaPlugin {
|
|||
configManager.saveDefaultConfig("banned_items.yml");
|
||||
configManager.saveDefaultConfig("auto_switch.yml");
|
||||
|
||||
// Update config file(s) when new updates come out and they need replaced
|
||||
checkAndUpdateConfigs();
|
||||
|
||||
// Register event listeners
|
||||
getServer().getPluginManager().registerEvents(new PlayerSpawn(configManager), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerArmor(configManager), this);
|
||||
|
@ -38,6 +43,10 @@ public final class PrisonSetup extends JavaPlugin {
|
|||
//new SettingsMenu(this, configManager);
|
||||
getServer().getPluginManager().registerEvents(new SettingsMenu(this, configManager), this);
|
||||
|
||||
// Tool Damage
|
||||
ToolDamageListener toolDamageListener = new ToolDamageListener(configManager);
|
||||
getServer().getPluginManager().registerEvents(toolDamageListener, this);
|
||||
|
||||
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&a&lNVus Prison Setup has been successfully enabled!"));
|
||||
|
||||
new UpdateChecker(this, 12345).getVersion(version -> {
|
||||
|
@ -73,4 +82,42 @@ public final class PrisonSetup extends JavaPlugin {
|
|||
public ConfigManager getConfigManager() {
|
||||
return configManager;
|
||||
}
|
||||
|
||||
private void checkAndUpdateConfigs() {
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
saveResource("config.yml", false);
|
||||
saveResource("auto_switch.yml", false);
|
||||
return;
|
||||
}
|
||||
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
String configVersion = config.getString("ConfigVersion", "0"); // Default to "0" if not found
|
||||
if (!"1.0".equals(configVersion)) {
|
||||
backupAndReplaceConfig("config.yml");
|
||||
backupAndReplaceConfig("auto_switch.yml");
|
||||
|
||||
// After backing up and copying new ones, you might want to reload these configs into your ConfigManager
|
||||
// assuming you have such a method in your ConfigManager
|
||||
getConfigManager().reloadConfig("config.yml");
|
||||
getConfigManager().reloadConfig("auto_switch.yml");
|
||||
}
|
||||
}
|
||||
|
||||
private void backupAndReplaceConfig(String fileName) {
|
||||
File configFile = new File(getDataFolder(), fileName);
|
||||
File backupFile = new File(getDataFolder(), fileName + ".BACKUP");
|
||||
|
||||
// Backup the old file
|
||||
try {
|
||||
Files.move(configFile.toPath(), backupFile.toPath());
|
||||
} catch (IOException e) {
|
||||
getLogger().warning("Could not backup " + fileName + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
// Copy new file from resources
|
||||
saveResource(fileName, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,14 +5,6 @@
|
|||
# Discord: FNGnation.net/discord #
|
||||
#======================================================================================#
|
||||
|
||||
# If AutoSwitch = true in the config.yml, what tools should the prisoner auto switch to?
|
||||
# I'd always keep some kind of pickaxe, axe and shovel in here even if you don't want to auto switch to them.
|
||||
# Just eliminate the Materials list for that tool(s) to disable that particular tool. Just to prevent conflicts/errors.
|
||||
AutoSwitchTools:
|
||||
- IRON_PICKAXE
|
||||
- IRON_AXE
|
||||
- IRON_SHOVEL
|
||||
|
||||
# What blocks/ores should cause the prisoner to auto switch to a pickaxe?
|
||||
PickaxeMaterials:
|
||||
- STONE
|
||||
|
|
|
@ -20,3 +20,15 @@ AutoSwitch: true
|
|||
PrisonerArmor: true
|
||||
# Should prisoners be able to remove/change their default prisoner armor?
|
||||
RestrictArmor: true
|
||||
|
||||
# What tools are considered Prisoner Tools? These are used for the ToolDamage toggle and for auto switching feature!
|
||||
# See auto_switch.yml to set up which blocks trigger the auto switch to these tools.
|
||||
PrisonerTools:
|
||||
- IRON_PICKAXE
|
||||
- IRON_AXE
|
||||
- IRON_SHOVEL
|
||||
# When set to FALSE it will prevent Prisoner Tools from receiving damage when mining etc.
|
||||
ToolDamage: false
|
||||
|
||||
|
||||
ConfigVersion: 1.0 # Do not change this value!
|
||||
|
|
|
@ -2,7 +2,7 @@ name: NVus_PrisonSetup
|
|||
version: '${project.version}'
|
||||
main: me.nvus.nvus_prison_setup.PrisonSetup
|
||||
api-version: '1.20'
|
||||
prefix: NVus Prison
|
||||
prefix: NVus Prison Lite
|
||||
authors: [never2nv]
|
||||
website: https://FNGnation.net
|
||||
|
||||
|
|
Loading…
Reference in New Issue