Skip to content
Permalink
Browse files
Fix cast exception for fireworks in projectile events
  • Loading branch information
PseudoKnight committed Jul 20, 2020
1 parent 9c887c8 commit 7d6c37a7058c05923b0ba8d446c1f1d985ff5591
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
@@ -6,7 +6,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;

public class BukkitMCFirework extends BukkitMCEntity implements MCFirework {
public class BukkitMCFirework extends BukkitMCProjectile implements MCFirework {

Firework f;

@@ -13,53 +13,55 @@

public class BukkitMCProjectile extends BukkitMCEntity implements MCProjectile {

Projectile proj;

public BukkitMCProjectile(Entity e) {
super(e);
this.proj = (Projectile) e;
}

@Override
public boolean doesBounce() {
return proj.doesBounce();
// Some entities (like fireworks prior to 1.16) may not be treated as projectiles on this server implementation
if(getHandle() instanceof Projectile) {
return ((Projectile) getHandle()).doesBounce();
}
return false;
}

@Override
public MCProjectileSource getShooter() {
ProjectileSource source = proj.getShooter();
if(getHandle() instanceof Projectile) {
ProjectileSource source = ((Projectile) getHandle()).getShooter();

if(source instanceof BlockProjectileSource) {
return new BukkitMCBlockProjectileSource((BlockProjectileSource) source);
}
if(source instanceof BlockProjectileSource) {
return new BukkitMCBlockProjectileSource((BlockProjectileSource) source);
}

if(source instanceof Entity) {
MCEntity e = BukkitConvertor.BukkitGetCorrectEntity((Entity) source);
if(e instanceof MCProjectileSource) {
return (MCProjectileSource) e;
if(source instanceof Entity) {
MCEntity e = BukkitConvertor.BukkitGetCorrectEntity((Entity) source);
if(e instanceof MCProjectileSource) {
return (MCProjectileSource) e;
}
}
}

return null;
}

@Override
public void setBounce(boolean doesBounce) {
proj.setBounce(doesBounce);
if(getHandle() instanceof Projectile) {
((Projectile) getHandle()).setBounce(doesBounce);
}
}

@Override
public void setShooter(MCProjectileSource shooter) {
if(shooter == null) {
proj.setShooter(null);
} else if(shooter instanceof MCBlockProjectileSource) {
proj.setShooter((BlockProjectileSource) shooter.getHandle());
} else {
proj.setShooter((ProjectileSource) shooter.getHandle());
if(getHandle() instanceof Projectile) {
if(shooter == null) {
((Projectile) getHandle()).setShooter(null);
} else if(shooter instanceof MCBlockProjectileSource) {
((Projectile) getHandle()).setShooter((BlockProjectileSource) shooter.getHandle());
} else {
((Projectile) getHandle()).setShooter((ProjectileSource) shooter.getHandle());
}
}
}

public Projectile asProjectile() {
return proj;
}
}
@@ -75,6 +75,7 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Event;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
@@ -251,7 +252,7 @@ public MCBlock getHitBlock() {

public static BukkitMCProjectileHitEvent _instantiate(MCProjectile p) {
return new BukkitMCProjectileHitEvent(
new ProjectileHitEvent(((BukkitMCProjectile) p).asProjectile()));
new ProjectileHitEvent(((Projectile) p.getHandle())));
}

}
@@ -1,9 +1,8 @@
package com.laytonsmith.abstraction.entities;

import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.MCFireworkMeta;

public interface MCFirework extends MCEntity {
public interface MCFirework extends MCProjectile {

MCFireworkMeta getFireWorkMeta();

0 comments on commit 7d6c37a

Please sign in to comment.