Fixed some possible errors if bad command arguments were used.

This commit is contained in:
GJ 2012-04-04 16:12:13 -04:00
parent 2b7f21fee4
commit 74ee210514
7 changed files with 113 additions and 130 deletions

View File

@ -30,7 +30,7 @@ public class AddlevelsCommand implements CommandExecutor{
int levels; int levels;
SkillType skill; SkillType skill;
String skillName; String skillName;
String usage = ChatColor.RED + "Proper usage is /addlevels <playername> <skillname> <levels>"; //TODO: Needs more locale. String usage = ChatColor.RED + "Proper usage is /addlevels [playername] <skill> <level>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) {
return true; return true;
@ -54,10 +54,13 @@ public class AddlevelsCommand implements CommandExecutor{
PP.addLevels(skill, levels); PP.addLevels(skill, levels);
sender.sendMessage(ChatColor.GREEN + "You were awarded " + levels + " levels in " + skillName + "!"); //TODO: Needs more locale. sender.sendMessage(ChatColor.GREEN + "You were awarded " + levels + " levels in " + skillName + "!"); //TODO: Needs more locale.
return true;
} }
} }
else {
sender.sendMessage(usage);
}
return true;
case 3: case 3:
modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]); modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]);
@ -90,9 +93,12 @@ public class AddlevelsCommand implements CommandExecutor{
if (modifiedPlayer.isOnline()) { if (modifiedPlayer.isOnline()) {
((Player) modifiedPlayer).sendMessage(ChatColor.GREEN + "You were awarded " + levels + " levels in " + skillName + "!"); //TODO: Needs more locale. ((Player) modifiedPlayer).sendMessage(ChatColor.GREEN + "You were awarded " + levels + " levels in " + skillName + "!"); //TODO: Needs more locale.
} }
return true;
} }
else {
sender.sendMessage(usage);
}
return true;
default: default:
sender.sendMessage(usage); sender.sendMessage(usage);

View File

@ -13,6 +13,7 @@ import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;
//TODO: Any way we can make this work for offline use?
public class AddxpCommand implements CommandExecutor { public class AddxpCommand implements CommandExecutor {
private final mcMMO plugin; private final mcMMO plugin;
@ -26,7 +27,7 @@ public class AddxpCommand implements CommandExecutor {
int xp; int xp;
SkillType skill; SkillType skill;
String skillName; String skillName;
String usage = ChatColor.RED + "Proper usage is /addxp <playername> <skillname> <xp>"; //TODO: Needs more locale. String usage = ChatColor.RED + "Proper usage is /addxp [player] <skill> <xp>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) {
return true; return true;
@ -57,10 +58,13 @@ public class AddxpCommand implements CommandExecutor {
else { else {
Skills.XpCheckSkill(skill, modifiedPlayer); Skills.XpCheckSkill(skill, modifiedPlayer);
} }
return true;
} }
} }
else {
sender.sendMessage(usage);
}
return true;
case 3: case 3:
modifiedPlayer = plugin.getServer().getPlayer(args[0]); modifiedPlayer = plugin.getServer().getPlayer(args[0]);
@ -91,9 +95,12 @@ public class AddxpCommand implements CommandExecutor {
else { else {
Skills.XpCheckSkill(skill, modifiedPlayer); Skills.XpCheckSkill(skill, modifiedPlayer);
} }
return true;
} }
else {
sender.sendMessage(usage);
}
return true;
default: default:
sender.sendMessage(usage); sender.sendMessage(usage);

View File

@ -25,7 +25,7 @@ public class InspectCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
OfflinePlayer target; OfflinePlayer target;
PlayerProfile PP; PlayerProfile PP;
String usage = "Proper usage is /inspect <playername>"; //TODO: Needs more locale. String usage = "Proper usage is /inspect <player>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.inspect")) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.inspect")) {
return true; return true;

View File

@ -30,7 +30,7 @@ public class MmoeditCommand implements CommandExecutor {
int newValue; int newValue;
SkillType skill; SkillType skill;
String skillName; String skillName;
String usage = ChatColor.RED + "Proper usage is /mmoedit <playername> <skillname> <newvalue>"; //TODO: Needs more locale. String usage = ChatColor.RED + "Proper usage is /mmoedit [player] <skill> <newvalue>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) {
return true; return true;
@ -54,10 +54,13 @@ public class MmoeditCommand implements CommandExecutor {
PP.modifySkill(skill, newValue); PP.modifySkill(skill, newValue);
sender.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale. sender.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
return true;
} }
} }
else {
sender.sendMessage(usage);
}
return true;
case 3: case 3:
modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]); modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]);
@ -90,9 +93,12 @@ public class MmoeditCommand implements CommandExecutor {
if (modifiedPlayer.isOnline()) { if (modifiedPlayer.isOnline()) {
((Player) modifiedPlayer).sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale. ((Player) modifiedPlayer).sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
} }
return true;
} }
else {
sender.sendMessage(usage);
}
return true;
default: default:
sender.sendMessage(usage); sender.sendMessage(usage);

