Search in sources :

Example 1 with BlockPlaceHandler

use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler 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 BlockPlaceHandler

use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project MissileWarfare by koiboi-dev.

the class GroundMissileLauncher method preRegister.

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

        @Override
        public void onPlayerPlace(BlockPlaceEvent event) {
            World world = event.getBlock().getWorld();
            Block below = world.getBlockAt(event.getBlock().getLocation().subtract(new Vector(0, 1, 0)));
            BlockData data = event.getBlockPlaced().getBlockData();
            ((Directional) data).setFacing(BlockFace.UP);
            event.getBlockPlaced().setBlockData(data);
            // Block bottom = world.getBlockAt(event.getBlock().getLocation().subtract(new Vector(0, 2, 0)));
            if (below.getType() == Material.GREEN_CONCRETE) {
                event.getPlayer().sendMessage(Translations.get("messages.launchers.ground.create.success"));
                TileState state = (TileState) event.getBlockPlaced().getState();
                PersistentDataContainer cont = state.getPersistentDataContainer();
                cont.set(new NamespacedKey(MissileWarfare.getInstance(), "canfire"), PersistentDataType.INTEGER, 1);
                state.update();
            /*if (bottom.getType() == Material.GREEN_CONCRETE){
                        event.getPlayer().sendMessage("Created Small Launcher!");
                    }else{
                        event.getPlayer().sendMessage("Bottom Block is type: " + bottom.getType() + " It needs Type GREEN_CONCRETE");
                        event.setCancelled(true);
                    }*/
            } else {
                event.getPlayer().sendMessage(Translations.get("messages.launchers.ground.create.failure").replace("{type}", below.getType().name()));
            }
        }
    };
    addItemHandler(blockPlaceHandler);
    BlockUseHandler blockUseHandler = this::onBlockRightClick;
    addItemHandler(blockUseHandler);
    BlockDispenseHandler blockDispenseHandler = this::blockDispense;
    addItemHandler(blockDispenseHandler);
}
Also used : TileState(org.bukkit.block.TileState) BlockPlaceHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) NamespacedKey(org.bukkit.NamespacedKey) BlockUseHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler) Block(org.bukkit.block.Block) BlockDispenseHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler) World(org.bukkit.World) BlockData(org.bukkit.block.data.BlockData) Vector(org.bukkit.util.Vector) Directional(org.bukkit.block.data.Directional) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer)

Example 3 with BlockPlaceHandler

use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project Slimefun4 by Slimefun.

the class ElevatorPlate method onPlace.

@Nonnull
private BlockPlaceHandler onPlace() {
    return new BlockPlaceHandler(false) {

        @Override
        public void onPlayerPlace(BlockPlaceEvent e) {
            Block b = e.getBlock();
            BlockStorage.addBlockInfo(b, DATA_KEY, ChatColor.WHITE + "Floor #0");
            BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
        }
    };
}
Also used : BlockPlaceHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) Block(org.bukkit.block.Block) Nonnull(javax.annotation.Nonnull)

Example 4 with BlockPlaceHandler

use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project Slimefun4 by Slimefun.

the class HologramProjector method onPlace.

@Nonnull
private BlockPlaceHandler onPlace() {
    return new BlockPlaceHandler(false) {

        @Override
        public void onPlayerPlace(BlockPlaceEvent e) {
            Block b = e.getBlockPlaced();
            BlockStorage.addBlockInfo(b, "text", "Edit me via the Projector");
            BlockStorage.addBlockInfo(b, OFFSET_PARAMETER, "0.5");
            BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
            getArmorStand(b, true);
        }
    };
}
Also used : BlockPlaceHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) Block(org.bukkit.block.Block) Nonnull(javax.annotation.Nonnull)

Example 5 with BlockPlaceHandler

use of io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler in project Slimefun4 by Slimefun.

the class BlockPlacer method onPlace.

@Nonnull
private BlockPlaceHandler onPlace() {
    return new BlockPlaceHandler(false) {

        @Override
        public void onPlayerPlace(BlockPlaceEvent e) {
            Player p = e.getPlayer();
            Block b = e.getBlock();
            BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
        }
    };
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) BlockPlaceHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) Block(org.bukkit.block.Block) Nonnull(javax.annotation.Nonnull)

Aggregations

BlockPlaceHandler (io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler)19 BlockPlaceEvent (org.bukkit.event.block.BlockPlaceEvent)19 Block (org.bukkit.block.Block)16 Nonnull (javax.annotation.Nonnull)12 Player (org.bukkit.entity.Player)5 BlockData (org.bukkit.block.data.BlockData)4 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)3 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)3 BlockDispenseHandler (io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler)3 Config (me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config)3 BlockTicker (me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker)3 NamespacedKey (org.bukkit.NamespacedKey)3 TileState (org.bukkit.block.TileState)3 Directional (org.bukkit.block.data.Directional)3 ItemStack (org.bukkit.inventory.ItemStack)3 PersistentDataContainer (org.bukkit.persistence.PersistentDataContainer)3 BlockUseHandler (io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler)2 List (java.util.List)2 MissileController (me.kaiyan.missilewarfare.Missiles.MissileController)2 Location (org.bukkit.Location)2