2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.commands;
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
2013-09-14 02:13:07 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2014-11-29 19:16:00 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2011-10-19 00:37:00 +00:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2013-09-14 02:13:07 +00:00
|
|
|
import org.bukkit.util.Vector;
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_expel extends FreedomCommand
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2013-09-14 02:13:07 +00:00
|
|
|
double radius = 20.0;
|
|
|
|
double strength = 5.0;
|
2012-11-24 01:22:52 +00:00
|
|
|
|
|
|
|
if (args.length >= 1)
|
2011-10-24 02:43:52 +00:00
|
|
|
{
|
2012-11-24 01:22:52 +00:00
|
|
|
try
|
|
|
|
{
|
2012-12-01 19:11:10 +00:00
|
|
|
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
|
2012-11-24 01:22:52 +00:00
|
|
|
}
|
2013-09-14 02:13:07 +00:00
|
|
|
catch (NumberFormatException ex)
|
2012-11-24 01:22:52 +00:00
|
|
|
{
|
|
|
|
}
|
2011-10-24 02:43:52 +00:00
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2012-11-24 01:22:52 +00:00
|
|
|
if (args.length >= 2)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-12-01 19:11:10 +00:00
|
|
|
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
|
2012-11-24 01:22:52 +00:00
|
|
|
}
|
2013-09-14 02:13:07 +00:00
|
|
|
catch (NumberFormatException ex)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
|
|
|
}
|
2012-11-24 01:22:52 +00:00
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2013-09-14 02:13:07 +00:00
|
|
|
List<String> pushedPlayers = new ArrayList<String>();
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
final Vector senderPos = playerSender.getLocation().toVector();
|
|
|
|
final List<Player> players = playerSender.getWorld().getPlayers();
|
2013-09-14 02:13:07 +00:00
|
|
|
for (final Player player : players)
|
2012-11-24 01:22:52 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
if (player.equals(playerSender))
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2013-09-14 02:13:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2013-09-14 02:13:07 +00:00
|
|
|
final Location targetPos = player.getLocation();
|
|
|
|
final Vector targetPosVec = targetPos.toVector();
|
|
|
|
|
|
|
|
boolean inRange = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
inRange = targetPosVec.distanceSquared(senderPos) < (radius * radius);
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException ex)
|
|
|
|
{
|
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2013-09-14 02:13:07 +00:00
|
|
|
if (inRange)
|
|
|
|
{
|
|
|
|
player.getWorld().createExplosion(targetPos, 0.0f, false);
|
2015-10-19 17:43:46 +00:00
|
|
|
FUtil.setFlying(player, false);
|
2013-09-14 02:13:07 +00:00
|
|
|
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
|
|
|
|
pushedPlayers.add(player.getName());
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-14 02:13:07 +00:00
|
|
|
if (pushedPlayers.isEmpty())
|
|
|
|
{
|
|
|
|
playerMsg("No players pushed.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerMsg("Pushed " + pushedPlayers.size() + " players: " + StringUtils.join(pushedPlayers, ", "));
|
|
|
|
}
|
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|