9 |
import org.bukkit.command.CommandSender; |
import org.bukkit.command.CommandSender; |
10 |
import org.bukkit.entity.Player; |
import org.bukkit.entity.Player; |
11 |
|
|
12 |
|
import java.util.HashMap; |
13 |
|
|
14 |
public class GeneralContractorCommands implements CommandExecutor{ |
public class GeneralContractorCommands implements CommandExecutor{ |
15 |
|
|
16 |
|
class StoredCommand { |
17 |
|
public StoredCommand(String l, String a[]) { |
18 |
|
this.label = l; |
19 |
|
this.args = a; |
20 |
|
} |
21 |
|
public String label; |
22 |
|
public String args[]; |
23 |
|
} |
24 |
|
|
25 |
final static int Y_MAX = 255; |
final static int Y_MAX = 255; |
26 |
|
final int valid_block_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 35, 41, 42, 43, 44, 45, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; |
27 |
|
|
28 |
|
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
//@Override |
//@Override |
33 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
43 |
player.sendMessage( ChatColor.RED + "This command may only be used in creative world" ); |
player.sendMessage( ChatColor.RED + "This command may only be used in creative world" ); |
44 |
return true; |
return true; |
45 |
} |
} |
46 |
|
|
47 |
|
|
48 |
|
if ( command.getLabel().equals("replay") ) { |
49 |
|
StoredCommand cmd = commands.get(player.getName() ); |
50 |
|
if (cmd != null) { |
51 |
|
label = cmd.label; |
52 |
|
args = cmd.args; |
53 |
|
} |
54 |
|
} else { |
55 |
|
commands.put(player.getName(), new StoredCommand(label,args) ); |
56 |
|
} |
57 |
|
|
58 |
//System.out.println( ">>" + label); //DEBUG |
//System.out.println( ">>" + label); //DEBUG |
59 |
|
|
60 |
if ( label.equals("levelarea") ) { |
if ( label.equals("levelarea") ) { |
61 |
if (validateLevelOrFill(player, args) ) { |
if (validateLevelOrFill(player, label, args) ) { |
62 |
levelArea(player, loc, args); |
levelArea(player, loc, args); |
63 |
} |
} |
64 |
return true; |
return true; |
66 |
|
|
67 |
|
|
68 |
if ( label.equals("fillarea") ) { |
if ( label.equals("fillarea") ) { |
69 |
if (validateLevelOrFill(player, args) ) { |
if (validateLevelOrFill(player, label, args) ) { |
70 |
fillArea(player, loc, args); |
fillArea(player, loc, args); |
71 |
} |
} |
72 |
return true; |
return true; |
82 |
setSurface(player, loc, args); |
setSurface(player, loc, args); |
83 |
return true; |
return true; |
84 |
} |
} |
85 |
|
|
86 |
|
if (label.equals("platform") ) { |
87 |
|
platform(player,loc,args); |
88 |
|
return true; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
return false; |
return false; |
93 |
} |
} |
94 |
|
|
95 |
|
|
96 |
void slopeArea(Player player, Location loc, String[] args) { |
void slopeArea(Player player, Location loc, String[] split) { |
97 |
int radius = Integer.parseInt(args[1]); |
int radius; |
98 |
|
try { |
99 |
|
radius = Integer.parseInt(split[0]); |
100 |
|
} catch (Exception e) { |
101 |
|
player.sendMessage("setsurface: radius must be an integer"); |
102 |
|
return; |
103 |
|
} |
104 |
|
|
105 |
System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius); |
106 |
|
|
130 |
} |
} |
131 |
} |
} |
132 |
|
|
133 |
private void setSurface(Player player, Location loc, String[] split) { |
private void platform(Player player, Location loc, String[] split) { |
|
int valid_block_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 35, 41, 42, 43, 44, 45, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; |
|
134 |
|
|
135 |
|
if (split.length != 2) { |
136 |
|
player.sendMessage("Usage /platform [radius] [blockID]"); |
137 |
|
return; |
138 |
|
} |
139 |
|
|
140 |
|
int radius; |
141 |
|
try { |
142 |
|
radius = Integer.parseInt(split[0]); |
143 |
|
} catch (Exception e) { |
144 |
|
player.sendMessage("platform: radius must be an integer"); |
145 |
|
return; |
146 |
|
} |
147 |
|
|
148 |
if (split.length != 3) { |
if (radius > 20) { |
149 |
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
player.sendMessage("platform: radius may not exceed 20"); |
150 |
|
return; |
151 |
|
} |
152 |
|
|
153 |
|
int blockid; |
154 |
|
try { |
155 |
|
blockid = Integer.parseInt(split[1]); |
156 |
|
} catch (Exception e) { |
157 |
|
player.sendMessage("platform: blockid must be an integer"); |
158 |
return; |
return; |
159 |
} |
} |
160 |
|
/* |
161 |
|
boolean validblock = false; |
162 |
|
for (int i=0; i<valid_block_array.length; i++) { |
163 |
|
if (valid_block_array[i] == blockid) { |
164 |
|
validblock = true; |
165 |
|
break; |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
|
if ( !validblock ) { |
170 |
|
player.sendMessage("setsurface: block now allowed"); |
171 |
|
return; |
172 |
|
}*/ |
173 |
|
|
174 |
|
int playerX = loc.getBlockX(); |
175 |
|
int playerY = loc.getBlockY(); |
176 |
|
int playerZ = loc.getBlockZ(); |
177 |
|
|
178 |
|
|
179 |
|
World world = loc.getWorld(); |
180 |
|
|
181 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
182 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
183 |
|
int y = playerY - 1; |
184 |
|
|
185 |
|
world.getBlockAt(x, y, z).setTypeId(blockid); |
186 |
|
} |
187 |
|
} |
188 |
|
} |
189 |
|
|
190 |
|
private void setSurface(Player player, Location loc, String[] split) { |
191 |
|
|
192 |
|
if (split.length != 2) { |
193 |
|
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
194 |
|
return; |
195 |
|
} |
196 |
|
|
197 |
int radius; |
int radius; |
198 |
try { |
try { |
199 |
radius = Integer.parseInt(split[1]); |
radius = Integer.parseInt(split[0]); |
200 |
} catch (Exception e) { |
} catch (Exception e) { |
201 |
player.sendMessage("setsurface: radius must be an integer"); |
player.sendMessage("setsurface: radius must be an integer"); |
202 |
return; |
return; |
207 |
return; |
return; |
208 |
} |
} |
209 |
|
|
|
|
|
210 |
int blockid; |
int blockid; |
211 |
try { |
try { |
212 |
blockid = Integer.parseInt(split[2]); |
blockid = Integer.parseInt(split[1]); |
213 |
} catch (Exception e) { |
} catch (Exception e) { |
214 |
player.sendMessage("setsurface: blockid must be an integer"); |
player.sendMessage("setsurface: blockid must be an integer"); |
215 |
return; |
return; |
238 |
} |
} |
239 |
|
|
240 |
World world = loc.getWorld(); |
World world = loc.getWorld(); |
|
|
|
241 |
|
|
242 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
243 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
244 |
//int y = getGroundLevel(x,z) - 1; |
//int y = getGroundLevel(x,z) - 1; |
245 |
int y = world.getHighestBlockYAt(x, z); |
int y = world.getHighestBlockYAt(x, z) ; |
246 |
|
|
247 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setTypeId(blockid); |
248 |
} |
} |
249 |
} |
} |
250 |
} |
} |
251 |
|
|
252 |
private boolean validateLevelOrFill(Player player, String[] split) { |
private boolean validateLevelOrFill(Player player, String label, String[] split) { |
253 |
if (split.length < 2 || split.length > 3) { |
if (split.length < 1 || split.length > 2) { |
254 |
player.sendMessage("Usage: " + split[0] + " [radius]"); |
player.sendMessage("Usage: " + label + " [radius]"); |
255 |
return false; |
return false; |
256 |
} |
} |
257 |
|
|
258 |
int radius; |
int radius; |
259 |
try { |
try { |
260 |
radius = Integer.parseInt(split[1]); |
radius = Integer.parseInt(split[0]); |
261 |
} catch (Exception e) { |
} catch (Exception e) { |
262 |
player.sendMessage(split[0] + ": radius must be an integer"); |
player.sendMessage(label + ": radius must be an integer"); |
263 |
return false; |
return false; |
264 |
} |
} |
265 |
|
|
266 |
if (radius > 20) { |
if (radius > 20) { |
267 |
player.sendMessage(split[0] + ": radius may not exceed 20"); |
player.sendMessage(label + ": radius may not exceed 20"); |
268 |
return false; |
return false; |
269 |
} |
} |
270 |
|
|
271 |
if (split.length == 3) { |
if (split.length == 2) { |
272 |
int id; |
int id; |
273 |
try { |
try { |
274 |
id = Integer.parseInt( split[2] ); |
id = Integer.parseInt( split[1] ); |
275 |
} catch (Exception e) { |
} catch (Exception e) { |
276 |
player.sendMessage(split[0] + ": id must be an integer"); |
player.sendMessage(label + ": id must be an integer"); |
277 |
return false; |
return false; |
278 |
} |
} |
279 |
if ( id == 46) { |
if ( id == 46) { |
287 |
} |
} |
288 |
|
|
289 |
private void fillArea(Player player, Location loc, String[] split) { |
private void fillArea(Player player, Location loc, String[] split) { |
290 |
int radius = Integer.parseInt(split[1]); |
int radius = Integer.parseInt(split[0]); |
291 |
|
|
292 |
int material = Material.DIRT.getId(); |
int material = Material.DIRT.getId(); |
293 |
|
|
294 |
if (split.length == 3) { |
if (split.length == 2) { |
295 |
material = Integer.parseInt( split[2] ); |
material = Integer.parseInt( split[1] ); |
296 |
} |
} |
297 |
|
|
298 |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
320 |
|
|
321 |
private void levelArea(Player player, Location loc, String[] split) { |
private void levelArea(Player player, Location loc, String[] split) { |
322 |
|
|
323 |
int radius = Integer.parseInt(split[1]); |
int radius = Integer.parseInt(split[0]); |
324 |
|
|
325 |
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
326 |
|
|