UUID Problem ?

Discussion in 'Plugin Development' started by JordyPwner, Oct 3, 2014.

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

    teej107

    Your post is a perfect example of what my signature says.

    You should remove the static keyword and learn to pass variables through the parameters.
     
    Hawktasard likes this.
  2. Offline

    JordyPwner

    I did
    it says: Cannot make a static reference to the non-static field Commands.list

    This is my Players now:
    Show Spoiler
    package com.jordypwner.simplelist2;

    import java.util.ArrayList;
    import java.util.UUID;

    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;

    public class Players implements Listener {

    public void onPlayerJoin(PlayerJoinEvent e){
    Player player = e.getPlayer();
    Commands.list.add(player.getUniqueId());

    if(player.hasPermission("list.Donator")){
    Commands.donators.add(player.getUniqueId());
    }else if(player.hasPermission("list.Staff")){
    Commands.staff.add(player.getUniqueId());
    }
    }
    public void onPlayerJoin(PlayerQuitEvent e){
    Player player = e.getPlayer();
    Commands.list.remove(player.getUniqueId());

    if(player.hasPermission("list.Donator")){
    Commands.donators.remove(player.getUniqueId());
    }else if(player.hasPermission("list.Staff")){
    Commands.staff.remove(player.getUniqueId());
    }
    }
    }

    My Commands where the arraylist is in:
    Show Spoiler
    package com.jordypwner.simplelist2;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    public class Commands implements CommandExecutor {
    ArrayList<UUID> list = new ArrayList<UUID>();
    ArrayList<UUID> donators = new ArrayList<UUID>();
    ArrayList<UUID> staff = new ArrayList<UUID>();

    public boolean onCommand(CommandSender sender, Command cmd, String cl,
    String[] args) {
    if (!(sender instanceof Player)) {
    sender.sendMessage("Only Players Can Do This!");
    return true;
    }
    Player p =(Player) sender;
    {
    if(cmd.getName().equalsIgnoreCase("list"))

    p.sendMessage(ChatColor.GOLD + "=====================================================");
    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "+" + ChatColor.DARK_GRAY + "]" + ChatColor.YELLOW + " Players Online:" + ChatColor.GOLD + " " + list.size());
    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "+" + ChatColor.DARK_GRAY + "]" + ChatColor.YELLOW + " Donors Online:" + ChatColor.GOLD + " " + donators.size());
    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "+" + ChatColor.DARK_GRAY + "]" + ChatColor.YELLOW + " Staff Online:" + ChatColor.GOLD + " " + staff.size());
    p.sendMessage(ChatColor.GOLD + "=====================================================");
    }
    return false;
    }
    }



    BUMP

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

    Hawktasard

    Still the same error?
     
  4. Offline

    teej107

    I would say learn Java, but I doubt you will because you make excuses. Step by step, here is how you fix your problem.
    1) Remove static from your Arraylists.
    Step 2 will come once you finish step 1
     
    mythbusterma likes this.
  5. Offline

    mythbusterma

    "Learning Java" implies you wouldn't use static in this context, actually. So, why use static? Is object-oriented programming too difficult for you?

    JordyPwner

    Make getter and setter methods, also Google Translate works wonders on webpages, so don't even try to say you can't understand the guides that teej107 linked.
     
  6. Offline

    JordyPwner

    Yes it says Cannot make a static reference to the non-static field Commands.list
    when i remove static
     
  7. Offline

    Hawktasard

    Do what mythbusterma said.
     
  8. Offline

    Mysticate

    mythbusterma teej107 I answered his question about how to make the lists static. And yes, I do know how to use objects.
     
  9. Offline

    mythbusterma

    Mysticate

    I didn't ask if you knew how to use "Objects," I asked if you understood the concept of OOP, which you don't, as you recommended static in a place where it does not belong.
     
  10. Offline

    Mysticate

    mythbusterma Yes, I do understand. I was simply answering his question about how to make the ArrayList static!
     
  11. Offline

    fireblast709

    Mysticate his question was not how to make his List static, he was accessing it through a static method which caused some compiler errors which he didn't know how to solve. Your answer - even though syntactically correct - is not how people should solve access issues (which is what mythbusterma was informing you about).
     
    mythbusterma likes this.
  12. Offline

    JordyPwner

  13. Offline

    fireblast709

    JordyPwner remove the static keyword from the method and pass along the same instance you use to register Commands to those classes that need access to the List
     
  14. Offline

    JordyPwner

    LIKE i said 1000 times! i already removed the STATIC if you read my new class. (sorry im just getting mad cause people say that i remove static but i already did)
     
  15. Offline

    fireblast709

    JordyPwner well according to your last post you refer to it either statically (in the form of <SomeClass>.<staticVariable>) or in a static method. I wasn't referring to your List in this case.
     
  16. Offline

    JordyPwner

  17. Offline

    teej107

    JordyPwner Now create a constructor in your Players class passing your Commands class in the parameters. In your Commands class, create a getter for each ArrayList.
     
  18. Offline

    JordyPwner

    ... My language please?
     
  19. Offline

    mythbusterma

    JordyPwner
    Maak nu een aannemer in uw Spelers klas slagen voor je Commando klasse in de parameters. In je Commando klasse, maak een getter voor elke ArrayList.
     
  20. Offline

    JordyPwner

    Dude you are translating that failed :/
     
  21. Offline

    mythbusterma

    JordyPwner

    This is an English forum, we offer help in English and English only. If you can't understand us, you should seek help elsewhere. The best we can do is use Google Translate to translate messages.
     
  22. Offline

    JordyPwner

    NEVER use google translate! it sticks word together!
     
  23. Offline

    teej107

    JordyPwner As bad as Google Translate can be, it is the only way we can translate into your language. As mythbusterma said, this is an English forum. Learn to understand what we are saying or find a different forum that you can understand. If you have a question about what we are saying, ask!
     
    mythbusterma likes this.
Thread Status:
Not open for further replies.

Share This Page