TotalFreedomMod/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java

80 lines
2.4 KiB
Java
Raw Normal View History

2011-10-19 00:37:00 +00:00
package me.StevenLawson.TotalFreedomMod.Commands;
2012-11-13 01:42:30 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
2011-10-19 00:37:00 +00:00
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class Command_expel extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
2011-10-24 02:43:52 +00:00
if (senderIsConsole)
{
sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE);
}
2012-11-13 01:42:30 +00:00
else if (TFM_SuperadminList.isUserSuperadmin(sender))
2011-10-19 00:37:00 +00:00
{
double radius = 50.0;
double strength = 100.0;
if (args.length >= 1)
{
try
{
radius = Math.max(1.0, Math.min(200.0, Double.parseDouble(args[0])));
2011-10-19 00:37:00 +00:00
}
catch (NumberFormatException nfex)
{
}
}
if (args.length >= 2)
{
try
{
strength = Math.max(0.0, Math.min(200.0, Double.parseDouble(args[1])));
2011-10-19 00:37:00 +00:00
}
catch (NumberFormatException nfex)
{
}
}
Location sender_pos = sender_p.getLocation();
2011-10-19 16:04:44 +00:00
for (Player p : sender_pos.getWorld().getPlayers())
2011-10-19 00:37:00 +00:00
{
if (!p.equals(sender_p))
{
Location target_pos = p.getLocation();
2011-10-28 00:37:30 +00:00
boolean in_range = false;
try
{
in_range = target_pos.distanceSquared(sender_pos) < (radius * radius);
2011-10-28 00:37:30 +00:00
}
catch (IllegalArgumentException ex)
{
}
if (in_range)
2011-10-19 00:37:00 +00:00
{
2011-10-19 16:04:44 +00:00
sender.sendMessage("Pushing " + p.getName());
Vector expel_direction = target_pos.subtract(sender_pos).toVector().normalize();
p.setVelocity(expel_direction.multiply(strength));
2011-10-19 00:37:00 +00:00
}
}
}
}
else
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
}
return true;
}
}