Updating signs?

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

Thread Status:
Not open for further replies.
  1. Hi, I want to do it every couple seconds in task.

    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onMovePlayer(final PlayerMoveEvent e) {
            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();
                                      }
                                  }
                              }
                         }
                     }
                 }
            }
        }
     
  2. Offline

    CraftCreeper6

    @mouz_
    Undating? Explain.

    EDIT: My bad, misread.

    EDIT 2: To do it every X seconds you would need to run a repeating scheduler.
     
  3. Online

    timtower Administrator Administrator Moderator

    @mouz_ And what is your question? What do you want in a task?
     
  4. Offline

    Zombie_Striker

    Scheduler.scheduleSynchRepeatingTask(JavaPlugin instance, new Runnable(){/*add stuff*/}, delay, delay betwen triggers);
     
  5. I don't know how to do it exactly. Can you create task with this code?
     
  6. Offline

    Xerox262

    Wasn't this answered in your other thread? Also you never answered my question from the other thread about if you got permission from the creator of the plugin to edit the code or why you didn't ask him to just add the updating sign feature.
     
    Zombie_Striker likes this.
  7. Author of this plugin is not playing Minecraft anymore, and I told him to give me the source, so I can continue creating the plugin.
     
  8. Offline

    Zombie_Striker

    @Xerox262
    If it was the same problem, this would be counted as double posted, which should be reported.
     
  9. Offline

    Xerox262

    It wasn't the same problem though, he was asking how to update it in a player move event, this time he is asking how to do it in a task.
     
  10. So how to do it?
     
  11. Offline

    Scimiguy

    Do you understand basic Java? Because.. that's what this is
     
    Zombie_Striker and Xerox262 like this.
  12. I'm just the beginner, this is why I'm asking for help.
     
  13. Offline

    mcdorli

    Learn java, this is the biggest help we can give you.
     
    Zombie_Striker likes this.
  14. I was thinking about task, which will check every sign within radius 5 block from exact location and update signs, like in this code.
     
  15. Offline

    Xerox262

    It's better to run a task ever so often in a task to check if a sign should be changed rather than just change the sign when something happens?
     
  16. I'm thinking about something which is maybe possible for me.
     
  17. Offline

    Scimiguy

    @mouz_

    Try an easier plugin then, or learn some more Java first
     
  18. This is my way to learn java. I'm asking for help in plugin developing, not life advices.
     
  19. Offline

    Scimiguy

    We're asking for common sense, not miracles.

    We don't say things for no reason.
    The best way to do this would be store the location of signs in a HashSet, and iterate over that set every 5 seconds or so with a BukkitRunnable();

    Here's a tutorial on Schedular programming for Bukkit:
    http://wiki.bukkit.org/Scheduler_Programming

    Here's the Javadoc for HashSet:
    http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html

    Here's a tutorial on how to use HashSets:
    http://javarevisited.blogspot.com.au/2012/06/hashset-in-java-10-examples-programs.html

    Here's a link to google:
    https://www.google.com

    I would suggest you use each of those, in that order.
     
    Zombie_Striker likes this.
  20. Dude, it's not that simple for me, that's why I'm asking for help.
     
  21. Offline

    Scimiguy

    Zombie_Striker likes this.
  22. I'm looking for help with creating the task, just like I said before.
     
  23. Offline

    mcdorli

  24. Offline

    Scimiguy

    To create a new BukkitRunnable(), you do it like this:

    Code:
    BukkitTask task = new BukkitRunnable() {
         public void run() {
            //Put stuff here
        }
    }.runTaskLater(Int Delay)
    You can also replace runTaskLater with runTaskTimer(Int Delay, Int Interval), which creates a repeating task.
    There's not a whole lot more we can do beside that, and giving you the link dorli just gave you (again)
    http://wiki.bukkit.org/Scheduler_Programming
     
  25. Great, now can you tell my what do i put there?
     
  26. Offline

    Scimiguy

    Whatever code it is that you want to run later?

    This is not something we can help you with. You need to figure this out for yourself

    I won't be answering any more questions here, good luck
     
    Zombie_Striker likes this.
  27. I don't know what to put it, how to loop blocks from exact position and check if they are signs.
     
    Last edited by a moderator: Nov 24, 2015
    Scimiguy likes this.
  28. Offline

    Zombie_Striker

    And you wan tot know why?
    This forum is meant for people who understand Java, but are having problems with bukkit. Everyone here who is helping you (even if you don't see it as helping), has learned Java. Bukkit uses and works with Java, so you must have an understand of Java before you can do anything with bukkit.

    As has been stated before, you clearly have not learned how to use Java or work with Object Oriented Programming. Please learn Java before you attempt to do anything with bukkit. Here are the links again:
    http://www.tutorialspoint.com/java/
    http://wiki.bukkit.org/Plugin_Tutorial#Bukkit_Javadocs
     
  29. Please tell me how to do this task and update these task.
     
  30. Online

    timtower Administrator Administrator Moderator

    @mouz_ What is your current code?
     
Thread Status:
Not open for further replies.

Share This Page