Not Being Added To List

Discussion in 'Plugin Development' started by danthonywalker, Jul 8, 2013.

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

    danthonywalker

    So basically I'm just trying out doing a queue system and whatnot. In theory, I would think this would work, but it's not. Actually, I can't even tell if it would work because I'm not being added to the list.

    Code:java
    1. public class Queue extends BukkitRunnable implements CommandExecutor
    2. {
    3. public ArrayList<String> queue = new ArrayList<String>();
    4. private Core plugin;
    5.  
    6. public Queue(Core plugin)
    7. {
    8. this.plugin = plugin;
    9. }
    10.  
    11. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    12. {
    13. PlayerData pData = new PlayerData(plugin);
    14. Player player = (Player) sender;
    15.  
    16. if(!(pData.getPlayerData().isSet(player.getName() + ".allow-to-queue")) || pData.getPlayerData().getBoolean(player.getName() + ".allow-to-queue"))
    17. {
    18. player.sendMessage(ChatColor.RED + plugin.getName() + ": " + ChatColor.GREEN + "Added to queue. A match will be found momentarily.");
    19. pData.getPlayerData().set(player.getName() + ".allow-to-queue", false);
    20. queue.add(player.getName());
    21. pData.savePlayerData();
    22. return true;
    23. }
    24.  
    25. player.sendMessage(ChatColor.RED + plugin.getName() + ": " + ChatColor.YELLOW + "You are unable to queue at this time.");
    26. return true;
    27. }
    28.  
    29. public void run()
    30. {
    31. System.out.print(queue.size());
    32.  
    33. for(String players : queue)
    34. {
    35. if(queue.size() < plugin.getConfig().getInt("queueNumber"))
    36. Bukkit.getPlayer(players).sendMessage(ChatColor.RED + plugin.getName() + ": " + ChatColor.YELLOW + "A match was not found. Still searching...");
    37.  
    38. else
    39. for(byte counter = 0; counter <= plugin.getConfig().getInt("queueNumber"); counter++)
    40. Bukkit.getPlayer(queue.get(counter)).sendMessage(ChatColor.RED + plugin.getName() + ": " + ChatColor.GREEN + "A match was found! Good luck!");
    41. }
    42.  
    43. }
    44.  
    45. }


    When I run the command everything goes fine. I get the text saying I've been adding, my allowed-to-queue changes successfully. However, my name is not being added to the list. I have the scheduler run every 30 seconds and each time it runs it displays nothing is in the list and I don't get any of the two messages that should occur. Anyone tell me what I'm doing wrong?
     
  2. Offline

    Polaris29

    I'm not sure how you're scheduling the task and setting the executor, but if you're doing it like this:
    Code:
    this.getCommand("commandname").setExecutor(new Queue());
    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Queue(), 0, 600);
    
    Then it's creating two separate instances with a different ArrayList<String> queue
     
    danthonywalker likes this.
  3. Offline

    LinearLogic

    I wouldn't try to use the same class as a BukkitRunnable and a CommandExecutor...

    And when you check the list, retrieve it from the CommandExecutor object, not a BukkitRunnable instance (which is a temporary subclass and, as Polaris29 mentioned, is maintaining a different list than your command executor).

    Quite frankly, I think your best bet is to maintain a central list in your main class, which both forms of the Queue access.
     
  4. Offline

    danthonywalker


    Alright, that actually helped. I basically just made a object of the class in my main and replaced all the instances instead. So now it looks like this.

    Code:java
    1. public void onEnable()
    2. {
    3. Queue queue = new Queue(this);
    4. getCommand("queue").setExecutor(queue);
    5. queue.runTaskTimer(this, 0, 600);
    6. }


    Thanks for the hint.
     
Thread Status:
Not open for further replies.

Share This Page