Solved More Sign Stuff

Discussion in 'Plugin Development' started by SeniorCluckers, Jul 21, 2016.

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

    SeniorCluckers

    Here I'm getting a sign from a world at the certain cords. But how do I get all signs, with a certain text on them, to do something.

    Code:
            Block b = Bukkit.getServer().getWorlds().get(0).getBlockAt(x, y, z);
            b.setType(Material.WALL_SIGN);
            BlockState state = b.getState();
            ((org.bukkit.material.Sign) state.getData()).setFacingDirection(BlockFace.EAST);
    
     
  2. @SeniorCluckers
    I'm not sure this is possible (with reasonable programming). But explain what you are trying to do, there is probably a simpler solution.
     
  3. Offline

    Zombie_Striker

    @SeniorCluckers
    There are two approach that you can use to do this:
    1. Loop through every block on the entire server and check if the block is a sign with the text on it.(very RAM intensive, not recommend). This is only good if you want to implement signs that are there before the plugin has been installed.
    2. When a sign is placed, check if the sign has the text on it. If so, add it to a list. If a sign from the list has been destroyed, remove the sign from the list. When you want to get all the signs, loop through the list.
     
  4. Offline

    SeniorCluckers

    @Zombie_Striker @AlvinB

    Okay sounds like a bad idea. Ill still use the one I posted, because I only need two signs on the server two change.

    So this is what I'm using to get the sign. But it works like this, if i place a sign anywhere or at the same location i specified, it places a new sign at the location I specified. How can I make it to check for the sign that is already at the location and just update it with a new line after a certain amount of players are on the server? I've tried this below. If you can link me to something I can take a look at for more info that would be great!

    Code:
        @EventHandler
        public void onSignChange(SignChangeEvent event) {
    
            int x = -140;
            int y = 59;
            int z = -339;
    
            Block b = Bukkit.getServer().getWorlds().get(0).getBlockAt(x, y, z);
            b.setType(Material.WALL_SIGN);
            BlockState state = b.getState();
            ((org.bukkit.material.Sign) state.getData()).setFacingDirection(BlockFace.EAST);
    
            Sign sign = (Sign) state;
    
            if ((Bukkit.getOnlinePlayers().size() == 1)) {
    
                countdown = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new Runnable() {
    
                    int i = 5;
    
                    @Override
                    public void run() {
    
                        if (i >= 0)
                        {
                            sign.setLine(3, "Starting In: " + i);
                            state.update();
                            i--;
                        } else {
    
                            sign.setLine(3, "Starting...");
                            state.update();
                           
                            Bukkit.getServer().getScheduler().cancelTask(countdown);
                        }
                    }
                }, 20, 20);
     
  5. Offline

    Zombie_Striker

    @SeniorCluckers
    Because you used SignChangeEvent for this, this will always update whenever any sign is placed. This means that there can be multiple tasks running at the same time. Instead, listen to the PlayerJoinEvent and then run the task. Also, before you set the block's type, just check if the block's type is already a Sign. If so, don't set any of those values.
    Create a repeating task that will check every couple of seconds the amount of players online. If there is a certain amount of playes online, the update the sign.
     
  6. Offline

    SeniorCluckers

Thread Status:
Not open for further replies.

Share This Page