mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
(1.6.0) Switch to Paper plugin & support Folia
This commit is contained in:
+9
-2
@@ -18,11 +18,17 @@ processResources {
|
||||
def props = [version: version]
|
||||
inputs.properties props
|
||||
filteringCharset 'UTF-8'
|
||||
filesMatching('plugin.yml') {
|
||||
filesMatching('paper-plugin.yml') {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
|
||||
runPaper {
|
||||
folia {
|
||||
registerTask()
|
||||
}
|
||||
}
|
||||
|
||||
runServer {
|
||||
minecraftVersion("1.21.7")
|
||||
downloadPlugins {
|
||||
@@ -33,7 +39,8 @@ runServer {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT")
|
||||
//compileOnly "io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT"
|
||||
compileOnly 'dev.folia:folia-api:1.21.4-R0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
jar {
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
pluginVersion = 1.5.0
|
||||
pluginVersion = 1.6.0
|
||||
@@ -2,9 +2,11 @@ package de.shiewk.smoderation.paper;
|
||||
|
||||
import de.shiewk.smoderation.paper.command.*;
|
||||
import de.shiewk.smoderation.paper.config.SModerationConfig;
|
||||
import de.shiewk.smoderation.paper.input.ChatInput;
|
||||
import de.shiewk.smoderation.paper.input.ChatInputListener;
|
||||
import de.shiewk.smoderation.paper.listener.*;
|
||||
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
|
||||
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@@ -72,7 +74,12 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
registerCommand(commands, new BanCommand());
|
||||
});
|
||||
|
||||
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, CustomInventoryListener::onTick, 1, 1);
|
||||
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1);
|
||||
|
||||
container.load(SAVE_FILE);
|
||||
|
||||
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
|
||||
}
|
||||
|
||||
private void registerCommand(Commands commands, CommandProvider provider){
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ChatInput {
|
||||
this.remainingTicks = remainingSeconds * 20 + 1;
|
||||
}
|
||||
|
||||
static void tickAll() {
|
||||
public static void tickAll() {
|
||||
runningInputs.values().forEach(ChatInput::tick);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package de.shiewk.smoderation.paper.input;
|
||||
|
||||
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
@@ -26,8 +24,4 @@ public class ChatInputListener implements Listener {
|
||||
runningInputs.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR) public void onServerTickStart(ServerTickStartEvent event){
|
||||
ChatInput.tickAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.shiewk.smoderation.paper.inventory;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@@ -47,7 +48,7 @@ public class InvSeeEquipmentInventory implements AutoUpdatingCustomInventory {
|
||||
if (viewer.hasPermission("smod.invsee.modify") && !subject.hasPermission("smod.invsee.preventmodify")){
|
||||
event.setCancelled(false);
|
||||
changing = true;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModerationPaper.PLUGIN, () -> {
|
||||
SchedulerUtil.scheduleGlobal(SModerationPaper.PLUGIN, () -> {
|
||||
changing = false;
|
||||
final EntityEquipment equipment = subject.getEquipment();
|
||||
equipment.setHelmet(inventory.getItem(0));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.shiewk.smoderation.paper.inventory;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@@ -49,7 +50,7 @@ public class InvSeeInventory implements AutoUpdatingCustomInventory {
|
||||
if (viewer.hasPermission("smod.invsee.modify") && !subject.hasPermission("smod.invsee.preventmodify")){
|
||||
event.setCancelled(false);
|
||||
changing = true;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModerationPaper.PLUGIN, () -> {
|
||||
SchedulerUtil.scheduleGlobal(SModerationPaper.PLUGIN, () -> {
|
||||
changing = false;
|
||||
applyChanges();
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -114,12 +115,12 @@ public class SModMenu extends PageableCustomInventory {
|
||||
}
|
||||
|
||||
public void promptSearchQuery(){
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(PLUGIN, player::closeInventory);
|
||||
SchedulerUtil.scheduleForEntity(PLUGIN, player, player::closeInventory);
|
||||
ChatInput.prompt(player, component -> {
|
||||
if (component instanceof TextComponent text){
|
||||
this.searchQuery = text.content();
|
||||
// chat event is async
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(PLUGIN, this::open);
|
||||
SchedulerUtil.scheduleForEntity(PLUGIN, player, this::open);
|
||||
}
|
||||
}, text("Enter your search query in chat").color(SECONDARY_COLOR), 30);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package de.shiewk.smoderation.paper.listener;
|
||||
|
||||
import com.destroystokyo.paper.event.server.ServerTickEndEvent;
|
||||
import de.shiewk.smoderation.paper.inventory.AutoUpdatingCustomInventory;
|
||||
import de.shiewk.smoderation.paper.inventory.CustomInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -26,8 +25,7 @@ public class CustomInventoryListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onServerTickEnd(ServerTickEndEvent event){
|
||||
public static void onTick(){
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.getOpenInventory().getTopInventory().getHolder() instanceof AutoUpdatingCustomInventory ci) {
|
||||
ci.refresh();
|
||||
|
||||
@@ -2,6 +2,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 net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -52,7 +53,7 @@ public class VanishListener implements Listener {
|
||||
if (message != null){
|
||||
broadcast(message.color(null));
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModerationPaper.PLUGIN, () -> {
|
||||
SchedulerUtil.scheduleForEntity(SModerationPaper.PLUGIN, player, () -> {
|
||||
player.sendMessage(SModerationPaper.CHAT_PREFIX
|
||||
.decorate(TextDecoration.BOLD)
|
||||
.append(
|
||||
@@ -69,7 +70,7 @@ public class VanishListener implements Listener {
|
||||
player.getPersistentDataContainer().remove(VanishCommand.KEY_VANISHED);
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModerationPaper.PLUGIN, () -> {
|
||||
SchedulerUtil.scheduleForEntity(SModerationPaper.PLUGIN, player, () -> {
|
||||
if (player.hasPermission("smod.vanish.see")){
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to show visible vanished players
|
||||
|
||||
@@ -37,7 +37,7 @@ public class PunishmentContainer {
|
||||
}
|
||||
|
||||
public @Nullable Punishment find(Predicate<Punishment> predicate){
|
||||
for (Punishment punishment : new CopyOnWriteArrayList<>(punishments)) {
|
||||
for (Punishment punishment : punishments) {
|
||||
if (predicate.test(punishment)){
|
||||
return punishment;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class PunishmentContainer {
|
||||
|
||||
public @NotNull List<Punishment> findAll(Predicate<Punishment> predicate){
|
||||
List<Punishment> found = new ArrayList<>();
|
||||
for (Punishment punishment : new CopyOnWriteArrayList<>(punishments)) {
|
||||
for (Punishment punishment : punishments) {
|
||||
if (predicate.test(punishment)){
|
||||
found.add(punishment);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class PunishmentContainer {
|
||||
return new ArrayList<>(punishments);
|
||||
}
|
||||
|
||||
public void load(File file){
|
||||
public synchronized void load(File file){
|
||||
final ComponentLogger logger = SModerationPaper.LOGGER;
|
||||
try {
|
||||
logger.info("Loading from {}", file.getPath());
|
||||
@@ -99,7 +99,7 @@ public class PunishmentContainer {
|
||||
}
|
||||
}
|
||||
|
||||
public void save(File file) {
|
||||
public synchronized void save(File file) {
|
||||
final ComponentLogger logger = SModerationPaper.LOGGER;
|
||||
try {
|
||||
if (!file.isFile()){
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package de.shiewk.smoderation.paper.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* This class provides some convenience methods that make Folia support easier
|
||||
*/
|
||||
public final class SchedulerUtil {
|
||||
private SchedulerUtil(){}
|
||||
|
||||
public static final boolean isFolia;
|
||||
|
||||
static {
|
||||
boolean folia;
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
folia = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
folia = false;
|
||||
}
|
||||
isFolia = folia;
|
||||
}
|
||||
|
||||
public static void scheduleForEntity(Plugin plugin, Entity entity, Runnable task, int delayTicks){
|
||||
if (isFolia){
|
||||
entity.getScheduler().execute(plugin, task, null, delayTicks);
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task, delayTicks);
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleForEntity(Plugin plugin, Entity entity, Runnable task){
|
||||
if (isFolia){
|
||||
entity.getScheduler().run(plugin, t -> task.run(), null);
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task);
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleGlobalRepeating(Plugin plugin, Runnable task, int delay, int interval){
|
||||
if (isFolia){
|
||||
Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, t -> task.run(), delay, interval);
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, interval);
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleGlobal(Plugin plugin, Runnable task){
|
||||
if (isFolia){
|
||||
Bukkit.getGlobalRegionScheduler().run(plugin, t -> task.run());
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
name: SModeration
|
||||
version: '${version}'
|
||||
main: de.shiewk.smoderation.paper.SModerationPaper
|
||||
website: https://github.com/Shiewk/SModeration
|
||||
api-version: '1.21.3'
|
||||
load: STARTUP
|
||||
authors:
|
||||
- Shiewk
|
||||
description: "SModeration is an easy-to-use minecraft plugin for moderating your server."
|
||||
folia-supported: true
|
||||
permissions:
|
||||
smod.mute:
|
||||
default: op
|
||||
Reference in New Issue
Block a user