/[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 1751 by torben, Sun Mar 18 14:58:22 2012 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    
15  public class GeneralContractorCommands implements CommandExecutor{  public class GeneralContractorCommands implements CommandExecutor{
# Line 28  public class GeneralContractorCommands i Line 29  public class GeneralContractorCommands i
29          HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();          HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();
30    
31    
32            public GeneralContractorCommands() {
33                    Arrays.sort(valid_block_array);
34            }
35                    
36          //@Override          //@Override
37          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 68  public class GeneralContractorCommands i
68                          return true;                          return true;
69                  }                  }
70                                    
71                    if ( label.equals("createcave") ) {
72                            if (validateLevelOrFill(player, label, args) ) {
73                                    createCave(player, loc, args);
74                            }
75                            return true;
76                    }
77                                    
78                  if ( label.equals("fillarea") ) {                  if ( label.equals("fillarea") ) {
79                          if (validateLevelOrFill(player, label, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
# Line 87  public class GeneralContractorCommands i Line 97  public class GeneralContractorCommands i
97                          platform(player,loc,args);                          platform(player,loc,args);
98                          return true;                          return true;
99                  }                  }
100    
101                    if (label.equals("cylinder") ) {
102                            if (validateLevelOrFill(player, label, args) ) {
103                                    cylinder(player,loc,args);
104                            }
105                            return true;
106                    }
107                    
108                    
109                  return false;                  return false;
# Line 215  public class GeneralContractorCommands i Line 232  public class GeneralContractorCommands i
232                          return;                          return;
233                  }                  }
234    
235                  boolean validblock = false;                  //check if the blockid is in the array of valid blocks
236                  for (int i=0; i<valid_block_array.length; i++) {                  boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0);
                         if (valid_block_array[i] == blockid) {  
                                 validblock = true;  
                                 break;  
                         }  
                 }  
237    
238                  if ( !validblock ) {                  if ( !validblock ) {
239                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
# Line 318  public class GeneralContractorCommands i Line 330  public class GeneralContractorCommands i
330                  }                  }
331          }          }
332    
333            private void createCave(Player player, Location loc, String[] split) {
334    
335                    int radius = Integer.parseInt(split[0]);
336    
337                    System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
338                    
339    
340                    int playerX = loc.getBlockX();
341                    int playerY = loc.getBlockY();
342                    int playerZ = loc.getBlockZ();
343                    
344    
345                    World world = loc.getWorld();
346    
347                    int count = 0;
348                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
349                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
350    
351                                    int y_max = playerY+radius;
352                                    //for (int y=playerY; y<=playerY+radius; y++) {
353                                    for (int y=playerY; y<=y_max; y++) {
354                                            count++;
355                                            world.getBlockAt(x, y, z).setType(Material.AIR);
356                                            
357                                    }
358    
359                            }
360    
361                    }
362            }
363            
364          private void levelArea(Player player, Location loc, String[] split) {          private void levelArea(Player player, Location loc, String[] split) {
365    
366                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
# Line 348  public class GeneralContractorCommands i Line 391  public class GeneralContractorCommands i
391                  }                  }
392          }          }
393                    
394    
395    
396            private void resetMap(boolean[][] map) {
397                    for (int x=0; x<map.length; x++) {
398                            for (int z=0; z<map[0].length; z++) {
399                                    map[x][z] = false;                              
400                            }
401                    }
402            }
403    
404            private void cylinder(Player player, Location loc, String[] split) {
405                    if (split.length != 2) {
406                            player.sendMessage("Usage: /cylinder [radius] [material] ");
407                            return;
408                    }
409                    int material = Integer.parseInt( split[1] );
410    
411                    int radius = Integer.parseInt(split[0]);
412                    int diameter = (radius*2) + 1;
413    
414                    boolean map[][] = new boolean[diameter][diameter];
415                    resetMap( map );
416    
417    /*              map[0][0] = true;
418                    map[0][diameter-1] = true;
419                    map[diameter-1][0] = true;
420                    map[diameter-1][diameter-1] = true;*/
421    
422                    for (int r=0; r<360; r++) {
423                            double rad = Math.toRadians( r );
424    
425                            double a = (double) radius * Math.sin( rad);
426                            double b = (double) radius * Math.cos( rad);
427    
428                            int x = radius + (int)Math.round(a);
429                            int y = radius + (int)Math.round(b);
430    
431                            map[x][y] = true;
432                    }
433    
434            
435                    drawMap( loc, map, material );  
436            }
437    
438            private void drawMap(Location loc, boolean[][] map, int material) {
439                    int playerX = loc.getBlockX();
440                    int playerY = loc.getBlockY();
441                    int playerZ = loc.getBlockZ();
442    
443                    World world = loc.getWorld();
444    
445                    for (int i=0; i<map.length; i++) {
446                            for (int j=0; j<map[0].length; j++) {
447    
448                                    int x = playerX + i + 1;
449                                    int z = playerZ + j;
450    
451                                    if (map[i][j] == true) {
452                                            for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
453                                                    world.getBlockAt(x, y, z).setTypeId(material);
454                                            }
455                                    }
456                                    
457                            }
458                    }
459            }
460    
461            
462                    
463  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20