/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/creative/GeneralContractorCommands.java
ViewVC logotype

Diff of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/creative/GeneralContractorCommands.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1733 by torben, Wed Mar 14 20:25:27 2012 UTC revision 3239 by torben, Wed Jul 18 07:59:05 2018 UTC
# Line 11  import org.bukkit.entity.Player; Line 11  import org.bukkit.entity.Player;
11    
12  import java.util.Arrays;  import java.util.Arrays;
13  import java.util.HashMap;  import java.util.HashMap;
14    import java.util.HashSet;
15    import java.util.Set;
16    
17  public class GeneralContractorCommands implements CommandExecutor{  public class GeneralContractorCommands implements CommandExecutor{
18    
# Line 24  public class GeneralContractorCommands i Line 26  public class GeneralContractorCommands i
26          }          }
27    
28          final static int Y_MAX = 255;          final static int Y_MAX = 255;
29          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} ;          final Material valid_block_array[] = {
30                            Material.STONE,
31                            Material.GRASS,
32                            Material.DIRT,
33                            Material.COBBLESTONE,
34                            
35                            //Material.WOOD,
36                            Material.ACACIA_WOOD,
37                            Material.BIRCH_WOOD,
38                            Material.DARK_OAK_WOOD,
39                            Material.JUNGLE_WOOD,
40                            Material.OAK_WOOD,
41                            Material.SPRUCE_WOOD,
42    
43                            Material.BEDROCK,
44                            Material.WATER,
45                            Material.SAND,
46                            Material.GRAVEL,
47                            Material.GOLD_ORE,
48                            Material.IRON_ORE,
49                            Material.COAL_ORE,
50                            
51                            //Material.LOG,
52                            Material.ACACIA_LOG,
53                            Material.BIRCH_LOG,
54                            Material.DARK_OAK_LOG,
55                            Material.JUNGLE_LOG,
56                            Material.OAK_LOG,
57                            Material.SPRUCE_LOG,
58                            //Material.LEAVES,
59                            Material.ACACIA_LEAVES,
60                            Material.BIRCH_LEAVES,
61                            Material.DARK_OAK_LEAVES,
62                            Material.JUNGLE_LEAVES,
63                            Material.OAK_LEAVES,
64                            Material.SPRUCE_LEAVES,
65                            
66                            Material.GLASS,
67                            Material.LAPIS_ORE,
68                            Material.LAPIS_BLOCK,
69                            Material.SANDSTONE,
70                            //Material.WOOL,
71                            Material.BLACK_WOOL,
72                            Material.WHITE_WOOL,
73                            Material.GRAY_WOOL,
74                            
75                            Material.GOLD_BLOCK,
76                            Material.IRON_BLOCK,
77                            Material.BRICK,
78                            Material.MOSSY_COBBLESTONE,
79                            Material.OBSIDIAN,
80                            Material.DIAMOND_ORE,
81                            Material.DIAMOND_BLOCK,
82                            Material.ICE,
83                            Material.SNOW,
84                            Material.CLAY,
85                            Material.NETHERRACK,
86                            Material.SOUL_SAND
87            };
88    //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} ;
89    
90            final Set<Material> valid_materials = new HashSet<Material>();
91    
92          HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();          HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();
93    
94    
95          public GeneralContractorCommands() {          public GeneralContractorCommands() {
96                  Arrays.sort(valid_block_array);                  Arrays.sort(valid_block_array);
97    
98                    for (Material mat : valid_block_array) {
99                            valid_materials.add( mat );
100                    }
101          }          }
102                    
103          //@Override          //@Override
# Line 68  public class GeneralContractorCommands i Line 135  public class GeneralContractorCommands i
135                          return true;                          return true;
136                  }                  }
137                                    
138                    if ( label.equals("createcave") ) {
139                            if (validateLevelOrFill(player, label, args) ) {
140                                    createCave(player, loc, args);
141                            }
142                            return true;
143                    }
144                                    
145                  if ( label.equals("fillarea") ) {                  if ( label.equals("fillarea") ) {
146                          if (validateLevelOrFill(player, label, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
# Line 75  public class GeneralContractorCommands i Line 148  public class GeneralContractorCommands i
148                          }                                }      
149                          return true;                          return true;
150                  }                  }
151    
152                    if (label.equals("levelandfillarea") ) {
153                            if (validateLevelOrFill(player, label, args) ) {
154    
155                                    levelArea(player, loc, args);
156                                    fillArea(player, loc, args);                            
157                                    setSurface(player, loc, args);  
158    
159                            }
160                    }              
161                                    
162                  if ( label.equals("slopearea") ) {                  if ( label.equals("slopearea") ) {
163                          slopeArea(player, loc, args);                            slopeArea(player, loc, args);  
# Line 98  public class GeneralContractorCommands i Line 181  public class GeneralContractorCommands i
181                          }                          }
182                          return true;                          return true;
183                  }                  }
184    
185    
186                    
187                    
188                  return false;                  return false;
# Line 144  public class GeneralContractorCommands i Line 229  public class GeneralContractorCommands i
229          private void platform(Player player, Location loc, String[] split) {          private void platform(Player player, Location loc, String[] split) {
230    
231                  if (split.length != 2) {                  if (split.length != 2) {
232                          player.sendMessage("Usage /platform [radius] [blockID]");                          player.sendMessage("Usage /platform [radius] [material]");
233                          return;                          return;
234                  }                  }
235    
# Line 156  public class GeneralContractorCommands i Line 241  public class GeneralContractorCommands i
241                          return;                          return;
242                  }                  }
243    
244                  if (radius > 20) {                  if (radius > 25) {
245                          player.sendMessage("platform: radius may not exceed 20");                          player.sendMessage("platform: radius may not exceed 25");
246                          return;                          return;
247                  }                  }
248    
249                  int blockid;                  Material material = Material.matchMaterial( split[1] );
250                  try {                  if (material == null) {
251                          blockid = Integer.parseInt(split[1]);                          player.sendMessage("platform: unknown material: " + split[1] );
                 } catch (Exception e) {  
                         player.sendMessage("platform: blockid must be an integer");  
252                          return;                          return;
253                  }                  }
254  /*  /*
# Line 193  public class GeneralContractorCommands i Line 276  public class GeneralContractorCommands i
276                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
277                                  int y = playerY - 1;                                  int y = playerY - 1;
278                                                                    
279                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType( material );
280                          }                          }
281                  }                  }
282          }          }
# Line 213  public class GeneralContractorCommands i Line 296  public class GeneralContractorCommands i
296                          return;                          return;
297                  }                  }
298    
299                  if (radius > 20) {                  if (radius > 25) {
300                          player.sendMessage("setsurface: radius may not exceed 20");                          player.sendMessage("setsurface: radius may not exceed 25");
301                          return;                          return;
302                  }                  }
303    
304                  int blockid;                  Material material = Material.matchMaterial( split[1] );
305                  try {                  if (material == null) {
306                          blockid = Integer.parseInt(split[1]);                          player.sendMessage("setsurface: unknown material: " + split[1] );
                 } catch (Exception e) {  
                         player.sendMessage("setsurface: blockid must be an integer");  
307                          return;                          return;
308                  }                  }
309    
310                  //check if the blockid is in the array of valid blocks                  //check if the blockid is in the array of valid blocks
311                  boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0);                  if ( ! valid_materials.contains(material) ) {
   
                 if ( !validblock ) {  
312                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
313                          return;                          return;
314                  }                  }
# Line 238  public class GeneralContractorCommands i Line 317  public class GeneralContractorCommands i
317                  int playerY = loc.getBlockY();                  int playerY = loc.getBlockY();
318                  int playerZ = loc.getBlockZ();                  int playerZ = loc.getBlockZ();
319    
320                  if(playerY <= 2 && blockid != 7) {                  if(playerY <= 2 && material != Material.BEDROCK ) {
321                          player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");                          player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");
322                          return;                          return;
323                  }                  }
# Line 249  public class GeneralContractorCommands i Line 328  public class GeneralContractorCommands i
328                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
329                                  //int y = getGroundLevel(x,z) - 1;                                  //int y = getGroundLevel(x,z) - 1;
330                                  int y = world.getHighestBlockYAt(x, z) ;                                  int y = world.getHighestBlockYAt(x, z) ;
331                                    y -= 1;
332                                                                    
333                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType(material);
334                          }                          }
335                  }                  }
336          }          }
# Line 269  public class GeneralContractorCommands i Line 349  public class GeneralContractorCommands i
349                          return false;                          return false;
350                  }                  }
351    
352                  if (radius > 20) {                  if (radius > 25) {
353                          player.sendMessage(label + ": radius may not exceed 20");                          player.sendMessage(label + ": radius may not exceed 25");
354                          return false;                          return false;
355                  }                  }
356                                    
357                  if (split.length == 2) {                  if (split.length == 2) {
358                          int id;                          Material material = Material.matchMaterial( split[1] );
359                          try {                          if (material == null) {
360                                  id = Integer.parseInt( split[1] );                                  player.sendMessage(label + ": unknown material: " + split[1] );
                         } catch (Exception e) {  
                                 player.sendMessage(label + ": id must be an integer");  
361                                  return false;                                  return false;
362                          }                          }
363                          if ( id == 46) {                          if ( material == Material.TNT) {
364                                  player.sendMessage("Sorry dave, i can't do that");                                  player.sendMessage("Sorry dave, i can't do that");
365                                  return false;                                  return false;
366                          }                          }
# Line 295  public class GeneralContractorCommands i Line 373  public class GeneralContractorCommands i
373          private void fillArea(Player player, Location loc, String[] split) {          private void fillArea(Player player, Location loc, String[] split) {
374                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
375                                    
376                  int material = Material.DIRT.getId();                  Material material = Material.DIRT;
377    
378                                    
379                  if (split.length == 2) {                  if (split.length == 2) {
380                          material = Integer.parseInt( split[1] );                          material = Material.matchMaterial( split[1] );
381                            if (material == null) {
382                                    player.sendMessage("Unknown material: " + split[1] );
383                                    return;
384                            }
385                  }                  }
386    
387                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
# Line 316  public class GeneralContractorCommands i Line 399  public class GeneralContractorCommands i
399                                                                    
400    
401                                  for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                                                      for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
402                                          world.getBlockAt(x, y, z).setTypeId(material);                                          world.getBlockAt(x, y, z).setType( material );
403                                  }                                  }
404    
405                          }                          }
# Line 324  public class GeneralContractorCommands i Line 407  public class GeneralContractorCommands i
407                  }                  }
408          }          }
409    
410            private void createCave(Player player, Location loc, String[] split) {
411    
412                    int radius = Integer.parseInt(split[0]);
413    
414                    System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
415                    
416    
417                    int playerX = loc.getBlockX();
418                    int playerY = loc.getBlockY();
419                    int playerZ = loc.getBlockZ();
420                    
421    
422                    World world = loc.getWorld();
423    
424                    
425                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
426                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
427    
428                                    int y_max = playerY+radius;
429                                    //for (int y=playerY; y<=playerY+radius; y++) {
430                                    for (int y=playerY; y<=y_max; y++) {
431    
432                                            world.getBlockAt(x, y, z).setType(Material.AIR);
433                                            
434                                    }
435    
436                            }
437    
438                    }
439            }
440            
441          private void levelArea(Player player, Location loc, String[] split) {          private void levelArea(Player player, Location loc, String[] split) {
442    
443                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
# Line 338  public class GeneralContractorCommands i Line 452  public class GeneralContractorCommands i
452    
453                  World world = loc.getWorld();                  World world = loc.getWorld();
454    
                 int count = 0;  
455                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {
456                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
457    
458                                  //for (int y=playerY; y<=playerY+radius; y++) {                                  //for (int y=playerY; y<=playerY+radius; y++) {
459                                  for (int y=playerY; y<=Y_MAX; y++) {                                  for (int y=playerY; y<=Y_MAX; y++) {
                                         count++;  
460                                          world.getBlockAt(x, y, z).setType(Material.AIR);                                          world.getBlockAt(x, y, z).setType(Material.AIR);
461                                                                                    
462                                  }                                  }
# Line 353  public class GeneralContractorCommands i Line 465  public class GeneralContractorCommands i
465    
466                  }                  }
467          }          }
468            
469    
470    
471          private void resetMap(boolean[][] map) {          private void resetMap(boolean[][] map) {
# Line 368  public class GeneralContractorCommands i Line 481  public class GeneralContractorCommands i
481                          player.sendMessage("Usage: /cylinder [radius] [material] ");                          player.sendMessage("Usage: /cylinder [radius] [material] ");
482                          return;                          return;
483                  }                  }
484                  int material = Integer.parseInt( split[1] );  
485                    Material material = Material.matchMaterial( split[1] );
486                    if ( material == null) {
487                            player.sendMessage("/cylinder: unknown material: " + split[1]);
488                            return;
489                    }
490    
491                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
492                  int diameter = (radius*2) + 1;                  int diameter = (radius*2) + 1;
# Line 397  public class GeneralContractorCommands i Line 515  public class GeneralContractorCommands i
515                  drawMap( loc, map, material );                    drawMap( loc, map, material );  
516          }          }
517    
518          private void drawMap(Location loc, boolean[][] map, int material) {          private void drawMap(Location loc, boolean[][] map, Material material) {
519                  int playerX = loc.getBlockX();                  int playerX = loc.getBlockX();
520                  int playerY = loc.getBlockY();                  int playerY = loc.getBlockY();
521                  int playerZ = loc.getBlockZ();                  int playerZ = loc.getBlockZ();
# Line 412  public class GeneralContractorCommands i Line 530  public class GeneralContractorCommands i
530    
531                                  if (map[i][j] == true) {                                  if (map[i][j] == true) {
532                                          for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                                                              for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
533                                                  world.getBlockAt(x, y, z).setTypeId(material);                                                  world.getBlockAt(x, y, z).setType(material);
534                                          }                                          }
535                                  }                                  }
536                                                                    

Legend:
Removed from v.1733  
changed lines
  Added in v.3239

  ViewVC Help
Powered by ViewVC 1.1.20