mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2024-11-14 13:13:32 +00:00
Implemented basic command spy
This commit is contained in:
parent
2ac955cc0a
commit
722b1b72a4
@ -1,6 +1,7 @@
|
|||||||
package me.totalfreedom.datura;
|
package me.totalfreedom.datura;
|
||||||
|
|
||||||
import me.totalfreedom.base.Patchwork;
|
import me.totalfreedom.base.Patchwork;
|
||||||
|
import me.totalfreedom.datura.features.CommandSpy;
|
||||||
import me.totalfreedom.datura.punishment.Cager;
|
import me.totalfreedom.datura.punishment.Cager;
|
||||||
import me.totalfreedom.datura.punishment.Halter;
|
import me.totalfreedom.datura.punishment.Halter;
|
||||||
import me.totalfreedom.datura.punishment.Locker;
|
import me.totalfreedom.datura.punishment.Locker;
|
||||||
@ -12,10 +13,14 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
public class Datura extends JavaPlugin
|
public class Datura extends JavaPlugin
|
||||||
{
|
{
|
||||||
private final MySQL sql = new MySQL("localhost", 3011, "master");
|
private final MySQL sql = new MySQL("localhost", 3011, "master");
|
||||||
|
|
||||||
|
// Punishment
|
||||||
private final Halter halter = new Halter();
|
private final Halter halter = new Halter();
|
||||||
private final Locker locker = new Locker();
|
private final Locker locker = new Locker();
|
||||||
private final Cager cager = new Cager();
|
private final Cager cager = new Cager();
|
||||||
|
|
||||||
|
// Features
|
||||||
|
private final CommandSpy commandSpy = new CommandSpy();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
@ -36,6 +41,8 @@ public class Datura extends JavaPlugin
|
|||||||
|
|
||||||
Bukkit.getPluginManager()
|
Bukkit.getPluginManager()
|
||||||
.registerEvents(halter, this);
|
.registerEvents(halter, this);
|
||||||
|
Bukkit.getPluginManager()
|
||||||
|
.registerEvents(commandSpy, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MySQL getSQL()
|
public MySQL getSQL()
|
||||||
@ -57,4 +64,8 @@ public class Datura extends JavaPlugin
|
|||||||
{
|
{
|
||||||
return cager;
|
return cager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandSpy getCommandSpy() {
|
||||||
|
return commandSpy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package me.totalfreedom.datura.cmd;
|
||||||
|
|
||||||
|
import me.totalfreedom.command.Commander;
|
||||||
|
import me.totalfreedom.command.annotation.Base;
|
||||||
|
import me.totalfreedom.command.annotation.Info;
|
||||||
|
import me.totalfreedom.command.annotation.Permissive;
|
||||||
|
import me.totalfreedom.datura.Datura;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@Info(name = "commandspy", description = "Spy on commands executed by players.", usage = "/commandspy")
|
||||||
|
@Permissive(perm = "datura.commandspy")
|
||||||
|
public class CommandSpyCommand extends Commander
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the
|
||||||
|
* command.
|
||||||
|
* <p>
|
||||||
|
* This constructor will automatically register all subcommands and completions for this command. It will also
|
||||||
|
* automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin which contains this command.
|
||||||
|
*/
|
||||||
|
protected CommandSpyCommand(@NotNull JavaPlugin plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Base
|
||||||
|
public void commandSpy(final CommandSender sender)
|
||||||
|
{
|
||||||
|
if (!(sender instanceof Player))
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("You have to be a player to perform this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final var commandSpy = ((Datura) getPlugin()).
|
||||||
|
getCommandSpy();
|
||||||
|
|
||||||
|
final var uuid = ((Player) sender).
|
||||||
|
getUniqueId();
|
||||||
|
|
||||||
|
if (commandSpy.isSpying(uuid))
|
||||||
|
{
|
||||||
|
commandSpy.stop(uuid);
|
||||||
|
sender.sendPlainMessage("CommandSpy disabled.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commandSpy.spy(uuid);
|
||||||
|
sender.sendPlainMessage("CommandSpy enabled.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package me.totalfreedom.datura.features;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CommandSpy implements Listener
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Set<UUID> commandWatchers;
|
||||||
|
|
||||||
|
public CommandSpy()
|
||||||
|
{
|
||||||
|
this.commandWatchers = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spy(final UUID uuid)
|
||||||
|
{
|
||||||
|
this.commandWatchers.add(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop(final UUID uuid)
|
||||||
|
{
|
||||||
|
this.commandWatchers.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
this.commandWatchers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSpying(final UUID uuid)
|
||||||
|
{
|
||||||
|
return this.commandWatchers.contains(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void commandProcess(final PlayerCommandPreprocessEvent event)
|
||||||
|
{
|
||||||
|
Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(player -> isSpying(player.getUniqueId()))
|
||||||
|
.forEach(player -> player.sendMessage(Component.text(event.getPlayer().getName(), NamedTextColor.GRAY)
|
||||||
|
.append(Component.text(": ", NamedTextColor.GRAY))
|
||||||
|
.append(Component.text(event.getMessage(), NamedTextColor.GRAY))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user