本文整理汇总了Java中org.bukkit.material.Attachable类的典型用法代码示例。如果您正苦于以下问题:Java Attachable类的具体用法?Java Attachable怎么用?Java Attachable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attachable类属于org.bukkit.material包,在下文中一共展示了Attachable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateBlockBehindJoinSigns
import org.bukkit.material.Attachable; //导入依赖的package包/类
/**
* Updates the blocks behind the signs according to the values given in the configuration.
* @param arena The arena wherefrom the signs need to be updated.
*/
@SuppressWarnings("deprecation")
private void updateBlockBehindJoinSigns(Arena arena){
for (Sign sign : arena.getSigns()) {
MaterialData signMaterialData = sign.getBlock().getState().getData();
if (signMaterialData instanceof Attachable) {
Block attachedBlock = sign.getBlock().getRelative(((Attachable) signMaterialData).getAttachedFace());
DyeColor dyeColor = gameStatesColor.get(arena.getState());
attachedBlock.setType(Material.STAINED_GLASS);
if (dyeColor != null) {
//((Colorable) attachedBlock.getState()).setColor((gameStatesColor.get(arena.getState())));
//No other viable method found for setting the color of stained glass. Above method does not work but who knows, in the future.
attachedBlock.setData((byte) dyeColor.ordinal());
attachedBlock.getState().update();
} else
Main.getInstance().getLogger().warning("Wrong input at config.yml at signs.glass-colors." +
arena.getState().toString().toLowerCase(Locale.getDefault()));
}
}
}
示例2: getConnectedBelow
import org.bukkit.material.Attachable; //导入依赖的package包/类
public static Block getConnectedBelow(Location location)
{
Block block = location.getBlock().getWorld().getBlockAt(location.getBlockX(), location.getBlockY() - 1, location.getBlockZ());
switch (block.getType())
{
case LEVER:
case STONE_BUTTON:
case WOOD_BUTTON:
Attachable at = (Attachable) block.getState().getData();
if (at.getAttachedFace() == BlockFace.UP)
return block;
return null;
default:
return null;
}
}
示例3: getAttachedBlock
import org.bukkit.material.Attachable; //导入依赖的package包/类
private Block getAttachedBlock(Block block) {
MaterialData data = block.getState().getData();
if (data instanceof Attachable) {
return block.getRelative(((Attachable) data).getAttachedFace());
}
return null;
}
示例4: checkAttachable
import org.bukkit.material.Attachable; //导入依赖的package包/类
private static boolean checkAttachable(final BlockState block, final BlockFace face) {
if (block.getData() instanceof Attachable) {
final Attachable a = (Attachable) block.getData();
return a.getAttachedFace().getOppositeFace().equals(face);
}
return false;
}
示例5: update
import org.bukkit.material.Attachable; //导入依赖的package包/类
public boolean update(boolean force, boolean applyPhysics) {
requirePlaced();
Block block = getBlock();
if (block.getType() != getType()) {
if (!force) {
return false;
}
}
BlockPosition pos = new BlockPosition(x, y, z);
IBlockData newBlock = CraftMagicNumbers.getBlock(getType()).fromLegacyData(getRawData());
block.setTypeIdAndData(getTypeId(), getRawData(), applyPhysics);
world.getHandle().notify(
pos,
CraftMagicNumbers.getBlock(block).fromLegacyData(block.getData()),
newBlock,
3
);
// Update levers etc
if (applyPhysics && getData() instanceof Attachable) {
world.getHandle().applyPhysics(pos.shift(CraftBlock.blockFaceToNotch(((Attachable) getData()).getAttachedFace())), newBlock.getBlock());
}
return true;
}
示例6: getAttachedFace
import org.bukkit.material.Attachable; //导入依赖的package包/类
private static BlockFace getAttachedFace(Block lever) {
BlockState state = lever.getState();
MaterialData md = state.getData();
if (md instanceof Attachable) {
BlockFace face = ((Attachable) md).getAttachedFace();
return face.getOppositeFace();
} else {
return null;
}
}
示例7: setLever
import org.bukkit.material.Attachable; //导入依赖的package包/类
/**
* Sets the toggled state of a single lever<br>
* <b>No Lever type check is performed</b>
*
* @param lever block
* @param down state to set to
*/
private static void setLever(org.bukkit.block.Block lever, boolean down) {
if (lever.getType() != Material.LEVER) {
return;
}
byte data = lever.getData();
int newData;
if (down) {
newData = data | 0x8;
} else {
newData = data & 0x7;
}
if (newData != data) {
// CraftBukkit start - Redstone event for lever
int old = !down ? 1 : 0;
int current = down ? 1 : 0;
BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(lever, old, current);
Bukkit.getServer().getPluginManager().callEvent(eventRedstone);
if ((eventRedstone.getNewCurrent() > 0) != down) {
return;
}
// CraftBukkit end
lever.setData((byte) newData, true);
lever.getState().update();
Block attached = lever.getRelative(((Attachable) lever.getState().getData()).getAttachedFace());
}
}
示例8: getSignFacingFromWorld
import org.bukkit.material.Attachable; //导入依赖的package包/类
private BlockFace getSignFacingFromWorld() {
// try getting the current sign facing from the sign in the world:
Sign sign = this.getSign();
if (sign != null) {
return ((Attachable) sign.getData()).getFacing();
}
return null;
}
示例9: spawn
import org.bukkit.material.Attachable; //导入依赖的package包/类
@Override
public boolean spawn() {
Location signLocation = this.getActualLocation();
if (signLocation == null) return false;
Block signBlock = signLocation.getBlock();
if (signBlock.getType() != Material.AIR) {
return false;
}
// place sign: // TODO maybe also allow non-wall signs?
// cancel block physics for this placed sign if needed:
ShopkeepersPlugin.getInstance().cancelNextBlockPhysics(signLocation);
signBlock.setType(Material.WALL_SIGN);
// cleanup state if no block physics were triggered:
ShopkeepersPlugin.getInstance().cancelNextBlockPhysics(null);
// in case sign placement has failed for some reason:
if (!Utils.isSign(signBlock.getType())) {
return false;
}
// set sign facing:
if (signFacing != null) {
Sign signState = (Sign) signBlock.getState();
((Attachable) signState.getData()).setFacingDirection(signFacing);
// apply facing:
signState.update();
}
// init sign content:
updateSign = false;
this.updateSign();
return true;
}
示例10: getConnectedAbove
import org.bukkit.material.Attachable; //导入依赖的package包/类
public static Block getConnectedAbove(Location location)
{
Block b = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ());
switch (b.getType())
{
case SAPLING:
//Rails
case RAILS:
case POWERED_RAIL:
case DETECTOR_RAIL:
case ACTIVATOR_RAIL:
case LONG_GRASS:
case DEAD_BUSH:
case YELLOW_FLOWER:
case RED_ROSE:
case BROWN_MUSHROOM:
case RED_MUSHROOM:
case TORCH:
case REDSTONE_WIRE:
case WHEAT:
case SIGN_POST:
//Doors
case WOOD_DOOR:
case ACACIA_DOOR:
case BIRCH_DOOR:
case DARK_OAK_DOOR:
case IRON_DOOR:
case JUNGLE_DOOR:
case SPRUCE_DOOR:
case LEVER:
//Pressure Plates
case GOLD_PLATE:
case IRON_PLATE:
case STONE_PLATE:
case WOOD_PLATE:
case REDSTONE_TORCH_ON:
case REDSTONE_TORCH_OFF:
case SUGAR_CANE_BLOCK:
case CACTUS:
case REDSTONE_COMPARATOR_OFF:
case REDSTONE_COMPARATOR_ON:
case MELON_STEM:
case PUMPKIN_STEM:
case NETHER_STALK:
case TRIPWIRE:
case FLOWER_POT:
case CARROT:
case POTATO:
case ANVIL:
case SKULL:
case CARPET:
case DOUBLE_PLANT:
case STANDING_BANNER:
case ARMOR_STAND:
//Block b = block.getWorld().getBlockAt(x, y, z);
// handle torches, levers, etc. above but connected to another block
switch (b.getType())
{
case TORCH:
case REDSTONE_TORCH_OFF:
case REDSTONE_TORCH_ON:
case LEVER:
Attachable t = (Attachable) b.getState().getData();
if (t.getAttachedFace() != BlockFace.DOWN)
return null;
else
return b;
default:
return b;
}
default:
return null;
}
}
示例11: getConnectedSide
import org.bukkit.material.Attachable; //导入依赖的package包/类
public static Block getConnectedSide(Location location, BlockFace side)
{
// int x = location.getBlockX();
// int y = location.getBlockY();
// int z = location.getBlockZ();
Block block = location.getBlock().getRelative(side);
Block b = location.getBlock();
Bukkit.getLogger().info("Block: " + block.getX() + ", " + block.getY() + ", " + block.getZ());
Bukkit.getLogger().info("Side block: " + b.getX() + ", " + b.getY() + ", " + b.getZ());
switch (block.getType())
{
// case 50:
//case 65:
// case 75:
//case 76:
// case 68:
// case 69:
// case 77:
// case 96:
case TORCH:
case LADDER:
case WALL_SIGN:
case LEVER:
case REDSTONE_TORCH_ON:
case REDSTONE_TORCH_OFF:
case STONE_BUTTON:
case WOOD_BUTTON:
case TRAP_DOOR:
case IRON_TRAPDOOR:
case WALL_BANNER:
BlockFace face = ((Attachable) (block.getState().getData())).getAttachedFace().getOppositeFace();
if (b.getRelative(face).getX() == block.getX() && b.getRelative(face).getZ() == block.getZ())
{
return block;
}
return null;
case TRIPWIRE_HOOK:
BlockFace face2 = ((Directional) (block.getState().getData())).getFacing().getOppositeFace();
if (b.getRelative(face2).getX() == block.getX() && b.getRelative(face2).getZ() == block.getZ())
{
return block;
}
return null;
//case 27:
//case 28:
//case 66:
case RAILS:
case ACTIVATOR_RAIL:
case DETECTOR_RAIL:
case POWERED_RAIL:
Rails rail = (Rails) block.getState().getData();
if (rail.isOnSlope())
{
BlockFace face1 = rail.getDirection().getOppositeFace();
if (b.getRelative(face1).getX() == block.getX() && b.getRelative(face1).getZ() == block.getZ())
{
return block;
}
}
default:
return null;
}
}
示例12: execute
import org.bukkit.material.Attachable; //导入依赖的package包/类
@Override
public boolean execute(Plugin plugin, CommandSender sender, String[] args) {
notFromConsole(sender);
Player player = (Player) sender;
BaseSTBItem item = SensibleToolbox.getItemRegistry().fromItemStack(player.getItemInHand());
BaseSTBBlock stb = null;
Chargeable c = null;
if (item != null && item instanceof Chargeable) {
c = (Chargeable) item;
} else {
// maybe there's a chargeable block targeted
Block b = player.getTargetBlock(null, 10);
if (b != null) {
if (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
Sign s = (Sign) b.getState();
b = b.getRelative(((Attachable) s.getData()).getAttachedFace());
}
stb = LocationManager.getManager().get(b.getLocation());
if (stb != null && stb instanceof Chargeable) {
c = (Chargeable) stb;
}
}
}
DHValidate.notNull(c, "Nothing suitable to charge.");
int max = c.getMaxCharge();
int amount;
if (args.length > 0) {
try {
amount = Integer.parseInt(args[0]);
Validate.isTrue(amount >= 0 && amount <= max, "Must be in range 0-" + max);
} catch (IllegalArgumentException e) {
throw new DHUtilsException("Invalid value: " + args[0] + " - " + e.getMessage());
}
} else {
amount = max;
}
c.setCharge(amount);
if (item != null) {
player.setItemInHand(item.toItemStack());
} else if (stb != null) {
stb.update(true);
MiscUtil.statusMessage(player, "&6" + stb.getItemName() + "&- charged to " + STBUtil.getChargeString(c));
}
return true;
}
示例13: redstoneChange
import org.bukkit.material.Attachable; //导入依赖的package包/类
/**
* Called when a block is charged.
* When the furnace block is powered, starts the factory and toggles on any attached levers.
* On completion, toggles off any attached levers.
*/
@EventHandler()
public void redstoneChange(BlockRedstoneEvent e)
{
// Only trigger on transition from 0 to positive
if (e.getOldCurrent() > 0 || e.getNewCurrent() == 0) {
return;
}
// Allow this to be disabled with config
if (!FactoryModPlugin.REDSTONE_START_ENABLED) {
return;
}
Block rsBlock = e.getBlock();
BlockFace[] directions = null;
if (rsBlock.getType() == Material.REDSTONE_WIRE) {
directions = ProductionFactory.REDSTONE_FACES;
} else if (rsBlock.getType() == Material.WOOD_BUTTON) {
directions = new BlockFace[] {((Attachable) rsBlock.getState().getData()).getAttachedFace()};
} else if (rsBlock.getType() == Material.STONE_BUTTON) {
directions = new BlockFace[] {((Attachable) rsBlock.getState().getData()).getAttachedFace()};
} else if (rsBlock.getType() == Material.LEVER) {
directions = new BlockFace[] {((Attachable) rsBlock.getState().getData()).getAttachedFace()};
} else {
return; // Don't care
}
for (BlockFace direction : directions) {
Block block = rsBlock.getRelative(direction);
//Is the block part of a factory?
if(block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE)
{
if (factoryMan.factoryExistsAt(block.getLocation()))
{
//Is the factory a production factory?
if (productionMan.factoryExistsAt(block.getLocation()))
{
ProductionFactory factory = (ProductionFactory) productionMan.getFactory(block.getLocation());
Block lever = factory.findActivationLever();
if (lever == null) {
// No lever - don't respond to redstone
return;
}
if (!factory.getActive()) {
// Try to start the factory
factory.togglePower();
}
}
}
}
}
}
示例14: getAttached
import org.bukkit.material.Attachable; //导入依赖的package包/类
private static Block getAttached(Sign sign) {
Attachable data = (Attachable) sign.getData();
BlockFace attachingBlockFace = data.getFacing().getOppositeFace();
return sign.getBlock().getRelative(attachingBlockFace);
}
示例15: findSupportingBlock
import org.bukkit.material.Attachable; //导入依赖的package包/类
/**
* Gets the block that supports the given block. If the returned block is
* destroyed, the given block is destroyed too.
*
* For blocks that are self-supporting (most blocks in Minecraft), the
* method returns the block itself.
*
* @param block
* The block.
* @return The block the given block is attached on.
*/
public Block findSupportingBlock(Block block) {
MaterialData data = BlockData.get(block);
if (data instanceof Attachable) {
return block.getRelative(((Attachable) data).getAttachedFace());
}
return block;
}