mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 11:44:19 +01:00
Added the concept of a projectile.
By: sunkid <sunkid@iminurnetz.com>
This commit is contained in:
parent
2a62ac59bf
commit
31e3c65440
11 changed files with 83 additions and 16 deletions
|
@ -2,7 +2,5 @@ package org.bukkit.entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an arrow.
|
* Represents an arrow.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public interface Arrow extends Entity {}
|
public interface Arrow extends Projectile {}
|
||||||
|
|
|
@ -2,7 +2,5 @@ package org.bukkit.entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an egg.
|
* Represents an egg.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public interface Egg extends Entity {}
|
public interface Egg extends Projectile {}
|
||||||
|
|
|
@ -1,6 +1,24 @@
|
||||||
package org.bukkit.entity;
|
package org.bukkit.entity;
|
||||||
|
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Fireball.
|
* Represents a Fireball.
|
||||||
*/
|
*/
|
||||||
public interface Fireball extends Explosive {}
|
public interface Fireball extends Projectile, Explosive {
|
||||||
|
/**
|
||||||
|
* Fireballs fly straight and do not take setVelocity(...) well.
|
||||||
|
*
|
||||||
|
* @param direction
|
||||||
|
* the direction this fireball is flying toward
|
||||||
|
*/
|
||||||
|
public void setDirection(Vector direction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the direction this fireball is heading toward
|
||||||
|
*
|
||||||
|
* @return the direction
|
||||||
|
*/
|
||||||
|
public Vector getDirection();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,5 @@ package org.bukkit.entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Fish.
|
* Represents a Fish.
|
||||||
*
|
|
||||||
* @author Cogito
|
|
||||||
*/
|
*/
|
||||||
public interface Fish extends Entity {}
|
public interface Fish extends Projectile {}
|
||||||
|
|
23
paper-api/src/main/java/org/bukkit/entity/Projectile.java
Normal file
23
paper-api/src/main/java/org/bukkit/entity/Projectile.java
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package org.bukkit.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a shootable entity
|
||||||
|
*/
|
||||||
|
public interface Projectile extends Entity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the shooter of this projectile. The returned value can be null
|
||||||
|
* for projectiles shot from a {@link Dispenser} for example.
|
||||||
|
*
|
||||||
|
* @return the {@link LivingEntity} that shot this projectile
|
||||||
|
*/
|
||||||
|
public LivingEntity getShooter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the shooter of this projectile
|
||||||
|
*
|
||||||
|
* @param shooter
|
||||||
|
* the {@link LivingEntity} that shot this projectile
|
||||||
|
*/
|
||||||
|
public void setShooter(LivingEntity shooter);
|
||||||
|
}
|
|
@ -2,7 +2,5 @@ package org.bukkit.entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements a snowball.
|
* Implements a snowball.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public interface Snowball extends Entity {}
|
public interface Snowball extends Projectile {}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.bukkit.event;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an event
|
* Represents an event
|
||||||
*/
|
*/
|
||||||
|
@ -618,6 +620,12 @@ public abstract class Event implements Serializable {
|
||||||
* @see org.bukkit.event.entity.EntityTameEvent
|
* @see org.bukkit.event.entity.EntityTameEvent
|
||||||
*/
|
*/
|
||||||
ENTITY_TAME (Category.LIVING_ENTITY),
|
ENTITY_TAME (Category.LIVING_ENTITY),
|
||||||
|
/**
|
||||||
|
* Called when a {@link Projectile} hits something
|
||||||
|
*
|
||||||
|
* @see org.bukkit.event.entity.ProjectileHitEvent
|
||||||
|
*/
|
||||||
|
PROJECTILE_HIT (Category.ENTITY),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a LivingEntity is regains health
|
* Called when a LivingEntity is regains health
|
||||||
|
|
|
@ -3,13 +3,18 @@ package org.bukkit.event.entity;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
|
||||||
public class EntityDamageByProjectileEvent extends EntityDamageByEntityEvent {
|
public class EntityDamageByProjectileEvent extends EntityDamageByEntityEvent {
|
||||||
|
|
||||||
private Entity projectile;
|
private Projectile projectile;
|
||||||
private boolean bounce;
|
private boolean bounce;
|
||||||
|
|
||||||
public EntityDamageByProjectileEvent(Entity damager, Entity damagee, Entity projectile, DamageCause cause, int damage) {
|
public EntityDamageByProjectileEvent(Entity damagee, Projectile projectile, DamageCause cause, int damage) {
|
||||||
|
this(projectile.getShooter(), damagee, projectile, cause, damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityDamageByProjectileEvent(Entity damager, Entity damagee, Projectile projectile, DamageCause cause, int damage) {
|
||||||
super(damager, damagee, cause, damage);
|
super(damager, damagee, cause, damage);
|
||||||
this.projectile = projectile;
|
this.projectile = projectile;
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
@ -19,9 +24,10 @@ public class EntityDamageByProjectileEvent extends EntityDamageByEntityEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The projectile used to cause the event
|
* The projectile used to cause the event
|
||||||
|
*
|
||||||
* @return the projectile
|
* @return the projectile
|
||||||
*/
|
*/
|
||||||
public Entity getProjectile() {
|
public Projectile getProjectile() {
|
||||||
return projectile;
|
return projectile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,4 +41,6 @@ public class EntityListener implements Listener {
|
||||||
public void onEntityTame(EntityTameEvent event) {}
|
public void onEntityTame(EntityTameEvent event) {}
|
||||||
|
|
||||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {}
|
public void onEntityRegainHealth(EntityRegainHealthEvent event) {}
|
||||||
|
|
||||||
|
public void onProjectileHit(ProjectileHitEvent event) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.bukkit.event.entity;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
|
||||||
|
public class ProjectileHitEvent extends EntityEvent {
|
||||||
|
|
||||||
|
public ProjectileHitEvent(Projectile projectile) {
|
||||||
|
super(Type.PROJECTILE_HIT, projectile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -719,6 +719,13 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case PROJECTILE_HIT:
|
||||||
|
return new EventExecutor() {
|
||||||
|
public void execute(Listener listener, Event event) {
|
||||||
|
((EntityListener) listener).onProjectileHit((ProjectileHitEvent) event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Vehicle Events
|
// Vehicle Events
|
||||||
case VEHICLE_CREATE:
|
case VEHICLE_CREATE:
|
||||||
return new EventExecutor() {
|
return new EventExecutor() {
|
||||||
|
|
Loading…
Reference in a new issue