summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/commands/SetBorder.java
blob: a485c9168444c370b770dee72d92818f095efefa (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
package net.tylermurphy.hideAndSeek.commands;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.ICommand;

import static net.tylermurphy.hideAndSeek.Store.*;

public class SetBorder implements ICommand {

	public void execute(CommandSender sender, String[] args) {
		if(!status.equals("Standby") && !status.equals("Setup")) {
			sender.sendMessage(errorPrefix + "Game is currently in session");
			return;
		}
		if(spawnPosition == null) {
			sender.sendMessage(errorPrefix + "Please set spawn position first");
			return;
		}
		if(args.length < 2) {
			getConfig().set("borderEnabled", false);
			worldborderEnabled = false;
			saveConfig();
			sender.sendMessage(messagePrefix + "Disabled worldborder.");
			Functions.resetWorldborder();
			return;
		}
		int num,delay;
		try { num = Integer.parseInt(args[0]); } catch (Exception e) {
			sender.sendMessage(errorPrefix + "Invalid integer: "+args[0]);
			return;
		}
		try { delay = Integer.parseInt(args[1]); } catch (Exception e) {
			sender.sendMessage(errorPrefix + "Invalid integer: "+args[1]);
			return;
		}
		if(num < 100) {
			sender.sendMessage(errorPrefix + "Worldborder cannot be smaller than 100 blocks.");
			return;
		}
		Vector newWorldborderPosition = new Vector();
		Player player = (Player) sender;
		newWorldborderPosition.setX(player.getLocation().getBlockX());
		newWorldborderPosition.setY(0);
		newWorldborderPosition.setZ(player.getLocation().getBlockZ());
		if(spawnPosition.distance(newWorldborderPosition) > 100) {
			sender.sendMessage(errorPrefix + "Spawn position must be 100 from worldborder center");
			return;
		}
		worldborderPosition = newWorldborderPosition;
		worldborderSize = num;
		worldborderDelay = delay;
		sender.sendMessage(messagePrefix + "Set border center to current location, size to "+num+", and delay to "+delay);
		getConfig().set("borderPosition", newWorldborderPosition);
		getConfig().set("borderSize", num);
		getConfig().set("borderDelay", delay);
		getConfig().set("borderEnabled", false);
		worldborderEnabled = true;
		saveConfig();
		Functions.resetWorldborder();
	}

	public String getLabel() {
		return "setBorder";
	}
	
	public String getUsage() {
		return "<size> <delay>";
	}

	public String getDescription() {
		return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable.";
	}

}