Advertisement
Lisenochek

Untitled

Jan 9th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. package ru.lisenochek.drugs;
  2.  
  3. import org.bukkit.entity.Player;
  4. import org.bukkit.event.EventHandler;
  5. import org.bukkit.event.Listener;
  6. import org.bukkit.event.block.Action;
  7. import org.bukkit.event.player.PlayerInteractEvent;
  8. import org.bukkit.potion.PotionEffect;
  9. import org.bukkit.potion.PotionEffectType;
  10.  
  11. import java.util.Random;
  12.  
  13. public class UseDrugsListener implements Listener {
  14.  
  15. @EventHandler
  16. public void useDrugs(PlayerInteractEvent e) {
  17.  
  18. Player p = e.getPlayer();
  19.  
  20. if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
  21. if (!p.getInventory().getItemInMainHand().hasItemMeta()) return;
  22. if (p.getInventory().getItemInMainHand().getItemMeta().getDisplayName() == null) return;
  23.  
  24. if (p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase(DrugList.cocaine.getItemMeta().getDisplayName())) {
  25. getDrugEffect(p);
  26. }
  27. }
  28.  
  29. public void getDrugEffect(Player p) {
  30.  
  31. Random r = new Random();
  32.  
  33. if (p.getItemInHand().getAmount() == 1) {
  34. p.getInventory().setItemInMainHand(null);
  35. } else {
  36. p.getInventory().getItemInMainHand().setAmount(p.getInventory().getItemInMainHand().getAmount() - 1);
  37. }
  38.  
  39. if (r.nextBoolean()) {
  40. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 150, 1));
  41. p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 150, 1));
  42. p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 150, 1));
  43.  
  44. p.sendMessage(C.getPrefix() + C.c("&aЧувак, ты такой смешной.... *безудержанный смех*."));
  45. } else {
  46. p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 150, 1));
  47. p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 150, 1));
  48. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 150, 1));
  49.  
  50. p.sendMessage(C.getPrefix() + C.c("&aОоо... Чего-то мне нехорошо..."));
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement