Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.meloncode.cristalix.prison.mobs;
- import java.util.HashMap;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Effect;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Event;
- import org.bukkit.event.entity.EntityDamageEvent;
- import org.bukkit.event.entity.EntityRegainHealthEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- import net.md_5.bungee.api.ChatMessageType;
- import net.md_5.bungee.api.chat.ComponentBuilder;
- import net.minecraft.server.v1_12_R1.DamageSource;
- import net.minecraft.server.v1_12_R1.Entity;
- import net.minecraft.server.v1_12_R1.EntityCreature;
- import net.minecraft.server.v1_12_R1.EntityHuman;
- import net.minecraft.server.v1_12_R1.EntityInsentient;
- import net.minecraft.server.v1_12_R1.EntityPlayer;
- import net.minecraft.server.v1_12_R1.EntityVindicator;
- import net.minecraft.server.v1_12_R1.GenericAttributes;
- import net.minecraft.server.v1_12_R1.PathfinderGoal;
- import net.minecraft.server.v1_12_R1.PathfinderGoalHurtByTarget;
- import net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer;
- import net.minecraft.server.v1_12_R1.PathfinderGoalMeleeAttack;
- import net.minecraft.server.v1_12_R1.PathfinderGoalMoveTowardsRestriction;
- import net.minecraft.server.v1_12_R1.PathfinderGoalNearestAttackableTarget;
- import net.minecraft.server.v1_12_R1.PathfinderGoalRandomStroll;
- import net.minecraft.server.v1_12_R1.World;
- import ru.meloncode.cristalix.prison.Main;
- import ru.meloncode.cristalix.prison.PrisonPlayer;
- import ru.meloncode.cristalix.prison.Utils;
- public class EntityFilimPidor extends EntityVindicator
- {
- Spawner spawner;
- int hp_delay;
- int jump_delay = 80;
- int storm = 400;
- HashMap<String, Integer> attackers = new HashMap<>();
- int totalDamage = 0;
- Random rand;
- public EntityFilimPidor(final Spawner spawner) {
- super((World)((CraftWorld)spawner.getSpawnLocation().getWorld()).getHandle());
- this.hp_delay = 20;
- this.rand = new Random();
- this.getAttributeInstance(GenericAttributes.maxHealth).setValue((double)Main.BERSERK_HEALTH);
- this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128.0);
- this.getAttributeInstance(GenericAttributes.c).setValue(-1.0);
- this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0);
- this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(1);
- this.setHealth((float)Main.BERSERK_HEALTH);
- this.goalSelector.a(1, (PathfinderGoal)new PathfinderGoalLookAtPlayer((EntityInsentient)this, (Class<EntityHuman>)EntityHuman.class, 128.0f));
- this.goalSelector.a(5, (PathfinderGoal)new PathfinderGoalMoveTowardsRestriction((EntityCreature)this, 1.0));
- this.goalSelector.a(7, (PathfinderGoal)new PathfinderGoalRandomStroll((EntityCreature)this, 1.0));
- this.targetSelector.a(4, (PathfinderGoal)new PathfinderGoalNearestAttackableTarget<EntityHuman>((EntityCreature)this, (Class<EntityHuman>)EntityHuman.class, true));
- this.targetSelector.a(5, (PathfinderGoal)new PathfinderGoalHurtByTarget((EntityCreature)this, true, new Class[0]));
- this.goalSelector.a(9, (PathfinderGoal)new PathfinderGoalLookAtPlayer((EntityInsentient)this, (Class<EntityHuman>)EntityHuman.class, 64.0f));
- this.goalSelector.a(2, (PathfinderGoal)new PathfinderGoalMeleeAttack((EntityCreature)this, (double)Main.BERSERK_DAMAGE, true));
- this.spawner = spawner;
- this.setCustomName(Main.BERSERK_NAME.replace("#", String.valueOf((int)this.getHealth())).replace("<3", "\u2764"));
- this.setCustomNameVisible(true);
- this.canPickUpLoot = false;
- this.fireProof = true;
- if (this.spawner != null) {
- this.spawner.register((Entity)this);
- }
- this.persistent = true;
- this.expToDrop = 0;
- LivingEntity entity = (LivingEntity) this.getBukkitEntity();
- entity.getEquipment().setItemInHand(new ItemStack(Material.IRON_AXE));
- }
- public void superJump() {
- this.getBukkitEntity().setVelocity(new Vector(0, 0, 0).multiply(0));
- new BukkitRunnable() {
- public void run() {
- EntityFilimPidor.this.getBukkitEntity().getWorld().playSound(EntityFilimPidor.this.getBukkitEntity().getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0f, 1.0f);
- for (final org.bukkit.entity.Entity entity : EntityFilimPidor.this.getBukkitEntity().getNearbyEntities(7.0, 6.0, 7.0)) {
- if (entity.getType() == EntityType.PLAYER) {
- entity.setVelocity(entity.getVelocity().add(entity.getLocation().getDirection()).multiply(-3));
- final EntityDamageEvent event = new EntityDamageEvent(entity, EntityDamageEvent.DamageCause.MAGIC, 5);
- Bukkit.getPluginManager().callEvent((Event)event);
- if (event.isCancelled()) {
- continue;
- }
- ((LivingEntity)entity).damage(5.0);
- }
- }
- }
- }.runTaskLater(Main.getInstance(), 25L);
- }
- public boolean damageEntity(final DamageSource source, float a) {
- if ((this.passengers.size() != 0 && source.getEntity() == this.passengers.get(0)) || source == DamageSource.STUCK || source == DamageSource.FALL) {
- return false;
- }
- this.setCustomName(Main.BERSERK_NAME.replace("#", String.valueOf((int)this.getHealth())).replace("<3", "\u2764"));
- if (this.passengers.size() != 0) {
- return source != DamageSource.projectile((net.minecraft.server.v1_12_R1.Entity)this, this.passengers.get(0)) && this.passengers.get(0).damageEntity(source, a);
- }
- final net.minecraft.server.v1_12_R1.Entity entity = source.i();
- if (entity != null && entity.getBukkitEntity().getType() == EntityType.PLAYER) {
- Player p = (Player) Bukkit.getPlayer(entity.getBukkitEntity().getName());
- final PrisonPlayer pp = PrisonPlayer.getPrisonPlayer(p);
- if (!this.attackers.containsKey(pp.getName())) {
- this.attackers.put(pp.getName(), (int)a);
- }
- else {
- this.attackers.put(pp.getName(), (int)(this.attackers.get(pp.getName()) + a));
- }
- this.totalDamage += (int)a;
- }
- float newhp = getHealth() - a;
- double dmg = this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue();
- if(newhp <= 300 && dmg == Main.BERSERK_DAMAGE) this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(Main.BERSERK_DAMAGE * 5);
- return super.damageEntity(source, a);
- }
- public void n() {
- if(this.spawner.getCurrent() == null) return;
- if (this.spawner.getCurrent() != null && this.spawner.getSpawnLocation().distance(this.spawner.getCurrent().getBukkitEntity().getLocation()) > 20.0) {
- this.spawner.getCurrent().setLocation(this.spawner.getSpawnLocation().getX(), this.spawner.getSpawnLocation().getY(), this.spawner.getSpawnLocation().getZ(), 0.0f, 0.0f);
- }
- if (this.hp_delay-- <= 0) {
- this.setCustomName(Main.BERSERK_NAME.replace("#", String.valueOf((int)this.getHealth())).replace("<3", "\u2764"));
- if (this.getHealth() < Main.BERSERK_HEALTH) {
- this.heal(1.0f, EntityRegainHealthEvent.RegainReason.REGEN);
- }
- this.hp_delay = 5;
- }
- if (this.jump_delay-- <= 0) {
- this.jump_delay = 25;
- superJump();
- }
- if (this.getGoalTarget() != null && this.passengers.size() == 0) {
- final boolean isSameWorld = this.getBukkitEntity().getLocation().getWorld() == this.getGoalTarget().getBukkitEntity().getLocation().getWorld();
- final double distance = isSameWorld ? this.getBukkitEntity().getLocation().distance(this.getGoalTarget().getBukkitEntity().getLocation()) : 32.0;
- if (distance > 16.0) {
- this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.0);
- }
- else {
- this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(Main.BERSERK_SPEED);
- }
- }
- super.n();
- }
- @Override
- public boolean r(final Entity entity) {
- return super.r(entity);
- }
- public void summonEffect(PotionEffectType type, int duration, int level) {
- this.getBukkitEntity().getNearbyEntities(15d, 10d, 15d).stream().filter(e -> e.getType() == EntityType.PLAYER).forEach(e -> ((Player) e).addPotionEffect(new PotionEffect(type, duration, level)));
- }
- public void die() {
- if (this.spawner != null) {
- this.spawner.iDead();
- }
- if (this.killer instanceof EntityPlayer) {
- final Player p = (Player)this.killer.getBukkitEntity();
- if (this.spawner != null) {
- PrisonPlayer.getPrisonPlayer(p).addMobKill(this.spawner.getType());
- }
- }
- if (this.killer != null) {
- final HashMap<String, Double> percents = Utils.calculatePercents(this.attackers, this.totalDamage);
- for (final String key : percents.keySet()) {
- final int money = (int)(percents.get(key) * Main.BERSERK_MONEY / 100.0);
- Main.economy.depositPlayer(key, (double)money * PrisonPlayer.getPrisonPlayer(key).getResourcesMultiplier());
- Player p = Bukkit.getPlayer(key);
- if (p != null) {
- PrisonPlayer.getPrisonPlayer(p).addShards(Main.BERSERK_SHARD * PrisonPlayer.getPrisonPlayer(key).getCrystalsMultiplier());
- p.sendMessage(Utils.f("&a&l\u041d\u0430\u0433\u0440\u0430\u0434\u0430: &b" + Main.BERSERK_SHARD * PrisonPlayer.getPrisonPlayer(key).getCrystalsMultiplier()) + " \u0448\u0430\u0440\u0434\u043e\u0432");
- p.sendMessage(ChatColor.GREEN + "\u041d\u0430 \u0432\u0430\u0448 \u0441\u0447\u0435\u0442 \u0431\u044b\u043b\u043e \u0437\u0430\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e " + ChatColor.GREEN + money * PrisonPlayer.getPrisonPlayer(key).getExpMultiplier() + "$");
- PrisonPlayer.getPrisonPlayer(p).addExp((int)(Main.BERSERK_EXP * PrisonPlayer.getPrisonPlayer(key).getExpMultiplier()));
- p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder("+" + (int)(Main.BERSERK_EXP * PrisonPlayer.getPrisonPlayer(key).getExpMultiplier()) + " \u043e\u043f\u044b\u0442").color(net.md_5.bungee.api.ChatColor.GOLD).create());
- }
- }
- Bukkit.broadcastMessage(ChatColor.RED +(Utils.f("&a\u0411\u043e\u0441\u0441 &c\u0411\u0435\u0440\u0441\u0435\u0440\u043a &a\u0431\u044b\u043b \u0443\u0431\u0438\u0442!")));
- Main.dropBerserkDropOn(this.getBukkitEntity().getLocation());
- }
- super.die();
- }
- @Override
- public String getName() {
- return Main.BERSERK_NAME.replace("<3", "").replace("#", "");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement