From 6afd19156a2b1f827e87ad035e4f173e72c45ef8 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 16 Jul 2021 16:26:08 +0300 Subject: [PATCH] Add API method for updating the player's last position Signed-off-by: BuildTools --- .../huskhomes2/api/HuskHomesAPI.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/api/HuskHomesAPI.java b/src/main/java/me/william278/huskhomes2/api/HuskHomesAPI.java index dc970113..ae843feb 100644 --- a/src/main/java/me/william278/huskhomes2/api/HuskHomesAPI.java +++ b/src/main/java/me/william278/huskhomes2/api/HuskHomesAPI.java @@ -13,6 +13,7 @@ import org.bukkit.entity.Player; import java.sql.Connection; import java.sql.SQLException; import java.util.List; +import java.util.UUID; import java.util.logging.Level; /** @@ -183,6 +184,21 @@ public class HuskHomesAPI { return TeleportManager.getSpawnLocation(); } + /** + * Updates a player's last position on the server + * @param player The {@link Player} who's last position you wish to update + * @param point the {@link TeleportationPoint} to set as their new last position + */ + public void updatePlayerLastPosition(Player player, TeleportationPoint point) { + Bukkit.getScheduler().runTaskAsynchronously(huskHomes, () -> { + try { + DataManager.setPlayerLastPosition(player, point, HuskHomes.getConnection()); + } catch (SQLException e) { + huskHomes.getLogger().severe("An SQL exception occurred updating a player's last position via the API."); + } + }); + } + /** * Teleport a player to a specific TeleportationPoint * @param player The player to be teleported @@ -191,7 +207,7 @@ public class HuskHomesAPI { * @see TeleportationPoint */ public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) { - Connection connection = huskHomes.getInstance().getConnection(); + Connection connection = HuskHomes.getConnection(); Bukkit.getScheduler().runTask(huskHomes, () -> { try { if (timed) { @@ -200,7 +216,7 @@ public class HuskHomesAPI { TeleportManager.teleportPlayer(player, point, connection); } } catch (SQLException e) { - huskHomes.getLogger().log(Level.WARNING, "An SQLException occurred timed-teleporting a player via API"); + huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred timed-teleporting a player via the API."); } }); }