amog
This commit is contained in:
parent
a18a12243b
commit
498d96267b
2 changed files with 26 additions and 2 deletions
|
@ -1,7 +1,10 @@
|
|||
package pl.minecon724.giants;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
@ -20,15 +23,18 @@ import org.bukkit.event.entity.EntitySpawnEvent;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class Main extends JavaPlugin implements Listener {
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
FileConfiguration config;
|
||||
|
||||
Random rnd = new Random();
|
||||
List<Entity> giants = new ArrayList<Entity>();
|
||||
|
||||
boolean ai;
|
||||
double chance;
|
||||
double attackDamage;
|
||||
Map<PotionEffectType, Integer> effects = new HashMap<PotionEffectType, Integer>();
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +46,7 @@ public class Main extends JavaPlugin implements Listener {
|
|||
|
||||
ai = config.getBoolean("ai");
|
||||
chance = config.getDouble("chance");
|
||||
attackDamage = config.getDouble("attackDamage");
|
||||
for (Object s : config.getList("effects")) {
|
||||
try {
|
||||
String[] parts = ((String) s).split(":");
|
||||
|
@ -60,6 +67,17 @@ public class Main extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entity e : giants) {
|
||||
Collection<Entity> nearby = e.getWorld().getNearbyEntities(e.getBoundingBox().expand(4D, 1D, 4D));
|
||||
for (Entity n : nearby) {
|
||||
((LivingEntity) n).damage(attackDamage, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(this, 20L, 0L)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -75,12 +93,16 @@ public class Main extends JavaPlugin implements Listener {
|
|||
Entity spawnGiant(boolean ai, Location pos) {
|
||||
LivingEntity entity = (LivingEntity) pos.getWorld().spawnEntity(pos, EntityType.GIANT);
|
||||
if (ai) {
|
||||
entity.addPassenger(pos.getWorld().spawnEntity(pos, EntityType.HUSK));
|
||||
Entity passenger = pos.getWorld().spawnEntity(pos, EntityType.HUSK);
|
||||
new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1).apply((LivingEntity) passenger);
|
||||
passenger.setInvulnerable(true);
|
||||
entity.addPassenger(passenger);
|
||||
}
|
||||
for (Entry<PotionEffectType, Integer> t : effects.entrySet()) {
|
||||
PotionEffect effect = new PotionEffect(t.getKey(), Integer.MAX_VALUE, t.getValue());
|
||||
effect.apply(entity);
|
||||
}
|
||||
return null;
|
||||
giants.add((Entity) entity);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
ai: true
|
||||
attackDamage: 1.0
|
||||
# Spawning chance, from 0 to 1
|
||||
chance: 0.02
|
||||
# Additional potion effects
|
||||
# type:amplifier
|
||||
# See https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html
|
||||
# Set to [] to disable
|
||||
effects:
|
||||
- "JUMP:2"
|
Loading…
Reference in a new issue