Search in sources :

Example 96 with Listener

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));
    }
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) Player(org.spongepowered.api.entity.living.player.Player) BlockQueueEntry(com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Date(java.util.Date) Listener(org.spongepowered.api.event.Listener)

Example 97 with Listener

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));
            }
        }
    }
}
Also used : Chest(org.spongepowered.api.block.tileentity.carrier.Chest) BlockCarrier(org.spongepowered.api.item.inventory.BlockCarrier) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) InventoryQueueEntry(com.karanumcoding.adamantineshield.db.queue.InventoryQueueEntry) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Date(java.util.Date) Listener(org.spongepowered.api.event.Listener)

Example 98 with Listener

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()));
    }
}
Also used : MatterProperty(org.spongepowered.api.data.property.block.MatterProperty) BlockType(org.spongepowered.api.block.BlockType) BlockQueueEntry(com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Date(java.util.Date) Listener(org.spongepowered.api.event.Listener)

Example 99 with Listener

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));
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockQueueEntry(com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Date(java.util.Date) Listener(org.spongepowered.api.event.Listener)

Example 100 with Listener

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));
    }
}
Also used : BlockQueueEntry(com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) UUID(java.util.UUID) Date(java.util.Date) Listener(org.spongepowered.api.event.Listener)

Aggregations

Listener (org.spongepowered.api.event.Listener)360 Player (org.spongepowered.api.entity.living.player.Player)118 World (org.spongepowered.api.world.World)97 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)65 Entity (org.spongepowered.api.entity.Entity)58 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)46 Text (org.spongepowered.api.text.Text)46 ItemStack (org.spongepowered.api.item.inventory.ItemStack)45 Location (org.spongepowered.api.world.Location)45 Sponge (org.spongepowered.api.Sponge)22 BlockType (org.spongepowered.api.block.BlockType)22 Task (org.spongepowered.api.scheduler.Task)17 IOException (java.io.IOException)16 Optional (java.util.Optional)16 Living (org.spongepowered.api.entity.living.Living)15 ItemType (org.spongepowered.api.item.ItemType)15 UUID (java.util.UUID)14 Monster (org.spongepowered.api.entity.living.monster.Monster)14 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)14 Map (java.util.Map)13