/[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 3132 by torben, Sun Mar 18 14:58:22 2012 UTC revision 3133 by torben, Fri Nov 18 13:14:07 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            };
35    //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} ;
36    
37            final Set<Material> valid_materials = new HashSet<Material>();
38    
39          HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();          HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();
40    
41    
42          public GeneralContractorCommands() {          public GeneralContractorCommands() {
43                  Arrays.sort(valid_block_array);                  Arrays.sort(valid_block_array);
44    
45                    for (Material mat : valid_block_array) {
46                            valid_materials.add( mat );
47                    }
48          }          }
49                    
50          //@Override          //@Override
# Line 150  public class GeneralContractorCommands i Line 164  public class GeneralContractorCommands i
164          private void platform(Player player, Location loc, String[] split) {          private void platform(Player player, Location loc, String[] split) {
165    
166                  if (split.length != 2) {                  if (split.length != 2) {
167                          player.sendMessage("Usage /platform [radius] [blockID]");                          player.sendMessage("Usage /platform [radius] [material]");
168                          return;                          return;
169                  }                  }
170    
# Line 167  public class GeneralContractorCommands i Line 181  public class GeneralContractorCommands i
181                          return;                          return;
182                  }                  }
183    
184                  int blockid;                  Material material = Material.matchMaterial( split[1] );
185                  try {                  if (material == null) {
                         blockid = Integer.parseInt(split[1]);  
                 } catch (Exception e) {  
186                          player.sendMessage("platform: blockid must be an integer");                          player.sendMessage("platform: blockid must be an integer");
187                          return;                          return;
188                  }                  }
# Line 199  public class GeneralContractorCommands i Line 211  public class GeneralContractorCommands i
211                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
212                                  int y = playerY - 1;                                  int y = playerY - 1;
213                                                                    
214                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType( material );
215                          }                          }
216                  }                  }
217          }          }
# Line 224  public class GeneralContractorCommands i Line 236  public class GeneralContractorCommands i
236                          return;                          return;
237                  }                  }
238    
239                  int blockid;                  Material material = Material.matchMaterial( split[1] );
240                  try {                  if (material == null) {
241                          blockid = Integer.parseInt(split[1]);                          player.sendMessage("platform: blockid must be an integer");
                 } catch (Exception e) {  
                         player.sendMessage("setsurface: blockid must be an integer");  
242                          return;                          return;
243                  }                  }
244    
245                  //check if the blockid is in the array of valid blocks                  //check if the blockid is in the array of valid blocks
246                  boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0);                  if ( ! valid_materials.contains(material) ) {
   
                 if ( !validblock ) {  
247                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
248                          return;                          return;
249                  }                  }
# Line 244  public class GeneralContractorCommands i Line 252  public class GeneralContractorCommands i
252                  int playerY = loc.getBlockY();                  int playerY = loc.getBlockY();
253                  int playerZ = loc.getBlockZ();                  int playerZ = loc.getBlockZ();
254    
255                  if(playerY <= 2 && blockid != 7) {                  if(playerY <= 2 && material != Material.BEDROCK ) {
256                          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)");
257                          return;                          return;
258                  }                  }
# Line 256  public class GeneralContractorCommands i Line 264  public class GeneralContractorCommands i
264                                  //int y = getGroundLevel(x,z) - 1;                                  //int y = getGroundLevel(x,z) - 1;
265                                  int y = world.getHighestBlockYAt(x, z) ;                                  int y = world.getHighestBlockYAt(x, z) ;
266                                                                    
267                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType(material);
268                          }                          }
269                  }                  }
270          }          }
# Line 301  public class GeneralContractorCommands i Line 309  public class GeneralContractorCommands i
309          private void fillArea(Player player, Location loc, String[] split) {          private void fillArea(Player player, Location loc, String[] split) {
310                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
311                                    
312                  int material = Material.DIRT.getId();                  Material material = Material.DIRT;
313    
314                                    
315                  if (split.length == 2) {                  if (split.length == 2) {
316                          material = Integer.parseInt( split[1] );                          material = Material.matchMaterial( split[1] );
317                            if (material == null) {
318                                    player.sendMessage("Unknown material: " + split[1] );
319                                    return;
320                            }
321                  }                  }
322    
323                  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 335  public class GeneralContractorCommands i
335                                                                    
336    
337                                  for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                                                      for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
338                                          world.getBlockAt(x, y, z).setTypeId(material);                                          world.getBlockAt(x, y, z).setType( material );
339                                  }                                  }
340    
341                          }                          }
# Line 406  public class GeneralContractorCommands i Line 419  public class GeneralContractorCommands i
419                          player.sendMessage("Usage: /cylinder [radius] [material] ");                          player.sendMessage("Usage: /cylinder [radius] [material] ");
420                          return;                          return;
421                  }                  }
422                  int material = Integer.parseInt( split[1] );  
423                    Material material = Material.matchMaterial( split[1] );
424                    if ( material == null) {
425                            player.sendMessage("/cylinder: unknown material: " + split[1]);
426                            return;
427                    }
428    
429                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
430                  int diameter = (radius*2) + 1;                  int diameter = (radius*2) + 1;
# Line 435  public class GeneralContractorCommands i Line 453  public class GeneralContractorCommands i
453                  drawMap( loc, map, material );                    drawMap( loc, map, material );  
454          }          }
455    
456          private void drawMap(Location loc, boolean[][] map, int material) {          private void drawMap(Location loc, boolean[][] map, Material material) {
457                  int playerX = loc.getBlockX();                  int playerX = loc.getBlockX();
458                  int playerY = loc.getBlockY();                  int playerY = loc.getBlockY();
459                  int playerZ = loc.getBlockZ();                  int playerZ = loc.getBlockZ();
# Line 450  public class GeneralContractorCommands i Line 468  public class GeneralContractorCommands i
468    
469                                  if (map[i][j] == true) {                                  if (map[i][j] == true) {
470                                          for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                                                              for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
471                                                  world.getBlockAt(x, y, z).setTypeId(material);                                                  world.getBlockAt(x, y, z).setType(material);
472                                          }                                          }
473                                  }                                  }
474                                                                    

Legend:
Removed from v.3132  
changed lines
  Added in v.3133

  ViewVC Help
Powered by ViewVC 1.1.20