/[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 3133 by torben, Fri Nov 18 13:14:07 2016 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    import java.util.HashSet;
15    import java.util.Set;
16    
17  public class GeneralContractorCommands implements CommandExecutor{  public class GeneralContractorCommands implements CommandExecutor{
18    
19            class StoredCommand {
20                    public StoredCommand(String l, String a[]) {
21                            this.label = l;
22                            this.args = a;
23                    }
24                    public String label;
25                    public String args[];
26            }
27    
28          final static int Y_MAX = 255;          final static int Y_MAX = 255;
29            final Material valid_block_array[] = {
30                            Material.STONE,
31                            Material.GRASS,
32                            Material.DIRT,
33                            Material.COBBLESTONE
34            };
35    //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} ;
36    
37            final Set<Material> valid_materials = new HashSet<Material>();
38    
39            HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();
40    
41    
42            public GeneralContractorCommands() {
43                    Arrays.sort(valid_block_array);
44    
45                    for (Material mat : valid_block_array) {
46                            valid_materials.add( mat );
47                    }
48            }
49                    
50          //@Override          //@Override
51          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 61  public class GeneralContractorCommands i
61                          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" );
62                          return true;                          return true;
63                  }                  }
64    
65    
66                    if ( command.getLabel().equals("replay")  ) {
67                            StoredCommand cmd = commands.get(player.getName() );
68                            if (cmd != null) {
69                                    label = cmd.label;
70                                    args = cmd.args;
71                            }
72                    } else {
73                            commands.put(player.getName(), new StoredCommand(label,args) );
74                    }
75                                    
76                  //System.out.println( ">>" + label); //DEBUG                  //System.out.println( ">>" + label); //DEBUG
77                                    
78                  if ( label.equals("levelarea") ) {                  if ( label.equals("levelarea") ) {
79                          if (validateLevelOrFill(player, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
80                                  levelArea(player, loc, args);                                  levelArea(player, loc, args);
81                          }                          }
82                          return true;                          return true;
83                  }                  }
84                                    
85                    if ( label.equals("createcave") ) {
86                            if (validateLevelOrFill(player, label, args) ) {
87                                    createCave(player, loc, args);
88                            }
89                            return true;
90                    }
91                                    
92                  if ( label.equals("fillarea") ) {                  if ( label.equals("fillarea") ) {
93                          if (validateLevelOrFill(player, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
94                                  fillArea(player, loc, args);                                  fillArea(player, loc, args);
95                          }                                }      
96                          return true;                          return true;
# Line 56  public class GeneralContractorCommands i Line 106  public class GeneralContractorCommands i
106                          setSurface(player, loc, args);                            setSurface(player, loc, args);  
107                          return true;                          return true;
108                  }                  }
109    
110                    if (label.equals("platform") ) {
111                            platform(player,loc,args);
112                            return true;
113                    }
114    
115                    if (label.equals("cylinder") ) {
116                            if (validateLevelOrFill(player, label, args) ) {
117                                    cylinder(player,loc,args);
118                            }
119                            return true;
120                    }
121                    
122                    
123                  return false;                  return false;
# Line 99  public class GeneralContractorCommands i Line 161  public class GeneralContractorCommands i
161                  }                                }              
162          }          }
163                    
164          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} ;  
   
   
165    
166                  if (split.length != 2) {                  if (split.length != 2) {
167                          player.sendMessage("Usage /setsurface [radius] [blockID]");                          player.sendMessage("Usage /platform [radius] [material]");
168                          return;                          return;
169                  }                  }
170    
   
