Thread: I would like some help :S

Results 1 to 2 of 2
  1. #1 I would like some help :S 
    Banned

    Join Date
    Dec 2011
    Posts
    967
    Thanks given
    234
    Thanks received
    208
    Rep Power
    0
    Could this be made any cleaner keeping the same functions, I don't really know, I'm still a begginer...

    I'm just trying to make it friendly for myself.
    Code:
    			if (playerCommand.startsWith("item") && (c.playerRights != 2 || c.playerRights != 3 || c.playerRights != 12)) {
    		public static int UNSP[] = {14484, 6586, 6585, 4151, 4152, 15486, 15487, 10551, 19784, 19780, 18786, 10548};
    				try {
    					String[] args = playerCommand.split(" ");
    					if (args.length == 3) {
    								int ID = Integer.parseInt(args[1]);
    					if (c.inPvP() || c.inWild())
    						return;
    						int newItemAmount = Integer.parseInt(args[2]);
    						if (newItemAmount > 1000) {
    							c.sendMessage("<shad=1242141>You can't spawn more than 1000 of an item");
    								return;
    									}
    						if((ID > 13300) && (ID < 13940)) {
    								c.sendMessage("<shad=214141>Ya'd think these would be spawnable?</col>");
    									return;
    							}else if((ID > 11250) && (ID < 11900)) {
    								c.sendMessage("<shad=214141>Cannot spawn godwars items</col>");
    									return;
    							}else if((ID > 1030) && (ID < 1080)) {
    								c.sendMessage("<shad=214141>You cannot spawn rares</col>");
    									return;
    							}else if((ID > 4600) && (ID < 4900)) {
    								c.sendMessage("<shad=212441>Can't spawn barrows buddy");
    									return;
    							}else if((ID > 14700) && (ID < 15000)) {
    								c.sendMessage("<shad=241> Can't Spawn Statuetes");
    									return;
    							}else if((ID > 13300) && (ID < 13800)) {
    								c.sendMessage("<shad=241> Nice try buddy, maybe next time");
    									return;
    						}else if ((ID <= 15500) && (ID >= 0) && (ID != UNSP) && (ID != DONITEMS)) {
    							c.getItems().addItem(ID, newItemAmount);		
    						}else {
    							c.sendMessage("<shad=214141>This Item is Unattainable or Earnable</col>");
    						}
    					} else {
    						c.sendMessage("Wrong usage: (Ex:(::item 995 1))");
    					}
    				} catch(Exception e) {
    					
    					}  
    					}
    Reply With Quote  
     

  2. #2  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    I would suggest to use correct tabbing to make it look cleaner.
    3 things though:

    Near the beginning, you have written "public static". I suggest you either let go of the "public static" part or move the line as a whole outside the method.

    Also near the beginning, you use "String[] args = playerCommand.split(" ");". Since almost every method uses that line (it's common to many commands), you could move it to near the top of the method.

    The third thing I want to say is about "(ID != UNSP) && (ID != DONITEMS)"
    "ID" is an integer and "UNSP" is an integer array (DONITEMS is too I guess).
    Are you sure that works? Try spawning an item in either one of those arrays, I guess you'll manage to do it.
    Why?
    Because it's int vs int[].
    What you need is this method:
    Code:
    private static boolean isInArray(int value, int[] array){
    	for(int arrayValue : array)
    		if(arrayValue == value)
    			return true;
    	return false;
    }
    Use as: !isInArray(ID, UNSP) && !isInArray(ID, DONITEMS)
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 2
    Last Post: 09-09-2012, 05:08 AM
  2. Would like some CC
    By TheRedArmy in forum Showcase
    Replies: 1
    Last Post: 07-26-2012, 09:21 AM
  3. Replies: 2
    Last Post: 04-01-2010, 08:17 PM
  4. Some npcs i would like
    By cheesesong in forum Requests
    Replies: 1
    Last Post: 11-18-2009, 12:57 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •