[SOLVED] Cannot Apply Potion Effect To A Player

Discussion in 'Plugin Development' started by Tooner101, Aug 16, 2012.

  1. Offline

    Tooner101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I am trying to apply a potion effect to a player before I teleport them and it is not working with any type of potion effect. Any help would be great. Thanks in advance. Here is my code.

    Code:
    @EventHandler
    public void respawn(PlayerRespawnEvent event){
               final Player player = event.getPlayer();
               player.sendMessage(ChatColor.RED+"Hades has summoned you to the underworld!");
               player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1000, 1));
               World nether = Bukkit.getWorld(ExtendedDeath.nether);
               final Location loc = nether.getSpawnLocation();
               plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                       publicvoid run() { 
                              player.teleport(loc);
                       }
              }, (long)(20*5)); //5 seconds
    }
    
    The player just never gets a potion effect applied to them and I'm not sure why... I have applied potion effects to players in my other plugins and this just does not seem to work.
  2. Offline

    frozenpoptartmc

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    if you want to write your own plugin for this, i wouldn't be much help
    but currently there's a plugin that applies currently existing and hidden potion effects to players via command
  3. Online

    Jogy34

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    2 things
    First did you make sure that you registered the event listener?
    Second Bukkit fires events 1 tick before they actually happen so what you might actually be doing is adding the potion effect the tick before the player respawns. Try scheduling a delayed event for 1 tick around everything
  4. Offline

    Tooner101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    okay I will try that also. Thanks
  5. Offline

    CubixCoders

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    When you change worlds it removes potion effects.. Just a headsup
    Tooner101 likes this.
  6. Offline

    CubixCoders

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

    Tooner101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yep I just needed to delay the task of applying the potion. Thanks
  8. Offline

    CubixCoders

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

Share This Page