Skip to content

Commit

Permalink
Warn if plugin get db handler while ORM not fully enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Apr 28, 2019
1 parent af50206 commit 1d30c4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/mengcraft/simpleorm/EbeanManager.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/mengcraft/simpleorm/ORM.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public class ORM extends JavaPlugin {
private static RedisWrapper globalRedisWrapper;
private static MongoWrapper globalMongoWrapper;
private static ThreadLocal<Gson> jsonLazy = ThreadLocal.withInitial(GsonUtils::createJsonInBuk);
private static ORM plugin;

@Override
public void onLoad() {
plugin = this;
loadLibrary(this);
saveDefaultConfig();

Expand Down Expand Up @@ -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()}.
*
Expand Down

0 comments on commit 1d30c4a

Please sign in to comment.