Thread: [Any Source] Making Handlers (New Files = Less Junk In Client Class!)

Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1 [Any Source] Making Handlers (New Files = Less Junk In Client Class!) 
    Registered Member LesterKnome's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    306
    Thanks given
    3
    Thanks received
    3
    Rep Power
    107
    Well today i'm going to be teaching you how to make a thing that has become a 'trend' in rsps, I will be teaching how to make a handler.

    What is a "Handler"?

    A handler is when you take a piece of code (Usually a packet) and put it into a new file to stop your client.java from being so cluttered up!

    Lol, why would i ever want to use a handler?


    Again the person of a handler is to make coding in packets easier, and to remove junk from client.java



    Now that we have that out of the way; let's get started. To make a handler make a new java file (Meaning the extension is .java, ex. client.java) and this can range from shitFace.java to rockCrab.java; it doesn't matter. So in this tutorial i will make a new file called 'objectClick.java'.

    Now, in your server class i will declare the following code (What you do might be different):
    Code:
    public static objectClick objectClick = null;
    [Did you know: They call it server class because the there is a 'class' called server declared in there!]

    this is making a new object in the objectClick class ( Which we have not made yet )

    Now in your main(String[] args) method add:
    Code:
    objectClick = new objectClick();
    [Did you know: When you make a java program the first method that is called is main(String[] args)!]

    Now let's open up that file we made shitFace or whatever it was; and let's declare a class in it. you can do this by simply adding:
    Code:
    public class objectClick {
    
    }
    [Warning!: Whatever the filename was called, that is the name of the class that needs to be declared!]

    Now let's make a new method called 'objectClick1' and let's pass a argument to at that requires a int type. We would do so like this (NOTE: You should make this argument and everything i do to, just with a different name):
    Code:
    public void objectClick1(int ID) {
    
    }
    Now in that method let's make a new variable like so:
    Code:
    client c = (client) server.playerHandler.players[ID];
    Now, add whatever code you wish to have in there, and whenever you want to use a variable or method from the client class use c.method(); or c.variable.

    Now to call the method from the client class (Perhaps in a packet or whatever)
    call this (Modified to your needs) :
    Code:
    server.objectClick.objectClick1(playerId);
    Enjoy
    I fighting for the crust of the little brown loaf
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jun 2008
    Posts
    163
    Thanks given
    5
    Thanks received
    0
    Discord
    View profile
    Rep Power
    18
    Good work feathercomb
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Dec 2008
    Posts
    47
    Thanks given
    0
    Thanks received
    1
    Rep Power
    1
    Ty alot!
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jun 2008
    Posts
    913
    Thanks given
    30
    Thanks received
    94
    Rep Power
    0
    It can also be called directly rather than declaring an object in the server class and calling that. You'd have to make all the methods and variables within the called class static though.
    Reply With Quote  
     

  5. #5  
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Quote Originally Posted by Primadude View Post
    It can also be called directly rather than declaring an object in the server class and calling that. You'd have to make all the methods and variables within the called class static though.
    Or declare an instance of the class in the player class.
    Reply With Quote  
     

  6. #6  
    Registered Member LesterKnome's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    306
    Thanks given
    3
    Thanks received
    3
    Rep Power
    107
    Quote Originally Posted by Cascade View Post
    Or declare an instance of the class in the player class.
    Like this?

    Code:
    public objectClick = new objectClick();
    I fighting for the crust of the little brown loaf
    Reply With Quote  
     

  7. #7  
    Registered Member
    Core's Avatar
    Join Date
    Sep 2007
    Posts
    4,194
    Thanks given
    11
    Thanks received
    393
    Rep Power
    1985
    Umm kinda, not really lol. You're pretty far off and in the Java Conventions, the first letter of each word in the name of class files are always capitalized.
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Nov 2008
    Posts
    2,180
    Thanks given
    148
    Thanks received
    99
    Rep Power
    2004
    Should be pretty self explanatory on how to make a handler. >.<

    Idk.
    Reply With Quote  
     

  9. #9  
    Donator

    Ecstasy's Avatar
    Join Date
    Sep 2008
    Age
    26
    Posts
    5,032
    Thanks given
    324
    Thanks received
    596
    Rep Power
    843
    Quote Originally Posted by Demetri View Post
    Should be pretty self explanatory on how to make a handler. >.<

    Idk.
    I agree.

    Reply With Quote  
     

  10. #10  
    Registered Member LesterKnome's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    306
    Thanks given
    3
    Thanks received
    3
    Rep Power
    107
    Quote Originally Posted by Ecstasy' View Post
    I agree.
    Someone requested this.

    Core can you please explain?
    I fighting for the crust of the little brown loaf
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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
  •