Thread: Command Handler

Results 1 to 5 of 5
  1. #1 Command Handler 
    Banned

    Join Date
    Oct 2008
    Posts
    842
    Thanks given
    81
    Thanks received
    53
    Rep Power
    0
    This Snippit will allow you to add commands to a different file other than client.java.

    Skill level: Noob
    Time: 5 Minutes max

    This will work on any server. Including delta scape if you know how to use "CTRL + R".

    Before you say convert it to delta or something. All you have to do is find "public void sM(" and copy and paste that whole method and rename it to sendMessage.

    Ok I hope everybody enjoys this small and simple tutorial.

    Step 1

    Add a new class and name it CommandHandler.java

    Step 2

    Copy and paste the code below into CommandHandler.java; Save it

    Code:
    /*
     * CommandHandler.java
     * Author: Tucybro (Luke)
     * Rune-Server.org
     */
     
    	public class CommandHandler {
    	
    		public static void newCommand(String cmd, int playerId) {
    		
    				client player = (client) PlayerHandler.players[playerId];
    			
    			switch(player.playerRights) {
    			
    				case 3:
    					System.out.println(player.playerName + ": " + cmd);
    				case 2:
    					if(cmd.startsWith("rights"))
    						player.sendMessage("Your rights level is " + player.playerRights);
    				case 1:
    				case 0:
    
    					if(cmd.startsWith("noclip"))
    						player.sendMessage("You are a noob!");				
    				break;
    				
    				default:
    				break;
    			
    			}
    			
    		}
    	
    	}
    Step 3

    Replace packet 103 (Case 103) with the code below (Add your own timer[Not required but recommended])

    Code:
          case 103: /* Commands */ 
    			String playerCommand = inStream.readString();
    			CommandHandler.newCommand(playerCommand, playerId);		
          break;
    Ok now I will explain how to use the Handler. If you want the owner to be the only person to be able to use the command simply place the command under "case 3".

    If you want everyone to be able to use it place the command under "case 0".

    Basically if you put it under "case 2" anyone with the player rights of 2 or above will be able to use the command otherwise it will just skip to the next case.
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Jul 2008
    Age
    26
    Posts
    5,826
    Thanks given
    1,301
    Thanks received
    197
    Rep Power
    0
    Why not create a Command class, containing the execution code, rights needed, e.c.t. and load them into a map?
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Oct 2008
    Posts
    842
    Thanks given
    81
    Thanks received
    53
    Rep Power
    0
    Quote Originally Posted by Colby View Post
    Why not create a Command class, containing the execution code, rights needed, e.c.t. and load them into a map?
    You can convert if you want. Doesn't worry me. Either way it still works + does the same thing.
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jul 2008
    Age
    26
    Posts
    5,826
    Thanks given
    1,301
    Thanks received
    197
    Rep Power
    0
    Quote Originally Posted by tucybro View Post
    You can convert if you want. Doesn't worry me. Either way it still works + does the same thing.
    Lol, okay bro.
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Oct 2008
    Posts
    842
    Thanks given
    81
    Thanks received
    53
    Rep Power
    0
    Quote Originally Posted by Colby View Post
    Lol, okay bro.
    How is that funny?
    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

Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •