Updating signs?

Discussion in 'Plugin Development' started by mouz_, Nov 21, 2015.

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

    timtower Administrator Administrator Moderator

    @mouz_ Please get some sort of sign storage, it will make your plugin less resource intensive. And you don't need players anymore, which is probably throwing errors.
    And a toString method could work with languages as well.
     
  2. Ok, how to store the signs? I know that I don't need players anymore, you asked about the code, so I gave you it.
     
  3. Online

    timtower Administrator Administrator Moderator

    @mouz_ Set of locations would do for now.
     
  4. Ok, how to do it?
     
  5. Offline

    Zombie_Striker

  6. Ok, how to do it? How to store signs, or location from which blocks will be looped?
     
  7. Offline

    mythbusterma

    @mouz_

    Welp, you put them in a Set of Locations or BlockStates, depending on your mood. Hell, I'll even give you the declaration for Locations, since you're probably going to want to use those as you're going to likely want this in the config file.

    Set<Location> signs = new HashSet<>();

    Just so you know, this is a terrible way to learn Java, especially since you're not even trying. This thread has been absolutely laughable. I mean, look at this:

    Just because you were too lazy to do some Googling for yourself.
     
  8. Offline

    Scimiguy

    I've just been following this thread for the laughs, I'll be honest.

    @mouz_
    This will go on forever, or until either:
    1. Everyone realises the futility and leaves
    2. You realise the real issue and take the advice we gave you a long time ago: Learn Java First.
     
  9. I would end this in a nice way, but the post has to be accepted before sending to public.

    Guys, don't tell me what to do, tell me how.
     
  10. Offline

    mcdorli

    1.: Store the signs when the players place them
    2.: Create a scheduler
    3.: Go trough the sign list and update every sign

    OR

    1.: Store the signs, when the players place them
    2.: Every time, something happens in the configs, go trough every sign and update it

    There you have it, know, you just need the code for it. I'm not going to help anymore.
     
    Zombie_Striker likes this.
  11. Why are you still telling me what to do, when I don't know how to do it?
     
  12. Online

    timtower Administrator Administrator Moderator

    @mouz_ Because you said that you know java and bukkit.
    So we think that you know how to make a normal variable.
     
    Chloe-chan and Zombie_Striker like this.
  13. Offline

    Chloe-chan

    Well... he did say he is learning... :p
     
  14. Offline

    Scimiguy

    This is not the place to learn Java.
    We help with Bukkit problems here.
     
    Zombie_Striker likes this.
  15. So I have bukkit problems with creating the code.
     
  16. Offline

    Zombie_Striker

    @mouz_
    The thing is, that's wrong. We told you all the components you need. We told you how to arrange and use all those components. You have the ability to google search everything we told you to do (and hens, gave you the ability to see the code and how it's structured). This is no longer a problem with coding, it about your ability to actually act upon what we told you to do.
     
  17. Offline

    mythbusterma

    @mouz_

    I think you have problems following directions, to be honest. Here, since you've begged and pleaded, here's some code:

    Code:
    // creating your set:
    List<Location> locations = new ArrayList<Location>();
    
    // adding a location to it:
    
    Block sign = // get the block
    locations.add(sign.getLocation());
    
    // iterate over all the locations in the list:
    
    for (Location loc: locations) {
        // do something with loc
    }
    
    // save to config:
    
    JavaPlugin yourPlugin = // get your plugin
    yourPlugin.getConfig().set("signs", locations);
    
    // load from config:
    
    JavaPlugin yourPlugin = // get your plugin
    locations = (List<Location>) yourPlugin.getConfig().get("signs");
    But I'm confident in giving you this code that you still won't be able to do what you're trying to do. Because you haven't tried. Writing code requires giving a damn, and you obviously don't.

    P.S. before you all get on me about using a List here, I was just too lazy to write the three lines it takes to load a Set, so I used the built in ones for List instead.
     
    timtower and Xerox262 like this.
  18. On enable:
    Code:
            locations = (List<Location>) config.get("signs");
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    for (Location loc: locations) {
                        if (loc.getBlock().getType().equals(Material.WALL_SIGN)) {
                            final List<String> arena = (List<String>)config.getStringList("ArenaList");
                            Sign sign = (Sign) loc.getBlock().getState();
                            if (sign.getLine(0).contains("[Castle]")) {
                                String map = null;
                                map = sign.getLine(1);
                                for (int i = 0; i < Main.this.arenaList.size(); ++i) {
                                    if ((map == null || Main.this.arenaList.get(i).getName().equalsIgnoreCase(map))) {
                                           sign.setLine(3, "" + ChatColor.WHITE + Main.this.arenaList.get(i).getPlayerList().size() + ChatColor.DARK_GRAY + "/" + ChatColor.WHITE + Main.this.arenaList.get(i).getToStart());
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.DISABLED) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.ERROR) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.FINISHING) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.INACTIVE) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.INGAME) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x...");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.LOADING) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.RESETING) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.STARTING) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x...");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.WAITING) {
                                               sign.setLine(2, ChatColor.GREEN + "x");
                                           }
                                           sign.update();
                                    }
                                }
                            }
                        }
                    }
                }
            }, 0L, 20L);
    Creating the sign:
    Code:
        @EventHandler
        public void onSignChange(final SignChangeEvent e) {
            final String l0 = e.getLine(0);
            final String l = e.getLine(1);
            final FileConfiguration config = this.getConfig();
            final List<String> arena = (List<String>)config.getStringList("ArenaList");
            final Block b = e.getBlock();
            if ((b.getType() == Material.SIGN || b.getType() == Material.WALL_SIGN || b.getType() == Material.WALL_SIGN) && l0.contains("[Castle]")) {
                Block sign = e.getBlock();
                locations.add(sign.getLocation());
                this.getConfig().set("signs", locations);
                this.saveConfig();
            }
        }
    Error in the console:
    Code:
    [16:48:16] [Server thread/WARN]: [cpvpCastle] Task #35 for x v0.5 generated an exception
    java.lang.NullPointerException
        at x.x.x.Main$1.run(Main.java:120) ~[?:?]
        at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:71) ~[x.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:701) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:643) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:549) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [x.jar:git-PaperSpigot-1f7d532]
     
    Last edited: Nov 29, 2015
  19. Online

    timtower Administrator Administrator Moderator

    @mouz_ Now you are getting there.
    On what line is the error, what is causing it.
     
  20. Line number 120 is: for (Location loc: locations) {
     
  21. Offline

    Xerox262

    Code:
    if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.DISABLED) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.ERROR) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.FINISHING) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.INACTIVE) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.INGAME) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x...");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.LOADING) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.RESETING) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.STARTING) {
                                               sign.setLine(2, ChatColor.DARK_RED + "x...");
                                           }
                                           if (Main.this.arenaList.get(i).getMode() == Arena.GameMode.WAITING) {
                                               sign.setLine(2, ChatColor.GREEN + "x");
                                           }
    From what you showed before you should really remove them and do
    Code:
    GameMode mode = Main.arenaList.get(i).getMode();
    if (mode == GameMode.Waiting)
        sign.setLine(2, ChatColor.GREEN + mode.name());
    else
        sign.setLine(2, ChatColor.DARK_RED + mode.name());
    or even a switch

    Code:
    GameMode mode = Main.arenaList.get(i).getMode();
    switch (mode) {
        case WAITING:
            sign.setLine(2, ChatColor.GREEN + mode.name()); break;
        default: sign.setLine(2, ChatColor.DARK_RED + mode.name()); break;
    }
     
    Zombie_Striker likes this.
  22. Online

    timtower Administrator Administrator Moderator

    @mouz_ move the locations to somewhere out of the onEnable, then you can also add signs to it.
     
  23. Online

    timtower Administrator Administrator Moderator

    @mouz_ Declare it in the class outside any methods.
    Fill it inside the onEnable, save to the config in onDisable, add in the events.
     
    Zombie_Striker likes this.
  24. Online

    timtower Administrator Administrator Moderator

    @mouz_ What part didn't you get?
     
  25. "Declare it in the class outside any methods.
    Fill it inside the onEnable, save to the config in onDisable, add in the events."
     
  26. Offline

    Zombie_Striker

    @mouz_
    Do you know what the following means/how to do it:
    • How to declare a field.
    • Instantiate it inside a method.
    If not, That is why we were telling you to learn Java for the past 3 pages. If you do know what it means, then you should understand what he's saying.
     
  27. Online

    timtower Administrator Administrator Moderator

    @mouz_ Based on that I have come to my personal conclusion that you don't know enough Java and aren't googling terms that you don't know.
    I won't help you anymore with this.
     
    Zombie_Striker likes this.
  28. Error:
    Code:
    [22:37:46] [Server thread/ERROR]: Could not pass event SignChangeEvent to x v0.5
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[x.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[x.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [x.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:1732) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.PacketPlayInUpdateSign.a(PacketPlayInUpdateSign.java:58) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.PacketPlayInUpdateSign.handle(PacketPlayInUpdateSign.java:78) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:189) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:795) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:643) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:549) [x.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [x.jar:git-PaperSpigot-1f7d532]
    Caused by: java.lang.NullPointerException
        at x.x.x.Main.onSignChange(Main.java:292) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[x.jar:git-PaperSpigot-1f7d532]
        ... 13 more
    Line number 292 is: locations.add(sign.getLocation());
     
Thread Status:
Not open for further replies.

Share This Page