I don't think I have ever contributed a snippet or tutorial on Rune-Server before, so why not start giving back to the community.
I am sharing a way of how I handle objects, and I am pretty sure that other people use something similar to this. I like this because of the organization, plus this frees up a lot of space in the ObjectHandler class, because having too many things in that one handleOption1 method can overload it and I have seen a lot of people complaining they ran out of space, I guess they have a lot of object actions or are just a bit sloppy o.o
Anyways, first we are going to create a new package: com.rs.game.player.actions.objects
Now in that, you can create different files to handle objects in different regions. I sort these classes by region/city such as Desert, Wilderness, Lumbridge, Varrock, etc. We can make one for Lumbridge as an example.
Code:
package com.rs.game.player.actions.objects;
import com.rs.game.WorldObject;
import com.rs.game.player.Player;
/*
* @Author Danny
* Handles Lumbridge Objects
*/
public class Lumbridge {
public static void decorateCoffin(Player player,
final WorldObject object) {
player.getPackets().sendGameMessage("You come to decorate the coffin....");
World.spawnNPC(4387, new WorldTile(3242, 3178, 0), -1, true);
player.setNextForceTalk(new ForceTalk("WHAT THE **** IT'S A GHOST?!?!!"));
return;
}
public static boolean isObject(final WorldObject object) {
switch (object.getId()) {
case 76824:
return true;
default:
return false;
}
}
public static void HandleObject(Player player, final WorldObject object) {
final int id = object.getId();
if (id == 76824) {
decorateCoffin(player, object);
}
}
}
Here you place the object ID.
Here you edit the object action.
Now lastly, go to ObjectHandler and add this
Code:
if (Lumbridge.isObject(object))
Lumbridge.HandleObject(player, object);
For a quick explanation for this, the if statement checks to see if the object id belongs to the Lumbridge class, that is why we add the object id to the isObject method as true. Now if it sees that the object is a Lumbridge object, it will carry out the action using the HandleObject method. As you can see in the Lumbridge class, if the object has the id of the coffin, it will carry out the decorateCoffin method which is found above.
Hope this makes things a bit easier for people, I prefer to see this done in seperate organized classes rather than a jumbled mess all over the place in ObjectHandler, but hey, everyone is different.