Adding and getting text from a sign

Discussion in 'Plugin Development' started by Suprem20, Apr 11, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Suprem20

    Hello,

    I can't seem to be able to get sign from a text nor set the sign on the text, could someone please advise me on what I'm doing wrong?

    Code:
        @EventHandler(priority = EventPriority.MONITOR)
        public void onPlayerInteract(PlayerInteractEvent event) {
     
            if (!event.hasBlock()) {
     
                return;
     
            }
     
            Block block = event.getClickedBlock();
            Player player = event.getPlayer();
     
            if (block.getType().equals(Material.SIGN_POST) || block.getType().equals(Material.WALL_SIGN)) {
     
                Sign sign = (Sign) block.getState();
     
                if (sign.getLine(0).equalsIgnoreCase("[xpbank]") && sign.getLine(1).equalsIgnoreCase(player.getDisplayName())
                        && sign.getLine(2).equalsIgnoreCase("Store")) {
                    plugin.log.info("lol");
     
                    if (player.getExp() == 0) {
     
                        plugin.tell(player, "You have no xp to store!");
                        return;
                    }
                    String xp = Float.toString(player.getExp());
                    plugin.tell(player, "Stored" + player.getExp());
                    sign.setLine(3, xp);
                    sign.update();
                    player.setExp(0);
                }
                if (sign.getLine(0).equalsIgnoreCase("[xpbank]") && sign.getLine(1).equalsIgnoreCase(player.getDisplayName())
                        && sign.getLine(2).equalsIgnoreCase("Take")) {
     
                    String str = sign.getLine(3);
                    Float f = new Float(str);
     
                    if (f == 0) {
     
                        plugin.tell(player, "You stored no xp!");
                        return;
                    }
                    player.setExp(f);
                    sign.setLine(3, "");
                    sign.update();
                    plugin.log.info("lol1");
                }
            }
        }
     
        @EventHandler(priority = EventPriority.MONITOR)
        public void onBlockPlace(BlockPlaceEvent event) {
     
            Block block = event.getBlock();
            Player player = event.getPlayer();
           
            if (block.getType().equals(Material.SIGN_POST) || block.getType().equals(Material.WALL_SIGN)) {
     
                Sign sign = (Sign) block.getState();
               
                if (sign.getLine(0).equalsIgnoreCase("[xpbank]")) {
                   
                    sign.setLine(1, player.getDisplayName());
                    sign.update();
                   
                }
            }
        }
    }
     
  2. Offline

    stuntguy3000

    I am also looking into this, i did ask like you but got no response :/
    So i am trying to get my way into plugin's sources who rely on signs.

    I will let you know if i find anything :)
     
  3. Offline

    messageofdeath

    PHP:
    Player player event.getPlayer();
    Block block event.getBlock();
    BlockState state block.getState();
    Sign sign = (Sign)state;
    String signline1 sign.getLine(0);
     
    //To get
    if(message.equals(signline1)){
    }
     
    //To set
    sign.setLine(0"Message");
    sign.update(true);
     
  4. Offline

    Sessional

    The sign listener method from my mod if your curious.
    Suprem20 Your code looked proper, the only thing I can think of is possibly your sign doesn't match what your code looked like. I guess I wouldn't know for sure as I just glanced over it. If it's not giving errors, are you rememering to do a register event in the plugin?

    getServer().getPluginManager().registerEvents(new ClassName(), this);
    Code:
    @EventHandler
        public void onSignUse(PlayerInteractEvent event)
        {
            if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK)
            {
                if (event.getClickedBlock().getType() == Material.SIGN_POST || event.getClickedBlock().getType() == Material.WALL_SIGN)
                {
                    Sign s = (Sign) event.getClickedBlock().getState();
     
                    for (int i = 0; i < s.getLines().length - 1; i++)
                    {
                        if (s.getLine(i).equals("Waypoint:") || s.getLine(i).equals("§aWaypoint:"))
                        {
                            String wp = s.getLine(i + 1);
                            WpsPlugin plug = (WpsPlugin) getPlugin().getServer().getPluginManager().getPlugin("Waypoints");
                            if (getPlugin().isBukkitPermissions())
                            {
                                if (event.getPlayer().hasPermission("waypoints.basic.go") || event.getPlayer().hasPermission("waypoints.sign.go"))
                                {
                                    if (!s.getLine(i).equals("§aWaypoint:"))
                                    {
                                        s.setLine(i, "§aWaypoint:");
                                    }
                                    plug.getCommandHandler().doGo(event.getPlayer(), new String[]
                                            {
                                                wp
                                            });
                                } else
                                {
                                    event.getPlayer().sendMessage("You do not have permission to sign waypoint.");
                                }
                            } else
                            {
                                if (!s.getLine(i).equals("§aWaypoint:"))
                                {
                                    System.out.println("Set color!");
                                    s.setLine(i, "§aWaypoint:");
                                    s.update();
                                }
                                plug.getCommandHandler().doGo(event.getPlayer(), new String[]
                                        {
                                            wp
                                        });
                            }
                        }
                    }
                }
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page