TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java

199 lines
5.8 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2019-01-28 01:49:07 +00:00
import com.google.common.collect.Lists;
import java.util.List;
import lombok.Getter;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.player.PlayerData;
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.command.AbstractCommandBase;
import net.pravian.aero.util.Players;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
2019-01-28 01:49:07 +00:00
import org.bukkit.util.StringUtil;
2019-11-03 21:40:05 +00:00
import org.spigotmc.SpigotConfig;
public abstract class FreedomCommand extends AbstractCommandBase<TotalFreedomMod>
{
2019-11-03 21:40:05 +00:00
public static final String UNKNOWN_COMMAND = ChatColor.WHITE + SpigotConfig.unknownCommandMessage;
public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!";
//
@Getter
private final CommandParameters params;
@Getter
private final CommandPermissions perms;
public FreedomCommand()
{
this.params = getClass().getAnnotation(CommandParameters.class);
if (params == null)
{
FLog.warning("Ignoring command usage for command " + getClass().getSimpleName() + ". Command is not annotated!");
}
this.perms = getClass().getAnnotation(CommandPermissions.class);
if (perms == null)
{
FLog.warning("Ignoring permissions for command " + getClass().getSimpleName() + ". Command is not annotated!");
}
}
@Override
public final boolean runCommand(final CommandSender sender, final Command command, final String label, final String[] args)
{
setVariables(sender, command, label, args);
try
{
return run(sender, playerSender, command, label, args, isConsole());
}
catch (CommandFailException ex)
{
msg(ex.getMessage());
return true;
}
catch (Exception ex)
{
FLog.severe("Uncaught exception executing command: " + command.getName());
FLog.severe(ex);
sender.sendMessage(ChatColor.RED + "Command error: " + (ex.getMessage() == null ? "Unknown cause" : ex.getMessage()));
return true;
}
}
2019-01-28 01:49:07 +00:00
/*@Override
public List<String> tabComplete(CommandSender sender, Command command, String alias, String[] args)
{
2019-01-29 04:57:41 +00:00
return null;
2019-01-28 01:49:07 +00:00
}*/
2019-01-29 04:57:41 +00:00
// Doesn't need to do any starts-with checks
protected List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) {
return null;
}
@Override
public List<String> tabComplete(CommandSender sender, Command command, String alias, String[] args)
{
List<String> options = getTabCompleteOptions(sender, command, alias, args);
if (options == null) {
return null;
}
return StringUtil.copyPartialMatches(args[args.length - 1], options, Lists.<String>newArrayList());
}
protected abstract boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole);
2019-01-28 01:49:07 +00:00
protected void checkConsole()
{
if (!isConsole())
{
throw new CommandFailException(getHandler().getOnlyConsoleMessage());
}
}
protected void checkPlayer()
{
if (isConsole())
{
throw new CommandFailException(getHandler().getOnlyPlayerMessage());
}
}
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
protected void checkNotHostConsole()
{
if (isConsole() && FUtil.isFromHostConsole(sender.getName()))
{
throw new CommandFailException("This command can not be used from the host console.");
}
}
protected void checkRank(Rank rank)
{
if (!plugin.rm.getRank(sender).isAtLeast(rank))
{
noPerms();
}
}
protected boolean noPerms()
{
throw new CommandFailException(getHandler().getPermissionMessage());
}
protected boolean isConsole()
{
return !(sender instanceof Player);
}
protected Player getPlayer(String name)
{
return Players.getPlayer(name);
}
protected void msg(final CommandSender sender, final String message, final ChatColor color)
{
if (sender == null)
{
return;
}
sender.sendMessage(color + message);
}
protected void msg(final String message, final ChatColor color)
{
msg(sender, message, color);
}
protected void msg(final CommandSender sender, final String message)
{
msg(sender, message, ChatColor.GRAY);
}
protected void msg(final String message)
{
msg(sender, message);
}
protected boolean isAdmin(CommandSender sender)
{
return plugin.al.isAdmin(sender);
}
protected Admin getAdmin(CommandSender sender)
{
return plugin.al.getAdmin(sender);
}
protected Admin getAdmin(Player player)
{
return plugin.al.getAdmin(player);
}
protected PlayerData getData(Player player)
{
return plugin.pl.getData(player);
}
public static FreedomCommand getFrom(Command command)
{
try
{
return (FreedomCommand)((FreedomCommandExecutor)(((PluginCommand)command).getExecutor())).getCommandBase();
}
catch (Exception ex)
{
return null;
}
}
}