Fix bridges and skywars lagging during the pregame lobby

This commit is contained in:
Sam 2018-01-14 15:22:53 +00:00 committed by Alexander Meech
parent edc1f5a9fd
commit 42ae60c894

View File

@ -1,23 +1,29 @@
package nautilus.game.arcade.stats;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import nautilus.game.arcade.game.Game;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.CombatComponent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import nautilus.game.arcade.game.Game;
public class DeathBomberStatTracker extends StatTracker<Game>
{
private int _required;
private final int _required;
private final Map<UUID, Integer> _killCount = new HashMap<>();
public DeathBomberStatTracker(Game game, int requiredKills)
@ -30,29 +36,39 @@ public class DeathBomberStatTracker extends StatTracker<Game>
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onCombatDeath(CombatDeathEvent event)
{
if (getGame().GetState() != Game.GameState.Live)
if (!getGame().IsLive())
{
return;
}
if (event.GetLog().GetKiller() == null)
CombatComponent killerComp = event.GetLog().GetKiller();;
if (killerComp == null || !killerComp.IsPlayer())
{
return;
}
if (!event.GetLog().GetKiller().IsPlayer())
return;
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
Player killer = UtilPlayer.searchExact(killerComp.GetName());
if (killer == null)
{
return;
}
if (event.GetLog().GetPlayer() == null)
return;
if (!event.GetLog().GetPlayer().IsPlayer())
if (event.GetLog().GetPlayer() == null || !event.GetLog().GetPlayer().IsPlayer())
{
return;
}
Player killed = UtilPlayer.searchExact(event.GetLog().GetPlayer().GetName());
if(killer.equals(killed))
{
return;
}
if (event.GetLog().GetKiller() != null && event.GetLog().GetKiller().GetReason().contains("Throwing TNT"))
{
@ -61,38 +77,53 @@ public class DeathBomberStatTracker extends StatTracker<Game>
count = (count == null ? 0 : count) + 1;
System.out.println("Death Bomber: " + killer.getName() + " " + count);
_killCount.put(killer.getUniqueId(), count);
if (count >= _required)
{
addStat(killer, "DeathBomber", 1, true, false);
}
}
}
@EventHandler
public void removeFakeThrowingTNT(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
if (event.getType() != UpdateType.FAST || !getGame().IsLive())
{
return;
}
for (Player player : getGame().GetPlayers(true))
{
ItemStack[] contents = player.getInventory().getContents();
int i = 0;
Inventory inventory = player.getInventory();
ItemStack[] contents = inventory.getContents();
for (ItemStack itemStack : contents)
for (int i = 0; i < contents.length; i++)
{
if (itemStack == null || itemStack.getItemMeta() == null || itemStack.getItemMeta().getDisplayName() == null)
ItemStack itemStack = contents[i];
if (itemStack == null || itemStack.getType() == Material.TNT)
{
continue;
}
if (itemStack.getItemMeta().getDisplayName().contains("Throwing TNT") && itemStack.getType() != Material.TNT)
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null || itemMeta.getDisplayName() == null)
{
player.getInventory().setItem(i, null);
continue;
}
String displayName = itemMeta.getDisplayName();
if (displayName == null || !displayName.contains("Throwing TNT"))
{
continue;
}
inventory.setItem(i, null);
}
}
}