diff --git a/src/main/java/pl/minecon724/giants/Main.java b/src/main/java/pl/minecon724/giants/Main.java index 7767117..17d87fc 100644 --- a/src/main/java/pl/minecon724/giants/Main.java +++ b/src/main/java/pl/minecon724/giants/Main.java @@ -17,6 +17,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; 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.EntitySpawnEvent; @@ -30,11 +31,13 @@ public class Main extends JavaPlugin implements Listener { FileConfiguration config; Random rnd = new Random(); - List giants = new ArrayList(); + List giants = new ArrayList(); boolean ai; + boolean headRotations; double chance; double attackDamage; + long refreshDelay; Map effects = new HashMap(); @Override @@ -71,13 +74,24 @@ public class Main extends JavaPlugin implements Listener { @Override public void run() { for (Entity e : giants) { - Collection nearby = e.getWorld().getNearbyEntities(e.getBoundingBox().expand(4D, 1D, 4D)); - for (Entity n : nearby) { - ((LivingEntity) n).damage(attackDamage, e); + Collection nearby = e.getWorld().getNearbyEntities(e.getBoundingBox().expand(4D, 1D, 4D), n -> (n instanceof Player)); + for (Entity p : nearby) { + ((LivingEntity) p).damage(attackDamage, e); } } } - }.runTaskTimer(this, 20L, 0L) + }.runTaskTimer(this, config.getLong("hitDelay"), 0L); + new BukkitRunnable() { + @Override + public void run() { + for (Entity e : giants) { + List passengers = e.getPassengers(); + passengers.removeIf(n -> (n.getType() != EntityType.HUSK)); + Location loc = passengers.get(0).getLocation(); + e.setRotation(loc.getYaw(), loc.getPitch()); + } + } + }.runTaskTimerAsynchronously(this, refreshDelay, 0L); } @EventHandler @@ -102,7 +116,7 @@ public class Main extends JavaPlugin implements Listener { PotionEffect effect = new PotionEffect(t.getKey(), Integer.MAX_VALUE, t.getValue()); effect.apply(entity); } - giants.add((Entity) entity); + giants.add(entity); return entity; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a6b1b6e..00c10df 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,9 +2,15 @@ ai: true attackDamage: 1.0 # Spawning chance, from 0 to 1 chance: 0.02 +# Attack delay in ticks, smaller values will lag the server more +hitDelay: 20 # Additional potion effects # type:amplifier # See https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html # Set to [] to disable effects: - - "JUMP:2" \ No newline at end of file + - "JUMP:2" + +# No need to change this +headRotations: true +refreshDelay: 40 \ No newline at end of file