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