From 1d30c4a5f8cd8076a6e3ccb36ce6ef88eb4cc2d5 Mon Sep 17 00:00:00 2001 From: caoli5288 Date: Sun, 28 Apr 2019 15:28:21 +0800 Subject: [PATCH] Warn if plugin get db handler while ORM not fully enabled. --- src/main/java/com/mengcraft/simpleorm/EbeanManager.java | 6 ++++++ src/main/java/com/mengcraft/simpleorm/ORM.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/com/mengcraft/simpleorm/EbeanManager.java b/src/main/java/com/mengcraft/simpleorm/EbeanManager.java index 75a546b..8bdb44e 100644 --- a/src/main/java/com/mengcraft/simpleorm/EbeanManager.java +++ b/src/main/java/com/mengcraft/simpleorm/EbeanManager.java @@ -1,6 +1,8 @@ package com.mengcraft.simpleorm; import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.plugin.java.JavaPlugin; import java.util.HashMap; @@ -20,6 +22,10 @@ private EbeanManager() { } public EbeanHandler getHandler(JavaPlugin plugin) { + if (!ORM.isFullyEnabled()) { + plugin.getLogger().warning("Try register db handler while ORM not fully enabled(Not depend on or register at onLoad?)."); + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + plugin.getName() + " try register db handler while ORM not fully enabled. This may cause unknown issues."); + } EbeanHandler out = map.get(plugin.getName()); if (out == null) { map.put(plugin.getName(), out = build(plugin)); diff --git a/src/main/java/com/mengcraft/simpleorm/ORM.java b/src/main/java/com/mengcraft/simpleorm/ORM.java index 67c650d..86401a7 100644 --- a/src/main/java/com/mengcraft/simpleorm/ORM.java +++ b/src/main/java/com/mengcraft/simpleorm/ORM.java @@ -26,9 +26,11 @@ public class ORM extends JavaPlugin { private static RedisWrapper globalRedisWrapper; private static MongoWrapper globalMongoWrapper; private static ThreadLocal jsonLazy = ThreadLocal.withInitial(GsonUtils::createJsonInBuk); + private static ORM plugin; @Override public void onLoad() { + plugin = this; loadLibrary(this); saveDefaultConfig(); @@ -84,6 +86,10 @@ public void onEnable() { getLogger().info("Welcome!"); } + public static boolean isFullyEnabled() { + return plugin.isEnabled(); + } + /** * Plz call this method in {@link Plugin#onLoad()}. *