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

6 Commits

9 changed files with 97 additions and 32 deletions
+3 -3
View File
@@ -30,11 +30,11 @@ runPaper {
}
runServer {
minecraftVersion("1.21.8")
minecraftVersion("1.21.10")
downloadPlugins {
// for testing from other client versions
modrinth("ViaVersion", "5.4.1")
modrinth("ViaBackwards", "5.4.1")
modrinth("ViaVersion", "5.5.1")
modrinth("ViaBackwards", "5.5.1")
}
}
+13 -5
View File
@@ -1,7 +1,15 @@
# SModeration config
| Key | What it does |
|--------------------------|--------------------------------------------------------------------|
| socialspy-commands | The commands that `/socialspy` will listen to. |
| force-reason | Whether a reason is required for every punishment. |
| muted-forbidden-commands | Commands that players are not allowed to run while they are muted. |
| Key | What it does |
|--------------------------|------------------------------------------------------------------------------------------------------------------------|
| socialspy-commands | The commands that `/socialspy` will listen to. |
| force-reason | Whether a reason is required for every punishment. |
| muted-forbidden-commands | Commands that players are not allowed to run while they are muted. |
| features | Controls which plugin features are enabled. |
| features.punishments | Whether the plugin provides punishing features (kick, ban, mute) |
| features.smodmenu | If punishments are enabled, controls whether the SMod Menu can be opened. Has no effect when punishments are disabled. |
| features.invsee | Whether the plugin provides invsee feature |
| features.enderchestsee | Whether the plugin provides enderchestsee feature |
| features.offlinetp | Whether the plugin provides the offlinetp feature |
| features.socialspy | Whether the plugin provides the SocialSpy feature |
| features.vanish | Whether the plugin provides the vanish feature |
+1 -1
View File
@@ -1 +1 @@
pluginVersion = 1.7.1
pluginVersion = 1.8.2
@@ -72,31 +72,44 @@ public final class SModerationPaper extends JavaPlugin {
updateConfig();
}
public boolean isFeatureEnabled(String feature){
return getConfig().getBoolean("features."+feature, true);
}
@Override
public void onEnable() {
listen(new PunishmentListener());
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
if (isFeatureEnabled("punishments")) listen(new PunishmentListener());
if (isFeatureEnabled("invsee")) listen(new InvSeeListener());
if (isFeatureEnabled("enderchestsee")) listen(new EnderchestSeeListener());
if (isFeatureEnabled("socialspy")) listen(new SocialSpyListener());
if (isFeatureEnabled("vanish")) listen(new VanishListener());
listen(new CustomInventoryListener());
listen(new InvSeeListener());
listen(new EnderchestSeeListener());
listen(new VanishListener());
listen(new ChatInputListener());
listen(new SocialSpyListener());
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
Commands commands = event.registrar();
registerCommand(commands, new KickCommand());
registerCommand(commands, new ModLogsCommand());
registerCommand(commands, new SModCommand());
registerCommand(commands, new InvseeCommand());
registerCommand(commands, new EnderchestSeeCommand());
registerCommand(commands, new SocialSpyCommand());
registerCommand(commands, new VanishCommand());
registerCommand(commands, new UnmuteCommand());
registerCommand(commands, new UnbanCommand());
registerCommand(commands, new MuteCommand());
registerCommand(commands, new BanCommand());
registerCommand(commands, new OfflineTPCommand());
if (isFeatureEnabled("punishments")){
registerCommand(commands, new KickCommand());
registerCommand(commands, new ModLogsCommand());
registerCommand(commands, new UnmuteCommand());
registerCommand(commands, new UnbanCommand());
registerCommand(commands, new MuteCommand());
registerCommand(commands, new BanCommand());
if (isFeatureEnabled("smodmenu")){
registerCommand(commands, new SModCommand());
}
}
if (isFeatureEnabled("invsee")) registerCommand(commands, new InvseeCommand());
if (isFeatureEnabled("enderchestsee")) registerCommand(commands, new EnderchestSeeCommand());
if (isFeatureEnabled("socialspy")) registerCommand(commands, new SocialSpyCommand());
if (isFeatureEnabled("vanish")) registerCommand(commands, new VanishCommand());
if (isFeatureEnabled("offlinetp")) registerCommand(commands, new OfflineTPCommand());
});
if (SchedulerUtil.isFolia){
@@ -109,8 +122,6 @@ public final class SModerationPaper extends JavaPlugin {
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1);
container.load(SAVE_FILE);
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
}
private void listen(Listener listener) {
@@ -1,5 +1,6 @@
package de.shiewk.smoderation.paper.inventory;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.translation.GlobalTranslator;
@@ -9,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public interface CustomInventory extends InventoryHolder {
void refresh();
@@ -26,6 +29,13 @@ public interface CustomInventory extends InventoryHolder {
}
static Component renderComponent(Player viewer, Component component){
return GlobalTranslator.render(component.children(component.children().stream().map(c -> renderComponent(viewer, c)).toList()), viewer.locale());
Component render = GlobalTranslator.render(component, viewer.locale());
List<Component> oldChildren = render.children();
List<Component> newChildren = new ObjectArrayList<>(oldChildren.size());
for (Component oldChild : oldChildren) {
Component e = renderComponent(viewer, oldChild);
newChildren.add(e);
}
return render.children(newChildren);
}
}
@@ -324,7 +324,7 @@ public class SModMenu extends PageableCustomInventory {
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.player", text(PlayerUtil.offlinePlayerName(punishment.to))))));
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.punishedBy", text(PlayerUtil.offlinePlayerName(punishment.by))))));
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.timestamp", TimeUtil.formatTimeLong(punishment.time)))));
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.timestamp", TimeUtil.calendarTimestamp(punishment.time)))));
if (punishment.type != PunishmentType.KICK){
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", TimeUtil.formatTimeLong(punishment.until - punishment.time)))));
@@ -2,6 +2,7 @@ package de.shiewk.smoderation.paper.listener;
import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.event.PunishmentIssueEvent;
import de.shiewk.smoderation.paper.inventory.CustomInventory;
import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentType;
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
@@ -85,7 +86,7 @@ public class PunishmentListener implements Listener {
case KICK, BAN -> {
final Player player = Bukkit.getPlayer(punishment.to);
if (player != null) {
player.kick(CHAT_PREFIX.append(punishment.playerMessage()));
player.kick(CustomInventory.renderComponent(player, CHAT_PREFIX.append(punishment.playerMessage())));
}
}
}
@@ -3,6 +3,7 @@ package de.shiewk.smoderation.paper.listener;
import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.command.VanishCommand;
import de.shiewk.smoderation.paper.util.SchedulerUtil;
import io.papermc.paper.event.entity.WardenAngerChangeEvent;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
@@ -11,7 +12,9 @@ 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.EntityTargetEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.persistence.PersistentDataType;
@@ -86,6 +89,30 @@ public class VanishListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityTarget(EntityTargetEvent event){
if (event.getTarget() instanceof Player pl && VanishCommand.isVanished(pl)) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityTarget(WardenAngerChangeEvent event){
if (event.getTarget() instanceof Player pl && VanishCommand.isVanished(pl)) {
event.setCancelled(true);
}
}
@EventHandler
public void onAdvancementDone(PlayerAdvancementDoneEvent event){
Player pl = event.getPlayer();
Component message = event.message();
if (VanishCommand.isVanished(pl) && message != null) {
broadcast(message);
event.message(null);
}
}
private static void broadcast(Component message) {
Component result = PREFIX.append(message);
Bukkit.getConsoleSender().sendMessage(result);
+9 -1
View File
@@ -22,4 +22,12 @@ muted-forbidden-commands:
- minecraft:msg
- minecraft:teammsg
- minecraft:tm
- minecraft:me
- minecraft:me
features:
punishments: true
smodmenu: true
invsee: true
enderchestsee: true
offlinetp: true
socialspy: true
vanish: true