Solved Arranging Players to Freeze with ArrayLists

Discussion in 'Plugin Development' started by FabeGabeMC, Mar 2, 2014.

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

    FabeGabeMC

    Hi. I have coded a scheduledrepeating task with the getServer().getScheduler()..... method and I have been wanting to add all Players from queue (ArrayList<String>) to frozen (ArrayList<String>) so the players can't leave their current positions until the countdown gets to a certain number.

    Here's my code just in case:

    Code:
    //ArrayLists (All classes)
     
    ArrayList<String> queue = new ArrayList<String>();
    ArrayList<String> frozen = new ArrayList<String>();
     
    /////////////////////////////////////////////////////
     
    //Countdown Code (Countdown.class)
     
    if(number == 1224){
    frozen.addAll(queue);
    queue.clear();
                }
     
    /////////////////////////////////////////////////////
    //Freeze Listener (PlayerListener.class)
     
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent e){
        Player p = e.getPlayer();
            if(frozen.contains(p.getName())){
        e.setTo(e.getFrom());
        }
        }
     
    /////////////////////////////////////////////////////
    For some reason, I think the one that didn't trigger was the Listener. It could have been the countdown.

    If it was the action that didn't trigger, would someone tell me how to make an arrayList accessible from other Java classes?

    If not, would someone tell me the error?

    Thanks,

    FabeGabe
     
  2. Offline

    Norbu10

    I think you need to do (Player).getName to save it in the arraylist
     
  3. Offline

    Barinade

  4. Offline

    FabeGabeMC

    Barinade What I'm looking for is how to do that, yes, but while a repeating task is going on. In my case, a countdown. Not by a command.
     
  5. Offline

    Barinade

    Use runTaskLater if you aren't doing so.
    I was sharing a better method, that's all.
     
  6. Offline

    FabeGabeMC

    Barinade I respect your methods on doing your plugins but I said what I was trying to do is freeze them or move them to a different arraylist once the countdown hits a certain number (1225) and unfreeze them once the countdown hits 1200. Would I have to do your method in those certain lines of code?
     
  7. Offline

    Barinade

    runTaskLater
     
  8. Offline

    FabeGabeMC

  9. Offline

    Barinade

    It is what you're looking for, you just don't know how to use it.
     
  10. Offline

    MisterPhiloe

    loooool RunTaskLater is good
     
  11. Offline

    Barinade

    //freeze players here
    getServer().getScheduler().runTaskLater(new Runnable() {
    //unfreeze players
    },100L); //100L is the time in ticks before the code is ran. 20L = 1 second. 100L = 5 seconds.

    If you want to access variables from your plugin class in a separate class, add this constructor
    Plugin plugin;
    public MyCustomClass(Plugin plugin) {
    this.plugin = plugin;
    }
    //use plugin.myVariable to access variables in your main plugin class
     
  12. Offline

    FabeGabeMC

    MisterPhiloe I just don't know how to use runtasklater.. >_>

    Barinade I use a different class for the countdown.
    getServer().getScheduler().runTaskLater(new Runnable() {
    would be
    getServer().getScheduler().runTaskLater(new Countdown()
    in my code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  13. Offline

    Barinade

    Congratulations then? I don't care how you create the runnable, just saying you should runTaskLater in this case.
     
  14. Offline

    FabeGabeMC

    Barinade I have no idea how to use runTaskLater. :/ I explained to MisterPhaloe.

    Philoe*

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  15. Offline

    Barinade

    First off, I was wrong before. runTaskLater calls for three arguments, plugin, runnable, and long

    getServer().getScheduler().runTaskLater(this, new MyRunnable(), 100l); //where 100l is 5 seconds, 20 per second
     
  16. Offline

    PogoStick29

    FabeGabeMC I probably could.

    Here's a video on cool downs (which you can adapt to unfreeze all players when the "cooldown" ends:

     
  17. Offline

    FabeGabeMC

    PogoStick29 Doesn't seem to work. I tried but it gave me a bunch o' errors:
    http://pastebin.com/XXvp63jE

    PogoStick29 Well, add me on Skype? Skype: megazoroark16.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  18. Offline

    PogoStick29

    Here's the important line:

    1. Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R1.entity.CraftItem cannot be cast to org.bukkit.entity.Player

    Looks like you forgot to check if the entity was a player in whatever event your are using.
     
  19. Offline

    FabeGabeMC

    PogoStick29 just add me on Skype. i will explain what the problem is in more detail.
     
  20. Offline

    Wolfey

    Or an easier way would be to use the System.currentTimeMillis() method.
     
    calebbfmv likes this.
  21. Offline

    FabeGabeMC

    *bump*

    Please help me guys! :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  22. Offline

    Borlea

    Do debug code, figure out what doesnt happen.
     
  23. Offline

    AoH_Ruthless

    FabeGabeMC
    You can only bump once every 24 hours.

    Everyone else has told you how to fix it: nobody is going to add you on skype if you are being ignorant. This issue should be solved by now, in all honesty.
     
  24. Offline

    FabeGabeMC

    AoH_Ruthless I never bumped twice. Plus, I fixed it. For some reason, the
    Code:java
    1. if(number == 1224){
    2. frozen.addAll(queue);
    3. queue.clear();
    4. }

    didn't trigger.
     
  25. Offline

    AoH_Ruthless

    FabeGabeMC
    That's great you fixed it!

    But, you are bumping significantly if you look at your posts.
    There is an edit tool, instead of adding multiple things in multiple posts.
     
  26. Offline

    FabeGabeMC

  27. Offline

    Hellborn5456

    FabeGabeMC
    Code:
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent e){
    if(frozen.contains(p.getName){
    Player p = e.getPlayer();
    p.teleport(p);
    }
    }
    
     
  28. Offline

    Wolfey

    Ugh, why exactly are you teleporting the player to it's self?
     
  29. Offline

    Hellborn5456

    Wolfey it wont it will just tele-port them to where they where standing. so you really frozen there intill you get remove off of frozen arraylist
     
  30. Offline

    Wolfey

    I believe the method you're looking for is this.
    Code:java
    1. e.setTo(e.getFrom());
     
Thread Status:
Not open for further replies.

Share This Page