Solved Error on PlayerDeathEvent

Discussion in 'Plugin Development' started by stimoze, Dec 5, 2017.

Thread Status:
Not open for further replies.
  1. Hi! I'm currently working on a bounty system what gives money to a player who kills another player, but takes from the killed player.

    I'm not sure where the problem comes from, but here are the class files & error message.
    The default (config.yml) config file doesn't even create itself.

    Main class:
    Code:
    public class Main extends JavaPlugin{
        public FileConfiguration lgConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "Lifeguard.yml"));
        public FileConfiguration btConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "Bounty.yml"));
        @Override
        public void onEnable(){
            setupEconomy();
            PluginDescriptionFile pdf = super.getDescription();
            getServer().getPluginManager().registerEvents(new BountyListener(), this);
            System.out.println("[" + pdf.getName()+ "]" + " elindult. | Verzio: " + pdf.getVersion() + " | Fejleszto: " + pdf.getAuthors());
        }
        @Override
        public void onDisable(){
            PluginDescriptionFile pdf = super.getDescription();
            System.out.println("[" + pdf.getName()+ "]" + " leallt. | Verzio: " + pdf.getVersion() + " | Fejleszto: " + pdf.getAuthors());
        }
     
        public static Economy economy = null;
        private boolean setupEconomy()
        {
            RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
            if (economyProvider != null) {
                economy = economyProvider.getProvider();
            }
    
            return (economy != null);
        }
    }
    BountyListener (class containing event listener)
    Code:
    public class BountyListener implements Listener {
        @EventHandler
        public void onPlayerKill(PlayerDeathEvent e){
            if (e.getEntity().getKiller() != e.getEntity()){
                if (e.getEntity() != null){
                    Player victim = e.getEntity();
                    Player killer = e.getEntity().getKiller();
                    BountyConfig.StrVictim = victim.getName();
                    BountyConfig.StrKiller = killer.getName();
                    Main.economy.withdrawPlayer(victim, BountyConfig.getKillreward());
                    Main.economy.depositPlayer(killer, BountyConfig.getKillreward());
                    victim.sendMessage(BountyConfig.getVictimText());
                    killer.sendMessage(BountyConfig.getKillerText());
                }
            }
        }
    }
    BountyConfig (i made an unique config file just for the bounty settings, because my plugin doesn't stand only from bounty system)
    Code:
    public class BountyConfig{
        static Main m = new Main();
        static String StrVictim = null;
        static String StrKiller = null;
     
        public static String conv(String msg){
            return ChatColor.translateAlternateColorCodes('&', msg);
        }
     
        public static int getKillreward(){
            return m.btConfig.getInt("killReward");
        }
     
        public static String getVictimText(){
            String msg = m.btConfig.getString(conv("victim"));
            msg.replaceAll("%money%", Integer.toString(getKillreward()));
            msg.replaceAll("%victim%", StrVictim);
            return msg;
        }
     
        public static String getKillerText(){
            String msg = m.btConfig.getString(conv("killer"));
            msg.replaceAll("%money%", Integer.toString(getKillreward()));
            msg.replaceAll("%killer%", StrVictim);
            return msg;
        }
    }
    
    Lastly the error
    Code:
    [18:14:08] [Server thread/ERROR]: Could not pass event PlayerDeathEvent to PvPsystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:365) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.EntityPlayer.die(EntityPlayer.java:402) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.EntityLiving.damageEntity(EntityLiving.java:801) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.EntityHuman.damageEntity(EntityHuman.java:794) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.EntityPlayer.damageEntity(EntityPlayer.java:481) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.EntityHuman.attack(EntityHuman.java:995) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.EntityPlayer.attack(EntityPlayer.java:1048) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1262) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.a(SourceFile:52) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.a(SourceFile:11) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-e91aed8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:676) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:632) [craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:540) [craftbukkit.jar:git-Bukkit-e91aed8]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.ExceptionInInitializerError
        at com.stimonz.pvpsystem.Bounty.BountyListener.onPlayerKill(BountyListener.java:18) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        ... 22 more
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at com.stimonz.pvpsystem.Main.<init>(Main.java:15) ~[?:?]
        at com.stimonz.pvpsystem.Bounty.BountyConfig.<clinit>(BountyConfig.java:8) ~[?:?]
        at com.stimonz.pvpsystem.Bounty.BountyListener.onPlayerKill(BountyListener.java:18) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        ... 22 more
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at com.stimonz.pvpsystem.Main.<init>(Main.java:15) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_121]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_121]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_121]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_121]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_121]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:288) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.<init>(CraftServer.java:250) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.PlayerList.<init>(PlayerList.java:69) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.DedicatedPlayerList.<init>(SourceFile:14) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:179) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:507) ~[craftbukkit.jar:git-Bukkit-e91aed8]
        ... 1 more
    Any help would be appreciated! Good day!
     
    Last edited: Dec 5, 2017
  2. You didn't provide the error message... and the error, if you read it closely and look for where your code is included, will tell you exactly what the error is and where it occurred in your code.
     
  3. Yes, I know, but i updated the post. So it's there now.
     
  4. Offline

    MightyOne

    Seems like this already anyther plugin on your server with the exact same folder path for the main. So bukkit throws an exception because idk it does not want init a class 2 times.

    Try to make you package path unique. Not something like main.Main.java
     
  5. Side Mistakes (open)


    Code:
    if (e.getEntity().getKiller() != e.getEntity()){
    Here you are checking if the killed entity was killed by itself.


    There is either one of two problems here that is causing the error:
    1. You have two of the same plugin in your plugins folder
    2. Your package name is the same as in another plugin. Try doing (dev prefix).(plugin name, lowercase).(plugin name , first letter capitalized)Plugin.

    Example, for my plugins (do not use this prefix):
    Code:
    com.october.invitation.Invitation.java
     
  6. Anyways, thanks for helping, I got my problem fixed! The problem was with calling datas from other classes, and wrong craftbukkit file. I fully redesigned my classes, now it's working fine.
     
Thread Status:
Not open for further replies.

Share This Page