diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/module/ZombieGuardianModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/module/ZombieGuardianModule.java new file mode 100644 index 000000000..adefa0479 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/module/ZombieGuardianModule.java @@ -0,0 +1,133 @@ +package nautilus.game.arcade.game.games.skywars.module; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Zombie; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.modules.Module; + +public class ZombieGuardianModule extends Module +{ + + private static final ItemStack[] ARMOUR = + { + new ItemStack(Material.GOLD_BOOTS), + new ItemStack(Material.GOLD_LEGGINGS), + new ItemStack(Material.GOLD_CHESTPLATE), + new ItemStack(Material.GOLD_HELMET) + }; + private static final int HEALTH = 15; + private static final int MAX_OFFSET_SQUARED = 64; + + private final List _spawns; + private final Map _zombies; + + public ZombieGuardianModule() + { + _spawns = new ArrayList<>(); + _zombies = new HashMap<>(); + } + + public ZombieGuardianModule addSpawns(List spawns) + { + _spawns.addAll(spawns); + return this; + } + + @EventHandler + public void spawnZombies(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + { + return; + } + + getGame().CreatureAllowOverride = true; + + for (Location location : _spawns) + { + Zombie zombie = location.getWorld().spawn(location, Zombie.class); + zombie.setRemoveWhenFarAway(false); + zombie.setCustomName(C.cDRed + "Zombie Guardian"); + zombie.setCustomNameVisible(true); + zombie.setMaxHealth(HEALTH); + zombie.setHealth(HEALTH); + + EntityEquipment equipment = zombie.getEquipment(); + equipment.setArmorContents(ARMOUR); + equipment.setHelmetDropChance(0); + equipment.setChestplateDropChance(0); + equipment.setLeggingsDropChance(0); + equipment.setBootsDropChance(0); + + _zombies.put(zombie, location); + } + + getGame().CreatureAllowOverride = false; + } + + @EventHandler + public void zombieTarget(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + return; + } + + _zombies.keySet().removeIf(zombie -> !zombie.isValid()); + + _zombies.forEach((zombie, location) -> + { + if (zombie.getTarget() == null || UtilMath.offsetSquared(zombie.getLocation(), location) > MAX_OFFSET_SQUARED) + { + zombie.setTarget(null); + UtilEnt.CreatureMove(zombie, location, 1); + } + }); + } + + @EventHandler + public void zombieTarget(EntityTargetLivingEntityEvent event) + { + if (event.getTarget() == null || !_zombies.containsKey(event.getEntity())) + { + return; + } + + Zombie zombie = (Zombie) event.getEntity(); + Location location = _zombies.get(zombie); + + if (UtilMath.offsetSquared(event.getTarget().getLocation(), location) > MAX_OFFSET_SQUARED) + { + event.setCancelled(true); + zombie.setTarget(null); + } + } + + @EventHandler + public void zombieCombust(EntityCombustEvent event) + { + if (_zombies.containsKey(event.getEntity())) + { + event.setCancelled(true); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/MapCrumbleModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/MapCrumbleModule.java index ff7781228..d3e0eb8dc 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/MapCrumbleModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/MapCrumbleModule.java @@ -21,6 +21,8 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.world.WorldData; public class MapCrumbleModule extends Module @@ -36,9 +38,14 @@ public class MapCrumbleModule extends Module _worldBlocks = new HashSet<>(100000); } - @Override - protected void setup() + @EventHandler + public void readWorld(GameStateChangeEvent event) { + if (event.GetState() != GameState.Recruit) + { + return; + } + WorldData worldData = getGame().WorldData; getGame().getArcadeManager().runSyncTimer(new BukkitRunnable() @@ -63,7 +70,7 @@ public class MapCrumbleModule extends Module } } - Bukkit.broadcastMessage("Blocks = " + _worldBlocks.size()); + Bukkit.broadcastMessage("Blocks = " + _worldBlocks.size() + " - " + y); if (++y == worldData.MaxY) { @@ -71,7 +78,7 @@ public class MapCrumbleModule extends Module Bukkit.broadcastMessage("Done"); } } - }, 1, 1); + }, 1, 2); } public MapCrumbleModule setEnabled(boolean enabled) @@ -80,6 +87,11 @@ public class MapCrumbleModule extends Module return this; } + public boolean isEnabled() + { + return _enabled; + } + public MapCrumbleModule setRate(int rate) { _rate = rate;