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

51 lines
1.7 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2012-12-08 00:37:27 +00:00
import java.util.SplittableRandom;
import me.totalfreedom.totalfreedommod.rank.Rank;
2012-12-08 00:37:27 +00:00
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 = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Makes random sounds.", usage = "/<command>")
public class Command_deafen extends FreedomCommand
2012-12-08 00:37:27 +00:00
{
2012-12-08 00:37:27 +00:00
public static final double STEPS = 10.0;
private static final SplittableRandom random = new SplittableRandom();
private static Location randomOffset(Location a)
{
return a.clone().add(randomDoubleRange() * 5.0, randomDoubleRange() * 5.0, randomDoubleRange() * 5.0);
}
private static Double randomDoubleRange()
{
return -1.0 + (random.nextDouble() * ((1.0 - -1.0) + 1.0));
}
2012-12-08 00:37:27 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
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);
2012-12-08 00:37:27 +00:00
new BukkitRunnable()
2012-12-08 00:37:27 +00:00
{
@Override
public void run()
{
playerSender.playSound(randomOffset(playerSender.getLocation()), 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;
}
}