Search in sources :

Example 1 with SimpleRollbackEntry

use of uk.co.oliwali.HawkEye.entry.SimpleRollbackEntry in project HawkEye by oliverwoodings.

the class MonitorPlayerListener method onPlayerInteract.

/**
 * Handles several actions:
 * OPEN_CHEST, DOOR_INTERACT, LEVER, STONE_BUTTON, FLINT_AND_STEEL, LAVA_BUCKET, WATER_BUCKET
 */
@HawkEvent(dataType = { DataType.OPEN_CONTAINER, DataType.DOOR_INTERACT, DataType.LEVER, DataType.STONE_BUTTON, DataType.LAVA_BUCKET, DataType.WATER_BUCKET })
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    // Check for inventory close
    HawkEye.containerManager.checkInventoryClose(player);
    if (block != null) {
        Location loc = block.getLocation();
        switch(block.getType()) {
            case FURNACE:
            case DISPENSER:
            case CHEST:
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                    // Call container manager for inventory open
                    HawkEye.containerManager.checkInventoryOpen(player, block);
                    DataManager.addEntry(new DataEntry(player, DataType.OPEN_CONTAINER, loc, Integer.toString(block.getTypeId())));
                }
                break;
            case WOODEN_DOOR:
            case TRAP_DOOR:
            case FENCE_GATE:
                DataManager.addEntry(new DataEntry(player, DataType.DOOR_INTERACT, loc, ""));
                break;
            case LEVER:
                DataManager.addEntry(new DataEntry(player, DataType.LEVER, loc, ""));
                break;
            case STONE_BUTTON:
                DataManager.addEntry(new DataEntry(player, DataType.STONE_BUTTON, loc, ""));
                break;
        }
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            loc = block.getRelative(event.getBlockFace()).getLocation();
            switch(player.getItemInHand().getType()) {
                case FLINT_AND_STEEL:
                    DataManager.addEntry(new SimpleRollbackEntry(player, DataType.FLINT_AND_STEEL, loc, ""));
                    break;
                case LAVA_BUCKET:
                    DataManager.addEntry(new SimpleRollbackEntry(player, DataType.LAVA_BUCKET, loc, ""));
                    break;
                case WATER_BUCKET:
                    DataManager.addEntry(new SimpleRollbackEntry(player, DataType.WATER_BUCKET, loc, ""));
                    break;
            }
        }
    }
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) Location(org.bukkit.Location) SimpleRollbackEntry(uk.co.oliwali.HawkEye.entry.SimpleRollbackEntry) HawkEvent(uk.co.oliwali.HawkEye.HawkEvent)

Aggregations

Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 Player (org.bukkit.entity.Player)1 HawkEvent (uk.co.oliwali.HawkEye.HawkEvent)1 DataEntry (uk.co.oliwali.HawkEye.entry.DataEntry)1 SimpleRollbackEntry (uk.co.oliwali.HawkEye.entry.SimpleRollbackEntry)1