Skip to content

Commit

Permalink
Merge pull request #1856 from mcmonkey4eva/master
Browse files Browse the repository at this point in the history
Pull Request for 1.13.2 stronk times
  • Loading branch information
mcmonkey4eva committed Dec 7, 2018
2 parents 6f10788 + 2014256 commit 946e120
Show file tree
Hide file tree
Showing 49 changed files with 1,167 additions and 792 deletions.
Expand Up @@ -113,7 +113,13 @@ class MapTraceResult {
*/
Location eyeTrace(LivingEntity from, double range);

Location faceLocation(Location from, Location at);
default Location faceLocation(Location from, Location at) {
Vector direction = from.toVector().subtract(at.toVector()).normalize();
Location newLocation = from.clone();
newLocation.setYaw(180 - (float) Math.toDegrees(Math.atan2(direction.getX(), direction.getZ())));
newLocation.setPitch(90 - (float) Math.toDegrees(Math.acos(direction.getY())));
return newLocation;
}

/**
* Changes an entity's yaw and pitch to make it face a location.
Expand All @@ -131,6 +137,17 @@ class MapTraceResult {
*/
void faceEntity(Entity entity, Entity target);

default boolean isFacingLocation(Location from, Location at, float yawLimitDegrees, float pitchLimitDegrees) {
Vector direction = from.toVector().subtract(at.toVector()).normalize();
float pitch = 90 - (float) Math.toDegrees(Math.acos(direction.getY()));
if (from.getPitch() > pitch + pitchLimitDegrees
|| from.getPitch() < pitch - pitchLimitDegrees) {
return false;
}

return isFacingLocation(from, at, yawLimitDegrees);
}

/**
* Checks if a Location's yaw is facing another Location.
* <p/>
Expand All @@ -146,7 +163,14 @@ class MapTraceResult {
* we check if it is facing.
* @return Returns a boolean.
*/
boolean isFacingLocation(Location from, Location at, float degreeLimit);
default boolean isFacingLocation(Location from, Location at, float degreeLimit) {
double currentYaw = normalizeYaw(from.getYaw());
double requiredYaw = normalizeYaw(getYaw(at.toVector().subtract(
from.toVector()).normalize()));
return (Math.abs(requiredYaw - currentYaw) < degreeLimit ||
Math.abs(requiredYaw + 360 - currentYaw) < degreeLimit ||
Math.abs(currentYaw + 360 - requiredYaw) < degreeLimit);
}

/**
* Checks if an Entity is facing a Location.
Expand All @@ -158,7 +182,9 @@ class MapTraceResult {
* is facing.
* @return Returns a boolean.
*/
boolean isFacingLocation(Entity from, Location at, float degreeLimit);
default boolean isFacingLocation(Entity from, Location at, float degreeLimit) {
return isFacingLocation(from.getLocation(), at, degreeLimit);
}

/**
* Checks if an Entity is facing another Entity.
Expand All @@ -170,7 +196,9 @@ class MapTraceResult {
* is facing.
* @return Returns a boolean.
*/
boolean isFacingEntity(Entity from, Entity at, float degreeLimit);
default boolean isFacingEntity(Entity from, Entity at, float degreeLimit) {
return isFacingLocation(from.getLocation(), at.getLocation(), degreeLimit);
}

/**
* Normalizes Mincraft's yaws (which can be negative or can exceed 360)
Expand All @@ -179,7 +207,13 @@ class MapTraceResult {
* @param yaw The original yaw.
* @return The normalized yaw.
*/
float normalizeYaw(float yaw);
default float normalizeYaw(float yaw) {
yaw = yaw % 360;
if (yaw < 0) {
yaw += 360.0;
}
return yaw;
}

/**
* Converts a vector to a yaw.
Expand All @@ -189,15 +223,67 @@ class MapTraceResult {
* @param vector The vector you want to get a yaw from.
* @return The yaw.
*/
float getYaw(Vector vector);
default float getYaw(Vector vector) {
double dx = vector.getX();
double dz = vector.getZ();
double yaw = 0;
// Set yaw
if (dx != 0) {
// Set yaw start value based on dx
if (dx < 0) {
yaw = 1.5 * Math.PI;
}
else {
yaw = 0.5 * Math.PI;
}
yaw -= Math.atan(dz / dx);
}
else if (dz < 0) {
yaw = Math.PI;
}
return (float) (-yaw * 180 / Math.PI);
}

/**
* Converts a yaw to a cardinal direction name.
*
* @param yaw The yaw you want to get a cardinal direction from.
* @return The name of the cardinal direction as a String.
*/
String getCardinal(float yaw);
default String getCardinal(float yaw) {
yaw = normalizeYaw(yaw);
// Compare yaws, return closest direction.
if (0 <= yaw && yaw < 22.5) {
return "south";
}
else if (22.5 <= yaw && yaw < 67.5) {
return "southwest";
}
else if (67.5 <= yaw && yaw < 112.5) {
return "west";
}
else if (112.5 <= yaw && yaw < 157.5) {
return "northwest";
}
else if (157.5 <= yaw && yaw < 202.5) {
return "north";
}
else if (202.5 <= yaw && yaw < 247.5) {
return "northeast";
}
else if (247.5 <= yaw && yaw < 292.5) {
return "east";
}
else if (292.5 <= yaw && yaw < 337.5) {
return "southeast";
}
else if (337.5 <= yaw && yaw < 360.0) {
return "south";
}
else {
return null;
}
}

void move(Entity entity, Vector vector);

Expand Down
Expand Up @@ -15,6 +15,10 @@

public interface PacketHelper {

void resetWorldBorder(Player player);

void setWorldBorder(Player player, Location center, double size, double currSize, long time, int warningDistance, int warningTime);

void setSlot(Player player, int slot, ItemStack itemStack, boolean playerOnly);

void setFieldOfView(Player player, float fov);
Expand Down
9 changes: 9 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -806,6 +806,9 @@ public Property get(dObject o) {
PropertyParser.registerProperty(EntityArmorPose.class, dEntity.class);
PropertyParser.registerProperty(EntityArms.class, dEntity.class);
PropertyParser.registerProperty(EntityBasePlate.class, dEntity.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
PropertyParser.registerProperty(EntityBeamTarget.class, dEntity.class);
}
PropertyParser.registerProperty(EntityBoundingBox.class, dEntity.class);
PropertyParser.registerProperty(EntityChestCarrier.class, dEntity.class);
PropertyParser.registerProperty(EntityColor.class, dEntity.class);
Expand All @@ -821,6 +824,9 @@ public Property get(dObject o) {
PropertyParser.registerProperty(EntityHealth.class, dEntity.class);
PropertyParser.registerProperty(EntityInfected.class, dEntity.class);
PropertyParser.registerProperty(EntityInventory.class, dEntity.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
PropertyParser.registerProperty(EntityIsShowingBottom.class, dEntity.class);
}
PropertyParser.registerProperty(EntityItem.class, dEntity.class);
PropertyParser.registerProperty(EntityJumpStrength.class, dEntity.class);
PropertyParser.registerProperty(EntityKnockback.class, dEntity.class);
Expand All @@ -836,6 +842,9 @@ public Property get(dObject o) {
PropertyParser.registerProperty(EntitySize.class, dEntity.class);
PropertyParser.registerProperty(EntitySkeleton.class, dEntity.class);
PropertyParser.registerProperty(EntitySpeed.class, dEntity.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1)) {
PropertyParser.registerProperty(EntitySpell.class, dEntity.class);
}
PropertyParser.registerProperty(EntityTame.class, dEntity.class);
PropertyParser.registerProperty(EntityVisible.class, dEntity.class);

Expand Down
Expand Up @@ -3,16 +3,21 @@
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.BukkitScriptEvent;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizencore.objects.Duration;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityCombustByBlockEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent;

public class EntityCombustsScriptEvent extends BukkitScriptEvent implements Listener {
Expand All @@ -31,6 +36,8 @@ public class EntityCombustsScriptEvent extends BukkitScriptEvent implements List
// @Context
// <context.entity> returns the entity that caught fire.
// <context.duration> returns the length of the burn.
// <context.source> returns the dEntity or dLocation that caused the fire, if any. NOTE: Currently, if the source is a dLocation, the tag will return a null. It is expected that this will be fixed by Spigot in the future.
// <context.source_type> returns the type of the source, which can be: ENTITY, LOCATION, NONE.
//
// @Determine
// Element(Number) set the length of duration.
Expand Down Expand Up @@ -108,6 +115,26 @@ public dObject getContext(String name) {
else if (name.equals("duration")) {
return new Duration(burntime);
}
else if (name.equals("source")) {
if (event instanceof EntityCombustByEntityEvent) {
return new dEntity(((EntityCombustByEntityEvent) event).getCombuster());
}
else if (event instanceof EntityCombustByBlockEvent) {
Block combuster = ((EntityCombustByBlockEvent) event).getCombuster();
if (combuster != null) {
return new dLocation(combuster.getLocation());
}
}
}
else if (name.equals("source_type")) {
if (event instanceof EntityCombustByEntityEvent) {
return new Element("ENTITY");
}
else if (event instanceof EntityCombustByBlockEvent) {
return new Element("LOCATION");
}
return new Element("NONE");
}
return super.getContext(name);
}

Expand Down
Expand Up @@ -24,9 +24,7 @@ public class EntityDamagedScriptEvent extends BukkitScriptEvent implements Liste
// @group Events
// @description
// Possible damage causes
// BLOCK_EXPLOSION, CONTACT, CUSTOM, DROWNING, ENTITY_ATTACK, ENTITY_EXPLOSION,
// FALL, FALLING_BLOCK, FIRE, FIRE_TICK, LAVA, LIGHTNING, MAGIC, MELTING, POISON,
// PROJECTILE, STARVATION, SUFFOCATION, SUICIDE, THORNS, VOID, WITHER.
// See list in Spigot source here: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html>
// -->

// <--[event]
Expand Down
Expand Up @@ -39,6 +39,7 @@ public class ProjectileHitsScriptEvent extends BukkitScriptEvent implements List
// <context.location> returns the dLocation of the block that was hit.
//
// -->

// <--[event]
// @Events
// entity shoots block (in <area>)
Expand Down
Expand Up @@ -17,7 +17,7 @@

public class LingeringPotionSplashScriptEvent extends BukkitScriptEvent implements Listener {

// TODO: Fix Event (Maybe spigot)
// <--[event]
// @Events
// lingering potion splash (in <area>)
// lingering <item> splashes (in <area>)
Expand All @@ -35,7 +35,7 @@ public class LingeringPotionSplashScriptEvent extends BukkitScriptEvent implemen
// <context.radius> returns the radius of the effect cloud.
// <context.duration> returns the lingering duration of the effect cloud.
//
// -- >
// -->

public LingeringPotionSplashScriptEvent() {
instance = this;
Expand Down
24 changes: 24 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/flags/FlagManager.java
Expand Up @@ -217,6 +217,30 @@ public Set<String> listNPCFlags(int npcid) {
return section != null ? _filterExpirations(section.getValues(true).keySet()) : null;
}

public void shrinkGlobalFlags(Collection<String> set) {
for (String str : new HashSet<>(set)) {
if (!serverHasFlag(str)) {
set.remove(str);
}
}
}

public void shrinkPlayerFlags(dPlayer player, Collection<String> set) {
for (String str : new HashSet<>(set)) {
if (!playerHasFlag(player, str)) {
set.remove(str);
}
}
}

public void shrinkEntityFlags(dEntity entity, Collection<String> set) {
for (String str : new HashSet<>(set)) {
if (!entityHasFlag(entity, str)) {
set.remove(str);
}
}
}

/**
* Returns a list of flag names currently attached to the server.
*/
Expand Down
Expand Up @@ -117,12 +117,7 @@ private void standInternal() {
sitting = false;
}

/**
* Makes the NPC sit at the specified location
*
* @param location where to sit
*/
public void sit(Location location) {
public void sitInternal(Location location) {
DenizenAPI.getDenizenNPC(npc).action("sit", null);

if (npc.getEntity().getType() != EntityType.PLAYER) {
Expand All @@ -133,10 +128,18 @@ public void sit(Location location) {
* Teleport NPC to the location before
* sending the sit packet to the clients.
*/
// TODO: Make this work better.
npc.teleport(location.clone().add(0, 0.5, 0), PlayerTeleportEvent.TeleportCause.PLUGIN);
npc.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);

sitInternal();
}

/**
* Makes the NPC sit at the specified location
*
* @param location where to sit
*/
public void sit(Location location) {
sitInternal(location.clone().add(0, 0.5, 0));
chairLocation = location.clone();
}

Expand Down

0 comments on commit 946e120

Please sign in to comment.