package net.mindoverflow.kissplugin.commands; import net.mindoverflow.kissplugin.Main; import org.bukkit.Sound; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; import java.util.Random; public class SpookCommand implements CommandExecutor { private Main plugin; public SpookCommand(Main plugin) { this.plugin = plugin; } ArrayListspookSounds = new ArrayList(){{ add(Sound.AMBIENT_CAVE); add(Sound.ENTITY_GENERIC_EXPLODE); add(Sound.ENTITY_DRAGON_FIREBALL_EXPLODE); }}; ArrayListspookedPlayers = new ArrayList<>(); @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { if(commandSender instanceof Player) { Player sender = (Player)commandSender; for(Entity e : sender.getNearbyEntities(6, 6, 6)) { if(e instanceof Player) { Player nearPlayer = (Player)e; String name = nearPlayer.getName(); if(spookedPlayers.contains(name)) { sender.sendMessage("§7You already spooked §c" + name + "§7 recently!"); return true; } spookedPlayers.add(name); plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, ()-> { spookedPlayers.remove(name); }, 1200); nearPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 1, false, false, false)); nearPlayer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 40, 1, false, false, false)); nearPlayer.playSound(nearPlayer.getLocation(), getRandomSound(spookSounds), 1, 1); nearPlayer.sendTitle("§4Boo!", "§cYou got spooked by " + sender.getName() + "!", 0, 60, 10); nearPlayer.getWorld().strikeLightningEffect(nearPlayer.getLocation()); return true; } } commandSender.sendMessage("§7there is no one to spook around you! =("); } return true; } private Sound getRandomSound(ArrayList list) { Random random = new Random(); return list.get(random.nextInt(list.size())); } }