MCore is now itself an mplugin.

This commit is contained in:
Olof Larsson 2012-08-31 12:59:26 +02:00
parent c99c441490
commit d56c87759a
5 changed files with 25 additions and 46 deletions

View File

@ -9,7 +9,6 @@ import org.bukkit.event.player.PlayerPreLoginEvent;
import com.massivecraft.mcore4.persist.IClassManager;
import com.massivecraft.mcore4.persist.Persist;
import com.massivecraft.mcore4.util.PlayerUtil;
public class InternalListener implements Listener
{
@ -27,8 +26,6 @@ public class InternalListener implements Listener
{
String id = event.getName();
PlayerUtil.getAllVisitorNames().add(id);
for (Persist instance : Persist.instances)
{
for (IClassManager<?> manager : instance.getClassManagers().values())

View File

@ -2,46 +2,29 @@ package com.massivecraft.mcore4;
import java.lang.reflect.Modifier;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import com.massivecraft.mcore4.adapter.InventoryAdapter;
import com.massivecraft.mcore4.adapter.ItemStackAdapter;
import com.massivecraft.mcore4.adapter.MongoURIAdapter;
import com.massivecraft.mcore4.persist.Persist;
import com.massivecraft.mcore4.util.PlayerUtil;
import com.massivecraft.mcore4.util.Txt;
import com.massivecraft.mcore4.xlib.gson.Gson;
import com.massivecraft.mcore4.xlib.gson.GsonBuilder;
import com.massivecraft.mcore4.xlib.mongodb.MongoURI;
public class MCore extends JavaPlugin
public class MCore extends MPlugin
{
// -------------------------------------------- //
// STATIC
// -------------------------------------------- //
public static Random random = new Random();
public static Gson gson = getGsonBuilder().create();
public static Gson gson = getMCoreGsonBuilder().create();
InternalListener listener;
@Override
public void onEnable()
{
logPrefix = "["+this.getDescription().getName()+"] ";
// Setup PlayerUtil and it's events
new PlayerUtil(this);
// This is safe since all plugins using Persist should bukkit-depend this plugin.
Persist.instances.clear();
// Register events
this.listener = new InternalListener(this);
}
public static GsonBuilder getGsonBuilder()
public static GsonBuilder getMCoreGsonBuilder()
{
return new GsonBuilder()
.setPrettyPrinting()
@ -53,15 +36,22 @@ public class MCore extends JavaPlugin
}
// -------------------------------------------- //
// LOGGING
// NON STATIC :)
// -------------------------------------------- //
private static String logPrefix = null;
public static void log(Object... msg)
InternalListener listener;
@Override
public void onEnable()
{
log(Level.INFO, msg);
}
public static void log(Level level, Object... msg)
{
Logger.getLogger("Minecraft").log(level, logPrefix + Txt.implode(msg, " "));
// Setup PlayerUtil and it's events
new PlayerUtil(this);
// This is safe since all plugins using Persist should bukkit-depend this plugin.
Persist.instances.clear();
// Register events
this.listener = new InternalListener(this);
}
}

View File

@ -75,7 +75,7 @@ public abstract class MPlugin extends JavaPlugin implements Listener
public GsonBuilder getGsonBuilder()
{
return MCore.getGsonBuilder();
return MCore.getMCoreGsonBuilder();
}
// -------------------------------------------- //

View File

@ -10,7 +10,6 @@ import org.bukkit.command.SimpleCommandMap;
import org.bukkit.entity.Player;
import com.massivecraft.mcore4.Lang;
import com.massivecraft.mcore4.MCore;
import com.massivecraft.mcore4.MPlugin;
import com.massivecraft.mcore4.cmd.arg.IArgHandler;
import com.massivecraft.mcore4.cmd.req.IReq;
@ -461,7 +460,7 @@ public abstract class MCommand
if (handler == null)
{
MCore.log(Level.SEVERE, "There is no ArgHandler for " + clazz.getName());
p().log(Level.SEVERE, "There is no ArgHandler for " + clazz.getName());
}
T ret = handler.parse(this.arg(idx), style, this.sender, p());

View File

@ -29,11 +29,6 @@ public class PlayerUtil implements Listener
// FIELDS
// -------------------------------------------- //
/**
* This is the latest created instance of this class.
*/
private static PlayerUtil i = null;
/**
* We will use this folder later.
*/
@ -57,8 +52,6 @@ public class PlayerUtil implements Listener
public PlayerUtil(Plugin plugin)
{
if (i != null) return;
i = this;
Bukkit.getPluginManager().registerEvents(this, plugin);
populateCaseInsensitiveNameToCaseCorrectName();
}