Constantly check some ints

Discussion in 'Plugin Development' started by Scullyking, Oct 29, 2012.

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

    Scullyking

    I'm new to using HashMaps and time in plugins (I've usually stuck to basic logic). How would I "constantly" check check two numbers (one being the number of values in a HashMap) and the other being a normal int var.

    Also, while I'm here does anyone know how I can simulate a hashmap full of players without having to get 12 friends online? Otherwise this plugin will be a nightmare to develop.
     
  2. Offline

    Infamous Jeezy

    For checking something or doing something in a repeated timed intervals look into this:
    http://wiki.bukkit.org/Scheduler_Programming

    As for simulating a hashmap full of players, nothing really that I can think of, although if your storing your players names instead of the Player object which I hope you are you can just enter fake names into there.
    If you store the Player object instead of the name you are setting yourself up for trouble.
     
  3. Offline

    Scullyking

    Luckily you pointed that out! I have been storing the player objects, oops! Will fix. :) Also how often is too often for checking an event. Would every 3 seconds be too intensive for the server? All its doing is looking up two ints and comparing them.
     
  4. Offline

    Courier

    3 seconds would not be very intensive, but a better approach is to check them every time one changes, then you get instant results, and it doesn't bog down the server at all when they aren't changing.
     
  5. Offline

    Scullyking

    Alright thanks. :) Also, this doesn't work... not sure why. Probably putting it in the wrong place (at the moment its just in the main class).
    Code:java
    1. int gameChecker = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
    2.  
    3. public void run() { plugin.getServer().broadcastMessage("This message is printed by an async thread"); }}, 60L, 200L);


    I've never done anything with time in plugins :/
     
Thread Status:
Not open for further replies.

Share This Page