Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.senalll.cekc_auth.api.monsters.skeletons;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.attribute.Attribute;
- import org.bukkit.block.Biome;
- import org.bukkit.entity.Arrow;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Skeleton;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.EntityShootBowEvent;
- import org.bukkit.event.entity.EntitySpawnEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.metadata.FixedMetadataValue;
- import org.bukkit.metadata.MetadataValue;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import ua.senalll.cekc_auth.Main;
- import ua.senalll.cekc_auth.utilities.ComponentUtils;
- import java.util.List;
- import java.util.Objects;
- public class AbstractSkeleton implements Listener {
- public static Plugin instance;
- private static MetadataValue dataValue;
- private static PotionEffectType potionType;
- private static Integer maxHealth;
- private static Float movSpeed;
- private static String name;
- private static List<Biome> biomeList;
- public AbstractSkeleton(String mob_key, PotionEffectType potion_effect, Integer max_health, Float mov_speed,
- String name, List<Biome> biomes_list){
- this.instance = Main.instance();
- this.dataValue = new FixedMetadataValue(instance, mob_key);
- this.potionType = potion_effect;
- this.maxHealth = max_health;
- this.movSpeed = mov_speed;
- this.name = name;
- this.biomeList = biomes_list;
- }
- public static void spawnSkeleton(Location location){
- Skeleton skeleton = location.getWorld().spawn(location, Skeleton.class);
- skeleton.customName(ComponentUtils.yellow(name));
- skeleton.setCustomNameVisible(true);
- Objects.requireNonNull(skeleton.getAttribute(Attribute.GENERIC_MAX_HEALTH)).setBaseValue(maxHealth);
- Objects.requireNonNull(skeleton.getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).setBaseValue(20);
- Objects.requireNonNull(skeleton.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED)).setBaseValue(movSpeed);
- skeleton.setCanPickupItems(false);
- skeleton.setMetadata("mob_type", dataValue);
- skeleton.getEquipment().setItemInMainHand(new ItemStack(Material.BOW));
- }
- @EventHandler
- public void onArrowHit(EntityShootBowEvent e){
- if(!isSkeleton(e.getEntity())) return;
- ((Arrow) e.getProjectile()).addCustomEffect(new PotionEffect(
- potionType, 40, 2), true)
- ;
- }
- public boolean isSkeleton(Entity entity){
- if(!(entity.getType().equals(EntityType.SKELETON))) return false;
- if(!(entity.hasMetadata("mob_type"))) return false;
- return entity.getMetadata("mob_type").contains(dataValue);
- }
- @EventHandler
- public void onEntitySpawn(EntitySpawnEvent e){
- if(!(e.getEntity().getType().equals(EntityType.SKELETON))) return;
- if(!biomeList.contains(e.getLocation().getBlock().getBiome())) return;
- e.getEntity().remove();
- spawnSkeleton(e.getLocation());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment