Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.lisenochek.drugs;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import java.util.Random;
- public class UseDrugsListener implements Listener {
- @EventHandler
- public void useDrugs(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
- if (!p.getInventory().getItemInMainHand().hasItemMeta()) return;
- if (p.getInventory().getItemInMainHand().getItemMeta().getDisplayName() == null) return;
- if (p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase(DrugList.cocaine.getItemMeta().getDisplayName())) {
- getDrugEffect(p);
- }
- }
- public void getDrugEffect(Player p) {
- Random r = new Random();
- if (p.getItemInHand().getAmount() == 1) {
- p.getInventory().setItemInMainHand(null);
- } else {
- p.getInventory().getItemInMainHand().setAmount(p.getInventory().getItemInMainHand().getAmount() - 1);
- }
- if (r.nextBoolean()) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 150, 1));
- p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 150, 1));
- p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 150, 1));
- p.sendMessage(C.getPrefix() + C.c("&aЧувак, ты такой смешной.... *безудержанный смех*."));
- } else {
- p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 150, 1));
- p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 150, 1));
- p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 150, 1));
- p.sendMessage(C.getPrefix() + C.c("&aОоо... Чего-то мне нехорошо..."));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement