mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Begin fixing command system
This commit is contained in:
parent
edef4d8558
commit
587ea8f352
@ -1,12 +0,0 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import dev.plex.command.source.CommandSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IPlexCommand
|
||||
{
|
||||
void execute(CommandSource sender, String[] args);
|
||||
|
||||
List<String> onTabComplete(CommandSource sender, String[] args);
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
@ -9,22 +8,25 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class PlexCommand extends Command implements TabExecutor, IPlexCommand
|
||||
public abstract class PlexCommand extends Command
|
||||
{
|
||||
protected static Plex plugin = Plex.get();
|
||||
|
||||
@ -32,19 +34,18 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
private final CommandPermissions perms;
|
||||
|
||||
private final Rank level;
|
||||
private CommandSource sender;
|
||||
private final RequiredCommandSource commandSource;
|
||||
|
||||
public PlexCommand(String name)
|
||||
public PlexCommand()
|
||||
{
|
||||
super(name);
|
||||
super("");
|
||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
||||
|
||||
setName(name);
|
||||
setLabel(name);
|
||||
setName(this.params.name());
|
||||
setLabel(this.params.name());
|
||||
setDescription(params.description());
|
||||
setUsage(params.usage().replace("<command>", name));
|
||||
setUsage(params.usage().replace("<command>", this.params.name()));
|
||||
if (params.aliases().split(",").length > 0)
|
||||
{
|
||||
setAliases(Arrays.asList(params.aliases().split(",")));
|
||||
@ -55,16 +56,11 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
getMap().register("plex", this);
|
||||
}
|
||||
|
||||
protected abstract Component execute(CommandSender sender, String[] args);
|
||||
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args)
|
||||
{
|
||||
onCommand(sender, this, label, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String label, String[] args)
|
||||
{
|
||||
if (!matches(label))
|
||||
{
|
||||
@ -85,7 +81,6 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
this.sender = new CommandSource(player);
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||
{
|
||||
@ -95,55 +90,23 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
}
|
||||
try
|
||||
{
|
||||
this.sender = new CommandSource(sender);
|
||||
execute(this.sender, args);
|
||||
Component component = this.execute(sender, args);
|
||||
if (component != null)
|
||||
{
|
||||
sender.sendMessage(component);
|
||||
}
|
||||
}
|
||||
catch (CommandArgumentException ex)
|
||||
{
|
||||
send(getUsage().replace("<command>", getLabel()));
|
||||
send(sender, getUsage().replace("<command>", getLabel()));
|
||||
}
|
||||
catch (PlayerNotFoundException | CommandFailException ex)
|
||||
{
|
||||
send(ex.getMessage());
|
||||
send(sender, ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
|
||||
{
|
||||
if (!matches(alias))
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
Player player = (Player)sender;
|
||||
|
||||
this.sender = new CommandSource(player);
|
||||
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||
{
|
||||
return onTabComplete(this.sender, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sender = new CommandSource(sender);
|
||||
return onTabComplete(this.sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args)
|
||||
{
|
||||
return tabComplete(sender, label, args);
|
||||
}
|
||||
|
||||
private boolean matches(String label)
|
||||
{
|
||||
@ -164,11 +127,6 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void send(String s, CommandSource sender)
|
||||
{
|
||||
sender.send(s);
|
||||
}
|
||||
|
||||
protected void send(String s, Player player)
|
||||
{
|
||||
player.sendMessage(s);
|
||||
@ -185,28 +143,35 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected boolean isConsole()
|
||||
protected boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return !(sender instanceof Player);
|
||||
}
|
||||
|
||||
protected String tl(String s, Object... objects)
|
||||
protected Component tl(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.tl(s, objects);
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(PlexUtils.tl(s, objects));
|
||||
}
|
||||
|
||||
protected String usage(String s)
|
||||
protected Component usage(String s)
|
||||
{
|
||||
return ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s;
|
||||
return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW)
|
||||
.append(Component.text(s).color(NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
protected void send(String s)
|
||||
protected void send(Audience audience, String s)
|
||||
{
|
||||
if (sender == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
send(s, sender);
|
||||
audience.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(s));
|
||||
}
|
||||
|
||||
protected void send(Audience audience, Component component)
|
||||
{
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
protected Component fromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
|
||||
}
|
||||
|
||||
protected Player getNonNullPlayer(String name)
|
||||
@ -245,7 +210,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
World world = Bukkit.getWorld(name);
|
||||
if (world == null)
|
||||
{
|
||||
throw new CommandFailException(tl("worldNotFound"));
|
||||
throw new CommandFailException(PlexUtils.tl("worldNotFound"));
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandParameters
|
||||
{
|
||||
String name();
|
||||
|
||||
String description() default "";
|
||||
|
||||
String usage() default "/<command>";
|
||||
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.ConsoleOnlyException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.AdminAddEvent;
|
||||
import dev.plex.event.AdminRemoveEvent;
|
||||
@ -15,44 +14,40 @@ import dev.plex.event.AdminSetRankEvent;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
||||
@CommandParameters(name = "admin", usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
||||
public class AdminCMD extends PlexCommand
|
||||
{
|
||||
//TODO: Better return messages
|
||||
|
||||
public AdminCMD()
|
||||
{
|
||||
super("admin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
sender.send(usage(getUsage()));
|
||||
return;
|
||||
return usage(getUsage());
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
sender.send(usage("/admin add <player>"));
|
||||
return;
|
||||
return usage("/admin add <player>");
|
||||
}
|
||||
|
||||
if (!sender.isConsoleSender())
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
sender.send(tl("consoleOnly"));
|
||||
send(sender, tl("consoleOnly"));
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
|
||||
@ -66,24 +61,22 @@ public class AdminCMD extends PlexCommand
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
sender.send(tl("playerIsAdmin"));
|
||||
return;
|
||||
return tl("playerIsAdmin");
|
||||
}
|
||||
|
||||
plexPlayer.setRank(Rank.ADMIN.name());
|
||||
DataUtils.update(plexPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("remove"))
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
sender.send(usage("/admin remove <player>"));
|
||||
return;
|
||||
return usage("/admin remove <player>");
|
||||
}
|
||||
|
||||
if (!sender.isConsoleSender())
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
@ -98,25 +91,23 @@ public class AdminCMD extends PlexCommand
|
||||
|
||||
if (!isAdmin(plexPlayer))
|
||||
{
|
||||
sender.send(tl("playerNotAdmin"));
|
||||
return;
|
||||
return tl("playerNotAdmin");
|
||||
}
|
||||
|
||||
plexPlayer.setRank("");
|
||||
DataUtils.update(plexPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("setrank"))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
sender.send(usage("/admin setrank <player> <rank>"));
|
||||
return;
|
||||
return usage("/admin setrank <player> <rank>");
|
||||
}
|
||||
|
||||
if (!sender.isConsoleSender())
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
@ -130,24 +121,21 @@ public class AdminCMD extends PlexCommand
|
||||
|
||||
if (!rankExists(args[2]))
|
||||
{
|
||||
sender.send(tl("rankNotFound"));
|
||||
return;
|
||||
return tl("rankNotFound");
|
||||
}
|
||||
|
||||
Rank rank = Rank.valueOf(args[2].toUpperCase());
|
||||
|
||||
if (!rank.isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
sender.send(tl("rankMustBeHigherThanAdmin"));
|
||||
return;
|
||||
return tl("rankMustBeHigherThanAdmin");
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
|
||||
if (!isAdmin(plexPlayer))
|
||||
{
|
||||
sender.send(tl("playerNotAdmin"));
|
||||
return;
|
||||
return tl("playerNotAdmin");
|
||||
}
|
||||
|
||||
plexPlayer.setRank(rank.name().toLowerCase());
|
||||
@ -155,23 +143,23 @@ public class AdminCMD extends PlexCommand
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
sender.send(usage("/admin list"));
|
||||
return;
|
||||
return usage("/admin list");
|
||||
}
|
||||
|
||||
sender.send("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
|
||||
return fromString("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
@ -184,6 +172,7 @@ public class AdminCMD extends PlexCommand
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
|
||||
private boolean rankExists(String rank)
|
||||
{
|
||||
for (Rank ranks : Rank.values())
|
||||
|
@ -3,39 +3,32 @@ package dev.plex.command.impl;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(aliases = "aw", description = "Teleport to the adminworld")
|
||||
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
|
||||
public class AdminworldCMD extends PlexCommand
|
||||
{
|
||||
public AdminworldCMD()
|
||||
{
|
||||
super("adminworld");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
// TODO: Add adminworld settings
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("adminworld"), 0, 50, 0);
|
||||
sender.getPlayer().teleportAsync(loc);
|
||||
send(tl("teleportedToWorld", "adminworld"));
|
||||
((Player)sender).teleportAsync(loc);
|
||||
return tl("teleportedToWorld", "adminworld");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -5,27 +5,24 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
|
||||
@CommandParameters(name = "adventure", aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
|
||||
public class AdventureCMD extends PlexCommand
|
||||
{
|
||||
public AdventureCMD()
|
||||
{
|
||||
super("adventure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
@ -61,7 +58,7 @@ public class AdventureCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
|
@ -7,7 +7,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
@ -32,7 +31,7 @@ public class BanCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
@ -80,7 +79,7 @@ public class BanCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args) {
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
@ -25,7 +24,7 @@ public class CreativeCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
@ -60,7 +59,7 @@ public class CreativeCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.world.BlockMapChunkGenerator;
|
||||
@ -34,7 +33,7 @@ public class FionnCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (!sender.getPlayer().getUniqueId().equals(UUID.fromString("9aa3eda6-c271-440a-a578-a952ee9aee2f")))
|
||||
{
|
||||
@ -125,7 +124,7 @@ public class FionnCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package dev.plex.command.impl;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -22,7 +21,7 @@ public class FlatlandsCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
@ -33,7 +32,7 @@ public class FlatlandsCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@ -29,7 +28,7 @@ public class FreezeCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
@ -49,7 +48,7 @@ public class FreezeCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package dev.plex.command.impl;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -22,7 +21,7 @@ public class MasterbuilderworldCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
// TODO: Add adminworld settings
|
||||
if (args.length == 0)
|
||||
@ -34,7 +33,7 @@ public class MasterbuilderworldCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.json.simple.JSONArray;
|
||||
@ -29,7 +28,7 @@ public class NameHistoryCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
@ -73,7 +72,7 @@ public class NameHistoryCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -22,7 +21,7 @@ public class OpAllCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
@ -32,7 +31,7 @@ public class OpAllCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,7 +21,7 @@ public class OpCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
@ -34,7 +33,7 @@ public class OpCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
|
@ -5,12 +5,10 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@ -21,7 +19,7 @@ public class PlexCMD extends PlexCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args) {
|
||||
public Component execute(CommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
send(ChatColor.LIGHT_PURPLE + "Plex. The long awaited TotalFreedomMod rewrite starts here...");
|
||||
send(ChatColor.LIGHT_PURPLE + "Plugin version: " + ChatColor.GOLD + "1.0");
|
||||
@ -47,7 +45,7 @@ public class PlexCMD extends PlexCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args) {
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return List.of("reload");
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.menu.PunishmentMenu;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
@ -23,14 +22,14 @@ public class PunishmentsCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
Player player = sender.getPlayer();
|
||||
new PunishmentMenu().openInv(player, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args) {
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package dev.plex.command.impl;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
@ -19,12 +18,12 @@ public class RankCMD extends PlexCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args) {
|
||||
public Component execute(CommandSender sender, String[] args) {
|
||||
send(tl("yourRank", sender.getPlexPlayer().getRank()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args) {
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
@ -25,7 +24,7 @@ public class SpectatorCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
@ -57,7 +56,7 @@ public class SpectatorCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
|
@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
@ -25,7 +24,7 @@ public class SurvivalCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
@ -60,7 +59,7 @@ public class SurvivalCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
|
@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
@ -21,13 +20,13 @@ public class TestCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
send(tl("variableTest", sender.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
|
@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -25,7 +24,7 @@ public class WorldCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
@ -37,7 +36,7 @@ public class WorldCMD extends PlexCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
List<String> worlds = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds())
|
||||
|
@ -1,37 +0,0 @@
|
||||
package dev.plex.command.source;
|
||||
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Getter
|
||||
public class CommandSource
|
||||
{
|
||||
private final CommandSender sender;
|
||||
private final Player player;
|
||||
private final PlexPlayer plexPlayer;
|
||||
private final boolean isConsoleSender;
|
||||
|
||||
public CommandSource(CommandSender sender)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.isConsoleSender = !(sender instanceof Player);
|
||||
this.player = sender instanceof Player ? Bukkit.getPlayer(sender.getName()) : null;
|
||||
this.plexPlayer = sender instanceof Player ? PlayerCache.getPlexPlayerMap().get(((Player)sender).getUniqueId()) : null;
|
||||
}
|
||||
|
||||
// there's a bug here where it sends it to the player not the console
|
||||
// i assume this is because there's no checking. no idea why but it always sends it to the player even if executed from the console
|
||||
public void send(String s)
|
||||
{
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return sender.getName();
|
||||
}
|
||||
}
|
@ -1,22 +1,18 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import lombok.Data;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Data
|
||||
public class AdminAddEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private CommandSource sender;
|
||||
private PlexPlayer plexPlayer;
|
||||
|
||||
public AdminAddEvent(CommandSource sender, PlexPlayer plexPlayer)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.plexPlayer = plexPlayer;
|
||||
}
|
||||
private final CommandSender sender;
|
||||
private final PlexPlayer plexPlayer;
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
@ -29,12 +25,4 @@ public class AdminAddEvent extends Event
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public PlexPlayer getPlexPlayer()
|
||||
{
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
public CommandSource getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,18 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import lombok.Data;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Data
|
||||
public class AdminRemoveEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private PlexPlayer plexPlayer;
|
||||
private CommandSource sender;
|
||||
|
||||
public AdminRemoveEvent(CommandSource sender, PlexPlayer plexPlayer)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.plexPlayer = plexPlayer;
|
||||
}
|
||||
private final CommandSender sender;
|
||||
private final PlexPlayer plexPlayer;
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
@ -28,13 +24,4 @@ public class AdminRemoveEvent extends Event
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public PlexPlayer getPlexPlayer()
|
||||
{
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
public CommandSource getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,21 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import lombok.Data;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Data
|
||||
public class AdminSetRankEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private CommandSource sender;
|
||||
private PlexPlayer plexPlayer;
|
||||
private Rank rank;
|
||||
private final CommandSender sender;
|
||||
private final PlexPlayer plexPlayer;
|
||||
private final Rank rank;
|
||||
|
||||
public AdminSetRankEvent(CommandSource sender, PlexPlayer plexPlayer, Rank rank)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.plexPlayer = plexPlayer;
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
@ -31,18 +27,4 @@ public class AdminSetRankEvent extends Event
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public PlexPlayer getPlexPlayer()
|
||||
{
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
public Rank getRank()
|
||||
{
|
||||
return rank;
|
||||
}
|
||||
|
||||
public CommandSource getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
|
@ -172,12 +172,7 @@ public class PlexUtils
|
||||
|
||||
public static List<String> getPlayerNameList()
|
||||
{
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
names.add(player.getName());
|
||||
}
|
||||
return names;
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void broadcast(String s)
|
||||
|
Loading…
Reference in New Issue
Block a user