use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.
the class PlaceBlockReport method showReport.
@Override
public void showReport(List<Action> actions, Receiver receiver) {
Action action = actions.get(0);
Optional<BlockSnapshot> orig = action.getCached(BLOCKS_ORIG, Recall::origSnapshot);
Optional<BlockSnapshot> repl = action.getCached(BLOCKS_REPL, Recall::replSnapshot);
if (!repl.isPresent()) {
throw new IllegalStateException();
}
showReport(actions, receiver, action, orig, repl.get());
}
use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.
the class Observe method cause.
public static Map<String, Object> cause(Object cause, boolean doRecursion) {
if (cause instanceof EntityDamageSource) {
Entity source = ((EntityDamageSource) cause).getSource();
Map<String, Object> sourceCause = Observe.cause(source);
Map<String, Object> indirectCause = null;
if (cause instanceof IndirectEntityDamageSource) {
indirectCause = Observe.cause(((IndirectEntityDamageSource) cause).getIndirectSource());
if (sourceCause == null) {
return indirectCause;
}
}
// TODO indirectCause
return sourceCause;
} else if (cause instanceof BlockDamageSource) {
return Observe.cause(((BlockDamageSource) cause).getBlockSnapshot());
} else if (cause instanceof DamageSource) {
return Observe.damageCause(((DamageSource) cause));
}
if (cause instanceof Player) {
return playerCause(((Player) cause));
} else if (cause instanceof BlockSnapshot) {
return blockCause(((BlockSnapshot) cause));
} else if (cause instanceof PrimedTNT) {
return tntCause(((PrimedTNT) cause));
} else if (cause instanceof Entity) {
return entityCause(((Entity) cause), doRecursion);
}
// TODO other causes that interest us
return null;
}
use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.
the class ItemDuctListener method onBreak.
@Listener
public void onBreak(ChangeBlockEvent.Break event) {
for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
if (!trans.getOriginal().getLocation().isPresent()) {
continue;
}
BlockType type = trans.getOriginal().getState().getType();
Location<World> loc = trans.getOriginal().getLocation().get();
if (isEndPointType(type)) {
Direction dir = trans.getOriginal().get(Keys.DIRECTION).orElse(Direction.NONE);
Optional<DuctData> data = loc.getRelative(dir).get(DuctData.class);
if (data.isPresent()) {
data.get().remove(dir.getOpposite());
if (data.get().getFilters().isEmpty()) {
loc.getRelative(dir).remove(DuctData.class);
} else {
loc.getRelative(dir).offer(data.get());
}
}
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.
the class MarketSignListener method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockSnapshot orig = transaction.getOriginal();
BlockType type = orig.getState().getType();
if (type == STANDING_SIGN || type == WALL_SIGN) {
Optional<ImmutableMarketSignData> signData = orig.get(ImmutableMarketSignData.class);
if (signData.isPresent()) {
if (signData.get().getSignType() != null) {
event.setCancelled(true);
return;
}
}
}
Location<World> origLoc = orig.getLocation().get();
for (Direction blockFace : BlockUtil.BLOCK_FACES) {
if (blockFace == DOWN) {
continue;
}
Location<World> relative = origLoc.getRelative(blockFace);
if (!relative.get(MarketSignData.class).isPresent()) {
continue;
}
if (blockFace == UP) {
if (relative.getBlockType() == STANDING_SIGN) {
event.setCancelled(true);
return;
}
} else {
if (relative.getBlockType() == WALL_SIGN && relative.get(Keys.DIRECTION).get() == blockFace) {
event.setCancelled(true);
return;
}
}
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project modules-extra by CubeEngine.
the class MarketSignListener method onSignPlace.
@Listener(order = Order.POST)
public void onSignPlace(ChangeBlockEvent.Place event, @First Player player) {
if (event.getTransactions().size() > 1 || !module.getEditModeCommand().hasUser(player)) {
return;
}
for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
BlockType type = trans.getFinal().getState().getType();
if (// placed sign
type == BlockTypes.STANDING_SIGN || type == BlockTypes.WALL_SIGN) {
if (!player.hasPermission(module.perms().EDIT_USE.getId())) {
event.setCancelled(true);
i18n.send(player, NEGATIVE, "You are not allowed to create market signs!");
return;
}
MarketSignData data = new MarketSignData();
data.setID(UUID.randomUUID());
data.setOwner(player.getUniqueId());
Location<World> loc = trans.getFinal().getLocation().get();
loc.offer(data);
manager.setSign(loc, player);
Sponge.getCauseStackManager().pushCause(player);
player.closeInventory();
}
}
}
Aggregations