Skip to content

Commit

Permalink
Fix wrong event registration on spigot.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Nov 28, 2024
1 parent ff23318 commit 4173dd6
Show file tree
Hide file tree
Showing 15 changed files with 1,478 additions and 117 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ allprojects {
dependencies {
implementation(project(":core"))
implementation(project(":v1_20_1"))
implementation(project(":v1_21"))
implementation(project(":v1_21_paper"))
implementation(project(":v1_21_spigot"))
}

tasks.shadowJar {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/cn/lunadeer/dominion/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ public DominionDTO getPlayerCurrentDominion(@NotNull Player player) {
}

// 如果玩家上次所在领地和当前所在领地不同,则触发玩家跨领地边界事件
new PlayerCrossDominionBorderEvent(player, last_dominion, current_dominion).callEvent();
new PlayerCrossDominionBorderEvent(player, last_dominion, current_dominion).call();

// 如果上次记录的领地不为空,则触发玩家离开领地事件
if (last_dom_id != -1) {
new PlayerMoveOutDominionEvent(player, last_dominion).callEvent();
new PlayerMoveOutDominionEvent(player, last_dominion).call();
}
// 如果当前领地不为空,则触发玩家进入领地事件
if (current_dom_id != -1) {
new PlayerMoveInDominionEvent(player, current_dominion).callEvent();
new PlayerMoveInDominionEvent(player, current_dominion).call();
}
// 更新玩家当前所在领地缓存
if (current_dominion == null) {
Expand Down
14 changes: 9 additions & 5 deletions core/src/main/java/cn/lunadeer/dominion/EventsRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ public EventsRegister(JavaPlugin plugin) {
switch (version) {
case v1_21:
XLogger.debug("Load API version: 1.21");
registerEvents("cn.lunadeer.dominion.events_v1_21.PlayerEvents");
registerEvents("cn.lunadeer.dominion.events_v1_21.EnvironmentEvents");
registerEvents("cn.lunadeer.dominion.events_v1_21.SelectPointEvents");
if (Common.isPaper()) {
registerEvents("cn.lunadeer.dominion.events_v1_21.special.Paper");
XLogger.debug("Load Paper special events");
registerEvents("cn.lunadeer.dominion.events_v1_21_paper.PlayerEvents");
registerEvents("cn.lunadeer.dominion.events_v1_21_paper.EnvironmentEvents");
registerEvents("cn.lunadeer.dominion.events_v1_21_paper.SelectPointEvents");
} else {
registerEvents("cn.lunadeer.dominion.events_v1_21.special.Spigot");
XLogger.debug("Load Spigot special events");
registerEvents("cn.lunadeer.dominion.events_v1_21_spigot.PlayerEvents");
registerEvents("cn.lunadeer.dominion.events_v1_21_spigot.EnvironmentEvents");
registerEvents("cn.lunadeer.dominion.events_v1_21_spigot.SelectPointEvents");
}
break;
case v1_20_1:
Expand Down Expand Up @@ -54,6 +57,7 @@ enum APIVersion {

private static APIVersion GetAPIVersion(JavaPlugin plugin) {
String version = plugin.getServer().getBukkitVersion();
XLogger.debug("API version: %s", version);
if (version.contains("1.21")) {
return APIVersion.v1_21;
} else if (version.contains("1.20.1")
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ include(
"api",
"core",
"v1_20_1",
"v1_21"
"v1_21_paper",
"v1_21_spigot"
)

This file was deleted.

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cn.lunadeer.dominion.events_v1_21;
package cn.lunadeer.dominion.events_v1_21_paper;

import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.minecraftpluginutils.XLogger;
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -401,5 +402,25 @@ public void onGravityBlockFalling(EntityChangeBlockEvent event) { // gravity_b
}
}

@EventHandler(priority = EventPriority.HIGHEST) // monster_move
public void onMonsterPathfinding(EntityPathfindEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof Monster)) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(event.getLoc());
checkFlag(dom, Flag.MONSTER_MOVE, event);
}

@EventHandler(priority = EventPriority.HIGHEST) // animal_move
public void onAnimalPathfinding(EntityPathfindEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof Animals)) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(event.getLoc());
checkFlag(dom, Flag.ANIMAL_MOVE, event);
}

private static final Map<UUID, Location> fallingBlockMap = new java.util.HashMap<>();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package cn.lunadeer.dominion.events_v1_21;
package cn.lunadeer.dominion.events_v1_21_paper;

import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.minecraftpluginutils.Common;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Teleport;
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
Expand Down Expand Up @@ -649,12 +648,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
if (bed == null) {
bed = player.getWorld().getSpawnLocation();
}
if (Common.isPaper()) {
player.teleportAsync(bed, PlayerTeleportEvent.TeleportCause.PLUGIN);
} else {
player.teleport(bed, PlayerTeleportEvent.TeleportCause.PLUGIN);
}

player.teleportAsync(bed, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.lunadeer.dominion.events_v1_21;
package cn.lunadeer.dominion.events_v1_21_paper;

import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
Expand Down
18 changes: 18 additions & 0 deletions v1_21_spigot/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("java")
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}

// utf-8
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

dependencies {
compileOnly(project(":api"))
compileOnly(project(":core"))
compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT")
}
Loading

0 comments on commit 4173dd6

Please sign in to comment.