mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Finish cross-server respawning, close #123
This commit is contained in:
1 parent
f0d9807ee4
commit
713bf2ea42
12 files changed
+70
-51
No files matched your search
@@ -135,14 +135,14 @@ public interface HuskHomes {
|
||||
*
|
||||
* @return the {@link Spawn} location data
|
||||
*/
|
||||
Optional<Spawn> getSpawn();
|
||||
Optional<Spawn> getServerSpawn();
|
||||
|
||||
/**
|
||||
* Update the {@link Spawn} position to a location on the server
|
||||
*
|
||||
* @param location the new {@link Spawn} location
|
||||
*/
|
||||
void setSpawn(@NotNull Location location);
|
||||
void setServerSpawn(@NotNull Location location);
|
||||
|
||||
/**
|
||||
* Set of active {@link PluginHook}s running on the server
|
||||
|
||||
@@ -34,7 +34,7 @@ public class SetSpawnCommand extends CommandBase {
|
||||
.orElse("")), position).join();
|
||||
}
|
||||
} else {
|
||||
plugin.setSpawn(position);
|
||||
plugin.setServerSpawn(position);
|
||||
}
|
||||
}).thenRun(() -> plugin.getLocales().getLocale("set_spawn_success").ifPresent(onlineUser::sendMessage));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class SpawnCommand extends CommandBase {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
final Optional<? extends Position> position = (plugin.getSettings().crossServer && plugin.getSettings().globalSpawn
|
||||
? plugin.getDatabase().getWarp(plugin.getSettings().globalSpawnName).join()
|
||||
: plugin.getSpawn().flatMap(spawn -> spawn.getLocation(plugin.getServer(onlineUser).join())));
|
||||
: plugin.getServerSpawn().flatMap(spawn -> spawn.getLocation(plugin.getServer(onlineUser).join())));
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_spawn_not_set").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
|
||||
@@ -146,7 +146,7 @@ public class Settings {
|
||||
@KeyPath("cross_server.global_spawn.warp_name")
|
||||
public String globalSpawnName = "Spawn";
|
||||
|
||||
@KeyPath("cross_server_global_respawning")
|
||||
@KeyPath("cross_server.global_respawning")
|
||||
public boolean globalRespawning = false;
|
||||
|
||||
@KeyPath("cross_server.redis_credentials.host")
|
||||
@@ -195,9 +195,9 @@ public class Settings {
|
||||
@KeyPath("economy.costs")
|
||||
public Map<String, Double> economyCosts = Map.of(
|
||||
EconomyAction.ADDITIONAL_HOME_SLOT.name().toLowerCase(), EconomyAction.ADDITIONAL_HOME_SLOT.defaultCost,
|
||||
EconomyAction.MAKE_HOME_PUBLIC.name(), EconomyAction.MAKE_HOME_PUBLIC.defaultCost,
|
||||
EconomyAction.MAKE_HOME_PUBLIC.name().toLowerCase(), EconomyAction.MAKE_HOME_PUBLIC.defaultCost,
|
||||
EconomyAction.RANDOM_TELEPORT.name().toLowerCase(), EconomyAction.RANDOM_TELEPORT.defaultCost,
|
||||
EconomyAction.BACK_COMMAND.name(), EconomyAction.BACK_COMMAND.defaultCost
|
||||
EconomyAction.BACK_COMMAND.name().toLowerCase(), EconomyAction.BACK_COMMAND.defaultCost
|
||||
);
|
||||
|
||||
public Optional<Double> getEconomyCost(@NotNull EconomyAction action) {
|
||||
|
||||
@@ -566,7 +566,7 @@ public class MySqlDatabase extends Database {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (Connection connection = getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||
SELECT `x`, `y`, `z`, `yaw`, `pitch`, `world_name`, `world_uuid`, `server_name`
|
||||
SELECT `x`, `y`, `z`, `yaw`, `pitch`, `world_name`, `world_uuid`, `server_name`, `type`
|
||||
FROM `%teleports_table%`
|
||||
INNER JOIN `%positions_table%` ON `%teleports_table%`.`destination_id` = `%positions_table%`.`id`
|
||||
WHERE `player_uuid`=?"""))) {
|
||||
@@ -637,10 +637,11 @@ public class MySqlDatabase extends Database {
|
||||
if (teleport != null) {
|
||||
try (Connection connection = getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||
INSERT INTO `%teleports_table%` (`player_uuid`, `destination_id`)
|
||||
VALUES (?,?);"""))) {
|
||||
INSERT INTO `%teleports_table%` (`player_uuid`, `destination_id`, `type`)
|
||||
VALUES (?,?,?);"""))) {
|
||||
statement.setString(1, user.uuid.toString());
|
||||
statement.setInt(2, setPosition(teleport.target, connection));
|
||||
statement.setInt(3, teleport.type.typeId);
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
@@ -649,10 +649,11 @@ public class SqLiteDatabase extends Database {
|
||||
if (teleport != null) {
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
INSERT INTO `%teleports_table%` (`player_uuid`, `destination_id`)
|
||||
VALUES (?,?);"""))) {
|
||||
INSERT INTO `%teleports_table%` (`player_uuid`, `destination_id`, `type`)
|
||||
VALUES (?,?,?);"""))) {
|
||||
statement.setString(1, user.uuid.toString());
|
||||
statement.setInt(2, setPosition(teleport.target, connection));
|
||||
statement.setInt(3, teleport.type.typeId);
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
@@ -53,18 +53,20 @@ public class EventListener {
|
||||
plugin.getDatabase().ensureUser(onlineUser).thenRun(() -> {
|
||||
// If the server is in proxy mode, check if the player is teleporting cross-server and handle
|
||||
if (plugin.getSettings().crossServer) {
|
||||
plugin.getDatabase().getCurrentTeleport(onlineUser)
|
||||
.thenAccept(teleport -> teleport.ifPresent(activeTeleport -> {
|
||||
// Handle respawn
|
||||
plugin.getDatabase().getCurrentTeleport(onlineUser).thenAccept(teleport -> teleport.ifPresent(activeTeleport -> {
|
||||
// Handle cross-server respawn
|
||||
if (activeTeleport.type == TeleportType.RESPAWN) {
|
||||
final Optional<Position> bedPosition = onlineUser.getBedSpawnPosition().join();
|
||||
if (bedPosition.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_respawn_invalid")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
plugin.getDatabase().setRespawnPosition(onlineUser, null).join();
|
||||
return;
|
||||
plugin.getServerSpawn().flatMap(spawn -> spawn.getLocation(plugin.getServer(onlineUser).join()))
|
||||
.ifPresent(onlineUser::teleport);
|
||||
onlineUser.sendMinecraftMessage("block.minecraft.spawn.not_valid");
|
||||
} else {
|
||||
onlineUser.teleport(bedPosition.get()).join();
|
||||
}
|
||||
onlineUser.teleport(bedPosition.get()).join();
|
||||
plugin.getDatabase().setCurrentTeleport(onlineUser, null).thenRun(() ->
|
||||
plugin.getDatabase().setRespawnPosition(onlineUser, bedPosition.orElse(null))
|
||||
.join()).join();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -156,20 +158,20 @@ public class EventListener {
|
||||
* @param onlineUser the respawning {@link OnlineUser}
|
||||
*/
|
||||
protected final void handlePlayerRespawn(@NotNull OnlineUser onlineUser) {
|
||||
// Display the return by death via /back notification
|
||||
if (plugin.getSettings().backCommandReturnByDeath && onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
|
||||
plugin.getLocales().getLocale("return_by_death_notification")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
|
||||
// Respawn the player cross-server if needed
|
||||
if (plugin.getSettings().crossServer && plugin.getSettings().globalRespawning) {
|
||||
plugin.getDatabase().getRespawnPosition(onlineUser).thenAccept(position -> {
|
||||
position.ifPresent(respawnPosition -> {
|
||||
if (!respawnPosition.server.equals(plugin.getServer(onlineUser).join())) {
|
||||
plugin.getTeleportManager().teleport(onlineUser, respawnPosition).thenAccept(
|
||||
result -> plugin.getTeleportManager().finishTeleport(onlineUser, result));
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if (plugin.getSettings().backCommandReturnByDeath && onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
|
||||
plugin.getLocales().getLocale("back_return_by_death")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
plugin.getDatabase().getRespawnPosition(onlineUser).thenAccept(position -> position.ifPresent(respawnPosition -> {
|
||||
if (!respawnPosition.server.equals(plugin.getServer(onlineUser).join())) {
|
||||
plugin.getTeleportManager().teleport(onlineUser, respawnPosition, TeleportType.RESPAWN).thenAccept(
|
||||
result -> plugin.getTeleportManager().finishTeleport(onlineUser, result));
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +183,7 @@ public class EventListener {
|
||||
*/
|
||||
protected final void handlePlayerUpdateSpawnPoint(@NotNull OnlineUser onlineUser, @NotNull Position position) {
|
||||
if (plugin.getSettings().crossServer && plugin.getSettings().globalRespawning) {
|
||||
plugin.getDatabase().setRespawnPosition(onlineUser, position);
|
||||
plugin.getDatabase().setRespawnPosition(onlineUser, position).join();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,13 @@ public abstract class OnlineUser extends User {
|
||||
*/
|
||||
public abstract void sendMessage(@NotNull MineDown mineDown);
|
||||
|
||||
/**
|
||||
* Dispatch a Minecraft translatable keyed-message to this player
|
||||
*
|
||||
* @param translationKey the translation key of the message to send
|
||||
*/
|
||||
public abstract void sendMinecraftMessage(@NotNull String translationKey);
|
||||
|
||||
/**
|
||||
* Teleport a player to the specified {@link Location}
|
||||
*
|
||||
@@ -168,6 +175,4 @@ public abstract class OnlineUser extends User {
|
||||
.map(permission -> Integer.parseInt(permission.getKey().substring(nodePrefix.length())))
|
||||
.sorted().toList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user