diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index 341de3aa3..fae1c0792 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -27,6 +27,7 @@ import org.bukkit.block.Jukebox; import org.bukkit.block.Skull; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; +import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.SkullMeta; diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java index ec1d0571f..582f76f7f 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java @@ -54,6 +54,8 @@ import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; +import mineplex.core.common.Pair; + public class UtilEnt { public static final String FLAG_NO_REMOVE = "noremove"; @@ -1130,4 +1132,47 @@ public class UtilEnt { ((CraftEntity) entity).getHandle().setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); } + + public static Pair getSideStandingBox(Entity entity) + { + Location location = entity.getLocation(); + + double xMod = location.getX() % 1; + double zMod = location.getZ() % 1; + + if (location.getX() < 0) + { + xMod += 1; + } + + if (location.getZ() < 0) + { + zMod += 1; + } + + int xMin = 0; + int xMax = 0; + int zMin = 0; + int zMax = 0; + + if (xMod < 0.3) + { + xMin = -1; + } + else if (xMod > 0.7) + { + xMax = 1; + } + + if (zMod < 0.3) + { + zMin = -1; + } + else if (zMod > 0.7) + { + zMax = 1; + } + + return Pair.create(new Location(location.getWorld(), xMin, 0, zMin), new Location(location.getWorld(), xMax, 0, zMax)); + } } \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 228fb8c73..bfa8d1428 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -72,7 +72,6 @@ import nautilus.game.arcade.game.games.quiver.modes.BunnyHop; import nautilus.game.arcade.game.games.quiver.modes.UltimateOITQ; import nautilus.game.arcade.game.games.rings.ElytraRings; import nautilus.game.arcade.game.games.runner.Runner; -import nautilus.game.arcade.game.games.runner.modes.FasterThanLight; import nautilus.game.arcade.game.games.sheep.SheepGame; import nautilus.game.arcade.game.games.sheep.modes.EweHeroes; import nautilus.game.arcade.game.games.sheep.modes.OverpoweredSheepQuest; @@ -255,8 +254,7 @@ public enum GameType new GameMode(SheepMania.class, GameType.Sheep, "Sheep Mania"), new GameMode(SmashSheep.class, GameType.Sheep, "Smash Sheep"), new GameMode(OverpoweredSheepQuest.class, GameType.Sheep, "OP Sheep Quest"), - new GameMode(FasterThanLight.class, GameType.Runner, "Faster Than Light"), - new GameMode(BunnyHop.class, GameType.Quiver, "Bunny Hop"), + new GameMode(BunnyHop.class, GameType.Quiver, "Bunny Hop"), new GameMode(UltimateOITQ.class, GameType.Quiver, "Ultimate OITQ"), new GameMode(Countdown.class, GameType.HideSeek, "Countdown"), new GameMode(SmashDom.class, GameType.ChampionsDominate, "Smash Dominate"), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java index df1f1afee..6d5aaf6c3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java @@ -80,6 +80,7 @@ public class Micro extends TeamGame .register(this); new MapCrumbleModule() + .setRate(3) .register(this); registerStatTrackers( diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/runner/Runner.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/runner/Runner.java index e6c375ee8..20318f535 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/runner/Runner.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/runner/Runner.java @@ -1,17 +1,13 @@ package nautilus.game.arcade.game.games.runner; -import java.lang.reflect.Field; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; - -import net.minecraft.server.v1_8_R3.EntityArrow; +import java.util.Map; import org.bukkit.Effect; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArrow; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.FallingBlock; @@ -28,8 +24,12 @@ import com.mineplex.anticheat.checks.move.Speed; import mineplex.core.Managers; import mineplex.core.antihack.AntiHack; +import mineplex.core.common.Pair; +import mineplex.core.common.util.C; import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; import mineplex.core.projectile.IThrown; import mineplex.core.projectile.ProjectileUser; @@ -49,325 +49,173 @@ import nautilus.game.arcade.stats.DistanceTraveledStatTracker; public class Runner extends SoloGame implements IThrown { - private HashMap _blocks = new HashMap(); - - public Runner(ArcadeManager manager) + + private static final String[] DESCRIPTION = + { + C.cGreen + "Blocks Fall" + C.Reset + " from underneath you.", + C.cAqua + "Keep Running" + C.Reset + " to stay alive.", + "Avoid " + C.cRed + "Falling Blocks" + C.Reset + " from above.", + C.cYellow + "Last Player" + C.Reset + " alive wins!" + }; + private static final long BLOCK_DECAY = 600; + private static final long BLOCK_LIFETIME = 1200; + + private final Map _blocks = new HashMap<>(); + + public Runner(ArcadeManager manager) { - this(manager, GameType.Runner); + super(manager, GameType.Runner, new Kit[] + { + new KitLeaper(manager), + new KitArcher(manager), + new KitFrosty(manager) + }, DESCRIPTION); - registerStatTrackers(new DistanceTraveledStatTracker(this, "MarathonRunner")); - - registerChatStats( - new ChatStatData("MarathonRunner", "Distance ran", true), - BlankLine, - new ChatStatData("kit", "Kit", true) - ); - } - - public Runner(ArcadeManager manager, GameType type) - { - super(manager, type, - - new Kit[] - { - new KitLeaper(manager), - new KitArcher(manager), - new KitFrosty(manager) - }, - - new String[] - { - "Blocks fall from underneath you", - "Keep running to stay alive", - "Avoid falling blocks from above", - "Last player alive wins!" - }); - - this.DamagePvP = false; - this.HungerSet = 20; - this.WorldWaterDamage = 4; - - this.PrepareFreeze = false; + DamagePvP = false; + HungerSet = 20; + WorldWaterDamage = 4; + PrepareFreeze = false; new CompassModule() - .setGiveCompass(true) - .setGiveCompassToSpecs(true) - .setGiveCompassToAlive(false) .register(this); - - this.GlideCheckEnabled = false; + + registerStatTrackers( + new DistanceTraveledStatTracker(this, "MarathonRunner") + ); + + registerChatStats( + new ChatStatData("MarathonRunner", "Distance ran", true) + ); + + GlideCheckEnabled = false; AntiHack antiHack = Managers.get(AntiHack.class); antiHack.addIgnoredCheck(Speed.class); antiHack.addIgnoredCheck(Glide.class); antiHack.addIgnoredCheck(HeadRoll.class); } - + @EventHandler - public void ArrowDamage(ProjectileHitEvent event) + public void arrowDamage(ProjectileHitEvent event) { - if (!(event.getEntity() instanceof Arrow)) - return; - - final Arrow arrow = (Arrow)event.getEntity(); - - Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + Entity entity = event.getEntity(); + + if (!(entity instanceof Arrow) || !IsLive()) { - public void run() + return; + } + + Manager.runSyncLater(() -> + { + Block block = UtilEnt.getHitBlock(entity); + + double radius = 2.5; + + for (Block other : UtilBlock.getInRadius(block.getLocation().add(0.5, 0.5, 0.5), radius).keySet()) { - try - { - EntityArrow entityArrow = ((CraftArrow)arrow).getHandle(); - - Field fieldX = EntityArrow.class.getDeclaredField("d"); - Field fieldY = EntityArrow.class.getDeclaredField("e"); - Field fieldZ = EntityArrow.class.getDeclaredField("f"); - - fieldX.setAccessible(true); - fieldY.setAccessible(true); - fieldZ.setAccessible(true); - - int x = fieldX.getInt(entityArrow); - int y = fieldY.getInt(entityArrow); - int z = fieldZ.getInt(entityArrow); - - Block block = arrow.getWorld().getBlockAt(x, y, z); - - double radius = 2.5; - - for (Block other : UtilBlock.getInRadius(block.getLocation().add(0.5, 0.5, 0.5), radius).keySet()) - { - AddBlock(other); - } - - arrow.remove(); - } - catch (Exception e) - { - e.printStackTrace(); - } + addBlock(other); } + + entity.remove(); }, 0); } - - public void AddBlock(Block block) + + private void addBlock(Block block) { - if (block == null || block.getTypeId() == 0 || block.getTypeId() == 7 || block.isLiquid()) + if (block == null || block.getType() == Material.AIR || block.getType() == Material.BEDROCK || block.isLiquid() || block.getRelative(BlockFace.UP).getTypeId() != 0 || _blocks.containsKey(block)) + { return; - - if (block.getRelative(BlockFace.UP).getTypeId() != 0) - return; - - if (_blocks.containsKey(block)) - return; - + } + _blocks.put(block, System.currentTimeMillis()); - - block.setTypeIdAndData(159, (byte) 14, false); + MapUtil.QuickChangeBlockAt(block.getLocation(), Material.STAINED_CLAY, (byte) 14); } - + @EventHandler - public void BlockBreak(UpdateEvent event) + public void blockBreak(UpdateEvent event) { - if (event.getType() != UpdateType.TICK) + if (event.getType() != UpdateType.TICK || !IsLive()) + { return; - - if (!IsLive()) - return; - - //Add Blocks + } + for (Player player : GetPlayers(true)) { - //Side Standing - double xMod = player.getLocation().getX() % 1; - if (player.getLocation().getX() < 0) - xMod += 1; - - double zMod = player.getLocation().getZ() % 1; - if (player.getLocation().getZ() < 0) - zMod += 1; - - int xMin = 0; - int xMax = 0; - int zMin = 0; - int zMax = 0; - - if (xMod < 0.3) xMin = -1; - if (xMod > 0.7) xMax = 1; - - if (zMod < 0.3) zMin = -1; - if (zMod > 0.7) zMax = 1; + Pair box = UtilEnt.getSideStandingBox(player); + Location min = box.getLeft(), max = box.getRight(); - for (int x=xMin ; x<=xMax ; x++) + for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { - for (int z=zMin ; z<=zMax ; z++) + for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { - AddBlock(player.getLocation().add(x, -0.5, z).getBlock()); - } + addBlock(player.getLocation().add(x, -0.5, z).getBlock()); + } } } - - //Decay - HashSet readd = new HashSet(); - - Iterator blockIterator = _blocks.keySet().iterator(); - - while (blockIterator.hasNext()) + + _blocks.entrySet().removeIf(entry -> { - Block block = blockIterator.next(); - - if (!UtilTime.elapsed(_blocks.get(block), 600)) - continue; - - //Fall - int id = block.getTypeId(); - byte data = block.getData(); + Block block = entry.getKey(); + long time = entry.getValue(); + + if (!UtilTime.elapsed(time, BLOCK_DECAY)) + { + return false; + } + MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR); - FallingBlock ent = block.getWorld().spawnFallingBlock(block.getLocation(), id, data); - Manager.GetProjectile().AddThrow(ent, null, this, -1, true, false, false, false, 0.3f); - - blockIterator.remove(); - } -// -//// if (!UtilTime.elapsed(_blocks.get(block), 120)) -//// continue; -// -// blockIterator.remove(); -// -// //Degrade -// if (block.getTypeId() == 98) -// { -// if (block.getData() == 0) -// { -// readd.add(block); -// block.setData((byte)2); -// continue; -// } -// } -// -// //Degrade -// if (block.getTypeId() == 35 || block.getTypeId() == 159) -// { -// if (block.getData() == 3) -// { -// readd.add(block); -// block.setData((byte)5); -// continue; -// } -// -// if (block.getData() == 5) -// { -// readd.add(block); -// block.setData((byte)4); -// continue; -// } -// -// if (block.getData() == 4) -// { -// readd.add(block); -// block.setData((byte)1); -// continue; -// } -// -// if (block.getData() == 1) -// { -// readd.add(block); -// block.setData((byte)14); -// continue; -// } -// -// else if (block.getData() != 14) -// { -// readd.add(block); -// block.setData((byte)3); -// continue; -// } -// } -// -// //Fall -// int id = block.getTypeId(); -// byte data = block.getData(); -// MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR); -// FallingBlock ent = block.getWorld().spawnFallingBlock(block.getLocation(), id, data); -// Manager.GetProjectile().AddThrow(ent, null, this, -1, true, false, false, false, 1d); -// } -// -// //Re-add -// for (Block block : readd) -// { -// _blocks.put(block, System.currentTimeMillis()); -// } + FallingBlock ent = block.getWorld().spawnFallingBlock(block.getLocation(), Material.STAINED_CLAY, (byte) 14); + Manager.GetProjectile().AddThrow(ent, null, this, BLOCK_LIFETIME, true, false, false, false, 0.3F); + return true; + }); } - + @EventHandler - public void BlockForm(EntityChangeBlockEvent event) + public void blockForm(EntityChangeBlockEvent event) { - BlockSmash(event.getEntity()); - + blockSmash(event.getEntity()); event.setCancelled(true); } - public void BlockSmash(Entity ent) + private void blockSmash(Entity entity) { - if (!(ent instanceof FallingBlock)) - return; - - FallingBlock block = (FallingBlock)ent; - - int id = block.getBlockId(); - if (id == 35 || id == 159) - id = 152; - - block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, id); - - ent.remove(); - } - - - - @Override - public void Collide(LivingEntity target, Block block, ProjectileUser data) - { - if (target == null) - return; - - if (target instanceof Player) + if (!(entity instanceof FallingBlock)) { - if (!Manager.GetGame().IsAlive((Player)target)) - { - return; - } - - if (target.getLocation().getY() > data.getThrown().getLocation().getY() + 0.5) - { - return; - } + return; } - - //Damage Event - Manager.GetDamage().NewDamageEvent(target, data.getThrower(), null, - DamageCause.ENTITY_ATTACK, 6, true, true, false, - "Falling Block", "Falling Block"); - BlockSmash(data.getThrown()); - } - - public HashMap getBlocks() - { - return _blocks; + if (Math.random() < 0.3) + { + FallingBlock block = (FallingBlock) entity; + block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK); + } + + entity.remove(); } @Override - public void Idle(ProjectileUser data) + public void Collide(LivingEntity target, Block block, ProjectileUser data) + { + if (target == null || UtilPlayer.isSpectator(target) || target.getLocation().getY() > data.getThrown().getLocation().getY() + 0.5) + { + return; + } + + Manager.GetDamage().NewDamageEvent(target, data.getThrower(), null, DamageCause.ENTITY_ATTACK, 6, true, true, false, "Falling Block", "Falling Block"); + blockSmash(data.getThrown()); + } + + @Override + public void Idle(ProjectileUser data) { } @Override - public void Expire(ProjectileUser data) + public void Expire(ProjectileUser data) { - + data.getThrown().remove(); } - + @Override public void ChunkUnload(ProjectileUser data) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/runner/modes/FasterThanLight.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/runner/modes/FasterThanLight.java deleted file mode 100644 index 78abda817..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/runner/modes/FasterThanLight.java +++ /dev/null @@ -1,125 +0,0 @@ -package nautilus.game.arcade.game.games.runner.modes; - -import java.util.HashSet; -import java.util.Iterator; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilTime; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.game.games.runner.Runner; - -/** - * GottaGoFast gamemode for Runner - * - * @author xXVevzZXx - */ -public class FasterThanLight extends Runner -{ - - public FasterThanLight(ArcadeManager manager) - { - super(manager); - } - - @EventHandler - public void speed(UpdateEvent event) - { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.SEC) - return; - - for (Player player : GetPlayers(true)) - { - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 40, 2, true, true), - true); - } - } - - @Override - @EventHandler - public void BlockBreak(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) - return; - - if (!IsLive()) - return; - - //Add Blocks - for (Player player : GetPlayers(true)) - { - //Side Standing - double xMod = player.getLocation().getX() % 1; - if (player.getLocation().getX() < 0) - xMod += 1; - - double zMod = player.getLocation().getZ() % 1; - if (player.getLocation().getZ() < 0) - zMod += 1; - - int xMin = 0; - int xMax = 0; - int zMin = 0; - int zMax = 0; - - if (xMod < 0.3) - xMin = -1; - if (xMod > 0.7) - xMax = 1; - - if (zMod < 0.3) - zMin = -1; - if (zMod > 0.7) - zMax = 1; - - for (int x = xMin; x <= xMax; x++) - { - for (int z = zMin; z <= zMax; z++) - { - AddBlock(player.getLocation().add(x, -0.5, z).getBlock()); - } - } - } - - //Decay - HashSet readd = new HashSet(); - - Iterator blockIterator = getBlocks().keySet().iterator(); - - while (blockIterator.hasNext()) - { - Block block = blockIterator.next(); - - if (!UtilTime.elapsed(getBlocks().get(block), 200)) - continue; - - //Fall - int id = block.getTypeId(); - byte data = block.getData(); - MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR); - FallingBlock ent = block.getWorld().spawnFallingBlock(block.getLocation(), id, data); - Manager.GetProjectile().AddThrow(ent, null, this, -1, true, false, false, false, 0.3f); - - blockIterator.remove(); - } - } - - @Override - public String GetMode() - { - return "Faster Than Light"; - } - -}