Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java help? Possibly easy.

    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.~

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    This is "JavaScript programming" sub-forum, not for Java. Request a moderator to move this thread to the right forum.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •