/[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 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;
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                            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>();
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 28  public class GeneralContractorCommands i Line 88  public class GeneralContractorCommands i
88                          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" );
89                          return true;                          return true;
90                  }                  }
91    
92    
93                    if ( command.getLabel().equals("replay")  ) {
94                            StoredCommand cmd = commands.get(player.getName() );
95                            if (cmd != null) {
96                                    label = cmd.label;
97                                    args = cmd.args;
98                            }
99                    } else {
100                            commands.put(player.getName(), new StoredCommand(label,args) );
101                    }
102                                    
103                  //System.out.println( ">>" + label); //DEBUG                  //System.out.println( ">>" + label); //DEBUG
104                                    
105                  if ( label.equals("levelarea") ) {                  if ( label.equals("levelarea") ) {
106                          if (validateLevelOrFill(player, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
107                                  levelArea(player, loc, args);                                  levelArea(player, loc, args);
108                          }                          }
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, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
121                                  fillArea(player, loc, args);                                  fillArea(player, loc, args);
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 56  public class GeneralContractorCommands i Line 143  public class GeneralContractorCommands i
143                          setSurface(player, loc, args);                            setSurface(player, loc, args);  
144                          return true;                          return true;
145                  }                  }
146    
147                    if (label.equals("platform") ) {
148                            platform(player,loc,args);
149                            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 99  public class GeneralContractorCommands i Line 200  public class GeneralContractorCommands i
200                  }                                }              
201          }          }
202                    
203          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} ;  
   
   
204    
205                  if (split.length != 2) {                  if (split.length != 2) {
206                          player.sendMessage("Usage /setsurface [radius] [blockID]");                          player.sendMessage("Usage /platform [radius] [material]");
207                          return;                          return;
208                  }                  }
209    
   
210                  int radius;                  int radius;
211                  try {                  try {
212                          radius = Integer.parseInt(split[0]);                          radius = Integer.parseInt(split[0]);
213                  } catch (Exception e) {                  } catch (Exception e) {
214                          player.sendMessage("setsurface: radius must be an integer");                          player.sendMessage("platform: radius must be an integer");
215                          return;                          return;
216                  }                  }
217    
218                  if (radius > 20) {                  if (radius > 25) {
219                          player.sendMessage("setsurface: radius may not exceed 20");                          player.sendMessage("platform: radius may not exceed 25");
220                          return;                          return;
221                  }                  }
222    
223                    Material material = Material.matchMaterial( split[1] );
224                  int blockid;                  if (material == null) {
225                  try {                          player.sendMessage("platform: unknown material: " + split[1] );
                         blockid = Integer.parseInt(split[1]);  
                 } catch (Exception e) {  
                         player.sendMessage("setsurface: blockid must be an integer");  
226                          return;                          return;
227                  }                  }
228    /*
229                  boolean validblock = false;                  boolean validblock = false;
230                  for (int i=0; i<valid_block_array.length; i++) {                  for (int i=0; i<valid_block_array.length; i++) {
231                          if (valid_block_array[i] == blockid) {                          if (valid_block_array[i] == blockid) {
# Line 143  public class GeneralContractorCommands i Line 237  public class GeneralContractorCommands i
237                  if ( !validblock ) {                  if ( !validblock ) {
238                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
239                          return;                          return;
240                    }*/
241    
242                    int playerX = loc.getBlockX();
243                    int playerY = loc.getBlockY();
244                    int playerZ = loc.getBlockZ();
245    
246                    
247                    World world = loc.getWorld();
248    
249                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
250                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
251                                    int y = playerY - 1;
252                                    
253                                    world.getBlockAt(x, y, z).setType( material );
254                            }
255                    }
256            }
257    
258            private void setSurface(Player player, Location loc, String[] split) {
259    
260                    if (split.length != 2) {
261                            player.sendMessage("Usage /setsurface [radius] [blockID]");
262                            return;
263                    }
264    
265                    int radius;
266                    try {
267                            radius = Integer.parseInt(split[0]);
268                    } catch (Exception e) {
269                            player.sendMessage("setsurface: radius must be an integer");
270                            return;
271                    }
272    
273                    if (radius > 25) {
274                            player.sendMessage("setsurface: radius may not exceed 25");
275                            return;
276                    }
277    
278                    Material material = Material.matchMaterial( split[1] );
279                    if (material == null) {
280                            player.sendMessage("setsurface: unknown material: " + split[1] );
281                            return;
282                    }
283    
284                    //check if the blockid is in the array of valid blocks
285                    if ( ! valid_materials.contains(material) ) {
286                            player.sendMessage("setsurface: block now allowed");
287                            return;
288                  }                  }
289    
290                  int playerX = loc.getBlockX();                  int playerX = loc.getBlockX();
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                  }                  }
298                                    
299                  World world = loc.getWorld();                  World world = loc.getWorld();
                   
300    
301                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {
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 181  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 207  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 228  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 236  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 266  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.1725  
changed lines
  Added in v.3196

  ViewVC Help
Powered by ViewVC 1.1.20