Search in sources :

Example 1 with BlockTicker

use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project MissileWarfare by koiboi-dev.

the class AntiMissileLauncher method preRegister.

@Override
public void preRegister() {
    // cancel thing on place
    BlockPlaceHandler blockPlaceHandler = new BlockPlaceHandler(false) {

        @Override
        public void onPlayerPlace(BlockPlaceEvent event) {
            BlockData data = event.getBlockPlaced().getBlockData();
            ((Directional) data).setFacing(BlockFace.UP);
            event.getBlockPlaced().setBlockData(data);
            Block block = event.getBlockPlaced();
            // Block bottom = world.getBlockAt(event.getBlock().getLocation().subtract(new Vector(0, 2, 0)));
            if (correctlyBuilt(block)) {
                event.getPlayer().sendMessage(Translations.get("messages.launchers.createantiair.success"));
            } else {
                event.getPlayer().sendMessage(Translations.get("messages.launchers.createantiair.failure"));
            }
        }
    };
    addItemHandler(blockPlaceHandler);
    BlockDispenseHandler blockDispenseHandler = this::blockDispense;
    addItemHandler(blockDispenseHandler);
    addItemHandler(new BlockTicker() {

        @Override
        public boolean isSynchronized() {
            return true;
        }

        @Override
        public void tick(Block block, SlimefunItem slimefunItem, Config config) {
            TileState state = (TileState) block.getState();
            PersistentDataContainer cont = state.getPersistentDataContainer();
            if (!block.isBlockPowered()) {
                List<MissileController> missiles = MissileWarfare.activemissiles;
                MissileController locked = null;
                if (!missiles.isEmpty()) {
                    for (MissileController missile : missiles) {
                        if (block.getLocation().distanceSquared(missile.pos.toLocation(missile.world)) < range && missile.isgroundmissile) {
                            locked = missile;
                            break;
                        }
                    }
                }
                state.update();
                try {
                    if (locked != null && cont.get(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER) <= System.currentTimeMillis()) {
                        cont.set(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER, (int) System.currentTimeMillis() + 1000);
                        fireMissile((Dispenser) block.getState(), locked);
                    }
                } catch (NullPointerException e) {
                    cont.set(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER, Integer.MIN_VALUE);
                    state.update();
                }
            }
        }
    });
}
Also used : Dispenser(org.bukkit.block.Dispenser) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) Config(me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) BlockTicker(me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker) Directional(org.bukkit.block.data.Directional) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer) TileState(org.bukkit.block.TileState) BlockPlaceHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler) NamespacedKey(org.bukkit.NamespacedKey) Block(org.bukkit.block.Block) BlockDispenseHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler) List(java.util.List) MissileController(me.kaiyan.missilewarfare.Missiles.MissileController) BlockData(org.bukkit.block.data.BlockData)

Example 2 with BlockTicker

use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project Slimefun4 by Slimefun.

the class GPSTransmitter method getItemHandler.

@Override
public BlockTicker getItemHandler() {
    return new BlockTicker() {

        @Override
        public void tick(Block b, SlimefunItem item, Config data) {
            int charge = getCharge(b.getLocation(), data);
            UUID owner = UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"));
            if (charge >= getEnergyConsumption()) {
                Slimefun.getGPSNetwork().updateTransmitter(b.getLocation(), owner, true);
                removeCharge(b.getLocation(), getEnergyConsumption());
            } else {
                Slimefun.getGPSNetwork().updateTransmitter(b.getLocation(), owner, false);
            }
        }

        @Override
        public boolean isSynchronized() {
            return false;
        }
    };
}
Also used : Config(me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config) Block(org.bukkit.block.Block) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) SimpleSlimefunItem(io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem) UUID(java.util.UUID) BlockTicker(me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker)

Example 3 with BlockTicker

use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project Slimefun4 by Slimefun.

the class EnhancedFurnace method getItemHandler.

