2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands;
|
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2013-03-28 17:57:49 +01:00
|
|
|
import org.bukkit.command.TabExecutor;
|
|
|
|
import org.bukkit.util.StringUtil;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-08-23 10:16:22 +02:00
|
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
2013-03-12 21:25:42 +01:00
|
|
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
|
|
public class XprateCommand implements TabExecutor {
|
2013-10-29 20:38:20 +01:00
|
|
|
private final double ORIGINAL_XP_RATE = ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
if (!args[0].equalsIgnoreCase("reset")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Permissions.xprateReset(sender)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mcMMO.p.isXPEventEnabled()) {
|
|
|
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.over"));
|
|
|
|
mcMMO.p.toggleXpEventEnabled();
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
ExperienceConfig.getInstance().setExperienceGainsGlobalMultiplier(ORIGINAL_XP_RATE);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case 2:
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.isInvalidInteger(sender, args[0])) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!Permissions.xprateSet(sender)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.shouldDisableToggle(args[1])) {
|
|
|
|
mcMMO.p.setXPEventEnabled(false);
|
|
|
|
}
|
|
|
|
else if (CommandUtils.shouldEnableToggle(args[1])) {
|
|
|
|
mcMMO.p.setXPEventEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int newXpRate = Integer.parseInt(args[0]);
|
2013-08-23 10:16:22 +02:00
|
|
|
ExperienceConfig.getInstance().setExperienceGainsGlobalMultiplier(newXpRate);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
if (mcMMO.p.isXPEventEnabled()) {
|
|
|
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.started.0"));
|
|
|
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.started.1", newXpRate));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", newXpRate));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-03-28 17:57:49 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
if (StringUtils.isInt(args[0])) {
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
|
|
|
|
return StringUtil.copyPartialMatches(args[0], CommandUtils.RESET_OPTIONS, new ArrayList<String>(CommandUtils.RESET_OPTIONS.size()));
|
|
|
|
case 2:
|
|
|
|
return StringUtil.copyPartialMatches(args[1], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<String>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
|
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|