How can I add a PotionEffect (SLOW)

Discussion in 'Plugin Development' started by Licio123, Mar 25, 2014.

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

    Licio123

    Code:java
    1. package bonemanager;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.EventPriority;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.entity.EntityDamageEvent;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. import org.bukkit.potion.PotionEffect;
    13. import org.bukkit.potion.PotionEffectType;
    14.  
    15. public class BONEMANAGER extends JavaPlugin implements Listener{
    16.  
    17. @Override
    18. public void onEnable() {
    19. this.getServer().getPluginManager().registerEvents(this, this);
    20. }
    21. @EventHandler(priority=EventPriority.NORMAL)
    22. public void EntityDamageEvent(EntityDamageEvent event) {
    23. if (event.getEntity() instanceof Player) {
    24. Player player = (Player) event.getEntity();
    25. if (event.getCause() == EntityDamageEvent.DamageCause.FALL)
    26. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 789, 2));
    27. }
    28. }
    29. @EventHandler(priority=EventPriority.NORMAL)
    30. public void PlayerInteractEvent(PlayerInteractEvent event) {
    31. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    32. Player player = (Player)event.getPlayer();
    33. if(event.getItem() != null && event.getItem().getType() == Material.BONE) {
    34. if(player.hasPotionEffect(PotionEffectType.SLOW))
    35. player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
    36. player.removePotionEffect(PotionEffectType.SLOW);
    37. }
    38. }
    39. }
    40. }
    41.  
    42.  
    43.  

    This code set only 1 sec to slowness
     
  2. Offline

    MrInspector

    Wrong section :p

    This is where you request plugins, not plugin development help, you're looking for the 'Plugin Development' section!
     
  3. Wrong section, buy why not just have the plugin execute a console command instead? /effect playername SLOW time multiplier

    Licio123
     
  4. Offline

    Licio123

    Its for a WARZ server then when player get FALL he breack his legs
     
  5. Offline

    webbhead

    Licio123

    e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.<PotionEffect>, <time (in ticks 1 second = 20 ticks)>, <Power>));

    Example:
    e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 1));

    This will give them Slowness 2 for 5 seconds.
     
  6. So why not have it when they fall.. console command executes...
     
  7. Offline

    xa112

    Da_Pepsi_Monster Bukkits potions are less likely to change than commands and not all servers will necessarily have that command enabled in the default configuration.
     
  8. Offline

    Jade

    Moved to correct section.
     
Thread Status:
Not open for further replies.

Share This Page