/[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 1751 by torben, Sun Mar 18 14:58:22 2012 UTC revision 3141 by torben, Fri Nov 18 21:12:47 2016 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                            Material.WOOD,
35                            Material.BEDROCK,
36                            Material.WATER,
37                            Material.SAND,
38                            Material.GRAVEL,
39                            Material.GOLD_ORE,
40                            Material.IRON_ORE,
41                            Material.COAL_ORE,
42                            Material.LOG,
43                            Material.LEAVES,
44                            Material.GLASS,
45                            Material.LAPIS_ORE,
46                            Material.LAPIS_BLOCK,
47                            Material.SANDSTONE,
48                            Material.WOOL,
49                            Material.GOLD_BLOCK,
50                            Material.IRON_BLOCK,
51                            Material.BRICK,
52                            Material.MOSSY_COBBLESTONE,
53                            Material.OBSIDIAN,
54                            Material.DIAMOND_ORE,
55                            Material.DIAMOND_BLOCK,
56                            Material.ICE,
57                            Material.SNOW,
58                            Material.CLAY,
59                            Material.NETHERRACK,
60                            Material.SOUL_SAND
61            };
62    //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} ;
63    
64            final Set<Material> valid_materials = new HashSet<Material>();
65    
66          HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();          HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();
67    
68    
69          public GeneralContractorCommands() {          public GeneralContractorCommands() {
70                  Arrays.sort(valid_block_array);                  Arrays.sort(valid_block_array);
71    
72                    for (Material mat : valid_block_array) {
73                            valid_materials.add( mat );
74                    }
75          }          }
76                    
77          //@Override          //@Override
# Line 150  public class GeneralContractorCommands i Line 191  public class GeneralContractorCommands i
191          private void platform(Player player, Location loc, String[] split) {          private void platform(Player player, Location loc, String[] split) {
192    
193                  if (split.length != 2) {                  if (split.length != 2) {
194                          player.sendMessage("Usage /platform [radius] [blockID]");                          player.sendMessage("Usage /platform [radius] [material]");
195                          return;                          return;
196                  }                  }
197    
# Line 167  public class GeneralContractorCommands i Line 208  public class GeneralContractorCommands i
208                          return;                          return;
209                  }                  }
210    
211                  int blockid;                  Material material = Material.matchMaterial( split[1] );
212                  try {                  if (material == null) {
213                          blockid = Integer.parseInt(split[1]);                          player.sendMessage("platform: unknown material: " + split[1] );
                 } catch (Exception e) {  
                         player.sendMessage("platform: blockid must be an integer");  
214                          return;                          return;
215                  }                  }
216  /*  /*
# Line 199  public class GeneralContractorCommands i Line 238  public class GeneralContractorCommands i
238                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
239                                  int y = playerY - 1;                                  int y = playerY - 1;
240                                                                    
241                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType( material );
242                          }                          }
243                  }                  }
244          }          }
# Line 224  public class GeneralContractorCommands i Line 263  public class GeneralContractorCommands i
263                          return;                          return;
264                  }                  }
265    
266                  int blockid;                  Material material = Material.matchMaterial( split[1] );
267                  try {                  if (material == null) {
268                          blockid = Integer.parseInt(split[1]);                          player.sendMessage("setsurface: unknown material: " + split[1] );
                 } catch (Exception e) {  
                         player.sendMessage("setsurface: blockid must be an integer");  
269                          return;                          return;
270                  }                  }
271    
272                  //check if the blockid is in the array of valid blocks                  //check if the blockid is in the array of valid blocks
273                  boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0);                  if ( ! valid_materials.contains(material) ) {
   
                 if ( !validblock ) {  
274                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
275                          return;                          return;
276                  }                  }
# Line 244  public class GeneralContractorCommands i Line 279  public class GeneralContractorCommands i
279                  int playerY = loc.getBlockY();                  int playerY = loc.getBlockY();
280                  int playerZ = loc.getBlockZ();                  int playerZ = loc.getBlockZ();
281    
282                  if(playerY <= 2 && blockid != 7) {                  if(playerY <= 2 && material != Material.BEDROCK ) {
283                          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)");
284                          return;                          return;
285                  }                  }
# Line 255  public class GeneralContractorCommands i Line 290  public class GeneralContractorCommands i
290                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
291                                  //int y = getGroundLevel(x,z) - 1;                                  //int y = getGroundLevel(x,z) - 1;
292                                  int y = world.getHighestBlockYAt(x, z) ;                                  int y = world.getHighestBlockYAt(x, z) ;
293                                    y -= 1;
294                                                                    
295                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType(material);
296                          }                          }
297                  }                  }
298          }          }
# Line 281  public class GeneralContractorCommands i Line 317  public class GeneralContractorCommands i
317                  }                  }
318                                    
319                  if (split.length == 2) {                  if (split.length == 2) {
320                          int id;                          Material material = Material.matchMaterial( split[1] );
321                          try {                          if (material == null) {
322                                  id = Integer.parseInt( split[1] );                                  player.sendMessage(label + ": unknown material: " + split[1] );
                         } catch (Exception e) {  
                                 player.sendMessage(label + ": id must be an integer");  
323                                  return false;                                  return false;
324                          }                          }
325                          if ( id == 46) {                          if ( material == Material.TNT) {
326                                  player.sendMessage("Sorry dave, i can't do that");                                  player.sendMessage("Sorry dave, i can't do that");
327                                  return false;                                  return false;
328                          }                          }
# Line 301  public class GeneralContractorCommands i Line 335  public class GeneralContractorCommands i
335          private void fillArea(Player player, Location loc, String[] split) {          private void fillArea(Player player, Location loc, String[] split) {
336                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
337                                    
338                  int material = Material.DIRT.getId();                  Material material = Material.DIRT;
339    
340                                    
341                  if (split.length == 2) {                  if (split.length == 2) {
342                          material = Integer.parseInt( split[1] );                          material = Material.matchMaterial( split[1] );
343                            if (material == null) {
344                                    player.sendMessage("Unknown material: " + split[1] );
345                                    return;
346                            }
347                  }                  }
348    
349                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
# Line 322  public class GeneralContractorCommands i Line 361  public class GeneralContractorCommands i
361                                                                    
362    
363                                  for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                                                      for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
364                                          world.getBlockAt(x, y, z).setTypeId(material);                                          world.getBlockAt(x, y, z).setType( material );
365                                  }                                  }
366    
367                          }                          }
# Line 406  public class GeneralContractorCommands i Line 445  public class GeneralContractorCommands i
445                          player.sendMessage("Usage: /cylinder [radius] [material] ");                          player.sendMessage("Usage: /cylinder [radius] [material] ");
446                          return;                          return;
447                  }                  }
448                  int material = Integer.parseInt( split[1] );  
449                    Material material = Material.matchMaterial( split[1] );
450                    if ( material == null) {
451                            player.sendMessage("/cylinder: unknown material: " + split[1]);
452                            return;
453                    }
454    
455                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
456                  int diameter = (radius*2) + 1;                  int diameter = (radius*2) + 1;
# Line 435  public class GeneralContractorCommands i Line 479  public class GeneralContractorCommands i
479                  drawMap( loc, map, material );                    drawMap( loc, map, material );  
480          }          }
481    
482          private void drawMap(Location loc, boolean[][] map, int material) {          private void drawMap(Location loc, boolean[][] map, Material material) {
483                  int playerX = loc.getBlockX();                  int playerX = loc.getBlockX();
484                  int playerY = loc.getBlockY();                  int playerY = loc.getBlockY();
485                  int playerZ = loc.getBlockZ();                  int playerZ = loc.getBlockZ();
# Line 450  public class GeneralContractorCommands i Line 494  public class GeneralContractorCommands i
494    
495                                  if (map[i][j] == true) {                                  if (map[i][j] == true) {
496                                          for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                                                              for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
497                                                  world.getBlockAt(x, y, z).setTypeId(material);                                                  world.getBlockAt(x, y, z).setType(material);
498                                          }                                          }
499                                  }                                  }
500                                                                    

Legend:
Removed from v.1751  
changed lines
  Added in v.3141

  ViewVC Help
Powered by ViewVC 1.1.20