Add CommandSpy

This commit is contained in:
Telesphoreo 2022-02-04 15:25:40 -06:00
parent dbf95441dc
commit eebb34cd1c
9 changed files with 86 additions and 10 deletions

View File

@ -0,0 +1,30 @@
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.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
public class CommandSpyCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
{
PlexPlayer plexPlayer = getPlexPlayer(playerSender);
plexPlayer.setCommandSpy(!plexPlayer.isCommandSpy());
Component component = Component.text("CommandSpy has been").color(NamedTextColor.GRAY)
.append(Component.space())
.append(Component.text(plexPlayer.isCommandSpy() ? "enabled." : "disabled.").color(NamedTextColor.GRAY));
return component;
}
}

View File

@ -24,6 +24,7 @@ public class CommandHandler extends PlexBase
commands.add(new AdminworldCMD()); commands.add(new AdminworldCMD());
commands.add(new AdventureCMD()); commands.add(new AdventureCMD());
commands.add(new BanCMD()); commands.add(new BanCMD());
commands.add(new CommandSpyCMD());
commands.add(new CreativeCMD()); commands.add(new CreativeCMD());
commands.add(new FlatlandsCMD()); commands.add(new FlatlandsCMD());
commands.add(new FreezeCMD()); commands.add(new FreezeCMD());

View File

@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.listener.impl.AdminListener; import dev.plex.listener.impl.AdminListener;
import dev.plex.listener.impl.ChatListener; import dev.plex.listener.impl.ChatListener;
import dev.plex.listener.impl.CommandListener;
import dev.plex.listener.impl.FreezeListener; import dev.plex.listener.impl.FreezeListener;
import dev.plex.listener.impl.LoginListener; import dev.plex.listener.impl.LoginListener;
import dev.plex.listener.impl.PlayerListener; import dev.plex.listener.impl.PlayerListener;
@ -19,6 +20,7 @@ public class ListenerHandler
List<PlexListener> listeners = Lists.newArrayList(); List<PlexListener> listeners = Lists.newArrayList();
listeners.add(new ServerListener()); listeners.add(new ServerListener());
listeners.add(new ChatListener()); listeners.add(new ChatListener());
listeners.add(new CommandListener());
listeners.add(new PlayerListener()); listeners.add(new PlayerListener());
listeners.add(new WorldListener()); listeners.add(new WorldListener());
listeners.add(new FreezeListener()); listeners.add(new FreezeListener());

View File

@ -16,7 +16,6 @@ import org.jetbrains.annotations.NotNull;
public class ChatListener extends PlexListener public class ChatListener extends PlexListener
{ {
private final PlexChatRenderer renderer = new PlexChatRenderer(); private final PlexChatRenderer renderer = new PlexChatRenderer();
@EventHandler @EventHandler

View File

@ -0,0 +1,27 @@
package dev.plex.listener.impl;
import dev.plex.cache.PlayerCache;
import dev.plex.listener.PlexListener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandListener extends PlexListener
{
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{
Bukkit.getOnlinePlayers().stream().filter(pl -> PlayerCache.getPlexPlayer(pl.getUniqueId()).isCommandSpy()).forEach(pl ->
{
Player player = event.getPlayer();
String command = event.getMessage();
if (pl != player)
{
pl.sendMessage(ChatColor.GRAY + player.getName() + ": " + command);
}
});
}
}

View File

@ -32,6 +32,17 @@ public class PlayerListener extends PlexListener
PlexPlayer plexPlayer; PlexPlayer plexPlayer;
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
player.setOp(true);
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
player.setOp(false);
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
}
if (!DataUtils.hasPlayedBefore(player.getUniqueId())) if (!DataUtils.hasPlayedBefore(player.getUniqueId()))
{ {
PlexLog.log("A player with this name has not joined the server before, creating new entry."); PlexLog.log("A player with this name has not joined the server before, creating new entry.");

View File

@ -37,6 +37,7 @@ public class PlexPlayer
private String prefix; private String prefix;
private boolean vanished; private boolean vanished;
private boolean commandSpy;
private long coins; private long coins;
@ -61,6 +62,7 @@ public class PlexPlayer
this.prefix = ""; this.prefix = "";
this.vanished = false; this.vanished = false;
this.commandSpy = false;
this.coins = 0; this.coins = 0;

View File

@ -50,16 +50,17 @@ public class SQLConnection extends PlexBase
"`ips` VARCHAR(2000), " + "`ips` VARCHAR(2000), " +
"`coins` BIGINT, " + "`coins` BIGINT, " +
"`vanished` BOOLEAN, " + "`vanished` BOOLEAN, " +
"`commandSpy` BOOLEAN, " +
"PRIMARY KEY (`uuid`));").execute(); "PRIMARY KEY (`uuid`));").execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `bans` (" + connection.prepareStatement("CREATE TABLE IF NOT EXISTS `bans` (" +
"`banID` VARCHAR(46)," + "`banID` VARCHAR(46), " +
" `uuid` VARCHAR(46) NOT NULL," + "`uuid` VARCHAR(46) NOT NULL, " +
" `banner` VARCHAR(46)," + "`banner` VARCHAR(46), " +
"`ip` VARCHAR(2000)," + "`ip` VARCHAR(2000), " +
" `reason` VARCHAR(256)," + "`reason` VARCHAR(256), " +
" `enddate` BIGINT," + "`enddate` BIGINT, " +
" `active` BOOLEAN," + "`active` BOOLEAN, " +
" PRIMARY KEY (`banID`)" + "PRIMARY KEY (`banID`)" +
");").execute(); ");").execute();
} }
} }

View File

@ -76,4 +76,7 @@ yourRank: "<b>Your rank is: <v>"
banningPlayer: "<e><v> - Banning <v>" banningPlayer: "<e><v> - Banning <v>"
unbanningPlayer: "<b><v> - Unbanning <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" teleportedToWorldSpawn: "<b>Teleporting to the local spawn"
toggleCommandSpy: "CommandSpy has been "
enabled: "enabled"
disabled: "disabled"