mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-17 04:46:11 +00:00
aca3398d21
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
184 lines
5.3 KiB
Java
184 lines
5.3 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import java.util.Arrays;
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
import net.pravian.aero.command.AeroCommandBase;
|
|
import net.pravian.aero.command.executor.AbstractCommandExecutor;
|
|
import net.pravian.aero.command.executor.AeroCommandExecutor;
|
|
import net.pravian.aero.command.executor.AeroCommandExecutorFactory;
|
|
import net.pravian.aero.command.handler.AeroCommandHandler;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.PluginCommand;
|
|
import org.bukkit.entity.Player;
|
|
|
|
public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends AbstractCommandExecutor<C>
|
|
{
|
|
|
|
private final TotalFreedomMod plugin;
|
|
|
|
public FreedomCommandExecutor(TotalFreedomMod plugin, AeroCommandHandler<?> handler, String name, C command)
|
|
{
|
|
super(handler, name, command);
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
protected FreedomCommand getCommand()
|
|
{
|
|
return commandBase instanceof FreedomCommand ? (FreedomCommand) commandBase : null;
|
|
}
|
|
|
|
@Override
|
|
public void setupCommand(PluginCommand pluginCommand)
|
|
{
|
|
final FreedomCommand command = getCommand();
|
|
if (command == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
final CommandParameters params = command.getParams();
|
|
if (params == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
String aliasString = params.aliases();
|
|
|
|
if (aliasString.length() > 0)
|
|
{
|
|
pluginCommand.setAliases(Arrays.asList(params.aliases().split(",")));
|
|
}
|
|
pluginCommand.setDescription(params.description());
|
|
pluginCommand.setUsage(params.usage());
|
|
|
|
// Check if permisions are correctly set up
|
|
CommandPermissions perms = command.getPerms();
|
|
if (perms != null)
|
|
{
|
|
if (perms.level().isConsole())
|
|
{
|
|
FLog.warning("[Command] " + pluginCommand.getName() + " - permission is set to a console rank, "
|
|
+ "should be set to player variant with 'source = SourceType.ONLY_CONSOLE'");
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
|
{
|
|
if (!hasPermission(sender, true))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
try
|
|
{
|
|
return commandBase.runCommand(sender, command, label, args);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// If this is ever ran, TFM failed :
|
|
FLog.severe("Unhandled command exception: " + command.getName());
|
|
FLog.severe(ex);
|
|
sender.sendMessage(ChatColor.RED + "Unhandled Command Error: " + command.getName());
|
|
return true;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean hasPermission(CommandSender sender, boolean sendMsg)
|
|
{
|
|
final FreedomCommand command = getCommand();
|
|
if (command == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
final CommandPermissions perms = command.getPerms();
|
|
if (perms == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// Block host console
|
|
if (FUtil.isFromHostConsole(sender.getName())
|
|
&& perms.blockHostConsole())
|
|
{
|
|
if (sendMsg)
|
|
{
|
|
sender.sendMessage(handler.getPermissionMessage());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
final Player player = sender instanceof Player ? (Player) sender : null;
|
|
|
|
// Only console
|
|
if (perms.source() == SourceType.ONLY_CONSOLE
|
|
&& player != null)
|
|
{
|
|
if (sendMsg)
|
|
{
|
|
sender.sendMessage(handler.getOnlyConsoleMessage());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Only in game
|
|
if (perms.source() == SourceType.ONLY_IN_GAME
|
|
&& player == null)
|
|
{
|
|
if (sendMsg)
|
|
{
|
|
sender.sendMessage(handler.getOnlyPlayerMessage());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Player permissions
|
|
if (player != null)
|
|
{
|
|
Rank rank = plugin.rm.getRank(player);
|
|
boolean result = rank.isAtLeast(perms.level());
|
|
if (!result && sendMsg)
|
|
{
|
|
sender.sendMessage(handler.getPermissionMessage());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Console permissions
|
|
Rank rank = plugin.rm.getRank(sender);
|
|
boolean result = rank.isAtLeast(perms.level());
|
|
if (!result && sendMsg)
|
|
{
|
|
sender.sendMessage(handler.getPermissionMessage());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static class FreedomExecutorFactory implements AeroCommandExecutorFactory
|
|
{
|
|
|
|
private final TotalFreedomMod plugin;
|
|
|
|
public FreedomExecutorFactory(TotalFreedomMod plugin)
|
|
{
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@Override
|
|
public AeroCommandExecutor<? extends AeroCommandBase<?>> newExecutor(AeroCommandHandler<?> handler, String name, AeroCommandBase<?> command)
|
|
{
|
|
return new FreedomCommandExecutor<>(plugin, handler, name, command);
|
|
}
|
|
|
|
}
|
|
|
|
}
|