mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-18 05:16:12 +00:00
0ae835aa04
sourcetype fixes; making sure in game commands work only in game
51 lines
1.8 KiB
Java
51 lines
1.8 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import java.util.Random;
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
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;
|
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
|
@CommandParameters(description = "Makes random sounds.", usage = "/<command>")
|
|
public class Command_deafen extends FreedomCommand
|
|
{
|
|
|
|
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)
|
|
{
|
|
{
|
|
for (double percent = 0.0; percent <= 1.0; percent += (1.0 / STEPS))
|
|
{
|
|
final float pitch = (float)(percent * 2.0);
|
|
|
|
new BukkitRunnable()
|
|
{
|
|
@Override
|
|
public void run()
|
|
{
|
|
playerSender.playSound(randomOffset(playerSender.getLocation(), 5.0), Sound.values()[random.nextInt(Sound.values().length)], 100.0f, pitch);
|
|
}
|
|
}.runTaskLater(plugin, Math.round(20.0 * percent * 2.0));
|
|
}
|
|
}
|
|
|
|
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));
|
|
}
|
|
} |