mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Move gamemode stuff to listener
- Fix messages in messages.yml not being used - Fixed checkRank not working - Added permissions support for tab handing
This commit is contained in:
parent
bd8c772228
commit
f2db87624f
@ -95,7 +95,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
*/
|
*/
|
||||||
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
|
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
@ -112,6 +111,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
sender.sendMessage(tl("noPermissionInGame"));
|
sender.sendMessage(tl("noPermissionInGame"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandSource == RequiredCommandSource.IN_GAME)
|
if (commandSource == RequiredCommandSource.IN_GAME)
|
||||||
{
|
{
|
||||||
if (sender instanceof ConsoleCommandSender)
|
if (sender instanceof ConsoleCommandSender)
|
||||||
@ -119,36 +119,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
send(sender, tl("noPermissionConsole"));
|
send(sender, tl("noPermissionConsole"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Player player = (Player)sender;
|
|
||||||
|
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
|
||||||
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
|
||||||
{
|
|
||||||
send(sender, tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG())));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
if (!player.hasPermission(perms.permission()))
|
|
||||||
{
|
|
||||||
send(sender, tl("noPermissionNode", perms.permission()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
|
||||||
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandSource == RequiredCommandSource.ANY)
|
|
||||||
{
|
|
||||||
if (sender instanceof Player player)
|
if (sender instanceof Player player)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||||
@ -176,7 +148,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args);
|
Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args);
|
||||||
@ -194,7 +165,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the string given is a command string
|
* Checks if the string given is a command string
|
||||||
*
|
*
|
||||||
@ -268,7 +238,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
if (!isConsole(sender))
|
if (!isConsole(sender))
|
||||||
{
|
{
|
||||||
return checkRank((Player)sender, rank, permission);
|
return checkRank((Player)sender, rank, permission);
|
||||||
// return true;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -284,10 +253,14 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
*/
|
*/
|
||||||
protected boolean checkRank(Player player, Rank rank, String permission)
|
protected boolean checkRank(Player player, Rank rank, String permission)
|
||||||
{
|
{
|
||||||
|
if (player instanceof ConsoleCommandSender)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
if (!plexPlayer.getRank().equals(rank.toString()))
|
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
{
|
{
|
||||||
throw new CommandFailException(PlexUtils.tl("noPermissionRank", ChatColor.stripColor(rank.getLoginMSG())));
|
throw new CommandFailException(PlexUtils.tl("noPermissionRank", ChatColor.stripColor(rank.getLoginMSG())));
|
||||||
}
|
}
|
||||||
@ -302,6 +275,48 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a sender has enough permissions or is high enough a rank
|
||||||
|
*
|
||||||
|
* @param sender The player object
|
||||||
|
* @param rank The rank to check (if the server is using ranks)
|
||||||
|
* @param permission The permission to check (if the server is using permissions)
|
||||||
|
* @return true if the sender has enough permissions
|
||||||
|
* @see Rank
|
||||||
|
*/
|
||||||
|
protected boolean checkTab(CommandSender sender, Rank rank, String permission)
|
||||||
|
{
|
||||||
|
if (!isConsole(sender))
|
||||||
|
{
|
||||||
|
return checkTab((Player)sender, rank, permission);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a player has enough permissions or is high enough a rank
|
||||||
|
*
|
||||||
|
* @param player The player object
|
||||||
|
* @param rank The rank to check (if the server is using ranks)
|
||||||
|
* @param permission The permission to check (if the server is using permissions)
|
||||||
|
* @return true if the sender has enough permissions
|
||||||
|
* @see Rank
|
||||||
|
*/
|
||||||
|
protected boolean checkTab(Player player, Rank rank, String permission)
|
||||||
|
{
|
||||||
|
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||||
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
|
{
|
||||||
|
return rank.isAtLeast(plexPlayer.getRankFromString());
|
||||||
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
|
{
|
||||||
|
return player.hasPermission(permission);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a player is an admin
|
* Checks if a player is an admin
|
||||||
*
|
*
|
||||||
@ -412,12 +427,22 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
/**
|
/**
|
||||||
* Converts usage to a component
|
* Converts usage to a component
|
||||||
*
|
*
|
||||||
* @param s The usage to convert
|
* @return A Kyori component stating the usage
|
||||||
* @return A kyori component stating the usage
|
*/
|
||||||
|
protected Component usage()
|
||||||
|
{
|
||||||
|
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + this.getUsage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts usage to a component
|
||||||
|
*
|
||||||
|
* s The usage to convert
|
||||||
|
* @return A Kyori component stating the usage
|
||||||
*/
|
*/
|
||||||
protected Component usage(String s)
|
protected Component usage(String s)
|
||||||
{
|
{
|
||||||
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s);
|
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + this.getUsage());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Player getNonNullPlayer(String name)
|
protected Player getNonNullPlayer(String name)
|
||||||
|
@ -36,7 +36,7 @@ public class AdminCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("add"))
|
if (args[0].equalsIgnoreCase("add"))
|
||||||
@ -64,8 +64,6 @@ public class AdminCMD extends PlexCommand
|
|||||||
return tl("playerIsAdmin");
|
return tl("playerIsAdmin");
|
||||||
}
|
}
|
||||||
|
|
||||||
plexPlayer.setRank(Rank.ADMIN.name());
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
|
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -94,8 +92,6 @@ public class AdminCMD extends PlexCommand
|
|||||||
return tl("playerNotAdmin");
|
return tl("playerNotAdmin");
|
||||||
}
|
}
|
||||||
|
|
||||||
plexPlayer.setRank("");
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
|
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -138,9 +134,6 @@ public class AdminCMD extends PlexCommand
|
|||||||
return tl("playerNotAdmin");
|
return tl("playerNotAdmin");
|
||||||
}
|
}
|
||||||
|
|
||||||
plexPlayer.setRank(rank.name().toLowerCase());
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
|
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -6,6 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -21,7 +22,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
@CommandParameters(name = "adventure", 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 class AdventureCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
{
|
{
|
||||||
@ -29,28 +29,27 @@ public class AdventureCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (isConsole(sender))
|
if (isConsole(sender))
|
||||||
{
|
{
|
||||||
throw new CommandFailException("You must define a player when using the console!");
|
throw new CommandFailException(PlexUtils.tl("consoleMustDefinePlayer"));
|
||||||
}
|
}
|
||||||
playerSender.setGameMode(GameMode.ADVENTURE);
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.ADVENTURE));
|
||||||
return tl("gameModeSetTo", "adventure");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRank(playerSender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
||||||
{
|
{
|
||||||
if (args[0].equals("-a"))
|
if (args[0].equals("-a"))
|
||||||
{
|
{
|
||||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||||
{
|
{
|
||||||
targetPlayer.setGameMode(GameMode.ADVENTURE);
|
targetPlayer.setGameMode(GameMode.ADVENTURE);
|
||||||
|
tl("gameModeSetTo", "adventure");
|
||||||
}
|
}
|
||||||
return tl("gameModeSetTo", "adventure");
|
PlexUtils.broadcast(tl("setEveryoneGameMode", sender.getName(), "adventure"));
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player nPlayer = getNonNullPlayer(args[0]);
|
Player nPlayer = getNonNullPlayer(args[0]);
|
||||||
// use send
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.ADVENTURE));
|
||||||
send(nPlayer, tl("playerSetOtherGameMode", sender.getName(), "adventure"));
|
|
||||||
nPlayer.setGameMode(GameMode.ADVENTURE);
|
|
||||||
return tl("setOtherPlayerGameModeTo", nPlayer.getName(), "adventure");
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -58,7 +57,7 @@ public class AdventureCMD extends PlexCommand
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (isAdmin(sender))
|
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class BanCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||||
|
@ -6,6 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,28 +29,31 @@ public class CreativeCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (isConsole(sender))
|
if (isConsole(sender))
|
||||||
{
|
{
|
||||||
throw new CommandFailException("You must define a player when using the console!");
|
throw new CommandFailException(PlexUtils.tl("consoleMustDefinePlayer"));
|
||||||
}
|
}
|
||||||
playerSender.setGameMode(GameMode.CREATIVE);
|
if (!(playerSender == null))
|
||||||
return tl("gameModeSetTo", "creative");
|
{
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender.getPlayer(), GameMode.CREATIVE));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRank(playerSender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
||||||
{
|
{
|
||||||
if (args[0].equals("-a"))
|
if (args[0].equals("-a"))
|
||||||
{
|
{
|
||||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||||
{
|
{
|
||||||
targetPlayer.setGameMode(GameMode.CREATIVE);
|
targetPlayer.setGameMode(GameMode.CREATIVE);
|
||||||
|
tl("gameModeSetTo", "creative");
|
||||||
}
|
}
|
||||||
return tl("gameModeSetTo", "creative");
|
PlexUtils.broadcast(tl("setEveryoneGameMode", sender.getName(), "creative"));
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player nPlayer = getNonNullPlayer(args[0]);
|
Player nPlayer = getNonNullPlayer(args[0]);
|
||||||
// use send
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.CREATIVE));
|
||||||
send(nPlayer, tl("playerSetOtherGameMode", sender.getName(), "creative"));
|
return null;
|
||||||
nPlayer.setGameMode(GameMode.CREATIVE);
|
|
||||||
return tl("setOtherPlayerGameModeTo", nPlayer.getName(), "creative");
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -57,7 +61,7 @@ public class CreativeCMD extends PlexCommand
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (isAdmin(sender))
|
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class DeopCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
Player player = getNonNullPlayer(args[0]);
|
Player player = getNonNullPlayer(args[0]);
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
|
@ -28,7 +28,7 @@ public class FreezeCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
Player player = getNonNullPlayer(args[0]);
|
Player player = getNonNullPlayer(args[0]);
|
||||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||||
|
@ -32,7 +32,7 @@ public class NameHistoryCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
String username = args[0];
|
String username = args[0];
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class OpCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
Player player = getNonNullPlayer(args[0]);
|
Player player = getNonNullPlayer(args[0]);
|
||||||
player.setOp(true);
|
player.setOp(true);
|
||||||
|
@ -53,7 +53,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,28 +29,27 @@ public class SpectatorCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (isConsole(sender))
|
if (isConsole(sender))
|
||||||
{
|
{
|
||||||
throw new CommandFailException("You must define a player when using the console!");
|
throw new CommandFailException(PlexUtils.tl("consoleMustDefinePlayer"));
|
||||||
}
|
}
|
||||||
playerSender.setGameMode(GameMode.SPECTATOR);
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SPECTATOR));
|
||||||
return tl("gameModeSetTo", "spectator");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRank(playerSender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
||||||
{
|
{
|
||||||
if (args[0].equals("-a"))
|
if (args[0].equals("-a"))
|
||||||
{
|
{
|
||||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||||
{
|
{
|
||||||
targetPlayer.setGameMode(GameMode.SPECTATOR);
|
targetPlayer.setGameMode(GameMode.SPECTATOR);
|
||||||
|
tl("gameModeSetTo", "spectator");
|
||||||
}
|
}
|
||||||
return tl("gameModeSetTo", "spectator");
|
PlexUtils.broadcast(tl("setEveryoneGameMode", sender.getName(), "spectator"));
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player nPlayer = getNonNullPlayer(args[0]);
|
Player nPlayer = getNonNullPlayer(args[0]);
|
||||||
// use send
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.SPECTATOR));
|
||||||
send(nPlayer, tl("playerSetOtherGameMode", sender.getName(), "spectator"));
|
|
||||||
nPlayer.setGameMode(GameMode.SPECTATOR);
|
|
||||||
return tl("setOtherPlayerGameModeTo", nPlayer.getName(), "spectator");
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ public class SpectatorCMD extends PlexCommand
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (isAdmin(sender))
|
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,28 +29,27 @@ public class SurvivalCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (isConsole(sender))
|
if (isConsole(sender))
|
||||||
{
|
{
|
||||||
throw new CommandFailException("You must define a player when using the console!");
|
throw new CommandFailException(PlexUtils.tl("consoleMustDefinePlayer"));
|
||||||
}
|
}
|
||||||
playerSender.setGameMode(GameMode.SURVIVAL);
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL));
|
||||||
return tl("gameModeSetTo", "survival");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRank(playerSender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
||||||
{
|
{
|
||||||
if (args[0].equals("-a"))
|
if (args[0].equals("-a"))
|
||||||
{
|
{
|
||||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||||
{
|
{
|
||||||
targetPlayer.setGameMode(GameMode.SURVIVAL);
|
targetPlayer.setGameMode(GameMode.SURVIVAL);
|
||||||
|
send(targetPlayer, tl("gameModeSetTo", "survival"));
|
||||||
}
|
}
|
||||||
return tl("gameModeSetTo", "survival");
|
PlexUtils.broadcast(tl("setEveryoneGameMode", sender.getName(), "survival"));
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player nPlayer = getNonNullPlayer(args[0]);
|
Player nPlayer = getNonNullPlayer(args[0]);
|
||||||
// use send
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.SURVIVAL));
|
||||||
send(nPlayer, tl("playerSetOtherGameMode", sender.getName(), "survival"));
|
return null;
|
||||||
nPlayer.setGameMode(GameMode.SURVIVAL);
|
|
||||||
return tl("setOtherPlayerGameModeTo", nPlayer.getName(), "survival");
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ public class SurvivalCMD extends PlexCommand
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (isAdmin(sender))
|
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class UnbanCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
|
@ -25,7 +25,7 @@ public class UnfreezeCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
Player player = getNonNullPlayer(args[0]);
|
Player player = getNonNullPlayer(args[0]);
|
||||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||||
@ -40,6 +40,6 @@ public class UnfreezeCMD extends PlexCommand
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && isAdmin(sender) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class WorldCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
return usage(getUsage());
|
return usage();
|
||||||
}
|
}
|
||||||
World world = getNonNullWorld(args[0]);
|
World world = getNonNullWorld(args[0]);
|
||||||
playerSender.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));
|
||||||
|
@ -30,7 +30,6 @@ public class AdminSetRankEvent extends Event
|
|||||||
*/
|
*/
|
||||||
private final Rank rank;
|
private final Rank rank;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers()
|
public HandlerList getHandlers()
|
||||||
{
|
{
|
||||||
|
32
src/main/java/dev/plex/event/GameModeUpdateEvent.java
Normal file
32
src/main/java/dev/plex/event/GameModeUpdateEvent.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package dev.plex.event;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GameModeUpdateEvent extends Event
|
||||||
|
{
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private final CommandSender sender;
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
|
private final GameMode gameMode;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull HandlerList getHandlers()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import dev.plex.listener.impl.BanListener;
|
|||||||
import dev.plex.listener.impl.ChatListener;
|
import dev.plex.listener.impl.ChatListener;
|
||||||
import dev.plex.listener.impl.CommandListener;
|
import dev.plex.listener.impl.CommandListener;
|
||||||
import dev.plex.listener.impl.FreezeListener;
|
import dev.plex.listener.impl.FreezeListener;
|
||||||
|
import dev.plex.listener.impl.GameModeListener;
|
||||||
import dev.plex.listener.impl.PlayerListener;
|
import dev.plex.listener.impl.PlayerListener;
|
||||||
import dev.plex.listener.impl.ServerListener;
|
import dev.plex.listener.impl.ServerListener;
|
||||||
import dev.plex.listener.impl.WorldListener;
|
import dev.plex.listener.impl.WorldListener;
|
||||||
@ -19,14 +20,15 @@ public class ListenerHandler
|
|||||||
public ListenerHandler()
|
public ListenerHandler()
|
||||||
{
|
{
|
||||||
List<PlexListener> listeners = Lists.newArrayList();
|
List<PlexListener> listeners = Lists.newArrayList();
|
||||||
listeners.add(new ServerListener());
|
|
||||||
listeners.add(new ChatListener());
|
|
||||||
listeners.add(new CommandListener());
|
|
||||||
listeners.add(new PlayerListener());
|
|
||||||
listeners.add(new WorldListener());
|
|
||||||
listeners.add(new FreezeListener());
|
|
||||||
listeners.add(new AdminListener());
|
listeners.add(new AdminListener());
|
||||||
listeners.add(new BanListener());
|
listeners.add(new BanListener());
|
||||||
|
listeners.add(new ChatListener());
|
||||||
|
listeners.add(new CommandListener());
|
||||||
|
listeners.add(new FreezeListener());
|
||||||
|
listeners.add(new GameModeListener());
|
||||||
|
listeners.add(new PlayerListener());
|
||||||
|
listeners.add(new ServerListener());
|
||||||
|
listeners.add(new WorldListener());
|
||||||
PlexLog.log(String.format("Registered %s listeners!", listeners.size()));
|
PlexLog.log(String.format("Registered %s listeners!", listeners.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.event.AdminAddEvent;
|
import dev.plex.event.AdminAddEvent;
|
||||||
import dev.plex.event.AdminRemoveEvent;
|
import dev.plex.event.AdminRemoveEvent;
|
||||||
import dev.plex.event.AdminSetRankEvent;
|
import dev.plex.event.AdminSetRankEvent;
|
||||||
@ -17,7 +18,8 @@ public class AdminListener extends PlexListener
|
|||||||
{
|
{
|
||||||
String userSender = event.getSender().getName();
|
String userSender = event.getSender().getName();
|
||||||
PlexPlayer target = event.getPlexPlayer();
|
PlexPlayer target = event.getPlexPlayer();
|
||||||
|
target.setRank(Rank.ADMIN.name());
|
||||||
|
DataUtils.update(target);
|
||||||
PlexUtils.broadcast(tl("newAdminAdded", userSender, target.getName()));
|
PlexUtils.broadcast(tl("newAdminAdded", userSender, target.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +28,8 @@ public class AdminListener extends PlexListener
|
|||||||
{
|
{
|
||||||
String userSender = event.getSender().getName();
|
String userSender = event.getSender().getName();
|
||||||
PlexPlayer target = event.getPlexPlayer();
|
PlexPlayer target = event.getPlexPlayer();
|
||||||
|
target.setRank("");
|
||||||
|
DataUtils.update(target);
|
||||||
PlexUtils.broadcast(tl("adminRemoved", userSender, target.getName()));
|
PlexUtils.broadcast(tl("adminRemoved", userSender, target.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +39,8 @@ public class AdminListener extends PlexListener
|
|||||||
String userSender = event.getSender().getName();
|
String userSender = event.getSender().getName();
|
||||||
PlexPlayer target = event.getPlexPlayer();
|
PlexPlayer target = event.getPlexPlayer();
|
||||||
Rank newRank = event.getRank();
|
Rank newRank = event.getRank();
|
||||||
|
target.setRank(newRank.name().toLowerCase());
|
||||||
PlexUtils.broadcast(tl("adminSetRank", userSender, target.getName(), newRank.name().toUpperCase()));
|
DataUtils.update(target);
|
||||||
|
PlexUtils.broadcast(tl("adminSetRank", userSender, target.getName(), newRank.getReadableString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
src/main/java/dev/plex/listener/impl/GameModeListener.java
Normal file
29
src/main/java/dev/plex/listener/impl/GameModeListener.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
||||||
|
public class GameModeListener extends PlexListener
|
||||||
|
{
|
||||||
|
@EventHandler
|
||||||
|
public void onGameModeUpdate(GameModeUpdateEvent event)
|
||||||
|
{
|
||||||
|
CommandSender userSender = event.getSender();
|
||||||
|
Player target = event.getPlayer();
|
||||||
|
if (userSender.getName().equals(target.getName()))
|
||||||
|
{
|
||||||
|
target.setGameMode(event.getGameMode());
|
||||||
|
userSender.sendMessage(PlexUtils.tl("gameModeSetTo", event.getGameMode().toString().toLowerCase()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.sendMessage(PlexUtils.tl("playerSetOtherGameMode", userSender.getName(), event.getGameMode().toString().toLowerCase()));
|
||||||
|
target.setGameMode(event.getGameMode());
|
||||||
|
userSender.sendMessage(PlexUtils.tl("setOtherPlayerGameModeTo", target.getName(), event.getGameMode().toString().toLowerCase()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -62,6 +62,7 @@ nameHistoryDoesntExist: "<e>Couldn't find this user! Please check if your spelli
|
|||||||
gameModeSetTo: "Your gamemode has been set to <v>."
|
gameModeSetTo: "Your gamemode has been set to <v>."
|
||||||
setOtherPlayerGameModeTo: "You set <v>'s gamemode to <v>."
|
setOtherPlayerGameModeTo: "You set <v>'s gamemode to <v>."
|
||||||
playerSetOtherGameMode: "<v> set your gamemode to <v>."
|
playerSetOtherGameMode: "<v> set your gamemode to <v>."
|
||||||
|
setEveryoneGameMode: "<b><v> - Changing everyone's gamemode to <v>"
|
||||||
consoleMustDefinePlayer: "You must define a player since you are running this command from console."
|
consoleMustDefinePlayer: "You must define a player since you are running this command from console."
|
||||||
newAdminAdded: "<b><v> - Adding <v> to the admin list"
|
newAdminAdded: "<b><v> - Adding <v> to the admin list"
|
||||||
adminRemoved: "<e><v> - Removing <v> from the admin list"
|
adminRemoved: "<e><v> - Removing <v> from the admin list"
|
||||||
|
Loading…
Reference in New Issue
Block a user