[525]Commands through one file.
Okay, this is quite simple and I am tired of making new classes for each command, and I am sure you're too.
Go to your packetHandler and replace your Command.java with this.
Code:
package com.rs2hd.packethandler;
import org.apache.mina.common.IoSession;
import com.rs2hd.model.Player;
import com.rs2hd.net.Packet;
import com.rs2hd.model.Location;
import com.rs2hd.model.ItemDefinition;
/**
*
* @author Luke132
* @author Peril
*/
public class Command implements PacketHandler {
@Override
public void handlePacket(Player player, IoSession session, Packet packet) {
String command = packet.readRS2String();
execute(player, command);
}
private void execute(Player player, String command) {
String cmd[] = command.split(" ");
cmd[0] = cmd[0].toLowerCase();
if(cmd[0].equals("emote")) {
player.animate(Integer.valueOf(cmd[1]));
}
if(cmd[0].equals("gfx")) {
player.graphics(Integer.valueOf(cmd[1]));
}
if(cmd[0].contains("inter")) {
player.getActionSender().displayInterface(Integer.parseInt(cmd[1]));
}
if(cmd[0].equals("pickup")) {
try {
if(ItemDefinition.forId(Integer.valueOf(cmd[1])) == null)
player.getActionSender().sendMessage("This item is currently not available.");
else
player.getInventory().addItem(Integer.valueOf(cmd[1]), Integer.valueOf(cmd[2]));
} catch (Exception e) {
player.getInventory().addItem(Integer.valueOf(cmd[1]), 1);
}
}
if(cmd[0].equals("teleport")) {
Location tele = null;
try {
tele = Location.location(Integer.parseInt(cmd[1]), Integer.parseInt(cmd[1]), Integer.parseInt(cmd[3]));
} catch (Exception e) {
tele = Location.location(Integer.parseInt(cmd[1]), Integer.parseInt(cmd[1]), 0);
}
player.teleport(tele);
}
}
}
These are just basic commands seeing I am starting a new project.
Other commands from the folder named "Commands" will not load after this is done. You will also be able to delete the folder "Commands" after removing some imports.
(h)