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.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@@ -73,13 +74,13 @@ public final class SModerationPaper extends JavaPlugin {
@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);
listen(new PunishmentListener());
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();
@@ -98,7 +99,13 @@ public final class SModerationPaper extends JavaPlugin {
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);
@@ -106,6 +113,10 @@ public final class SModerationPaper extends JavaPlugin {
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
}
private void listen(Listener listener) {
getPluginManager().registerEvents(listener, this);
}
private void registerCommand(Commands commands, CommandProvider provider){
commands.register(
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 {
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();
}
}
}
}
}
@@ -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>.",