diff --git a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/listener/BallBukkitListener.java b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/listener/BallBukkitListener.java index 67b24a5..ec528cf 100644 --- a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/listener/BallBukkitListener.java +++ b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/listener/BallBukkitListener.java @@ -13,6 +13,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerLoginEvent; @@ -84,7 +85,7 @@ public class BallBukkitListener extends BallListener implements Listener { Bukkit.shutdown(); } - @EventHandler(ignoreCancelled = true) + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onPlayerLogin(PlayerLoginEvent event) { Player player = event.getPlayer(); Location location = playerToLocation.remove(player.getUniqueId()); @@ -93,7 +94,7 @@ public class BallBukkitListener extends BallListener implements Listener { } } - @EventHandler(ignoreCancelled = true) + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onAsyncPlayerChat(AsyncPlayerChatEvent event) { } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java index c788485..fa2e655 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java @@ -13,6 +13,7 @@ import cn.hamster3.mc.plugin.ball.common.event.player.*; import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent; import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent; import cn.hamster3.mc.plugin.ball.common.listener.BallListener; +import cn.hamster3.mc.plugin.ball.common.listener.ListenerPriority; import cn.hamster3.mc.plugin.core.common.api.CoreAPI; import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects; import cn.hamster3.mc.plugin.core.common.data.Message; @@ -75,8 +76,8 @@ public abstract class BallAPI { addListener(new BallListener() { @Override - public int getPriority() { - return 0; + public ListenerPriority getPriority() { + return ListenerPriority.LOW; } @Override @@ -431,9 +432,9 @@ public abstract class BallAPI { /** * 给玩家发送一条消息 * - * @param receiver 玩家 - * @param message 消息 - * @param cache 当玩家不在线时,是否缓存消息等待玩家上线再发送 + * @param receiver 玩家 + * @param message 消息 + * @param cache 当玩家不在线时,是否缓存消息等待玩家上线再发送 */ public void sendMessageToPlayer(@NotNull Set receiver, @NotNull Message message, boolean cache) { for (UUID uuid : receiver) { @@ -662,7 +663,7 @@ public abstract class BallAPI { public void addListener(@NotNull BallListener listener) { listeners.add(listener); - listeners.sort(Comparator.comparingInt(BallListener::getPriority)); + listeners.sort(Comparator.comparing(BallListener::getPriority)); } public void removeListener(@NotNull BallListener listener) { diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/connector/BallChannelInboundHandler.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/connector/BallChannelInboundHandler.java index e431f7d..7682026 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/connector/BallChannelInboundHandler.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/connector/BallChannelInboundHandler.java @@ -109,33 +109,11 @@ public class BallChannelInboundHandler extends SimpleChannelInboundHandler + * 仅在使用 velocity 代理端时才会触发这个事件 */ @Data @AllArgsConstructor diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPreLoginEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPreLoginEvent.java index 6a1755f..23ce371 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPreLoginEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPreLoginEvent.java @@ -5,7 +5,7 @@ import lombok.Data; import org.jetbrains.annotations.NotNull; /** - * 玩家准备连接到服务器 + * 玩家准备连接到代理服务器 */ @Data @AllArgsConstructor diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/BallListener.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/BallListener.java index 8ba0763..6c89e96 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/BallListener.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/BallListener.java @@ -10,13 +10,11 @@ import org.jetbrains.annotations.NotNull; public abstract class BallListener { /** * 该监听器的执行优先级 - *

- * 数字越低越先执行 * * @return 优先级 */ - public int getPriority() { - return 100; + public ListenerPriority getPriority() { + return ListenerPriority.NORMAL; } public void onBroadcastPlayerMessage(@NotNull BroadcastPlayerMessageEvent event) { @@ -61,7 +59,7 @@ public abstract class BallListener { public void onBallPlayerLogout(@NotNull BallPlayerLogoutEvent event) { } - public void onPlayerChat(@NotNull BallPlayerChatEvent event) { + public void onBallPlayerChat(@NotNull BallPlayerChatEvent event) { } public void onServerOffline(@NotNull ServerOfflineEvent event) { @@ -70,10 +68,10 @@ public abstract class BallListener { public void onServerOnline(@NotNull ServerOnlineEvent event) { } - public void onMessageReceived(@NotNull MessageInfo event) { + public void onMessageSend(@NotNull MessageInfo event) { } - public void onMessageSend(@NotNull MessageInfo event) { + public void onMessageReceived(@NotNull MessageInfo event) { } public void onConnectInactive() { diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/ListenerPriority.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/ListenerPriority.java new file mode 100644 index 0000000..dc6f958 --- /dev/null +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/ListenerPriority.java @@ -0,0 +1,45 @@ +package cn.hamster3.mc.plugin.ball.common.listener; + +@SuppressWarnings("unused") +public enum ListenerPriority { + + /** + * Event call is of very low importance and should be ran first, to allow + * other plugins to further customise the outcome + */ + LOWEST(0), + /** + * Event call is of low importance + */ + LOW(1), + /** + * Event call is neither important nor unimportant, and may be ran + * normally + */ + NORMAL(2), + /** + * Event call is of high importance + */ + HIGH(3), + /** + * Event call is critical and must have the final say in what happens + * to the event + */ + HIGHEST(4), + /** + * Event is listened to purely for monitoring the outcome of an event. + *

+ * No modifications to the event should be made under this priority + */ + MONITOR(5); + + private final int slot; + + ListenerPriority(int slot) { + this.slot = slot; + } + + public int getSlot() { + return slot; + } +}