-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldSubCommand.java
More file actions
55 lines (51 loc) · 1.93 KB
/
Copy pathWorldSubCommand.java
File metadata and controls
55 lines (51 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dev.plex.command.sub;
import dev.plex.Guilds;
import dev.plex.command.source.RequiredCommandSource;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class WorldSubCommand extends GuildSubCommand
{
public WorldSubCommand()
{
super(command("world")
.description("Teleports to your guild world")
.usage("/guild <command>")
.aliases("base")
.permission("plex.guilds.world")
.source(RequiredCommandSource.IN_GAME)
.build());
}
@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild ->
{
send(player, messageComponent("guildWorldLoading"));
Guilds.get().getGuildWorldService().ensureWorld(guild).whenComplete((world, throwable) ->
{
if (throwable != null)
{
Guilds.get().api().scheduler().executeGlobal(() ->
{
throwable.printStackTrace();
send(player, messageComponent("guildWorldLoadFailed"));
});
return;
}
Guilds.get().api().scheduler().executeEntity(player, () -> teleport(player, world), 1L);
});
}, () -> send(player, messageComponent("guildNotFound")));
return null;
}
private void teleport(Player player, World world)
{
Location spawnLocation = world.getSpawnLocation().toCenterLocation();
player.teleportAsync(spawnLocation);
}
}