Scheduled tasks from InventoryClickEvent

Discussion in 'Plugin Development' started by TheBigSuperCraft, Feb 23, 2014.

Thread Status:
Not open for further replies.
  1. I'm creating a plugin that every time you walk, it will change the block under you to Diamond Block.
    I want it to be repeated.
    I'm trying to use the scheduleSyncRepeatingTask() method.
    The plugin have a GUI.
    When you take the Diamond Block, it needs to start the scheduled task.
    It's not.
    I have another issue: I want that the block will change back after 3 seconds (60 Ticks).
    What do I need to do?
    Thanks in advance.
     
  2. Offline

    tamajpm

    @TheBugSuperCraft

    For the gui you need to check the InventoryClickEvent.

    For the block change you need to make a map from blocks. In your onEnable you make a repeating task and every x seconds you remove 1 from the integer in the map<block, integer>

    Code:java
    1. public void BlockCheck() {
    2. private final Map<Block, Integer> blocks = new HashMap<Block, Integer>();
    3.  
    4. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    5. public void run() {
    6. if(blocks.size() >= 1) {
    7. for(Entry<Block, Integer> entry : blocks.entrySet()) {
    8. if(entry.getValue() >= 1) {
    9. blocks.put(entry.getKey(), entry.getValue() - 1);
    10. } else {
    11. blocks.remove(entry.getKey());
    12. }
    13. }
    14. }
    15. }
    16. }, 20, 20);
    17. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  3. @tamajmp
    I have already a GUI.
    You're not telling me how to replace the block under me and change it back after 3 seconds.
    I understand your code.
    But you're not telling me how to use it.
     
  4. I still have issues! When doing the scheduleSyncRepeatingTask I have so long error message... (Too long)
    I can only tell you the important part: The task had an exception. (The error message was the same thing over and over)
     
Thread Status:
Not open for further replies.

Share This Page