Search in sources :

Example 1 with BlockData

use of org.bukkit.block.data.BlockData in project Minigames by AddstarMC.

the class BlockDataFlag method loadValue.

@Override
public void loadValue(String path, FileConfiguration config) {
    String obj = config.getString(path + "." + getName());
    BlockData data = null;
    try {
        data = Bukkit.createBlockData(obj);
    } catch (IllegalArgumentException e) {
        data = parseOldMaterialData(path, config);
    }
    if (data != null)
        setFlag(data);
    else {
        setFlag(Material.STONE.createBlockData());
    }
}
Also used : BlockData(org.bukkit.block.data.BlockData) MenuItemBlockData(au.com.mineauz.minigames.menu.MenuItemBlockData)

Example 2 with BlockData

use of org.bukkit.block.data.BlockData in project Minigames by AddstarMC.

the class SetBlockAction method displayMenu.

@Override
public boolean displayMenu(MinigamePlayer player, Menu previous) {
    Menu m = new Menu(3, "Set Block", player);
    final MinigamePlayer fply = player;
    m.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), previous), m.getSize() - 9);
    m.addItem(new MenuItemBlockData("Type", Material.STONE, new Callback<BlockData>() {

        @Override
        public void setValue(BlockData value) {
            type.setFlag(value);
        }

        @Override
        public BlockData getValue() {
            return type.getFlag();
        }
    }));
    m.addItem(useBlockData.getMenuItem("Use Specific BlockData", Material.ENDER_PEARL));
    m.displayMenu(player);
    return true;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) BlockData(org.bukkit.block.data.BlockData)

Example 3 with BlockData

use of org.bukkit.block.data.BlockData in project Minigames by AddstarMC.

the class SwapBlockAction method executeRegionAction.

@Override
public void executeRegionAction(MinigamePlayer player, Region region) {
    debug(player, region);
    for (int y = region.getFirstPoint().getBlockY(); y <= region.getSecondPoint().getBlockY(); y++) {
        for (int x = region.getFirstPoint().getBlockX(); x <= region.getSecondPoint().getBlockX(); x++) {
            for (int z = region.getFirstPoint().getBlockZ(); z <= region.getSecondPoint().getBlockZ(); z++) {
                Block block = region.getFirstPoint().getWorld().getBlockAt(x, y, z);
                if (block.getBlockData().getMaterial() == matchType.getFlag().getMaterial()) {
                    if (matchData.getFlag() && block.getBlockData() != matchType.getFlag()) {
                        continue;
                    }
                    // Block matches, now replace it
                    BlockData newBlockData;
                    BlockFace facing = null;
                    if (toData.getFlag()) {
                        // Replace data
                        newBlockData = toType.getFlag();
                    } else {
                        // just create a new instance of the  Materials default blockdata
                        newBlockData = toType.getFlag().getMaterial().createBlockData();
                    }
                    if (keepAttachment.getFlag()) {
                        // Keep attachments if possible
                        BlockData data = block.getBlockData();
                        if (data instanceof Directional) {
                            facing = ((Directional) data).getFacing();
                        }
                    }
                    if (newBlockData instanceof Directional)
                        ((Directional) newBlockData).setFacingDirection(facing);
                    // Update block type
                    block.setBlockData(newBlockData);
                }
            }
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData) Directional(org.bukkit.material.Directional)

Example 4 with BlockData

use of org.bukkit.block.data.BlockData in project Minigames by AddstarMC.

the class SwapBlockAction method displayMenu.

@Override
public boolean displayMenu(MinigamePlayer player, Menu previous) {
    Menu m = new Menu(3, "Swap Block", player);
    m.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), previous), m.getSize() - 9);
    final MinigamePlayer fply = player;
    m.addItem(new MenuItemBlockData("Match Block", Material.COBBLESTONE, new Callback<BlockData>() {

        @Override
        public void setValue(BlockData value) {
            matchType.setFlag(value);
        }

        @Override
        public BlockData getValue() {
            return matchType.getFlag();
        }
    }));
    m.addItem(matchData.getMenuItem("Match Block Use Data?", Material.ENDER_PEARL));
    m.addItem(new MenuItemNewLine());
    m.addItem(new MenuItemBlockData("To Block", Material.STONE, new Callback<BlockData>() {

        @Override
        public void setValue(BlockData value) {
            toType.setFlag(value);
        }

        @Override
        public BlockData getValue() {
            return toType.getFlag();
        }
    }));
    m.addItem(toData.getMenuItem("To Block Use Data?", Material.ENDER_PEARL));
    m.addItem(keepAttachment.getMenuItem("Keep Attachment", Material.PISTON, MinigameUtils.stringToList("When on, and To Block Use Data is off;If the source and target block;types are both blocks that;attach to surfaces, this;attachment will be preserved")));
    m.displayMenu(player);
    return true;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) BlockData(org.bukkit.block.data.BlockData)

Example 5 with BlockData

use of org.bukkit.block.data.BlockData in project Minigames by AddstarMC.

the class MenuItemBlockData method onClickWithItem.

@Override
public ItemStack onClickWithItem(ItemStack item) {
    try {
        BlockData data = item.getType().createBlockData();
        this.data.setValue(data);
    } catch (IllegalArgumentException e) {
        String name = "unknown";
        if (item != null) {
            name = item.getType().name();
        }
        getContainer().getViewer().sendMessage(name + " cannot be made into a block!", MinigameMessageType.ERROR);
    }
    return getItem();
}
Also used : BlockData(org.bukkit.block.data.BlockData)

Aggregations

BlockData (org.bukkit.block.data.BlockData)34 Block (org.bukkit.block.Block)10 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)8 Location (org.bukkit.Location)7 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)3 ArrayList (java.util.ArrayList)3 Material (org.bukkit.Material)3 BlockState (org.bukkit.block.BlockState)3 Lightable (org.bukkit.block.data.Lightable)3 ItemStack (org.bukkit.inventory.ItemStack)3 LocationTag (com.denizenscript.denizen.objects.LocationTag)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 MaterialState (me.botsko.prism.api.objects.MaterialState)2 BlockStateChangeImpl (me.botsko.prism.events.BlockStateChangeImpl)2 Bisected (org.bukkit.block.data.Bisected)2 Bed (org.bukkit.block.data.type.Bed)2 Player (org.bukkit.entity.Player)2