From 8b104a04cd4d7cadd8ce1586a6094062d7d5b5c8 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 12 Jul 2021 19:04:38 +0300 Subject: [PATCH 1/7] Start work on tpOffline, add database column & modify upgrade script for 2.7 Signed-off-by: BuildTools --- .../me/william278/huskhomes2/HuskHomes.java | 11 ++++ .../huskhomes2/commands/TpIgnoreCommand.java | 17 ++++-- .../huskhomes2/data/DataManager.java | 61 +++++++++++++++++-- .../william278/huskhomes2/data/SQL/MySQL.java | 2 + .../huskhomes2/data/SQL/SQLite.java | 2 + .../huskhomes2/listeners/PlayerListener.java | 13 ++++ .../huskhomes2/migrators/UpgradeDatabase.java | 6 +- 7 files changed, 101 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/HuskHomes.java b/src/main/java/me/william278/huskhomes2/HuskHomes.java index 92b651a9..e8ce43d8 100644 --- a/src/main/java/me/william278/huskhomes2/HuskHomes.java +++ b/src/main/java/me/william278/huskhomes2/HuskHomes.java @@ -68,6 +68,17 @@ public final class HuskHomes extends JavaPlugin { ignoringTeleportRequests.remove(uuid); } + // Ignoring teleport requests handler + private static final HashSet teleportingPlayers = new HashSet<>(); + public static boolean isTeleporting(UUID uuid) { return teleportingPlayers.contains(uuid); } + public static void setTeleporting(UUID uuid) { + teleportingPlayers.add(uuid); + } + public static void setNotTeleporting(UUID uuid) { + teleportingPlayers.remove(uuid); + } + + // Metrics ID for bStats integration private static final int METRICS_PLUGIN_ID = 8430; /** diff --git a/src/main/java/me/william278/huskhomes2/commands/TpIgnoreCommand.java b/src/main/java/me/william278/huskhomes2/commands/TpIgnoreCommand.java index f04d9123..4f752112 100644 --- a/src/main/java/me/william278/huskhomes2/commands/TpIgnoreCommand.java +++ b/src/main/java/me/william278/huskhomes2/commands/TpIgnoreCommand.java @@ -15,21 +15,26 @@ public class TpIgnoreCommand extends CommandBase { @Override protected void onCommand(Player p, Command command, String label, String[] args) { + boolean ignoring; if (HuskHomes.isIgnoringTeleportRequests(p.getUniqueId())) { MessageManager.sendMessage(p, "tpignore_toggle_off"); - HuskHomes.setNotIgnoringTeleportRequests(p.getUniqueId()); - setIgnoringRequestsData(p, false); + ignoring = false; } else { MessageManager.sendMessage(p, "tpignore_toggle_on"); - HuskHomes.setIgnoringTeleportRequests(p.getUniqueId()); - setIgnoringRequestsData(p, true); + ignoring = true; } + setIgnoringRequestsData(p, ignoring); } - private void setIgnoringRequestsData(Player player, boolean isIgnoring) { + private void setIgnoringRequestsData(Player player, boolean ignoring) { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { try { - DataManager.setPlayerIgnoringRequests(player, isIgnoring, HuskHomes.getConnection()); + DataManager.setPlayerIgnoringRequests(player, ignoring, HuskHomes.getConnection()); + if (ignoring) { + HuskHomes.setIgnoringTeleportRequests(player.getUniqueId()); + } else { + HuskHomes.setNotIgnoringTeleportRequests(player.getUniqueId()); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/me/william278/huskhomes2/data/DataManager.java b/src/main/java/me/william278/huskhomes2/data/DataManager.java index c77e8545..7267fc58 100644 --- a/src/main/java/me/william278/huskhomes2/data/DataManager.java +++ b/src/main/java/me/william278/huskhomes2/data/DataManager.java @@ -706,6 +706,15 @@ public class DataManager { } } + public static TeleportationPoint getPlayerOfflinePosition(Player p, Connection connection) throws SQLException { + Integer locationID = getPlayerInteger(p, "offline_location_id", connection); + if (locationID != null) { + return getTeleportationPoint(locationID, connection); + } else { + return null; + } + } + // Insert a teleportation point, returns generated id public static Integer addTeleportationPoint(TeleportationPoint point, Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getLocationsDataTable() + " (world,server,x,y,z,yaw,pitch) VALUES(?,?,?,?,?,?,?);", Statement.RETURN_GENERATED_KEYS); @@ -728,6 +737,28 @@ public class DataManager { return null; } + // Update a player's offline position teleport point + public static void setTeleportationOfflinePositionData(UUID uuid, TeleportationPoint point, Connection connection) throws SQLException { + PreparedStatement ps; + // Add the teleportation point + Integer locationID = addTeleportationPoint(point, connection); + + if (locationID != null) { + // Set the destination location with the location_id of the last inserted teleport point + ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `offline_location_id`=? WHERE `user_uuid`=?;"); + ps.setInt(1, locationID); + ps.setString(2, uuid.toString()); + ps.executeUpdate(); + ps.close(); + } + } + + // Update a player's last position location on SQL + public static void setPlayerOfflinePosition(Player p, TeleportationPoint point, Connection connection) throws SQLException { + deletePlayerOfflinePosition(p, connection); + setTeleportationOfflinePositionData(p.getUniqueId(), point, connection); + } + // Update a player's last position teleport point public static void setTeleportationLastPositionData(UUID uuid, TeleportationPoint point, Connection connection) throws SQLException { PreparedStatement ps; @@ -761,12 +792,17 @@ public class DataManager { setPlayerDestinationLocation(p.getName(), point, connection); } - public static void setPlayerTeleporting(Player p, boolean value, Connection connection) throws SQLException { - setPlayerTeleportingData(p.getUniqueId(), value, connection); + public static void setPlayerTeleporting(Player p, boolean teleporting, Connection connection) throws SQLException { + setPlayerTeleportingData(p.getUniqueId(), teleporting, connection); + if (teleporting) { + HuskHomes.setTeleporting(p.getUniqueId()); + } else { + HuskHomes.setNotTeleporting(p.getUniqueId()); + } } - public static void setPlayerIgnoringRequests(Player p, boolean value, Connection connection) throws SQLException { - setPlayerIgnoringRequestsData(p.getUniqueId(), value, connection); + public static void setPlayerIgnoringRequests(Player p, boolean ignoringRequests, Connection connection) throws SQLException { + setPlayerIgnoringRequestsData(p.getUniqueId(), ignoringRequests, connection); } public static void updateRtpCooldown(Player p, Connection connection) throws SQLException { @@ -800,6 +836,14 @@ public class DataManager { } } + public static void deletePlayerOfflinePosition(Player p, Connection connection) throws SQLException { + Integer offlineLocationId = getPlayerInteger(p, "offline_location_id", connection); + if (offlineLocationId != null) { + deleteTeleportationPoint(offlineLocationId, connection); + clearPlayerOfflineData(p.getUniqueId(), connection); + } + } + // Update the location of a home public static void setHomeTeleportPoint(String homeName, int ownerID, TeleportationPoint point, Connection connection) throws SQLException { PreparedStatement ps; @@ -835,6 +879,15 @@ public class DataManager { ps.close(); } + // Clear a player's last position + public static void clearPlayerOfflineData(UUID uuid, Connection connection) throws SQLException { + PreparedStatement ps; + ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `offline_location_id`=NULL WHERE `user_uuid`=?;"); + ps.setString(1, uuid.toString()); + ps.executeUpdate(); + ps.close(); + } + public static void addWarp(Warp warp, Connection connection) throws SQLException { PreparedStatement ps; // Add the teleportation point diff --git a/src/main/java/me/william278/huskhomes2/data/SQL/MySQL.java b/src/main/java/me/william278/huskhomes2/data/SQL/MySQL.java index 1c3018a1..6d9c4fc4 100644 --- a/src/main/java/me/william278/huskhomes2/data/SQL/MySQL.java +++ b/src/main/java/me/william278/huskhomes2/data/SQL/MySQL.java @@ -33,9 +33,11 @@ public class MySQL extends Database { "`is_teleporting` boolean NOT NULL DEFAULT 0," + "`dest_location_id` integer NULL," + "`last_location_id` integer NULL," + + "`offline_location_id` integer NULL," + "`is_ignoring_requests` boolean NOT NULL DEFAULT 0," + "PRIMARY KEY (`player_id`)," + + "FOREIGN KEY (`offline_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION," + "FOREIGN KEY (`dest_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION," + "FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" + ");", diff --git a/src/main/java/me/william278/huskhomes2/data/SQL/SQLite.java b/src/main/java/me/william278/huskhomes2/data/SQL/SQLite.java index 227548a1..118c8122 100644 --- a/src/main/java/me/william278/huskhomes2/data/SQL/SQLite.java +++ b/src/main/java/me/william278/huskhomes2/data/SQL/SQLite.java @@ -35,8 +35,10 @@ public class SQLite extends Database { "`is_teleporting` boolean NOT NULL DEFAULT 0," + "`dest_location_id` integer NULL," + "`last_location_id` integer NULL," + + "`offline_location_id` integer NULL," + "`is_ignoring_requests` boolean NOT NULL DEFAULT 0," + "PRIMARY KEY (`player_id`)," + + "FOREIGN KEY (`offline_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION," + "FOREIGN KEY (`dest_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION," + "FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" + ");", diff --git a/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java b/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java index 3773f16a..04fbeaf4 100644 --- a/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java +++ b/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java @@ -13,6 +13,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import java.sql.Connection; import java.sql.SQLException; @@ -97,4 +98,16 @@ public class PlayerListener implements Listener { HuskHomes.getPlayerList().addPlayer(p.getName()); } } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent e) { + Player p = e.getPlayer(); + if (HuskHomes.isTeleporting(p.getUniqueId())) { + HuskHomes.setNotTeleporting(p.getUniqueId()); + Connection connection = HuskHomes.getConnection(); + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + // Set player offline position + }); + } + } } diff --git a/src/main/java/me/william278/huskhomes2/migrators/UpgradeDatabase.java b/src/main/java/me/william278/huskhomes2/migrators/UpgradeDatabase.java index 0685b63e..13f6a9ce 100644 --- a/src/main/java/me/william278/huskhomes2/migrators/UpgradeDatabase.java +++ b/src/main/java/me/william278/huskhomes2/migrators/UpgradeDatabase.java @@ -17,7 +17,11 @@ public class UpgradeDatabase { if (plugin.getConfig().getInt("config_file_version", 1) <= 5) { plugin.getLogger().info("Detected that the database needs updating. Running database upgrade..."); Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - try (PreparedStatement statement = HuskHomes.getConnection().prepareStatement("ALTER TABLE " + HuskHomes.getSettings().getPlayerDataTable() + " ADD `is_ignoring_requests` boolean NOT NULL DEFAULT 0")) { + try (PreparedStatement statement = HuskHomes.getConnection().prepareStatement( + "ALTER TABLE " + HuskHomes.getSettings().getPlayerDataTable() + + " ADD `is_ignoring_requests` boolean NOT NULL DEFAULT 0, " + + "`offline_location_id` integer NULL DEFAULT NULL, " + + "FOREIGN KEY (`offline_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION;")) { statement.executeUpdate(); plugin.getLogger().info("Database update complete!"); } catch (SQLException e) { From 10210da79246141b2f6ace9c76d13d8f6a27f95d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 12 Jul 2021 23:12:00 +0300 Subject: [PATCH 2/7] Added offline player handling Signed-off-by: BuildTools --- .../me/william278/huskhomes2/HuskHomes.java | 1 + .../william278/huskhomes2/MessageManager.java | 2 +- .../huskhomes2/commands/TpOfflineCommand.java | 34 +++++++++++++++++++ .../huskhomes2/data/DataManager.java | 20 +++++------ .../huskhomes2/listeners/PlayerListener.java | 16 +++++++-- .../huskhomes2/teleport/TeleportManager.java | 14 ++++++++ src/main/resources/Languages/en-gb.yml | 3 +- src/main/resources/plugin.yml | 7 ++++ 8 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 src/main/java/me/william278/huskhomes2/commands/TpOfflineCommand.java diff --git a/src/main/java/me/william278/huskhomes2/HuskHomes.java b/src/main/java/me/william278/huskhomes2/HuskHomes.java index e8ce43d8..5de01a60 100644 --- a/src/main/java/me/william278/huskhomes2/HuskHomes.java +++ b/src/main/java/me/william278/huskhomes2/HuskHomes.java @@ -155,6 +155,7 @@ public final class HuskHomes extends JavaPlugin { new SetHomeCommand().register(getCommand("sethome")).setTabCompleter(emptyTab); new SetWarpCommand().register(getCommand("setwarp")).setTabCompleter(emptyTab); new BackCommand().register(getCommand("back")).setTabCompleter(emptyTab); + new TpOfflineCommand().register(getCommand("tpoffline")).setTabCompleter(emptyTab); // Update caches PublicHomeCommand.updatePublicHomeTabCache(); diff --git a/src/main/java/me/william278/huskhomes2/MessageManager.java b/src/main/java/me/william278/huskhomes2/MessageManager.java index 512d6b5b..ef1ec37d 100644 --- a/src/main/java/me/william278/huskhomes2/MessageManager.java +++ b/src/main/java/me/william278/huskhomes2/MessageManager.java @@ -72,7 +72,7 @@ public class MessageManager { } saveFile(config, f); messages.clear(); - for (String message : config.getConfigurationSection("").getKeys(false)) { + for (String message : config.getKeys(false)) { messages.put(message, StringEscapeUtils.unescapeJava(config.getString(message))); } } diff --git a/src/main/java/me/william278/huskhomes2/commands/TpOfflineCommand.java b/src/main/java/me/william278/huskhomes2/commands/TpOfflineCommand.java new file mode 100644 index 00000000..0f85d3c9 --- /dev/null +++ b/src/main/java/me/william278/huskhomes2/commands/TpOfflineCommand.java @@ -0,0 +1,34 @@ +package me.william278.huskhomes2.commands; + +import me.william278.huskhomes2.HuskHomes; +import me.william278.huskhomes2.MessageManager; +import me.william278.huskhomes2.teleport.TeleportManager; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.logging.Level; + +public class TpOfflineCommand extends CommandBase { + + private static final HuskHomes plugin = HuskHomes.getInstance(); + + @Override + protected void onCommand(Player p, Command command, String label, String[] args) { + if (args.length == 1) { + final String targetPlayer = args[0]; + Connection connection = HuskHomes.getConnection(); + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + try { + TeleportManager.teleportToOfflinePlayer(p, targetPlayer, connection); + } catch (SQLException e) { + plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred teleporting you to a player's offline position"); + } + }); + } else { + MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage()); + } + } +} diff --git a/src/main/java/me/william278/huskhomes2/data/DataManager.java b/src/main/java/me/william278/huskhomes2/data/DataManager.java index 7267fc58..b974e29a 100644 --- a/src/main/java/me/william278/huskhomes2/data/DataManager.java +++ b/src/main/java/me/william278/huskhomes2/data/DataManager.java @@ -36,7 +36,7 @@ public class DataManager { } // Return a player's ID from their username - private static Integer getPlayerId(String playerUsername, Connection connection) throws SQLException { + public static Integer getPlayerId(String playerUsername, Connection connection) throws SQLException { PreparedStatement ps; ResultSet rs; @@ -706,8 +706,8 @@ public class DataManager { } } - public static TeleportationPoint getPlayerOfflinePosition(Player p, Connection connection) throws SQLException { - Integer locationID = getPlayerInteger(p, "offline_location_id", connection); + public static TeleportationPoint getPlayerOfflinePosition(int playerID, Connection connection) throws SQLException { + Integer locationID = getPlayerInteger(playerID, "offline_location_id", connection); if (locationID != null) { return getTeleportationPoint(locationID, connection); } else { @@ -754,9 +754,9 @@ public class DataManager { } // Update a player's last position location on SQL - public static void setPlayerOfflinePosition(Player p, TeleportationPoint point, Connection connection) throws SQLException { - deletePlayerOfflinePosition(p, connection); - setTeleportationOfflinePositionData(p.getUniqueId(), point, connection); + public static void setPlayerOfflinePosition(UUID uuid, TeleportationPoint point, Connection connection) throws SQLException { + deletePlayerOfflinePosition(uuid, connection); + setTeleportationOfflinePositionData(uuid, point, connection); } // Update a player's last position teleport point @@ -793,12 +793,12 @@ public class DataManager { } public static void setPlayerTeleporting(Player p, boolean teleporting, Connection connection) throws SQLException { - setPlayerTeleportingData(p.getUniqueId(), teleporting, connection); if (teleporting) { HuskHomes.setTeleporting(p.getUniqueId()); } else { HuskHomes.setNotTeleporting(p.getUniqueId()); } + setPlayerTeleportingData(p.getUniqueId(), teleporting, connection); } public static void setPlayerIgnoringRequests(Player p, boolean ignoringRequests, Connection connection) throws SQLException { @@ -836,11 +836,11 @@ public class DataManager { } } - public static void deletePlayerOfflinePosition(Player p, Connection connection) throws SQLException { - Integer offlineLocationId = getPlayerInteger(p, "offline_location_id", connection); + public static void deletePlayerOfflinePosition(UUID uuid, Connection connection) throws SQLException { + Integer offlineLocationId = getPlayerInteger(getPlayerId(uuid, connection), "offline_location_id", connection); if (offlineLocationId != null) { deleteTeleportationPoint(offlineLocationId, connection); - clearPlayerOfflineData(p.getUniqueId(), connection); + clearPlayerOfflineData(uuid, connection); } } diff --git a/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java b/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java index 04fbeaf4..2360a7e6 100644 --- a/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java +++ b/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java @@ -8,6 +8,7 @@ import me.william278.huskhomes2.data.DataManager; import me.william278.huskhomes2.teleport.TeleportManager; import me.william278.huskhomes2.teleport.points.TeleportationPoint; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -17,6 +18,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.sql.Connection; import java.sql.SQLException; +import java.util.UUID; import java.util.logging.Level; public class PlayerListener implements Listener { @@ -102,11 +104,19 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent e) { Player p = e.getPlayer(); - if (HuskHomes.isTeleporting(p.getUniqueId())) { - HuskHomes.setNotTeleporting(p.getUniqueId()); + final UUID uuid = p.getUniqueId(); + if (HuskHomes.isTeleporting(uuid)) { + final Location logOutLocation = p.getLocation(); + HuskHomes.setNotTeleporting(uuid); Connection connection = HuskHomes.getConnection(); Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - // Set player offline position + try { + DataManager.setPlayerOfflinePosition(uuid, + new TeleportationPoint(logOutLocation, HuskHomes.getSettings().getServerID()), + connection); + } catch (SQLException ex) { + Bukkit.getLogger().severe("An SQL exception occurred in retrieving if a warp exists from the table."); + } }); } } diff --git a/src/main/java/me/william278/huskhomes2/teleport/TeleportManager.java b/src/main/java/me/william278/huskhomes2/teleport/TeleportManager.java index 524ca04b..904199ca 100644 --- a/src/main/java/me/william278/huskhomes2/teleport/TeleportManager.java +++ b/src/main/java/me/william278/huskhomes2/teleport/TeleportManager.java @@ -85,6 +85,20 @@ public class TeleportManager { new TimedTeleport(player, point, TimedTeleport.TargetType.POINT).begin(); } + public static void teleportToOfflinePlayer(Player player, String targetPlayer, Connection connection) throws SQLException { + final Integer playerID = DataManager.getPlayerId(targetPlayer, connection); + if (playerID == null) { + MessageManager.sendMessage(player, "error_player_not_found", targetPlayer); + return; + } + TeleportationPoint offlinePoint = DataManager.getPlayerOfflinePosition(playerID, connection); + if (offlinePoint == null) { + MessageManager.sendMessage(player, "error_no_offline_position", targetPlayer); + return; + } + teleportPlayer(player, offlinePoint, connection); + } + public static void queueBackTeleport(Player player, Connection connection) throws SQLException { try { TeleportationPoint lastPosition = DataManager.getPlayerLastPosition(player, connection); diff --git a/src/main/resources/Languages/en-gb.yml b/src/main/resources/Languages/en-gb.yml index 95e23109..34976fb9 100644 --- a/src/main/resources/Languages/en-gb.yml +++ b/src/main/resources/Languages/en-gb.yml @@ -105,4 +105,5 @@ command_list_header: '\n[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)' error_invalid_on_arrival: '[Error:](#ff3300) [Failed to finish your teleportation as the target world could not be found.](#ff7e5e)' tpignore_toggle_on: '[You are now](#00fb9a) [ignoring](#00fb9a bold) [incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to any incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to ignore incoming teleport requests run_command=/huskhomes:tpignore)' -error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests!](#ff7e5e) [(Click to toggle)](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' \ No newline at end of file +error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests!](#ff7e5e) [(Click to toggle)](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' +error_no_offline_position: '[Error:](#ff3300) [Could not find where %1% last logged out from](#ff7e5e)' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8dfd23d3..a64d99cc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -100,6 +100,10 @@ commands: usage: /tpignore permission: huskhomes.tpignore aliases: [tpaignore, ignoretprequests] + tpoffline: + description: Teleport to where a player was last online + usage: /tpoffline + permission: huskhomes.tpoffline rtp: description: Teleport randomly into the wild usage: /rtp @@ -227,6 +231,9 @@ permissions: huskhomes.tpignore: description: Allows you to ingore teleport requests default: true + huskhomes.tpoffline: + description: Allows you to teleport to where players logged off + default: false huskhomes.back.death: description: Allows you to return to where you died default: true From 541f85596b8f916d9fc08aef153eb41ff37ddcb8 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 12 Jul 2021 23:22:54 +0300 Subject: [PATCH 3/7] Adjusted default inheritance on a few permissions Signed-off-by: BuildTools --- src/main/resources/plugin.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a64d99cc..a8c00024 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -211,8 +211,6 @@ permissions: huskhomes.rtp.bypass_cooldown: description: Allows you to bypass the /rtp cooldown default: false - children: - huskhomes.rtp: true huskhomes.about: description: View information about the plugin default: true @@ -224,7 +222,7 @@ permissions: default: op huskhomes.tp: description: Allows you to directly teleport to players or locations - default: false + default: op huskhomes.tprequest: description: Allows you to request to teleport to a player default: true @@ -233,7 +231,7 @@ permissions: default: true huskhomes.tpoffline: description: Allows you to teleport to where players logged off - default: false + default: op huskhomes.back.death: description: Allows you to return to where you died default: true @@ -243,10 +241,6 @@ permissions: huskhomes.spawn.set: description: Allows you to set the spawn location default: op - children: - huskhomes.spawn: true huskhomes.edithome.public: description: Allows you to make a home public - default: true - children: - huskhomes.edithome: true \ No newline at end of file + default: true \ No newline at end of file From 725d3d964b22e60705d8f0d098cae4c0e823a4c5 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 12 Jul 2021 23:33:02 +0300 Subject: [PATCH 4/7] Catch IllegalArgumentException Signed-off-by: BuildTools --- .../me/william278/huskhomes2/data/DataManager.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/data/DataManager.java b/src/main/java/me/william278/huskhomes2/data/DataManager.java index b974e29a..cedf1921 100644 --- a/src/main/java/me/william278/huskhomes2/data/DataManager.java +++ b/src/main/java/me/william278/huskhomes2/data/DataManager.java @@ -707,10 +707,14 @@ public class DataManager { } public static TeleportationPoint getPlayerOfflinePosition(int playerID, Connection connection) throws SQLException { - Integer locationID = getPlayerInteger(playerID, "offline_location_id", connection); - if (locationID != null) { - return getTeleportationPoint(locationID, connection); - } else { + try { + Integer locationID = getPlayerInteger(playerID, "offline_location_id", connection); + if (locationID != null) { + return getTeleportationPoint(locationID, connection); + } else { + return null; + } + } catch (IllegalArgumentException e) { return null; } } From 7e10bf83345dba9273a35ac08de9284353d1c578 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 12 Jul 2021 23:38:59 +0300 Subject: [PATCH 5/7] Adjust locale; add to it-it too Signed-off-by: BuildTools --- .../me/william278/huskhomes2/listeners/PlayerListener.java | 2 +- src/main/resources/Languages/it-it.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java b/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java index 2360a7e6..e1174866 100644 --- a/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java +++ b/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java @@ -105,7 +105,7 @@ public class PlayerListener implements Listener { public void onPlayerQuit(PlayerQuitEvent e) { Player p = e.getPlayer(); final UUID uuid = p.getUniqueId(); - if (HuskHomes.isTeleporting(uuid)) { + if (!HuskHomes.isTeleporting(uuid)) { final Location logOutLocation = p.getLocation(); HuskHomes.setNotTeleporting(uuid); Connection connection = HuskHomes.getConnection(); diff --git a/src/main/resources/Languages/it-it.yml b/src/main/resources/Languages/it-it.yml index 29de9fcc..b617a2e9 100644 --- a/src/main/resources/Languages/it-it.yml +++ b/src/main/resources/Languages/it-it.yml @@ -105,4 +105,5 @@ command_list_header: '\n[HuskHomes](#00fb9a bold) [| Comandi](#00fb9a)' error_invalid_on_arrival: '[Errore:](#ff3300) [Non sono riuscito a teletrasportarti perché il mondo non è caricato correttamente.](#ff7e5e)' tpignore_toggle_on: '[You are now](#00fb9a) [ignoring](#00fb9a bold) [incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to any incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to ignore incoming teleport requests run_command=/huskhomes:tpignore)' -error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests!](#ff7e5e) [(Click to toggle)](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' \ No newline at end of file +error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests!](#ff7e5e) [(Click to toggle)](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' +error_no_offline_position: '[Error:](#ff3300) [Could not find where %1% last logged out.](#ff7e5e)' \ No newline at end of file From a7fb700d0591b67192b0e552d8092f22e9620dbd Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 12 Jul 2021 23:44:19 +0300 Subject: [PATCH 6/7] Add action message Signed-off-by: BuildTools --- .../java/me/william278/huskhomes2/teleport/TeleportManager.java | 1 + src/main/resources/Languages/it-it.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/me/william278/huskhomes2/teleport/TeleportManager.java b/src/main/java/me/william278/huskhomes2/teleport/TeleportManager.java index 29eaecf1..f61c18ad 100644 --- a/src/main/java/me/william278/huskhomes2/teleport/TeleportManager.java +++ b/src/main/java/me/william278/huskhomes2/teleport/TeleportManager.java @@ -96,6 +96,7 @@ public class TeleportManager { MessageManager.sendMessage(player, "error_no_offline_position", targetPlayer); return; } + MessageManager.sendMessage(player, "teleporting_offline_player", targetPlayer); teleportPlayer(player, offlinePoint, connection); } diff --git a/src/main/resources/Languages/it-it.yml b/src/main/resources/Languages/it-it.yml index b617a2e9..f6859272 100644 --- a/src/main/resources/Languages/it-it.yml +++ b/src/main/resources/Languages/it-it.yml @@ -1,6 +1,7 @@ error_no_permission: '[Errore:](#ff3300) [Non hai il permesso di eseguire questo comando.](#ff7e5e)' error_no_last_position: '[Errore:](#ff3300) [Non hai nessuna posizione precedente salvata!](#ff7e5e)' teleporting_last_position: '[Teletrasporto alla posizione precedente tra](#00fb9a) [%1%](#00fb9a bold) [secondi](#00fb9a)' +teleporting_offline_player: '[Teleporting you to where %1% last logged out...](#00fb9a)' teleporting_countdown_start: '[Verrai teletrasportato tra](#00fb9a) [%1%](#00fb9a bold) [secondi](#00fb9a)' teleporting_cancelled_movement: '[Teletrasporto cancellato: ti sei mosso!](#ff7e5e)' teleporting_cancelled_damage: '[Teletrasporto cancellato: hai preso danno!](#ff7e5e)' From 50bed71414579543145668cd8f41eb2459da62cb Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 12 Jul 2021 23:49:31 +0300 Subject: [PATCH 7/7] Add locale to en-gb and minor update to how player cross-server teleporting is tracked Signed-off-by: BuildTools --- .../me/william278/huskhomes2/listeners/PlayerListener.java | 3 ++- src/main/resources/Languages/en-gb.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java b/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java index e1174866..a623f406 100644 --- a/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java +++ b/src/main/java/me/william278/huskhomes2/listeners/PlayerListener.java @@ -107,7 +107,6 @@ public class PlayerListener implements Listener { final UUID uuid = p.getUniqueId(); if (!HuskHomes.isTeleporting(uuid)) { final Location logOutLocation = p.getLocation(); - HuskHomes.setNotTeleporting(uuid); Connection connection = HuskHomes.getConnection(); Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { try { @@ -118,6 +117,8 @@ public class PlayerListener implements Listener { Bukkit.getLogger().severe("An SQL exception occurred in retrieving if a warp exists from the table."); } }); + } else { + HuskHomes.setNotTeleporting(uuid); } } } diff --git a/src/main/resources/Languages/en-gb.yml b/src/main/resources/Languages/en-gb.yml index 34976fb9..f37ff7ff 100644 --- a/src/main/resources/Languages/en-gb.yml +++ b/src/main/resources/Languages/en-gb.yml @@ -1,6 +1,7 @@ error_no_permission: '[Error:](#ff3300) [You do not have permission to execute that command.](#ff7e5e)' error_no_last_position: '[Error:](#ff3300) [You have no last position to return to!](#ff7e5e)' teleporting_last_position: '[Returning to your last position in](#00fb9a) [%1%](#00fb9a bold) [seconds](#00fb9a)' +teleporting_offline_player: '[Teleporting you to where %1% last logged out...](#00fb9a)' teleporting_countdown_start: '[You will be teleported in](#00fb9a) [%1%](#00fb9a bold) [seconds](#00fb9a)' teleporting_cancelled_movement: '[Teleportation cancelled; you moved!](#ff7e5e)' teleporting_cancelled_damage: '[Teleportation cancelled; you took damage!](#ff7e5e)' @@ -106,4 +107,4 @@ error_invalid_on_arrival: '[Error:](#ff3300) [Failed to finish your teleportatio tpignore_toggle_on: '[You are now](#00fb9a) [ignoring](#00fb9a bold) [incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to any incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to ignore incoming teleport requests run_command=/huskhomes:tpignore)' error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests!](#ff7e5e) [(Click to toggle)](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' -error_no_offline_position: '[Error:](#ff3300) [Could not find where %1% last logged out from](#ff7e5e)' \ No newline at end of file +error_no_offline_position: '[Error:](#ff3300) [Could not find where %1% last logged out.](#ff7e5e)' \ No newline at end of file