Guest User

Untitled

a guest
Nov 15th, 2023
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.23 KB | None | 0 0
  1. package ua.senalll.cekc_auth.api.monsters.skeletons;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.Material;
  5. import org.bukkit.attribute.Attribute;
  6. import org.bukkit.block.Biome;
  7. import org.bukkit.entity.Arrow;
  8. import org.bukkit.entity.Entity;
  9. import org.bukkit.entity.EntityType;
  10. import org.bukkit.entity.Skeleton;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.entity.EntityShootBowEvent;
  14. import org.bukkit.event.entity.EntitySpawnEvent;
  15. import org.bukkit.inventory.ItemStack;
  16. import org.bukkit.metadata.FixedMetadataValue;
  17. import org.bukkit.metadata.MetadataValue;
  18. import org.bukkit.plugin.Plugin;
  19. import org.bukkit.potion.PotionEffect;
  20. import org.bukkit.potion.PotionEffectType;
  21. import ua.senalll.cekc_auth.Main;
  22. import ua.senalll.cekc_auth.utilities.ComponentUtils;
  23.  
  24. import java.util.List;
  25. import java.util.Objects;
  26.  
  27. public class AbstractSkeleton implements Listener {
  28.  
  29.     public static Plugin instance;
  30.     private static MetadataValue dataValue;
  31.     private static PotionEffectType potionType;
  32.     private static Integer maxHealth;
  33.     private static Float movSpeed;
  34.     private static String name;
  35.     private static List<Biome> biomeList;
  36.  
  37.     public AbstractSkeleton(String mob_key, PotionEffectType potion_effect, Integer max_health, Float mov_speed,
  38.                             String name, List<Biome> biomes_list){
  39.         this.instance = Main.instance();
  40.         this.dataValue = new FixedMetadataValue(instance, mob_key);
  41.         this.potionType = potion_effect;
  42.         this.maxHealth = max_health;
  43.         this.movSpeed = mov_speed;
  44.         this.name = name;
  45.         this.biomeList = biomes_list;
  46.     }
  47.  
  48.     public static void spawnSkeleton(Location location){
  49.         Skeleton skeleton = location.getWorld().spawn(location, Skeleton.class);
  50.         skeleton.customName(ComponentUtils.yellow(name));
  51.         skeleton.setCustomNameVisible(true);
  52.         Objects.requireNonNull(skeleton.getAttribute(Attribute.GENERIC_MAX_HEALTH)).setBaseValue(maxHealth);
  53.         Objects.requireNonNull(skeleton.getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).setBaseValue(20);
  54.         Objects.requireNonNull(skeleton.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED)).setBaseValue(movSpeed);
  55.         skeleton.setCanPickupItems(false);
  56.         skeleton.setMetadata("mob_type", dataValue);
  57.         skeleton.getEquipment().setItemInMainHand(new ItemStack(Material.BOW));
  58.     }
  59.  
  60.  
  61.     @EventHandler
  62.     public void onArrowHit(EntityShootBowEvent e){
  63.         if(!isSkeleton(e.getEntity())) return;
  64.         ((Arrow) e.getProjectile()).addCustomEffect(new PotionEffect(
  65.                 potionType, 40, 2), true)
  66.         ;
  67.     }
  68.  
  69.     public boolean isSkeleton(Entity entity){
  70.         if(!(entity.getType().equals(EntityType.SKELETON))) return false;
  71.         if(!(entity.hasMetadata("mob_type"))) return false;
  72.         return entity.getMetadata("mob_type").contains(dataValue);
  73.     }
  74.  
  75.     @EventHandler
  76.     public void onEntitySpawn(EntitySpawnEvent e){
  77.         if(!(e.getEntity().getType().equals(EntityType.SKELETON))) return;
  78.         if(!biomeList.contains(e.getLocation().getBlock().getBiome())) return;
  79.         e.getEntity().remove();
  80.         spawnSkeleton(e.getLocation());
  81.     }
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment