1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-28 05:54:16 +02:00

SocialSpy command and permissions

This commit is contained in:
Shy
2024-08-21 18:32:01 +02:00
parent a7c487decd
commit 8de4382ec4
7 changed files with 194 additions and 16 deletions
+16 -15
View File
@@ -1,17 +1,18 @@
# SModeration commands # SModeration commands
| Command | Description | Permission | | Command | Description | Permission |
|----------------------------------------|------------------------------------------------------------------------------|---------------------| |----------------------------------------|------------------------------------------------------------------------------|--------------------|
| /smod | Opens the SMod menu. | smod.menu | | /smod | Opens the SMod menu. | smod.menu |
| /mute \<player> \<duration> \<reason?> | Mutes a player so that they can't type in chat for the specified duration. | smod.mute | | /mute \<player> \<duration> \<reason?> | Mutes a player so that they can't type in chat for the specified duration. | smod.mute |
| /ban \<player> \<duration> \<reason?> | Bans a player so that they can't join the server for the specified duration. | smod.ban | | /ban \<player> \<duration> \<reason?> | Bans a player so that they can't join the server for the specified duration. | smod.ban |
| /kick \<player> \<reason?> | Kicks a player from the server. | smod.kick | | /kick \<player> \<reason?> | Kicks a player from the server. | smod.kick |
| /modlogs <player\|uuid> | Lists a player's active punishments in chat. | smod.logs | | /modlogs <player\|uuid> | Lists a player's active punishments in chat. | smod.logs |
| /unmute <player> | Clears a player's mute status. | smod.unmute | | /unmute <player> | Clears a player's mute status. | smod.unmute |
| /unban <player> | Clears a player's ban status. | smod.unban | | /unban <player> | Clears a player's ban status. | smod.unban |
| /invsee \<player> inventory | Views another player's inventory. | smod.invsee | | /invsee \<player> inventory | Views another player's inventory. | smod.invsee |
| /invsee \<player> equipment | Views another player's equipment (armor and offhand). | smod.invsee | | /invsee \<player> equipment | Views another player's equipment (armor and offhand). | smod.invsee |
| /enderchestsee <player> | Views another player's ender chest. | smod.enderchestsee | | /enderchestsee <player> | Views another player's ender chest. | smod.enderchestsee |
| /vanish | Toggles vanish mode so that other players can't see you're online. | smod.vanish | | /vanish | Toggles vanish mode so that other players can't see you're online. | smod.vanish |
| /vanish toggle \<player> | Toggles vanish mode for another player. | smod.vanish | | /vanish toggle \<player> | Toggles vanish mode for another player. | smod.vanish |
| /vanish list | Lists all vanished players. | smod.vanish.see | | /vanish list | Lists all vanished players. | smod.vanish.see |
| /socialspy | Enables SocialSpy mode where you can see other player's private messages. | smod.socialspy |
+1
View File
@@ -19,5 +19,6 @@
| smod.enderchestsee.modify | Allows the player to view and modify other players ender chests. | | smod.enderchestsee.modify | Allows the player to view and modify other players ender chests. |
| smod.vanish | Allows the player to enter and leave vanish mode. | | smod.vanish | Allows the player to enter and leave vanish mode. |
| smod.vanish.see | Allows the player to see vanished players | | smod.vanish.see | Allows the player to see vanished players |
| smod.socialspy | Allows the player to enable SocialSpy |
All of these permissions are granted by default if the player is a server operator. All of these permissions are granted by default if the player is a server operator.
@@ -1,6 +1,7 @@
package de.shiewk.smoderation; package de.shiewk.smoderation;
import de.shiewk.smoderation.command.*; import de.shiewk.smoderation.command.*;
import de.shiewk.smoderation.config.SModerationConfig;
import de.shiewk.smoderation.input.ChatInputListener; import de.shiewk.smoderation.input.ChatInputListener;
import de.shiewk.smoderation.listener.*; import de.shiewk.smoderation.listener.*;
import de.shiewk.smoderation.storage.PunishmentContainer; import de.shiewk.smoderation.storage.PunishmentContainer;
@@ -26,6 +27,7 @@ public final class SModeration extends JavaPlugin {
public static final PunishmentContainer container = new PunishmentContainer(); public static final PunishmentContainer container = new PunishmentContainer();
public static ComponentLogger LOGGER = null; public static ComponentLogger LOGGER = null;
public static SModeration PLUGIN = null; public static SModeration PLUGIN = null;
public static SModerationConfig CONFIG = null;
public static File SAVE_FILE = null; public static File SAVE_FILE = null;
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255); public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
@@ -38,6 +40,7 @@ public final class SModeration extends JavaPlugin {
public void onLoad() { public void onLoad() {
LOGGER = getComponentLogger(); LOGGER = getComponentLogger();
PLUGIN = this; PLUGIN = this;
CONFIG = new SModerationConfig(this.getConfig(), this);
SAVE_FILE = new File(this.getDataFolder().getAbsolutePath() + "/container.gz"); SAVE_FILE = new File(this.getDataFolder().getAbsolutePath() + "/container.gz");
} }
@@ -49,6 +52,7 @@ public final class SModeration extends JavaPlugin {
getPluginManager().registerEvents(new EnderchestSeeListener(), this); getPluginManager().registerEvents(new EnderchestSeeListener(), this);
getPluginManager().registerEvents(new VanishListener(), this); getPluginManager().registerEvents(new VanishListener(), this);
getPluginManager().registerEvents(new ChatInputListener(), this); getPluginManager().registerEvents(new ChatInputListener(), this);
getPluginManager().registerEvents(new SocialSpyListener(), this);
registerCommand("mute", new MuteCommand()); registerCommand("mute", new MuteCommand());
registerCommand("ban", new BanCommand()); registerCommand("ban", new BanCommand());
@@ -60,6 +64,7 @@ public final class SModeration extends JavaPlugin {
registerCommand("invsee", new InvseeCommand()); registerCommand("invsee", new InvseeCommand());
registerCommand("enderchestsee", new EnderchestSeeCommand()); registerCommand("enderchestsee", new EnderchestSeeCommand());
registerCommand("vanish", new VanishCommand()); registerCommand("vanish", new VanishCommand());
registerCommand("socialspy", new SocialSpyCommand());
container.load(SAVE_FILE); container.load(SAVE_FILE);
} }
@@ -0,0 +1,32 @@
package de.shiewk.smoderation.command;
import de.shiewk.smoderation.listener.SocialSpyListener;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import static de.shiewk.smoderation.SModeration.CHAT_PREFIX;
import static net.kyori.adventure.text.Component.text;
public class SocialSpyCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
final boolean enabled = SocialSpyListener.toggle(sender);
sender.sendMessage(CHAT_PREFIX.append(text("SocialSpy ").append(
enabled ?
text("enabled").color(NamedTextColor.GREEN) :
text("disabled").color(NamedTextColor.RED)
).append(text("."))));
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return List.of();
}
}
@@ -0,0 +1,30 @@
package de.shiewk.smoderation.config;
import de.shiewk.smoderation.SModeration;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.List;
public class SModerationConfig {
private final FileConfiguration config;
private final SModeration plugin;
public SModerationConfig(FileConfiguration config, SModeration plugin) {
this.config = config;
this.plugin = plugin;
}
public List<String> getSocialSpyCommands(List<String> default_){
final String path = "socialspy-commands";
if (!config.contains(path)){
config.set(path, default_);
plugin.saveConfig();
}
return config.getStringList(path);
}
public FileConfiguration getConfig() {
return config;
}
}
@@ -0,0 +1,94 @@
package de.shiewk.smoderation.listener;
import de.shiewk.smoderation.SModeration;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.util.List;
import static de.shiewk.smoderation.SModeration.PRIMARY_COLOR;
import static de.shiewk.smoderation.SModeration.SECONDARY_COLOR;
import static net.kyori.adventure.text.Component.text;
public class SocialSpyListener implements Listener {
private static final List<String> defaultCommands = List.of(
"w",
"tell",
"msg",
"teammsg",
"tm",
"minecraft:w",
"minecraft:tell",
"minecraft:msg",
"minecraft:teammsg",
"minecraft:tm"
);
private static final NamespacedKey SAVE_KEY = new NamespacedKey("smoderation", "socialspy");
private static final ObjectArrayList<CommandSender> targets = new ObjectArrayList<>();
public static boolean toggle(CommandSender sender) {
boolean enabledNow = isEnabled(sender);
if (enabledNow){
targets.remove(sender);
if (sender instanceof Player player){
player.getPersistentDataContainer().set(SAVE_KEY, PersistentDataType.BOOLEAN, false);
}
return false;
} else {
targets.add(sender);
if (sender instanceof Player player){
player.getPersistentDataContainer().set(SAVE_KEY, PersistentDataType.BOOLEAN, true);
}
return true;
}
}
@EventHandler public void onPlayerJoin(PlayerJoinEvent event){
final PersistentDataContainer pdc = event.getPlayer().getPersistentDataContainer();
if (Boolean.TRUE.equals(pdc.get(SAVE_KEY, PersistentDataType.BOOLEAN))){
targets.add(event.getPlayer());
}
}
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
targets.remove(event.getPlayer());
}
public static boolean isEnabled(CommandSender sender){
return targets.contains(sender);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerSendCommand(PlayerCommandPreprocessEvent event){
List<String> ssCommands = SModeration.CONFIG.getSocialSpyCommands(defaultCommands);
final String message = event.getMessage();
if (ssCommands.stream().anyMatch(str ->
message.startsWith("/"+str+" ")
|| message.startsWith(str+" ")
)){
SocialSpyListener.command(event.getPlayer(), message);
}
}
public static void command(Player player, String command){
for (CommandSender target : targets) {
target.sendMessage(text("[SocialSpy] ")
.append(player.displayName().colorIfAbsent(SECONDARY_COLOR))
.append(text(": " + command).color(SECONDARY_COLOR))
.color(PRIMARY_COLOR));
}
}
}
+15
View File
@@ -75,8 +75,20 @@ commands:
usage: "§cUsage: /vanish list or /vanish toggle <player>" usage: "§cUsage: /vanish list or /vanish toggle <player>"
aliases: aliases:
- smvanish - smvanish
- smodvanish
- v
- smv
permission: smod.vanish permission: smod.vanish
description: Toggles vanish mode which prevents other players from seeing you're online description: Toggles vanish mode which prevents other players from seeing you're online
socialspy:
usage: "§cUsage: /socialspy"
description: Enables socialspy mode (you can see private messages of other players)
permission: smod.socialspy
aliases:
- smodsocialspy
- smsocialspy
- smss
- ss
permissions: permissions:
smod.mute: smod.mute:
default: op default: op
@@ -138,3 +150,6 @@ permissions:
smod.vanish.see: smod.vanish.see:
default: op default: op
description: Allows the player to see vanished players description: Allows the player to see vanished players
smod.socialspy:
default: op
description: Allows the player to enable SocialSpy