Package com.sk89q.craftbook

Examples of com.sk89q.craftbook.ChangedSign


                    //Boom, headshot.
                    Block sign = block.getRelative(BlockFace.DOWN);

                    if(SignUtil.isSign(sign)) {
                        final ChangedSign s = BukkitUtil.toChangedSign(sign);

                        if(s.getLine(1).equals("[Jump]")) {

                            CraftBookPlugin.logDebugMessage("Jump sign found where player jumped!", "bounce-blocks");

                            double x = 0,y = 0,z = 0;
                            boolean straight = s.getLine(2).startsWith("!");

                            String[] bits = RegexUtil.COMMA_PATTERN.split(StringUtils.replace(s.getLine(2), "!", ""));
                            if(bits.length == 0)
                                y = 0.5;
                            if(bits.length == 1)
                                y = Double.parseDouble(bits[0]);
                            else {
View Full Code Here


        if(!EventUtil.passesFilter(event)) return;

        if(!allowRedstone) return;
        Block block = event.getBlock();
        if (SignUtil.isSign(block)) {
            ChangedSign sign = BukkitUtil.toChangedSign(block);

            if(!sign.getLine(1).equals("[Chunk]")) return;

            sign.setLine(3, event.getNewCurrent() > event.getOldCurrent() ? "on" : "off");
            sign.update(false);
        }
    }
View Full Code Here

        LocalPlayer localPlayer = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());

        Block trigger = null;

        if (SignUtil.isSign(event.getClickedBlock())) {
            ChangedSign s = BukkitUtil.toChangedSign(event.getClickedBlock());
            if (!s.getLine(1).equals("[Teleporter]")) return;
            String[] pos = RegexUtil.COLON_PATTERN.split(s.getLine(2));
            if (pos.length <= 2) {
                localPlayer.printError("mech.teleport.invalidcoords");
                return;
            }
            trigger = event.getClickedBlock();
        } else if (event.getClickedBlock().getType() == Material.STONE_BUTTON || event.getClickedBlock().getType() == Material.WOOD_BUTTON) {
            Button b = (Button) event.getClickedBlock().getState().getData();
            if(b == null || b.getAttachedFace() == null) return;
            Block sign = event.getClickedBlock().getRelative(b.getAttachedFace(), 2);
            if (SignUtil.isSign(sign)) {
                ChangedSign s = BukkitUtil.toChangedSign(sign);
                if (!s.getLine(1).equals("[Teleporter]")) return;
                String[] pos = RegexUtil.COLON_PATTERN.split(s.getLine(2));
                if (pos.length <= 2) {
                    localPlayer.printError("mech.teleport.invalidcoords");
                    return;
                }
                trigger = sign;
View Full Code Here

        double toX = 0;
        double toY = 0;
        double toZ = 0;

        if (SignUtil.isSign(trigger)) {
            ChangedSign s = BukkitUtil.toChangedSign(trigger);
            String[] pos = RegexUtil.COLON_PATTERN.split(s.getLine(2));
            if (pos.length > 2) {
                try {
                    toX = Double.parseDouble(pos[0]);
                    toY = Double.parseDouble(pos[1]);
                    toZ = Double.parseDouble(pos[2]);
View Full Code Here

        if (!SignUtil.isSign(sign)) {
            player.printError("mech.teleport.sign");
            return false;
        }

        ChangedSign s = BukkitUtil.toChangedSign(sign);
        if (!s.getLine(1).equals("[Teleporter]")) {
            player.printError("mech.teleport.sign");
            return false;
        }

        return true;
View Full Code Here

        int x = l.getBlockX();
        int z = l.getBlockZ();

        for (int y = 0; y < w.getMaxHeight(); y++) {
            if (y != l.getBlockY()) if (SignUtil.isSign(w.getBlockAt(x, y, z))) {
                ChangedSign s = BukkitUtil.toChangedSign(w.getBlockAt(x, y, z));
                if (s.getLine(1).equalsIgnoreCase("[Code Block]")) {
                    y--;
                    Block b = w.getBlockAt(x, y, z);
                    StringBuilder code = new StringBuilder();
                    while (SignUtil.isSign(b)) {
                        s = BukkitUtil.toChangedSign(b);
                        for (int li = 0; li < 4 && y != l.getBlockY(); li++) {
                            code.append(s.getLine(li)).append("\n");
                        }
                        b = w.getBlockAt(x, --y, z);
                    }
                    return code.toString();
                }
View Full Code Here

        if(!location.getChunk().isLoaded())
            return;

        if (!chip.getInput(0)) return;
        Block left = SignUtil.getLeftBlock(BukkitUtil.toSign(getSign()).getBlock());
        ChangedSign effectSign = null;
        if (left.getType() == Material.WALL_SIGN)
            effectSign = BukkitUtil.toChangedSign(left);

        Block right = SignUtil.getRightBlock(BukkitUtil.toSign(getSign()).getBlock());
        ChangedSign armourSign = null;
        if (right.getType() == Material.WALL_SIGN)
            armourSign = BukkitUtil.toChangedSign(right);

        for (int i = 0; i < amount; i++) {
            Entity ent = BukkitUtil.toSign(getSign()).getWorld().spawn(location, type.getEntityClass());

            if (armourSign != null) { // Apply armor
                if (ent instanceof LivingEntity) {

                    for (int s = 0; s < 4; s++) {
                        String bit = armourSign.getLine(s);

                        ItemStack slot = ItemUtil.makeItemValid(ItemSyntax.getItem(bit));

                        switch (s) {
                            case 0:
View Full Code Here

    public Object[] setupIC(Block block, boolean create) {

        // if we're not looking at a wall sign, it can't be an IC.
        if (block.getType() != Material.WALL_SIGN) return null;
        ChangedSign sign = BukkitUtil.toChangedSign(block);

        // detect the text on the sign to see if it's any kind of IC at all.
        Matcher matcher = RegexUtil.IC_PATTERN.matcher(sign.getLine(1));
        if (!matcher.matches()) return null;

        String prefix = matcher.group(2);
        // TODO: remove after some time to stop converting existing MCA ICs
        // convert existing MCA ICs to the new [MCXXXX]A syntax
        if (prefix.equalsIgnoreCase("MCA")) {
            sign.setLine(1, (StringUtils.replace(sign.getLine(1).toLowerCase(Locale.ENGLISH), "mca", "mc") + "a").toUpperCase(Locale.ENGLISH));
            sign.update(false);

            return setupIC(block, create);
        }
        if (sign.getLine(1).toLowerCase(Locale.ENGLISH).startsWith("[mc0")) {
            if(sign.getLine(1).equalsIgnoreCase("[mc0420]"))
                sign.setLine(1, "[MC1421]S");
            else if(sign.getLine(1).equalsIgnoreCase("[mc0421]"))
                sign.setLine(1, "[MC1422]S");
            else
                sign.setLine(1, (StringUtils.replace(sign.getLine(1).toLowerCase(Locale.ENGLISH), "mc0", "mc1") + "s").toUpperCase(Locale.ENGLISH));
            sign.update(false);

            return setupIC(block, create);
        }

        if (sign.getLine(1).toLowerCase(Locale.ENGLISH).startsWith("[mcz")) {
            sign.setLine(1, (StringUtils.replace(sign.getLine(1).toLowerCase(Locale.ENGLISH), "mcz", "mcx") + "s").toUpperCase(Locale.ENGLISH));
            sign.update(false);

            return setupIC(block, create);
        }

        if (!manager.hasCustomPrefix(prefix)) return null;

        String id = matcher.group(1);

        if(disabledICs.contains(id.toLowerCase()) || disabledICs.contains(id)) return null; //This IC is disabled.
        // after this point, we don't return null if we can't make an IC: we throw shit,
        // because it SHOULD be an IC and can't possibly be any other kind of mechanic.

        // now actually try to pull up an IC of that id number.
        RegisteredICFactory registration = manager.get(id);
        if (registration == null) {
            CraftBookPlugin.logger().warning("\"" + sign.getLine(1) + "\" should be an IC ID, but no IC registered under that ID could be found.");
            block.breakNaturally();
            return null;
        }

        IC ic;
        // check if the ic is cached and get that single instance instead of creating a new one
        if (ICManager.isCachedIC(block.getLocation())) {
            ic = ICManager.getCachedIC(block.getLocation());
            if(ic.getSign().updateSign(sign)) {

                ICManager.removeCachedIC(block.getLocation());
                ic = registration.getFactory().create(sign);
                if(!sign.getLine(0).equals(ic.getSignTitle()) && !sign.getLine(0).startsWith("=")) {
                    sign.setLine(0, ic.getSignTitle());
                    sign.update(false);
                }
                ic.load();
                // add the created ic to the cache
                ICManager.addCachedIC(block.getLocation(), ic);
            }
        } else if (create) {
            ic = registration.getFactory().create(sign);
            if(!sign.getLine(0).equals(ic.getSignTitle()) && !sign.getLine(0).startsWith("=")) {
                sign.setLine(0, ic.getSignTitle());
                sign.update(false);
            }
            ic.load();
            // add the created ic to the cache
            ICManager.addCachedIC(block.getLocation(), ic);
        } else
            return null;
        // extract the suffix
        String suffix = "";
        String[] str = RegexUtil.RIGHT_BRACKET_PATTERN.split(sign.getLine(1));
        if (str.length > 1) {
            suffix = str[1];
        }

        ICFamily family = registration.getFamilies()[0];
        if (suffix != null && !suffix.isEmpty()) {
            for (ICFamily f : registration.getFamilies()) {
                if (f.getSuffix().equalsIgnoreCase(suffix)) {
                    family = f;
                    break;
                }
            }
        }

        // okay, everything checked out. we can finally make it.
        if (ic instanceof SelfTriggeredIC && (sign.getLine(1).trim().toUpperCase(Locale.ENGLISH).endsWith("S") || ((SelfTriggeredIC) ic).isAlwaysST()))
            CraftBookPlugin.inst().getSelfTriggerManager().registerSelfTrigger(block.getLocation());

        Object[] rets = new Object[3];
        rets[0] = id;
        rets[1] = family;
View Full Code Here

public class BukkitChangedSignTest {

    @Test(expected=IllegalArgumentException.class)
    public void testBukkitChangedSign() {

        new ChangedSign(null, null);

        ChangedSign sign = new ChangedSign(mock(Sign.class), new String[]{"","","",""});
        assertTrue(sign.getSign() != null);
        assertTrue(sign.getLines().length == 4);
    }
View Full Code Here

TOP

Related Classes of com.sk89q.craftbook.ChangedSign

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.