/[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 1730 by torben, Tue Mar 13 08:30:39 2012 UTC revision 3196 by torben, Mon May 29 13:03:52 2017 UTC
# Line 9  import org.bukkit.command.CommandExecuto Line 9  import org.bukkit.command.CommandExecuto
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;  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 23  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() {
70                    Arrays.sort(valid_block_array);
71    
72                    for (Material mat : valid_block_array) {
73                            valid_materials.add( mat );
74                    }
75            }
76                    
77          //@Override          //@Override
78          public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {          public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
# Line 64  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 71  public class GeneralContractorCommands i Line 122  public class GeneralContractorCommands i
122                          }                                }      
123                          return true;                          return true;
124                  }                  }
125    
126                    if (label.equals("levelandfillarea") ) {
127                            if (validateLevelOrFill(player, label, args) ) {
128    
129                                    levelArea(player, loc, args);
130                                    fillArea(player, loc, args);                            
131                                    setSurface(player, loc, args);  
132    
133                            }
134                    }              
135                                    
136                  if ( label.equals("slopearea") ) {                  if ( label.equals("slopearea") ) {
137                          slopeArea(player, loc, args);                            slopeArea(player, loc, args);  
# Line 87  public class GeneralContractorCommands i Line 148  public class GeneralContractorCommands i
148                          platform(player,loc,args);                          platform(player,loc,args);
149                          return true;                          return true;
150                  }                  }
151    
152                    if (label.equals("cylinder") ) {
153                            if (validateLevelOrFill(player, label, args) ) {
154                                    cylinder(player,loc,args);
155                            }
156                            return true;
157                    }
158    
159    
160                    
161                    
162                  return false;                  return false;
# Line 133  public class GeneralContractorCommands i Line 203  public class GeneralContractorCommands i
203          private void platform(Player player, Location loc, String[] split) {          private void platform(Player player, Location loc, String[] split) {
204    
205                  if (split.length != 2) {                  if (split.length != 2) {
206                          player.sendMessage("Usage /platform [radius] [blockID]");                          player.sendMessage("Usage /platform [radius] [material]");
207                          return;                          return;
208                  }                  }
209    
# Line 145  public class GeneralContractorCommands i Line 215  public class GeneralContractorCommands i
215                          return;                          return;
216                  }                  }
217    
218                  if (radius > 20) {                  if (radius > 25) {
219                          player.sendMessage("platform: radius may not exceed 20");                          player.sendMessage("platform: radius may not exceed 25");
220                          return;                          return;
221                  }                  }
222    
223                  int blockid;                  Material material = Material.matchMaterial( split[1] );
224                  try {                  if (material == null) {
225                          blockid = Integer.parseInt(split[1]);                          player.sendMessage("platform: unknown material: " + split[1] );
                 } catch (Exception e) {  
                         player.sendMessage("platform: blockid must be an integer");  
226                          return;                          return;
227                  }                  }
228  /*  /*
# Line 182  public class GeneralContractorCommands i Line 250  public class GeneralContractorCommands i
250                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
251                                  int y = playerY - 1;                                  int y = playerY - 1;
252                                                                    
253                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType( material );
254                          }                          }
255                  }                  }
256          }          }
# Line 202  public class GeneralContractorCommands i Line 270  public class GeneralContractorCommands i
270                          return;                          return;
271                  }                  }
272    
273                  if (radius > 20) {                  if (radius > 25) {
274                          player.sendMessage("setsurface: radius may not exceed 20");                          player.sendMessage("setsurface: radius may not exceed 25");
275                          return;                          return;
276                  }                  }
277    
278                  int blockid;                  Material material = Material.matchMaterial( split[1] );
279                  try {                  if (material == null) {
280                          blockid = Integer.parseInt(split[1]);                          player.sendMessage("setsurface: unknown material: " + split[1] );
                 } catch (Exception e) {  
                         player.sendMessage("setsurface: blockid must be an integer");  
281                          return;                          return;
282                  }                  }
283    
284                  boolean validblock = false;                  //check if the blockid is in the array of valid blocks
285                  for (int i=0; i<valid_block_array.length; i++) {                  if ( ! valid_materials.contains(material) ) {
                         if (valid_block_array[i] == blockid) {  
                                 validblock = true;  
                                 break;  
                         }  
                 }  
   
                 if ( !validblock ) {  
286                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
287                          return;                          return;
288                  }                  }
# Line 232  public class GeneralContractorCommands i Line 291  public class GeneralContractorCommands i
291                  int playerY = loc.getBlockY();                  int playerY = loc.getBlockY();
292                  int playerZ = loc.getBlockZ();                  int playerZ = loc.getBlockZ();
293    
294                  if(playerY <= 2 && blockid != 7) {                  if(playerY <= 2 && material != Material.BEDROCK ) {
295                          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)");
296                          return;                          return;
297                  }                  }
# Line 243  public class GeneralContractorCommands i Line 302  public class GeneralContractorCommands i
302                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
303                                  //int y = getGroundLevel(x,z) - 1;                                  //int y = getGroundLevel(x,z) - 1;
304                                  int y = world.getHighestBlockYAt(x, z) ;                                  int y = world.getHighestBlockYAt(x, z) ;
305                                    y -= 1;
306                                                                    
307                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType(material);
308                          }                          }
309                  }                  }
310          }          }
# Line 263  public class GeneralContractorCommands i Line 323  public class GeneralContractorCommands i
323                          return false;                          return false;
324                  }                  }
325    
326                  if (radius > 20) {                  if (radius > 25) {
327                          player.sendMessage(label + ": radius may not exceed 20");                          player.sendMessage(label + ": radius may not exceed 25");
328                          return false;                          return false;
329                  }                  }
330                                    
331                  if (split.length == 2) {                  if (split.length == 2) {
332                          int id;                          Material material = Material.matchMaterial( split[1] );
333                          try {                          if (material == null) {
334                                  id = Integer.parseInt( split[1] );                                  player.sendMessage(label + ": unknown material: " + split[1] );
                         } catch (Exception e) {  
                                 player.sendMessage(label + ": id must be an integer");  
335                                  return false;                                  return false;
336                          }                          }
337                          if ( id == 46) {                          if ( material == Material.TNT) {
338                                  player.sendMessage("Sorry dave, i can't do that");                                  player.sendMessage("Sorry dave, i can't do that");
339                                  return false;                                  return false;
340                          }                          }
# Line 289  public class GeneralContractorCommands i Line 347  public class GeneralContractorCommands i
347          private void fillArea(Player player, Location loc, String[] split) {          private void fillArea(Player player, Location loc, String[] split) {
348                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
349                                    
350                  int material = Material.DIRT.getId();                  Material material = Material.DIRT;
351    
352                                    
353                  if (split.length == 2) {                  if (split.length == 2) {
354                          material = Integer.parseInt( split[1] );                          material = Material.matchMaterial( split[1] );
355                            if (material == null) {
356                                    player.sendMessage("Unknown material: " + split[1] );
357                                    return;
358                            }
359                  }                  }
360    
361                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
# Line 310  public class GeneralContractorCommands i Line 373  public class GeneralContractorCommands i
373                                                                    
374    
375                                  for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                                                      for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
376                                          world.getBlockAt(x, y, z).setTypeId(material);                                          world.getBlockAt(x, y, z).setType( material );
377                                  }                                  }
378    
379                          }                          }
# Line 318  public class GeneralContractorCommands i Line 381  public class GeneralContractorCommands i
381                  }                  }
382          }          }
383    
384            private void createCave(Player player, Location loc, String[] split) {
385    
386                    int radius = Integer.parseInt(split[0]);
387    
388                    System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
389                    
390    
391                    int playerX = loc.getBlockX();
392                    int playerY = loc.getBlockY();
393                    int playerZ = loc.getBlockZ();
394                    
395    
396                    World world = loc.getWorld();
397    
398                    int count = 0;
399                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
400                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
401    
402                                    int y_max = playerY+radius;
403                                    //for (int y=playerY; y<=playerY+radius; y++) {
404                                    for (int y=playerY; y<=y_max; y++) {
405                                            count++;
406                                            world.getBlockAt(x, y, z).setType(Material.AIR);
407                                            
408                                    }
409    
410                            }
411    
412                    }
413            }
414            
415          private void levelArea(Player player, Location loc, String[] split) {          private void levelArea(Player player, Location loc, String[] split) {
416    
417                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
# Line 348  public class GeneralContractorCommands i Line 442  public class GeneralContractorCommands i
442                  }                  }
443          }          }
444                    
445    
446    
447            private void resetMap(boolean[][] map) {
448                    for (int x=0; x<map.length; x++) {
449                            for (int z=0; z<map[0].length; z++) {
450                                    map[x][z] = false;                              
451                            }
452                    }
453            }
454    
455            private void cylinder(Player player, Location loc, String[] split) {
456                    if (split.length != 2) {
457                            player.sendMessage("Usage: /cylinder [radius] [material] ");
458                            return;
459                    }
460    
461                    Material material = Material.matchMaterial( split[1] );
462                    if ( material == null) {
463                            player.sendMessage("/cylinder: unknown material: " + split[1]);
464                            return;
465                    }
466    
467                    int radius = Integer.parseInt(split[0]);
468                    int diameter = (radius*2) + 1;
469    
470                    boolean map[][] = new boolean[diameter][diameter];
471                    resetMap( map );
472    
473    /*              map[0][0] = true;
474                    map[0][diameter-1] = true;
475                    map[diameter-1][0] = true;
476                    map[diameter-1][diameter-1] = true;*/
477    
478                    for (int r=0; r<360; r++) {
479                            double rad = Math.toRadians( r );
480    
481                            double a = (double) radius * Math.sin( rad);
482                            double b = (double) radius * Math.cos( rad);
483    
484                            int x = radius + (int)Math.round(a);
485                            int y = radius + (int)Math.round(b);
486    
487                            map[x][y] = true;
488                    }
489    
490            
491                    drawMap( loc, map, material );  
492            }
493    
494            private void drawMap(Location loc, boolean[][] map, Material material) {
495                    int playerX = loc.getBlockX();
496                    int playerY = loc.getBlockY();
497                    int playerZ = loc.getBlockZ();
498    
499                    World world = loc.getWorld();
500    
501                    for (int i=0; i<map.length; i++) {
502                            for (int j=0; j<map[0].length; j++) {
503    
504                                    int x = playerX + i + 1;
505                                    int z = playerZ + j;
506    
507                                    if (map[i][j] == true) {
508                                            for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
509                                                    world.getBlockAt(x, y, z).setType(material);
510                                            }
511                                    }
512                                    
513                            }
514                    }
515            }
516    
517            
518                    
519  }  }

Legend:
Removed from v.1730  
changed lines
  Added in v.3196

  ViewVC Help
Powered by ViewVC 1.1.20