Do not require MPlugin if Plugin is sufficient
This commit is contained in:
		
							parent
							
								
									9a6cae780d
								
							
						
					
					
						commit
						d4f30331ef
					
				@ -2,40 +2,52 @@ package com.massivecraft.mcore;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.plugin.Plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.massivecraft.mcore.store.accessor.Accessor;
 | 
					import com.massivecraft.mcore.store.accessor.Accessor;
 | 
				
			||||||
import com.massivecraft.mcore.util.DiscUtil;
 | 
					import com.massivecraft.mcore.util.DiscUtil;
 | 
				
			||||||
 | 
					import com.massivecraft.mcore.xlib.gson.Gson;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SimpleConfig
 | 
					public class SimpleConfig
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// FIELDS
 | 
						// FIELDS
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	protected transient MPlugin mplugin;
 | 
						protected transient Plugin plugin;
 | 
				
			||||||
	protected MPlugin getMplugin() { return this.mplugin; }
 | 
						protected Plugin getPlugin() { return this.plugin; }
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	protected transient File file;
 | 
						protected transient File file;
 | 
				
			||||||
	protected File getFile() { return this.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;
 | 
							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
 | 
						// IO
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						private Gson getGson()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if (this.plugin instanceof MPlugin)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return ((MPlugin)this.plugin).gson;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return MCore.gson;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	protected static boolean contentRequestsDefaults(String content)
 | 
						protected static boolean contentRequestsDefaults(String content)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (content == null) return false;
 | 
							if (content == null) return false;
 | 
				
			||||||
@ -63,7 +75,7 @@ public class SimpleConfig
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				toShallowLoad = this.getMplugin().gson.fromJson(content, this.getClass());
 | 
									toShallowLoad = this.getGson().fromJson(content, this.getClass());
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			Accessor.get(this.getClass()).copy(toShallowLoad, this);
 | 
								Accessor.get(this.getClass()).copy(toShallowLoad, this);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -74,7 +86,7 @@ public class SimpleConfig
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		String content = DiscUtil.readCatch(this.getFile());
 | 
							String content = DiscUtil.readCatch(this.getFile());
 | 
				
			||||||
		if (contentRequestsDefaults(content)) return;
 | 
							if (contentRequestsDefaults(content)) return;
 | 
				
			||||||
		content = this.getMplugin().gson.toJson(this);
 | 
							content = this.getGson().toJson(this);
 | 
				
			||||||
		DiscUtil.writeCatch(file, content);
 | 
							DiscUtil.writeCatch(file, content);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,27 +7,27 @@ import java.util.TreeSet;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.bukkit.command.Command;
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					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.mixin.Mixin;
 | 
				
			||||||
import com.massivecraft.mcore.util.Txt;
 | 
					import com.massivecraft.mcore.util.Txt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class BukkitGlueCommand extends Command
 | 
					public class BukkitGlueCommand extends Command
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	public final MCommand mcommand;
 | 
						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<String>());
 | 
							super(name, mcommand.getDesc(), mcommand.getUseageTemplate(), new ArrayList<String>());
 | 
				
			||||||
		this.mcommand = mcommand;
 | 
							this.mcommand = mcommand;
 | 
				
			||||||
		this.mplugin = mplugin;
 | 
							this.plugin = plugin;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public boolean execute(CommandSender sender, String commandLabel, String[] args)
 | 
						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, " ")));
 | 
							this.mcommand.execute(sender, Txt.tokenizeArguments(Txt.implode(args, " ")));
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,10 +7,10 @@ import org.bukkit.command.Command;
 | 
				
			|||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
import org.bukkit.command.SimpleCommandMap;
 | 
					import org.bukkit.command.SimpleCommandMap;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.plugin.Plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.massivecraft.mcore.Lang;
 | 
					import com.massivecraft.mcore.Lang;
 | 
				
			||||||
import com.massivecraft.mcore.MCore;
 | 
					import com.massivecraft.mcore.MCore;
 | 
				
			||||||
import com.massivecraft.mcore.MPlugin;
 | 
					 | 
				
			||||||
import com.massivecraft.mcore.cmd.arg.ArgReader;
 | 
					import com.massivecraft.mcore.cmd.arg.ArgReader;
 | 
				
			||||||
import com.massivecraft.mcore.cmd.arg.ArgResult;
 | 
					import com.massivecraft.mcore.cmd.arg.ArgResult;
 | 
				
			||||||
import com.massivecraft.mcore.cmd.req.Req;
 | 
					import com.massivecraft.mcore.cmd.req.Req;
 | 
				
			||||||
@ -160,9 +160,9 @@ public abstract class MCommand
 | 
				
			|||||||
		return register(MCore.get(), true);
 | 
							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)
 | 
						public boolean register(boolean override)
 | 
				
			||||||
@ -170,7 +170,7 @@ public abstract class MCommand
 | 
				
			|||||||
		return this.register(MCore.get(), override);
 | 
							return this.register(MCore.get(), override);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public boolean register(MPlugin mplugin, boolean override)
 | 
						public boolean register(Plugin plugin, boolean override)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		boolean ret = false;
 | 
							boolean ret = false;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@ -178,7 +178,7 @@ public abstract class MCommand
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		for (String alias : this.getAliases())
 | 
							for (String alias : this.getAliases())
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			BukkitGlueCommand bgc = new BukkitGlueCommand(alias, this, mplugin);
 | 
								BukkitGlueCommand bgc = new BukkitGlueCommand(alias, this, plugin);
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			if (override)
 | 
								if (override)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user