- Баллы
- 66
- Имя в Minecraft
- DieF
JavaScript:
package Mobs;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import org.bukkit.craftbukkit.Main;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Giant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityEvent;
import org.*********ventory.ItemStack;
public class mainClass extends JavaPlugin implements Listener
{
public Main plugin;
public Random rng = new Random();
public void onEnable()
{
getLogger().info("Mobs plugin was Enable");
Bukkit.getPluginManager().registerEvents(this,this);
rng = new Random();
}
public void onDisable()
{
getLogger().info("Mobs plugin was Disable");
}
@EventHandler // откл. урон от солнца
public void stopFire(EntityCombustEvent e)
{
if (e.getEntityType() != EntityType.GIANT)
{
return;
}
e.setCancelled(true);
}
@EventHandler // отключая урон от стрел
public void stopArrowDamage(EntityDamageByEntityEvent e)
{
if (e.getEntityType() != EntityType.GIANT)
{
return;
}
if (!(e.getDamager() instanceof Arrow))
{
return;
}
//if (!(e.getDamager()))
e.setCancelled(true);
}
@EventHandler
public void stopFallDamage(EntityDamageEvent e)
{
if (e.getEntityType() != EntityType.GIANT)
{
return;
}
if ((e.getCause().equals(EntityDamageEvent.DamageCause.FALL)))
{
e.setCancelled(true);
}
}
/*@EventHandler
public void onDamage(EntityDamageEvent e)
{
if (e.getEntityType() == EntityType.GIANT)
{
e.setCancelled(true);
Giant Giant = (Giant) e.getEntity();
Giant.damage(e.getDamage());
}
} */
@EventHandler
public void jump(EntityDamageByEntityEvent e)
{
if (e.isCancelled())
{
return;
}
if (e.getEntityType() != EntityType.GIANT)
{
return;
}
int chance = this.rng.nextInt(100);
if (chance <= 10)
{
spawnFriends(e.getEntity());
return;
}
if (chance >= 85)
{
jump(e.getEntity());
return;
}
}
public void spawnFriends(Entity entity)
{
boolean spawnPiggy = false;
boolean spawnFour = this.rng.nextBoolean();
if (this.rng.nextInt(100) <= 20)
{
spawnPiggy = true;
}
if (spawnPiggy)
{
entity.getWorld().spawnEntity(entity.getLocation().getBlock().getRelative(0, 8, 0).getLocation(), EntityType.PIG_ZOMBIE);
entity.getWorld().spawnEntity(entity.getLocation().getBlock().getRelative(0, 8, 0).getLocation(), EntityType.ZOMBIE);
}
else
{
entity.getWorld().spawnEntity(entity.getLocation().getBlock().getRelative(0, 8, 0).getLocation(), EntityType.ZOMBIE);
entity.getWorld().spawnEntity(entity.getLocation().getBlock().getRelative(0, 8, 0).getLocation(), EntityType.ZOMBIE);
}
if (spawnFour)
{
entity.getWorld().spawnEntity(entity.getLocation().getBlock().getRelative(0, 8, 0).getLocation(), EntityType.ZOMBIE);
entity.getWorld().spawnEntity(entity.getLocation().getBlock().getRelative(0, 8, 0).getLocation(), EntityType.ZOMBIE);
}
}
public void jump(Entity entity)
{
entity.setVelocity(new Vector(0.0D, 1.8D, 0.0D));
//giantsActing.add(entity.getUniqueId());
//explodeOnImpact(entity, 45L);
entity.getWorld().playSound(entity.getLocation(), Sound.ENDERDRAGON_GROWL, 3.0F, 0.8F);
}
@EventHandler // отталкивание игрока
public void kickPlayer(EntityDamageByEntityEvent e)
{
if (e.isCancelled())
{
return;
}
if (e.getEntityType() != EntityType.PLAYER)
{
return;
}
if (e.getDamager().getType() != EntityType.GIANT)
{
return;
}
e.setDamage((int) 0.0D);
kick(e.getDamager(), e.getEntity());
}
public void kick(Entity entity, Entity kicked)
{
kicked.setVelocity(getDifferentialVector(entity.getLocation(), kicked.getLocation()).multiply(4.0D).setY(0.0D));
if ((kicked instanceof Player))
{
((Player)kicked).damage((int) 5.0D);
((Player)kicked).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 2));
}
}
public static Vector getDifferentialVector(Location from, Location to) {
return new Vector(to.getX() - from.getX(), to.getY() - from.getY(), to.getZ() - from.getZ());
}
@EventHandler // когда умирает гигант
public void onEntityDeath(EntityDeathEvent e)
{
if(e.getEntityType() == EntityType.GIANT)
if (e.getEntity().getCustomName() == null)
{
byte d = (byte) rng.nextInt(6);
if (d == 0)
{
e.getDrops().clear();
e.setDroppedExp(0);
e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENDERDRAGON_GROWL, 3.0F, 0.8F);
e.getDrops().add(new ItemStack(Material.DIAMOND_SWORD, 1));
e.getDrops().add(new ItemStack(Material.DIAMOND_SWORD, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
}
if (d == 1)
{
e.getDrops().clear();
e.setDroppedExp(0);
e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENDERDRAGON_GROWL, 3.0F, 0.8F);
e.getDrops().add(new ItemStack(Material.DIAMOND_SWORD, 1));
e.getDrops().add(new ItemStack(Material.GOLDEN_APPLE, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
}
if (d == 2)
{
e.getDrops().clear();
e.setDroppedExp(0);
e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENDERDRAGON_GROWL, 3.0F, 0.8F);
e.getDrops().add(new ItemStack(Material.GOLDEN_APPLE, 1));
e.getDrops().add(new ItemStack(Material.GOLDEN_APPLE, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
}
if (d == 3)
{
e.getDrops().clear();
e.setDroppedExp(0);
e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENDERDRAGON_GROWL, 3.0F, 0.8F);
e.getDrops().add(new ItemStack(Material.GOLDEN_APPLE, 1));
e.getDrops().add(new ItemStack(Material.BOW, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
}
if (d == 4)
{
e.getDrops().clear();
e.setDroppedExp(0);
e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENDERDRAGON_GROWL, 3.0F, 0.8F);
e.getDrops().add(new ItemStack(Material.BOW, 1));
e.getDrops().add(new ItemStack(Material.BOW, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
}
if (d == 5)
{
e.getDrops().clear();
e.setDroppedExp(0);
e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENDERDRAGON_GROWL, 3.0F, 0.8F);
e.getDrops().add(new ItemStack(Material.DIAMOND_SWORD, 1));
e.getDrops().add(new ItemStack(Material.BOW, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
e.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, 1));
}
}
}
@EventHandler // спаун гиганта
public void onEntitySpawnGiant(CreatureSpawnEvent e)
{
LivingEntity ent = e.getEntity();
if(e.getEntityType() == EntityType.GIANT)
{
byte m = (byte) rng.nextInt(1);
if(m == 0)
{
ent.setMaxHealth(100);
ent.setHealth((int) 100.0D);
e.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999, 2));
}
}
}
@EventHandler // спаун гиганта
public void onEntitySpawnZombie(CreatureSpawnEvent e)
{
LivingEntity ent = e.getEntity();
if(e.getEntityType() == EntityType.ZOMBIE)
{
byte m = (byte) rng.nextInt(1);
if(m == 0)
{
ent.setMaxHealth(20);
ent.setHealth((int) 20.0D);
e.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999, 2));
}
}
}
}
Как сделать так что бы - при получения в ближнем бою урона Гигант, не будет отталкивается, но когда по нему стреляют он не будет получать урона, кто может, помогите. Так же его нелзя будет толкать.