From 6d42c5c0756f88457564ef223d8d665e5a1d3420 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 12 Apr 2018 08:37:41 +0100 Subject: [PATCH] Block Hunt Update (#604) --- .../core/achievement/AchievementCategory.java | 10 +- .../arcade/game/games/hideseek/HideSeek.java | 491 +++++++++++------- .../game/games/hideseek/forms/BlockForm.java | 88 ++-- .../games/hideseek/kits/KitHiderInfestor.java | 1 - 4 files changed, 347 insertions(+), 243 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java index 556b86a78..11754062c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java @@ -120,7 +120,15 @@ public enum AchievementCategory Material.EGG, 0, GameCategory.CLASSICS, null, false, GameDisplay.BawkBawkBattles.getGameId()), BLOCK_HUNT("Block Hunt", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[] + { + StatDisplay.fromGame("Hider Wins", GameDisplay.HideSeek, "Wins"), + StatDisplay.fromGame("Hunter Wins", GameDisplay.HideSeek, "HunterWins"), + StatDisplay.fromGame("Games Played", GameDisplay.HideSeek, "Wins", "HunterWins", "Losses"), + StatDisplay.KILLS, + StatDisplay.DEATHS, + StatDisplay.GEMS_EARNED + }, Material.GRASS, 0, GameCategory.CLASSICS, "Infestor Kit", false, GameDisplay.HideSeek.getGameId()), SMASH_MOBS("Super Smash Mobs", null, diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/HideSeek.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/HideSeek.java index f0cf120fb..01ee1c61a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/HideSeek.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/HideSeek.java @@ -6,6 +6,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; +import java.util.Set; import net.minecraft.server.v1_8_R3.EntityCreature; import net.minecraft.server.v1_8_R3.NavigationAbstract; @@ -44,10 +45,12 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; @@ -55,7 +58,6 @@ import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.util.Vector; @@ -79,9 +81,10 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.disguise.disguises.DisguiseBase; +import mineplex.core.disguise.disguises.DisguiseLiving; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.packethandler.IPacketHandler; -import mineplex.core.packethandler.PacketInfo; +import mineplex.core.packethandler.PacketHandler; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -134,7 +137,7 @@ public class HideSeek extends TeamGame return getHandlerList(); } - public MeowEvent(Player who) + MeowEvent(Player who) { super(who); } @@ -191,7 +194,7 @@ public class HideSeek extends TeamGame } } - public static final ItemStack PLAYER_ITEM = ItemStackFactory.Instance.CreateStack(Material.SLIME_BALL, (byte) 0, 1, C.cYellow + C.Bold + "Click Block" + C.cWhite + C.Bold + " - " + C.cGreen + C.Bold + "Change Form"); + public static final ItemStack PLAYER_ITEM = ItemStackFactory.Instance.CreateStack(Material.SLIME_BALL, (byte) 0, 1, C.cYellowB + "Click Block" + C.cWhiteB + " - " + C.cGreenB + "Change Form"); private GameTeam _hiders; private GameTeam _seekers; @@ -204,96 +207,82 @@ public class HideSeek extends TeamGame private boolean _started = false; - private HashMap _arrowHits = new HashMap(); + private final HashMap _arrowHits = new HashMap<>(); - private HashMap _forms = new HashMap(); - private HashMap _infested = new HashMap(); - private HashSet _infestDeny = new HashSet(); + private final HashMap _forms = new HashMap<>(); + private final HashMap _infested = new HashMap<>(); + private final HashSet _infestDeny = new HashSet<>(); - private HashMap _mobs = new HashMap(); + private final HashMap _mobs = new HashMap<>(); private ArrayList _allowedBlocks; private ArrayList _allowedEnts; - private IPacketHandler _useEntity = new IPacketHandler() + private final Set _startingHunters = new HashSet<>(); + + private final IPacketHandler _useEntity = packetInfo -> { - @Override - public void handle(PacketInfo packetInfo) + if (packetInfo.getPacket() instanceof PacketPlayInUseEntity) { - if (packetInfo.getPacket() instanceof PacketPlayInUseEntity) + int id = ((PacketPlayInUseEntity) packetInfo.getPacket()).a; + + for (Entry entry : _forms.entrySet()) { - int id = ((PacketPlayInUseEntity) packetInfo.getPacket()).a; - - for (Entry entry : _forms.entrySet()) + if (entry.getValue() instanceof BlockForm) { - if (entry.getValue() instanceof BlockForm) - { - BlockForm blockForm = (BlockForm) entry.getValue(); + BlockForm blockForm = (BlockForm) entry.getValue(); - if (blockForm.getBlockId() == id) - { - ((PacketPlayInUseEntity) packetInfo.getPacket()).a = blockForm.Player - .getEntityId(); - break; - } + if (blockForm.getBlockId() == id) + { + ((PacketPlayInUseEntity) packetInfo.getPacket()).a = blockForm.Player.getEntityId(); + break; } } } } }; - private IPacketHandler _blockDisguise = new IPacketHandler() + private final IPacketHandler _blockDisguise = packetInfo -> { - @Override - public void handle(PacketInfo packetInfo) + if (packetInfo.getPacket() instanceof PacketPlayOutSpawnEntityLiving) { - if (packetInfo.getPacket() instanceof PacketPlayOutSpawnEntityLiving) - { - int id = ((PacketPlayOutSpawnEntityLiving) packetInfo - .getPacket()).a; + int id = ((PacketPlayOutSpawnEntityLiving) packetInfo + .getPacket()).a; + for (Entry entry : _forms.entrySet()) + { + if (!(entry.getValue() instanceof BlockForm)) + continue; + + final BlockForm blockForm = (BlockForm) entry.getValue(); + + if (blockForm.Player.getEntityId() != id || blockForm.Player == packetInfo.getPlayer()) + continue; + + final Player player = packetInfo.getPlayer(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), () -> UtilPlayer.sendPacket(player, blockForm.getBlockPackets(UtilPlayer.is1_9(player)))); + break; + } + } + else if (packetInfo.getPacket() instanceof PacketPlayOutEntityDestroy) + { + for (int i : ((PacketPlayOutEntityDestroy) packetInfo.getPacket()).a) + { for (Entry entry : _forms.entrySet()) { if (!(entry.getValue() instanceof BlockForm)) continue; - final BlockForm blockForm = (BlockForm) entry.getValue(); + BlockForm blockForm = (BlockForm) entry.getValue(); - if (blockForm.Player.getEntityId() != id || blockForm.Player == packetInfo.getPlayer()) + if (blockForm.Player.getEntityId() != i) continue; - final Player player = packetInfo.getPlayer(); - - Bukkit.getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() - { - public void run() - { - UtilPlayer.sendPacket(player, blockForm.getBlockPackets(UtilPlayer.is1_9(player))); - } - }); - - break; - } - } - else if (packetInfo.getPacket() instanceof PacketPlayOutEntityDestroy) - { - for (int i : ((PacketPlayOutEntityDestroy) packetInfo.getPacket()).a) - { - for (Entry entry : _forms.entrySet()) - { - if (!(entry.getValue() instanceof BlockForm)) - continue; - - BlockForm blockForm = (BlockForm) entry.getValue(); - - if (blockForm.Player.getEntityId() != i) - continue; - - UtilPlayer.sendPacket(packetInfo.getPlayer(), new PacketPlayOutEntityDestroy(new int[] - { - blockForm.getBlockId() - })); - } + UtilPlayer.sendPacket(packetInfo.getPlayer(), new PacketPlayOutEntityDestroy(new int[] + { + blockForm.getBlockId() + })); } } } @@ -304,7 +293,7 @@ public class HideSeek extends TeamGame this(manager, new Kit[] { - new KitHiderQuick(manager), new KitHiderSwapper(manager), new KitHiderInfestor(manager), + new KitHiderSwapper(manager), new KitHiderQuick(manager), new KitHiderInfestor(manager), new KitHiderShocker(manager), new NullKit(manager), new KitSeekerLeaper(manager), new KitSeekerTNT(manager), new KitSeekerRadar(manager), }); @@ -323,17 +312,17 @@ public class HideSeek extends TeamGame C.cRed + "Seekers" + C.cWhite + " Find and kill the Hiders!", }); - this.DamageSelf = false; - this.DeathOut = false; - this.HungerSet = 20; - this.PrepareFreeze = false; - this.SplitKitXP = true; - this.AllowParticles = false; + DamageSelf = false; + DeathOut = false; + HungerSet = 20; + PrepareFreeze = false; + SplitKitXP = true; + AllowParticles = false; + DeathSpectateSecs = 1; - _allowedBlocks = new ArrayList(); + _allowedBlocks = new ArrayList<>(); _allowedBlocks.add(Material.TNT); _allowedBlocks.add(Material.BOOKSHELF); - _allowedBlocks.add(Material.WORKBENCH); _allowedBlocks.add(Material.FURNACE); _allowedBlocks.add(Material.MELON_BLOCK); _allowedBlocks.add(Material.CAULDRON); @@ -342,7 +331,7 @@ public class HideSeek extends TeamGame _allowedBlocks.add(Material.HAY_BLOCK); _allowedBlocks.add(Material.CAKE_BLOCK); - _allowedEnts = new ArrayList(); + _allowedEnts = new ArrayList<>(); _allowedEnts.add(EntityType.PIG); _allowedEnts.add(EntityType.COW); _allowedEnts.add(EntityType.CHICKEN); @@ -359,7 +348,7 @@ public class HideSeek extends TeamGame new HunterOfTheYearStatTracker(this), new BadHiderStatTracker(this) ); - + registerQuestTrackers(new DisguiseQuestTracker(this)); //Need ideas for this one @@ -377,6 +366,8 @@ public class HideSeek extends TeamGame @EventHandler public void onceReady(GamePrepareCountdownCommence event) { + _startingHunters.addAll(_seekers.GetPlayers(false)); + List hiders = _hiders.GetPlayers(false); for (Player player : hiders) @@ -402,15 +393,17 @@ public class HideSeek extends TeamGame @EventHandler public void onGameEndStart(GameStateChangeEvent event) { + PacketHandler packetHandler = getArcadeManager().getPacketHandler(); + if (event.GetState() == GameState.Prepare) { - this.getArcadeManager().getPacketHandler().addPacketHandler(_blockDisguise, PacketPlayOutSpawnEntityLiving.class, PacketPlayOutEntityDestroy.class); - this.getArcadeManager().getPacketHandler().addPacketHandler(_useEntity, true, PacketPlayInUseEntity.class); + packetHandler.addPacketHandler(_blockDisguise, PacketPlayOutSpawnEntityLiving.class, PacketPlayOutEntityDestroy.class); + packetHandler.addPacketHandler(_useEntity, true, PacketPlayInUseEntity.class); } else if (event.GetState() == GameState.Dead) { - this.getArcadeManager().getPacketHandler().removePacketHandler(_blockDisguise); - this.getArcadeManager().getPacketHandler().removePacketHandler(_useEntity); + packetHandler.removePacketHandler(_blockDisguise); + packetHandler.removePacketHandler(_useEntity); } } @@ -429,28 +422,32 @@ public class HideSeek extends TeamGame @Override public void ParseData() { - int i = 0; - - for (ArrayList locs : WorldData.GetAllCustomLocs().values()) + WorldData.GetAllCustomLocs().keySet().forEach(key -> { - for (Location loc : locs) + if (!key.startsWith("IDS")) { - if (Math.random() > 0.25) - continue; - - if (loc.getBlock().getRelative(BlockFace.UP).getType() != Material.AIR) - continue; - - loc.getBlock().setType(Material.AIR); - i++; + return; } - } - System.out.println("Removed " + i + " Random Blocks."); + String[] split = key.split(" "); + + for (int i = 1; i < split.length; i++) + { + try + { + int id = Integer.parseInt(split[i]); + _allowedBlocks.add(Material.getMaterial(id)); + } + catch (NumberFormatException ex) + { + } + } + }); for (Location loc : WorldData.GetDataLocs("BLACK")) + { loc.getBlock().setType(Material.FENCE); - + } } @EventHandler @@ -481,7 +478,8 @@ public class HideSeek extends TeamGame { if (kit.GetName().contains("Hider")) team.GetRestrictedKits().add(kit); - } else + } + else { if (kit.GetName().contains("Hunter")) team.GetRestrictedKits().add(kit); @@ -503,7 +501,7 @@ public class HideSeek extends TeamGame if (GetKits().length <= 5 + i) continue; - GetKits()[5 + i].getGameKit().createNPC(WorldData.GetDataLocs("RED").get(i)); + GetKits()[5 + i].getGameKit().createNPC(WorldData.GetDataLocs("RED").get(i)); } CreatureAllowOverride = false; @@ -521,7 +519,8 @@ public class HideSeek extends TeamGame bow.addEnchantment(Enchantment.ARROW_INFINITE, 1); player.getInventory().setItem(1, bow); player.getInventory().setItem(28, ItemStackFactory.Instance.CreateStack(Material.ARROW)); - } else + } + else { // Axe player.getInventory().setItem(0, @@ -555,14 +554,11 @@ public class HideSeek extends TeamGame @EventHandler public void ChangeDisguise(PlayerInteractEvent event) { - if (event.getAction() == Action.PHYSICAL) + if (event.getAction() == Action.PHYSICAL || event.getClickedBlock() == null) { return; } - if (event.getClickedBlock() == null) - return; - Player player = event.getPlayer(); if (!UtilGear.isMat(player.getItemInHand(), Material.SLIME_BALL)) @@ -575,7 +571,13 @@ public class HideSeek extends TeamGame F.main("Game", "You cannot morph into " + F.elem(ItemStackFactory.Instance - .GetName(event.getClickedBlock().getType(), (byte) 0, false) + " Block") + ".")); + .GetName(event.getClickedBlock().getType(), (byte) 0, false)) + ".")); + return; + } + + if (UtilBlock.liquid(player.getLocation().getBlock())) + { + player.sendMessage(F.main("Game", "You cannot morph while in water.")); return; } @@ -586,9 +588,14 @@ public class HideSeek extends TeamGame UtilInv.remove(player, Material.SLIME_BALL, (byte) 0, 1); // Remove Old - _forms.get(player).Remove(); + Form form = _forms.get(player); - Form form = new BlockForm(this, player, event.getClickedBlock().getType()); + if (form != null) + { + form.Remove(); + } + + form = new BlockForm(this, player, event.getClickedBlock().getType()); // Set New _forms.put(player, form); @@ -773,7 +780,8 @@ public class HideSeek extends TeamGame { proj = (Projectile) eventEE.getDamager(); damager = (LivingEntity) proj.getShooter(); - } else if (eventEE.getDamager() instanceof LivingEntity) + } + else if (eventEE.getDamager() instanceof LivingEntity) { damager = (LivingEntity) eventEE.getDamager(); } @@ -865,15 +873,16 @@ public class HideSeek extends TeamGame if (!_hiders.HasPlayer(shooter)) return; - Arrow arrow = shooter.getWorld().spawnArrow( - shooter.getEyeLocation().add(shooter.getLocation().getDirection().multiply(1.5)), - shooter.getLocation().getDirection(), (float) event.getProjectile().getVelocity().length(), 0f); + Location location = shooter.getEyeLocation(); + + Vector direction = location.getDirection(); + Arrow arrow = shooter.getWorld().spawnArrow(location.add(direction.clone().multiply(1.5)).add(new Vector(Math.random() * 0.5 - 0.25, Math.random() * 0.5 - 0.25, Math.random() * 0.5 - 0.25)), direction, (float) event.getProjectile().getVelocity().length(), 0f); arrow.setShooter(shooter); event.setCancelled(true); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void ArrowHit(CustomDamageEvent event) { if (event.IsCancelled()) @@ -896,9 +905,8 @@ public class HideSeek extends TeamGame if (!_hiders.HasPlayer(damager)) return; - event.AddMod("Hide & Seek", "Negate", -event.GetDamageInitial(), false); - event.AddMod("Hide & Seek", "Damage Set", 2, false); - event.AddKnockback("Hide & Seek", 2); + event.AddMod(GetName(), "Constant Damage", -event.GetDamage() + 2, false); + event.AddKnockback(GetName(), 2); Powerup(damager); } @@ -922,7 +930,8 @@ public class HideSeek extends TeamGame // Inform UtilPlayer.message(player, F.main("Game", "You upgraded to " + F.elem("Super Axe") + "!")); - } else if (count == 8) + } + else if (count == 8) { player.getInventory().remove(Material.STONE_AXE); player.getInventory().addItem( @@ -933,7 +942,8 @@ public class HideSeek extends TeamGame // Inform UtilPlayer.message(player, F.main("Game", "You upgraded to " + F.elem("Ultra Axe") + "!")); - } else if (count == 12) + } + else if (count == 12) { player.getInventory().remove(Material.IRON_AXE); player.getInventory().addItem( @@ -944,7 +954,8 @@ public class HideSeek extends TeamGame // Inform UtilPlayer.message(player, F.main("Game", "You upgraded to " + F.elem("Hyper Axe") + "!")); - } else if (count < 12) + } + else if (count < 12) { // Sound player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1f, 1f); @@ -983,7 +994,8 @@ public class HideSeek extends TeamGame // Sound player.getWorld().playSound(player.getLocation(), Sound.BLAZE_BREATH, 1f, 1f); - } else if (UtilGear.isMat(player.getItemInHand(), Material.STONE_AXE)) + } + else if (UtilGear.isMat(player.getItemInHand(), Material.STONE_AXE)) { Manager.GetCondition().Factory().Speed("Boost", player, player, 4, 1, false, false, false); @@ -992,7 +1004,8 @@ public class HideSeek extends TeamGame // Sound player.getWorld().playSound(player.getLocation(), Sound.BLAZE_BREATH, 1f, 1f); - } else if (UtilGear.isMat(player.getItemInHand(), Material.IRON_AXE)) + } + else if (UtilGear.isMat(player.getItemInHand(), Material.IRON_AXE)) { Manager.GetCondition().Factory().Speed("Boost", player, player, 4, 1, false, false, false); Manager.GetCondition().Factory().Regen("Boost", player, player, 4, 0, false, false, false); @@ -1002,7 +1015,8 @@ public class HideSeek extends TeamGame // Sound player.getWorld().playSound(player.getLocation(), Sound.BLAZE_BREATH, 1f, 1f); - } else if (UtilGear.isMat(player.getItemInHand(), Material.DIAMOND_AXE)) + } + else if (UtilGear.isMat(player.getItemInHand(), Material.DIAMOND_AXE)) { Manager.GetCondition().Factory().Speed("Boost", player, player, 4, 2, false, false, false); Manager.GetCondition().Factory().Regen("Boost", player, player, 4, 1, false, false, false); @@ -1101,21 +1115,11 @@ public class HideSeek extends TeamGame while (_seekers.GetPlayers(true).size() < req && _hiders.GetPlayers(true).size() > 0) { - Player player = _hiders.GetPlayers(true).get(UtilMath.r(_hiders.GetPlayers(true).size())); + Player player = UtilAlg.Random(_hiders.GetPlayers(true)); SetSeeker(player, true); } } - @EventHandler - public void WaterDamage(UpdateEvent event) - { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.FAST) - return; - } - @EventHandler public void WorldWaterDamage(UpdateEvent event) { @@ -1142,6 +1146,8 @@ public class HideSeek extends TeamGame Form form = _forms.remove(event.getPlayer()); if (form != null) form.Remove(); + + _startingHunters.remove(event.getPlayer()); } @EventHandler @@ -1154,11 +1160,19 @@ public class HideSeek extends TeamGame public void SetSeeker(Player player, boolean forced) { GameTeam pastTeam = GetTeam(player); + if (pastTeam != null && pastTeam.equals(_hiders)) + { pastTeam.SetPlacement(player, PlayerState.OUT); + } SetPlayerTeam(player, _seekers, true); + if (IsInfesting(player)) + { + InfestEnd(player); + } + // Remove Form Form form = _forms.remove(player); if (form != null) @@ -1170,9 +1184,9 @@ public class HideSeek extends TeamGame { Manager.GetDisguise().undisguise(disguise); } + // Kit SetKit(player, GetKits()[5], false); - GetKits()[5].ApplyKit(player); // Refresh VisibilityManager vm = Managers.require(VisibilityManager.class); @@ -1182,19 +1196,14 @@ public class HideSeek extends TeamGame { AddGems(player, 10, "Forced Seeker", false, false); - Announce(F.main("Game", - F.elem(_hiders.GetColor() + player.getName()) + " was moved to " + F.elem(C.cRed + C.Bold + "Hunters") + ".")); + Announce(F.main("Game", F.elem(_hiders.GetColor() + player.getName()) + " was moved to " + F.elem(C.cRedB + "Hunters") + ".")); + _startingHunters.add(player); player.getWorld().strikeLightningEffect(player.getLocation()); - - player.damage(1000); + RespawnPlayer(player); } - UtilPlayer.message(player, C.cRed + C.Bold + "You are now a Hunter!"); - - player.eject(); - player.leaveVehicle(); - player.teleport(_seekers.GetSpawn()); + UtilPlayer.message(player, C.cRedB + "You are now a Hunter!"); } @Override @@ -1214,6 +1223,8 @@ public class HideSeek extends TeamGame ArrayList places = _hiders.GetPlacements(true); AnnounceEnd(_hiders.GetPlacements(true)); + // Need to manually set the WinnerTeam otherwise no one gets XP + WinnerTeam = _hiders; // Gems if (places.size() >= 1) @@ -1230,6 +1241,12 @@ public class HideSeek extends TeamGame AddGems(player, 10, "Participation", false, false); SetState(GameState.End); + + _startingHunters.forEach(player -> + { + AddStat(player, "HunterWins", 1, true, false); + GetStats().get(player).remove(GetName() + ".Losses"); + }); } } @@ -1256,7 +1273,7 @@ public class HideSeek extends TeamGame if (event.GetState() != GameState.Live) return; - Announce(C.cAqua + C.Bold + "Hiders have 20 Seconds to hide!"); + Announce(C.cAquaB + "Hiders have 20 Seconds to hide!"); } @EventHandler @@ -1346,14 +1363,15 @@ public class HideSeek extends TeamGame Scoreboard.writeNewLine(); Scoreboard.write(C.cYellow + C.Bold + "Hide Time"); - Scoreboard.write(UtilTime.MakeStr(Math.max(0, timeLeft), 0)); - } else + Scoreboard.write(UtilTime.MakeStr(Math.max(0, timeLeft))); + } + else { long timeLeft = _gameTime - (System.currentTimeMillis() - GetStateTime() - _hideTime); Scoreboard.writeNewLine(); Scoreboard.write(C.cYellow + C.Bold + "Seek Time"); - Scoreboard.write(UtilTime.MakeStr(Math.max(0, timeLeft), 0)); + Scoreboard.write(UtilTime.MakeStr(Math.max(0, timeLeft))); } Scoreboard.draw(); @@ -1379,16 +1397,6 @@ public class HideSeek extends TeamGame return true; } - @Override - public boolean CanThrowTNT(Location location) - { - for (Location loc : _seekers.GetSpawns()) - if (UtilMath.offset(loc, location) < 24) - return false; - - return true; - } - @Override public DeathMessageType GetDeathMessageType() { @@ -1398,16 +1406,78 @@ public class HideSeek extends TeamGame @EventHandler public void UsableCancel(PlayerInteractEvent event) { - if (event.getClickedBlock() == null) + if (event.getClickedBlock() == null || UtilPlayer.isSpectator(event.getPlayer())) + { return; - - if (UtilBlock.usable(event.getClickedBlock())) - event.setCancelled(true); + } if (event.getClickedBlock().getType() == Material.WOODEN_DOOR) { event.setCancelled(false); } + else if (UtilBlock.usable(event.getClickedBlock())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void updateSuffocation(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST || !IsLive()) + { + return; + } + + for (Player player : _hiders.GetPlayers(true)) + { + if (player.getVehicle() != null) + { + continue; + } + + Location location = player.getLocation(); + Block block = location.getBlock(); + + // % 1 gets the decimal reminder of the height so we can work out if they are on a slab or farmland + if (UtilBlock.fullSolid(block) && location.getY() % 1 < 0.5) + { + Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.SUFFOCATION, 1, false, true, true, GetName(), "Suffocation"); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void explosion(EntityExplodeEvent event) + { + if (!IsLive()) + { + return; + } + + Location location = UtilAlg.getAverageLocation(_seekers.GetSpawns()); + + event.blockList().removeIf(block -> + { + Material material = block.getType(); + return material == Material.LADDER || material == Material.WOODEN_DOOR || material == Material.CHEST || UtilBlock.liquid(material) || UtilMath.offset2dSquared(location, block.getLocation()) < 225; + }); + } + + @EventHandler + public void blockPhysics(BlockPhysicsEvent event) + { + if (!IsLive()) + { + return; + } + + Material material = event.getChangedType(); + + if (material == Material.LADDER || material == Material.WOODEN_DOOR || UtilBlock.liquid(material)) + { + event.setCancelled(true); + } } public GameTeam getHiders() @@ -1423,8 +1493,10 @@ public class HideSeek extends TeamGame @EventHandler public void InfestDisguise(PlayerInteractEvent event) { - if (event.getClickedBlock() == null) + if (event.getAction() == Action.PHYSICAL || event.getClickedBlock() == null) + { return; + } final Player player = event.getPlayer(); @@ -1439,7 +1511,7 @@ public class HideSeek extends TeamGame player, F.main("Game", "You cannot infest " - + F.elem(ItemStackFactory.Instance.GetName(block.getType(), (byte) 0, false) + " Block") + + F.elem(ItemStackFactory.Instance.GetName(block.getType(), (byte) 0, false)) + ".")); return; } @@ -1560,26 +1632,30 @@ public class HideSeek extends TeamGame public void InfectDamageShuffleUp(CustomDamageEvent event) { if (!IsLive()) - return; - - if (event.GetDamageePlayer() == null) { - if (event.GetDamageeEntity().getPassenger() != null - && event.GetDamageeEntity().getPassenger() instanceof LivingEntity) - { - LivingEntity passenger = (LivingEntity) event.GetDamageeEntity().getPassenger(); + return; + } - // Leave - event.GetDamageeEntity().eject(); - passenger.leaveVehicle(); + LivingEntity damagee = event.GetDamageeEntity(); - // End - InfestEnd(passenger); + if (damagee instanceof Player && IsInfesting(damagee)) + { + InfestEnd(event.GetDamageeEntity()); + } - // Damage Event - Manager.GetDamage().NewDamageEvent(passenger, event.GetDamagerEntity(true), null, DamageCause.CUSTOM, 4, true, - true, false, UtilEnt.getName(event.GetDamagerEntity(true)), null); - } + if (damagee.getPassenger() != null && damagee.getPassenger() instanceof Player) + { + LivingEntity passenger = (LivingEntity) damagee.getPassenger(); + + // Leave + damagee.eject(); + passenger.leaveVehicle(); + + // End + InfestEnd(passenger); + + // Damage Event + Manager.GetDamage().NewDamageEvent(passenger, event.GetDamagerEntity(true), null, DamageCause.CUSTOM, 4, true, true, false, UtilEnt.getName(event.GetDamagerEntity(true)), null); } } @@ -1606,20 +1682,13 @@ public class HideSeek extends TeamGame } } - @EventHandler - public void InfestLeave(VehicleExitEvent event) - { - if (!IsLive()) - return; - - InfestEnd(event.getExited()); - } - @EventHandler public void InfestLeave(UpdateEvent event) { - if (event.getType() != UpdateType.TICK) + if (event.getType() != UpdateType.TICK || !IsLive()) + { return; + } // Block Leave Iterator infestIterator = _infested.keySet().iterator(); @@ -1650,25 +1719,30 @@ public class HideSeek extends TeamGame } } - // Invisible - for (Player player : GetPlayers(true)) + for (Player player : _hiders.GetPlayers(true)) { - if (!(GetKit(player) instanceof KitHiderInfestor)) + if (!_infestDeny.contains(player) || _infested.containsKey(player) || player.getVehicle() != null) + { continue; + } - if (_infested.containsKey(player) || player.getVehicle() != null) - Manager.GetCondition().Factory().Cloak("Infest", player, player, 1.9, false, false); + InfestEnd(player); } } public void InfestStart(LivingEntity ent) { - UtilParticle.PlayParticle(ParticleType.SLIME, ent.getLocation().add(0, 0.6, 0), 0.3f, 0.3f, 0.3f, 0, 24, - ViewDist.MAX, UtilServer.getPlayers()); - ent.getWorld().playSound(ent.getLocation(), Sound.SLIME_ATTACK, 2f, 1f); + UtilParticle.PlayParticleToAll(ParticleType.SLIME, ent.getLocation().add(0, 0.6, 0), 0.3f, 0.3f, 0.3f, 0, 24, ViewDist.NORMAL); ent.getWorld().playSound(ent.getLocation(), Sound.SLIME_ATTACK, 2f, 1f); + ent.getWorld().playSound(ent.getLocation(), Sound.SLIME_ATTACK, 2f, 1.2f); - Manager.GetCondition().Factory().Cloak("Infest", ent, ent, 1.9, false, false); + DisguiseBase disguise = Manager.GetDisguise().getActiveDisguise(ent); + + if (disguise != null && disguise instanceof DisguiseLiving) + { + ((DisguiseLiving) disguise).setInvisible(true); + Manager.GetDisguise().updateDisguise(disguise); + } // Gets rid of timer, not needed until end Recharge.Instance.recharge((Player) ent, "Infest"); @@ -1678,8 +1752,15 @@ public class HideSeek extends TeamGame public void InfestEnd(LivingEntity ent) { - Manager.GetCondition().EndCondition(ent, null, "Infest"); + DisguiseBase disguise = Manager.GetDisguise().getActiveDisguise(ent); + if (disguise != null && disguise instanceof DisguiseLiving) + { + ((DisguiseLiving) disguise).setInvisible(false); + Manager.GetDisguise().updateDisguise(disguise); + } + + ent.leaveVehicle(); ent.getWorld().playSound(ent.getLocation(), Sound.SLIME_ATTACK, 2f, 0.6f); if (ent instanceof Player) @@ -1692,10 +1773,20 @@ public class HideSeek extends TeamGame public boolean IsInfesting(LivingEntity ent) { - if (_infested.containsKey(ent)) - return true; + return _infested.containsKey(ent) || ent.getVehicle() != null; + } - return ent.getVehicle() != null; + @Override + public void disqualify(Player player) + { + Form form = _forms.remove(player); + + if (form != null) + { + form.Remove(); + } + + super.disqualify(player); } public HashMap getForms() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/forms/BlockForm.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/forms/BlockForm.java index f0cee8975..4108ba791 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/forms/BlockForm.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/forms/BlockForm.java @@ -2,30 +2,16 @@ package nautilus.game.arcade.game.games.hideseek.forms; import java.util.UUID; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilInv; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.disguise.disguises.DisguiseCat; -import mineplex.core.disguise.disguises.DisguiseChicken; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.recharge.Recharge; -import nautilus.game.arcade.game.games.hideseek.HideSeek; -import nautilus.game.arcade.game.games.hideseek.kits.KitHiderQuick; import net.minecraft.server.v1_8_R3.DataWatcher; import net.minecraft.server.v1_8_R3.Entity; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.EntityTrackerEntry; import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.PacketPlayOutAttachEntity; -import net.minecraft.server.v1_8_R3.PacketPlayOutNewAttachEntity; import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMove; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; +import net.minecraft.server.v1_8_R3.PacketPlayOutNewAttachEntity; import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_8_R3.WorldServer; @@ -38,20 +24,32 @@ import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFallingSand; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.EntityType; -import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.disguise.disguises.DisguiseCat; +import mineplex.core.disguise.disguises.DisguiseChicken; +import mineplex.core.itemstack.ItemStackFactory; + +import nautilus.game.arcade.game.games.hideseek.HideSeek; +import nautilus.game.arcade.game.games.hideseek.kits.KitHiderQuick; + public class BlockForm extends Form { private Material _mat; private Block _block; - private int _entityId; private Location _loc; private int _fakeSilverfishId; @@ -70,15 +68,21 @@ public class BlockForm extends Form _fakeBlockId = UtilEnt.getNewEntityId(); System.out.println("Block Form: " + _mat + " " + _mat.getId()); } - + @Override public void Apply() { // Remove Old if (Player.getPassenger() != null) { - Player.getPassenger().remove(); Player.eject(); + Player.getPassenger().remove(); + } + + // If a player is in a cauldron and morphs they get stuck in it + if (Player.getLocation().getBlock().getType() == Material.CAULDRON) + { + Player.teleport(Player.getEyeLocation()); } EntityPlayer player = ((CraftPlayer) Player).getHandle(); @@ -115,9 +119,9 @@ public class BlockForm extends Form if (UtilPlayer.is1_9(Player)) { packets[2] = new PacketPlayOutNewAttachEntity(_fakeSilverfishId, new int[] - { - _fakeBlockId - }); + { + _fakeBlockId + }); } else @@ -144,7 +148,7 @@ public class BlockForm extends Form + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false) + " Block") + "!")); else UtilPlayer.message(Player, F.main("Game", - C.cWhite + "You are now a " + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false)) + "!")); + C.cWhite + "You are now a " + blockName + "!")); // Give Item Player.getInventory().setItem(8, new ItemStack(Host.GetItemEquivilent(_mat))); @@ -167,10 +171,10 @@ public class BlockForm extends Form if (is19) { packets[1] = new PacketPlayOutNewAttachEntity(Player.getEntityId(), new int[] - { - _blockId + { + _blockId - }); + }); } else { @@ -197,11 +201,18 @@ public class BlockForm extends Form Host.Manager.GetDisguise().undisguise(Player); UtilPlayer.sendPacket(Player, new PacketPlayOutEntityDestroy(new int[] - { - _fakeSilverfishId, - _fakeBlockId, - _blockId - })); + { + _fakeSilverfishId, + _fakeBlockId, + _blockId + })); + + Packet destroyPacket = new PacketPlayOutEntityDestroy(new int[]{getBlockId()}); + + for (Player player : Player.getWorld().getPlayers()) + { + UtilPlayer.sendPacket(player, destroyPacket); + } ((CraftEntity) Player).getHandle().getDataWatcher().watch(0, (byte) 0, Entity.META_ENTITYDATA, (byte) 0); } @@ -236,7 +247,7 @@ public class BlockForm extends Form Block block = Player.getLocation().getBlock(); // Not Able - if (block.getType() != Material.AIR || !UtilBlock.solid(block.getRelative(BlockFace.DOWN))) + if (block.getType() != Material.AIR || !UtilBlock.solid(block.getRelative(BlockFace.DOWN)) || UtilEnt.getPlayersInsideEntity(Player).size() > 1) { UtilPlayer.message(Player, F.main("Game", "You cannot become a Solid Block here.")); Player.setExp(0f); @@ -286,9 +297,9 @@ public class BlockForm extends Form for (Player player : UtilServer.getPlayers()) { UtilPlayer.sendPacket(player, new PacketPlayOutEntityDestroy(new int[] - { - getBlockId() - })); + { + getBlockId() + })); } } } @@ -432,9 +443,4 @@ public class BlockForm extends Form { return _block; } - - public int getEntityId() - { - return _entityId; - } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/kits/KitHiderInfestor.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/kits/KitHiderInfestor.java index 49b91020c..fb0e5d0f9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/kits/KitHiderInfestor.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/kits/KitHiderInfestor.java @@ -34,7 +34,6 @@ public class KitHiderInfestor extends Kit DisguiseSlime slime = new DisguiseSlime(player); slime.SetSize(2); - slime.setName(C.cAqua + player.getName()); Manager.GetDisguise().disguise(slime); } }