/[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 1723 by torben, Mon Mar 12 20:04:12 2012 UTC revision 1729 by torben, Tue Mar 13 07:58:31 2012 UTC
# Line 1  Line 1 
1  package dk.thoerup.bukkit.hoeruputils.creative;  package dk.thoerup.bukkit.hoeruputils.creative;
2    
3    import org.bukkit.ChatColor;
4  import org.bukkit.Location;  import org.bukkit.Location;
5  import org.bukkit.Material;  import org.bukkit.Material;
6  import org.bukkit.World;  import org.bukkit.World;
# Line 7  import org.bukkit.command.Command; Line 8  import org.bukkit.command.Command;
8  import org.bukkit.command.CommandExecutor;  import org.bukkit.command.CommandExecutor;
9  import org.bukkit.command.CommandSender;  import org.bukkit.command.CommandSender;
10  import org.bukkit.entity.Player;  import org.bukkit.entity.Player;
11  import org.spout.api.ChatColor;  
12    import java.util.HashMap;
13    
14  public class GeneralContractorCommands implements CommandExecutor{  public class GeneralContractorCommands implements CommandExecutor{
15    
16            class StoredCommand {
17                    public StoredCommand(String l, String a[]) {
18                            this.label = l;
19                            this.args = a;
20                    }
21                    public String label;
22                    public String args[];
23            }
24    
25          final static int Y_MAX = 255;          final static int Y_MAX = 255;
26    
27            HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();
28                    
29          //@Override          //@Override
30          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 27  public class GeneralContractorCommands i Line 40  public class GeneralContractorCommands i
40                          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" );
41                          return true;                          return true;
42                  }                  }
43    
44                    commands.put(player.getName(), new StoredCommand(label,args) );
45    
46                    if (label.equals("replay") || label.equals("*") ) {
47                            StoredCommand cmd = commands.get(player.getName() );
48                            if (cmd != null) {
49                                    label = cmd.label;
50                                    args = cmd.args;
51                            }
52                    }
53                                    
54                  //System.out.println( ">>" + label); //DEBUG                  //System.out.println( ">>" + label); //DEBUG
55                                    
56                  if ( label.equals("levelarea") ) {                  if ( label.equals("levelarea") ) {
57                          if (validateLevelOrFill(player, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
58                                  levelArea(player, loc, args);                                  levelArea(player, loc, args);
59                          }                          }
60                          return true;                          return true;
# Line 39  public class GeneralContractorCommands i Line 62  public class GeneralContractorCommands i
62                                    
63                                    
64                  if ( label.equals("fillarea") ) {                  if ( label.equals("fillarea") ) {
65                          if (validateLevelOrFill(player, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
66                                  fillArea(player, loc, args);                                  fillArea(player, loc, args);
67                          }                                }      
68                          return true;                          return true;
# Line 61  public class GeneralContractorCommands i Line 84  public class GeneralContractorCommands i
84          }          }
85    
86                    
87          void slopeArea(Player player, Location loc, String[] args) {          void slopeArea(Player player, Location loc, String[] split) {
88                  int radius = Integer.parseInt(args[1]);                  int radius;
89                    try {
90                            radius = Integer.parseInt(split[0]);
91                    } catch (Exception e) {
92                            player.sendMessage("setsurface: radius must be an integer");
93                            return;
94                    }
95    
96                  System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius);
97                                    
# Line 97  public class GeneralContractorCommands i Line 126  public class GeneralContractorCommands i
126    
127    
128    
129                  if (split.length != 3) {                  if (split.length != 2) {
130                          player.sendMessage("Usage /setsurface [radius] [blockID]");                          player.sendMessage("Usage /setsurface [radius] [blockID]");
131                          return;                          return;
132                  }                  }
# Line 105  public class GeneralContractorCommands i Line 134  public class GeneralContractorCommands i
134    
135                  int radius;                  int radius;
136                  try {                  try {
137                          radius = Integer.parseInt(split[1]);                          radius = Integer.parseInt(split[0]);
138                  } catch (Exception e) {                  } catch (Exception e) {
139                          player.sendMessage("setsurface: radius must be an integer");                          player.sendMessage("setsurface: radius must be an integer");
140                          return;                          return;
# Line 119  public class GeneralContractorCommands i Line 148  public class GeneralContractorCommands i
148    
149                  int blockid;                  int blockid;
150                  try {                  try {
151                          blockid = Integer.parseInt(split[2]);                          blockid = Integer.parseInt(split[1]);
152                  } catch (Exception e) {                  } catch (Exception e) {
153                          player.sendMessage("setsurface: blockid must be an integer");                          player.sendMessage("setsurface: blockid must be an integer");
154                          return;                          return;
# Line 153  public class GeneralContractorCommands i Line 182  public class GeneralContractorCommands i
182                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {
183                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
184                                  //int y = getGroundLevel(x,z) - 1;                                  //int y = getGroundLevel(x,z) - 1;
185                                  int y = world.getHighestBlockYAt(x, z);                                  int y = world.getHighestBlockYAt(x, z) ;
186                                                                    
187                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setTypeId(blockid);
188                          }                          }
189                  }                  }
190          }          }
191    
192          private boolean validateLevelOrFill(Player player, String[] split) {          private boolean validateLevelOrFill(Player player, String label, String[] split) {
193                  if (split.length < 2 || split.length > 3) {                  if (split.length < 1 || split.length > 2) {
194                          player.sendMessage("Usage: " + split[0] + " [radius]");                          player.sendMessage("Usage: " + label + " [radius]");
195                          return false;                          return false;
196                  }                  }
197                                    
198                  int radius;                  int radius;
199                  try {                  try {
200                          radius = Integer.parseInt(split[1]);                          radius = Integer.parseInt(split[0]);
201                  } catch (Exception e) {                  } catch (Exception e) {
202                          player.sendMessage(split[0] + ": radius must be an integer");                          player.sendMessage(label + ": radius must be an integer");
203                          return false;                          return false;
204                  }                  }
205    
206                  if (radius > 20) {                  if (radius > 20) {
207                          player.sendMessage(split[0] + ": radius may not exceed 20");                          player.sendMessage(label + ": radius may not exceed 20");
208                          return false;                          return false;
209                  }                  }
210                                    
211                  if (split.length == 3) {                  if (split.length == 2) {
212                          int id;                          int id;
213                          try {                          try {
214                                  id = Integer.parseInt( split[2] );                                  id = Integer.parseInt( split[1] );
215                          } catch (Exception e) {                          } catch (Exception e) {
216                                  player.sendMessage(split[0] + ": id must be an integer");                                  player.sendMessage(label + ": id must be an integer");
217                                  return false;                                  return false;
218                          }                          }
219                          if ( id == 46) {                          if ( id == 46) {
# Line 198  public class GeneralContractorCommands i Line 227  public class GeneralContractorCommands i
227          }          }
228    
229          private void fillArea(Player player, Location loc, String[] split) {          private void fillArea(Player player, Location loc, String[] split) {
230                  int radius = Integer.parseInt(split[1]);                  int radius = Integer.parseInt(split[0]);
231                                    
232                  int material = Material.DIRT.getId();                  int material = Material.DIRT.getId();
233                                    
234                  if (split.length == 3) {                  if (split.length == 2) {
235                          material = Integer.parseInt( split[2] );                          material = Integer.parseInt( split[1] );
236                  }                  }
237    
238                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
# Line 231  public class GeneralContractorCommands i Line 260  public class GeneralContractorCommands i
260    
261          private void levelArea(Player player, Location loc, String[] split) {          private void levelArea(Player player, Location loc, String[] split) {
262    
263                  int radius = Integer.parseInt(split[1]);                  int radius = Integer.parseInt(split[0]);
264    
265                  System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
266                                    

Legend:
Removed from v.1723  
changed lines
  Added in v.1729

  ViewVC Help
Powered by ViewVC 1.1.20