From 98fa779046fc7e29e0b465ae4463749b15a5a751 Mon Sep 17 00:00:00 2001 From: William278 Date: Wed, 22 Mar 2023 12:12:53 +0000 Subject: [PATCH] Rewrite map hooks, use more modern APIs --- bukkit/build.gradle | 4 - .../william278/huskhomes/BukkitHuskHomes.java | 29 ++- .../william278/huskhomes/hook/DynMapHook.java | 212 --------------- .../huskhomes/hook/RedisEconomyHook.java | 6 +- .../huskhomes/hook/VaultEconomyHook.java | 4 +- common/build.gradle | 3 +- .../net/william278/huskhomes/HuskHomes.java | 18 +- .../william278/huskhomes/config/Settings.java | 6 +- .../huskhomes/hook/BlueMapHook.java | 208 +++++++-------- .../william278/huskhomes/hook/DynmapHook.java | 243 ++++++++++++++++++ .../huskhomes/hook/EconomyHook.java | 2 +- .../net/william278/huskhomes/hook/Hook.java | 42 +++ .../william278/huskhomes/hook/MapHook.java | 92 +++---- .../william278/huskhomes/hook/PlanHook.java | 7 +- .../william278/huskhomes/hook/PluginHook.java | 44 ---- 15 files changed, 457 insertions(+), 463 deletions(-) delete mode 100644 bukkit/src/main/java/net/william278/huskhomes/hook/DynMapHook.java create mode 100644 common/src/main/java/net/william278/huskhomes/hook/DynmapHook.java create mode 100644 common/src/main/java/net/william278/huskhomes/hook/Hook.java delete mode 100644 common/src/main/java/net/william278/huskhomes/hook/PluginHook.java diff --git a/bukkit/build.gradle b/bukkit/build.gradle index d03eaeda..f60263cb 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -9,14 +9,10 @@ dependencies { compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' compileOnly 'org.jetbrains:annotations:24.0.0' compileOnly 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT' - compileOnly 'redis.clients:jedis:' + jedis_version - compileOnly 'commons-io:commons-io:2.11.0' - compileOnly 'com.google.guava:guava:31.1-jre' compileOnly 'net.william278:Annotaml:2.0.1' compileOnly 'net.william278:DesertWell:1.1.1' compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1' compileOnly 'com.github.Emibergo02:RedisEconomy:9f4f9c86f4' - compileOnly 'us.dynmap:dynmap-api:3.1' testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2' testImplementation 'de.themoep:minedown-adventure:1.7.1-SNAPSHOT' diff --git a/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java b/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java index 1778fdaa..8b69020e 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java +++ b/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java @@ -68,7 +68,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask private RandomTeleportEngine randomTeleportEngine; private Spawn serverSpawn; private UnsafeBlocks unsafeBlocks; - private Set pluginHooks; + private Set hooks; private List commands; private Map> globalPlayerList; private Set currentlyOnWarmup; @@ -168,12 +168,12 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask } private void loadHooks() { - this.pluginHooks = new HashSet<>(); + this.hooks = new HashSet<>(); if (settings.doEconomy()) { if (Bukkit.getPluginManager().getPlugin("RedisEconomy") != null) { - pluginHooks.add(new RedisEconomyHook(this)); + hooks.add(new RedisEconomyHook(this)); } else if (Bukkit.getPluginManager().getPlugin("Vault") != null) { - pluginHooks.add(new VaultEconomyHook(this)); + hooks.add(new VaultEconomyHook(this)); } } if (settings.doMapHook()) { @@ -181,24 +181,24 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask case DYNMAP -> { final Plugin dynmapPlugin = Bukkit.getPluginManager().getPlugin("Dynmap"); if (dynmapPlugin != null) { - pluginHooks.add(new DynMapHook(this, dynmapPlugin)); + hooks.add(new DynmapHook(this)); } } case BLUEMAP -> { if (Bukkit.getPluginManager().getPlugin("BlueMap") != null) { - pluginHooks.add(new BlueMapHook(this)); + hooks.add(new BlueMapHook(this)); } } } } if (Bukkit.getPluginManager().getPlugin("Plan") != null) { - pluginHooks.add(new PlanHook(this)); + hooks.add(new PlanHook(this)); } - if (pluginHooks.size() > 0) { - pluginHooks.forEach(PluginHook::initialize); - log(Level.INFO, "Registered " + pluginHooks.size() + " plugin hooks: " + pluginHooks.stream() - .map(PluginHook::getHookName) + if (hooks.size() > 0) { + hooks.forEach(Hook::initialize); + log(Level.INFO, "Registered " + hooks.size() + " plugin hooks: " + hooks.stream() + .map(Hook::getName) .collect(Collectors.joining(", "))); } } @@ -314,8 +314,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask @Override @NotNull - public Set getPluginHooks() { - return pluginHooks; + public Set getPluginHooks() { + return hooks; } @Override @@ -441,7 +441,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask metrics.addCustomChart(new SimplePie("using_economy", () -> Boolean.toString(getSettings().doEconomy()))); metrics.addCustomChart(new SimplePie("using_map", () -> Boolean.toString(getSettings().doMapHook()))); if (getSettings().doMapHook()) { - metrics.addCustomChart(new SimplePie("map_type", () -> getSettings().getMappingPlugin().displayName)); + metrics.addCustomChart(new SimplePie("map_type", () -> getSettings().getMappingPlugin().getDisplayName())); } } catch (Exception e) { log(Level.WARNING, "Failed to register metrics", e); @@ -484,6 +484,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask } // Super constructor for unit testing + @SuppressWarnings("unused") protected BukkitHuskHomes(@NotNull JavaPluginLoader loader, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file) { super(loader, description, dataFolder, file); } diff --git a/bukkit/src/main/java/net/william278/huskhomes/hook/DynMapHook.java b/bukkit/src/main/java/net/william278/huskhomes/hook/DynMapHook.java deleted file mode 100644 index 7ec950ba..00000000 --- a/bukkit/src/main/java/net/william278/huskhomes/hook/DynMapHook.java +++ /dev/null @@ -1,212 +0,0 @@ -package net.william278.huskhomes.hook; - -import net.william278.huskhomes.BukkitHuskHomes; -import net.william278.huskhomes.HuskHomes; -import net.william278.huskhomes.command.BukkitCommand; -import net.william278.huskhomes.position.Home; -import net.william278.huskhomes.position.Warp; -import net.william278.huskhomes.user.User; -import org.apache.commons.lang.StringEscapeUtils; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; -import org.dynmap.DynmapAPI; -import org.dynmap.markers.Marker; -import org.dynmap.markers.MarkerAPI; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CompletableFuture; - -/** - * Hook to display warps and public homes on Dynmap - */ -public class DynMapHook extends MapHook { - - @NotNull - private final DynmapAPI dynmapAPI; - - public DynMapHook(@NotNull HuskHomes implementor, @NotNull Plugin dynmapPlugin) { - super(implementor, "Dynmap"); - this.dynmapAPI = (DynmapAPI) dynmapPlugin; - } - - @Override - protected CompletableFuture initializeMap() { - final CompletableFuture initializedFuture = new CompletableFuture<>(); - plugin.runAsync(() -> { - final MarkerAPI markerAPI = dynmapAPI.getMarkerAPI(); - if (plugin.getSettings().isPublicHomesOnMap()) { - markerAPI.getMarkerIcons().stream() - .filter(markerIcon -> markerIcon.getMarkerIconID().equals(PUBLIC_HOME_MARKER_IMAGE_NAME)) - .findFirst() - .ifPresent(markerIcon -> markerAPI.getMarkerIcons().remove(markerIcon)); - markerAPI.createMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME, "Public Home", - ((BukkitHuskHomes) plugin).getResource("markers/16x/" + PUBLIC_HOME_MARKER_IMAGE_NAME + ".png")); - markerAPI.createMarkerSet(PUBLIC_HOMES_MARKER_SET_ID, - "Public Homes", dynmapAPI.getMarkerAPI().getMarkerIcons(), false); - } - if (plugin.getSettings().isWarpsOnMap()) { - markerAPI.getMarkerIcons().stream() - .filter(markerIcon -> markerIcon.getMarkerIconID().equals(WARP_MARKER_IMAGE_NAME)) - .findFirst() - .ifPresent(markerIcon -> markerAPI.getMarkerIcons().remove(markerIcon)); - markerAPI.createMarkerIcon(WARP_MARKER_IMAGE_NAME, "Warp", - ((BukkitHuskHomes) plugin).getResource("markers/16x/" + WARP_MARKER_IMAGE_NAME + ".png")); - markerAPI.createMarkerSet(WARPS_MARKER_SET_ID, - "Warps", dynmapAPI.getMarkerAPI().getMarkerIcons(), false); - } - initializedFuture.complete(null); - }); - return initializedFuture; - } - - @Override - public CompletableFuture updateHome(@NotNull Home home) { - if (!isValidPosition(home)) return CompletableFuture.completedFuture(null); - - final CompletableFuture updatedFuture = new CompletableFuture<>(); - removeHome(home).thenRun(() -> Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> { - dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).createMarker( - home.getOwner().getUuid() + ":" + home.getUuid(), home.getMeta().getName(), home.getWorld().getName(), - home.getX(), home.getY(), home.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME), false) - .setDescription(MarkerInformationPopup.create(home.getMeta().getName()) - .setThumbnailMarker(PUBLIC_HOME_MARKER_IMAGE_NAME) - .addField("Owner", home.getOwner().getUsername()) - .addField("Description", plugin.getLocales().wrapText(home.getMeta().getDescription(), 60)) - .addField("Command", "/" + BukkitCommand.Type.PUBLIC_HOME_COMMAND.getCommand().getName() + " " + home.getMeta().getName()) - .toHtml()); - updatedFuture.complete(null); - })); - return updatedFuture; - } - - @Override - public CompletableFuture removeHome(@NotNull Home home) { - if (!isValidPosition(home)) return CompletableFuture.completedFuture(null); - - final CompletableFuture removedFuture = new CompletableFuture<>(); - Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> { - dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).getMarkers().stream() - .filter(marker -> marker.getMarkerID().equals(home.getOwner().getUuid() + ":" + home.getUuid())) - .findFirst() - .ifPresent(Marker::deleteMarker); - removedFuture.complete(null); - }); - return removedFuture; - } - - @Override - public void clearHomes(@NotNull User user) { - final CompletableFuture clearedFuture = new CompletableFuture<>(); - Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> { - dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).getMarkers().stream() - .filter(marker -> marker.getMarkerID().startsWith(user.getUuid().toString())) - .forEach(Marker::deleteMarker); - clearedFuture.complete(null); - }); - } - - @Override - public CompletableFuture updateWarp(@NotNull Warp warp) { - if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null); - - final CompletableFuture updatedFuture = new CompletableFuture<>(); - removeWarp(warp).thenRun(() -> Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> { - dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).createMarker( - warp.getUuid().toString(), warp.getMeta().getName(), warp.getWorld().getName(), - warp.getX(), warp.getY(), warp.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(WARP_MARKER_IMAGE_NAME), false) - .setDescription(MarkerInformationPopup.create(warp.getMeta().getName()) - .setThumbnailMarker(WARP_MARKER_IMAGE_NAME) - .addField("Description", plugin.getLocales().wrapText(warp.getMeta().getDescription(), 60)) - .addField("Command", "/" + BukkitCommand.Type.WARP_COMMAND.getCommand().getName() + " " + warp.getMeta().getName()) - .toHtml()); - updatedFuture.complete(null); - })); - return updatedFuture; - } - - @Override - public CompletableFuture removeWarp(@NotNull Warp warp) { - if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null); - - final CompletableFuture removedFuture = new CompletableFuture<>(); - CompletableFuture.runAsync(() -> Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> { - dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).getMarkers().stream() - .filter(marker -> marker.getMarkerID().equals(warp.getUuid().toString())) - .findFirst() - .ifPresent(Marker::deleteMarker); - removedFuture.complete(null); - })); - return removedFuture; - } - - @Override - public void clearWarps() { - final CompletableFuture clearedFuture = new CompletableFuture<>(); - Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> { - dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).getMarkers() - .forEach(Marker::deleteMarker); - clearedFuture.complete(null); - }); - } - - /** - * Creates an HTML Dynmap marker information popup widget - */ - private static class MarkerInformationPopup { - @NotNull - private final String title; - - @Nullable - private String thumbnailMarkerId; - - @NotNull - private final Map fields; - - private MarkerInformationPopup(@NotNull String title) { - this.title = title; - this.fields = new HashMap<>(); - } - - @NotNull - private static DynMapHook.MarkerInformationPopup create(@NotNull String title) { - return new MarkerInformationPopup(title); - } - - @NotNull - private DynMapHook.MarkerInformationPopup setThumbnailMarker(@NotNull String thumbnailMarkerId) { - this.thumbnailMarkerId = thumbnailMarkerId; - return this; - } - - @NotNull - private DynMapHook.MarkerInformationPopup addField(@NotNull String key, @NotNull String value) { - fields.put(key, value); - return this; - } - - @NotNull - private String toHtml() { - final StringBuilder html = new StringBuilder(); - html.append("
"); - if (thumbnailMarkerId != null) { - html.append("") - .append(" "); - } - html.append("") - .append(StringEscapeUtils.escapeHtml(title)) - .append("
"); - fields.forEach((key, value) -> html.append("") - .append(StringEscapeUtils.escapeHtml(key)) - .append(": ") - .append(StringEscapeUtils.escapeHtml(value)) - .append("
")); - return html.toString(); - } - } - -} diff --git a/bukkit/src/main/java/net/william278/huskhomes/hook/RedisEconomyHook.java b/bukkit/src/main/java/net/william278/huskhomes/hook/RedisEconomyHook.java index 9ab45ba3..6be1be58 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/hook/RedisEconomyHook.java +++ b/bukkit/src/main/java/net/william278/huskhomes/hook/RedisEconomyHook.java @@ -11,14 +11,14 @@ public class RedisEconomyHook extends VaultEconomyHook { } @Override - public boolean initialize() { + public void initialize() { RedisEconomyAPI api = RedisEconomyAPI.getAPI(); if (api != null) { economy = api.getCurrencyByName(plugin.getSettings().getRedisEconomyName()); if (economy != null) { - return true; + return; } } - return super.initialize(); + super.initialize(); } } diff --git a/bukkit/src/main/java/net/william278/huskhomes/hook/VaultEconomyHook.java b/bukkit/src/main/java/net/william278/huskhomes/hook/VaultEconomyHook.java index 7edd6e8b..b2e4db04 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/hook/VaultEconomyHook.java +++ b/bukkit/src/main/java/net/william278/huskhomes/hook/VaultEconomyHook.java @@ -21,14 +21,12 @@ public class VaultEconomyHook extends EconomyHook { } @Override - public boolean initialize() { + public void initialize() { final RegisteredServiceProvider economyProvider = ((BukkitHuskHomes) plugin).getServer() .getServicesManager().getRegistration(Economy.class); if (economyProvider != null) { economy = economyProvider.getProvider(); - return true; } - return false; } @Override diff --git a/common/build.gradle b/common/build.gradle index 3ffc39c8..60b7a1e7 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -17,8 +17,9 @@ dependencies { compileOnly 'redis.clients:jedis:' + jedis_version compileOnly 'org.xerial:sqlite-jdbc:' + sqlite_driver_version compileOnly 'com.mysql:mysql-connector-j:' + mysql_driver_version - compileOnly 'com.github.BlueMap-Minecraft:BlueMapAPI:v2.1.0' compileOnly 'com.github.plan-player-analytics:Plan:5.5.1923' + compileOnly 'com.github.BlueMap-Minecraft:BlueMapAPI:2.5.0' + compileOnly 'us.dynmap:DynmapCoreAPI:3.4' testImplementation 'com.github.plan-player-analytics:Plan:5.5.1833' testImplementation 'com.github.yuriy-g:simple-java-plot:5c502c2e98' diff --git a/common/src/main/java/net/william278/huskhomes/HuskHomes.java b/common/src/main/java/net/william278/huskhomes/HuskHomes.java index 568f9826..fe34452c 100644 --- a/common/src/main/java/net/william278/huskhomes/HuskHomes.java +++ b/common/src/main/java/net/william278/huskhomes/HuskHomes.java @@ -13,7 +13,7 @@ import net.william278.huskhomes.database.Database; import net.william278.huskhomes.event.EventDispatcher; import net.william278.huskhomes.hook.EconomyHook; import net.william278.huskhomes.hook.MapHook; -import net.william278.huskhomes.hook.PluginHook; +import net.william278.huskhomes.hook.Hook; import net.william278.huskhomes.manager.Manager; import net.william278.huskhomes.network.Broker; import net.william278.huskhomes.position.Location; @@ -161,21 +161,21 @@ public interface HuskHomes extends TaskRunner, EventDispatcher { void setServerSpawn(@NotNull Location location); /** - * Set of active {@link PluginHook}s running on the server + * Set of active {@link Hook}s running on the server * - * @return the {@link Set} of active {@link PluginHook}s + * @return the {@link Set} of active {@link Hook}s */ @NotNull - Set getPluginHooks(); + Set getPluginHooks(); /** - * Finds the {@link PluginHook} of the given class instance from the set of active {@link PluginHook}s + * Finds the {@link Hook} of the given class instance from the set of active {@link Hook}s * - * @param hookClass the class of the {@link PluginHook} to get - * @param the type of the {@link PluginHook} - * @return the {@link PluginHook} instance, or an empty {@link Optional} if not found + * @param hookClass the class of the {@link Hook} to get + * @param the type of the {@link Hook} + * @return the {@link Hook} instance, or an empty {@link Optional} if not found */ - default Optional getHook(@NotNull Class hookClass) { + default Optional getHook(@NotNull Class hookClass) { return getPluginHooks().stream() .filter(hook -> hook.getClass().isInstance(hookClass)) .findFirst() diff --git a/common/src/main/java/net/william278/huskhomes/config/Settings.java b/common/src/main/java/net/william278/huskhomes/config/Settings.java index d8aafda4..3ccbddf9 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Settings.java +++ b/common/src/main/java/net/william278/huskhomes/config/Settings.java @@ -249,7 +249,7 @@ public class Settings { private boolean doMapHook = false; @YamlKey("map_hook.map_plugin") - private MapHook.MappingPlugin mappingPlugin = MapHook.MappingPlugin.DYNMAP; + private MapHook.Plugin type = MapHook.Plugin.DYNMAP; @YamlKey("map_hook.show_public_homes") private boolean publicHomesOnMap = true; @@ -479,8 +479,8 @@ public class Settings { return doMapHook; } - public MapHook.MappingPlugin getMappingPlugin() { - return mappingPlugin; + public MapHook.Plugin getMappingPlugin() { + return type; } public boolean isPublicHomesOnMap() { diff --git a/common/src/main/java/net/william278/huskhomes/hook/BlueMapHook.java b/common/src/main/java/net/william278/huskhomes/hook/BlueMapHook.java index 6108fe44..f6e810f5 100644 --- a/common/src/main/java/net/william278/huskhomes/hook/BlueMapHook.java +++ b/common/src/main/java/net/william278/huskhomes/hook/BlueMapHook.java @@ -1,7 +1,7 @@ package net.william278.huskhomes.hook; -import com.flowpowered.math.vector.Vector2i; import de.bluecolored.bluemap.api.BlueMapAPI; +import de.bluecolored.bluemap.api.BlueMapMap; import de.bluecolored.bluemap.api.BlueMapWorld; import de.bluecolored.bluemap.api.markers.MarkerSet; import de.bluecolored.bluemap.api.markers.POIMarker; @@ -12,161 +12,131 @@ import net.william278.huskhomes.position.World; import net.william278.huskhomes.user.User; import org.jetbrains.annotations.NotNull; -import javax.imageio.ImageIO; -import java.io.IOException; -import java.util.Objects; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.logging.Level; /** * Hook to display warps and public homes on BlueMap maps */ public class BlueMapHook extends MapHook { - private String publicHomeMarkerIconPath; - private String warpMarkerIconPath; + private Map publicHomesMarkerSets; + private Map warpsMarkerSets; - public BlueMapHook(@NotNull HuskHomes implementor) { - super(implementor, "BlueMap"); + public BlueMapHook(@NotNull HuskHomes plugin) { + super(plugin, Plugin.BLUEMAP); } @Override - protected CompletableFuture initializeMap() { - final CompletableFuture initializedFuture = new CompletableFuture<>(); - plugin.runAsync(() -> BlueMapAPI.onEnable(blueMapAPI -> { - // Create marker sets - plugin.getWorlds().forEach(world -> blueMapAPI.getWorld(world.getUuid()) - .ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(map -> { - if (plugin.getSettings().isPublicHomesOnMap()) { - map.getMarkerSets().put(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, - MarkerSet.builder().label("Public Homes").build()); - } - if (plugin.getSettings().isWarpsOnMap()) { - map.getMarkerSets().put(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, - MarkerSet.builder().label("Warps").build()); - } - }))); + public void initialize() { + BlueMapAPI.onEnable(api -> { + this.publicHomesMarkerSets = new HashMap<>(); + this.warpsMarkerSets = new HashMap<>(); - // Create marker icons - try { - publicHomeMarkerIconPath = blueMapAPI.getWebApp().createImage( - ImageIO.read(Objects.requireNonNull(plugin.getResource("markers/50x/" + PUBLIC_HOME_MARKER_IMAGE_NAME + ".png"))), - "huskhomes/" + PUBLIC_HOMES_MARKER_SET_ID + ".png"); - warpMarkerIconPath = blueMapAPI.getWebApp().createImage( - ImageIO.read(Objects.requireNonNull(plugin.getResource("markers/50x/" + WARP_MARKER_IMAGE_NAME + ".png"))), - "huskhomes/" + WARP_MARKER_IMAGE_NAME + ".png"); - } catch (IOException e) { - plugin.log(Level.SEVERE, "Failed to create warp marker image", e); + for (World world : plugin.getWorlds()) { + getMapWorld(world).ifPresent(mapWorld -> { + final MarkerSet publicHomeMarkers = MarkerSet.builder().label("Public Homes").build(); + final MarkerSet warpsMarkers = MarkerSet.builder().label("Warps").build(); + + for (BlueMapMap map : mapWorld.getMaps()) { + map.getMarkerSets().put(plugin.getKey(map.getId()).toString(), publicHomeMarkers); + map.getMarkerSets().put(plugin.getKey(map.getId()).toString(), warpsMarkers); + } + + publicHomesMarkerSets.put(world.getName(), publicHomeMarkers); + warpsMarkerSets.put(world.getName(), warpsMarkers); + }); } - initializedFuture.complete(null); - })); - return initializedFuture; + this.populateMap(); + }); } @Override - public CompletableFuture updateHome(@NotNull Home home) { - if (!isValidPosition(home)) return CompletableFuture.completedFuture(null); + public void updateHome(@NotNull Home home) { + if (!isValidPosition(home)) { + return; + } - return removeHome(home).thenRun(() -> BlueMapAPI.getInstance().flatMap( - blueMapAPI -> getBlueMapWorld(blueMapAPI, home.getWorld())).ifPresent(blueMapWorld -> blueMapWorld.getMaps() - .forEach(blueMapMap -> blueMapMap.getMarkerSets() - .computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> { - markerSet.getMarkers().put(home.getOwner().getUuid() + ":" + home.getUuid(), - POIMarker.toBuilder() - .label("/phome" + home.getOwner().getUsername() + "." + home.getMeta().getName()) - .position((int) home.getX(), (int) home.getY(), (int) home.getZ()) - .icon(publicHomeMarkerIconPath, Vector2i.from(25, 25)) - .maxDistance(5000) - .build()); - return markerSet; - })))); + getPublicHomesMarkerSet(home.getWorld()) + .ifPresent(markerSet -> { + final String markerId = home.getOwner().getUuid() + ":" + home.getUuid(); + markerSet.remove(markerId); + markerSet.put(markerId, POIMarker.builder() + .label("/phome " + home.getOwner().getUsername() + "." + home.getName()) + .position(home.getX(), home.getY(), home.getZ()) + .maxDistance(5000) + .defaultIcon() // todo: custom icon + .build()); + }); } @Override - public CompletableFuture removeHome(@NotNull Home home) { - if (!isValidPosition(home)) return CompletableFuture.completedFuture(null); + public void removeHome(@NotNull Home home) { + getPublicHomesMarkerSet(home.getWorld()) + .ifPresent(markerSet -> markerSet.remove(home.getOwner().getUuid() + ":" + home.getUuid())); - BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, home.getWorld())) - .ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets() - .computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> { - markerSet.getMarkers().remove(home.getOwner().getUuid() + ":" + home.getUuid()); - return markerSet; - }))); - return CompletableFuture.completedFuture(null); } @Override public void clearHomes(@NotNull User user) { - BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds() - .forEach(blueMapWorld -> blueMapWorld.getMaps() - .forEach(blueMapMap -> blueMapMap.getMarkerSets() - .computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> { - markerSet.getMarkers().keySet().removeIf(key -> key.startsWith(user.getUuid().toString())); - return markerSet; - })))); - - CompletableFuture.completedFuture(null); + if (publicHomesMarkerSets != null) { + for (MarkerSet markerSet : publicHomesMarkerSets.values()) { + markerSet.getMarkers().keySet() + .removeIf(markerId -> markerId.startsWith(user.getUuid().toString())); + } + } } @Override - public CompletableFuture updateWarp(@NotNull Warp warp) { - if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null); + public void updateWarp(@NotNull Warp warp) { + if (!isValidPosition(warp)) { + return; + } - return removeWarp(warp).thenRun(() -> BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.getWorld())) - .ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets() - .computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> { - markerSet.getMarkers().put(warp.getUuid().toString(), - POIMarker.toBuilder() - .label("/warp " + warp.getMeta().getName()) - .position((int) warp.getX(), (int) warp.getY(), (int) warp.getZ()) - .icon(warpMarkerIconPath, Vector2i.from(25, 25)) - .maxDistance(10000) - .build()); - return markerSet; - })))); + getPublicHomesMarkerSet(warp.getWorld()) + .ifPresent(markerSet -> { + final String markerId = warp.getUuid().toString(); + markerSet.remove(markerId); + markerSet.put(markerId, POIMarker.builder() + .label("/warp " + warp.getName()) + .position(warp.getX(), warp.getY(), warp.getZ()) + .maxDistance(5000) + .defaultIcon() // todo: custom icon + .build()); + }); } @Override - public CompletableFuture removeWarp(@NotNull Warp warp) { - if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null); - - BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.getWorld())) - .ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets() - .computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> { - markerSet.getMarkers().remove(warp.getUuid().toString()); - return markerSet; - }))); - return CompletableFuture.completedFuture(null); + public void removeWarp(@NotNull Warp warp) { + getWarpsMarkerSet(warp.getWorld()) + .ifPresent(markerSet -> markerSet.remove(warp.getUuid().toString())); } @Override public void clearWarps() { - BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds() - .forEach(blueMapWorld -> blueMapWorld.getMaps() - .forEach(blueMapMap -> blueMapMap.getMarkerSets() - .computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> { - markerSet.getMarkers().clear(); - return markerSet; - })))); - - CompletableFuture.completedFuture(null); - } - - /** - * Get the {@link BlueMapWorld} for a world - * - * @param world The {@link World} to get the {@link BlueMapWorld} for - * @return The {@link BlueMapWorld} of the world - */ - @NotNull - private Optional getBlueMapWorld(@NotNull BlueMapAPI blueMapAPI, @NotNull World world) { - if (world.getUuid().equals(new UUID(0, 0))) { - return blueMapAPI.getWorld(world.getName()); - } else { - return blueMapAPI.getWorld(world.getUuid()); + if (warpsMarkerSets != null) { + for (MarkerSet markerSet : warpsMarkerSets.values()) { + markerSet.getMarkers().keySet() + .forEach(markerSet::remove); + } } } + + @NotNull + private Optional getPublicHomesMarkerSet(@NotNull World world) { + return publicHomesMarkerSets == null ? Optional.empty() : Optional.ofNullable(publicHomesMarkerSets.get(world.getName())); + } + + @NotNull + private Optional getWarpsMarkerSet(@NotNull World world) { + return warpsMarkerSets == null ? Optional.empty() : Optional.ofNullable(warpsMarkerSets.get(world.getName())); + } + + @NotNull + private Optional getMapWorld(@NotNull World world) { + return BlueMapAPI.getInstance().flatMap(api -> api.getWorld(world.getName())); + } + } diff --git a/common/src/main/java/net/william278/huskhomes/hook/DynmapHook.java b/common/src/main/java/net/william278/huskhomes/hook/DynmapHook.java new file mode 100644 index 00000000..0b7b26c9 --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/hook/DynmapHook.java @@ -0,0 +1,243 @@ +package net.william278.huskhomes.hook; + +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.position.Home; +import net.william278.huskhomes.position.Warp; +import net.william278.huskhomes.user.User; +import org.apache.commons.text.StringEscapeUtils; +import org.dynmap.DynmapCommonAPI; +import org.dynmap.DynmapCommonAPIListener; +import org.dynmap.markers.Marker; +import org.dynmap.markers.MarkerIcon; +import org.dynmap.markers.MarkerSet; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +/** + * Hook to display warps and public homes on Dynmap + */ +public class DynmapHook extends MapHook { + + @Nullable + private DynmapCommonAPI dynmapApi; + @Nullable + private MarkerSet publicHomesMarkers; + @Nullable + private MarkerSet warpsMarkers; + + public DynmapHook(@NotNull HuskHomes plugin) { + super(plugin, Plugin.DYNMAP); + } + + @Override + public void initialize() { + DynmapCommonAPIListener.register(new DynmapCommonAPIListener() { + @Override + public void apiEnabled(@NotNull DynmapCommonAPI dynmapCommonAPI) { + dynmapApi = dynmapCommonAPI; + populateMap(); + } + }); + } + + @Override + protected void populateMap() { + getDynmap().ifPresent(api -> { + if (plugin.getSettings().isPublicHomesOnMap()) { + getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME).orElseThrow(); + api.getMarkerAPI().createMarkerSet(getPublicHomesKey(), + "Public Homes", api.getMarkerAPI().getMarkerIcons(), false); + } + if (plugin.getSettings().isWarpsOnMap()) { + getMarkerIcon(WARP_MARKER_IMAGE_NAME).orElseThrow(); + api.getMarkerAPI().createMarkerSet(getPublicHomesKey(), + "Public Homes", api.getMarkerAPI().getMarkerIcons(), false); + } + }); + } + + @Override + public void updateHome(@NotNull Home home) { + if (!isValidPosition(home)) { + return; + } + + plugin.runSync(() -> { + final String markerId = home.getOwner().getUuid() + ":" + home.getUuid(); + getPublicHomesMarkerSet().ifPresent(markerSet -> { + markerSet.getMarkers().stream() + .filter(marker -> marker.getMarkerID().equals(markerId)) + .forEach(Marker::deleteMarker); + markerSet.createMarker(markerId, home.getName(), home.getWorld().getName(), + home.getX(), home.getY(), home.getZ(), + getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME).orElseThrow(), false) + .setDescription(MarkerInformationPopup.create(home.getName()) + .thumbnail(PUBLIC_HOME_MARKER_IMAGE_NAME) + .field("Owner", home.getOwner().getUsername()) + .field("Description", plugin.getLocales().wrapText(home.getMeta().getDescription(), 60)) + .field("Command", "/phome " + home.getName()) + .toHtml()); + }); + }); + } + + @Override + public void removeHome(@NotNull Home home) { + plugin.runSync(() -> { + final String markerId = home.getOwner().getUuid() + ":" + home.getUuid(); + getPublicHomesMarkerSet().ifPresent(markerSet -> markerSet.getMarkers().stream() + .filter(marker -> marker.getMarkerID().equals(markerId)) + .forEach(Marker::deleteMarker)); + }); + } + + @Override + public void clearHomes(@NotNull User user) { + plugin.runSync(() -> getPublicHomesMarkerSet().ifPresent(markerSet -> markerSet.getMarkers().stream() + .filter(marker -> marker.getMarkerID().startsWith(user.getUuid().toString())) + .forEach(Marker::deleteMarker))); + } + + @Override + public void updateWarp(@NotNull Warp warp) { + if (!isValidPosition(warp)) { + return; + } + + plugin.runSync(() -> { + final String markerId = warp.getUuid().toString(); + getWarpsMarkerSet().ifPresent(markerSet -> { + markerSet.getMarkers().stream() + .filter(marker -> marker.getMarkerID().equals(markerId)) + .forEach(Marker::deleteMarker); + markerSet.createMarker(markerId, warp.getName(), warp.getWorld().getName(), + warp.getX(), warp.getY(), warp.getZ(), + getMarkerIcon(WARP_MARKER_IMAGE_NAME).orElseThrow(), false) + .setDescription(MarkerInformationPopup.create(warp.getName()) + .thumbnail(WARP_MARKER_IMAGE_NAME) + .field("Description", plugin.getLocales().wrapText(warp.getMeta().getDescription(), 60)) + .field("Command", "/phome " + warp.getName()) + .toHtml()); + }); + }); + } + + @Override + public void removeWarp(@NotNull Warp warp) { + plugin.runSync(() -> { + final String markerId = warp.getUuid().toString(); + getWarpsMarkerSet().ifPresent(markerSet -> markerSet.getMarkers().stream() + .filter(marker -> marker.getMarkerID().equals(markerId)) + .forEach(Marker::deleteMarker)); + }); + } + + @Override + public void clearWarps() { + plugin.runSync(() -> getWarpsMarkerSet().ifPresent(markerSet -> markerSet.getMarkers() + .forEach(Marker::deleteMarker))); + } + + private Optional getDynmap() { + return Optional.ofNullable(dynmapApi); + } + + private Optional getWarpsMarkerSet() { + return getDynmap().map(api -> { + warpsMarkers = api.getMarkerAPI().getMarkerSet(getWarpsKey()); + if (warpsMarkers == null) { + warpsMarkers = api.getMarkerAPI().createMarkerSet(getWarpsKey(), "Warps", + api.getMarkerAPI().getMarkerIcons(), false); + } else { + warpsMarkers.setMarkerSetLabel("Warps"); + } + return warpsMarkers; + }); + } + + private Optional getPublicHomesMarkerSet() { + return getDynmap().map(api -> { + publicHomesMarkers = api.getMarkerAPI().getMarkerSet(getPublicHomesKey()); + if (publicHomesMarkers == null) { + publicHomesMarkers = api.getMarkerAPI().createMarkerSet(getPublicHomesKey(), "Public Homes", + api.getMarkerAPI().getMarkerIcons(), false); + } else { + publicHomesMarkers.setMarkerSetLabel("Public Homes"); + } + return publicHomesMarkers; + }); + } + + private Optional getMarkerIcon(@NotNull String imageName) { + return getDynmap().map(api -> { + MarkerIcon icon = api.getMarkerAPI().getMarkerIcon(imageName); + if (icon == null) { + icon = api.getMarkerAPI().createMarkerIcon(imageName, imageName, + plugin.getResource("markers/16x/" + imageName + ".png")); + } + return icon; + }); + } + + /** + * Creates an HTML Dynmap marker information popup widget + */ + private static class MarkerInformationPopup { + @NotNull + private final String title; + + @Nullable + private String thumbnailMarkerId; + + @NotNull + private final Map fields; + + private MarkerInformationPopup(@NotNull String title) { + this.title = title; + this.fields = new HashMap<>(); + } + + @NotNull + private static DynmapHook.MarkerInformationPopup create(@NotNull String title) { + return new MarkerInformationPopup(title); + } + + @NotNull + private DynmapHook.MarkerInformationPopup thumbnail(@NotNull String thumbnailMarkerId) { + this.thumbnailMarkerId = thumbnailMarkerId; + return this; + } + + @NotNull + private DynmapHook.MarkerInformationPopup field(@NotNull String key, @NotNull String value) { + fields.put(key, value); + return this; + } + + @NotNull + private String toHtml() { + final StringBuilder html = new StringBuilder(); + html.append("
"); + if (thumbnailMarkerId != null) { + html.append("") + .append(" "); + } + html.append("") + .append(StringEscapeUtils.escapeHtml4(title)) + .append("
"); + fields.forEach((key, value) -> html.append("") + .append(StringEscapeUtils.escapeHtml4(key)) + .append(": ") + .append(StringEscapeUtils.escapeHtml4(value)) + .append("
")); + return html.toString(); + } + } + +} diff --git a/common/src/main/java/net/william278/huskhomes/hook/EconomyHook.java b/common/src/main/java/net/william278/huskhomes/hook/EconomyHook.java index 6f674ac8..8617f9a4 100644 --- a/common/src/main/java/net/william278/huskhomes/hook/EconomyHook.java +++ b/common/src/main/java/net/william278/huskhomes/hook/EconomyHook.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull; /** * A hook that provides economy features */ -public abstract class EconomyHook extends PluginHook { +public abstract class EconomyHook extends Hook { protected EconomyHook(@NotNull HuskHomes implementor, @NotNull String hookName) { super(implementor, hookName); diff --git a/common/src/main/java/net/william278/huskhomes/hook/Hook.java b/common/src/main/java/net/william278/huskhomes/hook/Hook.java new file mode 100644 index 00000000..58a2520f --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/hook/Hook.java @@ -0,0 +1,42 @@ +package net.william278.huskhomes.hook; + +import net.william278.huskhomes.HuskHomes; +import org.jetbrains.annotations.NotNull; + +/** + * A plugin hook, where HuskHomes hooks into another plugin + */ +public abstract class Hook { + + /** + * The plugin that this hook is for + */ + protected final HuskHomes plugin; + + /** + * The name of the hook + */ + protected final String name; + + /** + * Construct a new {@link Hook} + * + * @param plugin the {@link HuskHomes} instance + */ + protected Hook(@NotNull HuskHomes plugin, @NotNull String name) { + this.plugin = plugin; + this.name = name; + } + + /** + * Initialize the hook and return {@code true} if it could be enabled + */ + public abstract void initialize() ; + + @NotNull + public String getName() { + return name; + } + + +} diff --git a/common/src/main/java/net/william278/huskhomes/hook/MapHook.java b/common/src/main/java/net/william278/huskhomes/hook/MapHook.java index e0427d63..67ec641c 100644 --- a/common/src/main/java/net/william278/huskhomes/hook/MapHook.java +++ b/common/src/main/java/net/william278/huskhomes/hook/MapHook.java @@ -4,7 +4,6 @@ import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.position.Home; import net.william278.huskhomes.position.SavedPosition; import net.william278.huskhomes.position.Warp; -import net.william278.huskhomes.position.World; import net.william278.huskhomes.user.User; import org.jetbrains.annotations.NotNull; @@ -13,55 +12,44 @@ import java.util.concurrent.CompletableFuture; /** * A hook for a mapping plugin, such as Dynmap */ -public abstract class MapHook extends PluginHook { +public abstract class MapHook extends Hook { - protected static final String PUBLIC_HOMES_MARKER_SET_ID = "huskhomes-public-homes"; - protected static final String WARPS_MARKER_SET_ID = "huskhomes-warps"; protected static final String WARP_MARKER_IMAGE_NAME = "warp"; protected static final String PUBLIC_HOME_MARKER_IMAGE_NAME = "public-home"; - protected MapHook(@NotNull HuskHomes implementor, @NotNull String hookName) { - super(implementor, hookName); - } - - @Override - public final boolean initialize() { - initializeMap().thenRun(() -> { - if (plugin.getSettings().isPublicHomesOnMap()) { - plugin.getDatabase() - .getLocalPublicHomes(plugin) - .forEach(this::updateHome); - } - if (plugin.getSettings().isWarpsOnMap()) { - plugin.getDatabase() - .getLocalWarps(plugin) - .forEach(this::updateWarp); - } - }); - return true; + protected MapHook(@NotNull HuskHomes plugin, @NotNull MapHook.Plugin type) { + super(plugin, type.getDisplayName()); } /** - * Prepare the map plugin for adding homes to - * - * @return a {@link CompletableFuture} that completes when the map plugin is ready + * Populate the map with public homes and warps */ - protected abstract CompletableFuture initializeMap(); + protected void populateMap() { + if (plugin.getSettings().isPublicHomesOnMap()) { + plugin.getDatabase() + .getLocalPublicHomes(plugin) + .forEach(this::updateHome); + } + if (plugin.getSettings().isWarpsOnMap()) { + plugin.getDatabase() + .getLocalWarps(plugin) + .forEach(this::updateWarp); + } + } /** * Update a home, adding it to the map if it exists, or updating it on the map if it doesn't * * @param home the home to update */ - @SuppressWarnings("UnusedReturnValue") - public abstract CompletableFuture updateHome(@NotNull Home home); + public abstract void updateHome(@NotNull Home home); /** * Removes a home from the map * * @param home the home to remove */ - public abstract CompletableFuture removeHome(@NotNull Home home); + public abstract void removeHome(@NotNull Home home); /** * Clears homes owned by a player from the map @@ -75,15 +63,14 @@ public abstract class MapHook extends PluginHook { * * @param warp the warp to update */ - @SuppressWarnings("UnusedReturnValue") - public abstract CompletableFuture updateWarp(@NotNull Warp warp); + public abstract void updateWarp(@NotNull Warp warp); /** * Removes a warp from the map * * @param warp the warp to remove */ - public abstract CompletableFuture removeWarp(@NotNull Warp warp); + public abstract void removeWarp(@NotNull Warp warp); /** * Clears all warps from the map @@ -98,30 +85,43 @@ public abstract class MapHook extends PluginHook { */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") protected final boolean isValidPosition(@NotNull SavedPosition position) { - if (position instanceof Warp && !plugin.getSettings().isWarpsOnMap()) return false; - if (position instanceof Home && !plugin.getSettings().isPublicHomesOnMap()) return false; - - try { - return position.getServer().equals(plugin.getServerName()); - } catch (IllegalStateException e) { - return plugin.getWorlds().stream() - .map(World::getUuid) - .anyMatch(uuid -> uuid.equals(position.getWorld().getUuid())); + if (position instanceof Warp && !plugin.getSettings().isWarpsOnMap()) { + return false; } + if (position instanceof Home && !plugin.getSettings().isPublicHomesOnMap()) { + return false; + } + + return position.getServer().equals(plugin.getServerName()); + } + + @NotNull + protected final String getPublicHomesKey() { + return plugin.getKey(getName().toLowerCase(), "public_homes", "markers").toString(); + } + + @NotNull + protected final String getWarpsKey() { + return plugin.getKey(getName().toLowerCase(), "warps", "markers").toString(); } /** * Identifies types of supported Map plugins */ - public enum MappingPlugin { + public enum Plugin { DYNMAP("Dynmap"), BLUEMAP("BlueMap"); - @NotNull - public final String displayName; + private final String displayName; - MappingPlugin(@NotNull String displayName) { + Plugin(@NotNull String displayName) { this.displayName = displayName; } + + @NotNull + public String getDisplayName() { + return displayName; + } } + } diff --git a/common/src/main/java/net/william278/huskhomes/hook/PlanHook.java b/common/src/main/java/net/william278/huskhomes/hook/PlanHook.java index 61ef9174..764f671c 100644 --- a/common/src/main/java/net/william278/huskhomes/hook/PlanHook.java +++ b/common/src/main/java/net/william278/huskhomes/hook/PlanHook.java @@ -20,7 +20,7 @@ import java.util.logging.Level; /** * Hooks into Plan to provide the {@link PlanDataExtension} with stats on the web panel */ -public class PlanHook extends PluginHook { +public class PlanHook extends Hook { private final HuskHomes plugin; @@ -30,13 +30,12 @@ public class PlanHook extends PluginHook { } @Override - public boolean initialize() { + public void initialize() { if (!areAllCapabilitiesAvailable()) { - return false; + return; } registerDataExtension(); handlePlanReload(); - return true; } diff --git a/common/src/main/java/net/william278/huskhomes/hook/PluginHook.java b/common/src/main/java/net/william278/huskhomes/hook/PluginHook.java deleted file mode 100644 index ddd1451c..00000000 --- a/common/src/main/java/net/william278/huskhomes/hook/PluginHook.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.william278.huskhomes.hook; - -import net.william278.huskhomes.HuskHomes; -import org.jetbrains.annotations.NotNull; - -/** - * A plugin hook, where HuskHomes hooks into another plugin - */ -public abstract class PluginHook { - - /** - * The plugin that this hook is for - */ - protected final HuskHomes plugin; - - /** - * The name of the hook - */ - protected final String hookName; - - /** - * Construct a new {@link PluginHook} - * - * @param implementor the {@link HuskHomes} instance - */ - protected PluginHook(@NotNull HuskHomes implementor, @NotNull String hookName) { - this.plugin = implementor; - this.hookName = hookName; - } - - /** - * Initialize the hook and return {@code true} if it could be enabled - * - * @return {@code true} if the hook could be enabled - */ - public abstract boolean initialize() ; - - @NotNull - public String getHookName() { - return hookName; - } - - -}