View File

@ -1,124 +1,88 @@
package com.gmail.nossr50.commands.general; package com.gmail.nossr50.commands.general;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public class XprateCommand implements CommandExecutor { public class XprateCommand implements CommandExecutor {
private static int oldrate = LoadProperties.xpGainMultiplier; private static int oldrate = LoadProperties.xpGainMultiplier;
public static boolean xpevent = false;
public static boolean xpevent = false; @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage1 = mcLocale.getString("Commands.xprate.proper");
String usage2 = mcLocale.getString("Commands.xprate.proper2");
String usage3 = mcLocale.getString("Commands.xprate.proper3");
@Override if (CommandHelper.noCommandPermissions(sender, "mcmmo.admin")) {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { return true;
}
if (!(sender instanceof Player)) { switch (args.length) {
if(args.length <= 0) case 1:
{ if (args[0].equalsIgnoreCase("reset")) {
System.out.println(mcLocale.getString("Commands.xprate.proper", new Object[] {"xprate"})); if (xpevent) {
System.out.println(mcLocale.getString("Commands.xprate.proper2", new Object[] {"xprate"})); for (Player x : Bukkit.getServer().getOnlinePlayers()) {
} x.sendMessage(mcLocale.getString("Commands.xprate.over"));
}
if(args.length == 1 && args[0].equalsIgnoreCase("reset")) xpevent = !xpevent;
{ LoadProperties.xpGainMultiplier = oldrate;
if(xpevent) }
{ else {
for(Player x : Bukkit.getServer().getOnlinePlayers()) LoadProperties.xpGainMultiplier = oldrate;
x.sendMessage(mcLocale.getString("Commands.xprate.over")); }
xpevent = !xpevent; }
LoadProperties.xpGainMultiplier = oldrate; else if (m.isInt(args[0])) {
} else sender.sendMessage(usage3);
{ }
LoadProperties.xpGainMultiplier = oldrate; else {
} sender.sendMessage(usage2);
} }
if(args.length >= 1 && m.isInt(args[0])) return true;
{
oldrate = LoadProperties.xpGainMultiplier;
if(args.length >= 2 && (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false"))) case 2:
{ if (m.isInt(args[0])) {
if(args[1].equalsIgnoreCase("true")) oldrate = LoadProperties.xpGainMultiplier;
xpevent = true;
else
xpevent = false;
} else
{
System.out.println(mcLocale.getString("Commands.xprate.proper3"));
return true;
}
LoadProperties.xpGainMultiplier = m.getInt(args[0]);
if(xpevent = true)
for(Player x : Bukkit.getServer().getOnlinePlayers())
{
x.sendMessage(ChatColor.GOLD+"XP EVENT FOR mcMMO HAS STARTED!"); //TODO: Needs more locale.
x.sendMessage(ChatColor.GOLD+"mcMMO XP RATE IS NOW "+LoadProperties.xpGainMultiplier+"x!!"); //TODO: Needs more locale.
}
System.out.println("The XP RATE was modified to "+LoadProperties.xpGainMultiplier); //TODO: Needs more locale. if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) {
} xpevent = Boolean.valueOf(args[1]);
}
else {
sender.sendMessage(usage3);
}
return true; LoadProperties.xpGainMultiplier = m.getInt(args[0]);
}
Player player = (Player) sender; if (xpevent) {
for (Player x : Bukkit.getServer().getOnlinePlayers()) {
x.sendMessage(mcLocale.getString("Commands.xprate.started"));
x.sendMessage(mcLocale.getString("Commands.xprate.started2", new Object[] {LoadProperties.xpGainMultiplier}));
}
}
else {
sender.sendMessage("The XP RATE was modified to " + LoadProperties.xpGainMultiplier); //TODO: Locale
}
}
else {
sender.sendMessage(usage1);
sender.sendMessage(usage2);
}
if(!mcPermissions.getInstance().admin(player)) return true;
{
player.sendMessage(ChatColor.YELLOW+"[mcMMO] "+ChatColor.DARK_RED +mcLocale.getString("mcPlayerListener.NoPermission"));
return true;
}
if(args.length <= 0)
{
player.sendMessage(mcLocale.getString("Commands.xprate.proper", new Object[] {"xprate"}));
player.sendMessage(mcLocale.getString("Commands.xprate.proper2", new Object[] {"xprate"}));
}
if(args.length == 1 && args[0].equalsIgnoreCase("reset"))
{
if(xpevent)
{
for(Player x : Bukkit.getServer().getOnlinePlayers())
x.sendMessage(mcLocale.getString("Commands.xprate.over"));
xpevent = !xpevent;
LoadProperties.xpGainMultiplier = oldrate;
} else
{
LoadProperties.xpGainMultiplier = oldrate;
}
}
if(args.length >= 1 && m.isInt(args[0]))
{
oldrate = LoadProperties.xpGainMultiplier;
if(args.length >= 2 && (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false"))) default:
{ sender.sendMessage(usage1);
if(args[1].equalsIgnoreCase("true")) sender.sendMessage(usage2);
xpevent = true; return true;
else }
xpevent = false; }
} else
{
player.sendMessage(mcLocale.getString("Commands.xprate.proper3"));
return true;
}
LoadProperties.xpGainMultiplier = m.getInt(args[0]);
if(xpevent = true)
for(Player x : Bukkit.getServer().getOnlinePlayers())
{
x.sendMessage(mcLocale.getString("Commands.xprate.started"));
x.sendMessage(mcLocale.getString("Commands.xprate.started2", new Object[] {LoadProperties.xpGainMultiplier}));
}
}
return true;
}
} }

View File

@ -30,7 +30,7 @@ public class mcPermissions {
} }
public boolean arcaneBypass(Player player) { public boolean arcaneBypass(Player player) {
return player.hasPermission(("mcmmo.bypass.arcanebypass")); return player.hasPermission("mcmmo.bypass.arcanebypass");
} }
/* /*

View File

@ -321,12 +321,12 @@ Party.PasswordSet=[[GREEN]]Party password set to {0}
Party.CouldNotKick=[[DARK_RED]]Could not kick player {0} Party.CouldNotKick=[[DARK_RED]]Could not kick player {0}
Party.NotInYourParty=[[DARK_RED]]{0} is not in your party Party.NotInYourParty=[[DARK_RED]]{0} is not in your party
Party.CouldNotSetOwner=[[DARK_RED]]Could not set owner to {0} Party.CouldNotSetOwner=[[DARK_RED]]Could not set owner to {0}
Commands.xprate.proper=[[DARK_AQUA]]Proper usage is /{0} [integer] [true:false] Commands.xprate.proper=[[RED]]Proper usage to change the XP rate is /xprate <integer> <true/false>
Commands.xprate.proper2=[[DARK_AQUA]]Also you can type /{0} reset to turn everything back to normal Commands.xprate.proper2=[[RED]]Proper usage to reset the XP rate to default is /xprate reset
Commands.xprate.proper3=[[RED]]Enter true or false for the second value Commands.xprate.proper3=[[RED]]Please specify true or false to indicate if this is an xp event or not
Commands.xprate.over=[[RED]]mcMMO XP Rate Event is OVER!! Commands.xprate.over=[[RED]]mcMMO XP Rate Event is OVER!!
Commands.xprate.started=[[GOLD]]XP EVENT FOR mcMMO HAS STARTED! Commands.xprate.started=[[GOLD]]XP EVENT FOR mcMMO HAS STARTED!
Commands.xprate.started2=[[GOLD]]mcMMO XP RATE IS NOW {0}x!! Commands.xprate.started2=[[GOLD]]mcMMO XP RATE IS NOW {0}x!
Commands.xplock.locked=[[GOLD]]Your XP BAR is now locked to {0}! Commands.xplock.locked=[[GOLD]]Your XP BAR is now locked to {0}!
Commands.xplock.unlocked=[[GOLD]]Your XP BAR is now [[GREEN]]UNLOCKED[[GOLD]]! Commands.xplock.unlocked=[[GOLD]]Your XP BAR is now [[GREEN]]UNLOCKED[[GOLD]]!
Commands.xplock.invalid=[[RED]]That is not a valid skillname! Try /xplock mining Commands.xplock.invalid=[[RED]]That is not a valid skillname! Try /xplock mining