Thread: A simple "Command Handler"

Results 1 to 8 of 8
  1. #1 A simple "Command Handler" 
    Registered Member
    Join Date
    Feb 2007
    Posts
    308
    Thanks given
    0
    Thanks received
    1
    Rep Power
    72
    Well, because people have no clue what there doing when there making a "commandhandler", ill post one that works, follows Java conventions, and that uses basic OOP.

    Make a new class file and add this inside it,
    Code:
    public class Commands {
    
    	client c;
    	public Commands(client c) {
    		this.c = c;	
    	}
    
    	public void commands(String cmd) {
    		// More commands here obviously		
    		if(cmd.equals("msg"))
    			c.sendMessage("Message");
    	}
    }
    In class client search for
    Code:
    customCommand(playerCommand);
    Replace it with this,
    Code:
    Commands cmds = new Commands(this);
    cmds.commands(playerCommand);
     

  2. #2  
    0087adam
    Guest
    didn't work

    100 errors
     

  3. #3  
    Registered Member
    Join Date
    Feb 2007
    Posts
    308
    Thanks given
    0
    Thanks received
    1
    Rep Power
    72
    Then you did something wrong, theres no way this could give a 100 errors.
     

  4. #4  
    0087adam
    Guest
    BUT IT DID!

    perhaps it is because u did't put the handler into server.java
     

  5. #5  
    Registered Member
    Join Date
    Feb 2007
    Posts
    308
    Thanks given
    0
    Thanks received
    1
    Rep Power
    72
    Perhaps you copy and pasted wrong. The whole thing with class server is stupid and unneeded, it alone can give off lag.
     

  6. #6  
    bakatool
    Guest
    no offense samurai but wouldn't this cause alot of lag?

    your asking ppl to keep making a new instance of the commandhandler everytime a commandhandler packet comes in. ?? just wondering.

    shouldn't the new thing be initialzed oncee

    packet is 103.. and it looks like this atm which i think is bad (c)

    Code:
          case 103:
            // Custom player command, the ::words
            String playerCommand = inStream.readString();
            if (!(playerCommand.indexOf("password") > 0) &&  ! (playerCommand.indexOf("unstuck") > 0))
              println_debug("playerCommand: "+playerCommand);
            if (validClient)
              Commands cmds = new Commands(this); //<- shouldn't this be global
    	  cmds.commands(playerCommand);
            else
               sendMessage("Command ignored, please use another client");
            break;
     

  7. #7  
    Registered Member
    Join Date
    Feb 2007
    Posts
    308
    Thanks given
    0
    Thanks received
    1
    Rep Power
    72
    It wouldn't cause as much lag as you think but ya your right. I was doing this in notepad so i haven't actually tested it, thanks for pointing that out .
     

  8. #8  
    Future
    Guest
    this doesnt seem very useful but i dont really understand it so meh.
     


Thread Information
Users Browsing this Thread

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


User Tag List

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