/[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 1733 by torben, Wed Mar 14 20:25:27 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 87  public class GeneralContractorCommands i Line 91  public class GeneralContractorCommands i
91                          platform(player,loc,args);                          platform(player,loc,args);
92                          return true;                          return true;
93                  }                  }
94    
95                    if (label.equals("cylinder") ) {
96                            if (validateLevelOrFill(player, label, args) ) {
97                                    cylinder(player,loc,args);
98                            }
99                            return true;
100                    }
101                    
102                    
103                  return false;                  return false;
# Line 215  public class GeneralContractorCommands i Line 226  public class GeneralContractorCommands i
226                          return;                          return;
227                  }                  }
228    
229                  boolean validblock = false;                  //check if the blockid is in the array of valid blocks
230                  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;  
                         }  
                 }  
231    
232                  if ( !validblock ) {                  if ( !validblock ) {
233                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
# Line 347  public class GeneralContractorCommands i Line 353  public class GeneralContractorCommands i
353    
354                  }                  }
355          }          }
356    
357    
358            private void resetMap(boolean[][] map) {
359                    for (int x=0; x<map.length; x++) {
360                            for (int z=0; z<map[0].length; z++) {
361                                    map[x][z] = false;                              
362                            }
363                    }
364            }
365    
366            private void cylinder(Player player, Location loc, String[] split) {
367                    if (split.length != 2) {
368                            player.sendMessage("Usage: /cylinder [radius] [material] ");
369                            return;
370                    }
371                    int material = Integer.parseInt( split[1] );
372    
373                    int radius = Integer.parseInt(split[0]);
374                    int diameter = (radius*2) + 1;
375    
376                    boolean map[][] = new boolean[diameter][diameter];
377                    resetMap( map );
378    
379    /*              map[0][0] = true;
380                    map[0][diameter-1] = true;
381                    map[diameter-1][0] = true;
382                    map[diameter-1][diameter-1] = true;*/
383    
384                    for (int r=0; r<360; r++) {
385                            double rad = Math.toRadians( r );
386    
387                            double a = (double) radius * Math.sin( rad);
388                            double b = (double) radius * Math.cos( rad);
389    
390                            int x = radius + (int)Math.round(a);
391                            int y = radius + (int)Math.round(b);
392    
393                            map[x][y] = true;
394                    }
395    
396            
397                    drawMap( loc, map, material );  
398            }
399    
400            private void drawMap(Location loc, boolean[][] map, int material) {
401                    int playerX = loc.getBlockX();
402                    int playerY = loc.getBlockY();
403                    int playerZ = loc.getBlockZ();
404    
405                    World world = loc.getWorld();
406    
407                    for (int i=0; i<map.length; i++) {
408                            for (int j=0; j<map[0].length; j++) {
409    
410                                    int x = playerX + i + 1;
411                                    int z = playerZ + j;
412    
413                                    if (map[i][j] == true) {
414                                            for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
415                                                    world.getBlockAt(x, y, z).setTypeId(material);
416                                            }
417                                    }
418                                    
419                            }
420                    }
421            }
422    
423                    
424                    
425  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20