mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Rewrite map hooks, use more modern APIs
This commit is contained in:
1 parent
167d5d6c7a
commit
98fa779046
15 files changed
+457
-463
No files matched your search
@@ -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'
|
||||
|
||||
@@ -68,7 +68,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
private RandomTeleportEngine randomTeleportEngine;
|
||||
private Spawn serverSpawn;
|
||||
private UnsafeBlocks unsafeBlocks;
|
||||
private Set<PluginHook> pluginHooks;
|
||||
private Set<Hook> hooks;
|
||||
private List<Command> commands;
|
||||
private Map<String, List<String>> globalPlayerList;
|
||||
private Set<UUID> 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<PluginHook> getPluginHooks() {
|
||||
return pluginHooks;
|
||||
public Set<Hook> 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);
|
||||
}
|
||||
|
||||
@@ -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<Void> initializeMap() {
|
||||
final CompletableFuture<Void> 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<Void> updateHome(@NotNull Home home) {
|
||||
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
|
||||
|
||||
final CompletableFuture<Void> 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<Void> removeHome(@NotNull Home home) {
|
||||
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
|
||||
|
||||
final CompletableFuture<Void> 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<Void> 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<Void> updateWarp(@NotNull Warp warp) {
|
||||
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
|
||||
|
||||
final CompletableFuture<Void> 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<Void> removeWarp(@NotNull Warp warp) {
|
||||
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
|
||||
|
||||
final CompletableFuture<Void> 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<Void> 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<String, String> 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("<div class=\"infowindow\">");
|
||||
if (thumbnailMarkerId != null) {
|
||||
html.append("<img src=\"/tiles/_markers_/")
|
||||
.append(thumbnailMarkerId)
|
||||
.append(".png\" class=\"thumbnail\"/>")
|
||||
.append(" ");
|
||||
}
|
||||
html.append("<span style=\"font-weight: bold;\">")
|
||||
.append(StringEscapeUtils.escapeHtml(title))
|
||||
.append("</span><br/>");
|
||||
fields.forEach((key, value) -> html.append("<span style=\"font-weight: bold;\">")
|
||||
.append(StringEscapeUtils.escapeHtml(key))
|
||||
.append(": </span><span>")
|
||||
.append(StringEscapeUtils.escapeHtml(value))
|
||||
.append("</span><br/>"));
|
||||
return html.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -21,14 +21,12 @@ public class VaultEconomyHook extends EconomyHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
public void initialize() {
|
||||
final RegisteredServiceProvider<Economy> economyProvider = ((BukkitHuskHomes) plugin).getServer()
|
||||
.getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -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'
|
||||
|
||||
@@ -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<PluginHook> getPluginHooks();
|
||||
Set<Hook> 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 <H> 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 <H> the type of the {@link Hook}
|
||||
* @return the {@link Hook} instance, or an empty {@link Optional} if not found
|
||||
*/
|
||||
default <H extends PluginHook> Optional<H> getHook(@NotNull Class<H> hookClass) {
|
||||
default <H extends Hook> Optional<H> getHook(@NotNull Class<H> hookClass) {
|
||||
return getPluginHooks().stream()
|
||||
.filter(hook -> hook.getClass().isInstance(hookClass))
|
||||
.findFirst()
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 <a href="https://github.com/BlueMap-Minecraft/BlueMap">BlueMap</a> maps
|
||||
*/
|
||||
public class BlueMapHook extends MapHook {
|
||||
|
||||
private String publicHomeMarkerIconPath;
|
||||
private String warpMarkerIconPath;
|
||||
private Map<String, MarkerSet> publicHomesMarkerSets;
|
||||
private Map<String, MarkerSet> warpsMarkerSets;
|
||||
|
||||
public BlueMapHook(@NotNull HuskHomes implementor) {
|
||||
super(implementor, "BlueMap");
|
||||
public BlueMapHook(@NotNull HuskHomes plugin) {
|
||||
super(plugin, Plugin.BLUEMAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompletableFuture<Void> initializeMap() {
|
||||
final CompletableFuture<Void> 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<Void> 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<Void> 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<Void> 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<Void> 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<BlueMapWorld> 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<MarkerSet> getPublicHomesMarkerSet(@NotNull World world) {
|
||||
return publicHomesMarkerSets == null ? Optional.empty() : Optional.ofNullable(publicHomesMarkerSets.get(world.getName()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Optional<MarkerSet> getWarpsMarkerSet(@NotNull World world) {
|
||||
return warpsMarkerSets == null ? Optional.empty() : Optional.ofNullable(warpsMarkerSets.get(world.getName()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Optional<BlueMapWorld> getMapWorld(@NotNull World world) {
|
||||
return BlueMapAPI.getInstance().flatMap(api -> api.getWorld(world.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<DynmapCommonAPI> getDynmap() {
|
||||
return Optional.ofNullable(dynmapApi);
|
||||
}
|
||||
|
||||
private Optional<MarkerSet> 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<MarkerSet> 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<MarkerIcon> 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<String, String> 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("<div class=\"infowindow\">");
|
||||
if (thumbnailMarkerId != null) {
|
||||
html.append("<img src=\"/tiles/_markers_/")
|
||||
.append(thumbnailMarkerId)
|
||||
.append(".png\" class=\"thumbnail\"/>")
|
||||
.append(" ");
|
||||
}
|
||||
html.append("<span style=\"font-weight: bold;\">")
|
||||
.append(StringEscapeUtils.escapeHtml4(title))
|
||||
.append("</span><br/>");
|
||||
fields.forEach((key, value) -> html.append("<span style=\"font-weight: bold;\">")
|
||||
.append(StringEscapeUtils.escapeHtml4(key))
|
||||
.append(": </span><span>")
|
||||
.append(StringEscapeUtils.escapeHtml4(value))
|
||||
.append("</span><br/>"));
|
||||
return html.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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<Void> 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<Void> 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<Void> 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<Void> 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<Void> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user