diff --git a/pom.xml b/pom.xml index 55ec3fb1..0724c41c 100644 --- a/pom.xml +++ b/pom.xml @@ -124,6 +124,10 @@ minebench-repo https://repo.minebench.de/ + + pl3x-repo + https://repo.pl3x.net/ + @@ -145,6 +149,12 @@ v1.6.0 provided + + net.pl3x.map + pl3xmap-api + 1.0.0-SNAPSHOT + provided + com.github.MilkBowl VaultAPI diff --git a/src/main/java/me/william278/huskhomes2/HuskHomes.java b/src/main/java/me/william278/huskhomes2/HuskHomes.java index f32445c3..fe9e395b 100644 --- a/src/main/java/me/william278/huskhomes2/HuskHomes.java +++ b/src/main/java/me/william278/huskhomes2/HuskHomes.java @@ -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); diff --git a/src/main/java/me/william278/huskhomes2/commands/TpCommand.java b/src/main/java/me/william278/huskhomes2/commands/TpCommand.java index cbafc18a..977cae5e 100644 --- a/src/main/java/me/william278/huskhomes2/commands/TpCommand.java +++ b/src/main/java/me/william278/huskhomes2/commands/TpCommand.java @@ -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 "); + } + 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 "); + } + } 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); diff --git a/src/main/java/me/william278/huskhomes2/config/Settings.java b/src/main/java/me/william278/huskhomes2/config/Settings.java index 4998807d..b6762594 100644 --- a/src/main/java/me/william278/huskhomes2/config/Settings.java +++ b/src/main/java/me/william278/huskhomes2/config/Settings.java @@ -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; diff --git a/src/main/java/me/william278/huskhomes2/data/DataManager.java b/src/main/java/me/william278/huskhomes2/data/DataManager.java index 228f1d4c..f12db97a 100644 --- a/src/main/java/me/william278/huskhomes2/data/DataManager.java +++ b/src/main/java/me/william278/huskhomes2/data/DataManager.java @@ -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(); } } diff --git a/src/main/java/me/william278/huskhomes2/integrations/map/BlueMap.java b/src/main/java/me/william278/huskhomes2/integrations/map/BlueMap.java index 3d5744e9..dcf0d77b 100644 --- a/src/main/java/me/william278/huskhomes2/integrations/map/BlueMap.java +++ b/src/main/java/me/william278/huskhomes2/integrations/map/BlueMap.java @@ -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(); diff --git a/src/main/java/me/william278/huskhomes2/integrations/map/Pl3xMap.java b/src/main/java/me/william278/huskhomes2/integrations/map/Pl3xMap.java new file mode 100644 index 00000000..bacfb901 --- /dev/null +++ b/src/main/java/me/william278/huskhomes2/integrations/map/Pl3xMap.java @@ -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 publicHomeProviders = new HashMap<>(); + private final HashMap 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); + } + } + +} diff --git a/src/main/java/me/william278/huskhomes2/migrators/UpgradeDatabase.java b/src/main/java/me/william278/huskhomes2/migrators/UpgradeDatabase.java index 620f9a7e..89a9017b 100644 --- a/src/main/java/me/william278/huskhomes2/migrators/UpgradeDatabase.java +++ b/src/main/java/me/william278/huskhomes2/migrators/UpgradeDatabase.java @@ -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(); - }); - } - } - }); + } + } } diff --git a/src/main/resources/languages/en-gb.yml b/src/main/resources/languages/en-gb.yml index 8b49cbf6..00b3f2f6 100644 --- a/src/main/resources/languages/en-gb.yml +++ b/src/main/resources/languages/en-gb.yml @@ -9,8 +9,8 @@ teleporting_complete: '[Teleportation complete!](#00fb9a)' teleporting_action_bar_countdown: '[Teleporting in](#00fb9a) [%1%](#00fb9a bold)[...](#00fb9a)' teleporting_action_bar_cancelled: '[Teleportation cancelled!](#ff7e5e)' teleporting_please_stand_still: '[Teleportation will be cancelled if you move or take damage.](gray)' -home_deleted: '[Successfully deleted the home,](#00fb9a) [%1%](#00fb9a bold)' -warp_deleted: '[Successfully deleted the warp,](#00fb9a) [%1%](#00fb9a bold)' +home_deleted: '[Successfully deleted the home called](#00fb9a) [%1%](#00fb9a bold)' +warp_deleted: '[Successfully deleted the warp called](#00fb9a) [%1%](#00fb9a bold)' error_home_invalid: '[Error:](#ff3300) [You do not have a home named "%1%"](#ff7e5e)' error_warp_invalid: '[Error:](#ff3300) [There is no warp set named "%1%"](#ff7e5e)' error_invalid_syntax: '[Error:](#ff3300) [Incorrect syntax. Usage: %1%](#ff7e5e)' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 77159d7c..60166e44 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ version: ${project.version} main: me.william278.huskhomes2.HuskHomes api-version: 1.16 authors: [William278] -softdepend: [dynmap, Vault, BlueMap] +softdepend: [dynmap, Vault, BlueMap, Pl3xMap] description: A powerful, intuitive and flexible teleportation suite libraries: [mysql:mysql-connector-java:8.0.25]