Prevent power-up message spam when player is fully powered-up

This commit is contained in:
CoderTim 2014-07-21 17:26:45 -04:00
parent 4460f2e651
commit a6a274069c

View File

@ -22,6 +22,7 @@ public class PowerUpManager implements Listener
private final List<PowerUp> _powerUps = new ArrayList<>();
private Location _lastLocation = null;
private int _nextSpawnCountdown = -1;
private final Map<UUID, PowerUp> _powerUpPickUpCooldown = new HashMap<>();
public PowerUpManager(Game game, Random random, List<Location> spawnLocations)
{
@ -156,11 +157,28 @@ public class PowerUpManager implements Listener
{
event.setCancelled(true);
if (powerUp.powerUpPlayer(event.getPlayer()))
if (_powerUpPickUpCooldown.get(event.getPlayer().getUniqueId()) != powerUp)
{
powerUp.remove();
if (powerUp.powerUpPlayer(event.getPlayer()))
{
powerUp.remove();
schedulePowerUpSpawn(10);
schedulePowerUpSpawn(10);
}
else
{
_powerUpPickUpCooldown.put(event.getPlayer().getUniqueId(), powerUp);
Bukkit.getScheduler().runTaskLater(getPlugin(), new Runnable()
{
@Override
public void run()
{
if (_powerUpPickUpCooldown.get(event.getPlayer().getUniqueId()) == powerUp)
_powerUpPickUpCooldown.remove(event.getPlayer().getUniqueId());
}
}, 2000);
}
}
}
}