Fix Zombie's Deaths Grasp hitting spectating players

This commit is contained in:
Sam 2017-05-01 14:26:41 +01:00
parent b89e3c4abc
commit 41b7e4bf38
3 changed files with 37 additions and 54 deletions

View File

@ -1,23 +1,11 @@
package nautilus.game.arcade.game.games.smash.kits; package nautilus.game.arcade.game.games.smash.kits;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilInv;
import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.disguise.disguises.DisguiseEnderman; import mineplex.core.disguise.disguises.DisguiseEnderman;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.smash.perks.PerkSmashStats; import nautilus.game.arcade.game.games.smash.perks.PerkSmashStats;
@ -31,6 +19,13 @@ import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkDoubleJump; import nautilus.game.arcade.kit.perks.PerkDoubleJump;
import nautilus.game.arcade.kit.perks.event.PerkBlockGrabEvent; import nautilus.game.arcade.kit.perks.event.PerkBlockGrabEvent;
import nautilus.game.arcade.kit.perks.event.PerkBlockThrowEvent; import nautilus.game.arcade.kit.perks.event.PerkBlockThrowEvent;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
public class KitEnderman extends SmashKit public class KitEnderman extends SmashKit
{ {
@ -82,8 +77,6 @@ public class KitEnderman extends SmashKit
}; };
public HashMap<Player, DisguiseEnderman> _disguises = new HashMap<Player, DisguiseEnderman>();
public KitEnderman(ArcadeManager manager) public KitEnderman(ArcadeManager manager)
{ {
super(manager, "Enderman", KitAvailability.Gem, 3000, PERKS, EntityType.ENDERMAN, IN_HAND, DisguiseEnderman.class); super(manager, "Enderman", KitAvailability.Gem, 3000, PERKS, EntityType.ENDERMAN, IN_HAND, DisguiseEnderman.class);
@ -94,8 +87,6 @@ public class KitEnderman extends SmashKit
{ {
disguise(player); disguise(player);
_disguises.put(player, (DisguiseEnderman) Manager.GetDisguise().getActiveDisguise(player));
UtilInv.Clear(player); UtilInv.Clear(player);
player.getInventory().addItem(PLAYER_ITEMS[0], PLAYER_ITEMS[1]); player.getInventory().addItem(PLAYER_ITEMS[0], PLAYER_ITEMS[1]);
@ -111,54 +102,45 @@ public class KitEnderman extends SmashKit
@EventHandler @EventHandler
public void BlockGrab(PerkBlockGrabEvent event) public void BlockGrab(PerkBlockGrabEvent event)
{ {
SetBlock(_disguises.get(event.GetPlayer()), event.GetId(), event.GetData()); setBlock(event.GetPlayer(), event.GetId(), event.GetData());
} }
@EventHandler @EventHandler
public void BlockThrow(PerkBlockThrowEvent event) public void BlockThrow(PerkBlockThrowEvent event)
{ {
SetBlock(_disguises.get(event.GetPlayer()), 0, (byte) 0); setBlock(event.GetPlayer(), 0, (byte) 0);
} }
@EventHandler @EventHandler
public void Death(PlayerDeathEvent event) public void Death(PlayerDeathEvent event)
{ {
SetBlock(_disguises.get(event.getEntity()), 0, (byte) 0); setBlock(event.getEntity(), 0, (byte) 0);
}
public void SetBlock(DisguiseEnderman disguise, int id, byte data)
{
if (disguise == null)
{
return;
}
disguise.SetCarriedId(id);
disguise.SetCarriedData(data);
Manager.GetDisguise().updateDisguise(disguise);
} }
@EventHandler @EventHandler
public void cleanDisguises(UpdateEvent event) public void damage(CustomDamageEvent event)
{ {
if (event.getType() != UpdateType.FAST) Player player = event.GetDamageePlayer();
DisguiseBase disguise = Manager.GetDisguise().getActiveDisguise(player);
if (player != null && disguise != null && disguise instanceof DisguiseEnderman)
{ {
return; // Endermen drop their held block when damaged. This means the client renders it this way, so we need to resend the correct data on the next tick.
Manager.runSyncLater(() -> Manager.GetDisguise().updateDisguise(disguise), 1);
}
} }
for (Iterator<Entry<Player, DisguiseEnderman>> iterator = _disguises.entrySet().iterator(); iterator.hasNext();) public void setBlock(Player player, int id, byte data)
{ {
Entry<Player, DisguiseEnderman> current = iterator.next(); DisguiseBase disguise = Manager.GetDisguise().getActiveDisguise(player);
if (!Manager.GetDisguise().isDisguised(current.getKey())) if (player != null && disguise != null && disguise instanceof DisguiseEnderman)
{ {
iterator.remove(); DisguiseEnderman disguiseEnderman = (DisguiseEnderman) disguise;
} disguiseEnderman.SetCarriedId(id);
else if (Manager.GetDisguise().getActiveDisguise(current.getKey()) != current.getValue()) disguiseEnderman.SetCarriedData(data);
{
iterator.remove(); Manager.GetDisguise().updateDisguise(disguiseEnderman);
}
} }
} }
} }

View File

@ -138,7 +138,8 @@ public class PerkCreeperExplode extends SmashPerk
UtilAction.zeroVelocity(player); UtilAction.zeroVelocity(player);
// Sound // Sound
player.getWorld().playSound(player.getLocation(), Sound.CREEPER_HISS, (float) (0.5 + elapsed), (float) (0.5 + elapsed)); float volume = (float) 0.5F + elapsed / 1000F;
player.getWorld().playSound(player.getLocation(), Sound.CREEPER_HISS, volume, volume);
IncreaseSize(player); IncreaseSize(player);

View File

@ -129,7 +129,7 @@ public class PerkDeathsGrasp extends Perk
List<Player> team = TeamSuperSmash.getTeam(Manager, player, true); List<Player> team = TeamSuperSmash.getTeam(Manager, player, true);
for (Player other : Manager.GetGame().GetPlayers(true)) for (Player other : Manager.GetGame().GetPlayers(true))
{ {
if(team.contains(other)) if(UtilPlayer.isSpectator(player) || team.contains(other))
{ {
continue; continue;
} }