Thread: Command Handler packet

Results 1 to 6 of 6
  1. #1 Command Handler packet 
    Registered Member
    Enjoi's Avatar
    Join Date
    Sep 2008
    Posts
    2,454
    Thanks given
    565
    Thanks received
    281
    Rep Power
    1325
    Well I'm not really sure how i would write this out. Here is a start:



    Code:
    package net.simon.packet.packets;
    
    public class Commands implements PacketInter {
    
    	@Override
    	public void processPacket(Client c, int packetType, int packetSize) {
    		if(packetType == 103) {
    		
    	}
    }
    )

    Now what do i need to put in for it to handle commands?
     

  2. #2  
    Codex
    Rowan's Avatar
    Join Date
    Sep 2008
    Age
    25
    Posts
    1,593
    Thanks given
    0
    Thanks received
    20
    Rep Power
    1092
    put like int command = ...

    and then start making them..if (command.startsWith) or cmd[1] like pali did.

    edit: pali's:

    String playerCommand = p.stream.readString().toLowerCase();
    String[] cmd = playerCommand.split(" ");

    if (cmd[0].startsWith("name"){} or .equals or shit.


    edit2:
    and ofcourse load it in the packet whatever the packet id is.
    declare public Commands cmd = new Commands(); then in the packet put cmd.processPacket(c, packetType, packetSize);
    [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
     

  3. #3  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    Sec lemme get on my comp
     

  4. #4  
    Registered Member
    Enjoi's Avatar
    Join Date
    Sep 2008
    Posts
    2,454
    Thanks given
    565
    Thanks received
    281
    Rep Power
    1325
    Quote Originally Posted by Rowan View Post
    put like int command = ...

    and then start making them..if (command.startsWith) or cmd[1] like pali did.

    edit: pali's:

    String playerCommand = p.stream.readString().toLowerCase();
    String[] cmd = playerCommand.split(" ");

    if (cmd[0].startsWith("name"){} or .equals or shit.


    edit2:
    and ofcourse load it in the packet whatever the packet id is.
    declare public Commands cmd = new Commands(); then in the packet put cmd.processPacket(c, packetType, packetSize);


    the 2nd edit you put there is the easy bit
     

  5. #5  
    Codex
    Rowan's Avatar
    Join Date
    Sep 2008
    Age
    25
    Posts
    1,593
    Thanks given
    0
    Thanks received
    20
    Rep Power
    1092
    btw off topic perceptionz made fun out of us, he posted a thread where we "flame" eachother in sb.
    [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
     

  6. #6  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    Step 1:

    class 1- the interface
    Code:
    public interface Command {
    
           public void handleCommand(Client c., String command);
    
    }
    Step 2:

    Command manager

    Code:
    
    private Map<String, Command> commands = new HashMap<String, Command>();
    
    public static void loadAllCommands() {
            commands.put("commandname", commandObject());
            System.out.println(commands.size() + " commands loaded.");
    }
    
    public static void handleCommand(Client c, String name) {
           if(!commands.contains(name)) {
                  //command doesnt exit
           } else {
                  commands.get(name).handleCommand(c, name);
           }
    }
    Test command


    Code:
    public class TestCommand implements Command {
    
         public void handleCommand(Client c, String command) {
         }
    
    }
     


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
  •