Fixed the Minestrike multiple grenades bug.

This commit is contained in:
Mysticate 2015-10-08 18:41:40 -04:00
parent ef62fb5adf
commit 979e68dcc7

View File

@ -17,6 +17,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import nautilus.game.arcade.game.games.minestrike.MineStrike;
import nautilus.game.arcade.game.games.minestrike.items.StrikeItem;
@ -82,52 +83,47 @@ public abstract class Grenade extends StrikeItem
}
public boolean giveToPlayer(Player player, boolean setOwnerName)
{
int slot = 3;
{
int alreadyHas = 0;
int bestSlot = -1;
while (player.getInventory().getItem(slot) != null && player.getInventory().getItem(slot).getType() != Material.AIR && slot <= 6)
for (int i = 3 ; i < 7 ; i++)
{
if (player.getInventory().getItem(slot).getType() == getSkin())
{
if (UtilInv.IsItem(player.getInventory().getItem(i), getSkin(), (byte) -1))
alreadyHas++;
if (alreadyHas >= _limit)
return false;
}
slot++;
if (alreadyHas >= _limit)
return false;
if ((player.getInventory().getItem(i) == null || UtilInv.IsItem(player.getInventory().getItem(i), Material.AIR, (byte) -1)) && bestSlot == -1)
bestSlot = i;
}
if (slot > 6)
if (bestSlot == -1 || bestSlot > 6)
return false;
giveToPlayer(player, slot, setOwnerName);
giveToPlayer(player, bestSlot, setOwnerName);
return true;
}
public boolean canGiveToPlayer(Player player)
{
int slot = 3;
{
int alreadyHas = 0;
int bestSlot = -1;
while (player.getInventory().getItem(slot) != null && player.getInventory().getItem(slot).getType() != Material.AIR && slot <= 6)
for (int i = 3 ; i < 7 ; i++)
{
if (player.getInventory().getItem(slot).getType() == getSkin())
{
if (UtilInv.IsItem(player.getInventory().getItem(i), getSkin(), (byte) -1))
alreadyHas++;
if (alreadyHas >= _limit)
return false;
}
slot++;
if (alreadyHas >= _limit)
return false;
if ((player.getInventory().getItem(i) == null || UtilInv.IsItem(player.getInventory().getItem(i), Material.AIR, (byte) -1)) && bestSlot == -1)
bestSlot = i;
}
if (slot > 6)
if (bestSlot == -1 || bestSlot > 6)
return false;
return true;