Skip to content

Commit

Permalink
Added Folia scheduler for fishhook entity checks. Added v1_21_R2 se…
Browse files Browse the repository at this point in the history
…rver version. Changed version to `2.9.13a-SNAPSHOT-01`.
  • Loading branch information
Loving11ish committed Sep 11, 2024
1 parent b6822e8 commit 1214142
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tasks.compileJava.configure {
options.release.set(8)
}

version = "2.9.12a"
version = "2.9.13a-SNAPSHOT-01"

tasks.named<Copy>("processResources") {
filesMatching("plugin.yml") {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/main/java/me/dniym/IllegalStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,8 @@ private void setVersion() {
serverVersion = ServerVersion.v1_20_R5;
} else if (bukkitVersion.contains("1.21")) {
serverVersion = ServerVersion.v1_21_R1;
} else if (bukkitVersion.contains("1.21.1")) {
serverVersion = ServerVersion.v1_21_R2;
} else {
serverVersion = ServerVersion.valueOf(packageName.replace("org.bukkit.craftbukkit.", ""));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/main/java/me/dniym/enums/ServerVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public enum ServerVersion {
v1_20_R3,
v1_20_R4,
v1_20_R5,
v1_21_R1;
v1_21_R1,
v1_21_R2;

public boolean serverVersionEqual(ServerVersion version) {
return this.equals(version);
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/main/java/me/dniym/fishing/FishAttempt.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main.java.me.dniym.fishing;

import main.java.me.dniym.IllegalStack;
import main.java.me.dniym.utils.Scheduler;
import org.bukkit.Location;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
Expand All @@ -8,6 +10,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

public class FishAttempt {

Expand All @@ -33,12 +36,17 @@ public static FishAttempt findPlayer(Player p) {
}

public static FishHook findHook(Player player) {
final AtomicReference<FishHook> fishHook = new AtomicReference<>();
for (FishHook fh : player.getWorld().getEntitiesByClass(FishHook.class)) {
if (fh.getShooter() instanceof Player) {
if (fh.getShooter() == player) {
return fh;
// Get the fishhook entity's scheduler to run a task to check if the fishhook's shooter is the player
Scheduler.runTask(IllegalStack.getPlugin(), () -> {
if (fh.getShooter() instanceof Player) {
if (fh.getShooter() == player) {
fishHook.set(fh);
}
}
}
}, fh);
return fishHook.get();
}
return null;
}
Expand Down

0 comments on commit 1214142

Please sign in to comment.