Initial implementation of BlueMap hook.
WIP needs listeners to adapt when new islands made.
This commit is contained in:
parent
59c18e26f5
commit
8f4a962e5c
8
pom.xml
8
pom.xml
|
@ -88,7 +88,7 @@
|
|||
<!-- Do not change unless you want different name for local builds. -->
|
||||
<build.number>-LOCAL</build.number>
|
||||
<!-- This allows to change between versions. -->
|
||||
<build.version>2.0.1</build.version>
|
||||
<build.version>2.1.0</build.version>
|
||||
<sonar.organization>bentobox-world</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
<server.jars>${project.basedir}/lib</server.jars>
|
||||
|
@ -297,6 +297,12 @@
|
|||
<version>${myworlds.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.BlueMap-Minecraft</groupId>
|
||||
<artifactId>BlueMapAPI</artifactId>
|
||||
<version>v2.6.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Shaded APIs -->
|
||||
<dependency>
|
||||
<groupId>com.github.TheBusyBiscuit</groupId>
|
||||
|
|
|
@ -24,6 +24,7 @@ import world.bentobox.bentobox.api.user.Notifier;
|
|||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.commands.BentoBoxCommand;
|
||||
import world.bentobox.bentobox.database.DatabaseSetup;
|
||||
import world.bentobox.bentobox.hooks.BlueMapHook;
|
||||
import world.bentobox.bentobox.hooks.ItemsAdderHook;
|
||||
import world.bentobox.bentobox.hooks.MultiverseCoreHook;
|
||||
import world.bentobox.bentobox.hooks.MyWorldsHook;
|
||||
|
@ -239,6 +240,9 @@ public class BentoBox extends JavaPlugin implements Listener {
|
|||
// Register ItemsAdder
|
||||
hooksManager.registerHook(new ItemsAdderHook(this));
|
||||
|
||||
// BlueMap
|
||||
hooksManager.registerHook(new BlueMapHook());
|
||||
|
||||
// TODO: re-enable after implementation
|
||||
//hooksManager.registerHook(new DynmapHook());
|
||||
// TODO: re-enable after rework
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package world.bentobox.bentobox.hooks;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import de.bluecolored.bluemap.api.BlueMapAPI;
|
||||
import de.bluecolored.bluemap.api.BlueMapMap;
|
||||
import de.bluecolored.bluemap.api.markers.MarkerSet;
|
||||
import de.bluecolored.bluemap.api.markers.POIMarker;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.hooks.Hook;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class BlueMapHook extends Hook implements Listener {
|
||||
|
||||
private BlueMapAPI api;
|
||||
|
||||
public BlueMapHook() {
|
||||
super("BlueMap", Material.MAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hook() {
|
||||
if (BlueMapAPI.getInstance().isPresent()) {
|
||||
api = BlueMapAPI.getInstance().get();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// Register the islands known at hook time
|
||||
BentoBox.getInstance().getAddonsManager().getGameModeAddons().forEach(this::getMarkerSet);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void getMarkerSet(@NonNull GameModeAddon addon) {
|
||||
MarkerSet markerSet = MarkerSet.builder().label(addon.getWorldSettings().getFriendlyName()).build();
|
||||
// Register the island name for each island in this addon
|
||||
BentoBox.getInstance().getIslands().getIslands(addon.getOverWorld()).stream()
|
||||
.filter(is -> is.getOwner() != null).forEach(island -> {
|
||||
String name = getIslandName(island);
|
||||
POIMarker marker = POIMarker.builder().label(name)
|
||||
.position(island.getCenter().getX(), island.getCenter().getY(), island.getCenter().getZ())
|
||||
.maxDistance(1000).build();
|
||||
markerSet.getMarkers().put(addon.getWorldSettings().getFriendlyName(), marker);
|
||||
});
|
||||
// Over world
|
||||
api.getWorld(addon.getOverWorld()).ifPresent(world -> {
|
||||
for (BlueMapMap map : world.getMaps()) {
|
||||
map.getMarkerSets().put(addon.getWorldSettings().getFriendlyName(), markerSet);
|
||||
}
|
||||
});
|
||||
// Nether
|
||||
if (addon.getWorldSettings().isNetherGenerate() && addon.getWorldSettings().isNetherIslands()) {
|
||||
api.getWorld(addon.getNetherWorld()).ifPresent(world -> {
|
||||
for (BlueMapMap map : world.getMaps()) {
|
||||
map.getMarkerSets().put(addon.getWorldSettings().getFriendlyName(), markerSet);
|
||||
}
|
||||
});
|
||||
}
|
||||
// End
|
||||
if (addon.getWorldSettings().isEndGenerate() && addon.getWorldSettings().isEndIslands()) {
|
||||
api.getWorld(addon.getEndWorld()).ifPresent(world -> {
|
||||
for (BlueMapMap map : world.getMaps()) {
|
||||
map.getMarkerSets().put(addon.getWorldSettings().getFriendlyName(), markerSet);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private String getIslandName(Island island) {
|
||||
if (island.getName() != null && !island.getName().isBlank()) {
|
||||
// Name has been set
|
||||
return island.getName();
|
||||
} else if (island.getOwner() != null) {
|
||||
return User.getInstance(island.getOwner()).getDisplayName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFailureCause() {
|
||||
return "the version of BlueMap is incompatible with this hook. Use a newer version.";
|
||||
}
|
||||
}
|
|
@ -51,7 +51,7 @@ public class DynmapHook extends Hook {
|
|||
}
|
||||
}
|
||||
|
||||
public void registerMarkerSet(@NonNull GameModeAddon addon) {
|
||||
private void registerMarkerSet(@NonNull GameModeAddon addon) {
|
||||
String name = addon.getDescription().getName();
|
||||
if (getMarkerSet(addon) == null) {
|
||||
// From the javadoc: createMarkerSet(String id, String label, Set<MarkerIcon> allowedIcons, boolean persistent)
|
||||
|
@ -66,7 +66,7 @@ public class DynmapHook extends Hook {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public MarkerSet getMarkerSet(@NonNull GameModeAddon addon) {
|
||||
private MarkerSet getMarkerSet(@NonNull GameModeAddon addon) {
|
||||
if (markerSets.containsKey(addon)) {
|
||||
return markerSets.get(addon);
|
||||
} else {
|
||||
|
|
|
@ -26,6 +26,7 @@ softdepend:
|
|||
- LuckPerms
|
||||
- HolographicDisplays
|
||||
- EconomyPlus
|
||||
- BlueMap
|
||||
|
||||
libraries:
|
||||
- mysql:mysql-connector-java:${mysql.version}
|
||||
|
|
Loading…
Reference in New Issue