From 4b9ab74e6a9f2c04a2f9ce779f04b94141e7c553 Mon Sep 17 00:00:00 2001 From: WildInterloper <156627888+WildInterloper@users.noreply.github.com> Date: Sun, 10 Mar 2024 12:44:23 -0400 Subject: [PATCH] README.MD update, pushed ToolDamageListener --- README.MD | 52 ++++++++++++++++--- .../Listeners/ToolDamageListener.java | 49 +++++++++++++++++ 2 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 src/main/java/me/nvus/nvus_prison_setup/Listeners/ToolDamageListener.java diff --git a/README.MD b/README.MD index 45bb72b..708cb20 100644 --- a/README.MD +++ b/README.MD @@ -1,8 +1,44 @@ -A useful plugin for Minecraft prison servers.\ -Stable release! It implements the following features, so far: -- Equips orange leather armor to all prisoners upon connecting to the server and upon respawn. -- It generates a banned_items.yml file which can be configured to ban certain items for prisoners. -- It prevents the modificaiton of prisoner armor (they cannot equip/un-equip the default prisoner armor). -- It prevents banned items from being used, equipped in hand, transferred to storage or even crafted by prisoners. -- To enable the prisoner features players who are considered prisoners should have the permission **nvus.prisoner**. -- Just in case, all non-prisoners and players who are no longer considered a prisoner should have the permission nvus.prisoner **NEGATED**. \ No newline at end of file + +## 🔗 Useful Stuff +Author(s): [@never2nv](https://git.fngnation.net/never2nv) +| [Documentation](https://www.spigotmc.org/resources/nvus-prison-lite.115441/field?field=documentation) + +![portfolio](https://img.shields.io/badge/my_portfolio-000?style=for-the-badge&logo=ko-fi&logoColor=white) + +# NVus Prison Lite + +Useful features for Minecraft Prison Servers + + + + +## Features +![NVus Prison Lite Info](https://git.fngnation.net/never2nv/NVus_Prison_Lite/raw/branch/main/assets/plugin_info.png) + +Currently, the plugin implements the following features, so far: + +- Equips orange leather armor to all prisoners. It also prevents prisoners from changing or equipping any other armor. + +- It generates a banned_items.yml file which can be configured to ban certain items for prisoners. Banned items cannot be used, equipped in hand, transferred to storage or even crafted by prisoners. + +- Adds a toggle in the config.yml to turn on/off AutoPickup for prisoners to automatically pickup mined resource drops (if they have enough room in their inventory for the drop(s)). + +- Adds a toggle in the config.yml for AutoSwitch, when set to true it allows server admins to customize the auto_switch.yml which will list what type of tools prisoners can auto switch to and what materials will trigger the auto switch to certain tools. Mining stone then prisoners hit clay? It will auto switch to the proper tool, if they have it in their inventory! + +- You can now toggle PrisonerArmor and RestrictArmor options in the main config.yml file. Turning off PrisonerArmor will of course not give any prisoners the default orange leather armor. Turning off RestrictArmor will allow prisoners to change/remove their armor + . +- PrisonerTools: You can select which tool(s) are considered "Prisoner Tools" these tools are used for the auto switch and tool damage features. + +- You can toggle ToolDamage. Setting to FALSE will prevent prisoner tools from being damaged when prisoners use them for mining etc! + +- Commands for admins to use in-game to toggle certain features on/off, reload the configs and check plugin version. + +- /nvus menu will now open an easy GUI Menu to toggle options on/off + +- Armor is still craftable by prisoners. We felt this to be a cool roleplay element like allowing prisoners to craft and sell armor in the prison shops. Almost like the age ol' prisoners creating license plates! HAHA. If you don't like this you can always add various types of armor to the banned_items.yml file ie IRON_HELMET, DIAMOND_CHESTPLATE etc + + +## Documentation + +[Documentation](https://www.spigotmc.org/resources/nvus-prison-lite.115441/field?field=documentation) + diff --git a/src/main/java/me/nvus/nvus_prison_setup/Listeners/ToolDamageListener.java b/src/main/java/me/nvus/nvus_prison_setup/Listeners/ToolDamageListener.java new file mode 100644 index 0000000..be78821 --- /dev/null +++ b/src/main/java/me/nvus/nvus_prison_setup/Listeners/ToolDamageListener.java @@ -0,0 +1,49 @@ +package me.nvus.nvus_prison_setup.Listeners; + +import me.nvus.nvus_prison_setup.Configs.ConfigManager; +import org.bukkit.ChatColor; +import org.bukkit.Material; +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.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.List; +import java.util.stream.Collectors; + +public class ToolDamageListener implements Listener { + private final ConfigManager configManager; + + public ToolDamageListener(ConfigManager configManager) { + this.configManager = configManager; + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + ItemStack itemInHand = player.getInventory().getItemInMainHand(); + + if (!(itemInHand.getItemMeta() instanceof Damageable)) return; + + FileConfiguration config = configManager.getConfig("config.yml"); + boolean toolDamageEnabled = config.getBoolean("ToolDamage", true); + List prisonerTools = config.getStringList("PrisonerTools").stream().map(Material::valueOf).collect(Collectors.toList()); + + if (!toolDamageEnabled && prisonerTools.contains(itemInHand.getType())) { + Damageable itemMeta = (Damageable) itemInHand.getItemMeta(); + + itemMeta.setDamage(0); + + itemInHand.setItemMeta((ItemMeta) itemMeta); + + // DEBUGGGGGGGGGGGG + //player.sendMessage(ChatColor.GREEN + "Your tool's durability was preserved."); + } + } + + +}