Search in sources :

Example 1 with BlockQueueEntry

use of com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry 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 2 with BlockQueueEntry

use of com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry 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 3 with BlockQueueEntry

use of com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry 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 4 with BlockQueueEntry

use of com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry 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)

Example 5 with BlockQueueEntry

use of com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry in project AdamantineShield by Karanum.

the class EntityBlockChangeListener method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break e, @Root Explosion expl) {
    if (!expl.getSourceExplosive().isPresent())
        return;
    String source = expl.getSourceExplosive().get().getType().getName();
    long time = new Date().getTime();
    for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
        db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.MOB_DESTROY, source, time));
    }
}
Also used : BlockQueueEntry(com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Date(java.util.Date) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockQueueEntry (com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry)7 Date (java.util.Date)7 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)7 Listener (org.spongepowered.api.event.Listener)7 BlockType (org.spongepowered.api.block.BlockType)2 Player (org.spongepowered.api.entity.living.player.Player)2 UUID (java.util.UUID)1 MatterProperty (org.spongepowered.api.data.property.block.MatterProperty)1 Agent (org.spongepowered.api.entity.living.Agent)1 User (org.spongepowered.api.entity.living.player.User)1 World (org.spongepowered.api.world.World)1