/[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 1729 by torben, Tue Mar 13 07:58:31 2012 UTC revision 1731 by torben, Tue Mar 13 08:45:07 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 23  public class GeneralContractorCommands i Line 24  public class GeneralContractorCommands i
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>();          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 41  public class GeneralContractorCommands i Line 48  public class GeneralContractorCommands i
48                          return true;                          return true;
49                  }                  }
50    
                 commands.put(player.getName(), new StoredCommand(label,args) );  
51    
52                  if (label.equals("replay") || label.equals("*") ) {                  if ( command.getLabel().equals("replay")  ) {
53                          StoredCommand cmd = commands.get(player.getName() );                          StoredCommand cmd = commands.get(player.getName() );
54                          if (cmd != null) {                          if (cmd != null) {
55                                  label = cmd.label;                                  label = cmd.label;
56                                  args = cmd.args;                                  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
# Line 78  public class GeneralContractorCommands i Line 86  public class GeneralContractorCommands i
86                          setSurface(player, loc, args);                            setSurface(player, loc, args);  
87                          return true;                          return true;
88                  }                  }
89    
90                    if (label.equals("platform") ) {
91                            platform(player,loc,args);
92                            return true;
93                    }
94                    
95                    
96                  return false;                  return false;
# Line 121  public class GeneralContractorCommands i Line 134  public class GeneralContractorCommands i
134                  }                                }              
135          }          }
136                    
137          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} ;  
   
   
138    
139                  if (split.length != 2) {                  if (split.length != 2) {
140                          player.sendMessage("Usage /setsurface [radius] [blockID]");                          player.sendMessage("Usage /platform [radius] [blockID]");
141                          return;                          return;
142                  }                  }
143    
   
144                  int radius;                  int radius;
145                  try {                  try {
146                          radius = Integer.parseInt(split[0]);                          radius = Integer.parseInt(split[0]);
147                  } catch (Exception e) {                  } catch (Exception e) {
148                          player.sendMessage("setsurface: radius must be an integer");                          player.sendMessage("platform: radius must be an integer");
149                          return;                          return;
150                  }                  }
151    
152                  if (radius > 20) {                  if (radius > 20) {
153                          player.sendMessage("setsurface: radius may not exceed 20");                          player.sendMessage("platform: radius may not exceed 20");
154                          return;                          return;
155                  }                  }
156    
   
157                  int blockid;                  int blockid;
158                  try {                  try {
159                          blockid = Integer.parseInt(split[1]);                          blockid = Integer.parseInt(split[1]);
160                  } catch (Exception e) {                  } catch (Exception e) {
161                          player.sendMessage("setsurface: blockid must be an integer");                          player.sendMessage("platform: blockid must be an integer");
162                          return;                          return;
163                  }                  }
164    /*
165                  boolean validblock = false;                  boolean validblock = false;
166                  for (int i=0; i<valid_block_array.length; i++) {                  for (int i=0; i<valid_block_array.length; i++) {
167                          if (valid_block_array[i] == blockid) {                          if (valid_block_array[i] == blockid) {
# Line 165  public class GeneralContractorCommands i Line 173  public class GeneralContractorCommands i
173                  if ( !validblock ) {                  if ( !validblock ) {
174                          player.sendMessage("setsurface: block now allowed");                          player.sendMessage("setsurface: block now allowed");
175                          return;                          return;
176                    }*/
177    
178                    int playerX = loc.getBlockX();
179                    int playerY = loc.getBlockY();
180                    int playerZ = loc.getBlockZ();
181    
182                    
183                    World world = loc.getWorld();
184    
185                    for (int x=(playerX-radius); x<=(playerX+radius); x++) {
186                            for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
187                                    int y = playerY - 1;
188                                    
189                                    world.getBlockAt(x, y, z).setTypeId(blockid);
190                            }
191                    }
192            }
193    
194            private void setSurface(Player player, Location loc, String[] split) {
195    
196                    if (split.length != 2) {
197                            player.sendMessage("Usage /setsurface [radius] [blockID]");
198                            return;
199                    }
200    
201                    int radius;
202                    try {
203                            radius = Integer.parseInt(split[0]);
204                    } catch (Exception e) {
205                            player.sendMessage("setsurface: radius must be an integer");
206                            return;
207                    }
208    
209                    if (radius > 20) {
210                            player.sendMessage("setsurface: radius may not exceed 20");
211                            return;
212                    }
213    
214                    int blockid;
215                    try {
216                            blockid = Integer.parseInt(split[1]);
217                    } catch (Exception e) {
218                            player.sendMessage("setsurface: blockid must be an integer");
219                            return;
220                    }
221    
222                    //check if the blockid is in the array of valid blocks
223                    boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0);
224    
225                    if ( !validblock ) {
226                            player.sendMessage("setsurface: block now allowed");
227                            return;
228                  }                  }
229    
230                  int playerX = loc.getBlockX();                  int playerX = loc.getBlockX();
# Line 177  public class GeneralContractorCommands i Line 237  public class GeneralContractorCommands i
237                  }                  }
238                                    
239                  World world = loc.getWorld();                  World world = loc.getWorld();
                   
240    
241                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {                  for (int x=(playerX-radius); x<=(playerX+radius); x++) {
242                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                          for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {

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

  ViewVC Help
Powered by ViewVC 1.1.20