So, I made this code for my server, I added it but a get a few errors. a guy told me how to fix but I dont really understand.
My code is-
Code:
} else if (cmd[0].equals("banuser")) {
int id = Engine.getIdFromName(cmd[1]);
if (id == 0) {
p.frames.sendMessage(p, "Player either does not exist or is not online!");
return;
}
Player p2 = Engine.players[id];
if (p2 == null) {
return;
}
p2.disconnected[0] = true;
FileManager fm = new FileManager();
fm.appendData("banned/bannedusers.dat", cmd[1]);
fm = null;
Server.loadBannedUsers();
p.frames.sendMessage(p, "You have banned this user succesfuly!");
} else if (cmd[0].equals("ipban")) {
int id = Engine.getIdFromName(cmd[1]);
if (id == 0) {
p.frames.sendMessage(p, "Player either does not exist or is not online!");
return;
}
Player p2 = Engine.players[id];
if (p2 == null) {
return;
}
p2.disconnected[0] = true;
FileManager fm = new FileManager();
fm.appendData("banned/bannedhosts.dat", p2.connectionIP);
fm = null;
Server.socketListener.loadBannedHosts();
p.frames.sendMessage(p, "You have ip banned this user succesfuly!");
}
My error is-
Code:
.\palidino76\rs2\io\packets\Commands.java:331: non-static method getIdFromName(j
ava.lang.String) cannot be referenced from a static context
int id = Engine.getIdFromName(cmd[1]);
^
.\palidino76\rs2\io\packets\Commands.java:341: cannot find symbol
symbol : class FileManager
location: class palidino76.rs2.io.packets.Commands
FileManager fm = new FileManager();
^
.\palidino76\rs2\io\packets\Commands.java:341: cannot find symbol
symbol : class FileManager
location: class palidino76.rs2.io.packets.Commands
FileManager fm = new FileManager();
^
.\palidino76\rs2\io\packets\Commands.java:344: loadBannedUsers() has private acc
ess in palidino76.rs2.Server
Server.loadBannedUsers();
^
.\palidino76\rs2\io\packets\Commands.java:347: non-static method getIdFromName(j
ava.lang.String) cannot be referenced from a static context
int id = Engine.getIdFromName(cmd[1]);
^
.\palidino76\rs2\io\packets\Commands.java:357: cannot find symbol
symbol : class FileManager
location: class palidino76.rs2.io.packets.Commands
FileManager fm = new FileManager();
^
.\palidino76\rs2\io\packets\Commands.java:357: cannot find symbol
symbol : class FileManager
location: class palidino76.rs2.io.packets.Commands
FileManager fm = new FileManager();
^
.\palidino76\rs2\io\packets\Commands.java:358: cannot find symbol
symbol : variable connectionIP
location: class palidino76.rs2.players.Player
fm.appendData("banned/bannedhosts.dat", p2.connectionIP);
^
.\palidino76\rs2\io\packets\Commands.java:360: loadBannedHosts() has private acc
ess in palidino76.rs2.net.SocketListener
Server.socketListener.loadBannedHosts();
^
9 errors
the reply was-
Code:
Public void getIdForName - Public static void
Add the import for the fileManager class
And make the method loadBannedHosts() public instead of private
can any1 help? Thanks!
~.Tony.~