blob: 052602c5ff51e05ba1df693e77d6b6bfa5d3ab08 (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package cat.freya.khs.command.map.blockhunt.blocks;
import cat.freya.khs.Main;
import cat.freya.khs.command.util.ICommand;
import cat.freya.khs.configuration.Config;
import cat.freya.khs.configuration.Localization;
import cat.freya.khs.configuration.Map;
import cat.freya.khs.configuration.Maps;
import cat.freya.khs.game.util.Status;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Add implements ICommand {
public void execute(Player sender, String[] args) {
if (!Main.getInstance().supports(9)) {
sender.sendMessage(Config.errorPrefix + Localization.message("BLOCKHUNT_UNSUPPORTED"));
return;
}
if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
sender.sendMessage(Config.errorPrefix + Localization.message("GAME_INPROGRESS"));
return;
}
Map map = Maps.getMap(args[0]);
if(map == null) {
sender.sendMessage(Config.errorPrefix + Localization.message("INVALID_MAP"));
return;
}
Material block;
try { block = Material.valueOf(args[1]); }
catch (IllegalArgumentException e) {
sender.sendMessage(Config.errorPrefix + Localization.message("COMMAND_INVALID_ARG").addAmount(args[1]));
return;
}
List<Material> blocks = map.getBlockHunt();
if(blocks.contains(block)) {
sender.sendMessage(Config.errorPrefix + Localization.message("BLOCKHUNT_BLOCK_EXISTS").addAmount(args[1]));
}
blocks.add(block);
map.setBlockhunt(map.isBlockHuntEnabled(), blocks);
Maps.setMap(map.getName(), map);
sender.sendMessage(Config.messagePrefix + Localization.message("BLOCKHUNT_BLOCK_ADDED").addAmount(args[1]));
}
public String getLabel() {
return "add";
}
public String getUsage() {
return "<map> <block>";
}
public String getDescription() {
return "Add a blockhunt block to a map!";
}
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList());
} else if(parameter.equals("block")) {
return Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Material::toString)
.filter(s -> s.toUpperCase().startsWith(typed.toUpperCase()))
.collect(Collectors.toList());
}
return null;
}
}
|