Skip to content

Commit

Permalink
Implements ProjectileHitEvent (GlowstoneMC#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaiTon committed Dec 17, 2018
1 parent 17600c7 commit 0fd2db6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/main/java/net/glowstone/entity/GlowEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
Expand All @@ -16,6 +17,7 @@
import java.util.UUID;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import lombok.Getter;
import lombok.Setter;
import net.glowstone.EventFactory;
Expand Down Expand Up @@ -53,17 +55,10 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.entity.*;
import org.bukkit.event.Event;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.EntityPortalExitEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.vehicle.VehicleEnterEvent;
Expand Down Expand Up @@ -360,7 +355,7 @@ public UUID getUniqueId() {
*
* @param uuid The new UUID. Must not be null.
* @throws IllegalArgumentException if the passed UUID is null.
* @throws IllegalStateException if a UUID has already been set.
* @throws IllegalStateException if a UUID has already been set.
*/
public void setUniqueId(UUID uuid) {
checkNotNull(uuid, "uuid must not be null");
Expand Down Expand Up @@ -591,7 +586,7 @@ public void pulse() {
EntityPortalExitEvent e = EventFactory.getInstance()
.callEvent(new EntityPortalExitEvent(this, previousLocation,
location
.clone(), velocity.clone(), new Vector()));
.clone(), velocity.clone(), new Vector()));
if (!e.getAfter().equals(velocity)) {
setVelocity(e.getAfter());
}
Expand Down Expand Up @@ -671,7 +666,7 @@ public void reset() {
* Sets this entity's location.
*
* @param location The new location.
* @param fall Whether to calculate fall damage or not.
* @param fall Whether to calculate fall damage or not.
*/
public void setRawLocation(Location location, boolean fall) {
if (location.getWorld() != world) {
Expand Down Expand Up @@ -735,7 +730,7 @@ public void setRawLocation(Location location) {
* block.
*
* @return true to call {@link #setOnGround(boolean)} from {@link #setRawLocation(Location,
* boolean)}; false otherwise
* boolean)}; false otherwise
*/
protected boolean hasDefaultLandingBehavior() {
return true;
Expand Down Expand Up @@ -962,8 +957,8 @@ public boolean isTouchingMaterial(Material material) {
if (boundingBox == null) {
// less accurate calculation if no bounding box is present
for (BlockFace face : new BlockFace[]{BlockFace.EAST, BlockFace.WEST, BlockFace.SOUTH,
BlockFace.NORTH, BlockFace.DOWN, BlockFace.SELF, BlockFace.NORTH_EAST,
BlockFace.NORTH_WEST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST}) {
BlockFace.NORTH, BlockFace.DOWN, BlockFace.SELF, BlockFace.NORTH_EAST,
BlockFace.NORTH_WEST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST}) {
if (getLocation().getBlock().getRelative(face).getType() == material) {
return true;
}
Expand Down Expand Up @@ -1024,7 +1019,9 @@ protected void pulsePhysics() {
if (pendingLocationZ.getBlock().getType().isSolid()) {
velocity.setZ(0);
}

if (this instanceof Projectile) {
EventFactory.getInstance().callEvent(new ProjectileHitEvent((Projectile) this, pendingBlock));
}
collide(pendingBlock);
} else {
if (hasFriction()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package net.glowstone.entity.projectile;

import com.flowpowered.network.Message;

import java.util.Arrays;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import net.glowstone.EventFactory;
import net.glowstone.entity.GlowEntity;
import net.glowstone.net.message.play.entity.EntityMetadataMessage;
import net.glowstone.net.message.play.entity.EntityVelocityMessage;
Expand All @@ -15,6 +18,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;

Expand Down Expand Up @@ -69,6 +73,7 @@ protected void pulsePhysics() {
location, size.getX(), size.getY(), size.getZ())) {
if (entity != this && !(entity.equals(shooter))) {
if (entity instanceof LivingEntity) {
EventFactory.getInstance().callEvent(new ProjectileHitEvent(this, entity));
collide((LivingEntity) entity);
break;
}
Expand Down

0 comments on commit 0fd2db6

Please sign in to comment.