Updating /xprate to use Bukkit command API

This commit is contained in:
GJ 2013-02-04 12:47:48 -05:00
parent 6d486401b5
commit bb945a765c
4 changed files with 54 additions and 58 deletions

View File

@ -12,6 +12,7 @@ import com.gmail.nossr50.commands.admin.McgodCommand;
import com.gmail.nossr50.commands.admin.McrefreshCommand;
import com.gmail.nossr50.commands.admin.MmoeditCommand;
import com.gmail.nossr50.commands.admin.SkillresetCommand;
import com.gmail.nossr50.commands.admin.XprateCommand;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
import com.gmail.nossr50.skills.archery.ArcheryCommand;
@ -168,4 +169,14 @@ public final class CommandRegistrationHelper {
command.setUsage(LocaleLoader.getString("Commands.Usage.2", "skillreset", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">"));
command.setExecutor(new SkillresetCommand());
}
public static void registerXprateCommand() {
PluginCommand command = mcMMO.p.getCommand("xprate");
command.setDescription(LocaleLoader.getString("Commands.Description.xprate"));
command.setPermission("mcmmo.commands.xprate;mcmmo.commands.xprate.reset;mcmmo.commands.xprate.set");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.2", "xprate", "<" + LocaleLoader.getString("Commands.Usage.Rate") + ">", "<" + LocaleLoader.getString("Commands.Usage.True") + "|" + LocaleLoader.getString("Commands.Usage.False")+ ">"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "xprate", "reset"));
command.setExecutor(new XprateCommand());
}
}

View File

@ -6,88 +6,70 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class XprateCommand implements CommandExecutor {
private static double originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage1 = LocaleLoader.getString("Commands.xprate.proper.0");
String usage2 = LocaleLoader.getString("Commands.xprate.proper.1");
String usage3 = LocaleLoader.getString("Commands.xprate.proper.2");
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.xprate")) {
return true;
}
switch (args.length) {
case 1:
if (args[0].equalsIgnoreCase("reset")) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.xprate.reset")) {
return true;
}
if (mcMMO.p.isXPEventEnabled()) {
for (Player x : mcMMO.p.getServer().getOnlinePlayers()) {
x.sendMessage(LocaleLoader.getString("Commands.xprate.over"));
}
mcMMO.p.toggleXpEventEnabled();
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
}
else {
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
}
}
else if (Misc.isInt(args[0])) {
sender.sendMessage(usage3);
}
else {
sender.sendMessage(usage2);
if (!args[0].equalsIgnoreCase("reset")) {
return false;
}
if (!Permissions.hasPermission(sender, "mcmmo.commands.xprate.reset")) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (mcMMO.p.isXPEventEnabled()) {
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
player.sendMessage(LocaleLoader.getString("Commands.xprate.over"));
}
mcMMO.p.toggleXpEventEnabled();
}
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
return true;
case 2:
if (Misc.isInt(args[0])) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.xprate.set")) {
return true;
}
if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) {
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
}
else {
sender.sendMessage(usage3);
}
if (!Misc.isInt(args[0])) {
return false;
}
int newRate = Misc.getInt(args[0]);
Config.getInstance().setExperienceGainsGlobalMultiplier(newRate);
if (!Permissions.hasPermission(sender, "mcmmo.commands.xprate.set")) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (mcMMO.p.isXPEventEnabled()) {
for (Player x : mcMMO.p.getServer().getOnlinePlayers()) {
x.sendMessage(LocaleLoader.getString("Commands.xprate.started.0"));
x.sendMessage(LocaleLoader.getString("Commands.xprate.started.1", newRate));
}
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", newRate));
if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
return false;
}
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
int newXpRate = Misc.getInt(args[0]);
Config.getInstance().setExperienceGainsGlobalMultiplier(newXpRate);
if (mcMMO.p.isXPEventEnabled()) {
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
player.sendMessage(LocaleLoader.getString("Commands.xprate.started.0"));
player.sendMessage(LocaleLoader.getString("Commands.xprate.started.1", newXpRate));
}
}
else {
sender.sendMessage(usage1);
sender.sendMessage(usage2);
sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", newXpRate));
}
return true;
default:
sender.sendMessage(usage1);
sender.sendMessage(usage2);
return true;
return false;
}
}
}

View File

@ -25,7 +25,6 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
import com.gmail.nossr50.chat.commands.ACommand;
import com.gmail.nossr50.chat.commands.PCommand;
import com.gmail.nossr50.commands.CommandRegistrationHelper;
import com.gmail.nossr50.commands.admin.XprateCommand;
import com.gmail.nossr50.commands.player.InspectCommand;
import com.gmail.nossr50.commands.player.McabilityCommand;
import com.gmail.nossr50.commands.player.MccCommand;
@ -453,7 +452,7 @@ public class mcMMO extends JavaPlugin {
CommandRegistrationHelper.registerAddlevelsCommand();
CommandRegistrationHelper.registerMmoeditCommand();
getCommand("inspect").setExecutor(new InspectCommand());
getCommand("xprate").setExecutor(new XprateCommand());
CommandRegistrationHelper.registerXprateCommand();
getCommand("mmoupdate").setExecutor(new MmoupdateCommand());
CommandRegistrationHelper.registerSkillresetCommand();

View File

@ -490,13 +490,16 @@ Commands.ToggleAbility=[[RED]]- Toggle ability activation with right click
Commands.Usage.1=[[RED]]Proper usage is /{0} {1}
Commands.Usage.2=[[RED]]Proper usage is /{0} {1} {2}
Commands.Usage.3=[[RED]]Proper usage is /{0} {1} {2} {3}
Commands.Usage.False=false
Commands.Usage.Level=level
Commands.Usage.Message=message
Commands.Usage.Page=page
Commands.Usage.PartyName=party-name
Commands.Usage.Password=password
Commands.Usage.Player=player
Commands.Usage.Rate=rate
Commands.Usage.Skill=skill
Commands.Usage.True=true
Commands.Usage.XP=xp
mcMMO.NoInvites=[[RED]]You have no invites at this time
mcMMO.NoPermission=[[DARK_RED]]Insufficient permissions.
@ -691,3 +694,4 @@ Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO
Commands.Description.mmoedit=Edit mcMMO levels for a user
Commands.Description.Skill=Display detailed mcMMO skill info for {0}
Commands.Description.skillreset=Reset mcMMO levels for a user
Commands.Description.xprate=Modify the mcMMO XP rate or start an mcMMO XP event