Skip to content

Commit 2425f1e

Browse files
theShadowsDustTheMeinerLP
authored andcommitted
Make teleportation async and add a message if the teleport failed
1 parent a1c0a4f commit 2425f1e

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

src/main/java/de/theshadowsdust/ultimatespawn/command/SpawnCommand.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package de.theshadowsdust.ultimatespawn.command;
22

3-
import cloud.commandframework.annotations.Argument;
4-
import cloud.commandframework.annotations.CommandDescription;
5-
import cloud.commandframework.annotations.CommandMethod;
6-
import cloud.commandframework.annotations.CommandPermission;
7-
import cloud.commandframework.annotations.specifier.Greedy;
8-
import cloud.commandframework.annotations.suggestions.Suggestions;
9-
import cloud.commandframework.context.CommandContext;
3+
import de.theshadowsdust.ultimatespawn.UltimateSpawnPlugin;
104
import de.theshadowsdust.ultimatespawn.position.SpawnPosition;
115
import de.theshadowsdust.ultimatespawn.position.WrappedLocation;
126
import de.theshadowsdust.ultimatespawn.service.LanguageService;
13-
import de.theshadowsdust.ultimatespawn.UltimateSpawnPlugin;
147
import org.bukkit.Location;
158
import org.bukkit.command.CommandSender;
169
import org.bukkit.entity.Player;
1710
import org.bukkit.util.StringUtil;
11+
import org.incendo.cloud.annotation.specifier.Greedy;
12+
import org.incendo.cloud.annotations.Argument;
13+
import org.incendo.cloud.annotations.Command;
14+
import org.incendo.cloud.annotations.CommandDescription;
15+
import org.incendo.cloud.annotations.Permission;
16+
import org.incendo.cloud.annotations.suggestion.Suggestions;
17+
import org.incendo.cloud.context.CommandContext;
1818
import org.jetbrains.annotations.NotNull;
1919

2020
import java.util.ArrayList;
@@ -32,8 +32,8 @@ public SpawnCommand(@NotNull UltimateSpawnPlugin plugin) {
3232
this.languageService = plugin.getLanguageService();
3333
}
3434

35-
@CommandMethod("spawn [name]")
36-
@CommandPermission("ultimatespawn.command.spawn")
35+
@Command("spawn [name]")
36+
@Permission("ultimatespawn.command.spawn")
3737
@CommandDescription("Teleport to the spawn")
3838
public void executeSpawnCommand(Player player, final @Argument(value = "name", suggestions = "spawn_names") @Greedy String name) {
3939

@@ -53,8 +53,16 @@ public void executeSpawnCommand(Player player, final @Argument(value = "name", s
5353
return;
5454
}
5555

56-
player.teleport(location);
57-
player.sendMessage(this.languageService.getMessage("spawn-teleport-success", this.languageService.getPluginPrefix()));
56+
player.teleportAsync(location).thenAccept(success -> {
57+
if(Boolean.TRUE.equals(success)) {
58+
player.sendMessage(this.languageService.getMessage("spawn-teleport-success",
59+
this.languageService.getPluginPrefix()));
60+
} else {
61+
player.sendMessage(this.languageService.getMessage("spawn-teleport-failure",
62+
this.languageService.getPluginPrefix()));
63+
}
64+
});
65+
5866
} catch (ExecutionException | InterruptedException e) {
5967
this.plugin.getLogger().log(Level.SEVERE, "Something went wrong on teleportation", e);
6068
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)