This is a much better way to work with our commands dynamically. It

allows for localized description strings, aliases, etc.

With this addition, our "ugly alias" method in CommandPreProcessEvent is
no longer needed, nor is our alias map.

This also makes us more friendly with Essentials - if Essentials is
enabled, the /repair command will be changed to /mcrepair for
compatibility reasons.
This commit is contained in:
GJ
2013-02-01 12:27:24 -05:00
parent cec132092f
commit 89e5e16aad
5 changed files with 118 additions and 118 deletions

View File

@ -0,0 +1,112 @@
package com.gmail.nossr50.commands;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.PluginCommand;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
import com.gmail.nossr50.skills.archery.ArcheryCommand;
import com.gmail.nossr50.skills.axes.AxesCommand;
import com.gmail.nossr50.skills.excavation.ExcavationCommand;
import com.gmail.nossr50.skills.fishing.FishingCommand;
import com.gmail.nossr50.skills.herbalism.HerbalismCommand;
import com.gmail.nossr50.skills.mining.MiningCommand;
import com.gmail.nossr50.skills.repair.RepairCommand;
import com.gmail.nossr50.skills.smelting.SmeltingCommand;
import com.gmail.nossr50.skills.swords.SwordsCommand;
import com.gmail.nossr50.skills.taming.TamingCommand;
import com.gmail.nossr50.skills.unarmed.UnarmedCommand;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingCommand;
import com.gmail.nossr50.util.Misc;
public final class CommandRegistrationHelper {
private CommandRegistrationHelper() {};
public static void registerSkillCommands() {
for (SkillType skill : SkillType.values()) {
if (skill != SkillType.ALL) {
String commandName = skill.toString().toLowerCase();
String localizedName = LocaleLoader.getString(Misc.getCapitalized(commandName) + ".SkillName").toLowerCase();
List<String> aliasList = new ArrayList<String>();
aliasList.add(localizedName);
PluginCommand command;
// Make us play nice with Essentials
if (skill == SkillType.REPAIR && mcMMO.p.getServer().getPluginManager().isPluginEnabled("Essentials")) {
command = mcMMO.p.getCommand("mcrepair");
}
else {
command = mcMMO.p.getCommand(commandName);
}
command.setAliases(aliasList);
command.setDescription(LocaleLoader.getString("Commands.Description.Skill", new Object[] { Misc.getCapitalized(localizedName) }));
command.setPermission("mcmmo.skills." + commandName);
command.setPermissionMessage(LocaleLoader.getString("mcMMO.NoPermission"));
switch (skill) {
case ACROBATICS:
command.setExecutor(new AcrobaticsCommand());
break;
case ARCHERY:
command.setExecutor(new ArcheryCommand());
break;
case AXES:
command.setExecutor(new AxesCommand());
break;
case EXCAVATION:
command.setExecutor(new ExcavationCommand());
break;
case FISHING:
command.setExecutor(new FishingCommand());
break;
case HERBALISM:
command.setExecutor(new HerbalismCommand());
break;
case MINING:
command.setExecutor(new MiningCommand());
break;
case REPAIR:
command.setExecutor(new RepairCommand());
break;
case SMELTING:
command.setExecutor(new SmeltingCommand());
break;
case SWORDS:
command.setExecutor(new SwordsCommand());
break;
case TAMING:
command.setExecutor(new TamingCommand());
break;
case UNARMED:
command.setExecutor(new UnarmedCommand());
break;
case WOODCUTTING:
command.setExecutor(new WoodcuttingCommand());
break;
default:
break;
}
}
}
}
}