mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Add BlueMap integration, close #39
This commit is contained in:
1 parent
9737f6ba79
commit
50e0d60859
3 files changed
+128
-29
No files matched your search
@@ -199,6 +199,7 @@ public final class HuskHomes extends JavaPlugin {
|
||||
} else if (mapPlugin.equalsIgnoreCase("bluemap")) {
|
||||
map = new BlueMap();
|
||||
}
|
||||
map.initialize();
|
||||
}
|
||||
|
||||
// Setup economy if it is enabled
|
||||
|
||||
@@ -2,25 +2,57 @@ package me.william278.huskhomes2.integrations.Map;
|
||||
|
||||
import de.bluecolored.bluemap.api.BlueMapAPI;
|
||||
import de.bluecolored.bluemap.api.BlueMapMap;
|
||||
import de.bluecolored.bluemap.api.marker.MarkerAPI;
|
||||
import de.bluecolored.bluemap.api.marker.MarkerSet;
|
||||
import de.bluecolored.bluemap.api.marker.POIMarker;
|
||||
import de.bluecolored.bluemap.api.marker.*;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class BlueMap extends Map {
|
||||
|
||||
//todo finish
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
private static final HashMap<Warp,Boolean> queuedWarps = new HashMap<>();
|
||||
private static final HashMap<Warp,Boolean> queuedPublicHomes = new HashMap<>();
|
||||
private static final HashMap<String,Boolean> queuedWarps = new HashMap<>();
|
||||
private static final HashMap<String,Boolean> queuedPublicHomes = new HashMap<>();
|
||||
|
||||
private void executeQueuedOperations() {
|
||||
try {
|
||||
for (String warpName : queuedWarps.keySet()) {
|
||||
boolean add = queuedWarps.get(warpName);
|
||||
if (add) {
|
||||
Warp warpToAdd = DataManager.getWarp(warpName, HuskHomes.getConnection());
|
||||
if (warpToAdd != null) {
|
||||
addWarpMarker(warpToAdd);
|
||||
}
|
||||
} else {
|
||||
removeWarpMarker(warpName);
|
||||
}
|
||||
}
|
||||
for (String fullHomeName : queuedPublicHomes.keySet()) {
|
||||
boolean add = queuedPublicHomes.get(fullHomeName);
|
||||
String ownerName = fullHomeName.split("\\.")[0];
|
||||
String homeName = fullHomeName.split("\\.")[1];
|
||||
if (add) {
|
||||
Home homeToAdd = DataManager.getHome(ownerName, homeName, HuskHomes.getConnection());
|
||||
if (homeToAdd != null) {
|
||||
addPublicHomeMarker(homeToAdd);
|
||||
}
|
||||
} else {
|
||||
removePublicHomeMarker(homeName, ownerName);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.WARNING,
|
||||
"An SQL exception occurred retrieving warp and home data when updating the BlueMap.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWarpMarker(Warp warp) {
|
||||
@@ -28,43 +60,109 @@ public class BlueMap extends Map {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
BlueMapAPI.getInstance().ifPresentOrElse(api -> {
|
||||
try {
|
||||
MarkerAPI markerAPI = api.getMarkerAPI();
|
||||
markerAPI.getMarkerSet(WARPS_MARKER_SET_ID).ifPresent(markerSet -> {
|
||||
api.getWorld(world.getUID()).ifPresent(blueMapWorld -> {
|
||||
String markerId = WARPS_MARKER_SET_ID + "." + warp.getName();
|
||||
for (BlueMapMap map : blueMapWorld.getMaps()) {
|
||||
POIMarker marker = markerSet.createPOIMarker(markerId, map, warp.getX(), warp.getY(), warp.getZ());
|
||||
marker.setLabel(warp.getName());
|
||||
//marker.setIcon();
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (IOException ignored) { }
|
||||
}, () -> queuedWarps.put(warp,true));
|
||||
});
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> BlueMapAPI.getInstance().ifPresentOrElse(api -> {
|
||||
try {
|
||||
MarkerAPI markerAPI = api.getMarkerAPI();
|
||||
markerAPI.getMarkerSet(WARPS_MARKER_SET_ID).ifPresent(markerSet -> api.getWorld(world.getUID()).ifPresent(blueMapWorld -> {
|
||||
String markerId = WARPS_MARKER_SET_ID + "." + warp.getName();
|
||||
for (BlueMapMap map : blueMapWorld.getMaps()) {
|
||||
POIMarker marker = markerSet.createPOIMarker(markerId, map, warp.getX(), warp.getY(), warp.getZ());
|
||||
marker.setLabel(getWarpInfoMenu(warp));
|
||||
}
|
||||
try {
|
||||
markerAPI.save();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}));
|
||||
} catch (IOException ignored) { }
|
||||
}, () -> queuedWarps.put(warp.getName(), true)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeWarpMarker(String warpName) {
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
// Remove the marker
|
||||
BlueMapAPI.getInstance().ifPresentOrElse(api -> {
|
||||
try {
|
||||
MarkerAPI markerAPI = api.getMarkerAPI();
|
||||
markerAPI.getMarkerSet(WARPS_MARKER_SET_ID).ifPresent(markerSet -> {
|
||||
String markerId = WARPS_MARKER_SET_ID + "." + warpName;
|
||||
markerSet.removeMarker(markerId);
|
||||
try {
|
||||
markerAPI.save();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
});
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}, () -> queuedWarps.put(warpName, false));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPublicHomeMarker(Home home) {
|
||||
|
||||
World world = home.getLocation().getWorld();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> BlueMapAPI.getInstance().ifPresentOrElse(api -> {
|
||||
try {
|
||||
MarkerAPI markerAPI = api.getMarkerAPI();
|
||||
markerAPI.getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).ifPresent(markerSet -> api.getWorld(world.getUID()).ifPresent(blueMapWorld -> {
|
||||
String markerId = PUBLIC_HOMES_MARKER_SET_ID + "." + home.getName();
|
||||
for (BlueMapMap map : blueMapWorld.getMaps()) {
|
||||
POIMarker marker = markerSet.createPOIMarker(markerId, map, home.getX(), home.getY(), home.getZ());
|
||||
marker.setLabel(getPublicHomeInfoMenu(home));
|
||||
}
|
||||
try {
|
||||
markerAPI.save();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}));
|
||||
} catch (IOException ignored) { }
|
||||
}, () -> queuedPublicHomes.put(home.getOwnerUsername() + "." + home.getName(), true)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePublicHomeMarker(String homeName, String ownerName) {
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
// Remove the marker
|
||||
BlueMapAPI.getInstance().ifPresentOrElse(api -> {
|
||||
try {
|
||||
MarkerAPI markerAPI = api.getMarkerAPI();
|
||||
markerAPI.getMarkerSet(WARPS_MARKER_SET_ID).ifPresent(markerSet -> {
|
||||
String markerId = WARPS_MARKER_SET_ID + "." + homeName;
|
||||
markerSet.removeMarker(markerId);
|
||||
try {
|
||||
markerAPI.save();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
});
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}, () -> queuedPublicHomes.put(ownerName + "." + homeName, false));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
try {
|
||||
for (Home home : DataManager.getPublicHomes(connection)) {
|
||||
if (!HuskHomes.getSettings().doBungee() || home.getServer().equals(HuskHomes.getSettings().getServerID())) {
|
||||
addPublicHomeMarker(home);
|
||||
}
|
||||
}
|
||||
for (Warp warp : DataManager.getWarps(connection)) {
|
||||
if (!HuskHomes.getSettings().doBungee() || warp.getServer().equals(HuskHomes.getSettings().getServerID())) {
|
||||
addWarpMarker(warp);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred initialising homes and warps onto the BlueMap");
|
||||
}
|
||||
|
||||
// Create Marker Set
|
||||
BlueMapAPI.onEnable(api -> {
|
||||
try {
|
||||
@@ -79,7 +177,7 @@ public class BlueMap extends Map {
|
||||
markerAPI.save();
|
||||
plugin.getLogger().info("Enabled BlueMap integration!");
|
||||
|
||||
//executeQueuedOperations();
|
||||
executeQueuedOperations();
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("An exception occurred initialising BlueMap.");
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ version: ${project.version}
|
||||
main: me.william278.huskhomes2.HuskHomes
|
||||
api-version: 1.16
|
||||
authors: [William278]
|
||||
softdepend: [dynmap, Vault]
|
||||
softdepend: [dynmap, Vault, BlueMap]
|
||||
description: A powerful, intuitive and flexible teleportation suite
|
||||
libraries:
|
||||
- mysql:mysql-connector-java:8.0.25
|
||||
|
||||
Reference in new issue
Block a user