use of org.bukkit.inventory.InventoryHolder in project HawkEye by oliverwoodings.
the class ContainerEntry method rebuild.
@Override
public boolean rebuild(Block block) {
if (!(block instanceof InventoryHolder))
return false;
Inventory inv = ((InventoryHolder) block.getState()).getInventory();
List<HashMap<String, Integer>> ops = InventoryUtil.interpretDifferenceString(data);
//Handle the additions
if (ops.size() > 0) {
for (ItemStack stack : InventoryUtil.uncompressInventory(ops.get(0))) inv.addItem(stack);
}
//Handle subtractions
if (ops.size() > 1) {
for (ItemStack stack : InventoryUtil.uncompressInventory(ops.get(1))) inv.removeItem(stack);
}
return true;
}
use of org.bukkit.inventory.InventoryHolder in project Prism-Bukkit by prism.
the class PrismInventoryMoveItemEvent method onInventoryMoveItem.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryMoveItem(final InventoryMoveItemEvent event) {
// Hopper inserted
if (Prism.getIgnore().event("item-insert") && event.getDestination() != null) {
// Get container
final InventoryHolder ih = event.getDestination().getHolder();
Location containerLoc = null;
if (ih instanceof BlockState) {
final BlockState eventChest = (BlockState) ih;
containerLoc = eventChest.getLocation();
}
if (containerLoc == null)
return;
if (event.getSource().getType().equals(InventoryType.HOPPER)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-insert", event.getItem(), event.getItem().getAmount(), 0, null, containerLoc, "hopper"));
}
}
// Hopper removed
if (Prism.getIgnore().event("item-remove") && event.getSource() != null) {
// Get container
final InventoryHolder ih = event.getSource().getHolder();
Location containerLoc = null;
if (ih instanceof BlockState) {
final BlockState eventChest = (BlockState) ih;
containerLoc = eventChest.getLocation();
}
if (containerLoc == null)
return;
if (event.getDestination().getType().equals(InventoryType.HOPPER)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-remove", event.getItem(), event.getItem().getAmount(), 0, null, containerLoc, "hopper"));
}
}
}
use of org.bukkit.inventory.InventoryHolder in project Denizen-For-Bukkit by DenizenScript.
the class CopyBlockCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dLocation copy_location = (dLocation) scriptEntry.getObject("location");
dLocation destination = (dLocation) scriptEntry.getObject("destination");
dCuboid copy_cuboid = (dCuboid) scriptEntry.getObject("cuboid");
Element remove_original = (Element) scriptEntry.getObject("remove");
dB.report(scriptEntry, getName(), (copy_location != null ? copy_location.debug() : "") + (copy_cuboid != null ? copy_cuboid.debug() : "") + destination.debug() + remove_original.debug());
List<Location> locations = new ArrayList<Location>();
if (copy_location != null) {
locations.add(copy_location);
} else if (copy_cuboid != null) {
// TODO: make this work?...
locations.addAll(copy_cuboid.getBlockLocations());
}
for (Location loc : locations) {
Block source = loc.getBlock();
BlockState sourceState = source.getState();
Block update = destination.getBlock();
update.setTypeIdAndData(source.getTypeId(), source.getData(), false);
BlockState updateState = update.getState();
// of InventoryHolder
if (sourceState instanceof InventoryHolder) {
((InventoryHolder) updateState).getInventory().setContents(((InventoryHolder) sourceState).getInventory().getContents());
} else if (sourceState instanceof Sign) {
int n = 0;
for (String line : ((Sign) sourceState).getLines()) {
((Sign) updateState).setLine(n, line);
n++;
}
} else if (sourceState instanceof NoteBlock) {
((NoteBlock) updateState).setNote(((NoteBlock) sourceState).getNote());
} else if (sourceState instanceof Skull) {
((Skull) updateState).setSkullType(((Skull) sourceState).getSkullType());
((Skull) updateState).setOwner(((Skull) sourceState).getOwner());
((Skull) updateState).setRotation(((Skull) sourceState).getRotation());
} else if (sourceState instanceof Jukebox) {
((Jukebox) updateState).setPlaying(((Jukebox) sourceState).getPlaying());
} else if (sourceState instanceof Banner) {
((Banner) updateState).setBaseColor(((Banner) sourceState).getBaseColor());
((Banner) updateState).setPatterns(((Banner) sourceState).getPatterns());
} else if (sourceState instanceof CommandBlock) {
((CommandBlock) updateState).setName(((CommandBlock) sourceState).getName());
((CommandBlock) updateState).setCommand(((CommandBlock) sourceState).getCommand());
} else if (sourceState instanceof CreatureSpawner) {
((CreatureSpawner) updateState).setCreatureTypeByName(((CreatureSpawner) sourceState).getCreatureTypeName());
((CreatureSpawner) updateState).setDelay(((CreatureSpawner) sourceState).getDelay());
}
updateState.update();
if (remove_original.asBoolean()) {
loc.getBlock().setType(Material.AIR);
}
}
}
use of org.bukkit.inventory.InventoryHolder in project Towny by ElgarL.
the class ProtectionRegenTask method replaceProtections.
public void replaceProtections() {
try {
Block block = state.getBlock();
if (state.getData() instanceof Door) {
Door door = (Door) state.getData();
Block topHalf;
Block bottomHalf;
if (door.isTopHalf()) {
topHalf = block;
bottomHalf = block.getRelative(BlockFace.DOWN);
} else {
bottomHalf = block;
topHalf = block.getRelative(BlockFace.UP);
}
door.setTopHalf(true);
topHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
door.setTopHalf(false);
bottomHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
} else if (state instanceof Sign) {
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
Sign sign = (Sign) block.getState();
int i = 0;
for (String line : ((Sign) state).getLines()) sign.setLine(i++, line);
sign.update(true);
} else if (state instanceof CreatureSpawner) {
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
((CreatureSpawner) block.getState()).setSpawnedType(((CreatureSpawner) state).getSpawnedType());
} else if (state instanceof InventoryHolder) {
block.setTypeId(state.getTypeId(), false);
// Container to receive the inventory
Inventory container = ((InventoryHolder) block.getState()).getInventory();
container.setContents(contents.toArray(new ItemStack[0]));
block.setData(state.getData().getData(), false);
} else if (state.getData() instanceof PistonExtensionMaterial) {
PistonExtensionMaterial extension = (PistonExtensionMaterial) state.getData();
Block piston = block.getRelative(extension.getAttachedFace());
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
if (altState != null) {
piston.setTypeIdAndData(altState.getTypeId(), altState.getData().getData(), false);
}
} else if (state.getData() instanceof Attachable) {
Block attachedBlock = block.getRelative(((Attachable) state.getData()).getAttachedFace());
if (attachedBlock.getTypeId() == 0) {
attachedBlock.setTypeId(placeholder.getId(), false);
TownyRegenAPI.addPlaceholder(attachedBlock);
}
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
} else {
if (NeedsPlaceholder.contains(state.getType())) {
Block blockBelow = block.getRelative(BlockFace.DOWN);
if (blockBelow.getTypeId() == 0) {
if (state.getType().equals(Material.CROPS)) {
blockBelow.setTypeId(Material.SOIL.getId(), true);
} else {
blockBelow.setTypeId(placeholder.getId(), true);
}
TownyRegenAPI.addPlaceholder(blockBelow);
}
}
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), !NeedsPlaceholder.contains(state.getType()));
}
TownyRegenAPI.removePlaceholder(block);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.bukkit.inventory.InventoryHolder in project Denizen-For-Bukkit by DenizenScript.
the class PlayerDragsInInvScriptEvent method onPlayerDragsInInv.
@EventHandler
public void onPlayerDragsInInv(InventoryDragEvent event) {
if (dEntity.isCitizensNPC(event.getWhoClicked())) {
return;
}
entity = dEntity.getPlayerFrom(event.getWhoClicked());
inventory = event.getInventory();
dInv = dInventory.mirrorBukkitInventory(inventory);
item = new dItem(event.getOldCursor());
slots = new dList();
for (Integer slot : event.getInventorySlots()) {
slots.add(slot.toString());
}
raw_slots = new dList();
for (Integer raw_slot : event.getRawSlots()) {
raw_slots.add(raw_slot.toString());
}
cancelled = event.isCancelled();
manual_cancelled = false;
this.event = event;
fire();
if (cancelled && manual_cancelled) {
final InventoryHolder holder = inventory.getHolder();
new BukkitRunnable() {
@Override
public void run() {
entity.getPlayerEntity().updateInventory();
if (holder != null && holder instanceof Player) {
((Player) holder).updateInventory();
}
}
}.runTaskLater(DenizenAPI.getCurrentInstance(), 1);
}
event.setCancelled(cancelled);
}
Aggregations