From f023285992ea02f46dadb5697b39a250d342843d Mon Sep 17 00:00:00 2001 From: "Larry (Wolfieheart)" Date: Mon, 12 Sep 2022 21:06:36 +0200 Subject: [PATCH] [CORE] Add in Custom Item Name Support - Closes #118 (#122) * [CORE] Add in Functionality for Custom Names * [CORE] Bump to 1.19.2-37.3 * [CORE] Bump to 1.19.2-37.3 * [CORE] Bump PlotSquared to 6.9.4 * [CORE] Optimize Imports * [CORE] Fix Bugs in Implementation Part 1 - Objests.RequireNonNull * [CORE] Fix Bug in Checking String Comparison * [CORE] Fix Build Compliation due to incorrect variable * [CORE] Bump to 1.19.2-38 - After Debug Fixes. Signed-off-by: Wolfieheart Signed-off-by: Wolfieheart --- pom.xml | 6 ++-- .../ArmorStandEditorPlugin.java | 30 ++++++++++++++++--- src/main/resources/config.yml | 10 +++++-- src/main/resources/plugin.yml | 2 +- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index e25ae5af..f8fbe29d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.rypofalem.armorstandeditor armorstandeditor jar - 1.19.2-37.2 + 1.19.2-37.3 armorstandeditor http://maven.apache.org @@ -90,14 +90,14 @@ com.plotsquared PlotSquared-Core - 6.9.3 + 6.9.4 provided com.plotsquared PlotSquared-Bukkit - 6.9.3 + 6.9.4 provided diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java b/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java index 4b648d07..65dd151d 100644 --- a/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java +++ b/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java @@ -20,9 +20,7 @@ package io.github.rypofalem.armorstandeditor; import io.github.rypofalem.armorstandeditor.language.Language; - import com.jeff_media.updatechecker.*; - import io.github.rypofalem.armorstandeditor.Metrics.*; import org.bukkit.Bukkit; @@ -71,11 +69,14 @@ public class ArmorStandEditorPlugin extends JavaPlugin{ int editToolData = Integer.MIN_VALUE; boolean requireSneaking = false; + boolean requireToolName = false; + String editToolName = null; boolean requireToolLore = false; String editToolLore = null; boolean allowCustomModelData = false; Integer customModelDataInt = Integer.MIN_VALUE; + boolean debug = false; //weather or not to broadcast messages via print(String message) double coarseRot; double fineRot; @@ -192,6 +193,13 @@ public void onEnable(){ //ArmorStandVisibility Node armorStandVisibility = getConfig().getBoolean("armorStandVisibility", true); + //Do we require a custom tool name? + requireToolName = getConfig().getBoolean("requireToolName", false); + if(requireToolName){ + editToolName = getConfig().getString("toolName", null); + if(editToolName != null) editToolName = ChatColor.translateAlternateColorCodes('&', editToolName); + } + //Is there NBT Required for the tool requireToolData = getConfig().getBoolean("requireToolData", false); @@ -370,14 +378,24 @@ public boolean isEditTool(ItemStack itemStk){ } } + if(requireToolName && editToolName != null){ + if(!itemStk.hasItemMeta()) { return false; } + + //Get the name of the Edit Tool - If Null, return false + String itemName = Objects.requireNonNull(itemStk.getItemMeta()).getDisplayName(); + + //If the name of the Edit Tool is not the Name specified in Config then Return false + if(!itemName.equals(editToolName)) { return false; } + + } + if(requireToolLore && editToolLore != null){ //If the ItemStack does not have Metadata then we return false if(!itemStk.hasItemMeta()) { return false; } //Get the lore of the Item and if it is null - Return False - List itemLore = Objects.requireNonNull(itemStk.getItemMeta()).getLore(); //Ignore warnings this gives. Will be fixed in the future - if (itemLore == null){ return false; } + List itemLore = Objects.requireNonNull(itemStk.getItemMeta()).getLore(); //If the Item does not have Lore - Return False boolean hasTheItemLore = itemStk.getItemMeta().hasLore(); @@ -467,6 +485,10 @@ private void getMetrics(){ //ArmorStandInvis Config metrics.addCustomChart(new SimplePie("itemframe_invisibility_used", () -> getConfig().getString("invisibleItemFrames"))); + //TODO: Add tracking to see who is using Custom Naming in BStats - AKA Remove this soon TM + //metrics.addCustomChart(new SimplePie("custom_toolname_enabled", () -> getConfig().getString("requireToolName"))); + + } public NamespacedKey getIconKey() { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b191dd27..68cdf88b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,7 +3,7 @@ #-----------------------------# #DO NOT CHANGE THIS - CHANGES AUTOMATICALLY PER UPDATE -version: "1.19.2-37.2" +version: "1.19.2-38" #----------- LANGUAGE #Name of the language file you wish to use @@ -25,12 +25,18 @@ tool: FLINT requireToolData: false toolData: 0 +#(Optional) data that the plugin looks for to identify the name of the Edit Tool. Useful for Public Servers that do not want +#normal use of Flint to be impacted. +requireToolName: false +toolName: Example Name here + #(Optional) The first "Lore" entry that the plugin looks for to identify the edit tool. requireToolLore: false toolLore: Let's get dangerous #(Optional) Allow the use of CustomModelData - NOTE: This looks at the editTool set by Config #and at the Int set here to know what to set. + #Also please if you are using this, ensure that you also give people the ability asedit.give in #order to allow them to change their edit #tool for the right Custom Model Data @@ -62,4 +68,4 @@ requireSneaking: false #(Optional) Glowing Item Frames Support for Item Frames in 1.17 - WILL NOT WORK IN 1.16 OR LOWER AND 1.17.1 OR HIGHER #If true, players can make itemFrames glow by right-clicking with a Glow Ink Sac -glowingItemFrame: true \ No newline at end of file +glowingItemFrame: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index dfa073aa..45563200 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: ArmorStandEditor main: io.github.rypofalem.armorstandeditor.ArmorStandEditorPlugin -version: 1.19.2-37.2 +version: 1.19.2-38 api-version: "1.13" website: https://www.spigotmc.org/resources/94503/ author: Wolfstorm