/[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 1731 by torben, Tue Mar 13 08:45:07 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 68  public class GeneralContractorCommands i Line 109  public class GeneralContractorCommands i
109                          return true;                          return true;
110                  }                  }
111                                    
112                    if ( label.equals("createcave") ) {
113                            if (validateLevelOrFill(player, label, args) ) {
114                                    createCave(player, loc, args);
115                            }
116                            return true;
117                    }
118                                    
119                  if ( label.equals("fillarea") ) {                  if ( label.equals("fillarea") ) {
120                          if (validateLevelOrFill(player, label, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
# Line 91  public class GeneralContractorCommands i Line 138  public class GeneralContractorCommands i
138                          platform(player,loc,args);                          platform(player,loc,args);
139                          return true;                          return true;
140                  }                  }
141    
142                    if (label.equals("cylinder") ) {
143                            if (validateLevelOrFill(player, label, args) ) {
144                                    cylinder(player,loc,args);
145                            }
146                            return true;
147                    }
148                    
149                    
150                  return false;                  return false;
# Line 137  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 154  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 186  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 211  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 231  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 242  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 268  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 288  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 309  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 317  public class GeneralContractorCommands i Line 369  public class GeneralContractorCommands i
369                  }                  }
370          }          }
371    
372            private void createCave(Player player, Location loc, String[] split) {
373    
374                    int radius = Integer.parseInt(split[0]);
375    
376                    System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
377                    
378    
379                    int playerX = loc.getBlockX();
380                    int playerY = loc.getBlockY();
381                    int playerZ = loc.getBlockZ();
382                    
383    
384                    World world = loc.getWorld();
385    
386                    int count = 0;
387                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
388                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
389    
390                                    int y_max = playerY+radius;
391                                    //for (int y=playerY; y<=playerY+radius; y++) {
392                                    for (int y=playerY; y<=y_max; y++) {
393                                            count++;
394                                            world.getBlockAt(x, y, z).setType(Material.AIR);
395                                            
396                                    }
397    
398                            }
399    
400                    }
401            }
402            
403          private void levelArea(Player player, Location loc, String[] split) {          private void levelArea(Player player, Location loc, String[] split) {
404    
405                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
# Line 347  public class GeneralContractorCommands i Line 430  public class GeneralContractorCommands i
430                  }                  }
431          }          }
432                    
433    
434    
435            private void resetMap(boolean[][] map) {
436                    for (int x=0; x<map.length; x++) {
437                            for (int z=0; z<map[0].length; z++) {
438                                    map[x][z] = false;                              
439                            }
440                    }
441            }
442    
443            private void cylinder(Player player, Location loc, String[] split) {
444                    if (split.length != 2) {
445                            player.sendMessage("Usage: /cylinder [radius] [material] ");
446                            return;
447                    }
448    
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]);
456                    int diameter = (radius*2) + 1;
457    
458                    boolean map[][] = new boolean[diameter][diameter];
459                    resetMap( map );
460    
461    /*              map[0][0] = true;
462                    map[0][diameter-1] = true;
463                    map[diameter-1][0] = true;
464                    map[diameter-1][diameter-1] = true;*/
465    
466                    for (int r=0; r<360; r++) {
467                            double rad = Math.toRadians( r );
468    
469                            double a = (double) radius * Math.sin( rad);
470                            double b = (double) radius * Math.cos( rad);
471    
472                            int x = radius + (int)Math.round(a);
473                            int y = radius + (int)Math.round(b);
474    
475                            map[x][y] = true;
476                    }
477    
478            
479                    drawMap( loc, map, material );  
480            }
481    
482            private void drawMap(Location loc, boolean[][] map, Material material) {
483                    int playerX = loc.getBlockX();
484                    int playerY = loc.getBlockY();
485                    int playerZ = loc.getBlockZ();
486    
487                    World world = loc.getWorld();
488    
489                    for (int i=0; i<map.length; i++) {
490                            for (int j=0; j<map[0].length; j++) {
491    
492                                    int x = playerX + i + 1;
493                                    int z = playerZ + j;
494    
495                                    if (map[i][j] == true) {
496                                            for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
497                                                    world.getBlockAt(x, y, z).setType(material);
498                                            }
499                                    }
500                                    
501                            }
502                    }
503            }
504    
505            
506                    
507  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20