Add Pl3xMap support, Close #58

This commit is contained in:
William committed 2021-08-26 12:16:59 +01:00
1 parent e28ceb20ff
commit c89d263505
10 files changed
+237 -76

No files matched your search

@@ -10,6 +10,7 @@ import me.william278.huskhomes2.integrations.map.BlueMap;
import me.william278.huskhomes2.integrations.map.DynMap;
import me.william278.huskhomes2.integrations.map.Map;
import me.william278.huskhomes2.integrations.VaultIntegration;
import me.william278.huskhomes2.integrations.map.Pl3xMap;
import me.william278.huskhomes2.listeners.PlayerListener;
import me.william278.huskhomes2.listeners.PluginMessageListener;
import me.william278.huskhomes2.migrators.UpgradeDatabase;
@@ -191,16 +192,19 @@ public final class HuskHomes extends JavaPlugin {
// Initialize the database
initializeDatabase();
// Upgrade Database if needed
UpgradeDatabase.upgradeDatabase();
// Fetch spawn location if set
SettingHandler.fetchSpawnLocation();
// Setup the map integration with the correct plugin
if (HuskHomes.getSettings().doMapIntegration()) {
String mapPlugin = HuskHomes.getSettings().getMapPlugin();
if (mapPlugin.equalsIgnoreCase("dynmap")) {
map = new DynMap();
} else if (mapPlugin.equalsIgnoreCase("bluemap")) {
map = new BlueMap();
switch (mapPlugin) {
case "dynmap" -> map = new DynMap();
case "bluemap" -> map = new BlueMap();
case "pl3xmap" -> map = new Pl3xMap();
}
map.initialize();
}
@@ -221,9 +225,6 @@ public final class HuskHomes extends JavaPlugin {
// Register events
registerEvents(this);
// Upgrade Database if needed
UpgradeDatabase.upgradeDatabase();
// bStats initialisation
try {
Metrics metrics = new Metrics(this, METRICS_PLUGIN_ID);
@@ -28,7 +28,8 @@ public class TpCommand extends CommandBase {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
switch (args.length) {
default: case 0:
default:
case 0:
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
return;
case 1:
@@ -78,6 +79,38 @@ public class TpCommand extends CommandBase {
} else {
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
}
return;
case 6:
try {
double x = Double.parseDouble(args[0]);
double y = Double.parseDouble(args[1]);
double z = Double.parseDouble(args[2]);
String worldName = args[3];
float yaw = Float.parseFloat(args[4]);
float pitch = Float.parseFloat(args[5]);
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, yaw, pitch, HuskHomes.getSettings().getServerID());
TeleportManager.teleportPlayer(p, teleportationPoint, connection);
} catch (NumberFormatException e) {
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <yaw> <pitch>");
}
case 7:
if (HuskHomes.getSettings().doBungee()) {
try {
double x = Double.parseDouble(args[0]);
double y = Double.parseDouble(args[1]);
double z = Double.parseDouble(args[2]);
String worldName = args[3];
String serverName = args[4];
float yaw = Float.parseFloat(args[5]);
float pitch = Float.parseFloat(args[6]);
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, yaw, pitch, serverName);
TeleportManager.teleportPlayer(p, teleportationPoint, connection);
} catch (NumberFormatException e) {
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <server> <yaw> <pitch>");
}
} else {
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
}
}
} catch (SQLException e) {
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred while using /tp", e);
@@ -149,22 +149,12 @@ public class Settings {
if (this.doMapIntegration) {
PluginManager pluginManager = HuskHomes.getInstance().getServer().getPluginManager();
switch (mapPlugin.toLowerCase(Locale.ROOT)) {
case "dynmap" -> {
Plugin dynMap = pluginManager.getPlugin("dynmap");
if (dynMap == null) {
Bukkit.getLogger().warning("Dynmap integration was enabled in config, but the Dynmap plugin could not be found!");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure BlueMap is installed and restart the server.");
this.doMapIntegration = false;
plugin.getConfig().set("map_integration.enabled", false);
plugin.saveConfig();
}
}
case "bluemap" -> {
Plugin blueMap = pluginManager.getPlugin("BlueMap");
if (blueMap == null) {
Bukkit.getLogger().warning("BlueMap integration was enabled in config, but the BlueMap plugin could not be found!");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure BlueMap is installed and restart the server.");
switch (mapPlugin.toLowerCase()) {
case "dynmap", "bluemap", "pl3xmap" -> {
Plugin mapSpigotPlugin = pluginManager.getPlugin(mapPlugin.toLowerCase());
if (mapSpigotPlugin == null) {
Bukkit.getLogger().warning(mapPlugin + " integration was enabled in config, but the " + mapPlugin + " plugin could not be found!");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure " + mapPlugin + " is installed and restart the server.");
this.doMapIntegration = false;
plugin.getConfig().set("map_integration.enabled", false);
plugin.saveConfig();
@@ -178,7 +168,6 @@ public class Settings {
plugin.saveConfig();
}
}
}
this.mapPublicHomes = config.getBoolean("map_integration.markers.public_homes.show", true);
@@ -305,7 +294,9 @@ public class Settings {
return server;
}
public int getClusterID() { return clusterID; }
public int getClusterID() {
return clusterID;
}
public boolean doBungee() {
return doBungee;
@@ -383,7 +374,9 @@ public class Settings {
return crossServerSpawnWarpName;
}
public boolean doForceSpawnOnLogin() { return forceSpawnOnLogin; }
public boolean doForceSpawnOnLogin() {
return forceSpawnOnLogin;
}
public boolean doEconomy() {
return doEconomy;
@@ -777,7 +777,7 @@ public class DataManager {
statement.setInt(1, addTeleportationPoint(warp, connection));
statement.setString(2, warp.getName());
statement.setString(3, warp.getDescription());
statement.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
statement.setTimestamp(4, new Timestamp(warp.getCreationTime()));
statement.executeUpdate();
}
}
@@ -792,7 +792,7 @@ public class DataManager {
statement.setString(3, home.getName());
statement.setString(4, home.getDescription());
statement.setBoolean(5, home.isPublic());
statement.setTimestamp(6, new Timestamp(System.currentTimeMillis()));
statement.setTimestamp(6, new Timestamp(home.getCreationTime()));
statement.executeUpdate();
}
}
@@ -109,7 +109,7 @@ public class BlueMap extends Map {
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();
String markerId = PUBLIC_HOMES_MARKER_SET_ID + "." + home.getOwnerUsername() + "." + home.getName();
for (BlueMapMap map : blueMapWorld.getMaps()) {
POIMarker marker = markerSet.createPOIMarker(markerId, map, home.getX(), home.getY(), home.getZ());
marker.setLabel(getPublicHomeInfoMenu(home));
@@ -130,8 +130,8 @@ public class BlueMap extends Map {
BlueMapAPI.getInstance().ifPresentOrElse(api -> {
try {
MarkerAPI markerAPI = api.getMarkerAPI();
markerAPI.getMarkerSet(WARPS_MARKER_SET_ID).ifPresent(markerSet -> {
String markerId = WARPS_MARKER_SET_ID + "." + homeName;
markerAPI.getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).ifPresent(markerSet -> {
String markerId = PUBLIC_HOMES_MARKER_SET_ID + "." + ownerName + "." + homeName;
markerSet.removeMarker(markerId);
try {
markerAPI.save();
@@ -0,0 +1,120 @@
package me.william278.huskhomes2.integrations.map;
import me.william278.huskhomes2.HuskHomes;
import me.william278.huskhomes2.teleport.points.Home;
import me.william278.huskhomes2.teleport.points.Warp;
import net.pl3x.map.api.Key;
import net.pl3x.map.api.Pl3xMapProvider;
import net.pl3x.map.api.Point;
import net.pl3x.map.api.SimpleLayerProvider;
import net.pl3x.map.api.marker.Icon;
import net.pl3x.map.api.marker.Marker;
import net.pl3x.map.api.marker.MarkerOptions;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.HashMap;
public class Pl3xMap extends Map {
private final HashMap<String,SimpleLayerProvider> publicHomeProviders = new HashMap<>();
private final HashMap<String,SimpleLayerProvider> warpProviders = new HashMap<>();
@Override
public void addWarpMarker(Warp warp) {
World world = Bukkit.getWorld(warp.getWorldName());
if (world != null) {
if (warpProviders.containsKey(world.getName())) {
Icon marker = Marker.icon(
Point.of(warp.getX(), warp.getZ()),
Key.of(HuskHomes.getSettings().getMapWarpMarkerIconID()),
10);
marker.markerOptions(MarkerOptions.builder()
.hoverTooltip(warp.getName())
.clickTooltip(getWarpInfoMenu(warp))
.build());
warpProviders.get(world.getName()).addMarker(Key.of(WARPS_MARKER_SET_ID + "." + warp.getName()), marker);
}
}
}
@Override
public void removeWarpMarker(String warpName) {
String warpMarkerWorld = null;
final Key warpMarkerKey = Key.of(WARPS_MARKER_SET_ID + "." + warpName);
for (String worldName : warpProviders.keySet()) {
SimpleLayerProvider warpProvider = warpProviders.get(worldName);
if (warpProvider.hasMarker(warpMarkerKey)) {
warpMarkerWorld = worldName;
break;
}
}
if (warpMarkerWorld != null) {
warpProviders.get(warpMarkerWorld).removeMarker(warpMarkerKey);
}
}
@Override
public void addPublicHomeMarker(Home home) {
World world = Bukkit.getWorld(home.getWorldName());
if (world != null) {
if (publicHomeProviders.containsKey(world.getName())) {
Icon marker = Marker.icon(
Point.of(home.getX(), home.getZ()),
Key.of(HuskHomes.getSettings().getMapPublicHomeMarkerIconID()),
10);
marker.markerOptions(MarkerOptions.builder()
.hoverTooltip(home.getName())
.clickTooltip(getPublicHomeInfoMenu(home))
.build());
publicHomeProviders.get(world.getName()).addMarker(
Key.of(PUBLIC_HOMES_MARKER_SET_ID + "." + home.getOwnerUsername() + "." + home.getName()), marker);
}
}
}
@Override
public void removePublicHomeMarker(String homeName, String ownerName) {
String publicHomeMarkerWorld = null;
final Key publicHomeMarkerKey = Key.of(PUBLIC_HOMES_MARKER_SET_ID + "." + ownerName + "." + homeName);
for (String worldName : publicHomeProviders.keySet()) {
SimpleLayerProvider warpProvider = publicHomeProviders.get(worldName);
if (warpProvider.hasMarker(publicHomeMarkerKey)) {
publicHomeMarkerWorld = worldName;
break;
}
}
if (publicHomeMarkerWorld != null) {
publicHomeProviders.get(publicHomeMarkerWorld).removeMarker(publicHomeMarkerKey);
}
}
@Override
public void initialize() {
net.pl3x.map.api.Pl3xMap mapAPI = Pl3xMapProvider.get();
for (net.pl3x.map.api.MapWorld world : mapAPI.mapWorlds()) {
// Register public home map layer
SimpleLayerProvider publicHomeProvider =
SimpleLayerProvider.builder(HuskHomes.getSettings().getMapPublicHomeMarkerSet())
.showControls(true)
.defaultHidden(false)
.layerPriority(6)
.zIndex(250)
.build();
world.layerRegistry().register(Key.of(PUBLIC_HOMES_MARKER_SET_ID), publicHomeProvider);
publicHomeProviders.put(world.name(), publicHomeProvider);
// Register warps map layer
SimpleLayerProvider warpProvider =
SimpleLayerProvider.builder(HuskHomes.getSettings().getMapPublicHomeMarkerSet())
.showControls(true)
.defaultHidden(false)
.layerPriority(7)
.zIndex(250)
.build();
world.layerRegistry().register(Key.of(WARPS_MARKER_SET_ID), warpProvider);
warpProviders.put(world.name(), warpProvider);
}
}
}
@@ -12,59 +12,63 @@ public class UpgradeDatabase {
private static final HuskHomes plugin = HuskHomes.getInstance();
//todo this stuff doesn't work. TEST BEFORE LAUNCH
// Upgrade the database system if the config file version is not high enough
public static void upgradeDatabase() {
plugin.reloadConfig();
if (plugin.getConfig().getInt("config_file_version", 1) <= 6) {
plugin.getLogger().info("Detected that the database might need updating. Running database upgrade...");
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
"ALTER TABLE " + HuskHomes.getSettings().getPlayerDataTable()
+ " ADD `is_ignoring_requests` boolean NOT NULL DEFAULT 0, "
+ "ADD `offline_location_id` integer NULL DEFAULT NULL, "
+ "ADD FOREIGN KEY (`offline_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION;")) {
tableUpdateStatement.executeUpdate();
plugin.getLogger().info("Database update complete!");
} catch (SQLException e) {
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
e.printStackTrace();
} finally {
// Update the config file version
plugin.getConfig().set("config_file_version", 7);
plugin.saveConfig();
}
}
if (plugin.getConfig().getInt("config_file_version", 1) <= 7) {
plugin.getLogger().info("Detected that the database might need updating. Running database upgrade...");
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
"ALTER TABLE " + HuskHomes.getSettings().getHomesDataTable()
+ " ADD `creation_time` timestamp NOT NULL DEFAULT 0;")) {
tableUpdateStatement.execute();
try (PreparedStatement timeSettingStatement = HuskHomes.getConnection().prepareStatement(
"UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `creation_time`=CURRENT_TIMESTAMP;")) {
timeSettingStatement.executeUpdate();
}
plugin.getLogger().info("Database update complete!");
} catch (SQLException e) {
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
e.printStackTrace();
} finally {
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
"ALTER TABLE " + HuskHomes.getSettings().getPlayerDataTable()
+ " ADD `is_ignoring_requests` boolean NOT NULL DEFAULT 0, "
+ "ADD `offline_location_id` integer NULL DEFAULT NULL, "
+ "ADD FOREIGN KEY (`offline_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION;")) {
tableUpdateStatement.executeUpdate();
"ALTER TABLE " + HuskHomes.getSettings().getWarpsDataTable()
+ " ADD `creation_time` timestamp NOT NULL DEFAULT 0;")) {
tableUpdateStatement.execute();
try (PreparedStatement timeSettingStatement = HuskHomes.getConnection().prepareStatement(
"UPDATE " + HuskHomes.getSettings().getWarpsDataTable() + " SET `creation_time`=CURRENT_TIMESTAMP;")) {
timeSettingStatement.executeUpdate();
}
plugin.getLogger().info("Database update complete!");
} catch (SQLException e) {
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
e.printStackTrace();
} finally {
// Update the config file version
Bukkit.getScheduler().runTask(plugin, () -> {
plugin.getConfig().set("config_file_version", 7);
plugin.saveConfig();
});
plugin.getConfig().set("config_file_version", 8);
plugin.saveConfig();
}
});
}
if (plugin.getConfig().getInt("config_file_version", 1) <= 6) {
plugin.getLogger().info("Detected that the database might need updating. Running database upgrade...");
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
"ALTER TABLE " + HuskHomes.getSettings().getHomesDataTable()
+ " ADD `creation_time` timestamp NOT NULL DEFAULT ?;")) {
tableUpdateStatement.setTimestamp(1, new Timestamp(Instant.now().getEpochSecond()));
tableUpdateStatement.executeUpdate();
plugin.getLogger().info("Database update complete!");
} catch (SQLException e) {
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
} finally {
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
"ALTER TABLE " + HuskHomes.getSettings().getWarpsDataTable()
+ " ADD `creation_time` timestamp NOT NULL DEFAULT ?;")) {
tableUpdateStatement.setTimestamp(1, new Timestamp(Instant.now().getEpochSecond()));
tableUpdateStatement.executeUpdate();
plugin.getLogger().info("Database update complete!");
} catch (SQLException e) {
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
} finally {
// Update the config file version
Bukkit.getScheduler().runTask(plugin, () -> {
plugin.getConfig().set("config_file_version", 8);
plugin.saveConfig();
});
}
}
});
}
}
}