Search in sources :

Example 1 with Chest

use of org.bukkit.block.Chest in project Ublisk by Derkades.

the class PlayerInteract method tracker.

// ignoreCancelled = true - Still track clicks if they are cancelled
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void tracker(PlayerInteractEvent event) {
    UPlayer player = new UPlayer(event);
    Action action = event.getAction();
    if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
        player.tracker(PlayerInfo.RIGHT_CLICKED);
    }
    if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
        player.tracker(PlayerInfo.LEFT_CLICKED);
    }
    if (action == Action.RIGHT_CLICK_BLOCK) {
        if (event.getClickedBlock().getType() == Material.CHEST) {
            Chest chest = (Chest) event.getClickedBlock().getState();
            if (Loot.isLoot(chest)) {
                player.tracker(PlayerInfo.LOOT_FOUND);
            }
        }
    }
}
Also used : Chest(org.bukkit.block.Chest) Action(org.bukkit.event.block.Action) UPlayer(xyz.derkades.ublisk.utils.UPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Chest

use of org.bukkit.block.Chest in project Ublisk by Derkades.

the class PlayerInteract method chestOpen.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void chestOpen(PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock().getType() != Material.CHEST)
        return;
    Chest chest = (Chest) event.getClickedBlock().getState();
    UPlayer player = new UPlayer(event);
    if (player.isInBuilderMode()) {
        if (!Loot.isLoot(chest)) {
            // Send message if chest is not loot
            player.sendMessage(ChatColor.RED + "Warning: Regular players won't be able to open this chest.");
        }
        return;
    }
    if (!Loot.isLoot(chest)) {
        // Cancel chest right click if chest is not loot
        event.setCancelled(true);
    }
}
Also used : Chest(org.bukkit.block.Chest) UPlayer(xyz.derkades.ublisk.utils.UPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Chest

use of org.bukkit.block.Chest in project Ublisk by Derkades.

the class Voting method onVoteBoxOpen.

@EventHandler(priority = EventPriority.HIGH)
public void onVoteBoxOpen(PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    UPlayer player = new UPlayer(event);
    if (player.isSneaking()) {
        return;
    }
    Block block = event.getClickedBlock();
    if (Voting.isVotingChest(block)) {
        Chest chest = (Chest) block.getState();
        Inventory inv = chest.getInventory();
        int gold = Voting.getRandomGold();
        int xp = Voting.getRandomXP();
        int life = Voting.getRandomLife();
        Item goldItem = new Item(Material.GOLD_NUGGET).setName(ChatColor.GOLD + "" + ChatColor.BOLD + "Gold: " + gold).setAmount(gold);
        Item xpItem = new Item(Material.EXP_BOTTLE).setName(ChatColor.GREEN + "" + ChatColor.BOLD + "XP: " + xp).setAmount(xp);
        Item lifeItem = new Item(Material.NETHER_STAR).setName(ChatColor.BOLD + "Life Crystals: " + life).setAmount(life);
        inv.setItem(12, goldItem.getItemStack());
        inv.setItem(13, xpItem.getItemStack());
        inv.setItem(14, lifeItem.getItemStack());
        if (gold != 0) {
            player.getInventory().addItem(Material.GOLD_NUGGET, gold);
        }
        if (xp != 0) {
            player.addXP(xp);
        }
        if (life != 0) {
            player.setLifeCrystals(player.getLifeCrystals() + life);
        }
        player.tracker(PlayerInfo.VOTE_BOX);
        Logger.log(LogLevel.DEBUG, "Voting", "Gold: " + gold + " | XP: " + xp + " | Life: " + life);
    }
}
Also used : Chest(org.bukkit.block.Chest) Item(xyz.derkades.ublisk.utils.inventory.Item) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Block(org.bukkit.block.Block) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Chest

use of org.bukkit.block.Chest in project Minigames by AddstarMC.

the class TreasureHuntMechanic method removeTreasure.

public static void removeTreasure(Minigame minigame) {
    TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(minigame);
    thm.clearHints();
    if (thm.hasTreasureLocation()) {
        Location old = thm.getTreasureLocation();
        if (old.getWorld() != null && !old.getWorld().isChunkLoaded(old.getChunk().getX(), old.getChunk().getZ())) {
            boolean loaded = old.getChunk().load();
            Chunk c = null;
            if (loaded) {
                c = old.getChunk();
                c.setForceLoaded(true);
            }
            if (old.getBlock().getState() instanceof Chest) {
                Chest chest = (Chest) old.getBlock().getState();
                chest.getInventory().clear();
                old.getBlock().setType(Material.AIR);
            }
            if (loaded) {
                c.setForceLoaded(false);
                c.unload();
            }
            thm.setTreasureLocation(null);
        }
    }
}
Also used : TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) Chest(org.bukkit.block.Chest)

Example 5 with Chest

use of org.bukkit.block.Chest in project Minigames by AddstarMC.

the class TreasureHuntMechanic method interactEvent.

@EventHandler
private void interactEvent(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Block cblock = event.getClickedBlock();
        boolean cancelled = (event.useInteractedBlock() == Event.Result.DENY || event.useItemInHand() == Event.Result.DENY);
        if (cblock != null && cblock.getState() instanceof Chest && !cancelled) {
            for (Minigame minigame : mdata.getAllMinigames().values()) {
                if (minigame.getType() == MinigameType.GLOBAL && minigame.getMechanicName().equalsIgnoreCase(getMechanic()) && minigame.getMinigameTimer() != null) {
                    TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(minigame);
                    if (!thm.isTreasureFound() && thm.hasTreasureLocation()) {
                        int x1 = thm.getTreasureLocation().getBlockX();
                        int x2 = cblock.getLocation().getBlockX();
                        int y1 = thm.getTreasureLocation().getBlockY();
                        int y2 = cblock.getLocation().getBlockY();
                        int z1 = thm.getTreasureLocation().getBlockZ();
                        int z2 = cblock.getLocation().getBlockZ();
                        if (x2 == x1 && y2 == y1 && z2 == z1) {
                            MinigameUtils.broadcast(MinigameUtils.formStr("minigame.treasurehunt.plyFound", event.getPlayer().getDisplayName(), minigame.getName(true)), minigame, "minigame.treasure.announce");
                            event.setCancelled(true);
                            Chest chest = (Chest) cblock.getState();
                            event.getPlayer().openInventory(chest.getInventory());
                            thm.setTreasureFound(true);
                            minigame.getMinigameTimer().setTimeLeft(300);
                        }
                    }
                }
            }
        }
    }
}
Also used : Chest(org.bukkit.block.Chest) TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) Block(org.bukkit.block.Block) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Chest (org.bukkit.block.Chest)14 ItemStack (org.bukkit.inventory.ItemStack)8 Block (org.bukkit.block.Block)4 EventHandler (org.bukkit.event.EventHandler)4 Inventory (org.bukkit.inventory.Inventory)4 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)3 Location (org.bukkit.Location)3 World (org.bukkit.World)3 BlockState (org.bukkit.block.BlockState)3 DoubleChest (org.bukkit.block.DoubleChest)3 InventoryHolder (org.bukkit.inventory.InventoryHolder)3 UPlayer (xyz.derkades.ublisk.utils.UPlayer)3 ArrayList (java.util.ArrayList)2 DyeColor (org.bukkit.DyeColor)2 Material (org.bukkit.Material)2 TreeType (org.bukkit.TreeType)2 Sign (org.bukkit.block.Sign)2 Entity (org.bukkit.entity.Entity)2 EntityType (org.bukkit.entity.EntityType)2 Horse (org.bukkit.entity.Horse)2