From b0803df7c5236a71d92b076555b68669c9980f29 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 23 Sep 2019 16:18:36 -0700 Subject: [PATCH] Fixing a few more things --- .../gmail/nossr50/config/ConfigConstants.java | 138 +++++++++--------- .../config/hocon/SerializedConfigLoader.java | 8 +- .../nossr50/datatypes/player/McMMOPlayer.java | 2 +- .../nossr50/datatypes/skills/ToolType.java | 3 +- .../gmail/nossr50/util/nbt/NBTManager.java | 12 +- 5 files changed, 85 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/ConfigConstants.java b/src/main/java/com/gmail/nossr50/config/ConfigConstants.java index da7ffa118..781758965 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigConstants.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigConstants.java @@ -1,5 +1,7 @@ package com.gmail.nossr50.config; +import com.gmail.nossr50.mcMMO; + import java.io.File; import java.util.ArrayList; @@ -40,72 +42,72 @@ public class ConfigConstants { EXAMPLE_BLACKLIST_WORLDS_LIST_DEFAULT.add(EXAMPLE_BLACKLIST_WORLDS[2]); } -// /** -// * Return the data folder for mcMMO -// * -// * @return the File for the data folder used by mcMMO -// */ -// public static File getDataFolder() { -// return pluginRef.getDataFolder(); -// } -// -// public static File getConfigFolder() { -// return new File(getDataFolder(), FOLDER_NAME_CONFIG); -// } -// -// public static File getDefaultsFolder() { -// return new File(getConfigFolder().getAbsolutePath(), FOLDER_NAME_DEFAULTS); -// } -// -// public static File getDefaultsConfigFolder() { -// return new File(getDefaultsFolder().getAbsolutePath(), FOLDER_NAME_CONFIG); -// } -// -// public static File getDefaultsSkillFolder() { -// return new File(getDefaultsConfigFolder().getAbsolutePath(), FOLDER_NAME_SKILLS); -// } -// -// public static File getDefaultsXPFolder() { -// return new File(getDefaultsConfigFolder().getAbsolutePath(), FOLDER_NAME_EXPERIENCE); -// } -// -// public static File getConfigSkillFolder() { -// return new File(getConfigFolder().getAbsolutePath(), FOLDER_NAME_SKILLS); -// } -// -// public static File getConfigXPFolder() { -// return new File(getConfigFolder().getAbsolutePath(), FOLDER_NAME_EXPERIENCE); -// } -// -// /** -// * Creates all directories used by mcMMO config files -// */ -// public static void makeAllConfigDirectories() { -// /* CONFIG DIRECTORY */ -// -// if (!getConfigFolder().exists()) -// getConfigFolder().mkdirs(); -// -// /* DEFAULT DIRECTORIES */ -// -// if (!getDefaultsFolder().exists()) -// getDefaultsFolder().mkdirs(); -// -// if (!getDefaultsConfigFolder().exists()) -// getDefaultsConfigFolder().mkdirs(); -// -// if (!getDefaultsSkillFolder().exists()) -// getDefaultsSkillFolder().mkdirs(); -// -// if (!getDefaultsXPFolder().exists()) -// getDefaultsXPFolder().mkdirs(); -// -// /* CONFIG SUBDIRECTORIES */ -// -// if (!getConfigSkillFolder().exists()) -// getConfigSkillFolder().mkdirs(); -// -// if (!getConfigXPFolder().exists()) -// getConfigXPFolder().mkdirs(); -// } + /** + * Return the data folder for mcMMO + * + * @return the File for the data folder used by mcMMO + */ + public static File getDataFolder(mcMMO pluginRef) { + return pluginRef.getDataFolder(); + } + + public static File getConfigFolder(mcMMO pluginRef) { + return new File(getDataFolder(pluginRef), FOLDER_NAME_CONFIG); + } + + public static File getDefaultsFolder(mcMMO pluginRef) { + return new File(getConfigFolder(pluginRef).getAbsolutePath(), FOLDER_NAME_DEFAULTS); + } + + public static File getDefaultsConfigFolder(mcMMO pluginRef) { + return new File(getDefaultsFolder(pluginRef).getAbsolutePath(), FOLDER_NAME_CONFIG); + } + + public static File getDefaultsSkillFolder(mcMMO pluginRef) { + return new File(getDefaultsConfigFolder(pluginRef).getAbsolutePath(), FOLDER_NAME_SKILLS); + } + + public static File getDefaultsXPFolder(mcMMO pluginRef) { + return new File(getDefaultsConfigFolder(pluginRef).getAbsolutePath(), FOLDER_NAME_EXPERIENCE); + } + + public static File getConfigSkillFolder(mcMMO pluginRef) { + return new File(getConfigFolder(pluginRef).getAbsolutePath(), FOLDER_NAME_SKILLS); + } + + public static File getConfigXPFolder(mcMMO pluginRef) { + return new File(getConfigFolder(pluginRef).getAbsolutePath(), FOLDER_NAME_EXPERIENCE); + } + + /** + * Creates all directories used by mcMMO config files + */ + public static void makeAllConfigDirectories(mcMMO pluginRef) { + /* CONFIG DIRECTORY */ + + if (!getConfigFolder(pluginRef).exists()) + getConfigFolder(pluginRef).mkdirs(); + + /* DEFAULT DIRECTORIES */ + + if (!getDefaultsFolder(pluginRef).exists()) + getDefaultsFolder(pluginRef).mkdirs(); + + if (!getDefaultsConfigFolder(pluginRef).exists()) + getDefaultsConfigFolder(pluginRef).mkdirs(); + + if (!getDefaultsSkillFolder(pluginRef).exists()) + getDefaultsSkillFolder(pluginRef).mkdirs(); + + if (!getDefaultsXPFolder(pluginRef).exists()) + getDefaultsXPFolder(pluginRef).mkdirs(); + + /* CONFIG SUBDIRECTORIES */ + + if (!getConfigSkillFolder(pluginRef).exists()) + getConfigSkillFolder(pluginRef).mkdirs(); + + if (!getConfigXPFolder(pluginRef).exists()) + getConfigXPFolder(pluginRef).mkdirs(); + } } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/SerializedConfigLoader.java b/src/main/java/com/gmail/nossr50/config/hocon/SerializedConfigLoader.java index fb6c9cb6c..8e21e633d 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/SerializedConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/SerializedConfigLoader.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.config.hocon; import com.gmail.nossr50.config.ConfigConstants; +import com.gmail.nossr50.mcMMO; import ninja.leaping.configurate.ConfigurationOptions; import ninja.leaping.configurate.ValueType; import ninja.leaping.configurate.commented.CommentedConfigurationNode; @@ -52,6 +53,8 @@ import java.util.Objects; * @param the class type of the config */ public class SerializedConfigLoader { + private final mcMMO pluginRef; + private static final String CONFIG_HEADER = "Configuration files are now in the HOCON file format!\n" + "\nHOCON is a lot less strict than YAML, so don't worry about the number of spaces and such!\n" + "\nIt is recommended that you use a nice text editor to view and edit these files" + @@ -80,7 +83,8 @@ public class SerializedConfigLoader { */ private ObjectMapper.BoundInstance configMapper; - public SerializedConfigLoader(Class clazz, String fileName, String rootNodeName, SerializedConfigLoader parent) { + public SerializedConfigLoader(mcMMO pluginRef, Class clazz, String fileName, String rootNodeName, SerializedConfigLoader parent) { + this.pluginRef = pluginRef; ROOT_NODE_ADDRESS = rootNodeName; this.parent = parent; this.path = getPathFromFileName(fileName); @@ -119,7 +123,7 @@ public class SerializedConfigLoader { } private Path getPathFromFileName(String fileName) { - File configFile = new File(ConfigConstants.getConfigFolder(), fileName); + File configFile = new File(ConfigConstants.getConfigFolder(pluginRef), fileName); return configFile.toPath(); } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 291ee020a..9a93bf7c0 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -986,7 +986,7 @@ public class McMMOPlayer { * Woodcutting & Axes need to be treated differently. * Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action */ - if (tool.inHand(inHand) && !getToolPreparationMode(tool)) { + if (tool.inHand(pluginRef, inHand) && !getToolPreparationMode(tool)) { if (primarySkillType != PrimarySkillType.WOODCUTTING && primarySkillType != PrimarySkillType.AXES) { int timeRemaining = calculateTimeRemaining(ability); diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/ToolType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/ToolType.java index 36c98b845..8821fda46 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/ToolType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/ToolType.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.datatypes.skills; +import com.gmail.nossr50.mcMMO; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -33,7 +34,7 @@ public enum ToolType { * @param itemStack The item to check * @return true if the item is the right type, false otherwise */ - public boolean inHand(ItemStack itemStack) { + public boolean inHand(mcMMO pluginRef, ItemStack itemStack) { switch (this) { case AXE: return pluginRef.getItemTools().isAxe(itemStack); diff --git a/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index 4418da4a8..99e2e6b4f 100644 --- a/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -2,12 +2,12 @@ package com.gmail.nossr50.util.nbt; import com.gmail.nossr50.mcMMO; -import net.minecraft.server.v1_13_R2.NBTBase; -import net.minecraft.server.v1_13_R2.NBTList; -import net.minecraft.server.v1_13_R2.NBTTagCompound; +import net.minecraft.server.v1_14_R1.NBTBase; +import net.minecraft.server.v1_14_R1.NBTList; +import net.minecraft.server.v1_14_R1.NBTTagCompound; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_13_R2.util.CraftNBTTagConfigSerializer; +import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer; import org.bukkit.inventory.ItemStack; public class NBTManager { @@ -31,7 +31,7 @@ public class NBTManager { public NBTTagCompound getNBT(ItemStack itemStack) { Bukkit.broadcastMessage("Checking NBT for "+itemStack.toString()); - net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); + net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound rootTag = nmsItemStack.getTag(); return rootTag; }