mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 09:15:38 +00:00
Rework /expel command.
Move TFM_LandmineData out of main package.
This commit is contained in:
parent
8ba477140b
commit
8cdff6a3c1
@ -1,5 +1,5 @@
|
|||||||
#Fri, 13 Sep 2013 14:48:43 -0400
|
#Fri, 13 Sep 2013 22:11:21 -0400
|
||||||
|
|
||||||
program.VERSION=3.2
|
program.VERSION=3.2
|
||||||
program.BUILDNUM=576
|
program.BUILDNUM=579
|
||||||
program.BUILDDATE=09/13/2013 02\:48 PM
|
program.BUILDDATE=09/13/2013 10\:11 PM
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Fri Sep 13 14:48:43 EDT 2013
|
#Fri Sep 13 22:11:21 EDT 2013
|
||||||
build.number=577
|
build.number=580
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
||||||
@ -12,8 +16,8 @@ public class Command_expel extends TFM_Command
|
|||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
double radius = 15.0;
|
double radius = 20.0;
|
||||||
double strength = 20.0;
|
double strength = 5.0;
|
||||||
|
|
||||||
if (args.length >= 1)
|
if (args.length >= 1)
|
||||||
{
|
{
|
||||||
@ -21,7 +25,7 @@ public class Command_expel extends TFM_Command
|
|||||||
{
|
{
|
||||||
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
|
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException nfex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,33 +36,50 @@ public class Command_expel extends TFM_Command
|
|||||||
{
|
{
|
||||||
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
|
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException nfex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Location sender_pos = sender_p.getLocation();
|
List<String> pushedPlayers = new ArrayList<String>();
|
||||||
for (Player player : sender_pos.getWorld().getPlayers())
|
|
||||||
{
|
|
||||||
if (!player.equals(sender_p))
|
|
||||||
{
|
|
||||||
Location targetPos = player.getLocation();
|
|
||||||
|
|
||||||
boolean in_range = false;
|
final Vector senderPos = sender_p.getLocation().toVector();
|
||||||
|
final List<Player> players = sender_p.getWorld().getPlayers();
|
||||||
|
for (final Player player : players)
|
||||||
|
{
|
||||||
|
if (player.equals(sender_p))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Location targetPos = player.getLocation();
|
||||||
|
final Vector targetPosVec = targetPos.toVector();
|
||||||
|
|
||||||
|
boolean inRange = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
in_range = targetPos.distanceSquared(sender_pos) < (radius * radius);
|
inRange = targetPosVec.distanceSquared(senderPos) < (radius * radius);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex)
|
catch (IllegalArgumentException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_range)
|
if (inRange)
|
||||||
{
|
{
|
||||||
player.setVelocity(targetPos.clone().subtract(sender_pos).toVector().normalize().multiply(strength));
|
player.getWorld().createExplosion(targetPos, 0.0f, false);
|
||||||
playerMsg("Pushing " + player.getName() + ".");
|
player.setFlying(false);
|
||||||
|
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
|
||||||
|
pushedPlayers.add(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pushedPlayers.isEmpty())
|
||||||
|
{
|
||||||
|
playerMsg("No players pushed.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Pushed " + pushedPlayers.size() + " players: " + StringUtils.join(pushedPlayers, ", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_LandmineData;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -48,4 +50,20 @@ public class Command_landmine extends TFM_Command
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TFM_LandmineData
|
||||||
|
{
|
||||||
|
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
|
||||||
|
public Location location;
|
||||||
|
public Player player;
|
||||||
|
public double radius;
|
||||||
|
|
||||||
|
public TFM_LandmineData(Location landmine_pos, Player player, double radius)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.location = landmine_pos;
|
||||||
|
this.player = player;
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import me.StevenLawson.TotalFreedomMod.*;
|
import me.StevenLawson.TotalFreedomMod.*;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -396,10 +397,10 @@ public class TFM_PlayerListener implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
|
Iterator<Command_landmine.TFM_LandmineData> landmines = Command_landmine.TFM_LandmineData.landmines.iterator();
|
||||||
while (landmines.hasNext())
|
while (landmines.hasNext())
|
||||||
{
|
{
|
||||||
TFM_LandmineData landmine = landmines.next();
|
Command_landmine.TFM_LandmineData landmine = landmines.next();
|
||||||
|
|
||||||
Location location = landmine.location;
|
Location location = landmine.location;
|
||||||
if (location.getBlock().getType() != Material.TNT)
|
if (location.getBlock().getType() != Material.TNT)
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TFM_LandmineData
|
|
||||||
{
|
|
||||||
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
|
|
||||||
public Location location;
|
|
||||||
public Player player;
|
|
||||||
public double radius;
|
|
||||||
|
|
||||||
public TFM_LandmineData(Location landmine_pos, Player player, double radius)
|
|
||||||
{
|
|
||||||
this.location = landmine_pos;
|
|
||||||
this.player = player;
|
|
||||||
this.radius = radius;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user