mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Bump to v3.1, rewrite Teleport/TimedTeleport and add TeleportBuilder, expose new Teleport API, remove TeleportManager, minor database utility refactoring
This commit is contained in:
1 parent
e7f8298b12
commit
9630e53613
35 files changed
+1070
-881
No files matched your search
@@ -3,6 +3,8 @@ package net.william278.huskhomes.command;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -15,17 +17,11 @@ public class BackCommand extends CommandBase {
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
plugin.getDatabase().getLastPosition(onlineUser).thenAccept(lastPosition ->
|
||||
lastPosition.ifPresentOrElse(position -> {
|
||||
// Validate the /back command economy action and that the user has sufficient funds if needed
|
||||
if (!plugin.validateEconomyCheck(onlineUser, Settings.EconomyAction.BACK_COMMAND)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Teleport the player
|
||||
plugin.getTeleportManager().timedTeleport(onlineUser, position, Settings.EconomyAction.BACK_COMMAND)
|
||||
.thenAccept(result -> plugin.getTeleportManager()
|
||||
.finishTeleport(onlineUser, result, Settings.EconomyAction.BACK_COMMAND));
|
||||
},
|
||||
lastPosition.ifPresentOrElse(position -> Teleport.builder(plugin, onlineUser)
|
||||
.setTarget(position)
|
||||
.setEconomyActions(Settings.EconomyAction.BACK_COMMAND)
|
||||
.toTimedTeleport()
|
||||
.thenApply(TimedTeleport::execute),
|
||||
() -> plugin.getLocales().getLocale("error_no_last_position").ifPresent(onlineUser::sendMessage)));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.player.User;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import net.william278.huskhomes.util.RegexUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,8 +32,9 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
// Send the home list if they have homes set. If they have just one home set, teleport the player
|
||||
switch (homes.size()) {
|
||||
case 0 -> plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage);
|
||||
case 1 -> plugin.getTeleportManager().timedTeleport(onlineUser, homes.get(0)).thenAccept(result ->
|
||||
plugin.getTeleportManager().finishTeleport(onlineUser, result));
|
||||
case 1 -> Teleport.builder(plugin, onlineUser)
|
||||
.setTarget(homes.get(0))
|
||||
.toTimedTeleport().thenAccept(TimedTeleport::execute);
|
||||
default -> plugin.getCache().getHomeList(onlineUser, onlineUser,
|
||||
plugin.getLocales(), homes, plugin.getSettings().listItemsPerPage, 1)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
@@ -42,16 +46,42 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(
|
||||
homeIdentifier -> plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName())
|
||||
.thenAccept(optionalUserData -> optionalUserData.ifPresentOrElse(
|
||||
userData -> plugin.getTeleportManager().teleportToHomeByName(onlineUser, userData.user(), homeIdentifier.homeName()),
|
||||
userData -> teleportToNamedHome(onlineUser, userData.user(), homeIdentifier.homeName()),
|
||||
() -> plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName())
|
||||
.ifPresent(onlineUser::sendMessage))),
|
||||
() -> plugin.getTeleportManager().teleportToHomeByName(onlineUser, onlineUser, homeName));
|
||||
() -> teleportToNamedHome(onlineUser, onlineUser, homeName));
|
||||
}
|
||||
default -> plugin.getLocales().getLocale("error_invalid_syntax", "/home [name]")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
|
||||
final boolean otherHome = owner.uuid.equals(teleporter.uuid);
|
||||
plugin.getDatabase()
|
||||
.getHome(owner, homeName)
|
||||
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
|
||||
if (otherHome && !home.isPublic) {
|
||||
if (!teleporter.hasPermission(Permission.COMMAND_HOME_OTHER.node)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
}
|
||||
}
|
||||
Teleport.builder(plugin, teleporter)
|
||||
.setTarget(home)
|
||||
.toTimedTeleport()
|
||||
.thenAccept(TimedTeleport::execute);
|
||||
}, () -> {
|
||||
if (otherHome) {
|
||||
plugin.getLocales().getLocale("error_home_invalid", homeName)
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName)
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsoleExecute(@NotNull String[] args) {
|
||||
if (args.length != 2) {
|
||||
@@ -80,9 +110,11 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
}
|
||||
|
||||
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to "
|
||||
+ home.owner.username + "." + home.meta.name);
|
||||
plugin.getTeleportManager().teleport(playerToTeleport, home)
|
||||
.thenAccept(result -> plugin.getTeleportManager().finishTeleport(playerToTeleport, result));
|
||||
+ home.owner.username + "." + home.meta.name);
|
||||
Teleport.builder(plugin, playerToTeleport)
|
||||
.setTarget(home)
|
||||
.toTeleport()
|
||||
.thenAccept(Teleport::execute);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.player.User;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import net.william278.huskhomes.util.RegexUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -43,7 +46,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
||||
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(
|
||||
homeIdentifier -> plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName())
|
||||
.thenAccept(optionalUserData -> optionalUserData.ifPresentOrElse(
|
||||
userData -> plugin.getTeleportManager().teleportToHomeByName(onlineUser, userData.user(), homeIdentifier.homeName()),
|
||||
userData -> teleportToNamedHome(onlineUser, userData.user(), homeIdentifier.homeName()),
|
||||
() -> plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName())
|
||||
.ifPresent(onlineUser::sendMessage))),
|
||||
() -> plugin.getDatabase().getPublicHomes().thenAccept(publicHomes -> {
|
||||
@@ -51,7 +54,9 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
||||
final List<Home> homeMatches = publicHomes.stream()
|
||||
.filter(home -> home.meta.name.equalsIgnoreCase(homeName)).toList();
|
||||
if ((long) homeMatches.size() == 1) {
|
||||
plugin.getTeleportManager().teleportToHome(onlineUser, homeMatches.get(0));
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTarget(homeMatches.get(0))
|
||||
.toTimedTeleport().thenAccept(TimedTeleport::execute);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/publichome [<owner_name>.<home_name>]")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
@@ -63,6 +68,32 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
||||
}
|
||||
}
|
||||
|
||||
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
|
||||
final boolean otherHome = owner.uuid.equals(teleporter.uuid);
|
||||
plugin.getDatabase()
|
||||
.getHome(owner, homeName)
|
||||
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
|
||||
if (otherHome && !home.isPublic) {
|
||||
if (!teleporter.hasPermission(Permission.COMMAND_HOME_OTHER.node)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
}
|
||||
}
|
||||
Teleport.builder(plugin, teleporter)
|
||||
.setTarget(home)
|
||||
.toTimedTeleport()
|
||||
.thenAccept(TimedTeleport::execute);
|
||||
}, () -> {
|
||||
if (otherHome) {
|
||||
plugin.getLocales().getLocale("error_home_invalid", homeName)
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName)
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsoleExecute(@NotNull String[] args) {
|
||||
if (args.length != 2) {
|
||||
@@ -93,9 +124,11 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
||||
}
|
||||
|
||||
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to "
|
||||
+ home.owner.username + "." + home.meta.name);
|
||||
plugin.getTeleportManager().teleport(playerToTeleport, home)
|
||||
.thenAccept(result -> plugin.getTeleportManager().finishTeleport(playerToTeleport, result));
|
||||
+ home.owner.username + "." + home.meta.name);
|
||||
Teleport.builder(plugin, playerToTeleport)
|
||||
.setTarget(home)
|
||||
.toTeleport()
|
||||
.thenAccept(Teleport::execute);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.player.UserData;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.TeleportResult;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TeleportBuilder;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -76,19 +77,21 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
||||
return;
|
||||
}
|
||||
|
||||
final CompletableFuture<TeleportResult> randomTeleport = isExecutorTeleporting ? plugin.getTeleportManager()
|
||||
.timedTeleport(userToTeleport, position.get(), Settings.EconomyAction.RANDOM_TELEPORT)
|
||||
: plugin.getTeleportManager().teleport(userToTeleport, position.get());
|
||||
randomTeleport.thenAccept(result -> {
|
||||
if (isExecutorTeleporting &&
|
||||
result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
|
||||
plugin.getDatabase().updateUserData(new UserData(onlineUser,
|
||||
userData.get().homeSlots(), userData.get().ignoringTeleports(),
|
||||
Instant.now().plus(plugin.getSettings().rtpCooldownLength, ChronoUnit.MINUTES)));
|
||||
}
|
||||
plugin.getTeleportManager().finishTeleport(userToTeleport, result,
|
||||
Settings.EconomyAction.RANDOM_TELEPORT);
|
||||
});
|
||||
final TeleportBuilder builder = Teleport.builder(plugin, userToTeleport)
|
||||
.setTarget(position.get());
|
||||
final CompletableFuture<? extends Teleport> teleportFuture = isExecutorTeleporting
|
||||
? builder.setEconomyActions(Settings.EconomyAction.RANDOM_TELEPORT).toTimedTeleport()
|
||||
: builder.toTeleport();
|
||||
|
||||
teleportFuture.thenAccept(teleport -> teleport.execute()
|
||||
.thenAccept(result -> {
|
||||
if (isExecutorTeleporting &&
|
||||
result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
|
||||
plugin.getDatabase().updateUserData(new UserData(onlineUser,
|
||||
userData.get().homeSlots(), userData.get().ignoringTeleports(),
|
||||
Instant.now().plus(plugin.getSettings().rtpCooldownLength, ChronoUnit.MINUTES)));
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -111,15 +114,16 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
||||
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + foundUser.get().username + " to a random position; randomization timed out!");
|
||||
return;
|
||||
}
|
||||
plugin.getTeleportManager().teleport(foundUser.get(), position.get())
|
||||
.thenAccept(result -> {
|
||||
Teleport.builder(plugin, foundUser.get())
|
||||
.setTarget(position.get())
|
||||
.toTeleport()
|
||||
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
|
||||
if (result.successful) {
|
||||
plugin.getLoggingAdapter().log(Level.INFO, "Teleported " + foundUser.get().username + " to a random position.");
|
||||
} else {
|
||||
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport" + foundUser.get().username + " to a random position.");
|
||||
}
|
||||
plugin.getTeleportManager().finishTeleport(foundUser.get(), result);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -25,7 +27,9 @@ public class SpawnCommand extends CommandBase {
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getTeleportManager().timedTeleport(onlineUser, position.get());
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTarget(position.get())
|
||||
.toTimedTeleport().thenAccept(TimedTeleport::execute);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -35,8 +37,12 @@ public class TpAllCommand extends CommandBase {
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
|
||||
// Teleport every player
|
||||
players.forEach(playerName -> plugin.getTeleportManager()
|
||||
.teleportPlayerByName(playerName, onlineUser.getPosition(), onlineUser, false));
|
||||
final Position targetPosition = onlineUser.getPosition();
|
||||
players.forEach(playerName -> Teleport.builder(plugin, onlineUser)
|
||||
.setTeleporter(playerName)
|
||||
.setTarget(targetPosition)
|
||||
.toTeleport()
|
||||
.thenAccept(Teleport::execute));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.Server;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TeleportBuilder;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -61,21 +63,21 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
||||
|
||||
// Execute the teleport
|
||||
if (teleportTarget.get() instanceof TargetPlayer targetPlayer) {
|
||||
// Handle player teleport targets
|
||||
plugin.getTeleportManager()
|
||||
.teleportNamedPlayers(playerToTeleport, targetPlayer.playerName, onlineUser, false)
|
||||
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
|
||||
result -> {
|
||||
if (!result.successful) {
|
||||
plugin.getTeleportManager().finishTeleport(onlineUser, result);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("teleporting_other_complete",
|
||||
playerToTeleport, targetPlayer.playerName)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
},
|
||||
() -> plugin.getLocales().getLocale("error_player_not_found", targetPlayer.playerName)
|
||||
.ifPresent(onlineUser::sendMessage)));
|
||||
// Carry out the teleport to a player, by name
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTeleporter(playerToTeleport)
|
||||
.setTarget(targetPlayer.playerName)
|
||||
.toTeleport()
|
||||
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
|
||||
if (result.successful) {
|
||||
plugin.getLocales().getLocale("teleporting_other_complete",
|
||||
playerToTeleport, targetPlayer.playerName)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_player_not_found", targetPlayer.playerName)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
}));
|
||||
} else if (teleportTarget.get() instanceof TargetPosition targetPosition) {
|
||||
// Handle coordinate teleport targets
|
||||
if (!onlineUser.hasPermission(Permission.COMMAND_TP_TO_COORDINATES.node)) {
|
||||
@@ -83,21 +85,22 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getTeleportManager()
|
||||
.teleportPlayerByName(playerToTeleport, targetPosition.position, onlineUser, false)
|
||||
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresent(
|
||||
result -> {
|
||||
if (!result.successful || playerToTeleport.equalsIgnoreCase(onlineUser.username)) {
|
||||
plugin.getTeleportManager().finishTeleport(onlineUser, result);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("teleporting_other_complete_position",
|
||||
playerToTeleport,
|
||||
Integer.toString((int) targetPosition.position.x),
|
||||
Integer.toString((int) targetPosition.position.y),
|
||||
Integer.toString((int) targetPosition.position.z))
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}));
|
||||
// Carry out the teleport to a position
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTeleporter(playerToTeleport)
|
||||
.setTarget(targetPosition.position)
|
||||
.toTeleport()
|
||||
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
|
||||
if (!result.successful || playerToTeleport.equalsIgnoreCase(onlineUser.username)) {
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("teleporting_other_complete_position",
|
||||
playerToTeleport,
|
||||
Integer.toString((int) targetPosition.position.x),
|
||||
Integer.toString((int) targetPosition.position.y),
|
||||
Integer.toString((int) targetPosition.position.z))
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -176,23 +179,20 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
||||
}
|
||||
|
||||
// Execute the console teleport
|
||||
final TeleportBuilder builder = Teleport.builder(plugin, playerToTeleport)
|
||||
.setTeleporter(playerToTeleport.username);
|
||||
if (teleportTarget instanceof TargetPlayer targetPlayer) {
|
||||
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username
|
||||
+ " to " + targetPlayer.playerName);
|
||||
plugin.getTeleportManager().teleportToPlayerByName(playerToTeleport, targetPlayer.playerName, false);
|
||||
builder.setTarget(targetPlayer.playerName);
|
||||
} else {
|
||||
final TargetPosition targetPosition = (TargetPosition) teleportTarget;
|
||||
plugin.getTeleportManager().teleport(playerToTeleport, targetPosition.position)
|
||||
.thenAccept(teleportResult -> {
|
||||
if (teleportResult.successful) {
|
||||
plugin.getLoggingAdapter().log(Level.INFO, "Successfully teleported " + playerToTeleport.username);
|
||||
} else {
|
||||
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + playerToTeleport.username
|
||||
+ " (" + teleportResult.name() + ")");
|
||||
}
|
||||
plugin.getTeleportManager().finishTeleport(playerToTeleport, teleportResult);
|
||||
});
|
||||
builder.setTarget(((TargetPosition) teleportTarget).position);
|
||||
}
|
||||
builder.toTeleport().thenAccept(teleport -> teleport.execute().thenAccept(result -> {
|
||||
if (result.successful) {
|
||||
plugin.getLoggingAdapter().log(Level.INFO, "Successfully teleported " + playerToTeleport.username);
|
||||
} else {
|
||||
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + playerToTeleport.username + " to " + teleportTarget);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -26,19 +27,17 @@ public class TpHereCommand extends CommandBase implements TabCompletable {
|
||||
return;
|
||||
}
|
||||
final String targetPlayerName = args[0];
|
||||
plugin.getTeleportManager().teleportPlayerByName(targetPlayerName, onlineUser.getPosition(), onlineUser, false)
|
||||
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
|
||||
result -> {
|
||||
if (result.successful) {
|
||||
plugin.getLocales().getLocale("teleporting_other_complete",
|
||||
targetPlayerName, onlineUser.username)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getTeleportManager().finishTeleport(onlineUser, result);
|
||||
},
|
||||
() -> plugin.getLocales().getLocale("error_player_not_found", targetPlayerName)
|
||||
.ifPresent(onlineUser::sendMessage)));
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTeleporter(targetPlayerName)
|
||||
.setTarget(onlineUser.getPosition())
|
||||
.toTeleport()
|
||||
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
|
||||
if (result.successful) {
|
||||
plugin.getLocales().getLocale("teleporting_other_complete",
|
||||
targetPlayerName, onlineUser.username)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -38,8 +39,15 @@ public class TpOfflineCommand extends CommandBase implements TabCompletable {
|
||||
}
|
||||
plugin.getLocales().getLocale("teleporting_offline_player", targetUser)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
plugin.getTeleportManager().teleport(onlineUser, offlinePosition.get()).thenAccept(
|
||||
result -> plugin.getTeleportManager().finishTeleport(onlineUser, result));
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTarget(offlinePosition.get())
|
||||
.toTeleport()
|
||||
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
|
||||
if (result.successful) {
|
||||
plugin.getLocales().getLocale("teleporting_offline_complete", targetUser)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,20 +20,22 @@ public class TpaCommand extends CommandBase implements TabCompletable {
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
plugin.getRequestManager().sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA).thenAccept(sent -> {
|
||||
if (sent.isPresent()) {
|
||||
plugin.getLocales().getLocale("tpa_request_sent", sent.get().getRecipientName())
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
} else {
|
||||
if (plugin.findPlayer(args[0]).isPresent()) {
|
||||
plugin.getLocales().getLocale("error_teleport_request_self")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("error_player_not_found", args[0])
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
});
|
||||
plugin.getRequestManager()
|
||||
.sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA)
|
||||
.thenAccept(sent -> {
|
||||
if (sent.isPresent()) {
|
||||
plugin.getLocales().getLocale("tpa_request_sent", sent.get().getRecipientName())
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
} else {
|
||||
if (plugin.findPlayer(args[0]).isPresent()) {
|
||||
plugin.getLocales().getLocale("error_teleport_request_self")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("error_player_not_found", args[0])
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/tpa <player>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
|
||||
@@ -20,20 +20,22 @@ public class TpaHereCommand extends CommandBase implements TabCompletable {
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
plugin.getRequestManager().sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA_HERE).thenAccept(sent -> {
|
||||
if (sent.isEmpty()) {
|
||||
if (plugin.findPlayer(args[0]).isPresent()) {
|
||||
plugin.getLocales().getLocale("error_teleport_request_self")
|
||||
plugin.getRequestManager()
|
||||
.sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA_HERE)
|
||||
.thenAccept(sent -> {
|
||||
if (sent.isEmpty()) {
|
||||
if (plugin.findPlayer(args[0]).isPresent()) {
|
||||
plugin.getLocales().getLocale("error_teleport_request_self")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("error_player_not_found", args[0])
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("tpahere_request_sent", sent.get().getRecipientName())
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("error_player_not_found", args[0])
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("tpahere_request_sent", sent.get().getRecipientName())
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/tpahere <player>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
|
||||
@@ -3,12 +3,13 @@ package net.william278.huskhomes.command;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -33,7 +34,15 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
});
|
||||
case 1 -> {
|
||||
final String warpName = args[0];
|
||||
plugin.getTeleportManager().teleportToWarpByName(onlineUser, warpName);
|
||||
plugin.getDatabase()
|
||||
.getWarp(warpName)
|
||||
.thenAccept(warpResult -> warpResult.ifPresentOrElse(warp ->
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTarget(warp)
|
||||
.toTimedTeleport()
|
||||
.thenAccept(TimedTeleport::execute),
|
||||
() -> plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||
.ifPresent(onlineUser::sendMessage)));
|
||||
}
|
||||
default -> plugin.getLocales().getLocale("error_invalid_syntax", "/warp [name]")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
@@ -68,9 +77,10 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
final Warp warp = optionalWarp.get();
|
||||
|
||||
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to " + warp.meta.name);
|
||||
plugin.getTeleportManager()
|
||||
.teleport(playerToTeleport, warp)
|
||||
.thenAccept(result -> plugin.getTeleportManager().finishTeleport(playerToTeleport, result));
|
||||
Teleport.builder(plugin, playerToTeleport)
|
||||
.setTarget(warp)
|
||||
.toTimedTeleport()
|
||||
.thenAccept(TimedTeleport::execute);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user