aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java')
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java31
1 files changed, 30 insertions, 1 deletions
diff --git a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java
index b1f048b7..dc400912 100644
--- a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java
+++ b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java
@@ -5,6 +5,8 @@ import com.leonardobishop.quests.common.plugin.Quests;
import com.leonardobishop.quests.common.quest.Quest;
import com.leonardobishop.quests.common.quest.Task;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -18,7 +20,34 @@ import java.util.concurrent.TimeUnit;
*/
public class QuestProgressFile {
- private final Map<String, QuestProgress> questProgress = new HashMap<>();
+ private static final Constructor<?> optimizedMapCtor;
+
+ static {
+ Class<?> optimizedMapClazz;
+
+ try {
+ optimizedMapClazz = Class.forName("it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap");
+ } catch (ClassNotFoundException ignored) {
+ optimizedMapClazz = HashMap.class;
+ }
+
+ try {
+ optimizedMapCtor = optimizedMapClazz.getDeclaredConstructor();
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <K, V> Map<K, V> newOptimizedMapInstance() {
+ try {
+ return (Map<K, V>) optimizedMapCtor.newInstance();
+ } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private final Map<String, QuestProgress> questProgress = newOptimizedMapInstance();
private final UUID playerUUID;
private final Quests plugin;