Using other classes as variables

Discussion in 'Plugin Development' started by TheMinecraftKnight, Apr 12, 2017.

Thread Status:
Not open for further replies.
  1. I know this might be java stuff, but Bukkit seems like the best place to go

    I'm making a parties plugin for a client, and I'm a bit confused with other classes and using things inside them.

    I have a command executor and a class called Party. If you type /party create qwdqwd it makes a new instance of the Party class with the owner and members in.
    Here's what I'm confused about, however:
    1) How do I update an instance? For example, if I add a player to the party how would I add them to the List<String> in the instance.
    2) How would I make the method getParty(Player), where it returns the instance of the class that contains the player in it. Also, where would I have to put it so that an instance of Party isn't required to execute it. I don't want this:
    Code:
    Party test = new Party(owner, aListOfPlayers);
    party.getParty(player);
    //I want this instead
    Party playersParty = getParty(Player);
     
  2. Offline

    timtower Administrator Administrator Moderator

    @TheMinecraftKnight Save the parties in a list somewhere.
    Loop through the list, check if the player is in the part: if so: return, if not: continue.
     
  3. I have done that, but what would it return? ​
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. @timtower
    But that doesn't return the instance of the party, which is what I'm trying to get with the getParty method
    public void getParty(Player p) {
    for (String party : config.getConfigurationSection("Parties").getKeys(false)) {
    if (config.getString("Parties." + party + ".owner").equals(p.getName())) {
    return;
    }
    }
    }
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. @timtower
    I'm confused. If I make my code
    Code:
    public Object getParty(Player p) {
            for (String party : config.getConfigurationSection("Parties").getKeys(false)) {
                if (config.getString("Parties." + party + ".owner").equals(p.getName())) {
                    return party;
                }
            }
            return p;
        }
    Then that just returns my username. I'm trying to make it return the party that the player is in.
     
  8. Offline

    timtower Administrator Administrator Moderator

    @TheMinecraftKnight No, turn the parties into objects.
    Make a party class, put them in a list.
     
Thread Status:
Not open for further replies.

Share This Page