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());
}
}
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;
}
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);
}
}
}
}
}
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;
}
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();
}
Aggregations