Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* Copyright (c) 2018. Starlis LLC / dba Empire Minecraft
*
* This source code is proprietary software and must not be redistributed without Starlis LLC's approval
*
*/
package com.empireminecraft.items.uncommon;
import com.destroystokyo.paper.event.entity.ArrowHitBlockEvent;
import com.empireminecraft.features.items.CustomArrow;
import com.empireminecraft.features.items.Items;
import com.empireminecraft.features.items.SpecialProjectile;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
public final class ExplosiveArrow extends CustomArrow {
public static final ExplosiveArrowHandler EXPLOSIVE_ARROW_HANDLER = new ExplosiveArrowHandler();
public ExplosiveArrow() {
super("ExplosiveArrow", Material.TIPPED_ARROW, EXPLOSIVE_ARROW_HANDLER);
Items.buildLore(this)
.setName("&cExplosive Arrow")
.add("&4WARNING - EXPLOSIVE MATERIAL")
.add("&cHandle with care!")
.makeShiny()
.save();
PotionMeta meta = (PotionMeta) this.getItemMeta();
meta.setBasePotionData(new PotionData(PotionType.MUNDANE));
meta.setColor(Color.RED);
setItemMeta(meta);
}
public static class ExplosiveArrowHandler extends SpecialProjectile {
public ExplosiveArrowHandler() {
super("ExplosiveArrow");
}
@Override
public void onGroundHit(LivingEntity shooter, ArrowHitBlockEvent event) {
Arrow arrow = event.getEntity();
doExplosion(arrow);
}
private void doExplosion(Arrow arrow) {
arrow.remove();
Location location = arrow.getLocation();
location.getWorld().createExplosion(location, 2, false, false);
}
@Override
public void onEntityHit(LivingEntity shooter, EntityDamageByEntityEvent event) {
Arrow arrow = (Arrow) event.getDamager();
doExplosion(arrow);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.