-
Notifications
You must be signed in to change notification settings - Fork 0
/
Commands.java
239 lines (233 loc) · 10.7 KB
/
Commands.java
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package com.LRFLEW.PvP;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commands implements CommandExecutor {
private final PvP plugin;
protected Commands (PvP instance) {
plugin = instance;
}
public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (args.length >= 1 && args[0].equalsIgnoreCase("on")) {
if (sender instanceof Player && args.length == 1) {
Player player = (Player)sender;
if (plugin.cooldown.get(player.getName()) != null && plugin.cooldown.get(player.getName()) > System.currentTimeMillis()) {
player.sendMessage(Settings.preFx + "You need to wait " + plugin.sets.cooldownOnToOff + " seconds before you can turn PVP on");
} else {
if (!plugin.PvP.contains(player.getName())) {
plugin.PvP.add(player.getName());
plugin.cooldown.put(player.getName(), System.currentTimeMillis() + (plugin.sets.cooldownOnToOff*1000));
if (plugin.sets.announce) Misc.announceExclude(Settings.preFx + player.getDisplayName() + " is raring to fight", player);
} else {
if (plugin.cooldown.containsKey(player.getName())) plugin.cooldown.remove(player.getName());
}
player.sendMessage(Settings.preFx + "PvP is " + ChatColor.WHITE + "On" + Settings.preFx + " for you. Beware! " +
"Turn it off by typing " + ChatColor.WHITE + "/pvp off");
}
return true;
} else if (args.length >= 2){
Player player = Bukkit.getPlayer(args[1]);
if (plugin.cooldown.get(player.getName()) != null && plugin.cooldown.get(player.getName()) > System.currentTimeMillis()) {
sender.sendMessage(Settings.preFx + "You need to wait " + plugin.sets.cooldownOnToOff +
" seconds before you can turn PVP on for" + player.getDisplayName());
} else {
if (!plugin.PvP.contains(player.getName())) {
plugin.PvP.add(player.getName());
plugin.cooldown.put(player.getName(), System.currentTimeMillis() + (plugin.sets.cooldownOnToOff*1000));
if (plugin.sets.announce) Misc.announceExclude(Settings.preFx + player.getDisplayName() + " is raring to fight", player);
} else {
if (plugin.cooldown.containsKey(player.getName())) plugin.cooldown.remove(player.getName());
}
}
sender.sendMessage(Settings.preFx + "PvP is " + ChatColor.WHITE + "On" + Settings.preFx + " for " + player.getDisplayName());
return true;
}
}
if (args.length >= 1 && args[0].equalsIgnoreCase("off")) {
if (sender instanceof Player && args.length == 1) {
Player player = (Player)sender;
if (plugin.cooldown.get(player.getName()) != null && plugin.cooldown.get(player.getName()) > System.currentTimeMillis()) {
player.sendMessage(Settings.preFx + "You need to wait " + plugin.sets.cooldownOnToOff + " seconds before you can turn PVP off");
return true;
} else {
if (plugin.PvP.contains(player.getName())) {
plugin.PvP.remove(player.getName());
plugin.cooldown.put(player.getName(), System.currentTimeMillis() + (plugin.sets.cooldownOffToOn*1000));
if (plugin.sets.announce) Misc.announceExclude(Settings.preFx + player.getDisplayName() + " is done fighting", player);
}
player.sendMessage(Settings.preFx + "PvP is " + ChatColor.WHITE + "Off" + Settings.preFx + " for you. " +
"Just look out for spiders :)");
return true;
}
} else if (args.length >= 2) {
Player player = Bukkit.getPlayer(args[1]);
if (plugin.cooldown.get(player.getName()) != null && plugin.cooldown.get(player.getName()) > System.currentTimeMillis()) {
sender.sendMessage(Settings.preFx + "You need to wait " + plugin.sets.cooldownOnToOff +
" seconds before you can turn PVP on for" + player.getDisplayName());
return true;
} else {
if (plugin.PvP.contains(player.getName())) {
plugin.PvP.remove(player.getName());
plugin.cooldown.put(player.getName(), System.currentTimeMillis() + (plugin.sets.cooldownOffToOn*1000));
if (plugin.sets.announce) Misc.announceExclude(Settings.preFx + player.getDisplayName() + " is done fighting", player);
}
sender.sendMessage(Settings.preFx + "PvP is " + ChatColor.WHITE + "On" + Settings.preFx + " for " + player.getDisplayName());
return true;
}
}
}
if (args.length >= 1 && args[0].equalsIgnoreCase("spar")) {
if (sender instanceof Player) {
Player sparrer = (Player)sender;
if (args.length > 1) {
Player sparri = plugin.getServer().getPlayer(args[1]);
if (sparri == null) {
sparrer.sendMessage("Player not Found");
return true;
}
plugin.sparRequest.put(sparri.getName(), sparrer.getName());
sparri.sendMessage(sparrer.getDisplayName() + Settings.preFx + " wants to spar you. ");
sparri.sendMessage(Settings.preFx + "Accept by typing " + ChatColor.WHITE + "/pvp yes" +
Settings.preFx + " or deny with " + ChatColor.WHITE + "/pvp no");
sparrer.sendMessage("Request sent to " + sparri.getDisplayName());
return true;
}
}
}
if (args.length >= 1 && args[0].equalsIgnoreCase("yes")) {
if (sender instanceof Player) {
Player sparri = (Player)sender;
if (plugin.sparRequest.containsKey(sparri.getName())) {
if (plugin.sparRequest.get(sparri.getName()) == null) {
plugin.sparRequest.remove(sparri.getName());
new Misc.MapMissmatchException(sparri.getName() + " -> null");
} else {
Player sparrer = Bukkit.getPlayerExact(plugin.sparRequest.get(sparri.getName()));
plugin.sparRequest.remove(sparri.getName());
plugin.spar.put(sparri.getName(), sparrer.getName());
plugin.spar.put(sparrer.getName(), sparri.getName());
sparri.sendMessage(Settings.preFx + "You are now sparring " + ChatColor.WHITE + sparrer.getDisplayName() +
Settings.preFx + ". Good luck");
sparrer.sendMessage(Settings.preFx + "You are now sparring " + ChatColor.WHITE + sparrer.getDisplayName() +
Settings.preFx + ". Good luck");
if (plugin.sets.announce) Misc.announceExclude(Settings.preFx + sparri.getDisplayName() + " and " + sparrer.getDisplayName() +
" are noew dueling eachother. Epic", sparrer, sparri);
return true;
}
}
}
}
if (args.length >= 1 && args[0].equalsIgnoreCase("no")) {
if (sender instanceof Player) {
Player sparri = (Player)sender;
if (plugin.sparRequest.containsKey(sparri.getName())) {
if (plugin.sparRequest.get(sparri.getName()) == null) {
plugin.sparRequest.remove(sparri.getName());
new Misc.MapMissmatchException(sparri.getName() + " -> null");
} else {
Player sparrer = Bukkit.getPlayerExact(plugin.sparRequest.get(sparri.getName()));
plugin.sparRequest.remove(sparri.getName());
sparri.sendMessage("You have denied the spar request from " + sparrer.getDisplayName());
sparrer.sendMessage(sparrer.getDisplayName() + " Denied you sparring request. Sorry");
return true;
}
}
}
}
if (args.length >= 1 && args[0].equalsIgnoreCase("killswitch") || args.length >= 1 && args[0].equalsIgnoreCase("ks")) {
if (sender instanceof Player)
if (!((Player)sender).isOp()) {
sender.sendMessage((Settings.preFx + "You don't have permissions to run this command"));
return true;
}
if (args[1].equalsIgnoreCase("dissable") || args[1].equalsIgnoreCase("dis")) {
plugin.killSwitch = 0;
Bukkit.broadcastMessage(Settings.preFx + "Users can now set their own PvP status");
} else {
if (args[1].equalsIgnoreCase("on")) {
plugin.killSwitch = 1;
Bukkit.broadcastMessage(Settings.preFx + "PvP is now forced on for everybody");
} if (args[1].equalsIgnoreCase("off")) {
plugin.killSwitch = -1;
Bukkit.broadcastMessage(Settings.preFx + "PvP is now forced off for everybody");
return true;
}
}
}
if (args.length >= 1 && args[0].equalsIgnoreCase("list")) {
if (plugin.PvP.isEmpty()) {
sender.sendMessage(Settings.preFx + "Nobody has PvP on");
return true;
}
int page;
if (args.length >= 2) try {
page = Integer.parseInt(args[1]) - 1;
if (page < 0) {
if (page == -1) sender.sendMessage(Settings.preFx + "no page 0");
else sender.sendMessage(Settings.preFx + "no negative pages");
page = 0;
}
if (page * 16 > plugin.PvP.size()) {
sender.sendMessage(Settings.preFx + "there is no page " + (page + 1));
return true;
}
} catch (NumberFormatException e) {
sender.sendMessage(Settings.preFx + "\"" + args[1] + "\"" + " is not a number");
page = 0;
}
else page = 0;
boolean display = sender instanceof Player;
sender.sendMessage(Settings.preFx + "page " + (page + 1) + " out of " + Math.ceil((double)plugin.PvP.size()/16));
String[] names = new String[16];
int i = 0, j = 0;
for (String p : plugin.PvP) {
if (i++ < page * 16) continue;
if (display) names[j++] = Bukkit.getPlayer(p).getDisplayName();
else names[j++] = p;
if (j >= 16) break;
}
for (i = 0; i < 4 && (i*4) < j; i++) {
String temp = "";
for (int k = 0; k < 4 && (i*4) + k < j; k++) {
temp += Settings.preFx + names[(i*4) + k];
}
sender.sendMessage(temp);
}
return true;
}
if (args.length >= 1 && args[0].equalsIgnoreCase("help")) {
if (sender instanceof Player) {
Player player = (Player)sender;
player.sendMessage(Settings.preFx + "Usage:");
player.sendMessage(ChatColor.WHITE + " /PvP on" + Settings.preFx + " - you can be attacked by players");
player.sendMessage(ChatColor.WHITE + " /PvP off" + Settings.preFx + " - players can't attack you");
return true;
} else {
System.out.println("Usage:");
System.out.println("\t/PvP on" + Settings.preFx + " - you can be attacked by players");
System.out.println("\t/PvP off" + Settings.preFx + " - players can't attack you");
}
}
if (sender instanceof Player) {
Player player = (Player)sender;
if ( plugin.PvP.contains(player.getName())) {
player.sendMessage(Settings.preFx + "PvP is " + ChatColor.WHITE + "On" + Settings.preFx + " for you. Beware!");
} else {
player.sendMessage(Settings.preFx + "PvP is " + ChatColor.WHITE + "Off" + Settings.preFx + " for you. " +
"Just look out for spiders :)");
}
player.sendMessage(Settings.preFx + "Usage:");
player.sendMessage(ChatColor.WHITE + " /PvP on" + Settings.preFx + " - you can be attacked by players");
player.sendMessage(ChatColor.WHITE + " /PvP off" + Settings.preFx + " - players can't attack you");
Long l = plugin.cooldown.get(player.getName());
if (l != null && l <= System.currentTimeMillis()) plugin.cooldown.remove(player.getName());
return true;
} else {
System.out.println("Type \"pvp help\" for a list of commands");
}
return true;
}
}