Fix spleef breaking blocks in the lobby

This commit is contained in:
Sam 2018-04-19 13:25:33 +01:00 committed by Alexander Meech
parent 6731b5f3ab
commit 5985d5ef99

View File

@ -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,16 +24,18 @@ 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)
@ -84,13 +82,12 @@ 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;
@ -123,46 +120,30 @@ public class Spleef extends SoloGame
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()
{
try
{
EntityArrow entityArrow = ((CraftArrow)arrow).getHandle();
Block block = UtilEnt.getHitBlock(arrow);
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;
double radius = 0.5 + velocity / 1.6d;
BlockFade(block, player, false);
@ -172,12 +153,6 @@ public class Spleef extends SoloGame
}
arrow.remove();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}, 0);
}
@ -199,7 +174,7 @@ public class Spleef extends SoloGame
//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));
}
@ -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
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);