mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Adjust connection getting during teleport to fix expired connection error
This commit is contained in:
1 parent
4e2488399d
commit
9943d2c9d5
11 files changed
+145
-166
No files matched your search
@@ -246,14 +246,10 @@ public class HuskHomesAPI {
|
||||
*/
|
||||
public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) {
|
||||
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, point, connection);
|
||||
} else {
|
||||
TeleportManager.teleportPlayer(player, point, connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred timed-teleporting a player via the API.");
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, point);
|
||||
} else {
|
||||
TeleportManager.teleportPlayer(player, point);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -268,14 +264,10 @@ public class HuskHomesAPI {
|
||||
*/
|
||||
public void teleportPlayer(Player player, String targetPlayerName, boolean timed) {
|
||||
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, targetPlayerName, connection);
|
||||
} else {
|
||||
TeleportManager.teleportPlayer(player, targetPlayerName, connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
huskHomes.getLogger().log(Level.WARNING, "An SQLException occurred teleporting a player via API");
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, targetPlayerName);
|
||||
} else {
|
||||
TeleportManager.teleportPlayer(player, targetPlayerName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class HomeCommand extends CommandBase {
|
||||
PublicHomeCommand.queueHomeTeleport(p, homeArgument);
|
||||
} else if (DataManager.homeExists(p, homeArgument, connection)) {
|
||||
Home home = DataManager.getHome(p.getName(), homeArgument, connection);
|
||||
TeleportManager.queueTimedTeleport(p, home, connection);
|
||||
TeleportManager.queueTimedTeleport(p, home);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_home_invalid", homeArgument);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class HomeCommand extends CommandBase {
|
||||
List<Home> homes = DataManager.getPlayerHomes(p.getName(), connection);
|
||||
if (homes.size() == 1) {
|
||||
// Teleport the player if they only have one home
|
||||
TeleportManager.queueTimedTeleport(p, homes.get(0), connection);
|
||||
TeleportManager.queueTimedTeleport(p, homes.get(0));
|
||||
return;
|
||||
}
|
||||
HomeListCommand.displayPlayerHomeList(p, p.getName(), 1);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompleter {
|
||||
Home home = DataManager.getHome(ownerName, homeName, connection);
|
||||
assert home != null;
|
||||
if (home.isPublic() || p.getName().equalsIgnoreCase(ownerName) || p.hasPermission("huskhomes.home.other")) {
|
||||
TeleportManager.queueTimedTeleport(p, home, connection);
|
||||
TeleportManager.queueTimedTeleport(p, home);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_public_home_invalid", ownerName, homeName);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompleter {
|
||||
if (!home.isPublic()) {
|
||||
sender.sendMessage("Warning: Bypassed home security (" + home.getName() + " was not set to public by " + home.getOwnerUsername() + ")");
|
||||
}
|
||||
TeleportManager.teleportPlayer(targetPlayer, home, connection);
|
||||
TeleportManager.teleportPlayer(targetPlayer, home);
|
||||
sender.sendMessage("Successfully teleported player!");
|
||||
MessageManager.sendMessage(targetPlayer, "teleporting_complete_console", (home.getOwnerUsername() + "." + homeName));
|
||||
} else {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class SpawnCommand extends CommandBase {
|
||||
// Cross server spawn teleport
|
||||
if (HuskHomes.getSettings().doCrossServerSpawn()) {
|
||||
if (DataManager.warpExists(spawnWarpName, connection)) {
|
||||
TeleportManager.queueTimedTeleport(p, DataManager.getWarp(spawnWarpName, connection), connection);
|
||||
TeleportManager.queueTimedTeleport(p, DataManager.getWarp(spawnWarpName, connection));
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_spawn_undefined");
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class SpawnCommand extends CommandBase {
|
||||
|
||||
// Server-based spawn teleport
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
TeleportManager.queueTimedTeleport(p, TeleportManager.getSpawnLocation(), connection);
|
||||
TeleportManager.queueTimedTeleport(p, TeleportManager.getSpawnLocation());
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_spawn_undefined");
|
||||
}
|
||||
|
||||
@@ -27,94 +27,90 @@ public class TpCommand extends CommandBase {
|
||||
@Override
|
||||
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
switch (args.length) {
|
||||
default:
|
||||
case 0:
|
||||
switch (args.length) {
|
||||
default:
|
||||
case 0:
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return;
|
||||
case 1:
|
||||
String targetPlayer = args[0];
|
||||
TeleportManager.teleportPlayer(p, NameAutoCompleter.getAutoCompletedName(targetPlayer));
|
||||
return;
|
||||
case 3:
|
||||
try {
|
||||
double x = Double.parseDouble(args[0]);
|
||||
double y = Double.parseDouble(args[1]);
|
||||
double z = Double.parseDouble(args[2]);
|
||||
TeleportationPoint teleportationPoint = new TeleportationPoint(p.getWorld().getName(), x, y, z, 0F, 0F, HuskHomes.getSettings().getServerID());
|
||||
TeleportManager.teleportPlayer(p, teleportationPoint);
|
||||
} catch (NumberFormatException e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||
}
|
||||
return;
|
||||
case 4:
|
||||
try {
|
||||
double x = Double.parseDouble(args[0]);
|
||||
double y = Double.parseDouble(args[1]);
|
||||
double z = Double.parseDouble(args[2]);
|
||||
String worldName = args[3];
|
||||
if (Bukkit.getWorld(worldName) == null) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||
return;
|
||||
}
|
||||
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, HuskHomes.getSettings().getServerID());
|
||||
TeleportManager.teleportPlayer(p, teleportationPoint);
|
||||
} catch (NumberFormatException e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||
}
|
||||
return;
|
||||
case 5:
|
||||
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];
|
||||
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, serverName);
|
||||
TeleportManager.teleportPlayer(p, teleportationPoint);
|
||||
} catch (NumberFormatException e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <server>");
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return;
|
||||
case 1:
|
||||
String targetPlayer = args[0];
|
||||
TeleportManager.teleportPlayer(p, NameAutoCompleter.getAutoCompletedName(targetPlayer), connection);
|
||||
return;
|
||||
case 3:
|
||||
try {
|
||||
double x = Double.parseDouble(args[0]);
|
||||
double y = Double.parseDouble(args[1]);
|
||||
double z = Double.parseDouble(args[2]);
|
||||
TeleportationPoint teleportationPoint = new TeleportationPoint(p.getWorld().getName(), x, y, z, 0F, 0F, HuskHomes.getSettings().getServerID());
|
||||
TeleportManager.teleportPlayer(p, teleportationPoint, connection);
|
||||
} catch (NumberFormatException e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||
}
|
||||
return;
|
||||
case 4:
|
||||
}
|
||||
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);
|
||||
} 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];
|
||||
if (Bukkit.getWorld(worldName) == null) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||
return;
|
||||
}
|
||||
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, HuskHomes.getSettings().getServerID());
|
||||
TeleportManager.teleportPlayer(p, teleportationPoint, connection);
|
||||
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);
|
||||
} catch (NumberFormatException e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <server> <yaw> <pitch>");
|
||||
}
|
||||
return;
|
||||
case 5:
|
||||
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];
|
||||
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, serverName);
|
||||
TeleportManager.teleportPlayer(p, teleportationPoint, connection);
|
||||
} catch (NumberFormatException e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <server>");
|
||||
}
|
||||
} 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);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TpHereCommand extends CommandBase {
|
||||
String targetPlayer = args[0];
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
TeleportManager.teleportHere(p, NameAutoCompleter.getAutoCompletedName(targetPlayer), connection);
|
||||
TeleportManager.teleportHere(p, NameAutoCompleter.getAutoCompletedName(targetPlayer));
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred using /tphere");
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class WarpCommand extends CommandBase {
|
||||
if (DataManager.warpExists(warpName, connection)) {
|
||||
if (Warp.getWarpCanUse(p, warpName)) {
|
||||
Warp warp = DataManager.getWarp(warpName, connection);
|
||||
TeleportManager.queueTimedTeleport(p, warp, connection);
|
||||
TeleportManager.queueTimedTeleport(p, warp);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_permission_restricted_warp", warpName);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class WarpCommand extends CommandBase {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
if (DataManager.warpExists(warpName, connection)) {
|
||||
Warp warp = DataManager.getWarp(warpName, connection);
|
||||
TeleportManager.teleportPlayer(targetPlayer, warp, connection);
|
||||
TeleportManager.teleportPlayer(targetPlayer, warp);
|
||||
sender.sendMessage("Successfully warped player!");
|
||||
MessageManager.sendMessage(targetPlayer, "teleporting_complete_console", warpName);
|
||||
} else {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class CrossServerMessageHandler {
|
||||
MessageManager.sendMessage(recipient, "tpa_has_accepted", tpaReplierName);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
TeleportManager.queueTimedTeleport(recipient, tpaReplierName, connection);
|
||||
TeleportManager.queueTimedTeleport(recipient, tpaReplierName);
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred responding to a plugin message teleport request reply");
|
||||
}
|
||||
@@ -94,13 +94,7 @@ public class CrossServerMessageHandler {
|
||||
MessageManager.sendMessage(recipient, "tpa_has_declined", tpaHereReplierName);
|
||||
}
|
||||
}
|
||||
case TELEPORT_TO_ME -> Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
TeleportManager.teleportPlayer(recipient, receivedMessage.getMessageData(), connection);
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred responding to a plugin message teleport-to-me request");
|
||||
}
|
||||
});
|
||||
case TELEPORT_TO_ME -> Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> TeleportManager.teleportPlayer(recipient, receivedMessage.getMessageData()));
|
||||
case GET_PLAYER_LIST -> {
|
||||
final String requestingServer = receivedMessage.getMessageData();
|
||||
StringJoiner playerList = new StringJoiner("£");
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.bukkit.entity.Player;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeleportManager {
|
||||
@@ -35,13 +34,14 @@ public class TeleportManager {
|
||||
return preTeleportEvent.isCancelled();
|
||||
}
|
||||
|
||||
public static void teleportPlayer(Player player, String targetPlayer, Connection connection) {
|
||||
// Teleport a player to a player by name
|
||||
public static void teleportPlayer(Player player, String targetPlayer) {
|
||||
final TeleportationPoint destination = new TeleportationPoint(player.getLocation(),
|
||||
HuskHomes.getSettings().getServerID());
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (isEventCancelled(player, destination)) return;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
DataManager.setPlayerLastPosition(player, destination, connection);
|
||||
setPlayerDestinationFromTargetPlayer(player, targetPlayer, connection);
|
||||
} catch (SQLException e) {
|
||||
@@ -51,13 +51,14 @@ public class TeleportManager {
|
||||
});
|
||||
}
|
||||
|
||||
public static void teleportPlayer(Player player, TeleportationPoint point, Connection connection) {
|
||||
// Teleport a player to a location on the server or proxy server network
|
||||
public static void teleportPlayer(Player player, TeleportationPoint point) {
|
||||
final TeleportationPoint destination = new TeleportationPoint(player.getLocation(),
|
||||
HuskHomes.getSettings().getServerID());
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (isEventCancelled(player, destination)) return;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
DataManager.setPlayerLastPosition(player, destination, connection);
|
||||
DataManager.setPlayerDestinationLocation(player, point, connection);
|
||||
teleportPlayer(player);
|
||||
@@ -107,18 +108,18 @@ public class TeleportManager {
|
||||
});
|
||||
}
|
||||
|
||||
public static void queueTimedTeleport(Player player, String targetPlayer, Connection connection) throws SQLException {
|
||||
public static void queueTimedTeleport(Player player, String targetPlayer) {
|
||||
if (player.hasPermission("huskhomes.bypass_timer")) {
|
||||
teleportPlayer(player, targetPlayer, connection);
|
||||
teleportPlayer(player, targetPlayer);
|
||||
return;
|
||||
}
|
||||
|
||||
new TimedTeleport(player, targetPlayer).begin();
|
||||
}
|
||||
|
||||
public static void queueTimedTeleport(Player player, TeleportationPoint point, Connection connection) throws SQLException {
|
||||
public static void queueTimedTeleport(Player player, TeleportationPoint point) {
|
||||
if (player.hasPermission("huskhomes.bypass_timer")) {
|
||||
teleportPlayer(player, point, connection);
|
||||
teleportPlayer(player, point);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -137,7 +138,7 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
MessageManager.sendMessage(player, "teleporting_offline_player", targetPlayer);
|
||||
teleportPlayer(player, offlinePoint, connection);
|
||||
teleportPlayer(player, offlinePoint);
|
||||
}
|
||||
|
||||
public static void queueBackTeleport(Player player, Connection connection) throws SQLException {
|
||||
@@ -161,7 +162,7 @@ public class TeleportManager {
|
||||
MessageManager.sendMessage(player, "back_spent_money", VaultIntegration.format(backCost));
|
||||
}
|
||||
}
|
||||
teleportPlayer(player, lastPosition, connection);
|
||||
teleportPlayer(player, lastPosition);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -207,18 +208,18 @@ public class TeleportManager {
|
||||
MessageManager.sendMessage(player, "rtp_spent_money", VaultIntegration.format(rtpCost));
|
||||
}
|
||||
}
|
||||
teleportPlayer(player, randomPoint, connection);
|
||||
teleportPlayer(player, randomPoint);
|
||||
DataManager.updateRtpCoolDown(player, connection);
|
||||
return;
|
||||
}
|
||||
new TimedTeleport(player).begin();
|
||||
}
|
||||
|
||||
public static void teleportHere(Player requester, String targetPlayerName, Connection connection) throws SQLException {
|
||||
public static void teleportHere(Player requester, String targetPlayerName) throws SQLException {
|
||||
Player targetPlayer = Bukkit.getPlayerExact(targetPlayerName);
|
||||
if (targetPlayer != null) {
|
||||
if (targetPlayer.getUniqueId() != requester.getUniqueId()) {
|
||||
teleportPlayer(targetPlayer, requester.getName(), connection);
|
||||
teleportPlayer(targetPlayer, requester.getName());
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_tp_self");
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class TeleportRequestHandler {
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
// Target player and teleport request(s) to them hashmap
|
||||
public static HashMap<Player, HashMap<String,TeleportRequest>> teleportRequests = new HashMap<>();
|
||||
public static HashMap<Player, HashMap<String, TeleportRequest>> teleportRequests = new HashMap<>();
|
||||
|
||||
private static void sendTeleportRequestCrossServer(Player requester, String targetPlayerName, TeleportRequest.RequestType requestType) {
|
||||
if (requestType == TeleportRequest.RequestType.TPA) {
|
||||
@@ -108,43 +108,39 @@ public class TeleportRequestHandler {
|
||||
Player requester = Bukkit.getPlayer(requesterName);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
if (requester != null) {
|
||||
if (accepted) {
|
||||
MessageManager.sendMessage(p, "tpa_you_accepted", requesterName);
|
||||
MessageManager.sendMessage(requester, "tpa_has_accepted", p.getName());
|
||||
if (requester != null) {
|
||||
if (accepted) {
|
||||
MessageManager.sendMessage(p, "tpa_you_accepted", requesterName);
|
||||
MessageManager.sendMessage(requester, "tpa_has_accepted", p.getName());
|
||||
|
||||
if (requestType == TeleportRequest.RequestType.TPA) {
|
||||
TeleportManager.queueTimedTeleport(requester, p.getName(), connection);
|
||||
} else if (requestType == TeleportRequest.RequestType.TPA_HERE) {
|
||||
TeleportManager.queueTimedTeleport(p, requesterName, connection);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "tpa_you_declined", requesterName);
|
||||
MessageManager.sendMessage(requester, "tpa_has_declined", p.getName());
|
||||
if (requestType == TeleportRequest.RequestType.TPA) {
|
||||
TeleportManager.queueTimedTeleport(requester, p.getName());
|
||||
} else if (requestType == TeleportRequest.RequestType.TPA_HERE) {
|
||||
TeleportManager.queueTimedTeleport(p, requesterName);
|
||||
}
|
||||
} else {
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
if (accepted) {
|
||||
MessageManager.sendMessage(p, "tpa_you_accepted", requesterName);
|
||||
replyTeleportRequestCrossServer(p, requesterName, requestType, true);
|
||||
if (requestType == TeleportRequest.RequestType.TPA_HERE) {
|
||||
TeleportManager.queueTimedTeleport(p, requesterName, connection);
|
||||
}
|
||||
} else {
|
||||
replyTeleportRequestCrossServer(p, requesterName, requestType, false);
|
||||
MessageManager.sendMessage(p, "tpa_you_declined", requesterName);
|
||||
MessageManager.sendMessage(p, "tpa_you_declined", requesterName);
|
||||
MessageManager.sendMessage(requester, "tpa_has_declined", p.getName());
|
||||
}
|
||||
} else {
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
if (accepted) {
|
||||
MessageManager.sendMessage(p, "tpa_you_accepted", requesterName);
|
||||
replyTeleportRequestCrossServer(p, requesterName, requestType, true);
|
||||
if (requestType == TeleportRequest.RequestType.TPA_HERE) {
|
||||
TeleportManager.queueTimedTeleport(p, requesterName);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_player_not_found", requesterName);
|
||||
replyTeleportRequestCrossServer(p, requesterName, requestType, false);
|
||||
MessageManager.sendMessage(p, "tpa_you_declined", requesterName);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_player_not_found", requesterName);
|
||||
}
|
||||
teleportRequests.get(p).remove(teleportRequest.getSenderName());
|
||||
if (teleportRequests.get(p).isEmpty()) {
|
||||
teleportRequests.remove(p);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred!", e);
|
||||
}
|
||||
teleportRequests.get(p).remove(teleportRequest.getSenderName());
|
||||
if (teleportRequests.get(p).isEmpty()) {
|
||||
teleportRequests.remove(p);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -162,7 +158,7 @@ public class TeleportRequestHandler {
|
||||
MessageManager.sendMessage(p, "error_ignoring_teleport_requests");
|
||||
return;
|
||||
}
|
||||
HashMap<String,TeleportRequest> playerRequests = teleportRequests.get(p);
|
||||
HashMap<String, TeleportRequest> playerRequests = teleportRequests.get(p);
|
||||
long firstRequestTime = Long.MAX_VALUE;
|
||||
TeleportRequest targetRequest = null;
|
||||
for (String playerName : playerRequests.keySet()) {
|
||||
@@ -192,7 +188,7 @@ public class TeleportRequestHandler {
|
||||
MessageManager.sendMessage(p, "error_ignoring_teleport_requests");
|
||||
return;
|
||||
}
|
||||
HashMap<String,TeleportRequest> playerRequests = teleportRequests.get(p);
|
||||
HashMap<String, TeleportRequest> playerRequests = teleportRequests.get(p);
|
||||
TeleportRequest targetRequest = null;
|
||||
for (String playerName : playerRequests.keySet()) {
|
||||
TeleportRequest request = playerRequests.get(playerName);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TimedTeleport {
|
||||
}
|
||||
|
||||
public void begin() {
|
||||
final int[] i = {HuskHomes.getSettings().getTeleportWarmupTime()+1};
|
||||
final int[] i = {HuskHomes.getSettings().getTeleportWarmupTime() + 1};
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -88,14 +88,14 @@ public class TimedTeleport {
|
||||
sendWarmupMessage(player, "teleporting_action_bar_cancelled");
|
||||
return;
|
||||
}
|
||||
i[0] = i[0] -1;
|
||||
i[0] = i[0] - 1;
|
||||
if (i[0] == 0) {
|
||||
cancel();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
// Execute the teleport
|
||||
switch (getTargetType()) {
|
||||
case POINT -> TeleportManager.teleportPlayer(player, targetPoint, connection);
|
||||
case POINT -> TeleportManager.teleportPlayer(player, targetPoint);
|
||||
case BACK -> {
|
||||
if (HuskHomes.getSettings().doEconomy()) {
|
||||
double backCost = HuskHomes.getSettings().getBackCost();
|
||||
@@ -108,9 +108,9 @@ public class TimedTeleport {
|
||||
}
|
||||
}
|
||||
}
|
||||
TeleportManager.teleportPlayer(player, getTargetPoint(), connection);
|
||||
TeleportManager.teleportPlayer(player, getTargetPoint());
|
||||
}
|
||||
case PLAYER -> TeleportManager.teleportPlayer(player, getTargetPlayerName(), connection);
|
||||
case PLAYER -> TeleportManager.teleportPlayer(player, getTargetPlayerName());
|
||||
case RANDOM -> {
|
||||
RandomPoint randomPoint = new RandomPoint(player);
|
||||
if (randomPoint.hasFailed()) {
|
||||
@@ -127,7 +127,7 @@ public class TimedTeleport {
|
||||
}
|
||||
}
|
||||
}
|
||||
TeleportManager.teleportPlayer(player, randomPoint, connection);
|
||||
TeleportManager.teleportPlayer(player, randomPoint);
|
||||
DataManager.updateRtpCoolDown(player, connection);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user