Add additional teleport execution handling

This commit is contained in:
William committed 2023-03-24 01:20:33 +00:00
1 parent 9c6ed329d5
commit 88f34ac133
8 files changed
+87 -40

No files matched your search

@@ -9,6 +9,7 @@ import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.random.RandomTeleportEngine;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportBuilder;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.SavedUser;
import net.william278.huskhomes.user.User;
@@ -560,10 +561,14 @@ public abstract class BaseHuskHomesAPI {
final TeleportBuilder builder = Teleport.builder(plugin)
.teleporter(user)
.target(position.get());
if (timedTeleport) {
builder.toTimedTeleport().execute();
} else {
builder.toTeleport().execute();
try {
if (timedTeleport) {
builder.toTimedTeleport().execute();
} else {
builder.toTeleport().execute();
}
} catch (TeleportationException e) {
e.displayMessage(user, plugin, rtpArgs);
}
});
}
@@ -4,6 +4,7 @@ import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.hook.EconomyHook;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
@@ -25,12 +26,16 @@ public class BackCommand extends InGameCommand {
return;
}
Teleport.builder(plugin)
.teleporter(executor)
.target(lastPosition.get())
.economyActions(EconomyHook.Action.BACK_COMMAND)
.toTimedTeleport()
.execute();
try {
Teleport.builder(plugin)
.teleporter(executor)
.target(lastPosition.get())
.economyActions(EconomyHook.Action.BACK_COMMAND)
.toTimedTeleport()
.execute();
} catch (TeleportationException e) {
e.displayMessage(executor, plugin, args);
}
}
}
@@ -5,7 +5,9 @@ import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.SavedPosition;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportBuilder;
import net.william278.huskhomes.teleport.Teleportable;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.CommandUser;
import net.william278.huskhomes.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
@@ -109,11 +111,18 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
return;
}
Teleport.builder(plugin)
final TeleportBuilder builder = Teleport.builder(plugin)
.teleporter(teleporter)
.target(position)
.toTimedTeleport()
.execute();
.target(position);
try {
if (executor.equals(teleporter)) {
builder.toTimedTeleport().execute();
} else {
builder.toTeleport().execute();
}
} catch (TeleportationException e) {
e.displayMessage(executor, plugin, new String[0]);
}
}
@Override
@@ -5,6 +5,7 @@ import net.william278.huskhomes.network.Message;
import net.william278.huskhomes.network.Payload;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
@@ -20,11 +21,16 @@ public class TpAllCommand extends InGameCommand {
@Override
public void execute(@NotNull OnlineUser executor, @NotNull String[] args) {
final Position targetPosition = executor.getPosition();
for (OnlineUser user : plugin.getOnlineUsers()) {
Teleport.builder(plugin)
.teleporter(user)
.target(targetPosition)
.toTeleport().execute();
try {
for (OnlineUser user : plugin.getOnlineUsers()) {
Teleport.builder(plugin)
.teleporter(user)
.target(targetPosition)
.toTeleport().execute();
}
} catch (TeleportationException e) {
e.displayMessage(executor, plugin, args);
return;
}
if (plugin.getSettings().isCrossServer()) {
@@ -65,10 +65,10 @@ public class TpCommand extends Command implements TabProvider {
// Execute a teleport
private void execute(@NotNull CommandUser executor, @NotNull Teleportable teleportable, @NotNull Target target,
@NotNull String[] args) {
final TeleportBuilder builder = Teleport.builder(plugin)
.teleporter(teleportable)
.target(target);
try {
final TeleportBuilder builder = Teleport.builder(plugin)
.teleporter(teleportable)
.target(target);
if (executor instanceof OnlineUser user) {
builder.executor(user);
}
@@ -9,6 +9,7 @@ import net.william278.huskhomes.network.Message;
import net.william278.huskhomes.network.Payload;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
@@ -82,11 +83,17 @@ public class EventListener {
if (bedPosition.isEmpty()) {
plugin.getSpawn().ifPresent(spawn -> {
if (plugin.getSettings().isCrossServer() && !spawn.getServer().equals(plugin.getServerName())) {
plugin.runLater(() -> Teleport.builder(plugin)
.teleporter(teleporter)
.target(spawn)
.updateLastPosition(false)
.toTeleport().execute(), 40L);
plugin.runLater(() -> {
try {
Teleport.builder(plugin)
.teleporter(teleporter)
.target(spawn)
.updateLastPosition(false)
.toTeleport().execute();
} catch (TeleportationException e) {
e.displayMessage(teleporter, plugin, new String[0]);
}
}, 40L);
} else {
teleporter.teleportLocally(spawn, plugin.getSettings().doAsynchronousTeleports());
}
@@ -6,6 +6,7 @@ import net.william278.huskhomes.network.Payload;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportBuilder;
import net.william278.huskhomes.teleport.TeleportRequest;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.User;
import org.jetbrains.annotations.NotNull;
@@ -251,8 +252,7 @@ public class RequestsManager {
* @param recipient The recipient of the request
* @param accepted Whether the request should be accepted or not
*/
private void handleRequestResponse(@NotNull TeleportRequest request, @NotNull OnlineUser recipient,
boolean accepted) {
private void handleRequestResponse(@NotNull TeleportRequest request, @NotNull OnlineUser recipient, boolean accepted) {
// Remove the request(s) from the sender from the recipient's queue
removeTeleportRequest(request.getRequesterName(), recipient);
@@ -297,7 +297,11 @@ public class RequestsManager {
builder.target(request.getRequesterName());
}
builder.toTimedTeleport().execute();
try {
builder.toTimedTeleport().execute();
} catch (TeleportationException e) {
e.displayMessage(recipient, plugin, new String[0]);
}
}
}
@@ -315,11 +319,15 @@ public class RequestsManager {
// If the request is a tpa request, teleport the requester to the recipient
if (accepted && (request.getType() == TeleportRequest.Type.TPA)) {
Teleport.builder(plugin)
.teleporter(requester)
.target(request.getRecipientName())
.toTimedTeleport()
.execute();
try {
Teleport.builder(plugin)
.teleporter(requester)
.target(request.getRecipientName())
.toTimedTeleport()
.execute();
} catch (TeleportationException e) {
e.displayMessage(requester, plugin, new String[0]);
}
}
}
@@ -4,6 +4,7 @@ import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
@@ -35,11 +36,17 @@ public abstract class Broker {
}
switch (message.getType()) {
case TELEPORT_TO_POSITION -> message.getPayload()
.getPosition().ifPresent(position -> Teleport.builder(plugin)
.teleporter(receiver)
.target(position)
.toTeleport()
.execute());
.getPosition().ifPresent(position -> {
try {
Teleport.builder(plugin)
.teleporter(receiver)
.target(position)
.toTeleport()
.execute();
} catch (TeleportationException e) {
e.displayMessage(plugin.getConsole(), plugin, new String[]{});
}
});
case TELEPORT_TO_NETWORKED_POSITION -> Message.builder()
.type(Message.Type.TELEPORT_TO_POSITION)
.target(message.getSender())