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

3 Commits

8 changed files with 122 additions and 32 deletions
+9 -1
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. |
| 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.0
pluginVersion = 1.8.0
@@ -22,6 +22,7 @@ import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@@ -71,39 +72,60 @@ public final class SModerationPaper extends JavaPlugin {
updateConfig();
}
public boolean isFeatureEnabled(String feature){
return getConfig().getBoolean("features."+feature, true);
}
@Override
public void onEnable() {
getPluginManager().registerEvents(new PunishmentListener(), this);
getPluginManager().registerEvents(new CustomInventoryListener(), this);
getPluginManager().registerEvents(new InvSeeListener(), this);
getPluginManager().registerEvents(new EnderchestSeeListener(), this);
getPluginManager().registerEvents(new VanishListener(), this);
getPluginManager().registerEvents(new ChatInputListener(), this);
getPluginManager().registerEvents(new SocialSpyListener(), this);
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 ChatInputListener());
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
Commands commands = event.registrar();
if (isFeatureEnabled("punishments")){
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("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());
});
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, CustomInventoryListener::onTick, 1, 1);
if (SchedulerUtil.isFolia){
// Normal ticking logic can cause issues on Folia
listen(new FoliaInventoryUpdatingListener());
} else {
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, CustomInventoryListener::tickAllPaper, 1, 1);
}
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1);
container.load(SAVE_FILE);
}
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
private void listen(Listener listener) {
getPluginManager().registerEvents(listener, this);
}
private void registerCommand(Commands commands, CommandProvider provider){
@@ -59,6 +59,9 @@ public final class MuteCommand implements CommandProvider {
}
public static void executeMute(UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
if (duration == 0){
CommandUtil.errorTranslatable("smod.command.mute.fail.tooShort");
}
if (sender.equals(target)) {
CommandUtil.errorTranslatable("smod.command.mute.fail.self");
} else {
@@ -25,11 +25,15 @@ public class CustomInventoryListener implements Listener {
}
}
public static void onTick(){
public static void tickAllPaper(){
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
tickForPlayer(onlinePlayer);
}
}
public static void tickForPlayer(Player onlinePlayer) {
if (onlinePlayer.getOpenInventory().getTopInventory().getHolder() instanceof AutoUpdatingCustomInventory ci) {
ci.refresh();
}
}
}
}
@@ -0,0 +1,44 @@
package de.shiewk.smoderation.paper.listener;
import de.shiewk.smoderation.paper.SModerationPaper;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
public class FoliaInventoryUpdatingListener implements Listener {
public static final String METADATA_KEY = "smod_invtick";
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event){
Player player = event.getPlayer();
ScheduledTask task = player.getScheduler().runAtFixedRate(
SModerationPaper.PLUGIN,
t -> CustomInventoryListener.tickForPlayer(player),
null,
1,
1
);
player.setMetadata(METADATA_KEY, new FixedMetadataValue(
SModerationPaper.PLUGIN,
task
));
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event){
for (MetadataValue meta : event.getPlayer().getMetadata("smod_invtick")) {
if (meta.getOwningPlugin() == SModerationPaper.PLUGIN) {
if (meta.value() instanceof ScheduledTask task) {
task.cancel();
}
}
}
}
}
+8
View File
@@ -23,3 +23,11 @@ muted-forbidden-commands:
- minecraft:teammsg
- minecraft:tm
- minecraft:me
features:
punishments: true
smodmenu: true
invsee: true
enderchestsee: true
offlinetp: true
socialspy: true
vanish: true
@@ -24,6 +24,7 @@
"smod.command.mute.fail.forceReason": "Please provide a reason.",
"smod.command.mute.fail.protect": "This player can't be muted.",
"smod.command.mute.fail.self": "You can't mute yourself.",
"smod.command.mute.fail.tooShort": "You can't mute a player for less than 1ms.",
"smod.command.offlinetp.fail.unknown": "This player's location is unknown.",
"smod.command.offlinetp.teleporting": "<prefix>Teleporting you to <secondary><arg:0></secondary>.",
"smod.command.socialspy.disabled": "<prefix>SocialSpy <red>disabled</red>.",