use of org.spongepowered.api.event.Listener in project AdamantineShield by Karanum.
the class EntityBlockChangeListener method onBlockPlace.
// @Listener(order = Order.POST)
// public void onTileEntityBlockPlace(ChangeBlockEvent.Place e, @Root TileEntity te) {
// System.out.println("PLACE EVENT:");
// long time = new Date().getTime();
// for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
// BlockType orig = transaction.getOriginal().getState().getType();
// BlockType result = transaction.getFinal().getState().getType();
// if (orig != BlockTypes.AIR && !technicalBlocks.contains(orig)) {
// System.out.println(transaction);
// //db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.MOB_DESTROY, te.getType().getName(), time));
// }
// if (!technicalBlocks.contains(result))
// System.out.println(transaction);
// //db.addToQueue(new BlockQueueEntry(transaction.getFinal(), ActionType.MOB_PLACE, te.getType().getName(), time));
// }
// }
//
// @Listener(order = Order.POST)
// public void onTileEntityBlockBreak(ChangeBlockEvent.Break e, @Root TileEntity te) {
// System.out.println("BREAK EVENT:");
// long time = new Date().getTime();
// for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
// if (technicalBlocks.contains(transaction.getOriginal().getState().getType()))
// return;
// System.out.println(transaction);
// //db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.MOB_PLACE, te.getType().getName(), time));
// }
// }
@Listener(order = Order.POST)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Entity ent) {
if (ent instanceof Player || ent instanceof Agent)
return;
long time = new Date().getTime();
for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
String name = ent.getType().getName();
if (transaction.getOriginal().getState().getType() != BlockTypes.AIR) {
db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.MOB_DESTROY, name, time));
}
db.addToQueue(new BlockQueueEntry(transaction.getFinal(), ActionType.MOB_PLACE, name, time));
}
}
use of org.spongepowered.api.event.Listener in project AdamantineShield by Karanum.
the class InventoryChangeListener method onInventoryTransfer.
@Listener
public void onInventoryTransfer(AffectSlotEvent e, @First Player p) {
if (e.getTransactions().isEmpty())
return;
if (!(e.getTransactions().get(0).getSlot().parent() instanceof CarriedInventory))
return;
BlockCarrier carrier = null;
CarriedInventory<?> c = (CarriedInventory<?>) e.getTransactions().get(0).getSlot().parent();
if (c.getCarrier().get() instanceof BlockCarrier) {
carrier = (BlockCarrier) c.getCarrier().get();
}
if (carrier == null)
return;
if (!logContainers && !(carrier instanceof Chest))
return;
long timestamp = new Date().getTime();
int containerSize = c.iterator().next().capacity();
for (SlotTransaction transaction : e.getTransactions()) {
int slotId = transaction.getSlot().getProperty(SlotIndex.class, "slotindex").map(SlotIndex::getValue).orElse(-1);
if (slotId >= containerSize)
continue;
ItemStackSnapshot origItem = transaction.getOriginal();
ItemStackSnapshot finalItem = transaction.getFinal();
if (origItem == finalItem)
continue;
if (origItem.createGameDictionaryEntry().matches(finalItem.createStack()) && ItemStackComparators.ITEM_DATA.compare(origItem.createStack(), finalItem.createStack()) == 0) {
if (origItem.getQuantity() > finalItem.getQuantity()) {
ItemStackSnapshot stack = ItemStack.builder().itemType(origItem.getType()).quantity(origItem.getQuantity() - finalItem.getQuantity()).build().createSnapshot();
db.addToQueue(new InventoryQueueEntry(carrier, slotId, stack, ActionType.CONTAINER_REMOVE, p, timestamp));
} else if (origItem.getQuantity() < finalItem.getQuantity()) {
ItemStackSnapshot stack = ItemStack.builder().itemType(origItem.getType()).quantity(finalItem.getQuantity() - origItem.getQuantity()).build().createSnapshot();
db.addToQueue(new InventoryQueueEntry(carrier, slotId, stack, ActionType.CONTAINER_ADD, p, timestamp));
}
} else {
if (origItem.getType() != ItemTypes.NONE) {
db.addToQueue(new InventoryQueueEntry(carrier, slotId, origItem, ActionType.CONTAINER_REMOVE, p, timestamp));
}
if (finalItem.getType() != ItemTypes.NONE) {
db.addToQueue(new InventoryQueueEntry(carrier, slotId, finalItem, ActionType.CONTAINER_ADD, p, timestamp));
}
}
}
}
use of org.spongepowered.api.event.Listener in project AdamantineShield by Karanum.
the class LiquidFlowListener method onLiquidFlow.
@Listener(order = Order.POST)
public void onLiquidFlow(ChangeBlockEvent.Pre e) {
if (e.getLocations().isEmpty())
return;
Location<World> loc = e.getLocations().get(0);
BlockSnapshot snapshot = loc.getExtent().createSnapshot(loc.getBlockPosition());
Optional<MatterProperty> matter = snapshot.getState().getProperty(MatterProperty.class);
if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
String name = "Water";
BlockType type = snapshot.getState().getType();
if (type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA)
name = "Lava";
db.addToQueue(new BlockQueueEntry(snapshot, ActionType.FLOW, name, new Date().getTime()));
}
}
use of org.spongepowered.api.event.Listener in project AdamantineShield by Karanum.
the class PlantGrowthListener method onGrowth.
@Listener(order = Order.POST)
public void onGrowth(ChangeBlockEvent.Place e, @Root LocatableBlock b) {
BlockType type = b.getBlockState().getType();
if (!acceptedBlocks.contains(type))
return;
long time = new Date().getTime();
for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
db.addToQueue(new BlockQueueEntry(transaction.getFinal(), ActionType.MOB_PLACE, "block_growth", time));
}
}
use of org.spongepowered.api.event.Listener in project AdamantineShield by Karanum.
the class PlayerBlockChangeListener method onBlockPlace.
@Listener(order = Order.POST)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) {
long time = new Date().getTime();
for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
UUID id = p.getUniqueId();
if (transaction.getOriginal().getState().getType() != BlockTypes.AIR) {
db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.DESTROY, id.toString(), time));
}
db.addToQueue(new BlockQueueEntry(transaction.getFinal(), ActionType.PLACE, id.toString(), time));
}
}
Aggregations