mcMMO/src/main/java/com/gmail/nossr50/commands/general/XprateCommand.java

98 lines
3.3 KiB
Java
Raw Normal View History

2012-01-09 20:00:13 +01:00
package com.gmail.nossr50.commands.general;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
2012-04-26 16:27:57 +02:00
import com.gmail.nossr50.config.Config;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
2012-01-09 20:00:13 +01:00
public class XprateCommand implements CommandExecutor {
private final mcMMO plugin;
2012-08-02 01:32:25 +02:00
private static double oldRate = Config.getInstance().xpGainMultiplier;
2012-07-09 16:47:33 +02:00
private static boolean xpEvent = false;
2012-01-09 20:00:13 +01:00
public XprateCommand (mcMMO plugin) {
2012-04-21 00:09:50 +02:00
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
2012-04-27 11:47:11 +02:00
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.admin")) {
return true;
}
switch (args.length) {
case 1:
if (args[0].equalsIgnoreCase("reset")) {
2012-07-09 16:47:33 +02:00
if (xpEvent) {
2012-04-21 00:09:50 +02:00
for (Player x : plugin.getServer().getOnlinePlayers()) {
2012-04-27 11:47:11 +02:00
x.sendMessage(LocaleLoader.getString("Commands.xprate.over"));
}
2012-07-09 16:47:33 +02:00
xpEvent = !xpEvent;
Config.getInstance().xpGainMultiplier = oldRate;
}
else {
2012-07-09 16:47:33 +02:00
Config.getInstance().xpGainMultiplier = oldRate;
}
}
2012-04-27 11:47:11 +02:00
else if (Misc.isInt(args[0])) {
sender.sendMessage(usage3);
}
else {
sender.sendMessage(usage2);
}
return true;
case 2:
2012-04-27 11:47:11 +02:00
if (Misc.isInt(args[0])) {
2012-07-09 16:47:33 +02:00
oldRate = Config.getInstance().xpGainMultiplier;
if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) {
2012-07-09 16:47:33 +02:00
xpEvent = Boolean.valueOf(args[1]);
}
else {
sender.sendMessage(usage3);
}
2012-04-27 11:47:11 +02:00
Config.getInstance().xpGainMultiplier = Misc.getInt(args[0]);
2012-07-09 16:47:33 +02:00
if (xpEvent) {
2012-04-21 00:09:50 +02:00
for (Player x : plugin.getServer().getOnlinePlayers()) {
2012-04-27 11:47:11 +02:00
x.sendMessage(LocaleLoader.getString("Commands.xprate.started.0"));
x.sendMessage(LocaleLoader.getString("Commands.xprate.started.1", new Object[] {Config.getInstance().xpGainMultiplier}));
}
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", new Object[] {Config.getInstance().xpGainMultiplier}));
}
}
else {
sender.sendMessage(usage1);
sender.sendMessage(usage2);
}
return true;
default:
sender.sendMessage(usage1);
sender.sendMessage(usage2);
return true;
}
}
2012-07-09 16:46:55 +02:00
public static boolean isXpEventRunning() {
2012-07-09 16:47:33 +02:00
return xpEvent;
2012-07-09 16:46:55 +02:00
}
2012-01-09 20:00:13 +01:00
}