Skip to content

Commit

Permalink
feat(CatScheduler): 优化CatScheduler类以提高代码可读性
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Jul 31, 2024
1 parent dfcfaf9 commit 2a21cae
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/main/java/cc/baka9/catseedlogin/bukkit/CatScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,25 @@
import space.arim.morepaperlib.scheduling.ScheduledTask;

public class CatScheduler {
// folia check
private static final boolean folia = isFolia();
private static final Method teleportAsync;
private static final boolean folia = CatSeedLogin.morePaperLib.scheduling().isUsingFolia();
private static final Method teleportAsync = initTeleportAsync();

static {
// init reflect for folia
Method tempTeleportAsync = null;
private static Method initTeleportAsync() {
if (folia) {
try {
tempTeleportAsync = Player.class.getMethod("teleportAsync", Location.class);
return Player.class.getMethod("teleportAsync", Location.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
teleportAsync = tempTeleportAsync;
}

private static boolean isFolia() {
return CatSeedLogin.morePaperLib.scheduling().isUsingFolia();
return null;
}

public static void teleport(Player player, Location location) {
if (!folia) {
player.teleport(location);
return;
}

CatSeedLogin.morePaperLib.scheduling().entitySpecificScheduler(player).run(() -> {
try {
teleportAsync.invoke(player, location);
Expand Down

0 comments on commit 2a21cae

Please sign in to comment.