PlayerRespawnEvent don't do what I want...

Discussion in 'Plugin Development' started by xxsorpiaxx, Aug 20, 2012.

  1. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hello,
    So, I make a plugins to make battle with my friends (with teams... etc) but I have a problem.

    When a player dead, he need to respawn at him personal team spawn. For that I have use the event :
    "PlayerRespawnEvent".
    Code:
    public void onRespawnEvent(PlayerRespawnEvent e){
            if (blueTeam.contains(e.getPlayer())){
                e.getPlayer().sendMessage("blue") ;
                e.getPlayer().teleport(blueLoc) ;
            }else if (redTeam.contains(e.getPlayer())){
                e.getPlayer().sendMessage("red") ;
                e.getPlayer().teleport(redLoc) ;
            }
        }
    But that doesn't work; the player wasn't teleport to the location... :(

    Do you know why that don't work ? Please, I really need your help...

    PS: Sorry for my bad English, I am French.

    This post has been edited 1 time. It was last edited by xxsorpiaxx Aug 20, 2012.
  2. Offline

    Njol

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Use e.setRespawnLocation(...)
  3. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I have already test that, but again that don't work. I respawn at the normal spawn...
  4. Offline

    Njol

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Do you get the messages at least?
  5. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yes I get the message, it's strange.
  6. Offline

    Njol

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Are you sure that the message is sent by this listener? And are you sure that the team spawns are set (and not set to the worlds spawn)?
  7. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yeah I'm sure.

    Code:
    Location redLoc ;
    Location blueLoc ;
    Code:
    if (args[0].equalsIgnoreCase("/respawn"))    {
                        if (e.getPlayer().isOp() == true){
                            if (args[1].equalsIgnoreCase("red")){
                                e.setCancelled(true) ;
                                redLoc = e.getPlayer().getLocation() ;
                                e.getPlayer().sendMessage(ChatColor.GREEN + "Le point de réappariton de l'équipe " +
                                                              ChatColor.RED + "rouge " + ChatColor.GREEN + "a été mis à jour!") ;
                            }else if (args[1].equalsIgnoreCase("blue")){
                                e.setCancelled(true) ;
                                blueLoc = e.getPlayer().getLocation() ;
                                e.getPlayer().sendMessage(ChatColor.GREEN + "Le point de réappariton de l'équipe " +
                                                          ChatColor.BLUE + "bleu " + ChatColor.GREEN + "a été mis à jour!") ;
                                e.getPlayer().sendMessage(blueLoc.toString()) ;
                            }
                        }
                    }
    The Location are set, yes.
  8. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Please, who can help me ?
  9. Offline

    Njol

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    How does your command look like? For this code to work your command has to be used like this:
    Code:
    /somecommand /respawn blue
    'args' are the arguments after the command, the command itself is not included.
  10. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Why it works then ? :p
  11. Offline

    Njol

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Are you by chance using the PlayerCommandPreprocessEvent? That would explain why it works ;)

    I have no idea why the the teleport doesn't work though...
  12. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    No.

    Me too :D. Please, if someone know why that don't work, can he help me ?
  13. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    So, that is all my code for the moment.

    Code:
    package sorpia68.pluginsTest;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.LightningStrike;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Snowball;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.entity.ProjectileLaunchEvent;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import org.bukkit.event.player.PlayerEggThrowEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
     
     
    public class PlayerCommands implements Listener {
     
        List<Player> blueTeam = new ArrayList<Player>() ;
        List<Player> redTeam = new ArrayList<Player>() ;
        Location redLoc ;
        Location blueLoc ;
        Plugin plugins ;
        Player p ;
     
        public PlayerCommands(pluginsTest pluginsTest) {
                this.plugins = pluginsTest;
        }
     
        @EventHandler (priority = EventPriority.LOWEST)
        public void onEggThrow(PlayerEggThrowEvent e) {
        e.getEgg().getWorld().createExplosion(e.getEgg().getLocation(), 1, true) ; 
        }
     
        @EventHandler (priority = EventPriority.LOWEST)
        public void onProjectileLaunch(ProjectileLaunchEvent e) {
         
            if(e instanceof ProjectileLaunchEvent) {
                Entity entity = e.getEntity();
             
                if(entity instanceof Snowball) {
                e.getEntity().setVelocity(e.getEntity().getVelocity().multiply(2)) ;
                }
            }
        }
     
        @EventHandler (priority = EventPriority.LOWEST)
        public void onDamageByEntity(EntityDamageByEntityEvent e) {
            if(e instanceof EntityDamageByEntityEvent){
                Entity entity = e.getDamager() ;
                if(entity instanceof Snowball){
                    e.setDamage(2) ;
                }else if(entity instanceof Arrow){
                    e.setDamage(0) ;
                    e.getDamager().getWorld().strikeLightning(e.getDamager().getLocation()) ;
                }else if(entity instanceof LightningStrike){
                    e.setDamage(4) ;
                }
            }
        }
     
        @EventHandler (priority = EventPriority.LOWEST)
        public void onCommand(PlayerCommandPreprocessEvent e) {
        String args[] = e.getMessage().split(" ") ;
     
            if (args.length == 1) {
                if (args[0].equalsIgnoreCase("/snow")) {
                    ItemStack items = new ItemStack(Material.SNOW_BALL, 384) ;
                    e.getPlayer().getInventory().addItem(items) ;
                    e.setCancelled(true) ;
                } else if(args[0].equalsIgnoreCase("/food")){
                e.getPlayer().setFoodLevel(20) ;
                e.setCancelled(true) ;
                }
            }
            if (args.length == 2) {
             
                    if (args[0].equalsIgnoreCase("/respawn"))    {
                        if (e.getPlayer().isOp() == true){
                            if (args[1].equalsIgnoreCase("red")){
                                e.setCancelled(true) ;
                                redLoc = e.getPlayer().getLocation() ;
                                e.getPlayer().sendMessage(ChatColor.GREEN + "Le point de réappariton de l'équipe " +
                                                              ChatColor.RED + "rouge " + ChatColor.GREEN + "a été mis à jour!") ;
                            }else if (args[1].equalsIgnoreCase("blue")){
                                e.setCancelled(true) ;
                                blueLoc = e.getPlayer().getLocation() ;
                                e.getPlayer().sendMessage(ChatColor.GREEN + "Le point de réappariton de l'équipe " +
                                                          ChatColor.BLUE + "bleu " + ChatColor.GREEN + "a été mis à jour!") ;
                                e.getPlayer().sendMessage(blueLoc.toString()) ;
                            }
                        }
                    }else if (args[0].equalsIgnoreCase("/join")){
                        if (args[1].equalsIgnoreCase("red")){
                            e.setCancelled(true) ;
                            e.getPlayer().sendMessage(ChatColor.GREEN + "Vous avez rejoint l'équipe " + ChatColor.RED + "rouge.") ;
                            redTeam.add(e.getPlayer()) ;
                         
                        }else if (args[1].equalsIgnoreCase("blue")){
                            e.setCancelled(true) ;
                            e.getPlayer().sendMessage(ChatColor.GREEN + "Vous avez rejoint l'équipe " + ChatColor.BLUE + "bleu.") ;
                            blueTeam.add(e.getPlayer()) ;
                        }
                    }
                }
            }
         
        @EventHandler (priority = EventPriority.LOWEST)
        public void onDeathEvent(PlayerDeathEvent e){
            e.getDrops().clear() ;
            e.setDeathMessage(ChatColor.GOLD + e.getEntity().getKiller().getDisplayName() + ChatColor.AQUA + " a tué de sang froid " + ChatColor.GOLD + e.getEntity().getDisplayName()+ ".") ;
        }
     
        @EventHandler (priority = EventPriority.LOWEST)
        public void onRespawnEvent(PlayerRespawnEvent e){
            if (blueTeam.contains(e.getPlayer())){
                e.getPlayer().sendMessage("blue") ;
                e.setRespawnLocation(blueLoc) ;
            }else if (redTeam.contains(e.getPlayer())){
                e.getPlayer().sendMessage("red") ;
                e.setRespawnLocation(redLoc) ;
            }
        }
     
        @EventHandler (priority = EventPriority.LOWEST)
        public void onPlayerJoin(PlayerJoinEvent e){
            e.setJoinMessage(ChatColor.GOLD + e.getPlayer().getName() + ChatColor.GRAY + " s'est connecté.") ;
        }
     
        @EventHandler (priority = EventPriority.LOWEST)
        public void onPlayerQuit(PlayerQuitEvent e){
            e.setQuitMessage(ChatColor.GOLD + e.getPlayer().getName() + ChatColor.GRAY + " s'est déconnecté.") ;
        }
     
     
    }
    I need you help... please...
  14. Offline

    Njol

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Do you have any other plugins running on the server? Your respawn listened has lowest priority, i.e. most other plugins that change the respawn location will override yours.
    xxsorpiaxx likes this.
  15. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yes I have just "Essentials" and "World Edit", so I think "Essentials" is the problem. I test that tomorrow because I'am tired, sorry. :)

    Sorpia.
  16. Offline

    xxsorpiaxx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yeeaaah, that work ! Thank's !
    I have just make my listened priority as Hightest !

    Thank you,
    Sorpia.

Share This Page