From 69cd686d040f21a90893ecb3fd01ba7b63c915bd Mon Sep 17 00:00:00 2001
From: Stijn <38841986+Teriuihi@users.noreply.github.com>
Date: Sun, 18 Feb 2024 23:26:49 +0100
Subject: [PATCH] Implement teleportation to island in 'VisitRequest' accept
method (#9)
Fixed the accept function in the 'VisitRequest' class by adding teleportation to the island of the target. Additionally, validation checks for this were added. Specifically, it now verifies the existence of both the player and the requested island before carrying out the teleportation command.
---
.../alttd/cometskyblock/request/VisitRequest.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/plugin/src/main/java/com/alttd/cometskyblock/request/VisitRequest.java b/plugin/src/main/java/com/alttd/cometskyblock/request/VisitRequest.java
index ed431af..8f40239 100644
--- a/plugin/src/main/java/com/alttd/cometskyblock/request/VisitRequest.java
+++ b/plugin/src/main/java/com/alttd/cometskyblock/request/VisitRequest.java
@@ -1,7 +1,9 @@
package com.alttd.cometskyblock.request;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
+import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.IslandPlayer;
+import org.bukkit.World;
import org.bukkit.entity.Player;
public class VisitRequest extends Request {
@@ -26,7 +28,18 @@ public class VisitRequest extends Request {
return;
}
target().sendRichMessage(requests().visit().targetAccept(), placeholders());
+ IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(target().getUniqueId());
+ if (islandPlayer == null) {
+ requester().sendRichMessage("You requested a teleport to a player who does not exist");
+ return;
+ }
+ Island island = Island.getIsland(islandPlayer.islandUUID());
+ if (island == null) {
+ requester().sendRichMessage("The player who's island you requested to teleport to does not have an island");
+ return;
+ }
requester().sendRichMessage(requests().visit().requesterAccept(), placeholders());
+ requester().teleportAsync(plugin.worldGenerator().loadIslandWorld(island.worldName()).getSpawnLocation());
super.accept();
}