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.Arrays; |
13 |
|
import java.util.HashMap; |
14 |
|
|
15 |
public class GeneralContractorCommands implements CommandExecutor{ |
public class GeneralContractorCommands implements CommandExecutor{ |
16 |
|
|
17 |
|
class StoredCommand { |
18 |
|
public StoredCommand(String l, String a[]) { |
19 |
|
this.label = l; |
20 |
|
this.args = a; |
21 |
|
} |
22 |
|
public String label; |
23 |
|
public String args[]; |
24 |
|
} |
25 |
|
|
26 |
final static int Y_MAX = 255; |
final static int Y_MAX = 255; |
27 |
|
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} ; |
28 |
|
|
29 |
|
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
30 |
|
|
31 |
|
|
32 |
|
public GeneralContractorCommands() { |
33 |
|
Arrays.sort(valid_block_array); |
34 |
|
} |
35 |
|
|
36 |
//@Override |
//@Override |
37 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
47 |
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" ); |
48 |
return true; |
return true; |
49 |
} |
} |
50 |
|
|
51 |
|
|
52 |
|
if ( command.getLabel().equals("replay") ) { |
53 |
|
StoredCommand cmd = commands.get(player.getName() ); |
54 |
|
if (cmd != null) { |
55 |
|
label = cmd.label; |
56 |
|
args = cmd.args; |
57 |
|
} |
58 |
|
} else { |
59 |
|
commands.put(player.getName(), new StoredCommand(label,args) ); |
60 |
|
} |
61 |
|
|
62 |
//System.out.println( ">>" + label); //DEBUG |
//System.out.println( ">>" + label); //DEBUG |
63 |
|
|
86 |
setSurface(player, loc, args); |
setSurface(player, loc, args); |
87 |
return true; |
return true; |
88 |
} |
} |
89 |
|
|
90 |
|
if (label.equals("platform") ) { |
91 |
|
platform(player,loc,args); |
92 |
|
return true; |
93 |
|
} |
94 |
|
|
95 |
|
if (label.equals("cylinder") ) { |
96 |
|
if (validateLevelOrFill(player, label, args) ) { |
97 |
|
cylinder(player,loc,args); |
98 |
|
} |
99 |
|
return true; |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
return false; |
return false; |
141 |
} |
} |
142 |
} |
} |
143 |
|
|
144 |
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} ; |
|
|
|
|
|
|
|
145 |
|
|
146 |
if (split.length != 2) { |
if (split.length != 2) { |
147 |
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
player.sendMessage("Usage /platform [radius] [blockID]"); |
148 |
return; |
return; |
149 |
} |
} |
150 |
|
|
|
|
|
151 |
int radius; |
int radius; |
152 |
try { |
try { |
153 |
radius = Integer.parseInt(split[0]); |
radius = Integer.parseInt(split[0]); |
154 |
} catch (Exception e) { |
} catch (Exception e) { |
155 |
player.sendMessage("setsurface: radius must be an integer"); |
player.sendMessage("platform: radius must be an integer"); |
156 |
return; |
return; |
157 |
} |
} |
158 |
|
|
159 |
if (radius > 20) { |
if (radius > 20) { |
160 |
player.sendMessage("setsurface: radius may not exceed 20"); |
player.sendMessage("platform: radius may not exceed 20"); |
161 |
return; |
return; |
162 |
} |
} |
163 |
|
|
|
|
|
164 |
int blockid; |
int blockid; |
165 |
try { |
try { |
166 |
blockid = Integer.parseInt(split[1]); |
blockid = Integer.parseInt(split[1]); |
167 |
} catch (Exception e) { |
} catch (Exception e) { |
168 |
player.sendMessage("setsurface: blockid must be an integer"); |
player.sendMessage("platform: blockid must be an integer"); |
169 |
return; |
return; |
170 |
} |
} |
171 |
|
/* |
172 |
boolean validblock = false; |
boolean validblock = false; |
173 |
for (int i=0; i<valid_block_array.length; i++) { |
for (int i=0; i<valid_block_array.length; i++) { |
174 |
if (valid_block_array[i] == blockid) { |
if (valid_block_array[i] == blockid) { |
180 |
if ( !validblock ) { |
if ( !validblock ) { |
181 |
player.sendMessage("setsurface: block now allowed"); |
player.sendMessage("setsurface: block now allowed"); |
182 |
return; |
return; |
183 |
|
}*/ |
184 |
|
|
185 |
|
int playerX = loc.getBlockX(); |
186 |
|
int playerY = loc.getBlockY(); |
187 |
|
int playerZ = loc.getBlockZ(); |
188 |
|
|
189 |
|
|
190 |
|
World world = loc.getWorld(); |
191 |
|
|
192 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
193 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
194 |
|
int y = playerY - 1; |
195 |
|
|
196 |
|
world.getBlockAt(x, y, z).setTypeId(blockid); |
197 |
|
} |
198 |
|
} |
199 |
|
} |
200 |
|
|
201 |
|
private void setSurface(Player player, Location loc, String[] split) { |
202 |
|
|
203 |
|
if (split.length != 2) { |
204 |
|
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
205 |
|
return; |
206 |
|
} |
207 |
|
|
208 |
|
int radius; |
209 |
|
try { |
210 |
|
radius = Integer.parseInt(split[0]); |
211 |
|
} catch (Exception e) { |
212 |
|
player.sendMessage("setsurface: radius must be an integer"); |
213 |
|
return; |
214 |
|
} |
215 |
|
|
216 |
|
if (radius > 20) { |
217 |
|
player.sendMessage("setsurface: radius may not exceed 20"); |
218 |
|
return; |
219 |
|
} |
220 |
|
|
221 |
|
int blockid; |
222 |
|
try { |
223 |
|
blockid = Integer.parseInt(split[1]); |
224 |
|
} catch (Exception e) { |
225 |
|
player.sendMessage("setsurface: blockid must be an integer"); |
226 |
|
return; |
227 |
|
} |
228 |
|
|
229 |
|
//check if the blockid is in the array of valid blocks |
230 |
|
boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0); |
231 |
|
|
232 |
|
if ( !validblock ) { |
233 |
|
player.sendMessage("setsurface: block now allowed"); |
234 |
|
return; |
235 |
} |
} |
236 |
|
|
237 |
int playerX = loc.getBlockX(); |
int playerX = loc.getBlockX(); |
244 |
} |
} |
245 |
|
|
246 |
World world = loc.getWorld(); |
World world = loc.getWorld(); |
|
|
|
247 |
|
|
248 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
249 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
250 |
//int y = getGroundLevel(x,z) - 1; |
//int y = getGroundLevel(x,z) - 1; |
251 |
int y = world.getHighestBlockYAt(x, z) - 1; |
int y = world.getHighestBlockYAt(x, z) ; |
252 |
|
|
253 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setTypeId(blockid); |
254 |
} |
} |
353 |
|
|
354 |
} |
} |
355 |
} |
} |
356 |
|
|
357 |
|
|
358 |
|
private void resetMap(boolean[][] map) { |
359 |
|
for (int x=0; x<map.length; x++) { |
360 |
|
for (int z=0; z<map[0].length; z++) { |
361 |
|
map[x][z] = false; |
362 |
|
} |
363 |
|
} |
364 |
|
} |
365 |
|
|
366 |
|
private void cylinder(Player player, Location loc, String[] split) { |
367 |
|
if (split.length != 2) { |
368 |
|
player.sendMessage("Usage: /cylinder [radius] [material] "); |
369 |
|
return; |
370 |
|
} |
371 |
|
int material = Integer.parseInt( split[1] ); |
372 |
|
|
373 |
|
int radius = Integer.parseInt(split[0]); |
374 |
|
int diameter = (radius*2) + 1; |
375 |
|
|
376 |
|
boolean map[][] = new boolean[diameter][diameter]; |
377 |
|
resetMap( map ); |
378 |
|
|
379 |
|
/* map[0][0] = true; |
380 |
|
map[0][diameter-1] = true; |
381 |
|
map[diameter-1][0] = true; |
382 |
|
map[diameter-1][diameter-1] = true;*/ |
383 |
|
|
384 |
|
for (int r=0; r<360; r++) { |
385 |
|
double rad = Math.toRadians( r ); |
386 |
|
|
387 |
|
double a = (double) radius * Math.sin( rad); |
388 |
|
double b = (double) radius * Math.cos( rad); |
389 |
|
|
390 |
|
int x = radius + (int)Math.round(a); |
391 |
|
int y = radius + (int)Math.round(b); |
392 |
|
|
393 |
|
map[x][y] = true; |
394 |
|
} |
395 |
|
|
396 |
|
|
397 |
|
drawMap( loc, map, material ); |
398 |
|
} |
399 |
|
|
400 |
|
private void drawMap(Location loc, boolean[][] map, int material) { |
401 |
|
int playerX = loc.getBlockX(); |
402 |
|
int playerY = loc.getBlockY(); |
403 |
|
int playerZ = loc.getBlockZ(); |
404 |
|
|
405 |
|
World world = loc.getWorld(); |
406 |
|
|
407 |
|
for (int i=0; i<map.length; i++) { |
408 |
|
for (int j=0; j<map[0].length; j++) { |
409 |
|
|
410 |
|
int x = playerX + i + 1; |
411 |
|
int z = playerZ + j; |
412 |
|
|
413 |
|
if (map[i][j] == true) { |
414 |
|
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
415 |
|
world.getBlockAt(x, y, z).setTypeId(material); |
416 |
|
} |
417 |
|
} |
418 |
|
|
419 |
|
} |
420 |
|
} |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
|
|
425 |
} |
} |