use of org.bukkit.block.Container in project FluffyMachines by NCBPFluffyBear.
the class ExpDispenser method onInteract.
@Override
public void onInteract(Player p, Block b) {
Block dispenser = b.getRelative(0, -1, 0);
Container container = (Container) dispenser.getState();
int experience = 0;
for (ItemStack bottle : container.getInventory().getContents()) {
if (bottle != null && bottle.getType() == Material.EXPERIENCE_BOTTLE) {
// Search for xp bottles
// Collect experience from bottle
experience += EXP_PER_BOTTLE * bottle.getAmount();
// Delete bottle
bottle.setAmount(0);
}
}
Block barrel = dispenser.getRelative(((Directional) dispenser.getBlockData()).getFacing());
SlimefunItem sfItem = BlockStorage.check(barrel);
if (sfItem instanceof Barrel) {
Barrel sfBarrel = (Barrel) sfItem;
if (sfBarrel.getStoredItem(barrel).getType() == Material.EXPERIENCE_BOTTLE) {
experience += sfBarrel.getStored(barrel) * EXP_PER_BOTTLE;
sfBarrel.setStored(barrel, 0);
sfBarrel.updateMenu(barrel, BlockStorage.getInventory(barrel), true);
}
}
if (experience == 0) {
Utils.send(p, "&cThere were no experience bottles in the dispenser!");
} else {
p.giveExp(experience);
Utils.send(p, "&a+" + experience + " XP");
}
}
use of org.bukkit.block.Container in project kit-api by HGLabor.
the class DiggerKit method onPlayerRightClickKitItem.
@KitEvent
@Override
public void onPlayerRightClickKitItem(PlayerInteractEvent event, KitPlayer kitPlayer) {
Block clickedBlock = event.getClickedBlock();
Player player = event.getPlayer();
if (clickedBlock != null) {
// Reduce Digger item
if (player.getInventory().getItemInMainHand().isSimilar(mainKitItem)) {
player.getInventory().getItemInMainHand().subtract();
} else if (player.getInventory().getItemInOffHand().isSimilar(mainKitItem)) {
player.getInventory().getItemInOffHand().subtract();
}
Block block = clickedBlock.getLocation().add(0, 1, 0).getBlock();
kitPlayer.activateKitCooldown(this);
new BukkitRunnable() {
@Override
public void run() {
int dist = (int) Math.ceil((double) (radius - 1) / 2);
for (int y = -1; y >= -radius; y--) {
for (int x = -dist; x <= dist; x++) {
for (int z = -dist; z <= dist; z++) {
if (block.getY() + y <= 0) {
continue;
}
Block b = block.getWorld().getBlockAt(block.getX() + x, block.getY() + y, block.getZ() + z);
if (b.hasMetadata("feastBlock")) {
continue;
}
if (b.hasMetadata(KitMetaData.GLADIATOR_BLOCK.getKey())) {
continue;
}
if (!b.getType().equals(Material.BEDROCK)) {
if (b instanceof Container) {
b.breakNaturally();
} else {
b.setType(Material.AIR);
}
}
}
}
}
player.getWorld().playSound(player.getLocation(), sound, volume, 1);
}
}.runTaskLater(KitApi.getInstance().getPlugin(), 15);
}
}
use of org.bukkit.block.Container in project PrettySimpleShop by MLG-Fortress.
the class ShopListener method onBreakShop.
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
private void onBreakShop(BlockBreakEvent event) {
Block block = event.getBlock();
if (!config.isShopBlock(block.getType()))
return;
Container container = (Container) block.getState();
if (!shopAPI.isShop(container))
return;
instance.getServer().getPluginManager().callEvent(new ShopBreakEvent(event.getPlayer(), new ShopInfo(shopAPI.getLocation(container), shopAPI.getItemStack(container), shopAPI.getPrice(container)), event));
double deposit = shopAPI.getRevenue(container, true);
if (deposit <= 0)
return;
Player player = event.getPlayer();
economy.depositPlayer(player, deposit);
config.sendMessage(player, "collectRevenue", economy.format(deposit));
}
use of org.bukkit.block.Container in project PrettySimpleShop by MLG-Fortress.
the class ShopListener method selectShop.
public boolean selectShop(Player player, Block block, boolean wantToBuy) {
if (!config.isShopBlock(block.getType()))
return false;
Container container = (Container) block.getState();
if (!shopAPI.isShop(container))
return false;
ItemStack item = shopAPI.getItemStack(container);
double price = shopAPI.getPrice(container);
if (price < 0) {
config.sendMessage(player, "noPrice");
return true;
} else if (item == null) {
config.sendMessage(player, "noStock");
config.sendTip(player, "noStock");
return true;
}
ShopInfo shopInfo = new ShopInfo(shopAPI.getLocation(container), item, price);
ShopSelectEvent shopSelectEvent = new ShopSelectEvent(player, shopInfo, shopInfo.equals(selectedShop.get(player)) || wantToBuy);
selectedShop.put(player, shopInfo);
// Refactor: put this in the ShopInfo constructor instead
String textToSend = config.getString("saleInfo", PrettySimpleShop.getItemName(item), economy.format(price), Integer.toString(item.getAmount()));
String json;
item.setAmount(1);
try {
// CraftItemStack#asNMSCopy(itemStack); //nms version of the ItemStack
Object nmsItemStack = asNMSCopy.invoke(null, item);
// new NBTTagCompoundClazz(); //get a new NBTTagCompound, which will contain the nmsItemStack.
Object nbtTagCompound = NBTTagCompoundClazz.newInstance();
// nmsItemStack#save(nbtTagCompound); //saves nmsItemStack into our new NBTTagCompound
nbtTagCompound = saveNMSItemStack.invoke(nmsItemStack, nbtTagCompound);
json = nbtTagCompound.toString();
} catch (Throwable rock) {
// print stacktrace in debug
// https://howtodoinjava.com/java/string/convert-stacktrace-to-string/
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
rock.printStackTrace(pw);
PrettySimpleShop.debug(sw.toString());
player.sendMessage(textToSend);
instance.getServer().getPluginManager().callEvent(shopSelectEvent);
return true;
}
BaseComponent[] hoverEventComponents = new BaseComponent[] { new TextComponent(json) };
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_ITEM, hoverEventComponents);
TextComponent text = new TextComponent(textToSend);
text.setHoverEvent(hover);
text.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/buy " + container.getLocation().getWorld().getName() + " " + container.getLocation().getX() + " " + container.getLocation().getBlockY() + " " + container.getLocation().getBlockZ()));
player.spigot().sendMessage(text);
shopInfo.setHoverableText(text);
config.sendTip(player, "saleInfo");
instance.getServer().getPluginManager().callEvent(shopSelectEvent);
return true;
}
use of org.bukkit.block.Container in project RoseLoot by Rosewood-Development.
the class LootGenerateListener method onLootGenerate.
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLootGenerate(LootGenerateEvent event) {
if (!(event.getInventoryHolder() instanceof Container))
return;
Block block = ((Container) event.getInventoryHolder()).getBlock();
if (Setting.DISABLED_WORLDS.getStringList().stream().anyMatch(x -> x.equalsIgnoreCase(block.getWorld().getName())))
return;
LivingEntity looter = null;
if (event.getEntity() instanceof LivingEntity)
looter = (LivingEntity) event.getEntity();
LootContext lootContext = LootContext.builder(LootUtils.getEntityLuck(looter)).put(LootContextParams.ORIGIN, block.getLocation()).put(LootContextParams.LOOTER, looter).put(LootContextParams.LOOTED_BLOCK, block).put(LootContextParams.VANILLA_LOOT_TABLE_KEY, event.getLootTable().getKey()).build();
LootResult lootResult = this.lootTableManager.getLoot(LootTableTypes.CONTAINER, lootContext);
LootContents lootContents = lootResult.getLootContents();
// Overwrite existing loot if applicable
if (lootResult.shouldOverwriteItems())
event.getLoot().clear();
// Set items and drop experience
event.getLoot().addAll(lootResult.getLootContents().getItems());
int experience = lootContents.getExperience();
if (experience > 0) {
Location location = looter == null ? block.getLocation() : looter.getLocation();
block.getWorld().spawn(location, ExperienceOrb.class, x -> x.setExperience(experience));
}
lootContents.triggerExtras(block.getLocation());
}
Aggregations