Thread: Using Commands

Results 1 to 3 of 3
  1. #1 Using Commands 
    Registered Member
    Join Date
    Apr 2011
    Posts
    159
    Thanks given
    5
    Thanks received
    15
    Rep Power
    23
    Hi everyone. I am trying to use very basic commands in the server I am playing with, but even though my character has the proper rights, almost no commands are working properly.

    For example, this setlevel command is very basic:

    Code:
    		case "setlvl":
    			if (parser.hasNext(2)) {
    				short skill = parser.nextShort();
    				short amount = parser.nextShort();
    				player.getLevels()[skill] = amount;
    				player.getMaxLevels()[skill] = amount;
    				player.getSkill().getExperience()[skill] = Skill.EXP_FOR_LEVEL[amount - 1];
    				player.getSkill().update();
    				player.send(new SendMessage("You set " + Skills.SKILL_NAMES[skill] + " to level " + amount + "."));
    			}
    			return true;

    But when I type something like
    :etlevel 5 99
    nothing happens. This is true with almost all of the commands.


    I am not sure if I am calling the commands wrong or if I am missing something here. I have looked through the CommandParser file to see if anything looks odd and I cannot find anything. This is that file:

    CommandParser.java

    Code:
    package com.mayhem.rs2.entity.player.net.in.command;
    
    
    /**
     * Parses a command.
     *
     * @author Michael | Chex
     */
    public class CommandParser {
    
    	/**
    	 * The arguments of the command.
    	 */
    	private String[] arguments;
    
    	/**
    	 * The argument index.
    	 */
    	private int argumentIndex = 0;
    
    	/**
    	 * Creates a new command parser.
    	 *
    	 * @param command
    	 *            - The command to parse.
    	 */
    	public static CommandParser create(String command) {
    		CommandParser parser = new CommandParser();
    		parser.arguments = command.split(" ");
    		return parser;
    	}
    
    	/**
    	 * Reads the next integer in the arguments.
    	 *
    	 * @return The next integer.
    	 * @throws NumberFormatException
    	 *             The argument is an invalid integer.
    	 * @see #nextShort()
    	 * @see #nextLong()
    	 * @see #nextString()
    	 * @see #nextDouble()
    	 * @see #nextByte()
    	 */
    	public final int nextInt() throws NumberFormatException {
    		return Integer.parseInt(nextString());
    	}
    
    	/**
    	 * Reads the next double in the arguments.
    	 *
    	 * @return The next double.
    	 * @throws NumberFormatException
    	 *             The argument is an invalid integer.
    	 * @see #nextShort()
    	 * @see #nextLong()
    	 * @see #nextString()
    	 * @see #nextDouble()
    	 * @see #nextByte()
    	 */
    	public final double nextDouble() throws NumberFormatException {
    		return Double.parseDouble(nextString());
    	}
    
    	/**
    	 * Reads the next long in the arguments.
    	 *
    	 * @return The next long.
    	 * @throws NumberFormatException
    	 *             The argument is an invalid long.
    	 * @see #nextShort()
    	 * @see #nextString()
    	 * @see #nextInt()
    	 * @see #nextDouble()
    	 * @see #nextByte()
    	 */
    	public final long nextLong() throws NumberFormatException {
    		return Long.parseLong(nextString());
    	}
    
    	/**
    	 * Reads the next byte in the arguments.
    	 *
    	 * @return The next byte.
    	 * @throws NumberFormatException
    	 *             The argument is an invalid byte.
    	 * @see #nextShort()
    	 * @see #nextLong()
    	 * @see #nextInt()
    	 * @see #nextDouble()
    	 * @see #nextString()
    	 */
    	public final byte nextByte() throws NumberFormatException {
    		return Byte.parseByte(nextString());
    	}
    
    	/**
    	 * Reads the next short in the arguments.
    	 *
    	 * @return The next short.
    	 * @throws NumberFormatException
    	 *             The argument is an invalid short.
    	 * @see #nextString()
    	 * @see #nextLong()
    	 * @see #nextInt()
    	 * @see #nextDouble()
    	 * @see #nextByte()
    	 */
    	public final short nextShort() throws NumberFormatException {
    		return Short.parseShort(nextString());
    	}
    
    	/**
    	 * Reads the next argument in the command.
    	 *
    	 * @return The next argument.
    	 * @throws ArrayIndexOutOfBoundsException
    	 *             The next argument does not exist.
    	 * @see #nextShort()
    	 * @see #nextLong()
    	 * @see #nextInt()
    	 * @see #nextDouble()
    	 * @see #nextByte()
    	 */
    	public final String nextString() throws ArrayIndexOutOfBoundsException {
    		if (argumentIndex + 1 >= arguments.length)
    			throw new ArrayIndexOutOfBoundsException("The next argument does not exist. [Size: " + arguments.length + ", Attempted: " + (argumentIndex + 1) + "]");
    
    		return arguments[++argumentIndex];
    	}
    
    	/**
    	 * Checks if the command parser has an unread argument.
    	 *
    	 * @return <code>True</code> if there is an unread argument left.
    	 */
    	public final boolean hasNext() {
    		return hasNext(1);
    	}
    
    	/**
    	 * Checks if the command parser has n unread arguments.
    	 *
    	 * @param length
    	 *            - The length of arguments to check.
    	 * @return <code>True</code> if there is n unread arguments left.
    	 */
    	public final boolean hasNext(int length) {
    		return argumentIndex + length < arguments.length;
    	}
    
    	/**
    	 * Gets the command name.
    	 *
    	 * @return The command name.
    	 */
    	public final String getCommand() {
    		return arguments[0];
    	}
    	
    	@Override
    	public String toString() {
    		String string = "";
    		for (int i = 0; i < arguments.length; i++) {
    			string += arguments[i] + " ";
    		}
    		return string.trim();
    	}
    }

    Can anyone help with this?
    Reply With Quote  
     

  2. #2  
    Donator

    Join Date
    Feb 2017
    Posts
    99
    Thanks given
    0
    Thanks received
    10
    Rep Power
    36
    1. Make sure your player has the permissions necessary to run the command.
    2. Use a debugger and set breakpoints through your command method make sure the command is being reached.

    These are the most common issues with commands. You may also want to click on the code and make sure it actually does something (or what you expect). Some servers have empty methods or redundant methods that don't do what you expect.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Feb 2014
    Posts
    195
    Thanks given
    12
    Thanks received
    14
    Rep Power
    35
    This is going to sound kind of stupid, but I figure it's worth mentioning anyway.
    Last I recall, when projects are compiled in IDEs like Netbeans, things like run .bat files don't really match up, or act different than when the project is ran in IDEs. Like it's bound specifically to the project in the IDE.

    Found that one out not too long ago.

    edit- also, are any other commands working?
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 03-28-2009, 10:11 PM
  2. useful commands..
    By Rhys in forum Configuration
    Replies: 6
    Last Post: 11-03-2008, 02:09 AM
  3. Useful commands
    By Unkn0wn in forum Configuration
    Replies: 2
    Last Post: 10-26-2008, 06:43 PM
  4. [508]Changing how to use commands[simple]
    By Rune Arc in forum Tutorials
    Replies: 20
    Last Post: 09-06-2008, 03:25 PM
  5. RS2E - can't use commands in wilderness
    By java_noob in forum Tutorials
    Replies: 2
    Last Post: 06-27-2008, 05:51 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
  •