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
|
// Register commands
|
||||||
this.outerCmdMassiveCore = new CmdMassiveCore() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCore; } };
|
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 = 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 = 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 = 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 = new CmdMassiveCoreCmdurl() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreCmdurl; } };
|
||||||
this.outerCmdMassiveCoreCmdurl.register();
|
this.outerCmdMassiveCoreCmdurl.register(this);
|
||||||
|
|
||||||
// Integration
|
// Integration
|
||||||
this.integrate(
|
this.integrate(
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.command.ConsoleCommandSender;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||||
import com.massivecraft.massivecore.integration.IntegrationGlue;
|
import com.massivecraft.massivecore.integration.IntegrationGlue;
|
||||||
import com.massivecraft.massivecore.integration.Integration;
|
import com.massivecraft.massivecore.integration.Integration;
|
||||||
import com.massivecraft.massivecore.store.Coll;
|
import com.massivecraft.massivecore.store.Coll;
|
||||||
@ -77,7 +78,10 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
// Collection shutdowns.
|
// Commands
|
||||||
|
MassiveCommand.unregister(this);
|
||||||
|
|
||||||
|
// Collections
|
||||||
for (Coll<?> coll : Coll.getInstances())
|
for (Coll<?> coll : Coll.getInstances())
|
||||||
{
|
{
|
||||||
if (coll.getPlugin() != this) continue;
|
if (coll.getPlugin() != this) continue;
|
||||||
|
@ -5,8 +5,10 @@ import java.util.Map.Entry;
|
|||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.Lang;
|
import com.massivecraft.massivecore.Lang;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.cmd.arg.ArgReader;
|
import com.massivecraft.massivecore.cmd.arg.ArgReader;
|
||||||
import com.massivecraft.massivecore.cmd.arg.ArgResult;
|
import com.massivecraft.massivecore.cmd.arg.ArgResult;
|
||||||
import com.massivecraft.massivecore.cmd.req.Req;
|
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.
|
// This task unregisters /all/ registered MCommands and then register them all again.
|
||||||
// When registering again we use the fresh and current aliases.
|
// When registering again we use the fresh and current aliases.
|
||||||
|
|
||||||
private static transient Set<MassiveCommand> registeredCommands = new LinkedHashSet<MassiveCommand>();
|
private static transient Map<MassiveCommand, Plugin> registry = new LinkedHashMap<MassiveCommand, Plugin>();
|
||||||
public static Set<MassiveCommand> getRegisteredCommands() { return registeredCommands; }
|
|
||||||
public void register() { getRegisteredCommands().add(this); }
|
public static Set<MassiveCommand> getRegisteredCommands()
|
||||||
public void unregister() { getRegisteredCommands().remove(this); }
|
{
|
||||||
|
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
|
// COMMAND BEHAVIOR
|
||||||
|
Loading…
Reference in New Issue
Block a user