Actually add Player as a field to the commands

This commit is contained in:
Telesphoreo 2022-02-03 22:01:30 -06:00
parent fe53f5c49f
commit 081a702c70
25 changed files with 81 additions and 50 deletions

View File

@ -28,10 +28,13 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class PlexCommand extends Command
public abstract class PlexCommand extends Command implements PluginIdentifiableCommand
{
protected static Plex plugin = Plex.get();
@ -61,7 +64,7 @@ public abstract class PlexCommand extends Command
getMap().register("plex", this);
}
protected abstract Component execute(CommandSender sender, String[] args);
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
@Override
@ -113,7 +116,7 @@ public abstract class PlexCommand extends Command
}
try
{
Component component = this.execute(sender, args);
Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args);
if (component != null)
{
send(sender, component);
@ -237,6 +240,12 @@ public abstract class PlexCommand extends Command
return player.getUniqueId();
}
@Override
public @NotNull Plugin getPlugin()
{
return plugin;
}
protected boolean isConsole(CommandSender sender)
{

View File

@ -21,6 +21,7 @@ import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.ANY)
@ -30,7 +31,7 @@ public class AdminCMD extends PlexCommand
//TODO: Better return messages
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -16,13 +16,13 @@ import org.bukkit.entity.Player;
public class AdminworldCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
// TODO: Add adminworld settings
if (args.length == 0)
{
Location loc = new Location(Bukkit.getWorld("adminworld"), 0, 50, 0);
((Player)sender).teleportAsync(loc);
playerSender.teleportAsync(loc);
return tl("teleportedToWorld", "adminworld");
}
return null;

View File

@ -22,20 +22,19 @@ public class AdventureCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
Player player = (Player)sender;
if (args.length == 0)
{
if (isConsole(sender))
{
throw new CommandFailException("You must define a player when using the console!");
}
player.setGameMode(GameMode.ADVENTURE);
playerSender.setGameMode(GameMode.ADVENTURE);
return tl("gameModeSetTo", "adventure");
}
if (checkRank(player, Rank.ADMIN, "plex.gamemode.adventure.others"))
if (checkRank(playerSender, Rank.ADMIN, "plex.gamemode.adventure.others"))
{
if (args[0].equals("-a"))
{

View File

@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
public class BanCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -21,20 +21,19 @@ import org.jetbrains.annotations.NotNull;
public class CreativeCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
Player player = (Player)sender;
if (args.length == 0)
{
if (isConsole(sender))
{
throw new CommandFailException("You must define a player when using the console!");
}
player.setGameMode(GameMode.CREATIVE);
playerSender.setGameMode(GameMode.CREATIVE);
return tl("gameModeSetTo", "creative");
}
if (checkRank(player, Rank.ADMIN, "plex.gamemode.creative.others"))
if (checkRank(playerSender, Rank.ADMIN, "plex.gamemode.creative.others"))
{
if (args[0].equals("-a"))
{

View File

@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
public class DeopAllCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
for (Player player : Bukkit.getOnlinePlayers())
{

View File

@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull;
public class DeopCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length != 1)
{

View File

@ -17,12 +17,12 @@ public class FlatlandsCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length == 0)
{
Location loc = new Location(Bukkit.getWorld("flatlands"), 0, 50, 0);
((Player)sender).teleportAsync(loc);
playerSender.teleportAsync(loc);
return tl("teleportedToWorld", "flatlands");
}
return null;

View File

@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
public class FreezeCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length != 1)
{

View File

@ -12,23 +12,25 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandParameters(name = "list", description = "Show a list of all online players", usage = "/<command> <player>")
@CommandParameters(name = "list", description = "Show a list of all online players")
@CommandPermissions(level = Rank.OP, permission = "plex.list")
public class ListCMD extends PlexCommand
{
@Override
protected Component execute(CommandSender sender, String[] args)
protected Component execute(CommandSender sender, Player playerSender, String[] args)
{
List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers());
Component component = Component.text("There " + (players.size() > 1 ? "are" : "is") + " currently").color(NamedTextColor.GRAY)
Component component = Component.text("There " + (players.size() == 1 ? "is" : "are") + " currently").color(NamedTextColor.GRAY)
.append(Component.space())
.append(Component.text(players.size()).color(NamedTextColor.YELLOW))
.append(Component.space())
.append(Component.text(players.size() > 1 ? "players " : "player " + "online out of").color(NamedTextColor.GRAY))
.append(Component.text(players.size() == 1 ? "player" : "players").color(NamedTextColor.GRAY))
.append(Component.space())
.append(Component.text("online out of").color(NamedTextColor.GRAY))
.append(Component.space())
.append(Component.text(Bukkit.getMaxPlayers()).color(NamedTextColor.YELLOW))
.append(Component.newline())
.append(Component.text("players").color(NamedTextColor.GRAY))
.append(Component.space())
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY))
.append(Component.newline());
for (int i = 0; i < players.size(); i++)
{

View File

@ -0,0 +1,21 @@
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.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
@CommandPermissions(level = Rank.OP, permission = "plex.spawnpoint")
public class LocalSpawnCMD extends PlexCommand
{
@Override
protected Component execute(CommandSender sender, Player playerSender, String[] args)
{
playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation());
return tl("teleportedToWorldSpawn");
}
}

View File

@ -17,13 +17,13 @@ public class MasterbuilderworldCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
// TODO: Add adminworld settings
if (args.length == 0)
{
Location loc = new Location(Bukkit.getWorld("masterbuilderworld"), 0, 50, 0);
((Player)sender).teleportAsync(loc);
playerSender.teleportAsync(loc);
return tl("teleportedToWorld", "Master Builder World");
}
return null;

View File

@ -21,6 +21,7 @@ import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@CommandParameters(name = "namehistory", description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
@ -30,7 +31,7 @@ public class NameHistoryCMD extends PlexCommand
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' HH:mm:ss");
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length != 1)
{
@ -38,7 +39,6 @@ public class NameHistoryCMD extends PlexCommand
}
String username = args[0];
UUID uuid;
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(username);
if (offlinePlayer != null)

View File

@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
public class OpAllCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
for (Player player : Bukkit.getOnlinePlayers())
{

View File

@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull;
public class OpCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length != 1)
{

View File

@ -12,6 +12,7 @@ import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY)
@ -20,7 +21,7 @@ public class PlexCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -19,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
public class PunishmentsCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
new PunishmentMenu().openInv(((Player)sender), 0);
return null;

View File

@ -16,8 +16,8 @@ import org.bukkit.entity.Player;
public class RankCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
return tl("yourRank", getPlexPlayer((Player)sender).getRank());
return tl("yourRank", getPlexPlayer(playerSender).getLoginMSG());
}
}

View File

@ -21,20 +21,19 @@ import org.jetbrains.annotations.NotNull;
public class SpectatorCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
Player player = (Player)sender;
if (args.length == 0)
{
if (isConsole(sender))
{
throw new CommandFailException("You must define a player when using the console!");
}
player.setGameMode(GameMode.SPECTATOR);
playerSender.setGameMode(GameMode.SPECTATOR);
return tl("gameModeSetTo", "spectator");
}
if (checkRank(player, Rank.ADMIN, "plex.gamemode.spectator.others"))
if (checkRank(playerSender, Rank.ADMIN, "plex.gamemode.spectator.others"))
{
if (args[0].equals("-a"))
{

View File

@ -21,20 +21,19 @@ import org.jetbrains.annotations.NotNull;
public class SurvivalCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
Player player = (Player)sender;
if (args.length == 0)
{
if (isConsole(sender))
{
throw new CommandFailException("You must define a player when using the console!");
}
player.setGameMode(GameMode.SURVIVAL);
playerSender.setGameMode(GameMode.SURVIVAL);
return tl("gameModeSetTo", "survival");
}
if (checkRank(player, Rank.ADMIN, "plex.gamemode.survival.others"))
if (checkRank(playerSender, Rank.ADMIN, "plex.gamemode.survival.others"))
{
if (args[0].equals("-a"))
{

View File

@ -15,6 +15,7 @@ import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
@ -23,7 +24,7 @@ import org.jetbrains.annotations.NotNull;
public class UnbanCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -21,16 +21,15 @@ import org.jetbrains.annotations.NotNull;
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
public class WorldCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, String[] args)
public Component execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length != 1)
{
throw new CommandArgumentException();
}
World world = getNonNullWorld(args[0]);
((Player)sender).teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
playerSender.teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
return tl("playerWorldTeleport", world.getName());
}
@ -43,5 +42,4 @@ public class WorldCMD extends PlexCommand
}
return ImmutableList.of();
}
}

View File

@ -28,6 +28,7 @@ public class CommandHandler extends PlexBase
commands.add(new FlatlandsCMD());
commands.add(new FreezeCMD());
commands.add(new ListCMD());
commands.add(new LocalSpawnCMD());
commands.add(new MasterbuilderworldCMD());
commands.add(new NameHistoryCMD());
commands.add(new PlexCMD());

View File

@ -70,4 +70,5 @@ consoleOnly: "<e>This command can only be executed by the console."
yourRank: "<b>Your rank is: <v>"
banningPlayer: "<e><v> - Banning <v>"
unbanningPlayer: "<b><v> - Unbanning <v>"
playerNotBanned: "<e>That player is not banned!"
playerNotBanned: "<e>That player is not banned!"
teleportedToWorldSpawn: "<b>Teleporting to the local spawn"