Java 类org.bukkit.block.CommandBlock 实例源码

项目:Kineticraft    文件:Puzzle.java   
/**
 * Execute a trigger for this puzzle.
 *
 * Valid Method Signatures:
 * doStuff()
 * doStuff(CommandBlock)
 * @param trigger
 */
public void fireTrigger(String trigger, CommandBlock block) {
    if (!triggers.containsKey(getClass())) // Get and cache the trigger map.
        addTriggers(getClass());

    Map<String, Method> t = triggers.get(getClass());
    if (!t.containsKey(trigger))
        return; // Is this trigger applicable to this puzzle?

    try {
        Method m = t.get(trigger); // Fire the method associated with the trigger.
        PuzzleTrigger pt = m.getAnnotation(PuzzleTrigger.class);
        if (!pt.skipCheck() && !canTrigger())
            return; // If the trigger conditions aren't met, don't execute.

        if (m.getParameterCount() > 0) {
            m.invoke(this, block);
        } else {
            m.invoke(this);
        }
    } catch (Exception e) {
        e.printStackTrace();
        Core.warn("Failed to execute puzzle trigger '" + trigger + "' in " + getClass().getSimpleName() + ".");
    }
}
项目:Kineticraft    文件:GatherPuzzle.java   
@PuzzleTrigger
public void bPress(CommandBlock cmd) {
    buttons--;

    // Play sound.
    cmd.getBlock().getWorld().playSound(cmd.getBlock().getLocation(), Sound.BLOCK_NOTE_PLING, 1F, 2F);

    // Get rid of button
    for (BlockFace face : Utils.CUBE_FACES) {
        Block bk = cmd.getBlock().getRelative(face, 2);
        if (bk.getType() == Material.WOOD_BUTTON)
            bk.setType(Material.AIR);
    }

    if (buttons == 0) {// If there are no buttons left, activate the gold torch.
        GenericItem iw = new GenericItem(ItemManager.createItem(Material.RED_ROSE, ChatColor.RED + "Red Key"));
        iw.setTagString("id", "d1_red");
        Utils.giveItem(Utils.getNearestPlayer(cmd.getLocation(), 15), iw.generateItem());
        cmd.getBlock().getWorld().playSound(cmd.getBlock().getLocation(), Sound.BLOCK_NOTE_PLING, 1F, 0.5F);
    }
}
项目:Kineticraft    文件:MatchPuzzle.java   
@SuppressWarnings("SuspiciousMethodCalls")
@PuzzleTrigger
public void changeColor(CommandBlock block) {
    Block wool = block.getBlock().getRelative(BlockFace.UP);
    int index = COLORS.indexOf(((Wool) wool.getState().getData()).getColor()) + 1;
    wool.setData(COLORS.get(index >= COLORS.size() ? 0 : index).getWoolData());
    scanBoard();
}
项目:Kineticraft    文件:GatherPuzzle.java   
@PuzzleTrigger
public void lightTorch(CommandBlock cmd) {
    Location loc = cmd.getLocation();
    for (int i = 0; i < 10; i++) {
        loc.add(0, 1, 0);
        if (loc.getBlock().getType() == Material.REDSTONE_TORCH_ON)
            resetFakeBlock(loc.getBlock());
    }

    getDungeon().playSound(Sound.BLOCK_NOTE_HARP, 1.25F);
    getDungeon().playSound(Sound.BLOCK_NOTE_HARP, 1F);
}
项目:QuestManager    文件:QuestManager.java   
private void makeAnchors() {
    this.anchors = new HashMap<>();

    for (String worldName : QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getWorlds()) {
        World world = Bukkit.getWorld(worldName);
        if (world == null) {
            continue;
        }

        Location loc = world.getSpawnLocation().clone();
        loc.setY(5);
        loc.getBlock().setType(Material.COMMAND);
        anchors.put(worldName, (CommandBlock) loc.getBlock().getState());
    }
}
项目:Steel    文件:BlockStateSerializer.java   
@SuppressWarnings("deprecation")
public static Optional<String> serializeState(BlockState state) {
    YamlConfiguration yaml = new YamlConfiguration();

    // http://minecraft.gamepedia.com/Block_entity was used as a reference for this method

    if (state instanceof InventoryHolder) {
        yaml.set(INVENTORY_KEY, InventoryHelper.serializeInventory(((InventoryHolder) state).getInventory()));
    }

    if (state instanceof Sign) {
        yaml.set(SIGN_LINES_KEY, Arrays.asList(((Sign) state).getLines()));
    } else if (Support.BANNER && state instanceof Banner) {
        yaml.set(BANNER_BASE_COLOR_KEY, ((Banner) state).getBaseColor().name());
        ConfigurationSection patternSection = yaml.createSection(BANNER_PATTERNS_KEY);
        List<Pattern> patterns = ((Banner) state).getPatterns();
        for (int i = 0; i < patterns.size(); i++) {
            ConfigurationSection subSection = patternSection.createSection("" + i);
            subSection.set(BANNER_PATTERN_COLOR_KEY, patterns.get(i).getColor().name());
            subSection.set(BANNER_PATTERN_TYPE_KEY, patterns.get(i).getPattern().name());
        }
    } else if (state instanceof CreatureSpawner) {
        yaml.set(SPAWNER_TYPE_KEY, ((CreatureSpawner) state).getSpawnedType().name());
        yaml.set(SPAWNER_DELAY_KEY, ((CreatureSpawner) state).getDelay());
    } else if (state instanceof NoteBlock) {
        yaml.set(NOTE_OCTAVE_KEY, ((NoteBlock) state).getNote().getOctave());
        yaml.set(NOTE_TONE_KEY, ((NoteBlock) state).getNote().getTone().name());
    } else if (state instanceof Jukebox) {
        if (((Jukebox) state).isPlaying()) {
            yaml.set(JUKEBOX_DISC_KEY, ((Jukebox) state).getPlaying());
        }
    } else if (state instanceof Skull) {
        yaml.set(SKULL_OWNER_KEY, ((Skull) state).getOwner());
        yaml.set(SKULL_ROTATION_KEY, ((Skull) state).getRotation().name());
    } else if (state instanceof CommandBlock) {
        yaml.set(COMMAND_NAME_KEY, ((CommandBlock) state).getName());
        yaml.set(COMMAND_CMD_KEY, ((CommandBlock) state).getCommand());
    } else if (state instanceof FlowerPot) {
        yaml.set(FLOWER_TYPE_KEY, ((FlowerPot) state).getContents().getItemType().name());
        yaml.set(FLOWER_DATA_KEY, ((FlowerPot) state).getContents().getData());
    }

    if (yaml.getKeys(false).size() > 0) {
        return Optional.of(yaml.saveToString());
    }
    return Optional.absent();
}
项目:MagicLib    文件:MaterialAndData.java   
@SuppressWarnings("deprecation")
public boolean isDifferent(Block block) {
    Material blockMaterial = block.getType();
    byte blockData = block.getData();
    if ((material != null && blockMaterial != material) || (data != null && blockData != data)) {
        return true;
    }

    // Special cases
    if (material == Material.WALL_BANNER || material == Material.STANDING_BANNER) {
        // Can't compare patterns for now
        return true;
    }

    BlockState blockState = block.getState();
    if (blockState instanceof Sign) {
        // Not digging into sign text
        return true;
    } else if (blockState instanceof CommandBlock && extraData != null && extraData instanceof BlockCommand) {
        CommandBlock command = (CommandBlock)blockState;
        if (!command.getCommand().equals(((BlockCommand)extraData).command)) {
            return true;
        }
    } else if (blockState instanceof InventoryHolder) {
        // Just copy it over.... not going to compare inventories :P
        return true;
    }

    return false;
}
项目:MultiCommandBlockPlugin    文件:CommandBlockExt.java   
public void onBlockRedstone(BlockRedstoneEvent event) 
{
    //wenn: am Block  redstone  gebaut/abgebaut   bzw. Signal sich �ndert
    Block block = event.getBlock();
    int iBlockID = block.getTypeId();
    int iPower = 0;
    if ( !(iBlockID==137) )   { return; }
    BlockState blState = event.getBlock().getState();
    if (blState instanceof CommandBlock)   // Kommandoblock
    {
        m_CommandBlock = (CommandBlock)blState;
        try
        {
            iPower = block.getBlockPower();
            if(iPower==0) { return; }
        }  catch  ( Exception exc ) { iPower = 0; return; }
        System.out.println(" MCBP plugin:  Kommandoblock  onBlockRedstone()  ");
        System.out.println(" MCBP plugin:   BlockPower =  " + iPower);

        m_CommandsString = m_CommandBlock.getCommand();

        System.out.println(" MCBP plugin:    " + m_CommandsString);
        // logTo(String sLogStr)
        //  =>  weiter an   CommandParser()
        ParsedCommand[] commands = getCommands(m_CommandsString, block);
        for (int i=0; i < commands.length;i++)
        {   
            //CommandSender oSender = (CommandSender) m_CommandBlock.getBlock();
            //BlockCommandSender bcs = (BlockCommandSender)m_CommandBlock;
            sendeBefehl(commands[i].getCommand());
            System.out.println("send Command: " + commands[i].getCommand());
            try {
                Thread.sleep(commands[i].getInterval());
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
项目:SpectatorPlus    文件:SPUtils.java   
/**
 * @param commandSender A command sender.
 * @return A name for this sender: the player name, or “Command block 'name'”, or “Console”.
 */
public static String getName(CommandSender commandSender)
{
    if (commandSender instanceof Player)
        return ((Player) commandSender).getDisplayName();

    else if (commandSender instanceof CommandBlock)
        return "Command block '" + commandSender.getName() + "'";

    else
        return "Console";
}
项目:Kineticraft    文件:CommandPuzzleTrigger.java   
@Override
protected void onCommand(BlockCommandSender sender, String[] args) {
    getDungeon(sender).triggerPuzzles(args[0], (CommandBlock) sender.getBlock().getState());
}
项目:Kineticraft    文件:Puzzle.java   
@PuzzleTrigger
public void finish(CommandBlock cmd) {
    if (getGateLocation() == null || cmd.getLocation().distance(getGateLocation()) <= 10)
        complete();
}
项目:Kineticraft    文件:LazerPuzzle.java   
@PuzzleTrigger
public void fireLazer(CommandBlock block) {
    getRepeats().clear();
    Block bk = block.getBlock().getRelative(BlockFace.UP);

    BlockFace[] direction = new BlockFace[] {Utils.getDirection(bk)};
    Location lazer = bk.getLocation().add(.5, .15, .5);

    // Shoot the lazer.
    traceTask = addTimerTask(() -> {
        lazer.getWorld().spawnParticle(Particle.REDSTONE, lazer, 1, 0, 0, 0, 0); // Draw trail.

        Block last = lazer.getBlock();
        BlockFace d = direction[0];
        lazer.add(d.getModX() / ((double) PER_BLOCK), 0, d.getModZ() / ((double) PER_BLOCK)); // Move the lazer along its path.
        Block b = lazer.getBlock();

        if (!last.equals(b)) {
            if (b.getType() == Material.AIR)
                return;

            if (b.getType() == Material.DIODE_BLOCK_OFF && !getRepeats().contains(b)) { // Change direction.
                getRepeats().add(b); // Don't allow infinite loops.
                BlockFace newDirection = Utils.getDirection(b);
                if (newDirection.getOppositeFace() != d) { // Cannot activate repeater from the direction it faces.
                    lazer.add(d.getModX() * 0.5, 0, d.getModZ() * 0.5); // Center lazer.
                    activateRepeater(b);
                    direction[0] = newDirection; // Update direction.
                    return;
                }
            }

            // We've hit a wall.
            traceTask.cancel(); // Stop trying to trace the lazer.
            traceTask = null;
            if (b.getType() == Material.BEACON) {// This wall is actually the goal block.
                complete();
            } else { // They failed.
                b.getWorld().spawnEntity(b.getLocation().add(0, 1, 0), EntityType.ZOMBIE);
            }
        }
    }, 1L);
}
项目:QuestManager    文件:QuestManager.java   
public CommandBlock getAnchor(String worldName) {
    return anchors.get(worldName);
}
项目:ArmorStandTools    文件:NMS.java   
private void generateCmdBlockWithOffHand(Location l, ArmorStand as) {
    Location loc = as.getLocation();
    int dSlots = getDisabledSlots(as);
    String hand, boots, legs, chest, helm, offHand;
    int handDmg, offHandDmg;
    hand = as.getEquipment().getItemInMainHand() == null ? "air" : getNmsName(as.getEquipment().getItemInMainHand().getType());
    offHand = as.getEquipment().getItemInOffHand() == null ? "air" : getNmsName(as.getEquipment().getItemInOffHand().getType());
    boots = as.getBoots() == null ? "air" : getNmsName(as.getBoots().getType());
    legs = as.getLeggings() == null ? "air" : getNmsName(as.getLeggings().getType());
    chest = as.getChestplate() == null ? "air" : getNmsName(as.getChestplate().getType());
    helm = as.getHelmet() == null ? "air" : getNmsName(as.getHelmet().getType());
    handDmg = as.getEquipment().getItemInMainHand() == null ? 0 : as.getEquipment().getItemInMainHand().getDurability();
    offHandDmg = as.getEquipment().getItemInOffHand() == null ? 0 : as.getEquipment().getItemInOffHand().getDurability();

    int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability();
    int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability();
    int chestDmg = as.getChestplate() == null ? 0 : as.getChestplate().getDurability();
    int helmDmg = as.getHelmet() == null ? 0 : as.getHelmet().getDurability();
    EulerAngle he = as.getHeadPose();
    EulerAngle ll = as.getLeftLegPose();
    EulerAngle rl = as.getRightLegPose();
    EulerAngle la = as.getLeftArmPose();
    EulerAngle ra = as.getRightArmPose();
    EulerAngle bo = as.getBodyPose();
    String cmd = "summon " + summonEntityName + " " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {"
            + (as.isVisible() ? "" : "Invisible:1,")
            + (as.hasBasePlate() ? "" : "NoBasePlate:1,")
            + (as.hasGravity() ? "" : "NoGravity:1,")
            + (as.hasArms() ? "ShowArms:1," : "")
            + (as.isSmall() ? "Small:1," : "")
            + (isInvulnerable(as) ? "Invulnerable:1," : "")
            + (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ","))
            + (as.isCustomNameVisible() ? "CustomNameVisible:1," : "")
            + (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\","))
            + (loc.getYaw() == 0F ? "" : ("Rotation:[" + Utils.twoDec(loc.getYaw()) + "f],"))
            + (as.getBoots() == null && as.getLeggings() == null && as.getChestplate() == null && as.getHelmet() == null ? "" : (
            "ArmorItems:["
                    + "{id:" + boots + ",Count:" + as.getBoots().getAmount() + ",Damage:" + bootsDmg + getItemStackTags(as.getBoots()) + "},"
                    + "{id:" + legs + ",Count:" + as.getLeggings().getAmount() + ",Damage:" + legsDmg + getItemStackTags(as.getLeggings()) + "},"
                    + "{id:" + chest + ",Count:" + as.getChestplate().getAmount() + ",Damage:" + chestDmg + getItemStackTags(as.getChestplate()) + "},"
                    + "{id:" + helm + ",Count:" + as.getHelmet().getAmount() + ",Damage:" + helmDmg + getItemStackTags(as.getHelmet()) + skullOwner(as.getHelmet()) + "}],"))
            + (as.getEquipment().getItemInMainHand() == null && as.getEquipment().getItemInOffHand() == null ? "" : (
            "HandItems:["
                    + "{id:" + hand + ",Count:" + as.getEquipment().getItemInMainHand().getAmount() + ",Damage:" + handDmg + getItemStackTags(as.getEquipment().getItemInMainHand()) + "},"
                    + "{id:" + offHand + ",Count:" + as.getEquipment().getItemInOffHand().getAmount() + ",Damage:" + offHandDmg + getItemStackTags(as.getEquipment().getItemInOffHand()) + "}],"))
            + "Pose:{"
            + (bo.equals(zero) ? "" : ("Body:[" + Utils.angle(bo.getX()) + "f," + Utils.angle(bo.getY()) + "f," + Utils.angle(bo.getZ()) + "f],"))
            + (he.equals(zero) ? "" : ("Head:[" + Utils.angle(he.getX()) + "f," + Utils.angle(he.getY()) + "f," + Utils.angle(he.getZ()) + "f],"))
            + (ll.equals(zero) ? "" : ("LeftLeg:[" + Utils.angle(ll.getX()) + "f," + Utils.angle(ll.getY()) + "f," + Utils.angle(ll.getZ()) + "f],"))
            + (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],"))
            + (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],"))
            + "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}";
    Block b = l.getBlock();
    b.setType(Material.COMMAND);
    //noinspection deprecation
    b.setData((byte) 0);
    CommandBlock cb = (CommandBlock) b.getState();
    cb.setCommand(cmd);
    cb.update();
}
项目:ArmorStandTools    文件:NMS.java   
@SuppressWarnings("deprecation")
private void generateCmdBlockWithoutOffHand(Location l, ArmorStand as) {
    Location loc = as.getLocation();
    int dSlots = Main.nms.getDisabledSlots(as);
    String hand, boots, legs, chest, helm;
    int handDmg;

    hand = getItemInMainHand(as) == null ? "0" : String.valueOf(getItemInMainHand(as).getTypeId());
    boots = as.getBoots() == null ? "0" : String.valueOf(as.getBoots().getTypeId());
    legs = as.getLeggings() == null ? "0" : String.valueOf(as.getLeggings().getTypeId());
    chest = as.getChestplate() == null ? "0" : String.valueOf(as.getChestplate().getTypeId());
    helm = as.getHelmet() == null ? "0" : String.valueOf(as.getHelmet().getTypeId());
    handDmg = getItemInMainHand(as) == null ? 0 : getItemInMainHand(as).getDurability();

    int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability();
    int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability();
    int chestDmg = as.getChestplate() == null ? 0 : as.getChestplate().getDurability();
    int helmDmg = as.getHelmet() == null ? 0 : as.getHelmet().getDurability();
    EulerAngle he = as.getHeadPose();
    EulerAngle ll = as.getLeftLegPose();
    EulerAngle rl = as.getRightLegPose();
    EulerAngle la = as.getLeftArmPose();
    EulerAngle ra = as.getRightArmPose();
    EulerAngle bo = as.getBodyPose();
    String cmd = "summon ArmorStand " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {"
            + (as.isVisible() ? "" : "Invisible:1,")
            + (as.hasBasePlate() ? "" : "NoBasePlate:1,")
            + (as.hasGravity() ? "" : "NoGravity:1,")
            + (as.hasArms() ? "ShowArms:1," : "")
            + (as.isSmall() ? "Small:1," : "")
            + (Main.nms.isInvulnerable(as) ? "Invulnerable:1," : "")
            + (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ","))
            + (as.isCustomNameVisible() ? "CustomNameVisible:1," : "")
            + (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\","))
            + (loc.getYaw() == 0F ? "" : ("Rotation:[" + Utils.twoDec(loc.getYaw()) + "f],"))
            + (getItemInMainHand(as) == null && as.getBoots() == null && as.getLeggings() == null && as.getChestplate() == null && as.getHelmet() == null ? "" : (
            "Equipment:["
                    + "{id:" + hand + ",Count:" + getItemInMainHand(as).getAmount() + ",Damage:" + handDmg + getItemStackTags(getItemInMainHand(as)) + "},"
                    + "{id:" + boots + ",Count:" + as.getBoots().getAmount() + ",Damage:" + bootsDmg + getItemStackTags(as.getBoots()) + "},"
                    + "{id:" + legs + ",Count:" + as.getLeggings().getAmount() + ",Damage:" + legsDmg + getItemStackTags(as.getLeggings()) + "},"
                    + "{id:" + chest + ",Count:" + as.getChestplate().getAmount() + ",Damage:" + chestDmg + getItemStackTags(as.getChestplate()) + "},"
                    + "{id:" + helm + ",Count:" + as.getHelmet().getAmount() + ",Damage:" + helmDmg + getItemStackTags(as.getHelmet()) + skullOwner(as.getHelmet()) + "}],"))
            + "Pose:{"
            + (bo.equals(zero) ? "" : ("Body:[" + Utils.angle(bo.getX()) + "f," + Utils.angle(bo.getY()) + "f," + Utils.angle(bo.getZ()) + "f],"))
            + (he.equals(zero) ? "" : ("Head:[" + Utils.angle(he.getX()) + "f," + Utils.angle(he.getY()) + "f," + Utils.angle(he.getZ()) + "f],"))
            + (ll.equals(zero) ? "" : ("LeftLeg:[" + Utils.angle(ll.getX()) + "f," + Utils.angle(ll.getY()) + "f," + Utils.angle(ll.getZ()) + "f],"))
            + (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],"))
            + (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],"))
            + "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}";
    Block b = l.getBlock();
    b.setType(Material.COMMAND);
    b.setData((byte) 0);
    CommandBlock cb = (CommandBlock) b.getState();
    cb.setCommand(cmd);
    cb.update();
}
项目:MagicLib    文件:MaterialAndData.java   
@SuppressWarnings("deprecation")
public void updateFrom(Block block, Set<Material> restrictedMaterials) {
    if (block == null) {
        isValid = false;
        return;
    }
    if (!block.getChunk().isLoaded()) {
        block.getChunk().load(true);
        return;
    }

    Material blockMaterial = block.getType();
    if (restrictedMaterials != null && restrictedMaterials.contains(blockMaterial)) {
        isValid = false;
        return;
    }
    // Look for special block states
    extraData = null;

    material = blockMaterial;
    data = (short)block.getData();

    try {
        BlockState blockState = block.getState();
        if (material == Material.FLOWER_POT || blockState instanceof InventoryHolder || blockState instanceof Sign) {
            extraData = new BlockTileEntity(NMSUtils.getTileEntityData(block.getLocation()));
        } else if (blockState instanceof CommandBlock){
            // This seems to occasionally throw exceptions...
            CommandBlock command = (CommandBlock)blockState;
            extraData = new BlockCommand(command.getCommand(), command.getName());
        } else if (blockState instanceof Skull) {
            Skull skull = (Skull)blockState;
            data = (short)skull.getSkullType().ordinal();
            extraData = new BlockSkull(CompatibilityUtils.getSkullProfile(skull), skull.getSkullType(), skull.getRotation());
        } else if (blockState instanceof CreatureSpawner) {
            CreatureSpawner spawner = (CreatureSpawner)blockState;
            extraData = new BlockMobSpawner(spawner.getCreatureTypeName());
        } else if (blockMaterial == Material.STANDING_BANNER || blockMaterial == Material.WALL_BANNER) {
            if (blockState != null && blockState instanceof Banner) {
                Banner banner = (Banner)blockState;
                DyeColor color = banner.getBaseColor();
                extraData = new BlockBanner(banner.getPatterns(), color);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    isValid = true;
}
项目:MagicLib    文件:MaterialAndData.java   
@SuppressWarnings("deprecation")
public void modify(Block block, boolean applyPhysics) {
    if (!isValid) return;

    try {
        BlockState blockState = block.getState();
        // Clear chests so they don't dump their contents.
        if (blockState instanceof InventoryHolder) {
            NMSUtils.clearItems(block.getLocation());
        }

        if (material != null) {
            byte blockData = data != null ? (byte)(short)data : block.getData();
            block.setTypeIdAndData(material.getId(), blockData, applyPhysics);
            blockState = block.getState();
        }

        // Set tile entity data first
        // Command blocks still prefer internal data for parameterized commands
        if (blockState != null && blockState instanceof CommandBlock && extraData != null && extraData instanceof BlockCommand) {
            CommandBlock command = (CommandBlock)blockState;
            BlockCommand commandData = (BlockCommand)extraData;
            command.setCommand(commandData.command);
            if (commandData.customName != null) {
                command.setName(commandData.customName);
            }
            command.update();
        } else if (extraData != null && extraData instanceof BlockTileEntity) {
            // Tile entity data overrides everything else, and may replace all of this in the future.
            NMSUtils.setTileEntityData(block.getLocation(), ((BlockTileEntity) extraData).data);
        } else if (blockState != null && (material == Material.STANDING_BANNER || material == Material.WALL_BANNER) && extraData != null && extraData instanceof BlockBanner) {
            if (blockState != null && blockState instanceof Banner) {
                BlockBanner bannerData = (BlockBanner)extraData;
                Banner banner = (Banner)blockState;
                if (bannerData.patterns != null)
                {
                    banner.setPatterns(bannerData.patterns);
                }
                if (bannerData.baseColor != null)
                {
                    banner.setBaseColor(bannerData.baseColor);
                }
            }
            blockState.update(true, false);
        } else if (blockState != null && blockState instanceof Skull && extraData != null && extraData instanceof BlockSkull) {
            Skull skull = (Skull)blockState;
            BlockSkull skullData = (BlockSkull)extraData;
            if (skullData.skullType != null) {
                skull.setSkullType(skullData.skullType);
            }
            if (skullData.rotation != null) {
                skull.setRotation(skullData.rotation);
            }
            if (skullData.profile != null) {
                CompatibilityUtils.setSkullProfile(skull, skullData.profile);
            }
            skull.update(true, false);
        } else if (blockState != null && blockState instanceof CreatureSpawner && extraData != null && extraData instanceof BlockMobSpawner) {
            BlockMobSpawner spawnerData = (BlockMobSpawner)extraData;
            if (spawnerData.mobName != null && !spawnerData.mobName.isEmpty())
            {
                CreatureSpawner spawner = (CreatureSpawner)blockState;
                spawner.setCreatureTypeByName(spawnerData.mobName);
                spawner.update();
            }
        }
    } catch (Exception ex) {
        Bukkit.getLogger().warning("Error updating block state: " + ex.getMessage());
    }
}
项目:NucleusFramework    文件:SerializableBlockEntity.java   
/**
 * Constructor.
 *
 * @param blockState  The {@link org.bukkit.block.BlockState} that needs to be serialized.
 */
public SerializableBlockEntity(BlockState blockState) {
    PreCon.notNull(blockState);

    _location = blockState.getLocation();
    _material = blockState.getType();
    _data = blockState.getRawData();

    if (blockState instanceof InventoryHolder) {
        _contents = ((InventoryHolder) blockState).getInventory().getContents();
    }

    if (blockState instanceof CommandBlock) {
        CommandBlock commandBlock = (CommandBlock)blockState;
        _commandName = commandBlock.getName();
        _command = commandBlock.getCommand();
    }

    if (blockState instanceof CreatureSpawner) {
        CreatureSpawner spawner = (CreatureSpawner)blockState;
        _creatureTypeName = spawner.getCreatureTypeName();
        _creatureDelay = spawner.getDelay();
    }

    if (blockState instanceof NoteBlock) {
        NoteBlock noteBlock = (NoteBlock)blockState;

        _noteTone = noteBlock.getNote().getTone();
        _noteOctave = noteBlock.getNote().getOctave();
        _noteSharped = noteBlock.getNote().isSharped();
    }

    if (blockState instanceof Sign) {
        Sign sign = (Sign)blockState;

        _signLines = sign.getLines().clone();
    }

    if (blockState instanceof Skull) {
        Skull skull =  (Skull)blockState;

        _skullType = skull.getSkullType();
        _skullRotation = skull.getRotation();
        _skullOwner = skull.getOwner();
    }
}
项目:NucleusFramework    文件:SerializableBlockEntity.java   
private void applyTile(BlockState blockState) {

        boolean requiresUpdate = false;

        // InventoryHolder
        if (blockState instanceof InventoryHolder && _contents != null) {
            InventoryHolder holder = (InventoryHolder)blockState;

            Inventory inventory = holder.getInventory();

            inventory.setContents(_contents);

            requiresUpdate = true;
        }

        // CommandBlock
        if (blockState instanceof CommandBlock) {
            CommandBlock commandBlock = (CommandBlock)blockState;

            if (_commandName != null)
                commandBlock.setName(_commandName);

            if (_command != null)
                commandBlock.setCommand(_command);

            requiresUpdate = true;
        }

        // CreatureSpawner
        if (blockState instanceof CreatureSpawner) {
            CreatureSpawner spawner = (CreatureSpawner)blockState;

            if (_creatureTypeName != null) {
                spawner.setCreatureTypeByName(_creatureTypeName);
                spawner.setDelay(_creatureDelay);
            }

            requiresUpdate = true;
        }

        if (blockState instanceof NoteBlock && _noteTone != null) {
            NoteBlock noteBlock = (NoteBlock)blockState;

            Note note = new Note(_noteOctave, _noteTone, _noteSharped);
            noteBlock.setNote(note);

            requiresUpdate = true;
        }

        if (blockState instanceof Sign && _signLines != null) {
            Sign sign = (Sign)blockState;

            for (int i=0; i < 4; i++)
                sign.setLine(i, _signLines[i]);

            requiresUpdate = true;
        }

        if (blockState instanceof Skull && _skullType != null) {
            Skull skull =  (Skull)blockState;

            skull.setSkullType(_skullType);
            skull.setRotation(_skullRotation);
            skull.setOwner(_skullOwner);

            requiresUpdate = true;
        }

        if (requiresUpdate) {
            blockState.update(true);
        }
    }
项目:MultiCommandBlockPlugin    文件:main_MCBP.java   
@Override
public boolean onCommand(CommandSender cs, Command cmd, String strLabel, String[] args) 
{
    if(cmd.getName().equals("MCB")) 
    {
        if(args.length == 0)  //  nur  /MCB  ohne Params
        {
            if(bLogToConsole==true)  { System.out.println("  MCB   sendet ...   "); }
            return true;
        }
        else
        {
            if ((cs instanceof BlockCommandSender)) 
            {
                final BlockCommandSender blockCmdSender = (BlockCommandSender)cs;
                Block block = blockCmdSender.getBlock();
                CommandBlock m_CommandBlock = (CommandBlock)block.getState();
                m_CommandsString = m_CommandBlock.getCommand();
                System.out.println("     ");
                System.out.println(" BlockCommandSender sendet ... ");
                System.out.println("     " + m_CommandsString );
                ParsedCommand[] commands = getCommands(m_CommandsString, block);

                int iVorGesTime = 0;
                for (int i=0; i < commands.length;i++)
                {   
                    final String fiStr = commands[i].getCommand();
                    int iIntTime = 0;
                    if(i == 0) {
                        iIntTime = commands[i].getInterval() * 20;
                        iVorGesTime += iIntTime;
                    }
                    else {
                        iIntTime = iVorGesTime + (commands[i].getInterval() * 20);
                        iVorGesTime += iIntTime;
                    }

                    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() 
                    {
                        public void run() 
                        {
                            //hier rein:  sendeBefehl 
                            sendeBefehl(blockCmdSender, fiStr);
                        }
                    }, iIntTime );   //   * 20  ????

                    /*
                    try {
                        Thread.sleep(commands[i].getInterval());  // commands[i].getInterval()
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    */
                }
            }
            return true;
        }
    }
    return false;
}
项目:Kineticraft    文件:Dungeon.java   
/**
 * Fire a trigger for all of the puzzles in this dungeon.
 * @param trigger
 * @param block
 */
public void triggerPuzzles(String trigger, CommandBlock block) {
    getPuzzles().forEach(p -> p.fireTrigger(trigger, block));
}