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

51 lines
1.8 KiB
Java
Raw Normal View History

2020-04-14 06:40:22 +00:00
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
@CommandParameters(description = "Check your permissions", usage = "/<command> [prefix | reload]")
public class Command_permissions extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length > 0 && args[0].equalsIgnoreCase("reload") && plugin.al.isAdmin(sender))
2020-04-14 06:40:22 +00:00
{
plugin.permissions.load();
plugin.pem.loadPermissionNodes();
plugin.pem.updatePlayers();
msg("Reloaded permissions");
}
else
{
String prefix = "";
if (args.length > 0)
{
prefix = args[0];
}
checkPlayer();
List<String> permissions = new ArrayList<>();
for (PermissionAttachmentInfo attachmentInfo : playerSender.getEffectivePermissions())
{
if (attachmentInfo.getValue())
{
String permission = attachmentInfo.getPermission();
if (!prefix.isEmpty() && !permission.startsWith(prefix))
{
continue;
}
permissions.add(permission);
}
}
msg(String.join(", ", permissions));
}
return true;
}
}