/**
 * 
 */
package org.alfresco.contentcraft;

import java.lang.reflect.Constructor;
import java.util.Map;

import org.bukkit.command.CommandExecutor;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * Content craft plugin implementation
 * 
 * @author Roy Wetherall
 */
public class ContentCraftPlugin extends JavaPlugin 
{
	/**
	 * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
	 */
	@Override
	public void onEnable() 
	{
		getLogger().info("onEnable had been invoked");
		
		PluginDescriptionFile descriptionFile = getDescription();
		
		Map<String, Map<String, Object>> commands = descriptionFile.getCommands();
		for (Map.Entry<String, Map<String, Object>> entry : commands.entrySet()) 
		{
			String className = (String)entry.getValue().get("class");
			if (className != null)
			{
				try
				{
					Class<?> clazz = Class.forName(className);
					Constructor<?> ctor = clazz.getConstructor(String.class, Map.class);
					CommandExecutor commandExecutor = (CommandExecutor)ctor.newInstance(entry.getKey(), entry.getValue());
					
					getCommand(entry.getKey()).setExecutor(commandExecutor);
					
					if (commandExecutor instanceof Listener)
					{
						getServer().getPluginManager().registerEvents((Listener)commandExecutor, this);
					}
				}
				catch (Exception exception)
				{
					exception.printStackTrace();
				} 
			}
		}
	}
	
	/**
	 * @see org.bukkit.plugin.java.JavaPlugin#onDisable()
	 */
	@Override
	public void onDisable() 
	{
		getLogger().info("onDisable has been invoked");
	}
	
}

@@ -555,16 +555,53 @@
 d%22);%0A%09%09%0A
+%09%09// get the plugin description file%0A
 %09%09Plugin
@@ -655,16 +655,53 @@
 n();%0A%09%09%0A
+%09%09// get the command information map%0A
 %09%09Map%3CSt
@@ -849,16 +849,50 @@
 )) %0A%09%09%7B%0A
+%09%09%09// look for the executor class%0A
 %09%09%09Strin
@@ -985,24 +985,77 @@
 %09%09try%0A%09%09%09%09%7B%0A
+%09%09%09%09%09// create an instance of the the executor class%0A
 %09%09%09%09%09Class%3C?
@@ -1274,24 +1274,57 @@
 e());%0A%09%09%09%09%09%0A
+%09%09%09%09%09// set the command executor%0A
 %09%09%09%09%09getComm
@@ -1375,24 +1375,61 @@
 tor);%0A%09%09%09%09%09%0A
+%09%09%09%09%09// if the command is a listener%0A
 %09%09%09%09%09if (com
@@ -1465,24 +1465,49 @@
 ner)%0A%09%09%09%09%09%7B%0A
+%09%09%09%09%09%09// register events%0A
 %09%09%09%09%09%09getSer

Add comments