-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateSubCommand.java
More file actions
60 lines (56 loc) · 2.05 KB
/
Copy pathCreateSubCommand.java
File metadata and controls
60 lines (56 loc) · 2.05 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
56
57
58
59
60
package dev.plex.command.sub;
import dev.plex.Guilds;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.guild.Guild;
import java.util.Collections;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CreateSubCommand extends GuildSubCommand
{
public CreateSubCommand()
{
super(command("create")
.description("Creates a guild with a specified name")
.usage("/guild <command> <name>")
.aliases("make")
.permission("plex.guilds.create")
.source(RequiredCommandSource.IN_GAME)
.build());
}
@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
if (args.length == 0)
{
return usage();
}
assert player != null;
if (Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).isPresent())
{
return messageComponent("alreadyInGuild");
}
Guilds.get().getGuildRepository().createGuild(player, StringUtils.join(args, " "))
.thenCompose(guild -> Guilds.get().getGuildWorldService().ensureWorld(guild).thenApply(world -> guild))
.whenComplete((guild, throwable) ->
{
if (throwable != null)
{
send(player, messageComponent("guildStorageFailed"));
return;
}
Guilds.get().getGuildHolder().addGuild(guild);
send(player, messageComponent("guildCreated", guild.getName()));
});
return null;
}
@Override
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
{
return Collections.emptyList();
}
}