Added Dynmap hook

#475
This commit is contained in:
Florian CUNY 2019-04-13 14:22:05 +02:00
parent 7df34d73ba
commit 9386e8aa71
3 changed files with 98 additions and 0 deletions

11
pom.xml
View File

@ -130,6 +130,10 @@
<id>placeholderapi-repo</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>dynmap-repo</id>
<url>http://repo.mikeprimm.com/</url>
</repository>
</repositories>
<dependencies>
@ -186,6 +190,13 @@
<version>${placeholder.version}</version>
<scope>provided</scope>
</dependency>
<!-- Hooks -->
<dependency>
<groupId>us.dynmap</groupId>
<artifactId>dynmap-api</artifactId>
<version>3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Static analysis -->
<!-- We are using Eclipse's annotations.
If you're using IDEA, update your project settings to take these

View File

@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.Notifier;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.commands.BentoBoxCommand;
import world.bentobox.bentobox.hooks.DynmapHook;
import world.bentobox.bentobox.hooks.MultiverseCoreHook;
import world.bentobox.bentobox.hooks.PlaceholderAPIHook;
import world.bentobox.bentobox.hooks.VaultHook;
@ -181,6 +182,9 @@ public class BentoBox extends JavaPlugin {
hooksManager.registerHook(new MultiverseCoreHook());
islandWorldManager.registerWorldsToMultiverse();
// Register additional hooks
hooksManager.registerHook(new DynmapHook());
webManager = new WebManager(this);
webManager.requestGitHubData();

View File

@ -0,0 +1,83 @@
package world.bentobox.bentobox.hooks;
import org.bukkit.Material;
import org.dynmap.DynmapAPI;
import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerSet;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.hooks.Hook;
import java.util.HashMap;
import java.util.Map;
/**
* @author Poslovitch
* @since 1.5.0
*/
public class DynmapHook extends Hook {
private MarkerAPI markerAPI;
@NonNull
private Map<@NonNull GameModeAddon, @NonNull MarkerSet> markerSets;
public DynmapHook() {
super("dynmap", Material.FILLED_MAP);
this.markerSets = new HashMap<>();
}
@Override
public boolean hook() {
DynmapAPI dynmapAPI = (DynmapAPI) getPlugin();
MarkerAPI markers = dynmapAPI.getMarkerAPI();
if (markers == null) {
return false;
}
markerAPI = markers;
BentoBox.getInstance().getAddonsManager().getGameModeAddons().forEach(this::registerMarkerSet);
return true;
}
public 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)
MarkerSet set = markerAPI.createMarkerSet(name.toLowerCase() + ".markers", name, null, true);
markerSets.put(addon, set);
}
}
@NonNull
public Map<GameModeAddon, MarkerSet> getMarkerSets() {
return markerSets;
}
@Nullable
public MarkerSet getMarkerSet(@NonNull GameModeAddon addon) {
if (markerSets.containsKey(addon)) {
return markerSets.get(addon);
} else {
return markerAPI.getMarkerSet(addon.getDescription().getName().toLowerCase() + ".markers");
}
}
/**
* Returns the MarkerAPI instance. Not null.
* @return the MarkerAPI instance.
*/
@NonNull
public MarkerAPI getMarkerAPI() {
return markerAPI;
}
@Override
public String getFailureCause() {
return "the version of dynmap you're using is incompatible with this hook";
}
}