[TUT] Edit Blocks on Sight by Command

Discussion in 'Resources' started by emericask8ur, Nov 23, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    emericask8ur

    First set up a HashMap for the items you can set
    This is going to be a example hashmap of some items.
    In this case I named it HashMapz
    Code:
    public class HashMapz {
    	public static HashMap<String, Material> items = new HashMap<String, Material>();
    	public static void setItems() {
    items.put("bedrock", Material.BEDROCK);
    items.put("bookshelf", Material.BOOKSHELF);
    
    Now we are going to create the command:
    Code:
    if (cmdLabel.equalsIgnoreCase("edit") && args.length==1)){
    Block target = p.getTargetBlock(null, 200);
    			 if (target != null) {
    				    Material type = HashMapz.items.get(args[0].toLowerCase());
    				    if (type != null) {
    				        target.setType(type);
    				    } else {
    				        p.sendMessage("Invalid block type!");
    				    }
    				    return true;		
    			}
        
    By the use of
    Code:
    if (type !=null){ 
    You are also making sure if the user types nothing in or a item that is not on the hashmap it will send them that message of "Invalid Block Type!"
     
  2. Instead of using setItems() once you could use
    Code:java
    1. static {
    2. items.put("bedrock", Material.BEDROCK);
    3. }

    aswell.
     
  3. You can set the Distance to 120 as anything above will be set to 120 anyways: See here
     
Thread Status:
Not open for further replies.

Share This Page