use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.
the class UltimateStackerConversionHandler method handleConversion.
@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
Set<Stack<?>> stacks = new HashSet<>();
for (ConversionData data : conversionData) {
Item item = data.getItem();
if (item == null)
continue;
int stackSize = this.getItemAmount(item);
StackedItem stackedItem = new StackedItem(stackSize, data.getItem());
this.stackManager.addItemStack(stackedItem);
stacks.add(stackedItem);
}
return stacks;
}
use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.
the class ItemListener method onInventoryPickup.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInventoryPickup(InventoryPickupItemEvent event) {
if (this.stackManager.isWorldDisabled(event.getItem().getWorld()))
return;
if (!this.stackManager.isItemStackingEnabled())
return;
StackedItem stackedItem = this.stackManager.getStackedItem(event.getItem());
if (stackedItem == null)
return;
Inventory inventory = event.getInventory();
if (this.applyInventoryItemPickup(inventory, stackedItem, null))
event.setCancelled(true);
}
use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.
the class StackToolListener method onInteract.
/**
* Handles Shift Left Click for StackedItems
*
* @param event The PlayerInteractEvent
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack tool = player.getInventory().getItemInMainHand();
if (event.getAction() == Action.PHYSICAL || !ItemUtils.isStackingTool(tool))
return;
event.setCancelled(true);
if (!player.isSneaking() || event.getHand() != EquipmentSlot.HAND)
return;
if (!player.hasPermission("rosestacker.stacktool")) {
this.localeManager.sendMessage(player, "command-stacktool-no-permission");
return;
}
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
for (Entity entity : player.getNearbyEntities(3, 3, 3)) {
if (entity.getType() != EntityType.DROPPED_ITEM)
continue;
Item item = (Item) entity;
if (!EntityUtils.isLookingAtItem(player, item))
continue;
StackedItem stackedItem = this.stackManager.getStackedItem(item);
if (stackedItem == null)
continue;
ItemMeta itemMeta = item.getItemStack().getItemMeta();
this.localeManager.sendMessage(player, "command-stacktool-info");
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-uuid", StringPlaceholders.single("uuid", item.getUniqueId().toString()));
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-entity-id", StringPlaceholders.single("id", item.getEntityId()));
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-item-type", StringPlaceholders.single("type", item.getItemStack().getType().name()));
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-stack-size", StringPlaceholders.single("amount", stackedItem.getStackSize()));
if (itemMeta != null && itemMeta.hasDisplayName())
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-custom-name", StringPlaceholders.single("name", itemMeta.getDisplayName()));
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-location", StringPlaceholders.builder("x", item.getLocation().getBlockX()).addPlaceholder("y", item.getLocation().getBlockY()).addPlaceholder("z", item.getLocation().getBlockZ()).addPlaceholder("world", item.getWorld().getName()).build());
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-chunk", StringPlaceholders.builder("x", item.getLocation().getChunk().getX()).addPlaceholder("z", item.getLocation().getChunk().getZ()).build());
return;
}
}
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
Block clickedBlock = event.getClickedBlock();
if (clickedBlock == null)
return;
if (clickedBlock.getType() != Material.SPAWNER) {
StackedBlock stackedBlock = this.stackManager.getStackedBlock(clickedBlock);
if (stackedBlock == null)
return;
this.localeManager.sendMessage(player, "command-stacktool-info");
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-block-type", StringPlaceholders.single("type", clickedBlock.getType().name()));
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-stack-size", StringPlaceholders.single("amount", stackedBlock.getStackSize()));
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-location", StringPlaceholders.builder("x", clickedBlock.getX()).addPlaceholder("y", clickedBlock.getY()).addPlaceholder("z", clickedBlock.getZ()).addPlaceholder("world", clickedBlock.getWorld().getName()).build());
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-chunk", StringPlaceholders.builder("x", clickedBlock.getChunk().getX()).addPlaceholder("z", clickedBlock.getChunk().getZ()).build());
} else {
StackedSpawner stackedSpawner = this.stackManager.getStackedSpawner(clickedBlock);
if (stackedSpawner == null)
return;
this.localeManager.sendMessage(player, "command-stacktool-info");
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-spawner-type", StringPlaceholders.single("type", stackedSpawner.getSpawnerTile().getSpawnedType().name()));
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-stack-size", StringPlaceholders.single("amount", stackedSpawner.getStackSize()));
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-location", StringPlaceholders.builder("x", clickedBlock.getX()).addPlaceholder("y", clickedBlock.getY()).addPlaceholder("z", clickedBlock.getZ()).addPlaceholder("world", clickedBlock.getWorld().getName()).build());
this.localeManager.sendSimpleMessage(player, "command-stacktool-info-chunk", StringPlaceholders.builder("x", clickedBlock.getChunk().getX()).addPlaceholder("z", clickedBlock.getChunk().getZ()).build());
}
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block clickedBlock = event.getClickedBlock();
if (clickedBlock == null || clickedBlock.getType() != Material.SPAWNER)
return;
StackedSpawner stackedSpawner = this.stackManager.getStackedSpawner(clickedBlock);
if (stackedSpawner == null) {
CreatureSpawner creatureSpawner = (CreatureSpawner) clickedBlock.getState();
creatureSpawner.setDelay(5);
creatureSpawner.update();
} else {
stackedSpawner.getSpawnerTile().setDelay(5);
}
int points = 50;
for (int i = 0; i < points; i++) {
double dx = Math.cos(Math.PI * 2 * ((double) i / points)) * 0.25;
double dy = 0.5;
double dz = Math.sin(Math.PI * 2 * ((double) i / points)) * 0.25;
double angle = Math.atan2(dz, dx);
double xAng = Math.cos(angle);
double zAng = Math.sin(angle);
clickedBlock.getWorld().spawnParticle(Particle.END_ROD, clickedBlock.getLocation().add(0.5 + dx, dy, 0.5 + dz), 0, xAng, 0, zAng, 0.15);
}
}
// Make the item bob a little bit
player.updateInventory();
}
use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.
the class DataUtils method readStackedItem.
public static StackedItem readStackedItem(Item item) {
PersistentDataContainer pdc = item.getPersistentDataContainer();
byte[] data = pdc.get(ITEM_KEY, PersistentDataType.BYTE_ARRAY);
if (data == null)
return new StackedItem(item.getItemStack().getAmount(), item);
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
int dataVersion = dataInput.readInt();
if (dataVersion == 1) {
int stackSize = dataInput.readInt();
return new StackedItem(stackSize, item);
}
} catch (Exception e) {
e.printStackTrace();
pdc.remove(ITEM_KEY);
}
return null;
}
use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.
the class ItemConversionHandler method handleConversion.
@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
Set<Stack<?>> stacks = new HashSet<>();
for (ConversionData data : conversionData) {
StackedItem stackedItem = new StackedItem(data.getStackSize(), data.getItem());
this.stackManager.addItemStack(stackedItem);
stacks.add(stackedItem);
}
return stacks;
}
Aggregations