mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
(1.7.1) Fix Folia inventory ticking error (#11)
This commit is contained in:
+1
-1
@@ -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(),
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+44
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user