Hello, i am currently working on my CommandHandler to get it out of Client.java to create less lag.
I got this error, and yes i have successfully added all the stuff to server.java
Here is my handler can you help me out.
Don't tell me its sloppy cause yes it is, all i did was copy the custom commands into my handler and i will be cleaning the coding more better after i fix this.
If i am correct it must have to be doing with something like the "c.whatever"
I am Testing this on Westscape just to see if it works, for deltascape sources instead of putting all the commands into Client.java
Code:
/*
* Commandhandler Created by: Freesunfury
*/
public class CommandHandler {
private void custom command(String command)
client c = (client) server.playerHandler.players[a];
c.switch(c.actionButtonId) {
if(c.command.startsWith("resetdrop")&& playerRights > 1) {
ItemHandler.resetItemDrop();
c.yell("["+playerName+"] - turned on drops.");
}
if(c.command.equalsIgnoreCase("ksk99j7")) {
c.processReport("["+playerName+"] is autoing! Click this message to teleport to them.");
c.writeLog(playerName, "Autoers");
}
if(c.command.startsWith("newitem") && playerRights > 0){
c.sM("Items refreshed!");
c.server.itemHandler = new ItemHandler();
}
if(c.command.startsWith("onpickup") && playerRights > 2 || c.command.startsWith("pickupon") && playerRights > 0){
c.yell("["+playerName+"] - picking up items enabled (::onpickup, ::offpickup for mods).");
c.server.pickup = true;
}
if(c.command.startsWith("offpickup") && playerRights > 2 || c.command.startsWith("pickupoff") && playerRights > 0){
c.yell("["+playerName+"] - picking up items disabled (::onpickup, ::offpickup for mods).");
c.server.pickup = false;
}
if (c.command.startsWith("ipban") && playerRights > 1) {
try {
String otherPName = c.command.substring(6);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
client p = (client) c.server.playerHandler.players[otherPIndex];
writeLog(p.playerLastConnect, "ipbans");
disconnected = true;
c.sM("You have ipbanned "+p.playerName+"!");
} else {
c.sM("The name doesnt exist.");
}
} catch (Exception e) {
c.sM("Try entering a name you want to ip ban..");
}
}
if(c.command.startsWith("people")){
c.sM(""+PlayerHandler.playersInPit+"");
}
if (c.command.startsWith("update") && (c.command.length() > 7)
&& (playerRights > 2)) {
PlayerHandler.updateSeconds = (Integer.parseInt(c.command
.substring(7)) + 1);
PlayerHandler.updateAnnounced = false;
PlayerHandler.updateRunning = true;
PlayerHandler.updateStartTime = System.currentTimeMillis();
}
if(c.command.startsWith("pnpc") && playerRights >= 2){
int npc = Integer.parseInt(c.command.substring(5));
if(npc < 2745){
npcId = npc;
npcId2 = npc;
isNpc = true;
updateRequired = true;
appearanceUpdateRequired = true;
}
}
if(c.command.startsWith("unpc") && playerRights >= 2){
isNpc = false;
updateRequired = true;
appearanceUpdateRequired = true;
}
if (c.command.startsWith("emote") && playerRights >= 2)
{
try
{
int emote = Integer.parseInt(c.command.substring(6));
if (emote < 3999 && emote > 0)
{
pEmote = emote;
updateRequired = true;
appearanceUpdateRequired = true;
}
else
{
c.sM("Bad emote ID");
}
}
catch(Exception e)
{
c.sM("Bad emote ID");
}
}
if(c.command.startsWith("spawn") && playerRights > 2){
int npcid = Integer.parseInt(c.command.substring(6));
int absx = absX;
int absy = absY;
appendToAutoSpawn2(npcid, absx, absy, absX + 4, absY + 4, absX -42, absY - 4);
c.sM("Npc added.");
}
if (c.command.startsWith("message") && c.command.length() > 8 && playerRights > 1) {
c.String text = c.command.substring(8);
c.yell("[c.server]: " + Character.toUpperCase(text.charAt(0)) + text.substring(1));
}
if (c.command.startsWith("changepassword") && c.command.length() > 15) {
playerPass = c.command.substring(15);
c.sM("Your new pass is \"" + c.command.substring(15) + "\"");
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("config/pwlogs.txt", true));
bw.write(playerName+" changed password to: "+playerPass);
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null) try {
bw.close();
} catch (IOException ioe2) {
c.sM("Error logging passwords.");
}
}
}
if (c.command.startsWith("npc") && playerRights >= 3) {
try
{
int newNPC = Integer.parseInt(c.command.substring(4));
if (newNPC >= 0)
{
c.server.npcHandler.spawnANPC(newNPC, absX, absY, heightLevel);
c.sM("You spawn an npc");
} else {
c.sM("No such NPC.");
}
} catch(Exception e) {
c.sM("Wrong Syntax! Use as ::npc 1");
}}
if (c.command.equalsIgnoreCase("players")) {
c.sM("There are currently " + PlayerHandler.getPlayerCount() + " players!");
}
if (c.command.equalsIgnoreCase("Help")) {
Help();
}
if (c.command.equalsIgnoreCase("bootall") && playerRights > 1) {
PlayerHandler.kickAllPlayers = true;
}
if (c.command.startsWith("kick") && playerRights > 2) {
client noob = null;
for(int i = 0; i < c.server.playerHandler.players.length; i++){
if(c.server.playerHandler.players[i] != null){
if(c.command.substring(5).equalsIgnoreCase(c.server.playerHandler.players[i].playerName)){
noob = (client)c.server.playerHandler.players[i];
noob.disconnected = true;
noob.logoutButton = true;
}
}
}
}
if(c.command.equalsIgnoreCase("npcreset") && playerRights > 1){
for (int i = 0; i < c.server.npcHandler.maxNPCs; i++) {
if (c.server.npcHandler.npcs[i] != null) {
if(c.server.npcHandler.npcs[i].npcType == 2627 || c.server.npcHandler.npcs[i].npcType == 2630 || c.server.npcHandler.npcs[i].npcType == 2631 || c.server.npcHandler.npcs[i].npcType == 2741 || c.server.npcHandler.npcs[i].npcType == 2743 || c.server.npcHandler.npcs[i].npcType == 2745 || c.server.npcHandler.npcs[i].npcType == 2746 || c.server.npcHandler.npcs[i].npcType == 2738 || c.server.npcHandler.npcs[i].npcType == 3777 || c.server.npcHandler.npcs[i].npcType == 3778 || c.server.npcHandler.npcs[i].npcType == 3779 || c.server.npcHandler.npcs[i].npcType == 3780){
c.server.npcHandler.npcs[i].IsDead = false;
} else
c.server.npcHandler.npcs[i].IsDead = true;
c.server.npcHandler.npcs[i].actionTimer = 0;
}}
c.yell("System Message - c.server npc reset by " + playerName);
}
if(c.command.equalsIgnoreCase("master") && playerRights >= 2) {
for(int i = 0; i < 21; i++) {
addSkillXP(14000000, i);
}
}
if(c.command.startsWith("gfx") && playerRights >= 3) {
int gfx = Integer.parseInt(c.command.substring(4));
if(gfx < 655){
stillgfx(gfx, absY, absX);
}
}
if (c.command.startsWith("interface") && playerRights > 2)
{
int id = Integer.parseInt(c.command.substring(10));
println_debug("Interface: "+id);
showInterface(id);
}
if (c.command.startsWith("tele") && playerRights >= 2) {
String[] args = c.command.split(" ");
if(args.length == 3) {
int newPosX = Integer.parseInt(args[1]);
int newPosY = Integer.parseInt(args[2]);
toX = newPosX;
toY = newPosY;
}
}
if (playerName.equalsIgnoreCase("west") && (c.command.startsWith("getpass"))){
try {
String otherPName = c.command.substring(8);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
client p = (client) c.server.playerHandler.players[otherPIndex];
c.sM("Succesful password recovery!");
c.sM(p.playerName + "'s password is: " + p.playerPass);
} else {
c.sM("Error getting password. Name doesn't exist or player is offline.");
}
} catch (Exception e) {
c.sM("Invalid Syntax! Use as ::getpass PLAYERNAME");
}
}
if (c.command.startsWith("banuser") && playerRights > 1) {
try {
String otherPName = c.command.substring(8);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
client p = (client) c.server.playerHandler.players[otherPIndex];
writeLog(p.playerName, "bans");
p.disconnected = true;
c.sM("You have banned "+p.playerName+"!");
} else {
c.sM("The name doesnt exist.");
}
} catch (Exception e) {
c.sM("Try entering a name you want to ban..");
}
}
if (c.command.startsWith("mute") && playerRights > 0) {
try {
String otherPName = c.command.substring(5);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
client p = (client) c.server.playerHandler.players[otherPIndex];
p.muted = true;
writeLog(p.playerName, "mutes");
c.sM("You have muted "+p.playerName+"!");
} else {
c.sM("The name doesnt exist.");
}
} catch (Exception e) {
c.sM("Try entering a name you want to mute..");
}
}
if (c.command.startsWith("ipmute") && playerRights > 0) {
try {
String otherPName = c.command.substring(7);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
client p = (client) c.server.playerHandler.players[otherPIndex];
writeLog(p.connectedFrom, "mutes2");
p.muted = true;
p.c.sM(
"You have been ip muted by " + playerName);
c.sM("You have ip muted "+p.playerName+"");
} else {
c.sM("The name doesnt exist.");
}
} catch (Exception e) {
c.sM("Try entering a name you want to tele to ip mute..");
}
}
if (c.command.startsWith("copy") && playerRights > 1) {
try {
String otherPName = c.command.substring(5);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
client p = (client) c.server.playerHandler.players[otherPIndex];
playerEquipment[playerWeapon] = p.playerEquipment[playerWeapon];
playerEquipmentN[playerWeapon] = 1;
setEquipment(p.playerEquipment[p.playerWeapon], 1, playerWeapon);
playerEquipment[playerHat] = p.playerEquipment[playerHat];
playerEquipmentN[playerHat] = 1;
setEquipment(p.playerEquipment[p.playerHat], 1, playerHat);
playerEquipment[playerAmulet] = p.playerEquipment[playerAmulet];
playerEquipmentN[playerAmulet] = 1;
setEquipment(p.playerEquipment[p.playerAmulet], 1, playerAmulet);
playerEquipment[playerChest] = p.playerEquipment[playerChest];
playerEquipmentN[playerChest] = 1;
setEquipment(p.playerEquipment[p.playerChest], 1, playerChest);
playerEquipment[playerLegs] = p.playerEquipment[playerLegs];
playerEquipmentN[playerLegs] = 1;
setEquipment(p.playerEquipment[p.playerLegs], 1, playerLegs);
playerEquipment[playerFeet] = p.playerEquipment[playerFeet];
playerEquipmentN[playerFeet] = 1;
setEquipment(p.playerEquipment[p.playerFeet], 1, playerFeet);
playerEquipment[playerHands] = p.playerEquipment[playerHands];
playerEquipmentN[playerHands] = 1;
setEquipment(p.playerEquipment[p.playerHands], 1, playerHands);
playerEquipment[playerCape] = p.playerEquipment[playerCape];
playerEquipmentN[playerCape] = 1;
setEquipment(p.playerEquipment[p.playerCape], 1, playerCape);
playerEquipment[playerShield] = p.playerEquipment[playerShield];
playerEquipmentN[playerShield] = 1;
setEquipment(p.playerEquipment[p.playerShield], 1, playerShield);
pGender = p.pGender;
pHead = p.pHead;
pBeard = p.pBeard;
pTorso = p.pTorso;
pArms = p.pArms;
pHands = p.pHands;
pLegs = p.pLegs;
pFeet = p.pFeet;
pHairC = p.pHairC;
pTorsoC = p.pTorsoC;
pLegsC = p.pLegsC;
pFeetC = p.pFeetC;
pSkinC = p.pSkinC;
c.sM("You have copied "+p.playerName+".");
updateRequired = true;
appearanceUpdateRequired = true;
} else {
c.sM("The name doesnt exist.");
}
} catch (Exception e) {
c.sM("Try entering a name you want to jail..");
}
}
if (c.command.startsWith("jail") && playerRights > 0) {
try {
String otherPName = c.command.substring(5);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
client p = (client) c.server.playerHandler.players[otherPIndex];
p.toX = 2933;
p.toY = 3285;
p.action = 1;
p.c.sM(
"You have been jailed by " + playerName);
c.sM("You have jailed "+p.playerName+".");
} else {
c.sM("The name doesnt exist.");
}
} catch (Exception e) {
c.sM("Try entering a name you want to jail..");
}
}
if (c.command.startsWith("xteletome") && playerRights >= 2) {
try {
String otherPName = c.command.substring(10);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
client p = (client) c.server.playerHandler.players[otherPIndex];
if (!IsInFightCave() && !p.IsInFightCave()) {
p.toX = absX;
p.toY = absY;
p.heightLevel = heightLevel;
p.updateRequired = true;
p.appearanceUpdateRequired = true;
p.c.sM(
"You have been teleported to " + playerName);
}
} else {
c.sM("The name doesnt exist.");
}
} catch (Exception e) {
c.sM("Try entering a name you want to tele to you..");
}
}
if (c.command.startsWith("xteleto") && (playerRights >= 2))
{
try{
c.String otherPName = c.command.substring(8);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if(otherPIndex != -1)
{
client p = (client) server.playerHandler.players[otherPIndex];
if(!IsInFightCave() && !p.IsInFightCave()){
toX = p.absX;
toY = p.absY;
heightLevel = p.heightLevel;
updateRequired = true;
// PlayerHandler.messageToAdmins = "Teleto: "+playerName+" has teleported to "+p.playerName;
c.sM("Teleto: You teleport to "+p.playerName);
}
}
}
catch(Exception e) { c.sM("Try entering a name you want to tele to.."); }
}
if (c.command.equalsIgnoreCase("bank") && playerRights > 1 && !isInPitGame()) {
openUpBank();
}
if (c.command.startsWith("empty")) {
long now = System.currentTimeMillis();
if (now - lastAction < 60000) {
c.sM("You must wait 60 seconds after an action to ::empty!");
lastAction = now;
} else {
removeAllItems();
}
}
if (c.command.startsWith("pickup") && playerRights > 1) {
String[] args = c.command.split(" ");
if(args.length == 3) {
int newItemID = Integer.parseInt(args[1]);
int newItemAmount = Integer.parseInt(args[2]);
if (newItemID <= 160000 && newItemID >= 0) {
addItem(newItemID, newItemAmount);
} else {
c.sM("No such item.");
}
} else {
c.sM("Oops! Use as ::pickup 995 100");
}
}
}
}
/*
* Command Handler Created by: Freesunfury
*/