Thread: Commands not working?

Results 1 to 6 of 6
  1. #1 Commands not working? 
    Member

    Join Date
    Nov 2008
    Age
    27
    Posts
    4,859
    Thanks given
    774
    Thanks received
    341
    Rep Power
    0
    I'm trying to move my commands to a different file from what it originally was to make it easier for me any my brother to find them.

    When originally called from the Player.java they worked,
    Code:
    player.handleCommand(keyword, Arrays.copyOfRange(split, 1, split.length), command.substring(command.indexOf(" ") + 1));
    Now loading from a Commands.java calling it as commands.handleCommand none of them work?

    Here's my method that calls them.

    Code:
    	private void handleCommand(Player player, Packet packet) {
    		try {
    			String command = packet.getIn().readString();
    			String[] split = command.split(" ");
    			String keyword = split[0].toLowerCase();
    			commands.handleCommand(keyword, Arrays.copyOfRange(split, 1, split.length), command.substring(command.indexOf(" ") + 1));
    			}catch (Exception e) {
    			}
    	}

    Here's the method in the commands file.

    Code:
    	public void handleCommand(String keyword, String[] args, String fullString) {
    		keyword = keyword.toLowerCase();
    
    		if (player.getUsername().equalsIgnoreCase("James")||player.getUsername().equalsIgnoreCase("Vince")) { // Administrators
                              if (keyword.equals("potions") && player.getStaffRights() == 2) {
    					if (player.inWild()) {
    						actionSender.sendMessage("You can't use this command in the wilderness.");
    						return;
    					}
    					inventory.addItem(new Item(2437, 100));
    					inventory.addItem(new Item(2441, 100));
    					inventory.addItem(new Item(2443, 100));
    					inventory.addItem(new Item(2435, 100));
    				}
                    }}
    So what could stop it from working but it worked when it was in Player.java?
    Reply With Quote  
     

  2. #2  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Code:
    }catch (Exception e) {
    			}
    Try not to ignore exceptions for one
    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Member

    Join Date
    Nov 2008
    Age
    27
    Posts
    4,859
    Thanks given
    774
    Thanks received
    341
    Rep Power
    0
    Quote Originally Posted by Stuart View Post
    Code:
    }catch (Exception e) {
    			}
    Try not to ignore exceptions for one
    I used e.printStackTrace(); and it didn't print anything.
    Reply With Quote  
     

  5. #4  
    Jake from State Farm

    FKN Jake's Avatar
    Join Date
    Nov 2013
    Posts
    675
    Thanks given
    45
    Thanks received
    58
    Rep Power
    153
    Quote Originally Posted by Snow Cat123 View Post
    I used e.printStackTrace(); and it didn't print anything.
    It doesn't at least on my source. I have e.printStackTrace(); and if the command doesn't work it sends me a message "Error executing command"
    Reply With Quote  
     

  6. #5  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by Snow Cat123 View Post
    I used e.printStackTrace(); and it didn't print anything.

    It will only print the stacktrace if something within the method is incorrectly used (E.G misused command format). I'm almost positive your commands method is not being triggered. I feel like you didn't change the packet to read commands from this new method so it's still trying to read them from the old one and that contains none. You can always use System.out.println(""); to try and test if the method even gets triggered. If not, the mistake isn't in the method lol.
    Attached image
    Reply With Quote  
     

  7. #6  
    Member

    Join Date
    Nov 2008
    Age
    27
    Posts
    4,859
    Thanks given
    774
    Thanks received
    341
    Rep Power
    0
    Quote Originally Posted by Kris View Post

    It will only print the stacktrace if something within the method is incorrectly used (E.G misused command format). I'm almost positive your commands method is not being triggered. I feel like you didn't change the packet to read commands from this new method so it's still trying to read them from the old one and that contains none. You can always use System.out.println(""); to try and test if the method even gets triggered. If not, the mistake isn't in the method lol.
    Code:
    	private void handleCommand(Player player, Packet packet) {
    		try {
    			String command = packet.getIn().readString();
    			String[] split = command.split(" ");
    			String keyword = split[0].toLowerCase();
    			System.out.println("Lolcopta2");
    			commands.handleCommand(keyword, Arrays.copyOfRange(split, 1, split.length), command.substring(command.indexOf(" ") + 1));
    			//player.handleCommand(keyword, Arrays.copyOfRange(split, 1, split.length), command.substring(command.indexOf(" ") + 1));
    		} catch (Exception e) {
    		}
    	}
    This prints Lolcopta2 and not lolcopta which I put in the method of commands.java, if I make it print after commands.Handle command it doesn't print any of the lolcopta's. The method is exactly the same as the one in Player.java, so I don't see how it doesn't work?


    Here's the code that calls the handleCommand(player, packet) rather than the keyword, argument and substring

    Code:
    	@Override
    	public void handlePacket(Player  player, Packet packet) {
    		switch (packet.getOpcode()) {
    			case COMMAND :
    				handleCommand(player, packet);
    				break;
    		}
    	}
    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. BattleScape commands not working
    By DarkArt in forum Help
    Replies: 7
    Last Post: 12-09-2009, 05:32 PM
  2. [CLEANED V4] Commands not working?
    By Unity in forum Help
    Replies: 4
    Last Post: 06-29-2009, 02:20 AM
  3. commands not working !!!
    By RuneBlaze in forum Help
    Replies: 14
    Last Post: 05-11-2009, 01:41 PM
  4. making commands not work in wildy
    By Jared1220 in forum Requests
    Replies: 9
    Last Post: 11-10-2008, 06:37 PM
  5. Yell command not working
    By mitch123hoff in forum Help
    Replies: 7
    Last Post: 10-31-2008, 06:42 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
  •