/[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 1725 by torben, Mon Mar 12 20:16:29 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;
14    
15  public class GeneralContractorCommands implements CommandExecutor{  public class GeneralContractorCommands implements CommandExecutor{
16    
17            class StoredCommand {
18                    public StoredCommand(String l, String a[]) {
19                            this.label = l;
20                            this.args = a;
21                    }
22                    public String label;
23                    public String args[];
24            }
25    
26          final static int Y_MAX = 255;          final static int Y_MAX = 255;
27            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} ;
28    
29            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 28  public class GeneralContractorCommands i Line 47  public class GeneralContractorCommands i
47                          player.sendMessage( ChatColor.RED + "This command may only be used in creative world" );                          player.sendMessage( ChatColor.RED + "This command may only be used in creative world" );
48                          return true;                          return true;
49                  }                  }
50    
51    
52                    if ( command.getLabel().equals("replay")  ) {
53                            StoredCommand cmd = commands.get(player.getName() );
54                            if (cmd != null) {
55                                    label = cmd.label;
56                                    args = cmd.args;
57                            }
58                    } else {
59                            commands.put(player.getName(), new StoredCommand(label,args) );
60                    }
61                                    
62                  //System.out.println( ">>" + label); //DEBUG                  //System.out.println( ">>" + label); //DEBUG
63                                    
64                  if ( label.equals("levelarea") ) {                  if ( label.equals("levelarea") ) {
65                          if (validateLevelOrFill(player, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
66                                  levelArea(player, loc, args);                                  levelArea(player, loc, args);
67                          }                          }
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, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
80                                  fillArea(player, loc, args);                                  fillArea(player, loc, args);
81                          }                                }      
82                          return true;                          return true;
# Line 56  public class GeneralContractorCommands i Line 92  public class GeneralContractorCommands i
92                          setSurface(player, loc, args);                            setSurface(player, loc, args);  
93                          return true;                          return true;
94                  }                  }
95    
96                    if (label.equals("platform") ) {
97                            platform(player,loc,args);
98                            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 99  public class GeneralContractorCommands i Line 147  public class GeneralContractorCommands i
147                  }                                }              
148          }          }
149                    
150          private void setSurface(Player player, Location loc, String[] split) {          private void platform(Player player, Location loc, String[] split) {
                 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} ;  
   
   
151    
152                  if (split.length != 2) {                  if (split.length != 2) {
153                          player.sendMessage("Usage /setsurface [radius] [blockID]");                          player.sendMessage("Usage /platform [radius] [blockID]");
154                          return;                          return;
155                  }                  }
156    
   
157                  int radius;                  int radius;
158                  try {                  try {
159                          radius = Integer.parseInt(split[0]);                          radius = Integer.parseInt(split[0]);
160                  } catch (Exception e) {                  } catch (Exception e) {
161                          player.sendMessage("setsurface: radius must be an integer");                          player.sendMessage("platform: radius must be an integer");
162                          return;                          return;
163                  }                  }
164    
165                  if (radius > 20) {                  if (radius > 20) {
166                          player.sendMessage("setsurface: radius may not exceed 20");                          player.sendMessage("platform: radius may not exceed 20");
167                          return;                          return;
168                  }                  }
169    
   
170                  int blockid;                  int blockid;
171                  try {                  try {
172                          blockid = Integer.parseInt(split[1]);                          blockid = Integer.parseInt(split[1]);
173                  } catch (Exception e) {                  } catch (Exception e) {
174                          player.sendMessage("setsurface: blockid must be an integer");                          player.sendMessage("platform: blockid must be an integer");
175                          return;                          return;
176                  }                  }
177    /*
178                  boolean validblock = false;                  boolean validblock = false;
179                  for (int i=0; i<valid_block_array.length; i++) {                  for (int i=0; i<valid_block_array.length; i++) {
180                          if (valid_block_array[i] == blockid) {                          if (valid_block_array[i] == blockid) {
# Line 143  public class GeneralContractorCommands i Line 186  public class GeneralContractorCommands i
186                  if ( !validblock ) {                  if ( !validblock ) {
187                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
188                          return;                          return;
189                    }*/
190    
191                    int playerX = loc.getBlockX();
192                    int playerY = loc.getBlockY();
193                    int playerZ = loc.getBlockZ();
194    
195                    
196                    World world = loc.getWorld();
197    
198                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
199                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
200                                    int y = playerY - 1;
201                                    
202                                    world.getBlockAt(x, y, z).setTypeId(blockid);
203                            }
204                    }
205            }
206    
207            private void setSurface(Player player, Location loc, String[] split) {
208    
209                    if (split.length != 2) {
210                            player.sendMessage("Usage /setsurface [radius] [blockID]");
211                            return;
212                    }
213    
214                    int radius;
215                    try {
216                            radius = Integer.parseInt(split[0]);
217                    } catch (Exception e) {
218                            player.sendMessage("setsurface: radius must be an integer");
219                            return;
220                    }
221    
222                    if (radius > 20) {
223                            player.sendMessage("setsurface: radius may not exceed 20");
224                            return;
225                    }
226    
227                    int blockid;
228                    try {
229                            blockid = Integer.parseInt(split[1]);
230                    } catch (Exception e) {
231                            player.sendMessage("setsurface: blockid must be an integer");
232                            return;
233                    }
234    
235                    //check if the blockid is in the array of valid blocks
236                    boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0);
237    
238                    if ( !validblock ) {
239                            player.sendMessage("setsurface: block now allowed");
240                            return;
241                  }                  }
242    
243                  int playerX = loc.getBlockX();                  int playerX = loc.getBlockX();
# Line 155  public class GeneralContractorCommands i Line 250  public class GeneralContractorCommands i
250                  }                  }
251                                    
252                  World world = loc.getWorld();                  World world = loc.getWorld();
                   
253    
254                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {
255                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
256                                  //int y = getGroundLevel(x,z) - 1;                                  //int y = getGroundLevel(x,z) - 1;
257                                  int y = world.getHighestBlockYAt(x, z);                                  int y = world.getHighestBlockYAt(x, z) ;
258                                                                    
259                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setTypeId(blockid);
260                          }                          }
# Line 236  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 266  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.1725  
changed lines
  Added in v.1751

  ViewVC Help
Powered by ViewVC 1.1.20