Search in sources :

Example 6 with BlockQueueEntry

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

the class MobBlockChangeListener method onBlockPlace.

@Listener(order = Order.POST)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Agent a) {
    if (a instanceof Player)
        return;
    long time = new Date().getTime();
    for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
        String type = a.getType().getName();
        if (transaction.getOriginal().getState().getType() != BlockTypes.AIR) {
            db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.MOB_DESTROY, type, time));
        }
        db.addToQueue(new BlockQueueEntry(transaction.getFinal(), ActionType.MOB_PLACE, type, time));
    }
}
Also used : 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 7 with BlockQueueEntry

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

the class PlayerBlockChangeListener method onBreakCascade.

@Listener(order = Order.POST)
public void onBreakCascade(ChangeBlockEvent.Break e, @Root LocatableBlock b) {
    Optional<User> optionalUser = e.getCause().getContext().get(EventContextKeys.NOTIFIER);
    if (!optionalUser.isPresent())
        return;
    User user = optionalUser.get();
    long time = new Date().getTime();
    for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
        db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.DESTROY, user.getUniqueId().toString(), time));
    }
}
Also used : User(org.spongepowered.api.entity.living.player.User) 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