@Override
public BlockTicker getItemHandler() {
    return new BlockTicker() {

        @Override
        public void tick(Block b, SlimefunItem item, Config data) {
            if (b.getType() != Material.FURNACE) {
                // The Furnace has been destroyed, we can clear the block data
                BlockStorage.clearBlockInfo(b);
            } else {
                BlockStateSnapshotResult result = PaperLib.getBlockState(b, false);
                BlockState state = result.getState();
                // Check if the BlockState is a Furnace and cooking something
                if (state instanceof Furnace && ((Furnace) state).getCookTime() > 0) {
                    setProgress((Furnace) state);
                    // Only update if necessary
                    if (result.isSnapshot()) {
                        state.update(true, false);
                    }
                }
            }
        }

        @Override
        public boolean isSynchronized() {
            // This messes with BlockStates, so it needs to be synchronized
            return true;
        }
    };
}
Also used : BlockState(org.bukkit.block.BlockState) Config(me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config) Block(org.bukkit.block.Block) BlockStateSnapshotResult(io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) SimpleSlimefunItem(io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem) BlockTicker(me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker) Furnace(org.bukkit.block.Furnace)

Example 4 with BlockTicker

use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project Slimefun4 by Slimefun.

the class AbstractEntityAssembler method getItemHandler.

@Override
public BlockTicker getItemHandler() {
    return new BlockTicker() {

        @Override
        public void tick(Block b, SlimefunItem sf, Config data) {
            if ("false".equals(BlockStorage.getLocationInfo(b.getLocation(), KEY_ENABLED))) {
                return;
            }
            if (lifetime % 60 == 0 && getCharge(b.getLocation(), data) >= getEnergyConsumption()) {
                BlockMenu menu = BlockStorage.getInventory(b);
                boolean hasBody = findResource(menu, getBody(), bodySlots);
                boolean hasHead = findResource(menu, getHead(), headSlots);
                if (hasBody && hasHead) {
                    consumeResources(menu);
                    removeCharge(b.getLocation(), getEnergyConsumption());
                    double offset = Double.parseDouble(BlockStorage.getLocationInfo(b.getLocation(), KEY_OFFSET));
                    Slimefun.runSync(() -> {
                        Location loc = new Location(b.getWorld(), b.getX() + 0.5D, b.getY() + offset, b.getZ() + 0.5D);
                        spawnEntity(loc);
                        b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, getHead().getType());
                    });
                }
            }
        }

        @Override
        public void uniqueTick() {
            lifetime++;
        }

        @Override
        public boolean isSynchronized() {
            return false;
        }
    };
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) Config(me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config) Block(org.bukkit.block.Block) SimpleSlimefunItem(io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) BlockTicker(me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker) Location(org.bukkit.Location)

Example 5 with BlockTicker

use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project Slimefun4 by Slimefun.

the class AbstractGrowthAccelerator method preRegister.

@Override
public void preRegister() {
    super.preRegister();
    addItemHandler(new BlockTicker() {

        @Override
        public void tick(Block b, SlimefunItem sf, Config data) {
            AbstractGrowthAccelerator.this.tick(b);
        }

        @Override
        public boolean isSynchronized() {
            return true;
        }
    });
}
Also used : Config(me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config) Block(org.bukkit.block.Block) InventoryBlock(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) BlockTicker(me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker)

Aggregations

BlockTicker (me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker)15 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)13 Config (me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config)13 Block (org.bukkit.block.Block)13 SimpleSlimefunItem (io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem)4 BlockPlaceHandler (io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler)3 Location (org.bukkit.Location)3 BlockPlaceEvent (org.bukkit.event.block.BlockPlaceEvent)3 BlockDispenseHandler (io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler)2 List (java.util.List)2 UUID (java.util.UUID)2 MissileController (me.kaiyan.missilewarfare.Missiles.MissileController)2 InventoryBlock (me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock)2 NamespacedKey (org.bukkit.NamespacedKey)2 Dispenser (org.bukkit.block.Dispenser)2 TileState (org.bukkit.block.TileState)2 BlockData (org.bukkit.block.data.BlockData)2 Directional (org.bukkit.block.data.Directional)2 PersistentDataContainer (org.bukkit.persistence.PersistentDataContainer)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2