shceduled task not working?

Discussion in 'Plugin Development' started by xelatercero, Nov 22, 2019.

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

    xelatercero

    So i made a scheduled task to make like a countdown , but doesnt seem to work:

    EDIT: i even added a debug message in the shceduled task , but is not printing

    EDIT 2 : so im an idiot , the dbug message is in the wrong place, the scheduled task is firing correctly , its like there is nothing storing inot the map . I added the code from the class where the clock is getting the map.

    PHP:
    public class Clock {
     
        public 
    Clock() {
         
        }
     
        
    DrinkPotion drink = new DrinkPotion();
     
     
        public 
    void startClock() {
         
            
    Bukkit.getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("Vuelta"), new Runnable() {
             
             
                public 
    void run() {
                 
                    for(
    Entry<PlayerIntegermap drink.count.entrySet()) {
                        
    System.out.println("debug");
                     
                     
                        
    Player player map.getKey();
                        
    int sec map.getValue();
                     
                     
                        
    sec--;
                     
                        
    drink.count.put(playersec);
                     
                        if(
    sec == 0) {
                            
    drink.count.remove(player);
                            
    player.sendMessage("has sido eliminado de la lista");
                        }
                     
                     
                     
                    }
                 
                }
             
             
            }, 
    0L20);
         
         
        }

    }

    PHP:
    public class Main extends JavaPlugin {
     
        
    Frases frases = new Frases();
        
    Items itemsInstance = new Items();
        
    Clock clock = new Clock();

     
     
        @
    Override
     
        
    public void onEnable() {
     
            
    CommandSender console Bukkit.getConsoleSender();
         
            
    console.sendMessage(frases.PLUGIN_PREFIX "Plugin enabled correctly");
         
            
    clock.startClock();
            
    registerCommands();
            
    registerEvents();
            
    registerItems();
         
         
         
         
        }
     
     
     
        @
    Override
     
        
    public void onDisable() {
         
            
    CommandSender console Bukkit.getConsoleSender();
         
            
    console.sendMessage(frases.PLUGIN_PREFIX "Plugin disabled correctly");
        }
     
     
        private 
    void registerCommands() {
         
         
         
        }
     
     
        private 
    void registerEvents() {
            
    Bukkit.getPluginManager().registerEvents(new DrinkPotion(), this);
         
        }
     
        private 
    void registerItems() {
            
    itemsInstance.waterWalk();
         
        }

    PHP:
    public class DrinkPotion implements Listener {
       
        public 
    DrinkPotion() {
           
        }
       
        
    HashMap<PlayerIntegercount = new HashMap<PlayerInteger>();
       
        
    Items items = new Items();
       
        @
    EventHandler
       
        
    public void onPotionDrink(PlayerItemConsumeEvent e) {
            
    System.out.println("consumed item");
           
            
    Player player e.getPlayer();
           
            
    ItemStack item e.getItem();
            
    ItemMeta meta item.getItemMeta();
           
            if(
    item!=null) {
                if(
    meta!=null) {
                    if(
    meta.getDisplayName()!=null) {
                       
                        if(
    meta.getDisplayName().equalsIgnoreCase(ChatColor.DARK_PURPLE "ICE WALKER")) {
                            
    count.put(player30);
                            
    player.sendMessage("added to list");
                        }
                       
                       
                       
                    }
                } 
               
            }
               
                   
               
           
           
           
           
           
           
        }

    }
     
    Last edited: Nov 22, 2019
  2. Offline

    Strahan

    You're creating a new DrinkPotion instance in the Clock class then iterating over it. If you just created it, and I don't see anywhere you set data to it, I assume it's empty so of course nothing will happen when your runnable iterates it. I don't see the field being public or having a setter, so how do you plan to populate it?

    Also you don't need to get the console sender to send messages in onEnable; use the logger that's what it is there for. e.g. getLogger().info("blah blah"); That said, sending a "plugin enable" message is just pointless spam as Spigot already sends messages upon enable/disable.
     
Thread Status:
Not open for further replies.

Share This Page