blob: d64573c481e9d7fce5a607434d13647c0d526e24 (
plain) (
blame)
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
|
package com.MylesAndMore.tumble.commands;
import com.MylesAndMore.tumble.TumbleManager;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import java.util.Objects;
public class SetAutoStart implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Check if sender has perms to run command
if (sender.hasPermission("autostart")) {
// Check if game and lobby worlds are null
if (TumbleManager.getGameWorld() != null) {
if (TumbleManager.getLobbyWorld() != null) {
// Check the player # argument and parse it into an int
int args0 = 0;
try {
args0 = Integer.parseInt(args[0]);
} catch (NumberFormatException nfe){
sender.sendMessage(ChatColor.RED + "Player amount must be a valid number.");
} catch (Exception e){
sender.sendMessage(ChatColor.RED + "Invalid player amount.");
}
// Check the amount of args entered
if (args.length == 2) {
// PlayerAmount & enable/disable were entered
// Check if a playerAmount between 2-8 was entered
if ((args0 >= 2) && (args0 <= 8)) {
if (Objects.equals(args[1], "enable")) {
// Write values to the config
TumbleManager.getPlugin().getConfig().set("autoStart.players", args0);
TumbleManager.getPlugin().getConfig().set("autoStart.enabled", args[1]);
TumbleManager.getPlugin().saveConfig();
}
else if (Objects.equals(args[1], "disable")) {
TumbleManager.getPlugin().getConfig().set("autoStart.players", args0);
TumbleManager.getPlugin().getConfig().set("autoStart.enabled", args[1]);
TumbleManager.getPlugin().saveConfig();
}
else {
return false;
}
}
else {
sender.sendMessage(ChatColor.RED + "Please enter a player amount between two and eight!");
}
}
else if (args.length == 1) {
// Only PlayerAmount was entered
if ((args0 >= 2) && (args0 <= 8)) {
TumbleManager.getPlugin().getConfig().set("autoStart.players", args0);
TumbleManager.getPlugin().saveConfig();
}
else {
sender.sendMessage(ChatColor.RED + "Please enter a player amount between two and eight!");
}
}
else {
return false;
}
}
else {
sender.sendMessage(ChatColor.RED + "Please link a lobby world first!");
}
}
else {
sender.sendMessage(ChatColor.RED + "Please link a game world first!");
}
}
else {
sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage());
}
return true;
}
}
|