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

97 lines
3.7 KiB
Java
Raw Normal View History

package com.gmail.nossr50.commands.admin;
2012-01-09 20:00:13 +01:00
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;
import com.gmail.nossr50.util.Permissions;
2012-01-09 20:00:13 +01:00
public class XprateCommand implements CommandExecutor {
2013-01-26 23:01:55 +01:00
private static double originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
2012-04-21 00:09:50 +02:00
@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.commands.xprate") && !Permissions.admin((Player) sender)) {
return true;
}
2013-01-26 23:01:55 +01:00
boolean xpEventEnabled = mcMMO.p.isXPEventEnabled();
switch (args.length) {
case 1:
if (args[0].equalsIgnoreCase("reset")) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.xprate.reset") && !Permissions.admin((Player) sender)) {
return true;
}
2013-01-26 23:01:55 +01:00
if (xpEventEnabled) {
for (Player x : mcMMO.p.getServer().getOnlinePlayers()) {
2012-04-27 11:47:11 +02:00
x.sendMessage(LocaleLoader.getString("Commands.xprate.over"));
}
2013-01-26 23:01:55 +01:00
mcMMO.p.setXPEventEnabled(!xpEventEnabled);
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
}
else {
2013-01-26 23:01:55 +01:00
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
}
}
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])) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.xprate.set") && !Permissions.admin((Player) sender)) {
return true;
}
if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) {
2013-01-26 23:01:55 +01:00
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
}
else {
sender.sendMessage(usage3);
}
2013-01-26 23:01:55 +01:00
int newRate = Misc.getInt(args[0]);
Config.getInstance().setExperienceGainsGlobalMultiplier(newRate);
2013-01-26 23:01:55 +01:00
if (xpEventEnabled) {
for (Player x : mcMMO.p.getServer().getOnlinePlayers()) {
2012-04-27 11:47:11 +02:00
x.sendMessage(LocaleLoader.getString("Commands.xprate.started.0"));
2013-01-26 23:01:55 +01:00
x.sendMessage(LocaleLoader.getString("Commands.xprate.started.1", new Object[] {newRate}));
}
}
else {
2013-01-26 23:01:55 +01:00
sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", new Object[] {newRate}));
}
}
else {
sender.sendMessage(usage1);
sender.sendMessage(usage2);
}
return true;
default:
sender.sendMessage(usage1);
sender.sendMessage(usage2);
return true;
}
}
2012-01-09 20:00:13 +01:00
}