use of org.cubeengine.module.itemduct.data.DuctData in project modules-extra by CubeEngine.
the class ItemDuctListener method onInteractPiston.
@Listener
public void onInteractPiston(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
Optional<ItemStack> itemInHand = player.getItemInHand(HandTypes.MAIN_HAND);
Boolean hasActivator = itemInHand.map(ItemDuctListener::isActivator).orElse(false);
if (hasActivator) {
event.setCancelled(true);
}
if (!isDuctInteraction(event)) {
return;
}
Location<World> loc = event.getTargetBlock().getLocation().get();
Direction dir = loc.get(Keys.DIRECTION).orElse(Direction.NONE);
Location<World> te = loc.getRelative(dir);
Optional<DuctData> ductData = te.get(DuctData.class);
Direction dirO = dir.getOpposite();
if (!ductData.map(d -> d.has(dirO)).orElse(false) && hasActivator) {
if (loc.getBlockType() == BlockTypes.OBSERVER) {
if (!player.hasPermission(this.activateObserverPerm.getId())) {
event.setCancelled(true);
return;
}
} else {
if (!player.hasPermission(this.activatePistonPerm.getId())) {
event.setCancelled(true);
return;
}
}
te.offer(ductData.orElse(new DuctData()).with(dirO));
playCreateEffect(loc);
if (player.get(Keys.GAME_MODE).get() != GameModes.CREATIVE) {
ItemStack newStack = itemInHand.get().copy();
Integer uses = newStack.get(IDuctData.USES).orElse(0) - 1;
if (uses <= 0) {
if (// Infinite usage?
uses == -2) {
uses++;
} else {
newStack.setQuantity(itemInHand.get().getQuantity() - 1);
uses = module.getConfig().activatorUses;
}
}
newStack.offer(IDuctData.USES, uses);
module.getManager().updateUses(newStack);
player.setItemInHand(HandTypes.MAIN_HAND, newStack);
}
player.getProgress(module.activate).grant();
}
}
use of org.cubeengine.module.itemduct.data.DuctData in project modules-extra by CubeEngine.
the class ItemDuctTransferListener method onInteractPiston.
@Listener
public void onInteractPiston(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
event.getTargetBlock().getLocation().ifPresent(loc -> {
Direction dir = loc.get(Keys.DIRECTION).orElse(Direction.NONE);
Location<World> te = loc.getRelative(dir);
Optional<DuctData> ductData = te.get(DuctData.class);
Optional<ItemStack> itemInHand = player.getItemInHand(HandTypes.MAIN_HAND);
if (ductData.isPresent() && !itemInHand.isPresent() && !player.get(Keys.IS_SNEAKING).orElse(false)) {
// Play Effect for DuctPiston
manager.playEffect(loc);
}
});
}
Aggregations