Added utility methods to check for players within a sight pyramid
This commit is contained in:
parent
9142227dd4
commit
4a25265c7c
@ -6,6 +6,7 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -92,6 +93,10 @@ public class UtilAlg
|
||||
if (y <= 0) pitch += 90;
|
||||
else pitch -= 90;
|
||||
|
||||
//Fix for two vectors at same Y giving 180
|
||||
if (pitch == 180)
|
||||
pitch = 0;
|
||||
|
||||
return (float) pitch;
|
||||
}
|
||||
|
||||
@ -244,4 +249,15 @@ public class UtilAlg
|
||||
|
||||
return bestLoc;
|
||||
}
|
||||
|
||||
public static boolean isInPyramid(Vector a, Vector b, double angleLimit)
|
||||
{
|
||||
return (Math.abs(GetPitch(a) - GetPitch(b)) < angleLimit) && (Math.abs(GetYaw(a) - GetYaw(b)) < angleLimit);
|
||||
}
|
||||
|
||||
public static boolean isTargetInPlayerPyramid(Player player, Player target, double angleLimit)
|
||||
{
|
||||
return isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getEyeLocation()), angleLimit) ||
|
||||
isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getLocation()), angleLimit);
|
||||
}
|
||||
}
|
||||
|
@ -514,6 +514,26 @@ public class UtilPlayer
|
||||
return players;
|
||||
}
|
||||
|
||||
public static HashMap<Player, Double> getPlayersInPyramid(Player player, double angleLimit, double distance)
|
||||
{
|
||||
HashMap<Player, Double> players = new HashMap<Player, Double>();
|
||||
|
||||
for (Player cur : player.getWorld().getPlayers())
|
||||
{
|
||||
if (UtilPlayer.isSpectator(cur))
|
||||
continue;
|
||||
|
||||
//Get lower offset (eye to eye, eye to feet)
|
||||
double offset = Math.min(UtilMath.offset(player.getEyeLocation(), cur.getEyeLocation()),
|
||||
UtilMath.offset(player.getEyeLocation(), cur.getLocation()));
|
||||
|
||||
if (offset < distance && UtilAlg.isTargetInPlayerPyramid(player, cur, angleLimit))
|
||||
players.put(cur, 1 - (offset / distance));
|
||||
}
|
||||
|
||||
return players;
|
||||
}
|
||||
|
||||
public static void health(Player player, double mod)
|
||||
{
|
||||
if (player.isDead())
|
||||
|
@ -39,9 +39,11 @@ import mineplex.core.chat.Chat;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilGear;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.cosmetic.CosmeticManager;
|
||||
import mineplex.core.creature.Creature;
|
||||
import mineplex.core.disguise.DisguiseManager;
|
||||
@ -66,6 +68,8 @@ import mineplex.core.status.ServerStatusManager;
|
||||
import mineplex.core.task.TaskManager;
|
||||
import mineplex.core.teleport.Teleport;
|
||||
import mineplex.core.timing.TimingManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.minecraft.game.classcombat.Class.ClassManager;
|
||||
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
|
||||
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
|
||||
@ -127,8 +131,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
private Fire _fire;
|
||||
private ProjectileManager _projectileManager;
|
||||
|
||||
|
||||
|
||||
private Portal _portal;
|
||||
private ArcadeShop _arcadeShop;
|
||||
|
||||
@ -1197,7 +1199,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
|
||||
//Set Spec State
|
||||
player.setVelocity(new Vector(0,1,0));
|
||||
// player.setGameMode(GameMode.CREATIVE); //
|
||||
player.setAllowFlight(true);
|
||||
player.setFlying(true);
|
||||
player.setFlySpeed(0.1f);
|
||||
|
@ -1500,38 +1500,6 @@ public class SurvivalGames extends SoloGame
|
||||
|
||||
Collection<Block> blocks = UtilBlock.getInRadius(event.getEntity().getLocation(), 2.4).keySet();
|
||||
|
||||
|
||||
// Iterator<Block> blockIter = blocks.iterator();
|
||||
// while (blockIter.hasNext())
|
||||
// {
|
||||
// Block block = blockIter.next();
|
||||
//
|
||||
// block.setType(Material.NETHERRACK);
|
||||
//
|
||||
// //Dont destroy above hollow ground
|
||||
//
|
||||
// if (!UtilBlock.solid(block.getRelative(BlockFace.DOWN)))
|
||||
// {
|
||||
// blockIter.remove();
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// //Unstable, feel free to destroy!
|
||||
// if (!isStableBlock(block))
|
||||
// continue;
|
||||
//
|
||||
// //Check for block stability via neighbours
|
||||
// int stableSides = 0;
|
||||
// if (isStableBlock(block.getRelative(BlockFace.NORTH))) stableSides++;
|
||||
// if (isStableBlock(bl ck.getRelative(BlockFace.EAST))) stableSides++;
|
||||
// if (isStableBlock(block.getRelative(BlockFace.SOUTH))) stableSides++;
|
||||
// if (isStableBlock(block.getRelative(BlockFace.WEST))) stableSides++;
|
||||
//
|
||||
// //Stable!
|
||||
// if (stableSides >= 3)
|
||||
// blockIter.remove();
|
||||
// }
|
||||
|
||||
Manager.GetExplosion().BlockExplosion(blocks, event.getEntity().getLocation(), false);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user