-
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.
This change includes: - pathetic-mapper is no more and was replaced with a specific module pathetic-bukkit - pathetic-model is now pathetic-engine - pathetic-engine is now independent of the bukkit api - the required shutdown process was replaced with a shutdown hook - the PathfinderFactory is now part of the pathetic-api and has to be instantiated with the respective PathfinderInitializer
- Loading branch information
1 parent
5398136
commit 40fc3e3
Showing
31 changed files
with
291 additions
and
274 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
pathetic-api/src/main/java/de/metaphoriker/pathetic/api/pathing/PathfinderFactory.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,30 @@ | ||
package de.metaphoriker.pathetic.api.pathing; | ||
|
||
import de.metaphoriker.pathetic.api.pathing.configuration.PathfinderConfiguration; | ||
|
||
/** | ||
* A factory class for creating {@link Pathfinder} instances. | ||
* | ||
* @param <I> The type of {@link PathfinderInitializer} used to initialize the pathfinder. | ||
*/ | ||
public abstract class PathfinderFactory<I extends PathfinderInitializer> { | ||
|
||
protected final I initializer; | ||
|
||
/** | ||
* Creates a new {@link PathfinderFactory} with the given initializer. | ||
* | ||
* @param initializer The initializer to use for initializing the pathfinder. | ||
*/ | ||
public PathfinderFactory(I initializer) { | ||
this.initializer = initializer; | ||
} | ||
|
||
/** | ||
* Creates a new {@link Pathfinder} instance with the given configuration. | ||
* | ||
* @param configuration The configuration for the pathfinder. | ||
* @return A new {@link Pathfinder} instance. | ||
*/ | ||
public abstract Pathfinder createPathfinder(PathfinderConfiguration configuration); | ||
} |
17 changes: 17 additions & 0 deletions
17
pathetic-api/src/main/java/de/metaphoriker/pathetic/api/pathing/PathfinderInitializer.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,17 @@ | ||
package de.metaphoriker.pathetic.api.pathing; | ||
|
||
import de.metaphoriker.pathetic.api.pathing.configuration.PathfinderConfiguration; | ||
|
||
/** | ||
* An interface for initializing {@link Pathfinder} instances. | ||
*/ | ||
public interface PathfinderInitializer { | ||
|
||
/** | ||
* Initializes the given {@link Pathfinder} with the given {@link PathfinderConfiguration}. | ||
* | ||
* @param pathfinder The pathfinder to initialize. | ||
* @param configuration The configuration for the pathfinder. | ||
*/ | ||
void initialize(Pathfinder pathfinder, PathfinderConfiguration configuration); | ||
} |
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
67 changes: 67 additions & 0 deletions
67
pathetic-bukkit/src/main/java/de/metaphoriker/pathetic/bukkit/PatheticBukkit.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,67 @@ | ||
package de.metaphoriker.pathetic.bukkit; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
import de.metaphoriker.pathetic.Pathetic; | ||
import de.metaphoriker.pathetic.api.event.EventPublisher; | ||
import de.metaphoriker.pathetic.api.event.PathingStartFindEvent; | ||
import de.metaphoriker.pathetic.bukkit.listener.ChunkInvalidateListener; | ||
import de.metaphoriker.pathetic.bukkit.util.BukkitVersionUtil; | ||
import de.metaphoriker.pathetic.util.ErrorLogger; | ||
import lombok.experimental.UtilityClass; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
@Slf4j | ||
@UtilityClass | ||
public class PatheticBukkit { | ||
|
||
private static JavaPlugin instance; | ||
|
||
/** | ||
* @throws IllegalStateException If an attempt is made to initialize more than 1 time | ||
*/ | ||
public static void initialize(JavaPlugin javaPlugin) { | ||
|
||
if (instance != null) throw ErrorLogger.logFatalError("Can't be initialized twice"); | ||
|
||
instance = javaPlugin; | ||
Bukkit.getPluginManager().registerEvents(new ChunkInvalidateListener(), javaPlugin); | ||
|
||
registerPathingStartListener(); | ||
Pathetic.loadEngineVersion(); | ||
|
||
if (BukkitVersionUtil.getVersion().isUnder(16, 0) | ||
|| BukkitVersionUtil.getVersion().isEqual(BukkitVersionUtil.Version.of(16, 0))) { | ||
log.warn( | ||
"Pathetic is currently running in a version older than or equal to 1.16. " | ||
+ "Some functionalities might not be accessible, such as accessing the BlockState of blocks."); | ||
} | ||
|
||
log.debug("Pathetic v{} initialized", Pathetic.getEngineVersion()); | ||
} | ||
|
||
public static boolean isInitialized() { | ||
return instance != null; | ||
} | ||
|
||
public static JavaPlugin getPluginInstance() { | ||
return instance; | ||
} | ||
|
||
private static void registerPathingStartListener() { | ||
EventPublisher.registerListener( | ||
new Object() { | ||
@Subscribe | ||
public void onPathingStart(PathingStartFindEvent event) { | ||
pushToBStatsIfActivated(event); | ||
} | ||
|
||
private void pushToBStatsIfActivated(PathingStartFindEvent event) { | ||
if (event.getPathfinderConfiguration().isBStats()) { | ||
BStatsHandler.increasePathCount(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...bukkit/src/main/java/de/metaphoriker/pathetic/bukkit/factory/BukkitPathfinderFactory.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,33 @@ | ||
package de.metaphoriker.pathetic.bukkit.factory; | ||
|
||
import de.metaphoriker.pathetic.api.pathing.Pathfinder; | ||
import de.metaphoriker.pathetic.api.pathing.PathfinderFactory; | ||
import de.metaphoriker.pathetic.api.pathing.configuration.PathfinderConfiguration; | ||
import de.metaphoriker.pathetic.api.snapshot.BlockProvider; | ||
import de.metaphoriker.pathetic.bukkit.provider.FailingBlockProvider; | ||
import de.metaphoriker.pathetic.engine.pathfinder.AStarPathfinder; | ||
|
||
public class BukkitPathfinderFactory extends PathfinderFactory<BukkitPathfinderInitializer> { | ||
|
||
/** | ||
* Creates a new {@link PathfinderFactory} with the given initializer. | ||
* | ||
* @param initializer The initializer to use for initializing the pathfinder. | ||
*/ | ||
public BukkitPathfinderFactory(BukkitPathfinderInitializer initializer) { | ||
super(initializer); | ||
} | ||
|
||
@Override | ||
public Pathfinder createPathfinder(PathfinderConfiguration configuration) { | ||
Pathfinder pathfinder = new AStarPathfinder(getBlockProvider(configuration), configuration); | ||
initializer.initialize(pathfinder, configuration); | ||
return pathfinder; | ||
} | ||
|
||
private BlockProvider getBlockProvider(PathfinderConfiguration configuration) { | ||
return configuration.isLoadingChunks() | ||
? new FailingBlockProvider.RequestingBlockProvider() | ||
: new FailingBlockProvider(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...it/src/main/java/de/metaphoriker/pathetic/bukkit/factory/BukkitPathfinderInitializer.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.bukkit.factory; | ||
|
||
import de.metaphoriker.pathetic.api.pathing.Pathfinder; | ||
import de.metaphoriker.pathetic.api.pathing.PathfinderInitializer; | ||
import de.metaphoriker.pathetic.api.pathing.configuration.PathfinderConfiguration; | ||
import de.metaphoriker.pathetic.bukkit.hook.SpigotPathfindingHook; | ||
|
||
public class BukkitPathfinderInitializer implements PathfinderInitializer { | ||
|
||
@Override | ||
public void initialize(Pathfinder pathfinder, PathfinderConfiguration configuration) { | ||
pathfinder.registerPathfindingHook(new SpigotPathfindingHook()); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ing/pathfinder/SpigotPathfindingHook.java → ...ic/bukkit/hook/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
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
2 changes: 1 addition & 1 deletion
2
...pathetic/mapping/bukkit/BukkitMapper.java → .../pathetic/bukkit/mapper/BukkitMapper.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
Oops, something went wrong.