sign not updating

Discussion in 'Plugin Development' started by polak, Feb 14, 2020.

  1. Offline

    polak

    Code:
    public void placeAllSigns() {
            World w = org.bukkit.Bukkit.getWorld("mainlobby");
            Block block = w.getBlockAt(16, 116, 7);
            Block block1 = w.getBlockAt(16, 116, 9);
            block.setType(Material.WALL_SIGN);
            block1.setType(Material.WALL_SIGN);
            block.setData((byte) 4);
            block1.setData((byte) 4);
            Sign fod1sign = (Sign) block.getState();
            Sign fod2sign = (Sign) block1.getState();
            fod1sign.setLine(0, "-- game --");
            fod1sign.setLine(1, "0/3 players");
            fod1sign.setLine(2, "   ");
            fod1sign.setLine(3, "JOIN!");
           
            fod1sign.update();
           
            fod2sign.setLine(0, "-- game --");
            fod2sign.setLine(1, "0/3 players");
            fod2sign.setLine(2, "   ");
            fod2sign.setLine(3, "JOIN!");
           
            fod2sign.update();
        }
       
        public void updateSigns(String game) {
            if(game.equals("fod-1")) {
                fod1sign.setLine(1, String.valueOf(fod1playercount) + "/3 players");
                fod1sign.update();
            } else if(game.equals("fod-2")) {
                fod2sign.setLine(1, String.valueOf(fod2playercount) + "/3 players");
                fod2sign.update();
            }
        }
    fod1playercount its a global variable

    Code:
    @EventHandler
        public void onWorldChange(PlayerChangedWorldEvent ev) {
            World fromWorld = ev.getFrom();
            Player player = ev.getPlayer();
            String name = player.getName();
            if(fromWorld == Bukkit.getWorld("mainlobby")) {
                if(player.getWorld().getName().equals("fod-1")) {
                    for(Player players : Bukkit.getOnlinePlayers()) {
                        player.sendMessage(players.getName());
                    }
                    fod1playercount = Bukkit.getWorld("fod-1").getPlayers().size();
                //    player.sendMessage(String.valueOf(fod1playercount));
                    this.updateSigns("fod-1");
                } else if(player.getWorld().getName().equals("fod-2")) {
                    for(Player players : Bukkit.getOnlinePlayers()) {
                        player.sendMessage(players.getName());
                    }
                    fod2playercount = Bukkit.getWorld("fod-2").getPlayers().size();
                    this.updateSigns("fod-2");
                }
            }
        }
    Console error when i Interact with a sign
    Code:
       at org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity.teleport(CraftEntity.java:200) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at main.java.FoD.onInteract(FoD.java:145) [FoD.jar:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:225) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.PlayerInteractManager.interact(PlayerInteractManager.java:374) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:630) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.a(SourceFile:60) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.handle(SourceFile:9) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    Caused by: java.lang.NullPointerException
            at main.java.FoD.updateSigns(FoD.java:63) ~[?:?]
            at main.java.FoD.onWorldChange(FoD.java:128) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[kernel.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
            ... 27 more
    >
    
    In interact event just teleporting

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 15, 2020
  2. Offline

    caderapee

    @polak
    I guess you created a global variable for fod1sign and fod2sign, but u didnt set it.
     

Share This Page