This commit is contained in:
BuildTools 2022-01-29 15:33:54 +01:00
parent 498d96267b
commit 1335b2e759
2 changed files with 27 additions and 7 deletions

View File

@ -17,6 +17,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;
@ -30,11 +31,13 @@ public class Main extends JavaPlugin implements Listener {
FileConfiguration config; FileConfiguration config;
Random rnd = new Random(); Random rnd = new Random();
List<Entity> giants = new ArrayList<Entity>(); List<LivingEntity> giants = new ArrayList<LivingEntity>();
boolean ai; boolean ai;
boolean headRotations;
double chance; double chance;
double attackDamage; double attackDamage;
long refreshDelay;
Map<PotionEffectType, Integer> effects = new HashMap<PotionEffectType, Integer>(); Map<PotionEffectType, Integer> effects = new HashMap<PotionEffectType, Integer>();
@Override @Override
@ -71,13 +74,24 @@ public class Main extends JavaPlugin implements Listener {
@Override @Override
public void run() { public void run() {
for (Entity e : giants) { for (Entity e : giants) {
Collection<Entity> nearby = e.getWorld().getNearbyEntities(e.getBoundingBox().expand(4D, 1D, 4D)); Collection<Entity> nearby = e.getWorld().getNearbyEntities(e.getBoundingBox().expand(4D, 1D, 4D), n -> (n instanceof Player));
for (Entity n : nearby) { for (Entity p : nearby) {
((LivingEntity) n).damage(attackDamage, e); ((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<Entity> 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 @EventHandler
@ -102,7 +116,7 @@ public class Main extends JavaPlugin implements Listener {
PotionEffect effect = new PotionEffect(t.getKey(), Integer.MAX_VALUE, t.getValue()); PotionEffect effect = new PotionEffect(t.getKey(), Integer.MAX_VALUE, t.getValue());
effect.apply(entity); effect.apply(entity);
} }
giants.add((Entity) entity); giants.add(entity);
return entity; return entity;
} }
} }

View File

@ -2,9 +2,15 @@ ai: true
attackDamage: 1.0 attackDamage: 1.0
# Spawning chance, from 0 to 1 # Spawning chance, from 0 to 1
chance: 0.02 chance: 0.02
# Attack delay in ticks, smaller values will lag the server more
hitDelay: 20
# Additional potion effects # Additional potion effects
# type:amplifier # type:amplifier
# See https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html # See https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html
# Set to [] to disable # Set to [] to disable
effects: effects:
- "JUMP:2" - "JUMP:2"
# No need to change this
headRotations: true
refreshDelay: 40