summaryrefslogtreewikicommitdiff
path: root/src/main/java/cat/freya/khs/command/map/set/Border.java
blob: b0aa9053238802e8c2306b923d7be5fa30f4776b (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
76
77
78
79
80
81
82
83
84
85
86
package cat.freya.khs.command.map.set;

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.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class Border implements ICommand {

	public void execute(Player sender, String[] args) {
		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;
		}
		if (map.getSpawn().isNotSetup()) {
			sender.sendMessage(Config.errorPrefix + Localization.message("ERROR_GAME_SPAWN"));
			return;
		}

		int num,delay,change;
		try { num = Integer.parseInt(args[1]); } catch (Exception e) {
			sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_INVALID_INPUT").addAmount(args[0]));
			return;
		}
		try { delay = Integer.parseInt(args[2]); } catch (Exception e) {
			sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_INVALID_INPUT").addAmount(args[1]));
			return;
		}
		try { change = Integer.parseInt(args[3]); } catch (Exception e) {
			sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_INVALID_INPUT").addAmount(args[2]));
			return;
		}
		if (num < 100) {
			sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_MIN_SIZE"));
			return;
		}
		if (change < 1) {
			sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_CHANGE_SIZE"));
			return;
		}
		map.setWorldBorderData(
				sender.getLocation().getBlockX(),
				sender.getLocation().getBlockZ(),
				num,
				delay,
				change
		);
		Maps.setMap(map.getName(), map);
		sender.sendMessage(Config.messagePrefix + Localization.message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay).addAmount(change));
		map.getWorldBorder().resetWorldBorder();
	}

	public String getLabel() {
		return "border";
	}

	public String getUsage() {
		return "<map> <size> <delay> <move>";
	}

	public String getDescription() {
		return "Sets a maps world border information";
	}

	public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
		if(parameter.equals("map")) {
			return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList());
		}
		return Collections.singletonList(parameter);
	}

}