mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-17 12:54:03 +00:00
admin cmd done
This commit is contained in:
@@ -73,21 +73,21 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
PlexLog.log(this.sender.getSender().getName());
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
{
|
||||
send(tl("noPermissionInGame"));
|
||||
sender.sendMessage(tl("noPermissionInGame"));
|
||||
return true;
|
||||
}
|
||||
if (commandSource == RequiredCommandSource.IN_GAME)
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
send(tl("noPermissionConsole"));
|
||||
sender.sendMessage(tl("noPermissionConsole"));
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||
{
|
||||
send(tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG())));
|
||||
sender.sendMessage(tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -161,6 +161,11 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
player.sendMessage(s);
|
||||
}
|
||||
|
||||
protected String usage(String s)
|
||||
{
|
||||
return ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s;
|
||||
}
|
||||
|
||||
protected void send(String s)
|
||||
{
|
||||
if (sender == null)
|
||||
|
158
src/main/java/me/totalfreedom/plex/command/impl/AdminCMD.java
Normal file
158
src/main/java/me/totalfreedom/plex/command/impl/AdminCMD.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.totalfreedom.plex.cache.DataUtils;
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.annotation.CommandParameters;
|
||||
import me.totalfreedom.plex.command.annotation.CommandPermissions;
|
||||
import me.totalfreedom.plex.command.source.CommandSource;
|
||||
import me.totalfreedom.plex.command.source.RequiredCommandSource;
|
||||
import me.totalfreedom.plex.event.AdminAddEvent;
|
||||
import me.totalfreedom.plex.event.AdminRemoveEvent;
|
||||
import me.totalfreedom.plex.event.AdminSetRankEvent;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import me.totalfreedom.plex.util.PlexUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.CONSOLE)
|
||||
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "adminconfig,adminmanage", description = "Manages all admins")
|
||||
public class AdminCMD extends PlexCommand
|
||||
{
|
||||
public AdminCMD() {
|
||||
super("admin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
sender.send(usage(getUsage()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
sender.send(usage("/admin add <player>"));
|
||||
return;
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
sender.send(PlexUtils.tl("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
plexPlayer.setRank(Rank.ADMIN.name());
|
||||
DataUtils.update(plexPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(plexPlayer));
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("remove"))
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
sender.send(usage("/admin remove <player>"));
|
||||
return;
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
sender.send(PlexUtils.tl("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
plexPlayer.setRank("");
|
||||
DataUtils.update(plexPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(plexPlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("setrank"))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
sender.send(usage("/admin setrank <player> <rank>"));
|
||||
return;
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
sender.send(PlexUtils.tl("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rankExists(args[2]))
|
||||
{
|
||||
sender.send("Rank not found");
|
||||
return;
|
||||
}
|
||||
|
||||
Rank rank = Rank.valueOf(args[2].toUpperCase());
|
||||
|
||||
if (!rank.isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
sender.send("Must be admin+");
|
||||
return;
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
plexPlayer.setRank(rank.name().toLowerCase());
|
||||
DataUtils.update(plexPlayer);
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(plexPlayer, rank));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
sender.send(usage("/admin list"));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.send("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args) {
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("add", "remove", "setrank", "list");
|
||||
} else if (args.length == 2 && !args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
private boolean rankExists(String rank)
|
||||
{
|
||||
for (Rank ranks : Rank.values())
|
||||
{
|
||||
if (ranks.name().equalsIgnoreCase(rank))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.totalfreedom.plex.cache.PlayerCache;
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.annotation.CommandParameters;
|
||||
@@ -119,7 +120,7 @@ public class FionnCMD extends PlexCommand
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return null;
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
public static void lateFakeChat(String name, String message, ChatColor color, int delay)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.totalfreedom.plex.cache.PlayerCache;
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.annotation.CommandParameters;
|
||||
@@ -39,6 +40,6 @@ public class FreezeCMD extends PlexCommand
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : null;
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.annotation.CommandParameters;
|
||||
import me.totalfreedom.plex.command.annotation.CommandPermissions;
|
||||
@@ -7,9 +8,6 @@ import me.totalfreedom.plex.command.exception.CommandArgumentException;
|
||||
import me.totalfreedom.plex.command.source.CommandSource;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import me.totalfreedom.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.ParseException;
|
||||
@@ -73,6 +71,6 @@ public class NameHistoryCMD extends PlexCommand
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : null;
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.annotation.CommandParameters;
|
||||
import me.totalfreedom.plex.command.annotation.CommandPermissions;
|
||||
@@ -32,6 +33,6 @@ public class OpAllCMD extends PlexCommand
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args) {
|
||||
return null;
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.annotation.CommandParameters;
|
||||
import me.totalfreedom.plex.command.annotation.CommandPermissions;
|
||||
@@ -35,6 +36,6 @@ public class OpCMD extends PlexCommand
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : null;
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@@ -1,18 +1,17 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.annotation.CommandParameters;
|
||||
import me.totalfreedom.plex.command.annotation.CommandPermissions;
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.source.CommandSource;
|
||||
import me.totalfreedom.plex.command.source.RequiredCommandSource;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(usage = "/<command>", aliases = "plexhelp", description = "Help with plex")
|
||||
@CommandParameters(aliases = "plexhelp", description = "Help with plex")
|
||||
public class PlexCMD extends PlexCommand
|
||||
{
|
||||
public PlexCMD() {
|
||||
|
Reference in New Issue
Block a user