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

2 Commits

Author SHA1 Message Date
Shiewk 4ef2700d6b (1.7.1) Fix Folia inventory ticking error (#11) 2025-09-19 14:38:35 +02:00
Shiewk 7826c4e75a Make the mute command require a positive duration 2025-08-24 11:38:21 +02:00
6 changed files with 76 additions and 13 deletions
+1 -1
View File
@@ -1 +1 @@
pluginVersion = 1.7.0 pluginVersion = 1.7.1
@@ -22,6 +22,7 @@ import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
@@ -73,13 +74,13 @@ public final class SModerationPaper extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
getPluginManager().registerEvents(new PunishmentListener(), this); listen(new PunishmentListener());
getPluginManager().registerEvents(new CustomInventoryListener(), this); listen(new CustomInventoryListener());
getPluginManager().registerEvents(new InvSeeListener(), this); listen(new InvSeeListener());
getPluginManager().registerEvents(new EnderchestSeeListener(), this); listen(new EnderchestSeeListener());
getPluginManager().registerEvents(new VanishListener(), this); listen(new VanishListener());
getPluginManager().registerEvents(new ChatInputListener(), this); listen(new ChatInputListener());
getPluginManager().registerEvents(new SocialSpyListener(), this); listen(new SocialSpyListener());
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> { getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
Commands commands = event.registrar(); Commands commands = event.registrar();
@@ -98,7 +99,13 @@ public final class SModerationPaper extends JavaPlugin {
registerCommand(commands, new OfflineTPCommand()); 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); SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1);
container.load(SAVE_FILE); container.load(SAVE_FILE);
@@ -106,6 +113,10 @@ public final class SModerationPaper extends JavaPlugin {
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no"); LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
} }
private void listen(Listener listener) {
getPluginManager().registerEvents(listener, this);
}
private void registerCommand(Commands commands, CommandProvider provider){ private void registerCommand(Commands commands, CommandProvider provider){
commands.register( commands.register(
provider.getCommandNode(), provider.getCommandNode(),
@@ -59,6 +59,9 @@ public final class MuteCommand implements CommandProvider {
} }
public static void executeMute(UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException { 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)) { if (sender.equals(target)) {
CommandUtil.errorTranslatable("smod.command.mute.fail.self"); CommandUtil.errorTranslatable("smod.command.mute.fail.self");
} else { } else {
@@ -25,11 +25,15 @@ public class CustomInventoryListener implements Listener {
} }
} }
public static void onTick(){ public static void tickAllPaper(){
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.getOpenInventory().getTopInventory().getHolder() instanceof AutoUpdatingCustomInventory ci) { tickForPlayer(onlinePlayer);
ci.refresh(); }
} }
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();
}
}
}
}
}
@@ -24,6 +24,7 @@
"smod.command.mute.fail.forceReason": "Please provide a reason.", "smod.command.mute.fail.forceReason": "Please provide a reason.",
"smod.command.mute.fail.protect": "This player can't be muted.", "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.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.fail.unknown": "This player's location is unknown.",
"smod.command.offlinetp.teleporting": "<prefix>Teleporting you to <secondary><arg:0></secondary>.", "smod.command.offlinetp.teleporting": "<prefix>Teleporting you to <secondary><arg:0></secondary>.",
"smod.command.socialspy.disabled": "<prefix>SocialSpy <red>disabled</red>.", "smod.command.socialspy.disabled": "<prefix>SocialSpy <red>disabled</red>.",