2011-10-19 00:37:00 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
|
|
|
2012-12-06 01:54:38 +00:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
2011-10-19 00:37:00 +00:00
|
|
|
import java.util.Random;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
2012-12-06 01:54:38 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Location;
|
2011-10-19 00:37:00 +00:00
|
|
|
import org.bukkit.Material;
|
2012-12-06 01:54:38 +00:00
|
|
|
import org.bukkit.Sound;
|
2011-10-19 00:37:00 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2012-11-24 01:22:52 +00:00
|
|
|
@CommandPermissions(level = ADMIN_LEVEL.SUPER, source = SOURCE_TYPE_ALLOWED.BOTH, ignore_permissions = false)
|
2011-10-19 00:37:00 +00:00
|
|
|
public class Command_cake extends TFM_Command
|
|
|
|
{
|
2012-12-06 01:54:38 +00:00
|
|
|
public static final int DROP_COUNT = 5;
|
|
|
|
public static final double DROP_RADIUS_MAX = 3.0d;
|
|
|
|
public static final double DROP_RADIUS_MIN = 1.0d;
|
|
|
|
public static final double DROP_DURATION = 1.0d; // seconds
|
|
|
|
public static final int BAKE_TIME = 30; // seconds
|
|
|
|
public static Date bake_finished = new Date();
|
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2012-12-06 01:54:38 +00:00
|
|
|
if ((new Date()).before(bake_finished))
|
|
|
|
{
|
|
|
|
TFM_Util.playerMsg(sender, "Still baking cake, please wait...", ChatColor.BLUE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.setTime(new Date());
|
|
|
|
c.add(Calendar.SECOND, BAKE_TIME);
|
|
|
|
bake_finished = c.getTime();
|
|
|
|
|
2012-11-24 01:22:52 +00:00
|
|
|
StringBuilder output = new StringBuilder();
|
2012-12-06 01:54:38 +00:00
|
|
|
final Random random = new Random();
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2012-12-06 01:54:38 +00:00
|
|
|
String words[] = TotalFreedomMod.CAKE_LYRICS.split(" ");
|
|
|
|
for (String word : words)
|
2012-11-24 01:22:52 +00:00
|
|
|
{
|
2012-12-06 01:54:38 +00:00
|
|
|
String color_code = Integer.toHexString(1 + random.nextInt(14));
|
|
|
|
output.append(ChatColor.COLOR_CHAR).append(color_code).append(word).append(" ");
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2012-12-06 01:54:38 +00:00
|
|
|
TFM_Util.bcastMsg(output.toString());
|
|
|
|
|
|
|
|
for (final Player p : server.getOnlinePlayers())
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2012-11-24 01:22:52 +00:00
|
|
|
ItemStack heldItem = new ItemStack(Material.CAKE, 1);
|
|
|
|
p.getInventory().setItem(p.getInventory().firstEmpty(), heldItem);
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2012-12-06 01:54:38 +00:00
|
|
|
for (double theta_p = 0.0; theta_p <= 1.0; theta_p += (1.0d / (double) DROP_COUNT))
|
|
|
|
{
|
|
|
|
final double theta = theta_p * Math.PI * 2.0d;
|
|
|
|
final double radius = random.nextDouble() * (DROP_RADIUS_MAX - DROP_RADIUS_MIN) + DROP_RADIUS_MIN;
|
|
|
|
|
|
|
|
Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
double x = radius * Math.cos(theta);
|
|
|
|
double z = radius * Math.sin(theta);
|
|
|
|
Location drop_pos = p.getLocation().clone().add(x * 3.0d, 3.0d, z * 3.0d);
|
|
|
|
p.getWorld().dropItemNaturally(drop_pos, new ItemStack(Material.CAKE));
|
|
|
|
p.playSound(drop_pos, Sound.BURP, 100.0f, 0.5f + random.nextFloat());
|
|
|
|
}
|
|
|
|
}, Math.round(theta_p * 20.0d * DROP_DURATION));
|
|
|
|
}
|
|
|
|
}
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-12-06 01:54:38 +00:00
|
|
|
}
|