mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Add CommandSpy
This commit is contained in:
parent
dbf95441dc
commit
eebb34cd1c
30
src/main/java/dev/plex/command/impl/CommandSpyCMD.java
Normal file
30
src/main/java/dev/plex/command/impl/CommandSpyCMD.java
Normal 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;
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ public class CommandHandler extends PlexBase
|
||||
commands.add(new AdminworldCMD());
|
||||
commands.add(new AdventureCMD());
|
||||
commands.add(new BanCMD());
|
||||
commands.add(new CommandSpyCMD());
|
||||
commands.add(new CreativeCMD());
|
||||
commands.add(new FlatlandsCMD());
|
||||
commands.add(new FreezeCMD());
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.listener.impl.AdminListener;
|
||||
import dev.plex.listener.impl.ChatListener;
|
||||
import dev.plex.listener.impl.CommandListener;
|
||||
import dev.plex.listener.impl.FreezeListener;
|
||||
import dev.plex.listener.impl.LoginListener;
|
||||
import dev.plex.listener.impl.PlayerListener;
|
||||
@ -19,6 +20,7 @@ public class ListenerHandler
|
||||
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());
|
||||
|
@ -16,7 +16,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ChatListener extends PlexListener
|
||||
{
|
||||
|
||||
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
||||
|
||||
@EventHandler
|
||||
|
27
src/main/java/dev/plex/listener/impl/CommandListener.java
Normal file
27
src/main/java/dev/plex/listener/impl/CommandListener.java
Normal 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -32,6 +32,17 @@ public class PlayerListener extends PlexListener
|
||||
|
||||
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()))
|
||||
{
|
||||
PlexLog.log("A player with this name has not joined the server before, creating new entry.");
|
||||
|
@ -37,6 +37,7 @@ public class PlexPlayer
|
||||
private String prefix;
|
||||
|
||||
private boolean vanished;
|
||||
private boolean commandSpy;
|
||||
|
||||
private long coins;
|
||||
|
||||
@ -61,6 +62,7 @@ public class PlexPlayer
|
||||
this.prefix = "";
|
||||
|
||||
this.vanished = false;
|
||||
this.commandSpy = false;
|
||||
|
||||
this.coins = 0;
|
||||
|
||||
|
@ -50,16 +50,17 @@ public class SQLConnection extends PlexBase
|
||||
"`ips` VARCHAR(2000), " +
|
||||
"`coins` BIGINT, " +
|
||||
"`vanished` BOOLEAN, " +
|
||||
"`commandSpy` BOOLEAN, " +
|
||||
"PRIMARY KEY (`uuid`));").execute();
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `bans` (" +
|
||||
"`banID` VARCHAR(46)," +
|
||||
" `uuid` VARCHAR(46) NOT NULL," +
|
||||
" `banner` VARCHAR(46)," +
|
||||
"`ip` VARCHAR(2000)," +
|
||||
" `reason` VARCHAR(256)," +
|
||||
" `enddate` BIGINT," +
|
||||
" `active` BOOLEAN," +
|
||||
" PRIMARY KEY (`banID`)" +
|
||||
"`banID` VARCHAR(46), " +
|
||||
"`uuid` VARCHAR(46) NOT NULL, " +
|
||||
"`banner` VARCHAR(46), " +
|
||||
"`ip` VARCHAR(2000), " +
|
||||
"`reason` VARCHAR(256), " +
|
||||
"`enddate` BIGINT, " +
|
||||
"`active` BOOLEAN, " +
|
||||
"PRIMARY KEY (`banID`)" +
|
||||
");").execute();
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,7 @@ yourRank: "<b>Your rank is: <v>"
|
||||
banningPlayer: "<e><v> - Banning <v>"
|
||||
unbanningPlayer: "<b><v> - Unbanning <v>"
|
||||
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"
|
Loading…
Reference in New Issue
Block a user