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);
}
}
}
}
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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
}
}
}
}
}
Aggregations