Skip to content

Instantly share code, notes, and snippets.

@aikar
Created April 6, 2019 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aikar/a4653bb1ae44e21ea75034a3a2e1f23f to your computer and use it in GitHub Desktop.
Save aikar/a4653bb1ae44e21ea75034a3a2e1f23f to your computer and use it in GitHub Desktop.
/*
* 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