From 6383c9dae8ab5f8476f4b3b8ccd21292ab00e724 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 27 Jan 2021 19:25:33 +0000 Subject: Cached bool values --- .../leonardobishop/quests/commands/CommandQuests.java | 1 + .../java/com/leonardobishop/quests/obj/Options.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java b/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java index 0ea56759..382c3c1a 100644 --- a/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java +++ b/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java @@ -65,6 +65,7 @@ public class CommandQuests implements CommandExecutor { } else if (args[1].equalsIgnoreCase("reload")) { plugin.reloadConfig(); plugin.reloadQuests(); + Options.clearBoolValues(); if (!plugin.getQuestsConfigLoader().getBrokenFiles().isEmpty()) { sender.sendMessage(ChatColor.RED + "Quests has failed to load the following files:"); for (Map.Entry entry : plugin.getQuestsConfigLoader().getBrokenFiles().entrySet()) { diff --git a/src/main/java/com/leonardobishop/quests/obj/Options.java b/src/main/java/com/leonardobishop/quests/obj/Options.java index afcb8fcf..ffe8f6b7 100644 --- a/src/main/java/com/leonardobishop/quests/obj/Options.java +++ b/src/main/java/com/leonardobishop/quests/obj/Options.java @@ -3,11 +3,13 @@ package com.leonardobishop.quests.obj; import com.leonardobishop.quests.Quests; import org.bukkit.ChatColor; +import java.time.temporal.ValueRange; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public enum Options { - CATEGORIES_ENABLED("options.categories-enabled"), TRIM_GUI_SIZE("options.trim-gui-size"), QUESTS_START_LIMIT("options.quest-started-limit"), @@ -22,6 +24,8 @@ public enum Options { ALLOW_QUEST_CANCEL("options.allow-quest-cancel"), QUEST_AUTOSTART("options.quest-autostart"); + private static final Map cachedBools = new HashMap<>(); + private final String path; Options(String path) { @@ -37,7 +41,13 @@ public enum Options { } public boolean getBooleanValue() { - return Quests.get().getConfig().getBoolean(path); + Boolean val = cachedBools.get(path); + if (val != null) { + return val; + } else { + cachedBools.put(path, Quests.get().getConfig().getBoolean(path)); + return getBooleanValue(); + } } public List getStringListValue() { @@ -55,4 +65,8 @@ public enum Options { } return colored; } + + public static void clearBoolValues() { + cachedBools.clear(); + } } -- cgit v1.2.3-70-g09d2