[Solved] Strange error appeares only on my server!

Discussion in 'Plugin Development' started by Ancetras, Feb 21, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Ancetras

    Solved!
    Instead of my PexHandler class i used "if(player.hasPermission("SagaCraft.Admin")){"

    ---------------------------------------------

    Hi!

    When i start this plugin in my local server, it works ...

    but when i start it in my public server, it doesn't work and the log file gives me this error:

    Code:
    2012-02-21 15:25:34 [SEVERE] Could not load 'plugins/SagaCraft.jar' in folder 'plugins':
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:136)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:286)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:201)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:164)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:140)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:148)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.NoSuchMethodError: ancetras.main.integrations.PexHandler.<init>(Lancetras/main/SagaCraft;)V
        at ancetras.main.SagaCraft.<init>(SagaCraft.java:26)
        ... 13 more
    here my plugin:

    Code:
    public class SagaCraft extends JavaPlugin{
        public static Logger log = Logger.getLogger("Minecraft");
     
          public PexHandler pexHandler = new PexHandler(this);
        public PListener userListener = new PListener(this);
        public UserManager userManager = new UserManager(this);
        public final SpellManager spellsManager = new SpellManager(this);
     
        public Jobs jobsConfig = new Jobs(this);
        public Spells spellsConfig = new Spells(this);
        public General settingConfig = new General(this);
        public Altars altarsConfig = new Altars(this);
     
        public static File dataFolder;
     
        public void onDisable(){
            this.spellsManager.stop();
            log.info("[SagaCraft] SagaCraft is disabled!");
        }
        public void onEnable() {
            log.info("====================  SagaCraft  ======================");
                dataFolder = getDataFolder();
                if (!dataFolder.exists()) {
                    log.info("[SagaCraft] Directory doesn't exists! Attempting to create one ...");
                    dataFolder.mkdir();
                    log.info("[SagaCraft] SagaCraft directory created!");
                }
                UserManager.load();
                Altars.load();
                Spells.load();
                Jobs.load();
                General.load();
     
                this.spellsManager.start();
                PluginManager pm = getServer().getPluginManager();
                pm.registerEvent(Event.Type.PLAYER_MOVE, this.userListener, Event.Priority.Normal, this);
                pm.registerEvent(Event.Type.PLAYER_QUIT, this.userListener, Event.Priority.Normal, this);
                pm.registerEvent(Event.Type.PLAYER_JOIN, this.userListener, Event.Priority.Normal, this);
                pm.registerEvent(Event.Type.PLAYER_INTERACT, this.userListener, Event.Priority.Normal, this);
                pm.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, this.userListener, Event.Priority.Normal, this);
                log.info("[SagaCraft] Enabled (v1.0)! Plugin by Ancetras.");
            log.info("======================================================");
        }
    }
    PexHandler is the page for PermissionEx:

    Code:
    public class PexHandler{
        public SagaCraft plugin;
     
        public PexHandler(SagaCraft instance) {
            plugin = instance;
        }
     
        public static boolean isAdmin(Player p){
            if (Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx")) {
                PermissionManager permissions = PermissionsEx.getPermissionManager();
                if (permissions.has(p, "SagaCraft.Admin"))
                    return true;
            }
            return p.isOp();
        }
    }
    
     
  2. Offline

    Gravity

    It probably means the server isnt using PEX :p
     
  3. Offline

    dillyg10

    Are you using the latest version of bukkit? Do you have all of your other plugins working that you are hooking into?
     
  4. Offline

    Ancetras

    Yes! My public server is almost the same as my local server ... PermissionEx works perfect and another plugin of mine works correctly ... This error just appeared randomly ... dunno why T.T I can't figure out what the problem is T.T
     
  5. Offline

    Smex

    An error can't occur without a source for the error, so an error can't be random.
    Post your serverlog as a file.
     
  6. Offline

    Ancetras

    I tried to delete the line "public PexHandler pexHandler = new PexHandler(this);" and it works. But ... when i try to write the commands in the server chat an error appears ...

    Code:
    2012-02-22 12:06:32 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'sc' in plugin SagaCraft v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:402)
        at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:784)
        at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:744)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:732)
        at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:33)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:100)
        at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:537)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:435)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.NoSuchMethodError: ancetras.main.integrations.PexHandler.isAdmin(Lorg/bukkit/entity/Player;)Z
        at ancetras.main.SagaCraft.onCommand(SagaCraft.java:76)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 12 more
    Here my main class with the commands line:

    Code:
    public class SagaCraft extends JavaPlugin{
        public static Logger log = Logger.getLogger("Minecraft");
     
     
        public PListener userListener = new PListener(this);
        public UserManager userManager = new UserManager(this);
        public final SpellManager spellsManager = new SpellManager(this);
       
        public Jobs jobsConfig = new Jobs(this);
        public Spells spellsConfig = new Spells(this);
        public General settingConfig = new General(this);
        public Altars altarsConfig = new Altars(this);
       
        public static File dataFolder;
     
        public void onDisable(){
            this.spellsManager.stop();
            log.info("[SagaCraft] SagaCraft is disabled!");
        }
        public void onEnable() {
            log.info("====================  SagaCraft  ======================");
                dataFolder = getDataFolder();
                if (!dataFolder.exists()) {
                    log.info("[SagaCraft] Directory doesn't exists! Attempting to create one ...");
                    dataFolder.mkdir();
                    log.info("[SagaCraft] SagaCraft directory created!");
                }
                UserManager.load();
                Altars.load();
                Spells.load();
                Jobs.load();
                General.load();
       
                this.spellsManager.start();
                PluginManager pm = getServer().getPluginManager();
                pm.registerEvent(Event.Type.PLAYER_MOVE, this.userListener, Event.Priority.Normal, this);
                pm.registerEvent(Event.Type.PLAYER_QUIT, this.userListener, Event.Priority.Normal, this);
                pm.registerEvent(Event.Type.PLAYER_JOIN, this.userListener, Event.Priority.Normal, this);
                pm.registerEvent(Event.Type.PLAYER_INTERACT, this.userListener, Event.Priority.Normal, this);
                pm.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, this.userListener, Event.Priority.Normal, this);
                log.info("[SagaCraft] Enabled (v1.0)! Plugin by Ancetras.");
            log.info("======================================================");
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if ((sender instanceof Player)) {
                Player player = (Player)sender;
                if (commandLabel.equalsIgnoreCase("sc")) {
                    if (args.length == 0) {
                        player.sendMessage(ChatColor.WHITE + "{" + ChatColor.AQUA + " SagaCraft plugin Commands " + ChatColor.WHITE + "}");
                        player.sendMessage(ChatColor.YELLOW + "/sc " + ChatColor.GRAY + ": " + ChatColor.GRAY + "shows this help.");
                        player.sendMessage(ChatColor.YELLOW + "/sc info " + ChatColor.GRAY + ": " + ChatColor.GRAY + "shows info about you.");
                       
                        if (PexHandler.isAdmin(player)) {
                            player.sendMessage(ChatColor.YELLOW + "/sc join <job> " + ChatColor.GRAY + ": " + ChatColor.GRAY + "join a class.");
                            player.sendMessage(ChatColor.YELLOW + "/sc leave " + ChatColor.GRAY + ": " + ChatColor.GRAY + "leave a class.");
                        }
                        player.sendMessage("");
                        return true;
                    }
                   
                    else if ((args.length >= 0) && (args[0].equalsIgnoreCase("info"))) {
                            UserManager.showStats(player);
                            return true;
                    }
                   
                    else if ((args.length >= 0) && (args[0].equalsIgnoreCase("join"))) {
                        if (args.length >= 1) {
                            String job = args[1];
                            UserManager.joinClass(player, job);
                            return true;
                        }
                    }
                   
                    else if ((args.length >= 0) && (args[0].equalsIgnoreCase("leave"))) {
                        UserManager.leaveClass(player);
                        return true;
                    }
                   
                    else{
                        player.sendMessage(ChatColor.GRAY + "Invalid command. Type '/sc' to see the commands list.");
                        return true;
                    }
                }
            }
            return true;
          }
    }
    Here a screenshot in game:

    [​IMG]
     
  7. Offline

    Njol

    Here's your error:
    This means that you do not use the same version of PEX on both servers, try updating both to the latest version.

    edit: I'm a moron... I didn't even read the whole OP -_-
     
  8. Offline

    Ancetras

    I tried to update both my servers with the latest PEX and then re-upload my plugin but it's the same T.T
    Same error at the same line.
     
  9. Offline

    Smex

    Where do you even initizalize "PexHandler" in your class?
    Nowhere, so it can't run your if statement.
     
  10. Offline

    Ancetras

    I tried but it gave me errors, you can see it at the open post o,o
     
  11. Offline

    Smex

    You are trying to execute a method which has an if statement which has an not initialized object,
    sure it can't work. You have to create the object "PexHandler".

    "if (PexHandler.isAdmin(player))"
     
  12. Offline

    Ancetras

    Sorry for my question ... bot how? XD
    T.T some examples?
     
  13. Offline

    Smex

    I don't know what the PexHandler is or from where it comes.
    Usually, if you want to check if a player has permission for something, you
    would use "if(player.hasPermission("xx.xx")"
     
  14. Offline

    Sayshal

    I'm not a programmer and sorry if I'm totally wrong but:
    Code:
    Caused by: java.lang.NoSuchMethodError: ancetras.main.integrations.PexHandler.<init>(Lancetras/main/SagaCraft;)V
        at ancetras.main.SagaCraft.<init>(SagaCraft.java:26)
    Which turns into..
    SagaCraft.java at line 26 doesn't have the right Method, or that method doesn't exist (ancetras.main.integrations.PexHandler)
     
  15. Offline

    Ancetras

    By the way, here is my PexHandler:

    Code:
    public class PexHandler{
        public SagaCraft plugin;
       
        public PexHandler(SagaCraft instance) {
            plugin = instance;
        }
       
        public static boolean isAdmin(Player p){
            if (Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx")) {
                PermissionManager permissions = PermissionsEx.getPermissionManager();
                if (permissions.has(p, "SagaCraft.Admin"))
                    return true;
            }
            return p.isOp();
        }
    }
    Maybe it's wrong?
     
  16. Offline

    Smex

    Just use: if(player.hasPermission("SagaCraft.Admin"),
    why would you use your class?
     
  17. Offline

    Njol

  18. Offline

    Ancetras

    I thought with some other permissions i would not spend my time loocking in all the plugin's classes to change the permissions lines T.T

    Now it works with this method! I think i will use this instead of my class T.T

    Yes, thank you. I wanted to solve the problem of permission before trying to change the event system u.u

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  19. Offline

    dillyg10

    My solution...

    Don't use PEx... :D
     
  20. Offline

    Sir Savary

    Ancetras
    Using built in methods is usually better than making your own (Usually). I suggest you edit the thread title and add [SOLVED] to the beginning, and then edit the main post and add the solution to it.
     
  21. Offline

    Ancetras

    Ok >.< sorry
     
  22. Offline

    Sir Savary

    Ancetras
    No need to apologize! It's just something you should do to help better the forums and make it easier for people who are searching for solutions! You learned something new, no need to say sorry :)
     
Thread Status:
Not open for further replies.

Share This Page