diff --git a/src/main/java/org/shanerx/tradeshop/data/config/Message.java b/src/main/java/org/shanerx/tradeshop/data/config/Message.java index d745b7ce..6ad1156b 100644 --- a/src/main/java/org/shanerx/tradeshop/data/config/Message.java +++ b/src/main/java/org/shanerx/tradeshop/data/config/Message.java @@ -320,7 +320,7 @@ public final void sendItemMultiLineMessage(Player player, Map> entry : itemsToFill.entrySet()) { Pattern pattern = Pattern.compile(MULTILINEREGEX.replace("&V&", entry.getKey().toString())); @@ -367,7 +367,7 @@ public final void sendUserEditMultiLineMessage(Player player, Map> entry : valuesToFill.entrySet()) { Pattern pattern = Pattern.compile(MULTILINEREGEX.replace("&V&", entry.getKey().toString())); diff --git a/src/main/java/org/shanerx/tradeshop/data/config/Setting.java b/src/main/java/org/shanerx/tradeshop/data/config/Setting.java index ceeac4af..24ff83c0 100644 --- a/src/main/java/org/shanerx/tradeshop/data/config/Setting.java +++ b/src/main/java/org/shanerx/tradeshop/data/config/Setting.java @@ -47,16 +47,19 @@ public enum Setting { // PostComment " " adds single newline below setting and "\n" adds 2 newlines below // PreComment `/n ` will have a new comment marker added after a sufficient space for proper formatting - CONFIG_VERSION(SettingSection.NONE, "config-version", 1.3), + CONFIG_VERSION(SettingSection.NONE, "config-version", 1.4), // System Options DATA_STORAGE_TYPE(SettingSection.SYSTEM_OPTIONS, "data-storage-type", "FLATFILE"), MAX_SAVE_THREADS(SettingSection.SYSTEM_OPTIONS, "max-save-threads", 3), - ENABLE_DEBUG(SettingSection.SYSTEM_OPTIONS, "enable-debug", 0), CHECK_UPDATES(SettingSection.SYSTEM_OPTIONS, "check-updates", true), ALLOW_METRICS(SettingSection.SYSTEM_OPTIONS, "allow-metrics", true), UNLIMITED_ADMIN(SettingSection.SYSTEM_OPTIONS, "unlimited-admin", false), + // ^ Debug Settings + DEBUG_TO_CONSOLE(SettingSection.DEBUG_SETTINGS, "debug-to-console", Collections.singletonList("Disabled")), + DEBUG_TO_FILE(SettingSection.DEBUG_SETTINGS, "debug-to-file", Collections.singletonList("Disabled")), + // ^ Logging ENABLE_TRANSACTION_LOGGING(SettingSection.TRANSACTION_LOGGING_OPTIONS, "enable-transaction-logging", true), OUTPUT_TYPE(SettingSection.TRANSACTION_LOGGING_OPTIONS, "output-type", "TSV"), @@ -156,12 +159,7 @@ public static Setting findSetting(String search) { static boolean upgrade() { double version = CONFIG_VERSION.getDouble(); Set hasUpgraded = new HashSet<>(); // Uses this instead of a boolean to later replace below ifs with boolean return methods... - ConfigManager configManager = PLUGIN.getSettingManager(); - - // 2.2.2 Changed enable debug from true/false to integer - if (!configManager.getConfig().isInt(ENABLE_DEBUG.path)) { - ENABLE_DEBUG.clearSetting(); - } + ConfigManager configManager = PLUGIN.getVarManager().getSettingManager(); // 2.2.2 Better Sorted/potentially commented config if (version < 1.1) { @@ -280,6 +278,17 @@ static boolean upgrade() { version = 1.3; } + if (version < 1.4) { + + String oldKey = "system-options.enable-debug"; + if (configManager.getConfig().contains(oldKey)) { + configManager.getConfig().set(oldKey, null); + hasUpgraded.add(true); + } + + version = 1.4; + } + CONFIG_VERSION.setValue(version); return hasUpgraded.contains(true); @@ -380,7 +389,11 @@ public void setMappedValue(String subKey, Object obj) { } public void clearSetting() { - PLUGIN.getSettingManager().getConfig().set(getPath(), null); + setValue(null); + } + + public void resetSetting() { + setValue(getDefaultValue()); } public Object getSetting() { diff --git a/src/main/java/org/shanerx/tradeshop/data/config/SettingSection.java b/src/main/java/org/shanerx/tradeshop/data/config/SettingSection.java index ad903355..9991b41e 100644 --- a/src/main/java/org/shanerx/tradeshop/data/config/SettingSection.java +++ b/src/main/java/org/shanerx/tradeshop/data/config/SettingSection.java @@ -36,8 +36,9 @@ public enum SettingSection { NONE(0, ""), SYSTEM_OPTIONS(1, "system-options"), + DEBUG_SETTINGS(50, SYSTEM_OPTIONS, "debug-settings"), - TRANSACTION_LOGGING_OPTIONS(50, SYSTEM_OPTIONS, "transaction-logging-options"), + TRANSACTION_LOGGING_OPTIONS(51, SYSTEM_OPTIONS, "transaction-logging-options"), LANGUAGE_OPTIONS(2, "language-options"), GLOBAL_OPTIONS(3, "global-options"), diff --git a/src/main/java/org/shanerx/tradeshop/data/storage/DataStorage.java b/src/main/java/org/shanerx/tradeshop/data/storage/DataStorage.java index 3cfec64c..83f6e22a 100644 --- a/src/main/java/org/shanerx/tradeshop/data/storage/DataStorage.java +++ b/src/main/java/org/shanerx/tradeshop/data/storage/DataStorage.java @@ -58,7 +58,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; @@ -233,7 +232,7 @@ public int getShopCountInWorld(World world) { File folder = new File(TradeShop.getPlugin().getDataFolder().getAbsolutePath() + File.separator + "Data" + File.separator + worldName); if (folder.exists() && folder.listFiles() != null) { for (File file : folder.listFiles()) { - if (file.getName().contains(worldName)) + if (file.getName().contains(worldName) && file.getName().endsWith(".json")) count.addAndGet(new JsonShopData(ShopChunk.deserialize(file.getName().replace(".json", ""))).size()); } } @@ -287,7 +286,7 @@ protected ShopConfiguration getShopData(Chunk chunk) { return getShopData(new ShopChunk(chunk)); } - private Map chunkDataCache = new HashMap<>(); + private final Map chunkDataCache = new HashMap<>(); protected ShopConfiguration getShopData(ShopChunk chunk) { if (dataType == DataType.FLATFILE) { String serializedChunk = chunk.serialize(); diff --git a/src/main/java/org/shanerx/tradeshop/data/storage/Json/JsonConfiguration.java b/src/main/java/org/shanerx/tradeshop/data/storage/Json/JsonConfiguration.java index 05611be1..731f79c3 100644 --- a/src/main/java/org/shanerx/tradeshop/data/storage/Json/JsonConfiguration.java +++ b/src/main/java/org/shanerx/tradeshop/data/storage/Json/JsonConfiguration.java @@ -66,7 +66,7 @@ protected JsonConfiguration(String folderFromData, String fileName) { } // Caching File objects for synchronized(File) {} blocks - private static Map fileCache = new HashMap<>(); + private static final Map fileCache = new HashMap<>(); public static File getFile(String folderFromData, String fileName) { String path = getPath(folderFromData).getPath() + File.separator + fileName + ".json"; @@ -124,6 +124,7 @@ public static File[] getFilesInFolder(String folderFromData) { protected void loadFile() { try { + PLUGIN.getVarManager().getDebugger().log(String.join("\n", Files.readAllLines(file.toPath())), DebugLevels.JSON_LOADING, "JsonConfiguration#loadFile() - " + file.getName()); jsonObj = JsonParser.parseReader(new FileReader(file)).getAsJsonObject(); } catch (FileNotFoundException e) { @@ -134,6 +135,8 @@ protected void loadFile() { PLUGIN.getLogger().log(Level.SEVERE, "Could not load " + file.getName() + " file due to malformed Json! \n Please send the .err file with the same name to the TradeShop Devs. \n\nTradeShop will now disable, please remove/fix any err files before restarting the plugin.", e); jsonSyntaxError(file, e); + } catch (IOException e) { + throw new RuntimeException(e); } } diff --git a/src/main/java/org/shanerx/tradeshop/data/storage/Json/JsonShopData.java b/src/main/java/org/shanerx/tradeshop/data/storage/Json/JsonShopData.java index a883715d..aa7e0863 100644 --- a/src/main/java/org/shanerx/tradeshop/data/storage/Json/JsonShopData.java +++ b/src/main/java/org/shanerx/tradeshop/data/storage/Json/JsonShopData.java @@ -39,6 +39,8 @@ import org.shanerx.tradeshop.shop.Shop; import org.shanerx.tradeshop.shoplocation.ShopChunk; import org.shanerx.tradeshop.shoplocation.ShopLocation; +import org.shanerx.tradeshop.utils.debug.Debug; +import org.shanerx.tradeshop.utils.debug.DebugLevels; import org.shanerx.tradeshop.utils.gsonprocessing.GsonProcessor; import java.io.File; @@ -48,7 +50,11 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardOpenOption; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListSet; import java.util.logging.Level; @@ -273,8 +279,10 @@ public void run() { } int expectedLength = str.getBytes(StandardCharsets.UTF_8).length; + Debug debug = Debug.findDebugger(); try { + debug.log(str, DebugLevels.JSON_SAVING, "JsonShopData^SaveThreadMaster#run().try-1 - " + file.getName()); if (file.exists()) { bak.delete(); mjf.delete(); // Delete previous malformed and bak files to prevent conflicts with new ones. Could potentially rename with a counter if we really want to see a lot of malformed files. @@ -297,6 +305,7 @@ public void run() { } fileBytes = chan.write(byteBuff); + debug.log(new String(byteBuff.asCharBuffer().array()), DebugLevels.JSON_SAVING, "JsonShopData^SaveThreadMaster#run().try-1_post-verify - " + file.getName()); chan.force(true); chan.close(); diff --git a/src/main/java/org/shanerx/tradeshop/utils/debug/Debug.java b/src/main/java/org/shanerx/tradeshop/utils/debug/Debug.java index c28557b1..2e6cee44 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/debug/Debug.java +++ b/src/main/java/org/shanerx/tradeshop/utils/debug/Debug.java @@ -28,58 +28,139 @@ import org.bukkit.Bukkit; import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.data.config.Setting; +import org.shanerx.tradeshop.utils.objects.ObjectHolder; +import java.util.Collections; +import java.util.HashSet; +import java.util.Optional; import java.util.logging.Level; -public class Debug { +public abstract class Debug { - private final String PREFIX = "[TradeShop Debug%level%] "; - private int decimalDebugLevel; - private String binaryDebugLevel; + protected final String PREFIX; - public Debug() { + protected HashSet debugToConsole = new HashSet<>(), + debugToFile = new HashSet<>(); + + public Debug(int version) { + PREFIX = "[TradeShop Debug%V%%level%] ".replace("%V%", "V" + version); reload(); } public static Debug findDebugger() { final TradeShop plugin = ((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop")); - if (plugin != null) { - return plugin.getDebugger(); + if (plugin == null) return null; + + Debug debugger = plugin.getVarManager().getDebugger(); + if (debugger != null) return debugger; + + return newDebug(); + } + + /** + * @return true if the debug should be V3 + */ + public static Optional detectDebugVersion() { + Optional v3 = Optional.empty(); + + ObjectHolder debugToConsole = new ObjectHolder<>(Setting.DEBUG_TO_CONSOLE.getSetting()), + debugToFile = new ObjectHolder<>(Setting.DEBUG_TO_FILE.getSetting()); + + if (debugToConsole.isNull()) { + Setting.DEBUG_TO_CONSOLE.resetSetting(); + debugToConsole = new ObjectHolder<>(Setting.DEBUG_TO_CONSOLE.getSetting()); + } + + if (debugToFile.isNull()) { + Setting.DEBUG_TO_FILE.resetSetting(); + debugToFile = new ObjectHolder<>(Setting.DEBUG_TO_FILE.getSetting()); + } + + + boolean debugToConsoleAsList = debugToConsole.asStringList().orElse(Collections.emptyList()).isEmpty(), + debugToFileAsList = debugToFile.isList() && debugToFile.asStringList().orElse(Collections.emptyList()).isEmpty(), + debugToConsoleAsInt = debugToConsole.isInteger() && debugToConsole.asInteger() == 0, + debugToFileAsInt = debugToFile.isInteger() && debugToFile.asInteger() == 0; + + if (debugToConsole.isInteger() && debugToFile.isInteger()) { + v3 = Optional.of(true); + } else if (debugToConsole.isList() && debugToFile.isList()) { + v3 = Optional.of(true); + } else if (debugToConsoleAsList || debugToFileAsList || debugToConsoleAsInt || debugToFileAsInt) { + if (debugToConsoleAsInt || debugToConsoleAsList) { + v3 = Optional.of(debugToFile.isList()); + } else { + v3 = Optional.of(debugToConsole.isList()); + } + } + return v3; + } + + public static Debug newDebug() { + Optional debugVersion = detectDebugVersion(); + if (debugVersion.isPresent()) { + return debugVersion.get() ? new DebugV3() : new DebugV2(); } else { - return new Debug(); + Setting.DEBUG_TO_CONSOLE.resetSetting(); + Setting.DEBUG_TO_FILE.resetSetting(); + return new DebugV3(); } } public void reload() { - decimalDebugLevel = Setting.ENABLE_DEBUG.getInt(); - if (decimalDebugLevel < 0) { - decimalDebugLevel = DebugLevels.maxValue(); + if (loadDebugLevel(Setting.DEBUG_TO_CONSOLE, debugToConsole)) { + Bukkit.getLogger().log(Level.INFO, PREFIX.replace("%level%", "") + "Console Debugging enabled!"); + Bukkit.getLogger().log(Level.INFO, PREFIX.replace("%level%", "") + "Enabled debuggers: " + debugToConsole.toString()); } - StringBuilder sb = new StringBuilder(Integer.toBinaryString(decimalDebugLevel)); - while (sb.length() < DebugLevels.levels()) - sb.insert(0, 0); - - binaryDebugLevel = sb.reverse().toString(); + if (loadDebugLevel(Setting.DEBUG_TO_FILE, debugToFile)) { + Bukkit.getLogger().log(Level.INFO, PREFIX.replace("%level%", "") + "File Debugging enabled!"); + Bukkit.getLogger().log(Level.INFO, PREFIX.replace("%level%", "") + "Enabled debuggers: " + debugToFile.toString()); + } + } + /** + * @return true if debugging is enabled + * @implNote This method is called by {@link #reload()} to load the debug level. It should add enums from DebugLevels to the {@link HashSet} specified by debugDestination to enable debugging for each item. + * @var debugDestination The {@link HashSet} to add the debug levels to + * @var settingToReadFrom The {@link Setting} to read the debug level from + */ + public abstract boolean loadDebugLevel(Setting settingToReadFrom, HashSet debugDestination); - if (decimalDebugLevel > 0) { - Bukkit.getLogger().log(Level.INFO, PREFIX.replace("%level%", "") + "Debugging enabled!"); - Bukkit.getLogger().log(Level.INFO, PREFIX.replace("%level%", "") + "Decimal Debug level: " + decimalDebugLevel); - Bukkit.getLogger().log(Level.INFO, PREFIX.replace("%level%", "") + "Debug levels: " + binaryDebugLevel); - } + public String getFormattedPrefix(DebugLevels debugLevel) { + return PREFIX.replace("%level%", debugLevel.getPrefix()); } public void log(String message, DebugLevels level) { - if (level.getPosition() > 0 && binaryDebugLevel.charAt(level.getPosition() - 1) == '1') { - Bukkit.getLogger().log(level.getLogLevel(), PREFIX.replace("%level%", level.getPrefix()) + message); + log(message, level, null); + } + + public void log(String message, DebugLevels level, String positionalNote) { + StringBuilder messageBuilder = new StringBuilder(); + + if (debugToConsole.contains(level)) { + message = PREFIX.replace("%level%", level.getPrefix()) + message; } else if (level == DebugLevels.DISABLED) { - Bukkit.getLogger().log(level.getLogLevel(), PREFIX.replace(" Debug%level%", "") + message); + message = PREFIX.replaceAll("( Debug.%level%)", "") + message; } else if (level.getPosition() < 0) { - Bukkit.getLogger().log(level.getLogLevel(), PREFIX.replace("%level%", level.getPrefix()) + message); + message = PREFIX.replace("%level%", level.getPrefix()) + message; } + + if (positionalNote != null && !positionalNote.isEmpty()) { + messageBuilder.append("{ ").append(level.getPrefix()).append(" }\n"); + } + + messageBuilder.append(message); + + if (debugToConsole.contains(level)) logToConsole(level.getLogLevel(), messageBuilder.toString()); + if (debugToFile.contains(level)) logToFile(level.getLogLevel(), messageBuilder.toString()); } - public String getFormattedPrefix(DebugLevels debugLevel) { - return PREFIX.replace("%level%", debugLevel.getPrefix()); + private void logToConsole(Level level, String message) { + Bukkit.getLogger().log(level, message); + } + + private void logToFile(Level level, String message) { + Bukkit.getLogger().log(level, "\n----- LOGTOFILE -----" + message + "\n----- END LOGTOFILE -----\n"); //TODO: Add file logging } -} \ No newline at end of file + +} diff --git a/src/main/java/org/shanerx/tradeshop/utils/debug/DebugLevels.java b/src/main/java/org/shanerx/tradeshop/utils/debug/DebugLevels.java index 250b3fbb..0b7a6a00 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/debug/DebugLevels.java +++ b/src/main/java/org/shanerx/tradeshop/utils/debug/DebugLevels.java @@ -25,6 +25,7 @@ package org.shanerx.tradeshop.utils.debug; +import java.util.Optional; import java.util.logging.Level; public enum DebugLevels { @@ -46,8 +47,9 @@ public enum DebugLevels { SQLITE(12, Level.INFO), // 2048 GSON(13, Level.INFO), // 4096 DATA_VERIFICATION(14, Level.INFO), // 8192 - FIND_COMMAND(15, Level.INFO) // 16384 - + FIND_COMMAND(15, Level.INFO), // 16384 + JSON_SAVING(16, Level.INFO), // 32768 + JSON_LOADING(17, Level.INFO) // 65536 ; @@ -88,4 +90,16 @@ public String getPrefix() { return " - " + name(); } + public static Optional match(String desiredLevel) { + Optional ret = Optional.empty(); + for (DebugLevels level : values()) { + if (level.name().replaceAll("\\w", "").equalsIgnoreCase(desiredLevel)) { + ret = Optional.of(level); + break; + } + } + + return ret; + } + } \ No newline at end of file diff --git a/src/main/java/org/shanerx/tradeshop/utils/debug/DebugV2.java b/src/main/java/org/shanerx/tradeshop/utils/debug/DebugV2.java new file mode 100644 index 00000000..d895dc1e --- /dev/null +++ b/src/main/java/org/shanerx/tradeshop/utils/debug/DebugV2.java @@ -0,0 +1,58 @@ +/* + * + * Copyright (c) 2016-2023 + * SparklingComet @ http://shanerx.org + * KillerOfPie @ http://killerofpie.github.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * NOTICE: All modifications made by others to the source code belong + * to the respective contributor. No contributor should be held liable for + * any damages of any kind, whether be material or moral, which were + * caused by their contribution(s) to the project. See the full License for more information. + * + */ + +package org.shanerx.tradeshop.utils.debug; + +import org.shanerx.tradeshop.data.config.Setting; + +import java.util.HashSet; + +public class DebugV2 extends Debug { + + public DebugV2() { + super(2); + } + + @Override + public boolean loadDebugLevel(Setting settingToReadFrom, HashSet debugDestination) { + int decimalDebugLevel = settingToReadFrom.getInt(); + if (decimalDebugLevel < 0) { + decimalDebugLevel = DebugLevels.maxValue(); + } + StringBuilder sb = new StringBuilder(Integer.toBinaryString(decimalDebugLevel)); + while (sb.length() < DebugLevels.levels()) + sb.insert(0, 0); + + String binaryDebugLevel = sb.reverse().toString(); + + for (DebugLevels level : DebugLevels.values()) { + if (level.getPosition() - 1 < binaryDebugLevel.length() && binaryDebugLevel.charAt(level.getPosition()) == '1') { + debugDestination.add(level); + } + } + + return !debugDestination.isEmpty(); + } +} \ No newline at end of file diff --git a/src/main/java/org/shanerx/tradeshop/utils/debug/DebugV3.java b/src/main/java/org/shanerx/tradeshop/utils/debug/DebugV3.java new file mode 100644 index 00000000..b84bebc9 --- /dev/null +++ b/src/main/java/org/shanerx/tradeshop/utils/debug/DebugV3.java @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2016-2023 + * SparklingComet @ http://shanerx.org + * KillerOfPie @ http://killerofpie.github.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * NOTICE: All modifications made by others to the source code belong + * to the respective contributor. No contributor should be held liable for + * any damages of any kind, whether be material or moral, which were + * caused by their contribution(s) to the project. See the full License for more information. + * + */ + +package org.shanerx.tradeshop.utils.debug; + + +import org.shanerx.tradeshop.data.config.Setting; + +import java.util.HashSet; +import java.util.List; +import java.util.Optional; + +public class DebugV3 extends Debug { + + public DebugV3() { + super(3); + } + + @Override + public boolean loadDebugLevel(Setting settingToReadFrom, HashSet debugDestination) { + + List enabledDebug = settingToReadFrom.getStringList(); + + if (enabledDebug.isEmpty()) { + return false; + } + + for (String debug : enabledDebug) { + Optional level = DebugLevels.match(debug); + if (level.isPresent()) { + debugDestination.add(DebugLevels.valueOf(debug.toUpperCase())); + } + } + + return !debugToConsole.isEmpty(); + } +} diff --git a/src/main/java/org/shanerx/tradeshop/utils/management/VarManager.java b/src/main/java/org/shanerx/tradeshop/utils/management/VarManager.java index 3bff8538..629657ca 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/management/VarManager.java +++ b/src/main/java/org/shanerx/tradeshop/utils/management/VarManager.java @@ -236,15 +236,12 @@ public void resetStorages() { } public Debug getDebugger() { - if (debugger == null) resetDebugger(); + if (debugger == null) + debugger = Debug.newDebug(); //Debug attempts to determine if the setting is version 2(int) or 3(List). If it fails, it resets the setting to default values(V3). return debugger; } - public void resetDebugger() { - this.debugger = new Debug(); - } - public int getbStatsPluginID() { return bStatsPluginID; } diff --git a/src/main/java/org/shanerx/tradeshop/utils/objects/ObjectHolder.java b/src/main/java/org/shanerx/tradeshop/utils/objects/ObjectHolder.java index 7f6a31f2..c9edbc00 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/objects/ObjectHolder.java +++ b/src/main/java/org/shanerx/tradeshop/utils/objects/ObjectHolder.java @@ -28,7 +28,9 @@ import com.google.gson.annotations.SerializedName; import org.bukkit.Material; +import java.util.List; import java.util.Map; +import java.util.Optional; public class ObjectHolder { @@ -43,6 +45,10 @@ public Type getObject() { return obj; } + public boolean isNull() { + return obj == null; + } + public boolean isBoolean() { return obj != null && obj instanceof Boolean; } @@ -115,6 +121,21 @@ public Map asMap() { return null; } + public boolean isList() { + return !isNull() && obj instanceof List; + } + + public Optional> asStringList() { + Optional> ret = Optional.empty(); + if (isList()) { + try { + ret = Optional.of((List) obj); + } catch (ClassCastException ignored) { + } + } + return ret; + } + public boolean canBeMaterial() { return asMaterial() != null; } diff --git a/src/main/java/org/shanerx/tradeshop/utils/versionmanagement/Expirer.java b/src/main/java/org/shanerx/tradeshop/utils/versionmanagement/Expirer.java index 1d270534..619eead8 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/versionmanagement/Expirer.java +++ b/src/main/java/org/shanerx/tradeshop/utils/versionmanagement/Expirer.java @@ -29,6 +29,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; +import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.player.Permissions; import org.shanerx.tradeshop.utils.debug.Debug; import org.shanerx.tradeshop.utils.debug.DebugLevels; @@ -57,7 +58,7 @@ public boolean initiateDevExpiration() { final int devExpirationDays = 60, disableDayMessages = 25, expiredMessagesPerDay = 10; final long postExpirationRunTimeInTicks = 1728000, ticksPerDay = 1728000; - Debug debugger = Debug.findDebugger(); + Debug debugger = TradeShop.getPlugin().getVarManager().getDebugger(); if (buildTime.plusDays(devExpirationDays).isBefore(ChronoLocalDateTime.from(LocalDateTime.now()))) { diff --git a/src/main/resources/Lang/en-us.yml b/src/main/resources/Lang/en-us.yml index 9811b5a9..78b22334 100644 --- a/src/main/resources/Lang/en-us.yml +++ b/src/main/resources/Lang/en-us.yml @@ -4,6 +4,8 @@ setting: header: "" system-options: header: "System Options" + debug-settings: + header: "Debug Settings" logging-options: header: "Logging Options" language-options: @@ -49,14 +51,17 @@ setting: pre-comment: "How would you like your servers data stored? (FLATFILE, SQLITE)" max-save-threads: pre-comment: "Max. number of additional subthreads to spawn. For the best performance, take into account how many cores you have.\nSet to 0 to save everything in the main thread (not recommended unless you experience issues with data saving)." - enable-debug: - pre-comment: "What debug code should be run. This will add significant amounts of spam to the console/log, generally not used unless requested by Devs" check-updates: pre-comment: "Should we check for updates when the server starts" allow-metrics: pre-comment: "Allow us to connect anonymous metrics so we can see how our plugin is being used to better develop it" unlimited-admin: pre-comment: "We do not recommend enabling this setting since any editing an admin should need to do can be done without this.\n Should players with Admin permission be able to use any commands on any shops?" + debug-settings: + debug-to-console: + pre-comment: "List of debug values to output to console" + debug-to-file: + pre-comment: "List of debug values to output to file" logging-options: enable-logging: pre-comment: "Should we log transactions?"