1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-29 06:34:17 +02:00

9 Commits

Author SHA1 Message Date
Shiewk 1a9cf76a93 1.4.1 2024-08-25 11:12:39 +02:00
Shiewk b3ec076cae Fix chat input title delay 2024-08-25 10:59:29 +02:00
Shiewk 3cb3314f4c Allow opening own ender chest 2024-08-22 15:28:25 +02:00
Shiewk fb785fb53a Improve styling 2024-08-22 13:57:31 +02:00
Shiewk faa2eb0a43 1.4.0 2024-08-21 18:40:56 +02:00
Shiewk 8c00347ef2 Hide death messages from vanished players 2024-08-21 18:40:06 +02:00
Shiewk 8de4382ec4 SocialSpy command and permissions 2024-08-21 18:32:01 +02:00
Shiewk a7c487decd Update to version 1.3.1 2024-08-04 14:48:51 +02:00
Shiewk 22f42df1da Fixed a bug where unknown players would crash the SMod menu 2024-08-04 14:47:29 +02:00
14 changed files with 235 additions and 32 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ SModeration provides a nice user interface that can be used instead of chat comm
![SMod Menu Sort](https://github.com/Shiewk/SModeration/assets/152653291/23e3862d-0915-47bd-9c47-6d8d10f8ab69)
It has helpful functions like filtering and sorting options.
It has helpful functions like filtering, searching and sorting options.
## Commands
This plugin has many commands, for a complete list of commands and their usage, please see [the commands list](https://github.com/Shiewk/SModeration/blob/main/docs/commands.md).
+2 -1
View File
@@ -1,7 +1,7 @@
# SModeration commands
| Command | Description | Permission |
|----------------------------------------|------------------------------------------------------------------------------|---------------------|
|----------------------------------------|------------------------------------------------------------------------------|--------------------|
| /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 |
| /ban \<player> \<duration> \<reason?> | Bans a player so that they can't join the server for the specified duration. | smod.ban |
@@ -15,3 +15,4 @@
| /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 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.vanish | Allows the player to enter and leave vanish mode. |
| 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.
+1 -1
View File
@@ -1 +1 @@
pluginVersion = 1.3.0
pluginVersion = 1.4.1
@@ -1,6 +1,7 @@
package de.shiewk.smoderation;
import de.shiewk.smoderation.command.*;
import de.shiewk.smoderation.config.SModerationConfig;
import de.shiewk.smoderation.input.ChatInputListener;
import de.shiewk.smoderation.listener.*;
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 ComponentLogger LOGGER = null;
public static SModeration PLUGIN = null;
public static SModerationConfig CONFIG = null;
public static File SAVE_FILE = null;
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
@@ -38,6 +40,7 @@ public final class SModeration extends JavaPlugin {
public void onLoad() {
LOGGER = getComponentLogger();
PLUGIN = this;
CONFIG = new SModerationConfig(this.getConfig(), this);
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 VanishListener(), this);
getPluginManager().registerEvents(new ChatInputListener(), this);
getPluginManager().registerEvents(new SocialSpyListener(), this);
registerCommand("mute", new MuteCommand());
registerCommand("ban", new BanCommand());
@@ -60,6 +64,7 @@ public final class SModeration extends JavaPlugin {
registerCommand("invsee", new InvseeCommand());
registerCommand("enderchestsee", new EnderchestSeeCommand());
registerCommand("vanish", new VanishCommand());
registerCommand("socialspy", new SocialSpyCommand());
container.load(SAVE_FILE);
}
@@ -28,16 +28,12 @@ public class EnderchestSeeCommand implements TabExecutor {
if (sender instanceof HumanEntity human){
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
if (player != null) {
if (human.getUniqueId().equals(player.getUniqueId())){
human.sendMessage(Component.text("You can't open your own ender chest.").color(FAIL_COLOR));
} else {
human.sendMessage(CHAT_PREFIX.append(
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
.append(Component.text("."))
));
human.openInventory(player.getEnderChest());
}
} else {
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
}
@@ -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;
}
}
@@ -27,7 +27,7 @@ public class ChatInput {
this.player = player;
this.prompt = prompt;
this.action = action;
this.remainingTicks = remainingSeconds * 20;
this.remainingTicks = remainingSeconds * 20 + 1;
}
static void tickAll() {
@@ -102,7 +102,11 @@ public class SModMenu extends PageableCustomInventory {
}
private void reload(){
this.punishments = container.copy().stream().filter(getFilter().filter).filter(p -> getType() == null || p.type == getType()).filter(p -> p.matchesSearchQuery(searchQuery)).sorted(getSort().comparator).toList();
this.punishments = container.copy().stream()
.filter(getFilter().filter)
.filter(p -> getType() == null || p.type == getType())
.filter(p -> p.matchesSearchQuery(searchQuery))
.sorted(getSort().comparator).toList();
}
public void promptSearchQuery(){
@@ -269,7 +273,11 @@ public class SModMenu extends PageableCustomInventory {
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
stack.editMeta(meta -> {
if (meta instanceof SkullMeta skullMeta){
try {
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.to));
} catch (NullPointerException e) {
LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.to);
};
}
meta.displayName(applyFormatting(text(punishment.type.name).color(NamedTextColor.RED).decorate(TextDecoration.BOLD)));
ArrayList<Component> lore = new ArrayList<>();
@@ -0,0 +1,97 @@
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("[", PRIMARY_COLOR)
.append(text("SocialSpy", SECONDARY_COLOR))
.append(text("] "))
.append(player.displayName().colorIfAbsent(PRIMARY_COLOR))
.append(text(": ", PRIMARY_COLOR))
.append(text(command, SECONDARY_COLOR))
);
}
}
}
@@ -2,14 +2,19 @@ package de.shiewk.smoderation.listener;
import de.shiewk.smoderation.SModeration;
import de.shiewk.smoderation.command.VanishCommand;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import static de.shiewk.smoderation.SModeration.SECONDARY_COLOR;
import static net.kyori.adventure.text.Component.text;
public class VanishListener implements Listener {
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
@@ -37,4 +42,17 @@ public class VanishListener implements Listener {
});
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent event){
final Component message = event.deathMessage();
if (VanishCommand.isVanished(event.getPlayer()) && message != null){
event.deathMessage(null);
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.hasPermission("smod.vanish.see")){
onlinePlayer.sendMessage(text("[VANISH] ").color(SECONDARY_COLOR).append(message));
}
}
}
}
}
@@ -25,7 +25,7 @@ public abstract class PlayerUtil {
return "CONSOLE";
}
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
return player.getName() == null ? uuid.toString() : player.getName();
return player.getName() == null ? "Unknown Player" + uuid : player.getName();
}
public static @Nullable UUID offlinePlayerUUIDByName(String name){
+15
View File
@@ -75,8 +75,20 @@ commands:
usage: "§cUsage: /vanish list or /vanish toggle <player>"
aliases:
- smvanish
- smodvanish
- v
- smv
permission: smod.vanish
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:
smod.mute:
default: op
@@ -138,3 +150,6 @@ permissions:
smod.vanish.see:
default: op
description: Allows the player to see vanished players
smod.socialspy:
default: op
description: Allows the player to enable SocialSpy