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;
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-04-04 22:12:13 +02:00
|
|
|
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;
|
2013-01-31 21:39:21 +01:00
|
|
|
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
|
|
|
|
2012-04-04 22:12:13 +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");
|
2012-04-04 22:12:13 +02:00
|
|
|
|
2013-01-31 21:39:21 +01:00
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.xprate") && !Permissions.admin((Player) sender)) {
|
2012-04-04 22:12:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
boolean xpEventEnabled = mcMMO.p.isXPEventEnabled();
|
|
|
|
|
2012-04-04 22:12:13 +02:00
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
if (args[0].equalsIgnoreCase("reset")) {
|
2013-01-31 21:39:21 +01:00
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.xprate.reset") && !Permissions.admin((Player) sender)) {
|
2013-01-30 20:10:19 +01:00
|
|
|
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"));
|
2012-04-04 22:12:13 +02:00
|
|
|
}
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
mcMMO.p.setXPEventEnabled(!xpEventEnabled);
|
|
|
|
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
|
2012-04-04 22:12:13 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-01-26 23:01:55 +01:00
|
|
|
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
|
2012-04-04 22:12:13 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
else if (Misc.isInt(args[0])) {
|
2012-04-04 22:12:13 +02:00
|
|
|
sender.sendMessage(usage3);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sender.sendMessage(usage2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 2:
|
2012-04-27 11:47:11 +02:00
|
|
|
if (Misc.isInt(args[0])) {
|
2013-01-31 21:39:21 +01:00
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.xprate.set") && !Permissions.admin((Player) sender)) {
|
2013-01-30 20:10:19 +01:00
|
|
|
return true;
|
|
|
|
}
|
2012-04-04 22:12:13 +02:00
|
|
|
if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) {
|
2013-01-26 23:01:55 +01:00
|
|
|
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
|
2012-04-04 22:12:13 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sender.sendMessage(usage3);
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
int newRate = Misc.getInt(args[0]);
|
|
|
|
Config.getInstance().setExperienceGainsGlobalMultiplier(newRate);
|
2012-04-04 22:12:13 +02:00
|
|
|
|
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}));
|
2012-04-04 22:12:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-01-26 23:01:55 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", new Object[] {newRate}));
|
2012-04-04 22:12:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|