Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/WinWithoutOpeningChestStatTracker.java

75 lines
1.7 KiB
Java
Raw Normal View History

2015-06-25 04:59:28 +02:00
package nautilus.game.arcade.stats;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
2015-07-20 04:38:03 +02:00
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
2015-06-25 04:59:28 +02:00
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
2015-06-26 09:05:29 +02:00
import org.bukkit.Material;
2015-06-25 04:59:28 +02:00
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
2015-06-26 09:05:29 +02:00
import org.bukkit.event.block.BlockBreakEvent;
2015-06-26 11:44:13 +02:00
import org.bukkit.event.player.PlayerInteractEvent;
2015-06-25 04:59:28 +02:00
public class WinWithoutOpeningChestStatTracker extends StatTracker<Game>
{
2015-07-20 04:38:03 +02:00
private final Set<Player> _openChest = new HashSet<Player>();
2015-06-25 04:59:28 +02:00
public WinWithoutOpeningChestStatTracker(Game game)
{
super(game);
}
2015-07-20 04:38:03 +02:00
@EventHandler(priority = EventPriority.HIGH)
2015-06-26 11:44:13 +02:00
public void onOpenChest(PlayerInteractEvent event)
{
2015-07-20 04:38:03 +02:00
if (event.isCancelled())
{
return;
}
if (UtilEvent.isAction(event, ActionType.R_BLOCK))
2015-06-26 11:44:13 +02:00
{
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.CHEST)
{
2015-07-20 04:38:03 +02:00
_openChest.add(event.getPlayer());
2015-06-26 11:44:13 +02:00
}
}
2015-06-25 04:59:28 +02:00
}
2015-06-26 09:05:29 +02:00
@EventHandler
public void onBreakChest(BlockBreakEvent event)
{
if (event.getBlock().getType() == Material.CHEST)
2015-07-20 04:38:03 +02:00
{
_openChest.add(event.getPlayer());
}
2015-06-26 09:05:29 +02:00
}
2015-07-20 04:38:03 +02:00
@EventHandler(priority = EventPriority.MONITOR)
2015-06-25 04:59:28 +02:00
public void onGameStateChange(GameStateChangeEvent event)
{
if (event.GetState() == Game.GameState.End)
{
List<Player> winners = getGame().getWinners();
if (winners != null)
{
for (Player winner : winners)
{
2015-07-20 04:38:03 +02:00
if (!_openChest.contains(winner))
{
2015-06-25 04:59:28 +02:00
addStat(winner, "NoChest", 1, true, false);
2015-07-20 04:38:03 +02:00
}
2015-06-25 04:59:28 +02:00
}
}
}
}
}