171                  int radius;                  int radius;
172                  try {                  try {
173                          radius = Integer.parseInt(split[0]);                          radius = Integer.parseInt(split[0]);
174                  } catch (Exception e) {                  } catch (Exception e) {
175                          player.sendMessage("setsurface: radius must be an integer");                          player.sendMessage("platform: radius must be an integer");
176                          return;                          return;
177                  }                  }
178    
179                  if (radius > 20) {                  if (radius > 20) {
180                          player.sendMessage("setsurface: radius may not exceed 20");                          player.sendMessage("platform: radius may not exceed 20");
181                          return;                          return;
182                  }                  }
183    
184                    Material material = Material.matchMaterial( split[1] );
185                  int blockid;                  if (material == null) {
186                  try {                          player.sendMessage("platform: blockid must be an integer");
                         blockid = Integer.parseInt(split[1]);  
                 } catch (Exception e) {  
                         player.sendMessage("setsurface: blockid must be an integer");  
187                          return;                          return;
188                  }                  }
189    /*
190                  boolean validblock = false;                  boolean validblock = false;
191                  for (int i=0; i<valid_block_array.length; i++) {                  for (int i=0; i<valid_block_array.length; i++) {
192                          if (valid_block_array[i] == blockid) {                          if (valid_block_array[i] == blockid) {
# Line 143  public class GeneralContractorCommands i Line 198  public class GeneralContractorCommands i
198                  if ( !validblock ) {                  if ( !validblock ) {
199                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
200                          return;                          return;
201                    }*/
202    
203                    int playerX = loc.getBlockX();
204                    int playerY = loc.getBlockY();
205                    int playerZ = loc.getBlockZ();
206    
207                    
208                    World world = loc.getWorld();
209    
210                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
211                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
212                                    int y = playerY - 1;
213                                    
214                                    world.getBlockAt(x, y, z).setType( material );
215                            }
216                    }
217            }
218    
219            private void setSurface(Player player, Location loc, String[] split) {
220    
221                    if (split.length != 2) {
222                            player.sendMessage("Usage /setsurface [radius] [blockID]");
223                            return;
224                    }
225    
226                    int radius;
227                    try {
228                            radius = Integer.parseInt(split[0]);
229                    } catch (Exception e) {
230                            player.sendMessage("setsurface: radius must be an integer");
231                            return;
232                    }
233    
234                    if (radius > 20) {
235                            player.sendMessage("setsurface: radius may not exceed 20");
236                            return;
237                    }
238    
239                    Material material = Material.matchMaterial( split[1] );
240                    if (material == null) {
241                            player.sendMessage("platform: blockid must be an integer");
242                            return;
243                    }
244    
245                    //check if the blockid is in the array of valid blocks
246                    if ( ! valid_materials.contains(material) ) {
247                            player.sendMessage("setsurface: block now allowed");
248                            return;
249                  }                  }
250    
251                  int playerX = loc.getBlockX();                  int playerX = loc.getBlockX();
252                  int playerY = loc.getBlockY();                  int playerY = loc.getBlockY();
253                  int playerZ = loc.getBlockZ();                  int playerZ = loc.getBlockZ();
254    
255                  if(playerY <= 2 && blockid != 7) {                  if(playerY <= 2 && material != Material.BEDROCK ) {
256                          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)");
257                          return;                          return;
258                  }                  }
259                                    
260                  World world = loc.getWorld();                  World world = loc.getWorld();
                   
