Supply the Plugin upon registration of a MassiveCommand.
This commit is contained in:
parent
36303b66bb
commit
4b570f5de9
@ -193,19 +193,19 @@ public class MassiveCore extends MassivePlugin
|
||||
|
||||
// Register commands
|
||||
this.outerCmdMassiveCore = new CmdMassiveCore() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCore; } };
|
||||
this.outerCmdMassiveCore.register();
|
||||
this.outerCmdMassiveCore.register(this);
|
||||
|
||||
this.outerCmdMassiveCoreUsys = new CmdMassiveCoreUsys() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreUsys; } };
|
||||
this.outerCmdMassiveCoreUsys.register();
|
||||
this.outerCmdMassiveCoreUsys.register(this);
|
||||
|
||||
this.outerCmdMassiveCoreStore = new CmdMassiveCoreStore() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreStore; } };
|
||||
this.outerCmdMassiveCoreStore.register();
|
||||
this.outerCmdMassiveCoreStore.register(this);
|
||||
|
||||
this.outerCmdMassiveCoreBuffer = new CmdMassiveCoreBuffer() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreBuffer; } };
|
||||
this.outerCmdMassiveCoreBuffer.register();
|
||||
this.outerCmdMassiveCoreBuffer.register(this);
|
||||
|
||||
this.outerCmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreCmdurl; } };
|
||||
this.outerCmdMassiveCoreCmdurl.register();
|
||||
this.outerCmdMassiveCoreCmdurl.register(this);
|
||||
|
||||
// Integration
|
||||
this.integrate(
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||
import com.massivecraft.massivecore.integration.IntegrationGlue;
|
||||
import com.massivecraft.massivecore.integration.Integration;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
@ -77,7 +78,10 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
// Collection shutdowns.
|
||||
// Commands
|
||||
MassiveCommand.unregister(this);
|
||||
|
||||
// Collections
|
||||
for (Coll<?> coll : Coll.getInstances())
|
||||
{
|
||||
if (coll.getPlugin() != this) continue;
|
||||
|
@ -5,8 +5,10 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.massivecore.Lang;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.cmd.arg.ArgReader;
|
||||
import com.massivecraft.massivecore.cmd.arg.ArgResult;
|
||||
import com.massivecraft.massivecore.cmd.req.Req;
|
||||
@ -33,10 +35,56 @@ public class MassiveCommand
|
||||
// This task unregisters /all/ registered MCommands and then register them all again.
|
||||
// When registering again we use the fresh and current aliases.
|
||||
|
||||
private static transient Set<MassiveCommand> registeredCommands = new LinkedHashSet<MassiveCommand>();
|
||||
public static Set<MassiveCommand> getRegisteredCommands() { return registeredCommands; }
|
||||
public void register() { getRegisteredCommands().add(this); }
|
||||
public void unregister() { getRegisteredCommands().remove(this); }
|
||||
private static transient Map<MassiveCommand, Plugin> registry = new LinkedHashMap<MassiveCommand, Plugin>();
|
||||
|
||||
public static Set<MassiveCommand> getRegisteredCommands()
|
||||
{
|
||||
return registry.keySet();
|
||||
}
|
||||
|
||||
public static Map<MassiveCommand, Plugin> getRegistry()
|
||||
{
|
||||
return registry;
|
||||
}
|
||||
|
||||
public static void unregister(Plugin plugin)
|
||||
{
|
||||
Iterator<Entry<MassiveCommand, Plugin>> iter = registry.entrySet().iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Entry<MassiveCommand, Plugin> entry = iter.next();
|
||||
if (plugin.equals(entry.getValue()))
|
||||
{
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void register()
|
||||
{
|
||||
this.register(MassiveCore.get());
|
||||
}
|
||||
|
||||
public Plugin register(Plugin plugin)
|
||||
{
|
||||
return registry.put(this, plugin);
|
||||
}
|
||||
|
||||
public void unregister()
|
||||
{
|
||||
registry.remove(this);
|
||||
}
|
||||
|
||||
public boolean isRegistered()
|
||||
{
|
||||
return registry.containsKey(this);
|
||||
}
|
||||
|
||||
public Plugin getRegisteredPlugin()
|
||||
{
|
||||
return registry.get(this);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// COMMAND BEHAVIOR
|
||||
|
Loading…
Reference in New Issue
Block a user