Thread: [PI] Command doesn't work. [PI]

Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1 [PI] Command doesn't work. [PI] 
    Registered Member Brighter's Avatar
    Join Date
    Apr 2013
    Posts
    144
    Thanks given
    13
    Thanks received
    15
    Rep Power
    11
    This is what Eclipse shows as error:


    Code:
    		if (playerCommand.startsWith("sellitem")) {
    			try {
    				String[] args = playerCommand.split(" ");
    				if (!args[1] == Config.ALLOWED_SELLITEMS.length) {
    					c.sendMessage("You're not allowed to sell this item");
    					return;
    				}
    				c.getItems().deleteItem(args[1], 1);
    				c.getItems().addItem(995, Config.ALLOWED_SELLITEMS[1]);
    				c.sendMessage("You sell the item for " +Config.ALLOWED_SELLITEMS[1] + " coins.");
    			} catch(Exception e) {				
    			}
    		}
    Can anyone please help me fixing the command? I can't come out of it.
    Rep and thanks will be given.

    - Brighter



    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Mar 2012
    Posts
    172
    Thanks given
    44
    Thanks received
    12
    Rep Power
    36
    Code:
    if (playerCommand.startsWith("sellitem")) {
    			try {
    				String[] args = playerCommand.split(" ");
    				if (!args[1] == Config.ALLOWED_SELLITEMS.length) {
    					c.sendMessage("You're not allowed to sell this item");
    					return;
    				}
    				c.getItems().deleteItem(args[1], 1);
    				c.getItems().addItem(995, Config.ALLOWED_SELLITEMS[1]);
    				c.sendMessage("You sell the item for " +Config.ALLOWED_SELLITEMS[1] + " coins.");
    			} catch(Exception e) {				
    		}
    try that
    Mah hero dyrus

    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member Brighter's Avatar
    Join Date
    Apr 2013
    Posts
    144
    Thanks given
    13
    Thanks received
    15
    Rep Power
    11
    Quote Originally Posted by tomasio View Post
    Code:
    if (playerCommand.startsWith("sellitem")) {
    			try {
    				String[] args = playerCommand.split(" ");
    				if (!args[1] == Config.ALLOWED_SELLITEMS.length) {
    					c.sendMessage("You're not allowed to sell this item");
    					return;
    				}
    				c.getItems().deleteItem(args[1], 1);
    				c.getItems().addItem(995, Config.ALLOWED_SELLITEMS[1]);
    				c.sendMessage("You sell the item for " +Config.ALLOWED_SELLITEMS[1] + " coins.");
    			} catch(Exception e) {				
    		}
    try that
    Thanks for trying to help, but unfortunately it didn't work.



    Reply With Quote  
     

  5. #4  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    This should work.

    Code:
    	ArrayList<Integer> allowedItems = new ArrayList<Integer>();
    	private void loadSellableItems() {
    		for(int i = 0; i < Config.ALLOWED_SELLITEMS.length; i++)
    			allowedItems.add(Config.ALLOWED_SELLITEMS[i]);
    	}
    	
    	if (playerCommand.startsWith("sellitem")) {
    		try {
    			String[] args = playerCommand.split(" ");
    			int itemId = Integer.parseInt(args[1]);
    			if(allowedItems.size() <= 0) {
    				loadSellableItems();
    				allowedItems.trimToSize();
    			}
    			if(!allowedItems.contains(itemId)) {
    				c.sendMessage("Sorry but you cannot sell this item.");
    				return;
    			}
    			c.getItems().deleteItem(itemId, 1);
    			c.getItems().addItem(995, Config.ALLOWED_SELLITEMS[1]);
    			c.sendMessage("You sell the item for " +Config.ALLOWED_SELLITEMS[1] + " coins.");
    		} catch(Exception e) {				
    		}
    	}
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Registered Member Brighter's Avatar
    Join Date
    Apr 2013
    Posts
    144
    Thanks given
    13
    Thanks received
    15
    Rep Power
    11
    Quote Originally Posted by Jason View Post
    This should work.

    Code:
    	ArrayList<Integer> allowedItems = new ArrayList<Integer>();
    	private void loadSellableItems() {
    		for(int i = 0; i < Config.ALLOWED_SELLITEMS.length; i++)
    			allowedItems.add(Config.ALLOWED_SELLITEMS[i]);
    	}
    	
    	if (playerCommand.startsWith("sellitem")) {
    		try {
    			String[] args = playerCommand.split(" ");
    			int itemId = Integer.parseInt(args[1]);
    			if(allowedItems.size() <= 0) {
    				loadSellableItems();
    				allowedItems.trimToSize();
    			}
    			if(!allowedItems.contains(itemId)) {
    				c.sendMessage("Sorry but you cannot sell this item.");
    				return;
    			}
    			c.getItems().deleteItem(itemId, 1);
    			c.getItems().addItem(995, Config.ALLOWED_SELLITEMS[1]);
    			c.sendMessage("You sell the item for " +Config.ALLOWED_SELLITEMS[1] + " coins.");
    		} catch(Exception e) {				
    		}
    	}


    Thank you very much for helping, but it didn't work again. Do you maybe have any idea on how to fix it?



    Reply With Quote  
     

  8. #6  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    You have to add the import for ArrayList with the others before the class decleration

    import java.util.ArrayList;
    Reply With Quote  
     

  9. #7  
    Registered Member Brighter's Avatar
    Join Date
    Apr 2013
    Posts
    144
    Thanks given
    13
    Thanks received
    15
    Rep Power
    11
    Quote Originally Posted by Jason View Post
    You have to add the import for ArrayList with the others before the class decleration

    import java.util.ArrayList;
    Thanks a ton for helping! I'm coming really close. I have one last error.

    I'm really sorry for bothering you so much but if you could fix that I'll be extremely glad.



    Reply With Quote  
     

  10. #8  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Can you post the error that eclipse has given you rather then showing just the red line.
    Reply With Quote  
     

  11. Thankful user:


  12. #9  
    Extreme Donator

    Jilic-Matt's Avatar
    Join Date
    May 2011
    Age
    29
    Posts
    1,612
    Thanks given
    799
    Thanks received
    494
    Rep Power
    540
    the most useless information you could have possibly suplied

    Attached image
    Reply With Quote  
     

  13. #10  
    PokeFrontier Java Developer

    Pokemon's Avatar
    Join Date
    May 2011
    Posts
    2,726
    Thanks given
    495
    Thanks received
    807
    Rep Power
    1260
    Quote Originally Posted by Brighter View Post


    Thank you very much for helping, but it didn't work again. Do you maybe have any idea on how to fix it?
    import the array list

    Code:
    import java.util.ArrayList;
    and for this



    its just a problem with eclipse when you don't save the file just do ctrl + s


    Attached image


    I love
    Reply With Quote  
     

  14. Thankful user:


Page 1 of 2 12 LastLast

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. [pi] ::tele commands doesn't work
    By mr code in forum Help
    Replies: 10
    Last Post: 11-29-2011, 11:37 PM
  2. My Run doesn't work ! [PI]
    By Lootz in forum Help
    Replies: 4
    Last Post: 06-16-2011, 05:46 AM
  3. [PI]Thieving doesn't work? :L[DSPK]
    By CommunityX in forum Help
    Replies: 1
    Last Post: 03-26-2011, 12:23 PM
  4. [PI] Mute command doesn't work
    By Beanerrr in forum Help
    Replies: 13
    Last Post: 02-13-2011, 10:54 PM
  5. Teleporting doesn't work[PI]
    By sketzo in forum Help
    Replies: 3
    Last Post: 11-28-2010, 04:39 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •