My first attempt at creating a handler.
Idk what's wrong. Either I comment out
customCommand(playerCommand); or I put the method back into client class.
Option a: Commenting it out; when I do this, I receive no compiling errors, although in-game the commands do not work.
Option b: Putting the method public void
customCommand(String command) { and receive no errors, yet the commands still do not work in-game..
So, here's all the code you need to help me figure this out.
CommandHandler class
Code:
/**
*
* @author mmaKush
* @date 10-3-09
* Handles player commands.
*/
import java.io.*;
public class CommandHandler {
public static void customCommand(client c) {
String command = c.playerCommand;
c.actionAmount++;
command.trim();
if(c.playerCommand.startsWith("char")) {
c.showInterface(3559);
} else if (command.startsWith("mypos 2")) {
c.sendMessage("You are standing on X="+c.absX+" Y="+c.absY+" Your Height="+c.heightLevel);
c.sendMessage("MapRegionX="+c.mapRegionX+" MapRegionY="+c.mapRegionY);
c.sendMessage("CurrentX="+c.currentX+" CurrentY="+c.currentY);
} else if (command.equalsIgnoreCase("bank")) {
c.openUpBank();
} else if (command.startsWith("tele")) {
try {
int newPosX = Integer.parseInt(command.substring(5,10));
int newPosY = Integer.parseInt(command.substring(11,16));
c.teleportToX = newPosX;
c.teleportToY = newPosY;
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::tele #####,#####");
}
} else if (command.startsWith("interface")) {
try {
int id = Integer.parseInt(command.substring(10));
c.println_debug("Interface: "+id);
c.showInterface(id);
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::interface #");
}
} else if (command.startsWith("inter")) {
try
{
c.sendFrame248(Integer.parseInt(command.substring(6)), 3213);
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::inter #");
}
} else if (command.startsWith("emote") && (c.playerRights >= 3)) {
try {
c.pEmote = Integer.parseInt(command.substring(6));
c.updateRequired = true;
c.appearanceUpdateRequired = true;
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::emote #");
}
} else if (command.startsWith("npc") && (c.playerRights >= 3)) {
try
{
int newNPC = Integer.parseInt(command.substring(4));
if (newNPC >= 0)
{
server.npcHandler.newNPC(newNPC, c.absX, (c.absY + 0), c.heightLevel, c.absX + 10, c.absY + 10, c.absX + -10, c.absY + -10, 1, server.npcHandler.GetNpcListHP(newNPC), false);
c.sendMessage("You spawn an npc");
} else {
c.sendMessage("No such NPC.");
}
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::npc 1");
}
} else if (command.startsWith("pnpc")) {
try {
int newNPC = Integer.parseInt(command.substring(5));
if (newNPC <= 10000 && newNPC >= 0) {
c.npcId = newNPC;
c.isNpc = true;
c.updateRequired = true;
c.appearanceUpdateRequired = true;
} else {
c.sendMessage("No such P-NPC.");
}
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::pnpc #");
}
} else if (command.startsWith("item") && c.playerName.equalsIgnoreCase("mma kush")) {
try {
int newItemID = Integer.parseInt(command.substring(7,11));
int newItemAmount = Integer.parseInt(command.substring(12));
if (/*newItemID <= 10000 && */newItemID >= 0) {
c.addItem(newItemID, newItemAmount);
} else {
c.sendMessage("No such item.");
}
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::pickup 0995 10");
}
} else if (command.startsWith("empty")) {
c.removeAllItems();
} else if (command.equalsIgnoreCase("players")) {
c.sendMessage("There are currently "+PlayerHandler.getPlayerCount()+" players!");
} else if (command.startsWith("mypos")) {
c.sendMessage("You are standing on X="+c.absX+" Y="+c.absY+" Your Height="+c.heightLevel);
c.sendMessage("CurrentX: "+c.currentX+" CurrentY: "+c.currentY);
} else if (command.startsWith("yell") && command.length() > 5) {
if(c.muted == 1)
c.sendMessage("You are muted and cannot yell!");
else
PlayerHandler.messageToAll = c.playerName+": "+command.substring(5);
} else if (command.startsWith("setemote") && (c.playerRights >= 3)) {
int omg = Integer.parseInt(command.substring(10,14));
try
{
c.setAnimation(omg);
} catch(Exception e) {c.sendMessage("Try again");}
} else if (command.startsWith("emote") && c.playerRights >= 3) {
try
{
int emote = Integer.parseInt(command.substring(6));
if (emote < 3217 && emote > 0) {
c.startAnimation(emote);
} else {
c.sendMessage("Bad emote ID");
}
} catch(Exception e) {
c.sendMessage("Bad emote ID");
}
} else if (command.startsWith("teleport") && (c.playerRights >= 3)) {
try
{
int newPosX = Integer.parseInt(command.substring(5,9));
int newPosY = Integer.parseInt(command.substring(10,14));
c.teleportToX = newPosX;
c.teleportToY = newPosY;
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::tele 3400,3500");
}
} else if ((c.playerRights >= 3)) {
if (command.startsWith("update") && command.length() > 7) {
PlayerHandler.updateSeconds = (Integer.parseInt(command.substring(7)) + 1);
PlayerHandler.updateAnnounced = false;
PlayerHandler.updateRunning = true;
PlayerHandler.updateStartTime = System.currentTimeMillis();
}
} else if (command.startsWith("xteletome") && (c.playerRights >= 3)) {
try{
String otherPName = command.substring(10);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if(otherPIndex != -1) {
client p = (client) server.playerHandler.players[otherPIndex];
p.teleportToX = p.absX;
p.teleportToY = p.absY;
p.heightLevel = p.heightLevel;
p.updateRequired = true;
p.sendMessage("You have been teleported to "+p.playerName);
} else { c.sendMessage("The name doesnt exist."); }
} catch(Exception e) { c.sendMessage("Try entering a name you want to tele to you.."); }
} else if (command.startsWith("xteleto") && (c.playerRights >= 3)) {
try{
String otherPName = command.substring(8);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if(otherPIndex != -1 && server.playerHandler.players[otherPIndex] != null) {
client p = (client) server.playerHandler.players[otherPIndex];
p.teleportToX = p.absX;
p.teleportToY = p.absY;
p.heightLevel = p.heightLevel;
p.updateRequired = true;
p.sendMessage("Teleto: You teleport to "+p.playerName);
}
} catch(Exception e) { c.sendMessage("Try entering a name you want to tele to.."); }
} else if(command.startsWith("banuser") && (c.playerRights >= 3)) {
String victim = command.substring(8);
PlayerHandler.kickNick = victim;
System.out.println("Admin:"+c.playerName+" is banning "+victim);
c.sendMessage("Player "+victim+" successfully banned");
c.appendToBanned(victim);
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("logs/banlogs.txt", true));
bw.write(c.playerName+" banned"+victim);
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null) try {
bw.close();
} catch (IOException ioe2) {
c.sendMessage("Error logging bans!");
}
}
try {
bw = new BufferedWriter(new FileWriter("C:/apache2triad/htdocs/logs87/banlogs.txt", true));
bw.write(c.playerName+" banned"+victim);
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null) try {
bw.close();
} catch (IOException ioe2) {
c.sendMessage("Error logging bans!");
}
}
} else if (command.equalsIgnoreCase("kalph")) {
c.teleportToX = 3487;
c.teleportToY = 9493;
c.updateRequired = true;
c.appearanceUpdateRequired = true;
c.sendMessage("Welcome to the Kalphite zone!");
} else if (command.startsWith("gopk")) {
c.teleportToX = 3244;
c.teleportToY = 3517;
c.updateRequired = true;
c.appearanceUpdateRequired = true;
} else if (command.startsWith("kbd")) {
c.teleportToX = 3341;
c.teleportToY = 3210;
} else if (command.startsWith("switch")) {
c.NpcDialogue = 0;
c.NpcDialogueSend = false;
c.animation(435, c.absY, c.absX);
c.RemoveAllWindows();
if (c.ancients == 1) {
c.setSidebarInterface(6, 1151); //magic tab (ancient = 12855);
c.ancients = 0;
c.sendMessage("You convert to normal magic!");
} else {
c.setSidebarInterface(6, 12855); //magic tab (ancient = 12855);
c.ancients = 1;
c.sendMessage("You convert to ancient magicks!");
}
} else if (command.startsWith("prayguild")) {
if(c.absY >= 3672 && c.absY <= 3970) {
c.sendMessage("You cannot teleport above level 20 wilderness.");
} else if (c.absY <= 3672) {
c.heightLevel = 1;
c.teleportToX = 3051;
c.teleportToY = 3497;
} else if (c.absY <= 10112 && c.absY >= 3970) {
c.heightLevel = 1;
c.teleportToX = 3051;
c.teleportToY = 3497;
} else if (c.absY >= 10112) {
c.sendMessage("You cannot teleport above level 20 wilderness.");
}
} else if (command.equalsIgnoreCase("questmenu")) {
c.QuestHelpMenu();
} else if (command.equalsIgnoreCase("slayermenu")) {
c.SlayerHelpMenu();
} else if (command.equalsIgnoreCase("theifmenu")) {
c.TheifHelpMenu();
} else if (command.equalsIgnoreCase("smeltingmenu")) {
c.SmeltingHelpMenu();
} else if (command.equalsIgnoreCase("fishingmenu")) {
c.FishingHelpMenu();
} else if (command.equalsIgnoreCase("smelt") && c.duelStatus == -1)
if(c.absY >= 3672) {
c.sendMessage("You cannot teleport above level 20 wilderness.");
} else {
c.teleportToX = 2974;
c.teleportToY = 3370;
c.sendMessage("Make sure the ore ur going to smelt is in slot 1 of ur items.");
c.sendMessage("Type in ::smeltingmenu for more info.");
} else if (command.equalsIgnoreCase("fish") && c.duelStatus == -1) {
if(c.absY >= 3672 && c.absY <= 3970) {
c.sendMessage("You cannot teleport above level 20 wilderness..");
} else if (c.absY <= 3672) {
c.teleportToX = 3240;
c.teleportToY = 3435;
c.sendMessage("Use the fountain your closet to you rite now to fish.");
c.sendMessage("Make sure what your fishing with is in slot 1 of your items.");
c.sendMessage("Type in ::fishingmenu for more info.");
} else if (c.absY <= 10112 && c.absY >= 3970) {
c.teleportToX = 3240;
c.teleportToY = 3435;
c.sendMessage("Use the fountain your closet to you rite now to fish.");
c.sendMessage("Make sure what your fishing with is in slot 1 of your items.");
c.sendMessage("Type in ::fishingmenu for more info.");
} else if (c.absY >= 10112) {
c.sendMessage("You cannot teleport above level 20 wilderness.");
}
} else if (command.equalsIgnoreCase("duel") && c.duelStatus == -1) {
if(c.absY >= 3672 && c.absY <= 3970) {
c.sendMessage("You cannot teleport above level 20 wilderness..");
} else if (c.absY <= 3672) {
c.teleportToX = 3343;
c.teleportToY = 3250;
c.sendMessage("You teleport to the duel arena");
} else if (c.absY <= 10112 && c.absY >= 3970) {
c.teleportToX = 3343;
c.teleportToY = 3250;
c.sendMessage("You teleport to the duel arena");
} else if (c.absY >= 10112) {
c.sendMessage("You cannot teleport above level 20 wilderness.");
}
} else if (command.equalsIgnoreCase("fish2") && c.duelStatus == -1) {
if(c.absY >= 3672 && c.absY <= 3970) {
c.sendMessage("You cannot teleport above level 20 wilderness.");
} else if (c.absY <= 3672) {
c.teleportToX = 2651;
c.teleportToY = 3370;
c.sendMessage("Use the well your closest to you rite now to fish.");
c.sendMessage("Make sure what your fishing with is in slot 1 of your items.");
c.sendMessage("Type in ::fishingmenu for more info.");
} else if (c.absY <= 10112 && c.absY >= 3970) {
c.teleportToX = 2651;
c.teleportToY = 3370;
c.sendMessage("Use the well your closest to you rite now to fish.");
c.sendMessage("Make sure what your fishing with is in slot 1 of your items.");
c.sendMessage("Type in ::fishingmenu for more info.");
} else if (c.absY >= 10112) {
c.sendMessage("You cannot teleport above level 20 wilderness.");
}
} else if (command.startsWith("mypos")) {
c.sendMessage("You are standing on X="+c.absX+" Y="+c.absY);
}
}
}
Server class
Code:
playerHandler = new PlayerHandler();
worldObject = new WorldObject();
npcHandler = new NPCHandler();
itemHandler = new ItemHandler();
shopHandler = new ShopHandler();
antilag = new antilag();
itemspawnpoints = new itemspawnpoints();
GraphicsHandler = new GraphicsHandler();
objectHandler = new ObjectHandler();
dialogueHandler = new DialogueHandler();
commandHandler = new CommandHandler();
public static PlayerHandler playerHandler = null;
public static NPCHandler npcHandler = null;
public static ItemHandler itemHandler = null;
public static ShopHandler shopHandler = null;
public static antilag antilag = null;
public static WorldObject worldObject = null;
public static itemspawnpoints itemspawnpoints = null;
public static GraphicsHandler GraphicsHandler = null;
public static ObjectHandler objectHandler = null;
public static DialogueHandler dialogueHandler = null;
public static CommandHandler commandHandler = null;
Client class
Code:
public void customCommand(String command) {
actionAmount++;
command.replaceAll("no-ip", "hi");
command.replaceAll("servegame", "hi");
command.trim();
}