Updating signs?

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

Thread Status:
Not open for further replies.
  1. What code? The working code in PlayerMoveEvent is on the top.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @mouz_ Save all signs that are required for your plugin in a list.
    Make a timer that updates the changed signs every ... time.
    No need for events.
     
  3. Ok. How to do it?
     
  4. Offline

    Xerox262

    You have to learn some Java or ask someone that already knows to do it for you, you can't just magically know how to do it.
     
    Zombie_Striker likes this.
  5. I think I'm asking people who know how to do it.
     
  6. Offline

    Xerox262

    I mean as a plugin request.
     
  7. Offline

    Zombie_Striker

    Simply create a List (or Set) that stores locations/blocks (and preferably save it to the config), Then when a sign is placed down save it to that List or Set.
    --------------------
    ------------------------
    No Events needed IF you do not want to add any new signs. You would have to listen to BlockPlaceEvent and BlockBreakEvent to manage getting new/ deleting old signs.
     
  8. How many times I have to ask for help with doing it?
     
  9. Offline

    Chloe-chan

    Buddy... we all are trying help you out, but you are just trying to ask for someone to spoon-feed the code to you. It is not going to help you that way.

    @Zombie_Striker summarised most, if not all, of the help we have given you to accomplish this task.
    Off-topic:
    This is why we DON'T spoonfeed
     
    Abstract97 and Zombie_Striker like this.
  10. Ok, how to do the task?
     
  11. Offline

    timtower Administrator Administrator Moderator

    Zombie_Striker likes this.
  12. I know, how to create tasks. Why are you spamming?

    I want to know how to update these signs.
     
  13. Offline

    timtower Administrator Administrator Moderator

    @mouz_
    Because that wasn't clear to me that you already had the task.
    Do you also have storage of your signs then?
     
  14. Offline

    Zombie_Striker

    I was also confused about this one.

    To update the sign, I think you should use this:
    Code:
    Sign sign = (Sign) SignBlock.getState();
    sign.setline(line,"String");
    sign.update(true);
     
  15. Please ban Zombie_Striker, he is just spamming.

    Timtower I don't have storage of these signs.
     
    mcdorli and Zombie_Striker like this.
  16. Offline

    mcdorli

    Yes, he has 2 tousand messages and 200- likes, yes, the problem is probably in hím. Do you éven know java?
     
  17. Offline

    Scimiguy

    @mouz_
    And i have about 1500 messages and almost 200 likes. I've been here a month and a half

    We are here for a reason, and we actually do want to help.
    The problem is, you're not listening

    Those sort of responses are just going to make people disregard you, have some respect for those who are here answering questions in their spare time for you. For free
     
  18. Offline

    mcdorli

    timtower answered, then
    Did I miss out something? Do you time travel or what?
     
    Zombie_Striker likes this.
  19. Offline

    timtower Administrator Administrator Moderator

    @mouz_ Then make storage of the signs.
    And we don't ban for spamming like this, he is even giving you code to do what you need to do.
     
  20. It's just spam, he is giving me the code, which is already in the pasted code in my first post? In my country he will get at least warned.

    @timtower Ok, make storage, but how? And how to update signs from the storage?
     
  21. Offline

    timtower Administrator Administrator Moderator

    @mouz_ This isn't your country though.
    A set of locations, a set of signs, not my call, you are the developer.
    And you loop through them, set lines, update them.
     
    Chloe-chan likes this.
  22. I don't know how to do it, I'm asking for help.
     
  23. Offline

    timtower Administrator Administrator Moderator

    @mouz_ What do you have so far then/
    Do you have the task? Do you have a set of locations or signs?
     
  24. Offline

    Zombie_Striker

    I would just like to remind you that you posted this
    But you said you already have the code to update your signs.

    To add on to what @timtower said, can you post your updated class (I assume you tried something and are not waiting for us to post the code.)?
     
    Last edited: Nov 26, 2015
  25. Is it a troll?

    I put move event code into the task, this is what I have.
     
  26. Offline

    timtower Administrator Administrator Moderator

    @mouz_ You say what you have, please show the code.
     
  27. Code:
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    final Player player = e.getPlayer();
                    int radius = 5;
                    Location loc = player.getLocation();
                    if (!player.getWorld().getName().equals("world") && !player.getWorld().getName().equals("world2")) {
                        return;
                    }
                    Random gen = new Random();
                    int r = gen.nextInt(100);
                    if (r > 21) {
                        return;
                    }
                    for(int x = (int) (loc.getX() - radius); x < loc.getX() + radius; x++ ) {
                         for(int y = (int) (loc.getY() - radius); y < loc.getY() + radius; y++ ) {
                             for (int z = (int) (loc.getZ() - radius); z < loc.getZ() + radius; z++ ) {
                                 if (player.getWorld().getBlockAt(x, y, z).getType().equals(Material.WALL_SIGN) || player.getWorld().getBlockAt(x, y, z).getType().equals(Material.WALL_SIGN) ) {
                                     final FileConfiguration config = this.getConfig();
                                     final List<String> arena = (List<String>)config.getStringList("ArenaList");
                                     Sign sign = (Sign) player.getWorld().getBlockAt(x, y, z).getState();
                              
                                      if (sign.getLine(0).contains("[CastleWars]")) {
                                          String map = null;
                                          map = sign.getLine(1);
                                          for (int i = 0; i < this.arenaList.size(); ++i) {
                                              if ((map == null || this.arenaList.get(i).getName().equalsIgnoreCase(map)) && (this.arenaList.get(i).getPlayerList().size() < this.arenaList.get(i).getToStart() || (player.hasPermission("castlewars.vip") && this.arenaList.get(i).getPlayerList().size() < this.arenaList.get(i).getToStart() + 4))) {
                                                     sign.setLine(3, "" + ChatColor.WHITE + this.arenaList.get(i).getPlayerList().size() + ChatColor.DARK_GRAY + "/" + ChatColor.WHITE + this.arenaList.get(i).getToStart());
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.DISABLED) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Disabled");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.ERROR) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Error");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.FINISHING) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Finishing");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.INACTIVE) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Inactive");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.INGAME) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Ingame");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.LOADING) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Loading");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.RESETING) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Reseting");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.STARTING) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Starting");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.WAITING) {
                                                         sign.setLine(2, ChatColor.GREEN + "Waiting");
                                                     }
                                                     sign.update();
                                              }
                                          }
                                      }
                                 }
                             }
                         }
                    }
                }
            }, 0L, 20L);
    I have errors in: e.getPlayer(); this.getConfig(); and whole arenaList thing.
     
  28. Offline

    timtower Administrator Administrator Moderator

    @mouz_ You don't need players anymore.
    What do you have for sign location storage?
     
  29. Offline

    Zombie_Striker

    These two if statements cancel each other out, so this If statement does nothing.

    Don't create a new instance of Random each time!

    These two variables are exactly the same.

    This is a string list. You do not need to cast it.

    Are you sure you only want to see if it "contains" that string? Meaning Test[CastleWars] would also be accepted (PS. this is case sensitive. So it has to have those capital letters at those specific places).
    Why not just put "String map = sign.getLine(1);" if you're going to set what it will be equal to in the next line?
    I think you may want to re-read this whole line. BTW This line is MASSIVE. You might want to break it down/ make a method just for this line.

    Massive violation of DRY. Why not have a "toString"method for the Gamemode and just use the following
    Code:
    sign.setLine(2, ChatColor.GREEN +this.arenaList.get(i).getMode().toString() );
    BTW:
    I assume this is referring to me, correct? I, like everyone else here, am just trying to help you.
     
  30. This is corrected code. I don't want to use "toString" method, because I want to translate gamemodes later.
    Code:
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    int radius = 5;
                    for(int x = (int) (loc.getX() - radius); x < loc.getX() + radius; x++ ) {
                         for(int y = (int) (loc.getY() - radius); y < loc.getY() + radius; y++ ) {
                             for (int z = (int) (loc.getZ() - radius); z < loc.getZ() + radius; z++ ) {
                                 if (player.getWorld().getBlockAt(x, y, z).getType().equals(Material.WALL_SIGN) || player.getWorld().getBlockAt(x, y, z).getType().equals(Material.WALL_SIGN) ) {
                                     final FileConfiguration config = this.getConfig();
                                     final List<String> arena = (List<String>)config.getStringList("ArenaList");
                                     Sign sign = (Sign) player.getWorld().getBlockAt(x, y, z).getState();
                            
                                      if (sign.getLine(0).contains("[CastleWars]")) {
                                          String map = sign.getLine(1);
                                          for (int i = 0; i < this.arenaList.size(); ++i) {
                                              if ((map == null || this.arenaList.get(i).getName().equalsIgnoreCase(map)) && (this.arenaList.get(i).getPlayerList().size() < this.arenaList.get(i).getToStart() || (player.hasPermission("castlewars.vip") && this.arenaList.get(i).getPlayerList().size() < this.arenaList.get(i).getToStart() + 4))) {
                                                     sign.setLine(3, "" + ChatColor.WHITE + this.arenaList.get(i).getPlayerList().size() + ChatColor.DARK_GRAY + "/" + ChatColor.WHITE + this.arenaList.get(i).getToStart());
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.DISABLED) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Disabled");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.ERROR) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Error");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.FINISHING) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Finishing");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.INACTIVE) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Inactive");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.INGAME) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Ingame");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.LOADING) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Loading");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.RESETING) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Reseting");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.STARTING) {
                                                         sign.setLine(2, ChatColor.DARK_RED + "Starting");
                                                     }
                                                     if (this.arenaList.get(i).getMode() == Arena.GameMode.WAITING) {
                                                         sign.setLine(2, ChatColor.GREEN + "Waiting");
                                                     }
                                                     sign.update();
                                              }
                                          }
                                      }
                                 }
                             }
                         }
                    }
                }
            }, 0L, 20L);    
    I have It only. I don't have anything about the storage.
     
Thread Status:
Not open for further replies.

Share This Page