Solved Storing Sign In Config

Discussion in 'Plugin Development' started by ReadySetPawn, Dec 22, 2014.

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

    ReadySetPawn

    How would I store a sign in a config file? I tried saving it's x,y, and z coordinates but when I go back to retrieve the sign, it says block can't be cast to sign.

    Code:
    public static void newSign(Sign sign, Arena arena){
           
            if (arenas.contains(arena.getName())) return;
           
            int x = (int) sign.getLocation().getX();
            int y = (int) sign.getLocation().getY();
            int z = (int) sign.getLocation().getZ();
           
            arenas.set(arena.getName() + ".X", x);
            arenas.set(arena.getName() + ".Y", y);
            arenas.set(arena.getName() + ".Z", z);
           
            save();
        }
       
        public static Sign getSignFor(Arena arena){
           
            int x = (int) arenas.get(arena.getName() + ".X");
            int y = (int) arenas.get(arena.getName() + ".Y");
            int z = (int) arenas.get(arena.getName() + ".Z");
           
            return (Sign) arena.getWorld().getBlockAt(new Location(arena.getWorld(), x, y, z)).getState();
        }
     
  2. Offline

    dmiller2400

    You will want to check if the block at the location you have stored is of type sign

    Code:
     Location location = new Location(arena.getWorld(), x, y, z);
        if(arena.getWorld().getBlockAt(location).getType() == Material.Sign) {
            Sign s = (Sign) arena.getWorld().getBlockAt(location).getState();
            return sign;
        }
    That should be all, haven't tested it though
     
  3. Offline

    mine-care

  4. Offline

    ReadySetPawn

    Okay I fixed it now.
    It appeared that I was targeting a block in the arena world, not the lobby world.
     
Thread Status:
Not open for further replies.

Share This Page