Kick player on death...?

Discussion in 'Plugin Development' started by TheSmallBones, Jul 1, 2012.

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

    TheSmallBones

    Here is the code to my listener...
    Code:
    package com.Kyle.TheWalls;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    public class MyListener implements Listener {
     
        @EventHandler
        public void OnPlayerJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            player.teleport(player.getWorld().getSpawnLocation());
            Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "say Player teleported to spawn on connect, sorry if he/she was in a game!");
            player.sendMessage("You have been teleported to spawn. Sorry if you were in a game.");
           
        }
        @EventHandler
        public void OnPlayerDeath(PlayerDeathEvent event){
            Player player = event.getPlayer();
            player.KickPlayer();
           
           
           
        }
    }
     
  2. Here's code of an awesome derpy class:
    Code:
    public class Herp extends Derp {
        public void meow() {
             Derp.foobar("NYAAAAN!");
        }
    }
    Seriously, though ... what is your problem? Randomly posting code does not allow us to help you. As far as we know, you don't even have a problem - at least you didn't say so. And not to mention what that problem exactly is ...

    (Hint: your reply should NOT look like "it doesn't work!")
     
    justcool393 likes this.
  3. Offline

    chaseoes

    Use the PlayerRespawnEvent and kick them one tick after.
     
  4. Offline

    TheSmallBones

    player.KickPlayer(); doesn't work...
     
  5. Offline

    chaseoes

    Code:
    player.kickPlayer("Kick Message");
     
  6. Offline

    EnvisionRed

    Probably because it takes a String as a parameter.

    If you don't want to kick with a message, try just:
    Code:
    player.kickPlayer("");
    but seeing as you're kicking people on death, maybe something like:
    Code:
    player.kickPlayer("Kicked for dying");
     
  7. Offline

    TheSmallBones

    How do I make it 1 tick after?

    PS: The reason why I NEED it to be at least 1 tick is because you get into an infinite loop and the player can't get back in...
     
  8. Offline

    bitWolfy

    I would assume...
    Code:
    myPlugin.getServer().getScheduler().scheduleAsyncDelayedTask(myPlugin, new Runnable() {
     
      public void run() {
          // do stuff
      }
    }, 1L);
    Got this from Scheduler Tutorial.
     
  9. Offline

    TheSmallBones

    I have this now and Eclipse gives me red lines...
    Code:
    @EventHandler
        public void OnPlayerRespawn(PlayerRespawnEvent event){
            Player player = event.getPlayer();
           
            Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "say Player kicked from game for dying.");
           
           
           
            this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
                  public void run() {
                      Player player = event.getPlayer();
                      player.kickPlayer("Kicked for dying. GG!");
                  }
                }, 1L);
           
           
           
           
        }
    }
     
  10. Offline

    chaseoes

    ..and what do the red lines say when you hover over them?
     
  11. Offline

    bitWolfy

    Of course it does, because you are calling it from a different class, I would presume.
    Replace this with Bukkit, that should work just fine.

    EDIT: The first this. The second this should be replaced with your plugin reference.
     
  12. Offline

    TheSmallBones

    I replaced the first one with Bukkit. What do I do for the second one? The name of my plugin, or what?
     
  13. Offline

    bitWolfy

    Tell me where you have the listener. If it is in a separate class, then it should be the plugin object that you should have passed in the constructor. If it's in the main plugin class... not quite sure here, I'll check.

    But really, tell us what do the red lines say when you hover over them?
     
  14. Offline

    TheSmallBones

    Well right now the second one says Bukkit since I have nothing else to say in there lol. It says Bukkit cannot be resolved. I have this Listener in a separate class called MyListener. My main class is called TheWalls.
     
  15. Offline

    EnvisionRed

    Do you have a constructor so referencing plugin doesn't throw a nullpointerexception?
     
  16. Offline

    TheSmallBones

    What is a constructor? And no it doesn't throw one.

    Anyone?

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

    NerdsWBNerds

    Create an ArrayList<String> and when a player dies if the list doesn't contain his name, add his name to it, then on respawn if the list contains his name kick him.
     
  18. Offline

    SnRolls

    If you dont know whats constructor... then i advice you to learn the basics of java first then come back.
    (Sorry for being rude)
     
    ryguybuddy and Bone008 like this.
  19. Offline

    MrTheNewGuy

    use this event:

    Code:
    @EventHandler
        public void onEntityDeath(EntityDeathEvent event) {
            if (event instanceof PlayerDeathEvent) {
                Player player = (Player) event.getEntity();
                player.kickPlayer("message");
            }
        }
     
  20. Offline

    Deathmarine

    You don't even have to go that far anymore.
    Code:
    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event){
    event.getPlayer().kickPlayer("Message");
    }
    
     
  21. Offline

    MrTheNewGuy

    k thanks
     
  22. I tried this just to satisfy my curiosity and I needed to use this.
    Code:
    @EventHandler(priority=EventPriority.MONITOR)
        public void onPlayerDeath(PlayerDeathEvent event){
        event.getEntity().getPlayer().kickPlayer("Message");
        }
     
  23. Offline

    Deathmarine

    Lol... didn't have eclipse open so I didn't check it. Oh well I was close.

    :)
     
    Matthewenderle likes this.
  24. Of topic but are you actually a US marine? If so I appreciate your service.
     
Thread Status:
Not open for further replies.

Share This Page