This Snippit will allow you to add commands to a different file other than client.java.
Skill level: Noob
Time: 5 Minutes max
This will work on any server. Including delta scape if you know how to use "CTRL + R".
Before you say convert it to delta or something. All you have to do is find "public void sM(" and copy and paste that whole method and rename it to sendMessage.
Ok I hope everybody enjoys this small and simple tutorial.
Step 1
Add a new class and name it CommandHandler.java
Step 2
Copy and paste the code below into CommandHandler.java; Save it
Code:
/*
* CommandHandler.java
* Author: Tucybro (Luke)
* Rune-Server.org
*/
public class CommandHandler {
public static void newCommand(String cmd, int playerId) {
client player = (client) PlayerHandler.players[playerId];
switch(player.playerRights) {
case 3:
System.out.println(player.playerName + ": " + cmd);
case 2:
if(cmd.startsWith("rights"))
player.sendMessage("Your rights level is " + player.playerRights);
case 1:
case 0:
if(cmd.startsWith("noclip"))
player.sendMessage("You are a noob!");
break;
default:
break;
}
}
}
Step 3
Replace packet 103 (Case 103) with the code below (Add your own timer[Not required but recommended])
Code:
case 103: /* Commands */
String playerCommand = inStream.readString();
CommandHandler.newCommand(playerCommand, playerId);
break;
Ok now I will explain how to use the Handler. If you want the owner to be the only person to be able to use the command simply place the command under "case 3".
If you want everyone to be able to use it place the command under "case 0".
Basically if you put it under "case 2" anyone with the player rights of 2 or above will be able to use the command otherwise it will just skip to the next case.