TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java

53 lines
1.9 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2012-12-08 00:37:27 +00:00
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
2012-12-08 00:37:27 +00:00
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
2012-12-08 00:37:27 +00:00
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Make some noise.", usage = "/<command>")
public class Command_deafen extends FreedomCommand
2012-12-08 00:37:27 +00:00
{
2012-12-08 00:37:27 +00:00
private static final Random random = new Random();
public static final double STEPS = 10.0;
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
2012-12-08 00:37:27 +00:00
{
2013-08-14 14:01:42 +00:00
for (final Player player : server.getOnlinePlayers())
2012-12-08 00:37:27 +00:00
{
for (double percent = 0.0; percent <= 1.0; percent += (1.0 / STEPS))
{
final float pitch = (float) (percent * 2.0);
new BukkitRunnable()
2012-12-08 00:37:27 +00:00
{
@Override
public void run()
{
2013-08-14 14:01:42 +00:00
player.playSound(randomOffset(player.getLocation(), 5.0), Sound.values()[random.nextInt(Sound.values().length)], 100.0f, pitch);
2012-12-08 00:37:27 +00:00
}
}.runTaskLater(plugin, Math.round(20.0 * percent * 2.0));
2012-12-08 00:37:27 +00:00
}
}
return true;
}
private static Location randomOffset(Location a, double magnitude)
{
return a.clone().add(randomDoubleRange(-1.0, 1.0) * magnitude, randomDoubleRange(-1.0, 1.0) * magnitude, randomDoubleRange(-1.0, 1.0) * magnitude);
}
private static Double randomDoubleRange(double min, double max)
{
return min + (random.nextDouble() * ((max - min) + 1.0));
}
}