2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands;
|
|
|
|
|
2019-01-14 11:32:02 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2019-05-16 20:34:26 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
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;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
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;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.util.player.NotificationManager;
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2019-05-17 13:27:27 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2019-01-15 12:50:12 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.TabExecutor;
|
2019-05-17 13:27:27 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.util.StringUtil;
|
|
|
|
|
2019-05-17 13:27:27 +02:00
|
|
|
import java.security.Permission;
|
2019-01-15 07:11:58 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2013-03-28 17:57:49 +01:00
|
|
|
|
|
|
|
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:
|
2019-01-15 12:50:12 +01:00
|
|
|
if (!args[0].equalsIgnoreCase("reset") && !args[0].equalsIgnoreCase("clear")) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Permissions.xprateReset(sender)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mcMMO.p.isXPEventEnabled()) {
|
2019-01-15 12:50:12 +01:00
|
|
|
|
|
|
|
if(AdvancedConfig.getInstance().useTitlesForXPEvent())
|
|
|
|
{
|
|
|
|
NotificationManager.broadcastTitle(mcMMO.p.getServer(),
|
|
|
|
LocaleLoader.getString("Commands.Event.Stop"),
|
|
|
|
LocaleLoader.getString("Commands.Event.Stop.Subtitle"),
|
|
|
|
10, 10*20, 20);
|
|
|
|
}
|
|
|
|
|
2019-05-16 20:34:26 +02:00
|
|
|
if(Config.getInstance().broadcastEventMessages())
|
|
|
|
{
|
|
|
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.Stop"));
|
|
|
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.Stop.Subtitle"));
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:27:27 +02:00
|
|
|
for(Player player : Bukkit.getServer().getOnlinePlayers())
|
|
|
|
{
|
|
|
|
if(player.isOp() || Permissions.adminChat(player))
|
|
|
|
{
|
|
|
|
String senderName = LocaleLoader.getString("Server.ConsoleName");
|
|
|
|
|
|
|
|
if(sender instanceof Player)
|
|
|
|
{
|
|
|
|
senderName = ((Player) sender).getDisplayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("XPRate.AdminDetails.End", senderName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("XPRate.End"));
|
|
|
|
|
2019-01-15 12:50:12 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
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]);
|
2019-01-15 12:50:12 +01:00
|
|
|
|
|
|
|
if(newXpRate < 0)
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED+LocaleLoader.getString("Commands.NegativeNumberWarn"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-23 10:16:22 +02:00
|
|
|
ExperienceConfig.getInstance().setExperienceGainsGlobalMultiplier(newXpRate);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2019-05-17 13:27:27 +02:00
|
|
|
if(AdvancedConfig.getInstance().useTitlesForXPEvent())
|
|
|
|
{
|
|
|
|
NotificationManager.broadcastTitle(mcMMO.p.getServer(),
|
|
|
|
LocaleLoader.getString("Commands.Event.Start"),
|
|
|
|
LocaleLoader.getString("Commands.Event.XP", newXpRate),
|
|
|
|
10, 10*20, 20);
|
|
|
|
}
|
2019-05-16 20:34:26 +02:00
|
|
|
|
2019-05-17 13:27:27 +02:00
|
|
|
if(Config.getInstance().broadcastEventMessages())
|
|
|
|
{
|
|
|
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.Start"));
|
|
|
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.XP", newXpRate));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Player player : Bukkit.getServer().getOnlinePlayers())
|
|
|
|
{
|
|
|
|
if(player.isOp() || Permissions.adminChat(player))
|
2019-05-16 20:34:26 +02:00
|
|
|
{
|
2019-05-17 13:27:27 +02:00
|
|
|
String senderName = LocaleLoader.getString("Server.ConsoleName");
|
2019-05-16 20:34:26 +02:00
|
|
|
|
2019-05-17 13:27:27 +02:00
|
|
|
if(sender instanceof Player)
|
|
|
|
{
|
|
|
|
senderName = ((Player) sender).getDisplayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("XPRate.AdminDetails.Start", senderName, newXpRate));
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2019-05-17 13:27:27 +02:00
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("XPRate.Modified", newXpRate));
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|