261    
262                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {
263                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
264                                  //int y = getGroundLevel(x,z) - 1;                                  //int y = getGroundLevel(x,z) - 1;
265                                  int y = world.getHighestBlockYAt(x, z);                                  int y = world.getHighestBlockYAt(x, z) ;
266                                                                    
267                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setType(material);
268                          }                          }
269                  }                  }
270          }          }
# Line 207  public class GeneralContractorCommands i Line 309  public class GeneralContractorCommands i
309          private void fillArea(Player player, Location loc, String[] split) {          private void fillArea(Player player, Location loc, String[] split) {
310                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
311                                    
312                  int material = Material.DIRT.getId();                  Material material = Material.DIRT;
313    
314                                    
315                  if (split.length == 2) {                  if (split.length == 2) {
316                          material = Integer.parseInt( split[1] );                          material = Material.matchMaterial( split[1] );
317                            if (material == null) {
318                                    player.sendMessage("Unknown material: " + split[1] );
319                                    return;
320                            }
321                  }                  }
322    
323                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
# Line 228  public class GeneralContractorCommands i Line 335  public class GeneralContractorCommands i
335                                                                    
336    
337                                  for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                                                      for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
338                                          world.getBlockAt(x, y, z).setTypeId(material);                                          world.getBlockAt(x, y, z).setType( material );
339                                  }                                  }
340    
341                          }                          }
# Line 236  public class GeneralContractorCommands i Line 343  public class GeneralContractorCommands i
343                  }                  }
344          }          }
345    
346            private void createCave(Player player, Location loc, String[] split) {
347    
348                    int radius = Integer.parseInt(split[0]);
349    
350                    System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
351                    
352    
353                    int playerX = loc.getBlockX();
354                    int playerY = loc.getBlockY();
355                    int playerZ = loc.getBlockZ();
356                    
357    
358                    World world = loc.getWorld();
359    
360                    int count = 0;
361                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
362                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
363    
364                                    int y_max = playerY+radius;
365                                    //for (int y=playerY; y<=playerY+radius; y++) {
366                                    for (int y=playerY; y<=y_max; y++) {
367                                            count++;
368                                            world.getBlockAt(x, y, z).setType(Material.AIR);
369                                            
370                                    }
371    
372                            }
373    
374                    }
375            }
376            
377          private void levelArea(Player player, Location loc, String[] split) {          private void levelArea(Player player, Location loc, String[] split) {
378    
379                  int radius = Integer.parseInt(split[0]);                  int radius = Integer.parseInt(split[0]);
# Line 266  public class GeneralContractorCommands i Line 404  public class GeneralContractorCommands i
404                  }                  }
405          }          }
406                    
407    
408    
409            private void resetMap(boolean[][] map) {
410                    for (int x=0; x<map.length; x++) {
411                            for (int z=0; z<map[0].length; z++) {
412                                    map[x][z] = false;                              
413                            }
414                    }
415            }
416    
417            private void cylinder(Player player, Location loc, String[] split) {
418                    if (split.length != 2) {
419                            player.sendMessage("Usage: /cylinder [radius] [material] ");
420                            return;
421                    }
422    
423                    Material material = Material.matchMaterial( split[1] );
424                    if ( material == null) {
425                            player.sendMessage("/cylinder: unknown material: " + split[1]);
426                            return;
427                    }
428    
429                    int radius = Integer.parseInt(split[0]);
430                    int diameter = (radius*2) + 1;
431    
432                    boolean map[][] = new boolean[diameter][diameter];
433                    resetMap( map );
434    
435    /*              map[0][0] = true;
436                    map[0][diameter-1] = true;
437                    map[diameter-1][0] = true;
438                    map[diameter-1][diameter-1] = true;*/
439    
440                    for (int r=0; r<360; r++) {
441                            double rad = Math.toRadians( r );
442    
443                            double a = (double) radius * Math.sin( rad);
444                            double b = (double) radius * Math.cos( rad);
445    
446                            int x = radius + (int)Math.round(a);
447                            int y = radius + (int)Math.round(b);
448    
449                            map[x][y] = true;
450                    }
451    
452            
453                    drawMap( loc, map, material );  
454            }
455    
456            private void drawMap(Location loc, boolean[][] map, Material material) {
457                    int playerX = loc.getBlockX();
458                    int playerY = loc.getBlockY();
459                    int playerZ = loc.getBlockZ();
460    
461                    World world = loc.getWorld();
462    
463                    for (int i=0; i<map.length; i++) {
464                            for (int j=0; j<map[0].length; j++) {
465    
466                                    int x = playerX + i + 1;
467                                    int z = playerZ + j;
468    
469                                    if (map[i][j] == true) {
470                                            for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {                                    
471                                                    world.getBlockAt(x, y, z).setType(material);
472                                            }
473                                    }
474                                    
475                            }
476                    }
477            }
478    
479            
480                    
481  }  }

Legend:
Removed from v.1725  
changed lines
  Added in v.3133

  ViewVC Help
Powered by ViewVC 1.1.20