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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
package com.encrox.cplot.command;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
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.entity.Player;
import com.earth2me.essentials.OfflinePlayer;
import com.earth2me.essentials.api.Economy;
import com.encrox.cplot.Core;
import com.encrox.cplot.constants.Direction;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class Gs implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
if(sender instanceof Player) {
Player player = (Player)sender;
if(sender.hasPermission("cplot.gs." + player.getWorld().getName())) {
switch(args[0]) {
case "claim":
switch(args.length) {
case 2:
Selection sel = Core.we.getSelection((Player)sender);
if(sel == null) {
sender.sendMessage(ChatColor.RED + "No selection made. Please make a selection with the wand-tool first.");
return false;
}
Location min = sel.getMinimumPoint(), max = sel.getMaximumPoint();
return claim(player, args[1], min.getBlockX(), min.getBlockY(), min.getBlockZ(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
case 6:
return claim(player, args[1], Integer.parseInt(args[2]), 0, Integer.parseInt(args[3]), Integer.parseInt(args[4]), 255, Integer.parseInt(args[5]));
case 8:
return claim(player, args[1], Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), Integer.parseInt(args[7]));
}
case "expand":
return expand(player, args[1], Direction.getDirection(args[2]), Integer.parseInt(args[3]));
case "unclaim":
switch(args.length) {
case 2:
return unclaim(player, args[1]);
case 3:
if(player.hasPermission("cplot.admin")) {
String regionName = Bukkit.getServer().getOfflinePlayer(args[1]).getUniqueId().toString() + "_" + args[2];
if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
Core.wg.getRegionManager(player.getWorld()).removeRegion(regionName);
}
player.sendMessage(ChatColor.GREEN + "Region has been unclaimed.");
return true;
} else {
player.sendMessage(ChatColor.RED + "You dont have permission to perform this command.");
return false;
}
}
case "add":
return add(player, args[1], args[2]);
case "remove":
return remove(player, args[1], args[2]);
case "op":
return op(player, args[1], args[2]);
case "deop":
return deop(player, args[1], args[2]);
case "price":
return price(player);
case "help":
player.sendMessage(ChatColor.YELLOW + "/gs claim <name> [<x1> [<y1>] <z1> <x2> [<y2>] <z2>]\n" + ChatColor.WHITE + "Claims a new plot with the name <name> from pos1 to pos2.\n" +
ChatColor.YELLOW + "/gs expand <name> <north/south/east/west/up/down> <length>\n" + ChatColor.WHITE + "Expands the plot with the name <name> in a specific direction by <length>.\n" +
ChatColor.YELLOW + "/gs unclaim <name>\n" + ChatColor.WHITE + "Unclaims the plot with the name <name>.\n" +
ChatColor.YELLOW + "/gs add/remove <name> <player>\n" + ChatColor.WHITE + "Adds/Removes the player <player> to/from the members list of the plot with the name <name>.\n" +
ChatColor.YELLOW + "/gs op/deop <name> <player>\n" + ChatColor.WHITE + "Adds/Removes the player <player> to/from the members list of the plot with the name <name>.\n" +
ChatColor.YELLOW + "/gs price\n" + ChatColor.WHITE + "Shows the price/block in the current world.");
return true;
}
} else {
player.sendMessage(ChatColor.RED + "You dont have permissions to perform this command.");
}
} else {
sender.sendMessage("This can only be issued by a player.");
}
} catch(Exception e) {
e.printStackTrace();
}
return false;
}
private boolean claim(Player player, String label, int x1, int y1, int z1, int x2, int y2, int z2) {
String regionName = player.getUniqueId().toString() + "_" + label;
double cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (x2-x1) * (y2-y1) * (z2-z1);
try {
if(Economy.hasEnough(player.getName(), cost)) {
if(!Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName, new BlockVector(x1, y1, z1), new BlockVector(x2, y2, z2));
if(region.getIntersectingRegions(Core.wg.getRegionManager(player.getWorld()).getRegions().values()).size() == 0) {
Economy.subtract(player.getName(), cost);
Core.wg.getRegionManager(player.getWorld()).addRegion(region);
Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getOwners().addPlayer(player.getUniqueId());
player.sendMessage(ChatColor.GREEN + "Region claimed for " + ChatColor.GOLD + cost);
} else {
player.sendMessage(ChatColor.RED + "Region already claimed / Intersecting with another region.");
}
} else {
player.sendMessage(ChatColor.RED + "Name already taken.");
}
} else {
player.sendMessage(ChatColor.RED + "Not enough money! You need " + ChatColor.GOLD + cost);
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
private boolean expand(Player player, String label, byte direction, int size) {
String regionName = player.getUniqueId().toString() + "_" + label;
double cost = 0.0;
int x1, y1, z1, x2, y2, z2;
BlockVector min, max;
ProtectedCuboidRegion region = (ProtectedCuboidRegion) Core.wg.getRegionManager(player.getWorld()).getRegion(regionName);
if(region != null) {
min = region.getMinimumPoint();
max = region.getMaximumPoint();
x1 = min.getBlockX();
y1 = min.getBlockY();
z1 = min.getBlockZ();
x2 = max.getBlockX();
y2 = max.getBlockY();
z2 = max.getBlockZ();
Core.wg.getRegionManager(player.getWorld()).removeRegion(regionName);
try {
switch(direction) {
case Direction.NORTH:
cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
z1-=size;
break;
case Direction.SOUTH:
cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
z2+=size;
break;
case Direction.EAST:
cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
x2+=size;
break;
case Direction.WEST:
cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
x1-=size;
break;
case Direction.UP:
cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
y2+=size;
break;
case Direction.DOWN:
cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
y1-=size;
break;
}
if(Economy.hasEnough(player.getName(), cost)) {
ProtectedCuboidRegion newRegion = new ProtectedCuboidRegion(regionName, new BlockVector(x1, y1, z1), new BlockVector(x2, y2, z2));
if(newRegion.getIntersectingRegions(Core.wg.getRegionManager(player.getWorld()).getRegions().values()).size() == 0) {
Economy.subtract(player.getName(), cost);
Core.wg.getRegionManager(player.getWorld()).addRegion(newRegion);
Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getOwners().addPlayer(player.getUniqueId());
player.sendMessage(ChatColor.GREEN + "Region has been expanded for " + ChatColor.GOLD + cost);
} else {
player.sendMessage(ChatColor.RED + "Region already claimed / Intersecting with another region.");
}
} else {
player.sendMessage(ChatColor.RED + "Not enough money for expansion. You need " + ChatColor.GOLD + cost);
}
return true;
} catch(Exception e) {
player.sendMessage(ChatColor.RED + "Something, regarding to economy, went wrong.");
}
}
return false;
}
private boolean unclaim(Player player, String label) {
String regionName = player.getUniqueId().toString() + "_" + label;
if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
LocalPlayer lp = Core.wg.wrapPlayer(player);
if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
Core.wg.getRegionManager(player.getWorld()).removeRegion(regionName);
player.sendMessage(ChatColor.GREEN + "Plot has been unclaimed.");
return true;
} else {
player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
}
} else {
player.sendMessage(ChatColor.RED + "Region not found.");
}
return false;
}
private boolean add(Player player, String label, String addPlayer) {
String regionName = player.getUniqueId().toString() + "_" + label;
if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
LocalPlayer lp = Core.wg.wrapPlayer(player);
if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getMembers().addPlayer(addPlayer);
player.sendMessage(ChatColor.GREEN + "Player has been added.");
return true;
} else {
player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
}
} else {
player.sendMessage(ChatColor.RED + "Region not found.");
}
return false;
}
private boolean remove(Player player, String label, String removePlayer) {
String regionName = player.getUniqueId().toString() + "_" + label;
if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
LocalPlayer lp = Core.wg.wrapPlayer(player);
if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getMembers().removePlayer(removePlayer);
player.sendMessage(ChatColor.GREEN + "Player has been removed.");
return true;
} else {
player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
}
} else {
player.sendMessage(ChatColor.RED + "Region not found.");
}
return false;
}
private boolean op(Player player, String label, String addPlayer) {
String regionName = player.getUniqueId().toString() + "_" + label;
if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
LocalPlayer lp = Core.wg.wrapPlayer(player);
if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getOwners().addPlayer(addPlayer);
player.sendMessage(ChatColor.GREEN + "Player has been added.");
return true;
} else {
player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
}
} else {
player.sendMessage(ChatColor.RED + "Region not found.");
}
return false;
}
private boolean deop(Player player, String label, String removePlayer) {
String regionName = player.getUniqueId().toString() + "_" + label;
if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
LocalPlayer lp = Core.wg.wrapPlayer(player);
if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getOwners().removePlayer(removePlayer);
player.sendMessage(ChatColor.GREEN + "Player has been removed.");
return true;
} else {
player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
}
} else {
player.sendMessage(ChatColor.RED + "Region not found.");
}
return false;
}
private boolean price(Player player) {
String world = player.getWorld().getName();
player.sendMessage(ChatColor.GREEN + "Price/block in world " + world + ": " + ChatColor.GOLD + Core.p.getProperty(world + "_price"));
return true;
}
}
|