diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/spleef/Spleef.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/spleef/Spleef.java index 0651b6dca..04f20a701 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/spleef/Spleef.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/spleef/Spleef.java @@ -1,26 +1,22 @@ package nautilus.game.arcade.game.games.spleef; -import java.lang.reflect.Field; - -import nautilus.game.arcade.game.games.spleef.kits.*; - import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArrow; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.entity.Snowball; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.ProjectileHitEvent; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; @@ -28,35 +24,37 @@ import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; + import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.game.SoloGame; +import nautilus.game.arcade.game.games.spleef.kits.KitArcher; +import nautilus.game.arcade.game.games.spleef.kits.KitBrawler; +import nautilus.game.arcade.game.games.spleef.kits.KitSnowballer; import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.managers.chat.ChatStatData; import nautilus.game.arcade.stats.SpleefBlockDestroyStatTracker; -import net.minecraft.server.v1_8_R3.EntityArrow; - public class Spleef extends SoloGame { - public Spleef(ArcadeManager manager) + public Spleef(ArcadeManager manager) { super(manager, GameType.Spleef, new Kit[] { - new KitSnowballer(manager), - new KitBrawler(manager), - new KitArcher(manager) + new KitSnowballer(manager), + new KitBrawler(manager), + new KitArcher(manager) }, - new String[] - { - "Punch blocks to break them!", - "1 Hunger per block smashed!", - "Last player alive wins!" - }); + new String[] + { + "Punch blocks to break them!", + "1 Hunger per block smashed!", + "Last player alive wins!" + }); this.DamagePvP = false; this.WorldWaterDamage = 4; @@ -84,32 +82,31 @@ public class Spleef extends SoloGame @EventHandler public void SnowballDamage(ProjectileHitEvent event) { - if (!IsLive()) + if (!IsLive() || !(event.getEntity() instanceof Snowball)) + { return; + } - if (!(event.getEntity() instanceof Snowball)) - return; + Snowball ball = (Snowball) event.getEntity(); - Snowball ball = (Snowball)event.getEntity(); - if (ball.getShooter() == null || !(ball.getShooter() instanceof Player)) return; - + Location loc = ball.getLocation().add(ball.getVelocity().multiply(0.8)); - + Block block = loc.getBlock(); - + //Find Nearest if hit nothing :O if (block.getType() == Material.AIR) { Block closest = null; double closestDist = 0; - + for (Block other : UtilBlock.getSurrounding(block, true)) { if (other.getType() == Material.AIR) continue; - + double dist = UtilMath.offset(loc, other.getLocation().add(0.5, 0.5, 0.5)); if (closest == null || dist < closestDist) @@ -118,66 +115,44 @@ public class Spleef extends SoloGame closestDist = dist; } } - + if (closest != null) block = closest; } - BlockFade(block, (Player)ball.getShooter(), false); + BlockFade(block, (Player) ball.getShooter(), false); } @EventHandler public void ArrowDamage(ProjectileHitEvent event) { - if (!(event.getEntity() instanceof Arrow)) + if (!IsLive() || !(event.getEntity() instanceof Arrow)) + { return; + } - final Arrow arrow = (Arrow)event.getEntity(); + final Arrow arrow = (Arrow) event.getEntity(); final double velocity = arrow.getVelocity().length(); if (!(arrow.getShooter() instanceof Player)) return; - final Player player = (Player)arrow.getShooter(); + final Player player = (Player) arrow.getShooter(); - Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + Manager.runSyncLater(() -> { - public void run() + Block block = UtilEnt.getHitBlock(arrow); + + double radius = 0.5 + velocity / 1.6d; + + BlockFade(block, player, false); + + 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 = 0.5 + velocity/1.6d; - - BlockFade(block, player, false); - - for (Block other : UtilBlock.getInRadius(block.getLocation().add(0.5, 0.5, 0.5), radius).keySet()) - { - BlockFade(other, player, true); - } - - arrow.remove(); - } - catch (Exception e) - { - e.printStackTrace(); - } + BlockFade(other, player, true); } + + arrow.remove(); }, 0); } @@ -194,20 +169,20 @@ public class Spleef extends SoloGame if (event.getBlock().getType() == Material.BEDROCK) return; - + BlockFade(event.getBlock(), event.getPlayer(), false); //Snowball if (GetKit(event.getPlayer()) instanceof KitSnowballer && event.getBlock().getType() != Material.BEDROCK) - if (!UtilInv.contains(event.getPlayer(), Material.SNOW_BALL, (byte)0, 16)) + if (!UtilInv.contains(event.getPlayer(), Material.SNOW_BALL, (byte) 0, 16)) event.getPlayer().getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.SNOW_BALL)); } public void BlockFade(Block block, Player player, boolean slowDamage) { - if (block.getType() == Material.BEDROCK || block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) + if (block.getType() == Material.BEDROCK || block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) return; - + //Prevent Super Hunger from Bow if (Recharge.Instance.use(player, GetName() + " Hunger", 50, false, false)) UtilPlayer.hunger(player, 1); @@ -223,11 +198,11 @@ public class Spleef extends SoloGame { //Greens if (block.getData() == 5 || block.getData() == 13) - block.setData((byte)4); + block.setData((byte) 4); - //Yellow + //Yellow else if (block.getData() == 4) - block.setData((byte)14); + block.setData((byte) 14); else Break(block, player); @@ -243,7 +218,7 @@ public class Spleef extends SoloGame else if (block.getTypeId() == 98) { if (block.getData() == 0 || block.getData() == 1) - block.setData((byte)2); + block.setData((byte) 2); else Break(block, player); @@ -259,10 +234,10 @@ public class Spleef extends SoloGame else if (block.getTypeId() == 5) { if (block.getData() == 1) - block.setData((byte)0); + block.setData((byte) 0); else if (block.getData() == 0) - block.setData((byte)2); + block.setData((byte) 2); else Break(block, player); @@ -296,7 +271,7 @@ public class Spleef extends SoloGame { if (player.getFoodLevel() <= 0) { - Manager.GetDamage().NewDamageEvent(player, null, null, + Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.STARVATION, 1, false, true, false, "Starvation", GetName());