From d4f30331effd7f9b6c18df58a7e8c2f45bd412c0 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 10 Apr 2013 11:08:13 +0200 Subject: [PATCH] Do not require MPlugin if Plugin is sufficient --- src/com/massivecraft/mcore/SimpleConfig.java | 32 +++++++++++++------ .../mcore/cmd/BukkitGlueCommand.java | 10 +++--- src/com/massivecraft/mcore/cmd/MCommand.java | 10 +++--- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/com/massivecraft/mcore/SimpleConfig.java b/src/com/massivecraft/mcore/SimpleConfig.java index 2f38a466..b3fd8f17 100644 --- a/src/com/massivecraft/mcore/SimpleConfig.java +++ b/src/com/massivecraft/mcore/SimpleConfig.java @@ -2,40 +2,52 @@ package com.massivecraft.mcore; import java.io.File; +import org.bukkit.plugin.Plugin; + import com.massivecraft.mcore.store.accessor.Accessor; import com.massivecraft.mcore.util.DiscUtil; +import com.massivecraft.mcore.xlib.gson.Gson; public class SimpleConfig { // -------------------------------------------- // // FIELDS // -------------------------------------------- // - protected transient MPlugin mplugin; - protected MPlugin getMplugin() { return this.mplugin; } + protected transient Plugin plugin; + protected Plugin getPlugin() { return this.plugin; } protected transient File file; protected File getFile() { return this.file; } - public SimpleConfig(MPlugin mplugin, File file) + public SimpleConfig(Plugin plugin, File file) { - this.mplugin = mplugin; + this.plugin = plugin; this.file = file; } - public SimpleConfig(MPlugin mplugin, String confname) + public SimpleConfig(Plugin plugin, String confname) { - this(mplugin, new File(mplugin.getDataFolder(), confname+".json")); + this(plugin, new File(plugin.getDataFolder(), confname+".json")); } - public SimpleConfig(MPlugin mplugin) + public SimpleConfig(Plugin plugin) { - this(mplugin, "conf"); + this(plugin, "conf"); } // -------------------------------------------- // // IO // -------------------------------------------- // + private Gson getGson() + { + if (this.plugin instanceof MPlugin) + { + return ((MPlugin)this.plugin).gson; + } + return MCore.gson; + } + protected static boolean contentRequestsDefaults(String content) { if (content == null) return false; @@ -63,7 +75,7 @@ public class SimpleConfig } else { - toShallowLoad = this.getMplugin().gson.fromJson(content, this.getClass()); + toShallowLoad = this.getGson().fromJson(content, this.getClass()); } Accessor.get(this.getClass()).copy(toShallowLoad, this); } @@ -74,7 +86,7 @@ public class SimpleConfig { String content = DiscUtil.readCatch(this.getFile()); if (contentRequestsDefaults(content)) return; - content = this.getMplugin().gson.toJson(this); + content = this.getGson().toJson(this); DiscUtil.writeCatch(file, content); } } diff --git a/src/com/massivecraft/mcore/cmd/BukkitGlueCommand.java b/src/com/massivecraft/mcore/cmd/BukkitGlueCommand.java index ee7d0407..3757b425 100644 --- a/src/com/massivecraft/mcore/cmd/BukkitGlueCommand.java +++ b/src/com/massivecraft/mcore/cmd/BukkitGlueCommand.java @@ -7,27 +7,27 @@ import java.util.TreeSet; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; -import com.massivecraft.mcore.MPlugin; import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.util.Txt; public class BukkitGlueCommand extends Command { public final MCommand mcommand; - public final MPlugin mplugin; + public final Plugin plugin; - public BukkitGlueCommand(String name, MCommand mcommand, MPlugin mplugin) + public BukkitGlueCommand(String name, MCommand mcommand, Plugin plugin) { super(name, mcommand.getDesc(), mcommand.getUseageTemplate(), new ArrayList()); this.mcommand = mcommand; - this.mplugin = mplugin; + this.plugin = plugin; } @Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { - if ( ! mplugin.isEnabled()) return false; + if ( ! plugin.isEnabled()) return false; this.mcommand.execute(sender, Txt.tokenizeArguments(Txt.implode(args, " "))); return true; } diff --git a/src/com/massivecraft/mcore/cmd/MCommand.java b/src/com/massivecraft/mcore/cmd/MCommand.java index 834b12c5..a320e861 100644 --- a/src/com/massivecraft/mcore/cmd/MCommand.java +++ b/src/com/massivecraft/mcore/cmd/MCommand.java @@ -7,10 +7,10 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import com.massivecraft.mcore.Lang; import com.massivecraft.mcore.MCore; -import com.massivecraft.mcore.MPlugin; import com.massivecraft.mcore.cmd.arg.ArgReader; import com.massivecraft.mcore.cmd.arg.ArgResult; import com.massivecraft.mcore.cmd.req.Req; @@ -160,9 +160,9 @@ public abstract class MCommand return register(MCore.get(), true); } - public boolean register(MPlugin mplugin) + public boolean register(Plugin plugin) { - return this.register(mplugin, true); + return this.register(plugin, true); } public boolean register(boolean override) @@ -170,7 +170,7 @@ public abstract class MCommand return this.register(MCore.get(), override); } - public boolean register(MPlugin mplugin, boolean override) + public boolean register(Plugin plugin, boolean override) { boolean ret = false; @@ -178,7 +178,7 @@ public abstract class MCommand for (String alias : this.getAliases()) { - BukkitGlueCommand bgc = new BukkitGlueCommand(alias, this, mplugin); + BukkitGlueCommand bgc = new BukkitGlueCommand(alias, this, plugin); if (override) {