-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented a way to hook into the pathfinding process
- Loading branch information
1 parent
5336b2e
commit 3cbdd2d
Showing
7 changed files
with
88 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
pathetic-api/src/main/java/de/metaphoriker/pathetic/api/pathing/hook/PathfinderHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package de.metaphoriker.pathetic.api.pathing.hook; | ||
|
||
/** | ||
* Interface for hooks that are called during the pathfinding process. | ||
*/ | ||
public interface PathfinderHook { | ||
|
||
/** | ||
* Called on each step of the pathfinding process. | ||
* | ||
* @param pathfindingContext the context of the current pathfinding step | ||
*/ | ||
void onPathfindingStep(PathfindingContext pathfindingContext); | ||
} |
16 changes: 16 additions & 0 deletions
16
pathetic-api/src/main/java/de/metaphoriker/pathetic/api/pathing/hook/PathfindingContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.metaphoriker.pathetic.api.pathing.hook; | ||
|
||
import de.metaphoriker.pathetic.api.wrapper.Depth; | ||
import lombok.Value; | ||
|
||
/** | ||
* Context for the current step of the pathfinding process. | ||
*/ | ||
@Value | ||
public class PathfindingContext { | ||
|
||
/** | ||
* The depth of the current pathfinding step. | ||
*/ | ||
Depth depth; | ||
} |
2 changes: 1 addition & 1 deletion
2
...hetic/model/pathing/pathfinder/Depth.java → ...aphoriker/pathetic/api/wrapper/Depth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...rc/main/java/de/metaphoriker/pathetic/model/pathing/pathfinder/SpigotPathfindingHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.metaphoriker.pathetic.model.pathing.pathfinder; | ||
|
||
import de.metaphoriker.pathetic.api.pathing.hook.PathfinderHook; | ||
import de.metaphoriker.pathetic.api.pathing.hook.PathfindingContext; | ||
import de.metaphoriker.pathetic.api.wrapper.Depth; | ||
import de.metaphoriker.pathetic.util.WatchdogUtil; | ||
|
||
public class SpigotPathfindingHook implements PathfinderHook { | ||
|
||
@Override | ||
public void onPathfindingStep(PathfindingContext pathfindingContext) { | ||
tickWatchdogIfNeeded(pathfindingContext.getDepth()); | ||
} | ||
|
||
private void tickWatchdogIfNeeded(Depth depth) { | ||
if (depth.getDepth() % 500 == 0) { | ||
WatchdogUtil.tickWatchdog(); | ||
} | ||
} | ||
} |