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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
package com.MylesAndMore.tumble.commands;
import com.MylesAndMore.tumble.TumbleManager;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class SetWinnerLoc 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("tumble.winlocation")) {
// Check if the lobby world has been configured
if (TumbleManager.getLobbyWorld() != null) {
// Check if the sender is a player
if (sender instanceof Player) {
// Check the sender entered the correct number of args
if (args.length == 3) {
double args0 = 0;
double args1 = 0;
double args2 = 0;
try {
args0 = Double.parseDouble(args[0]);
args1 = Double.parseDouble(args[1]);
args2 = Double.parseDouble(args[2]);
} catch (NumberFormatException nfe){
sender.sendMessage(ChatColor.RED + "Input arguments must be valid numbers.");
} catch (Exception e){
sender.sendMessage(ChatColor.RED + "Invalid input arguments.");
}
// Check if any of the args were 0 (this will cause future problems so we prevent it here)
if (!((args0 == 0) || (args1 == 0) || (args2 == 0))) {
TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", args0);
TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", args1);
TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", args2);
TumbleManager.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
else {
sender.sendMessage(ChatColor.RED + "Your coordinates cannot be zero!");
sender.sendMessage(ChatColor.RED + "Use something like 0.5 (the middle of the block) instead.");
}
}
// If the sender entered no args, use their current location
else if (args.length == 0) {
Location senderPos = ((Player) sender).getLocation();
// if so, check if any of their locations are zero
if (!((senderPos.getX() == 0) || (senderPos.getY() == 0) || (senderPos.getZ() == 0))) {
// set the config values to their current pos
TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", senderPos.getX());
TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", senderPos.getY());
TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", senderPos.getZ());
TumbleManager.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
else {
sender.sendMessage(ChatColor.RED + "Your coordinates cannot be zero!");
sender.sendMessage(ChatColor.RED + "Use something like 0.5 (the middle of the block) instead.");
}
}
else {
return false;
}
}
// Check if the sender is the console
else if (sender instanceof ConsoleCommandSender) {
// Check if the correct # of args were entered
if (args.length == 3) {
double args0 = 0;
double args1 = 0;
double args2 = 0;
try {
args0 = Double.parseDouble(args[0]);
args1 = Double.parseDouble(args[1]);
args2 = Double.parseDouble(args[2]);
} catch (NumberFormatException nfe){
sender.sendMessage(ChatColor.RED + "Input arguments must be valid numbers.");
} catch (Exception e){
sender.sendMessage(ChatColor.RED + "Invalid input arguments.");
}
// Check if any of the args were 0 (this will cause future problems so we prevent it here)
if (!((args0 == 0) || (args1 == 0) || (args2 == 0))) {
TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", args0);
TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", args1);
TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", args2);
TumbleManager.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
else {
sender.sendMessage(ChatColor.RED + "Your coordinates cannot be zero!");
sender.sendMessage(ChatColor.RED + "Use something like 0.5 (the middle of the block) instead.");
}
}
else {
return false;
}
}
}
else {
sender.sendMessage(ChatColor.RED + "Please link a lobby world first!");
}
}
else {
sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage());
}
return true;
}
}
|