mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 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.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||||
compileOnly 'org.jetbrains:annotations:24.0.0'
|
compileOnly 'org.jetbrains:annotations:24.0.0'
|
||||||
compileOnly 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT'
|
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:Annotaml:2.0.1'
|
||||||
compileOnly 'net.william278:DesertWell:1.1.1'
|
compileOnly 'net.william278:DesertWell:1.1.1'
|
||||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
|
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
|
||||||
compileOnly 'com.github.Emibergo02:RedisEconomy:9f4f9c86f4'
|
compileOnly 'com.github.Emibergo02:RedisEconomy:9f4f9c86f4'
|
||||||
compileOnly 'us.dynmap:dynmap-api:3.1'
|
|
||||||
|
|
||||||
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2'
|
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2'
|
||||||
testImplementation 'de.themoep:minedown-adventure:1.7.1-SNAPSHOT'
|
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 RandomTeleportEngine randomTeleportEngine;
|
||||||
private Spawn serverSpawn;
|
private Spawn serverSpawn;
|
||||||
private UnsafeBlocks unsafeBlocks;
|
private UnsafeBlocks unsafeBlocks;
|
||||||
private Set<PluginHook> pluginHooks;
|
private Set<Hook> hooks;
|
||||||
private List<Command> commands;
|
private List<Command> commands;
|
||||||
private Map<String, List<String>> globalPlayerList;
|
private Map<String, List<String>> globalPlayerList;
|
||||||
private Set<UUID> currentlyOnWarmup;
|
private Set<UUID> currentlyOnWarmup;
|
||||||
@@ -168,12 +168,12 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadHooks() {
|
private void loadHooks() {
|
||||||
this.pluginHooks = new HashSet<>();
|
this.hooks = new HashSet<>();
|
||||||
if (settings.doEconomy()) {
|
if (settings.doEconomy()) {
|
||||||
if (Bukkit.getPluginManager().getPlugin("RedisEconomy") != null) {
|
if (Bukkit.getPluginManager().getPlugin("RedisEconomy") != null) {
|
||||||
pluginHooks.add(new RedisEconomyHook(this));
|
hooks.add(new RedisEconomyHook(this));
|
||||||
} else if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
} else if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||||
pluginHooks.add(new VaultEconomyHook(this));
|
hooks.add(new VaultEconomyHook(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (settings.doMapHook()) {
|
if (settings.doMapHook()) {
|
||||||
@@ -181,24 +181,24 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
case DYNMAP -> {
|
case DYNMAP -> {
|
||||||
final Plugin dynmapPlugin = Bukkit.getPluginManager().getPlugin("Dynmap");
|
final Plugin dynmapPlugin = Bukkit.getPluginManager().getPlugin("Dynmap");
|
||||||
if (dynmapPlugin != null) {
|
if (dynmapPlugin != null) {
|
||||||
pluginHooks.add(new DynMapHook(this, dynmapPlugin));
|
hooks.add(new DynmapHook(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case BLUEMAP -> {
|
case BLUEMAP -> {
|
||||||
if (Bukkit.getPluginManager().getPlugin("BlueMap") != null) {
|
if (Bukkit.getPluginManager().getPlugin("BlueMap") != null) {
|
||||||
pluginHooks.add(new BlueMapHook(this));
|
hooks.add(new BlueMapHook(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Bukkit.getPluginManager().getPlugin("Plan") != null) {
|
if (Bukkit.getPluginManager().getPlugin("Plan") != null) {
|
||||||
pluginHooks.add(new PlanHook(this));
|
hooks.add(new PlanHook(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginHooks.size() > 0) {
|
if (hooks.size() > 0) {
|
||||||
pluginHooks.forEach(PluginHook::initialize);
|
hooks.forEach(Hook::initialize);
|
||||||
log(Level.INFO, "Registered " + pluginHooks.size() + " plugin hooks: " + pluginHooks.stream()
|
log(Level.INFO, "Registered " + hooks.size() + " plugin hooks: " + hooks.stream()
|
||||||
.map(PluginHook::getHookName)
|
.map(Hook::getName)
|
||||||
.collect(Collectors.joining(", ")));
|
.collect(Collectors.joining(", ")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,8 +314,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<PluginHook> getPluginHooks() {
|
public Set<Hook> getPluginHooks() {
|
||||||
return pluginHooks;
|
return hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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_economy", () -> Boolean.toString(getSettings().doEconomy())));
|
||||||
metrics.addCustomChart(new SimplePie("using_map", () -> Boolean.toString(getSettings().doMapHook())));
|
metrics.addCustomChart(new SimplePie("using_map", () -> Boolean.toString(getSettings().doMapHook())));
|
||||||
if (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) {
|
} catch (Exception e) {
|
||||||
log(Level.WARNING, "Failed to register metrics", 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
|
// Super constructor for unit testing
|
||||||
|
@SuppressWarnings("unused")
|
||||||
protected BukkitHuskHomes(@NotNull JavaPluginLoader loader, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file) {
|
protected BukkitHuskHomes(@NotNull JavaPluginLoader loader, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file) {
|
||||||
super(loader, description, dataFolder, 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
|
@Override
|
||||||
public boolean initialize() {
|
public void initialize() {
|
||||||
RedisEconomyAPI api = RedisEconomyAPI.getAPI();
|
RedisEconomyAPI api = RedisEconomyAPI.getAPI();
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
economy = api.getCurrencyByName(plugin.getSettings().getRedisEconomyName());
|
economy = api.getCurrencyByName(plugin.getSettings().getRedisEconomyName());
|
||||||
if (economy != null) {
|
if (economy != null) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.initialize();
|
super.initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,14 +21,12 @@ public class VaultEconomyHook extends EconomyHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initialize() {
|
public void initialize() {
|
||||||
final RegisteredServiceProvider<Economy> economyProvider = ((BukkitHuskHomes) plugin).getServer()
|
final RegisteredServiceProvider<Economy> economyProvider = ((BukkitHuskHomes) plugin).getServer()
|
||||||
.getServicesManager().getRegistration(Economy.class);
|
.getServicesManager().getRegistration(Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
economy = economyProvider.getProvider();
|
economy = economyProvider.getProvider();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-1
@@ -17,8 +17,9 @@ dependencies {
|
|||||||
compileOnly 'redis.clients:jedis:' + jedis_version
|
compileOnly 'redis.clients:jedis:' + jedis_version
|
||||||
compileOnly 'org.xerial:sqlite-jdbc:' + sqlite_driver_version
|
compileOnly 'org.xerial:sqlite-jdbc:' + sqlite_driver_version
|
||||||
compileOnly 'com.mysql:mysql-connector-j:' + mysql_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.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.plan-player-analytics:Plan:5.5.1833'
|
||||||
testImplementation 'com.github.yuriy-g:simple-java-plot:5c502c2e98'
|
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.event.EventDispatcher;
|
||||||
import net.william278.huskhomes.hook.EconomyHook;
|
import net.william278.huskhomes.hook.EconomyHook;
|
||||||
import net.william278.huskhomes.hook.MapHook;
|
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.manager.Manager;
|
||||||
import net.william278.huskhomes.network.Broker;
|
import net.william278.huskhomes.network.Broker;
|
||||||
import net.william278.huskhomes.position.Location;
|
import net.william278.huskhomes.position.Location;
|
||||||
@@ -161,21 +161,21 @@ public interface HuskHomes extends TaskRunner, EventDispatcher {
|
|||||||
void setServerSpawn(@NotNull Location location);
|
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
|
@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 hookClass the class of the {@link Hook} to get
|
||||||
* @param <H> the type of the {@link PluginHook}
|
* @param <H> the type of the {@link Hook}
|
||||||
* @return the {@link PluginHook} instance, or an empty {@link Optional} if not found
|
* @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()
|
return getPluginHooks().stream()
|
||||||
.filter(hook -> hook.getClass().isInstance(hookClass))
|
.filter(hook -> hook.getClass().isInstance(hookClass))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ public class Settings {
|
|||||||
private boolean doMapHook = false;
|
private boolean doMapHook = false;
|
||||||
|
|
||||||
@YamlKey("map_hook.map_plugin")
|
@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")
|
@YamlKey("map_hook.show_public_homes")
|
||||||
private boolean publicHomesOnMap = true;
|
private boolean publicHomesOnMap = true;
|
||||||
@@ -479,8 +479,8 @@ public class Settings {
|
|||||||
return doMapHook;
|
return doMapHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapHook.MappingPlugin getMappingPlugin() {
|
public MapHook.Plugin getMappingPlugin() {
|
||||||
return mappingPlugin;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPublicHomesOnMap() {
|
public boolean isPublicHomesOnMap() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.william278.huskhomes.hook;
|
package net.william278.huskhomes.hook;
|
||||||
|
|
||||||
import com.flowpowered.math.vector.Vector2i;
|
|
||||||
import de.bluecolored.bluemap.api.BlueMapAPI;
|
import de.bluecolored.bluemap.api.BlueMapAPI;
|
||||||
|
import de.bluecolored.bluemap.api.BlueMapMap;
|
||||||
import de.bluecolored.bluemap.api.BlueMapWorld;
|
import de.bluecolored.bluemap.api.BlueMapWorld;
|
||||||
import de.bluecolored.bluemap.api.markers.MarkerSet;
|
import de.bluecolored.bluemap.api.markers.MarkerSet;
|
||||||
import de.bluecolored.bluemap.api.markers.POIMarker;
|
import de.bluecolored.bluemap.api.markers.POIMarker;
|
||||||
@@ -12,161 +12,131 @@ import net.william278.huskhomes.position.World;
|
|||||||
import net.william278.huskhomes.user.User;
|
import net.william278.huskhomes.user.User;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import java.util.HashMap;
|
||||||
import java.io.IOException;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
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
|
* Hook to display warps and public homes on <a href="https://github.com/BlueMap-Minecraft/BlueMap">BlueMap</a> maps
|
||||||
*/
|
*/
|
||||||
public class BlueMapHook extends MapHook {
|
public class BlueMapHook extends MapHook {
|
||||||
|
|
||||||
private String publicHomeMarkerIconPath;
|
private Map<String, MarkerSet> publicHomesMarkerSets;
|
||||||
private String warpMarkerIconPath;
|
private Map<String, MarkerSet> warpsMarkerSets;
|
||||||
|
|
||||||
public BlueMapHook(@NotNull HuskHomes implementor) {
|
public BlueMapHook(@NotNull HuskHomes plugin) {
|
||||||
super(implementor, "BlueMap");
|
super(plugin, Plugin.BLUEMAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CompletableFuture<Void> initializeMap() {
|
public void initialize() {
|
||||||
final CompletableFuture<Void> initializedFuture = new CompletableFuture<>();
|
BlueMapAPI.onEnable(api -> {
|
||||||
plugin.runAsync(() -> BlueMapAPI.onEnable(blueMapAPI -> {
|
this.publicHomesMarkerSets = new HashMap<>();
|
||||||
// Create marker sets
|
this.warpsMarkerSets = new HashMap<>();
|
||||||
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());
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Create marker icons
|
for (World world : plugin.getWorlds()) {
|
||||||
try {
|
getMapWorld(world).ifPresent(mapWorld -> {
|
||||||
publicHomeMarkerIconPath = blueMapAPI.getWebApp().createImage(
|
final MarkerSet publicHomeMarkers = MarkerSet.builder().label("Public Homes").build();
|
||||||
ImageIO.read(Objects.requireNonNull(plugin.getResource("markers/50x/" + PUBLIC_HOME_MARKER_IMAGE_NAME + ".png"))),
|
final MarkerSet warpsMarkers = MarkerSet.builder().label("Warps").build();
|
||||||
"huskhomes/" + PUBLIC_HOMES_MARKER_SET_ID + ".png");
|
|
||||||
warpMarkerIconPath = blueMapAPI.getWebApp().createImage(
|
for (BlueMapMap map : mapWorld.getMaps()) {
|
||||||
ImageIO.read(Objects.requireNonNull(plugin.getResource("markers/50x/" + WARP_MARKER_IMAGE_NAME + ".png"))),
|
map.getMarkerSets().put(plugin.getKey(map.getId()).toString(), publicHomeMarkers);
|
||||||
"huskhomes/" + WARP_MARKER_IMAGE_NAME + ".png");
|
map.getMarkerSets().put(plugin.getKey(map.getId()).toString(), warpsMarkers);
|
||||||
} catch (IOException e) {
|
}
|
||||||
plugin.log(Level.SEVERE, "Failed to create warp marker image", e);
|
|
||||||
|
publicHomesMarkerSets.put(world.getName(), publicHomeMarkers);
|
||||||
|
warpsMarkerSets.put(world.getName(), warpsMarkers);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
initializedFuture.complete(null);
|
this.populateMap();
|
||||||
}));
|
});
|
||||||
return initializedFuture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> updateHome(@NotNull Home home) {
|
public void updateHome(@NotNull Home home) {
|
||||||
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
|
if (!isValidPosition(home)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return removeHome(home).thenRun(() -> BlueMapAPI.getInstance().flatMap(
|
getPublicHomesMarkerSet(home.getWorld())
|
||||||
blueMapAPI -> getBlueMapWorld(blueMapAPI, home.getWorld())).ifPresent(blueMapWorld -> blueMapWorld.getMaps()
|
.ifPresent(markerSet -> {
|
||||||
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
final String markerId = home.getOwner().getUuid() + ":" + home.getUuid();
|
||||||
.computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
|
markerSet.remove(markerId);
|
||||||
markerSet.getMarkers().put(home.getOwner().getUuid() + ":" + home.getUuid(),
|
markerSet.put(markerId, POIMarker.builder()
|
||||||
POIMarker.toBuilder()
|
.label("/phome " + home.getOwner().getUsername() + "." + home.getName())
|
||||||
.label("/phome" + home.getOwner().getUsername() + "." + home.getMeta().getName())
|
.position(home.getX(), home.getY(), home.getZ())
|
||||||
.position((int) home.getX(), (int) home.getY(), (int) home.getZ())
|
.maxDistance(5000)
|
||||||
.icon(publicHomeMarkerIconPath, Vector2i.from(25, 25))
|
.defaultIcon() // todo: custom icon
|
||||||
.maxDistance(5000)
|
.build());
|
||||||
.build());
|
});
|
||||||
return markerSet;
|
|
||||||
}))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> removeHome(@NotNull Home home) {
|
public void removeHome(@NotNull Home home) {
|
||||||
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
|
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
|
@Override
|
||||||
public void clearHomes(@NotNull User user) {
|
public void clearHomes(@NotNull User user) {
|
||||||
BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds()
|
if (publicHomesMarkerSets != null) {
|
||||||
.forEach(blueMapWorld -> blueMapWorld.getMaps()
|
for (MarkerSet markerSet : publicHomesMarkerSets.values()) {
|
||||||
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
markerSet.getMarkers().keySet()
|
||||||
.computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
|
.removeIf(markerId -> markerId.startsWith(user.getUuid().toString()));
|
||||||
markerSet.getMarkers().keySet().removeIf(key -> key.startsWith(user.getUuid().toString()));
|
}
|
||||||
return markerSet;
|
}
|
||||||
}))));
|
|
||||||
|
|
||||||
CompletableFuture.completedFuture(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> updateWarp(@NotNull Warp warp) {
|
public void updateWarp(@NotNull Warp warp) {
|
||||||
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
|
if (!isValidPosition(warp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return removeWarp(warp).thenRun(() -> BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.getWorld()))
|
getPublicHomesMarkerSet(warp.getWorld())
|
||||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
.ifPresent(markerSet -> {
|
||||||
.computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
|
final String markerId = warp.getUuid().toString();
|
||||||
markerSet.getMarkers().put(warp.getUuid().toString(),
|
markerSet.remove(markerId);
|
||||||
POIMarker.toBuilder()
|
markerSet.put(markerId, POIMarker.builder()
|
||||||
.label("/warp " + warp.getMeta().getName())
|
.label("/warp " + warp.getName())
|
||||||
.position((int) warp.getX(), (int) warp.getY(), (int) warp.getZ())
|
.position(warp.getX(), warp.getY(), warp.getZ())
|
||||||
.icon(warpMarkerIconPath, Vector2i.from(25, 25))
|
.maxDistance(5000)
|
||||||
.maxDistance(10000)
|
.defaultIcon() // todo: custom icon
|
||||||
.build());
|
.build());
|
||||||
return markerSet;
|
});
|
||||||
}))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> removeWarp(@NotNull Warp warp) {
|
public void removeWarp(@NotNull Warp warp) {
|
||||||
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
|
getWarpsMarkerSet(warp.getWorld())
|
||||||
|
.ifPresent(markerSet -> markerSet.remove(warp.getUuid().toString()));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearWarps() {
|
public void clearWarps() {
|
||||||
BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds()
|
if (warpsMarkerSets != null) {
|
||||||
.forEach(blueMapWorld -> blueMapWorld.getMaps()
|
for (MarkerSet markerSet : warpsMarkerSets.values()) {
|
||||||
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
markerSet.getMarkers().keySet()
|
||||||
.computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
|
.forEach(markerSet::remove);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
* 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) {
|
protected EconomyHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
|
||||||
super(implementor, 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.Home;
|
||||||
import net.william278.huskhomes.position.SavedPosition;
|
import net.william278.huskhomes.position.SavedPosition;
|
||||||
import net.william278.huskhomes.position.Warp;
|
import net.william278.huskhomes.position.Warp;
|
||||||
import net.william278.huskhomes.position.World;
|
|
||||||
import net.william278.huskhomes.user.User;
|
import net.william278.huskhomes.user.User;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -13,55 +12,44 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
/**
|
/**
|
||||||
* A hook for a mapping plugin, such as Dynmap
|
* 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 WARP_MARKER_IMAGE_NAME = "warp";
|
||||||
protected static final String PUBLIC_HOME_MARKER_IMAGE_NAME = "public-home";
|
protected static final String PUBLIC_HOME_MARKER_IMAGE_NAME = "public-home";
|
||||||
|
|
||||||
protected MapHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
|
protected MapHook(@NotNull HuskHomes plugin, @NotNull MapHook.Plugin type) {
|
||||||
super(implementor, hookName);
|
super(plugin, type.getDisplayName());
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the map plugin for adding homes to
|
* Populate the map with public homes and warps
|
||||||
*
|
|
||||||
* @return a {@link CompletableFuture} that completes when the map plugin is ready
|
|
||||||
*/
|
*/
|
||||||
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
|
* 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
|
* @param home the home to update
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnusedReturnValue")
|
public abstract void updateHome(@NotNull Home home);
|
||||||
public abstract CompletableFuture<Void> updateHome(@NotNull Home home);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a home from the map
|
* Removes a home from the map
|
||||||
*
|
*
|
||||||
* @param home the home to remove
|
* @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
|
* 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
|
* @param warp the warp to update
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnusedReturnValue")
|
public abstract void updateWarp(@NotNull Warp warp);
|
||||||
public abstract CompletableFuture<Void> updateWarp(@NotNull Warp warp);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a warp from the map
|
* Removes a warp from the map
|
||||||
*
|
*
|
||||||
* @param warp the warp to remove
|
* @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
|
* Clears all warps from the map
|
||||||
@@ -98,30 +85,43 @@ public abstract class MapHook extends PluginHook {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
protected final boolean isValidPosition(@NotNull SavedPosition position) {
|
protected final boolean isValidPosition(@NotNull SavedPosition position) {
|
||||||
if (position instanceof Warp && !plugin.getSettings().isWarpsOnMap()) return false;
|
if (position instanceof Warp && !plugin.getSettings().isWarpsOnMap()) {
|
||||||
if (position instanceof Home && !plugin.getSettings().isPublicHomesOnMap()) return false;
|
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 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
|
* Identifies types of supported Map plugins
|
||||||
*/
|
*/
|
||||||
public enum MappingPlugin {
|
public enum Plugin {
|
||||||
DYNMAP("Dynmap"),
|
DYNMAP("Dynmap"),
|
||||||
BLUEMAP("BlueMap");
|
BLUEMAP("BlueMap");
|
||||||
|
|
||||||
@NotNull
|
private final String displayName;
|
||||||
public final String displayName;
|
|
||||||
|
|
||||||
MappingPlugin(@NotNull String displayName) {
|
Plugin(@NotNull String displayName) {
|
||||||
this.displayName = 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
|
* 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;
|
private final HuskHomes plugin;
|
||||||
|
|
||||||
@@ -30,13 +30,12 @@ public class PlanHook extends PluginHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initialize() {
|
public void initialize() {
|
||||||
if (!areAllCapabilitiesAvailable()) {
|
if (!areAllCapabilitiesAvailable()) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
registerDataExtension();
|
registerDataExtension();
|
||||||
handlePlanReload();
|
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