For Loop doesn't loop through teams

Discussion in 'Spigot Plugin Development' started by TeamAurora, Apr 18, 2015.

  1. I told you where you have to use it in your Command...
  2. I mean where would I create the method

  3. In your TeamManager class. I told you what code you need a few posts before.
  4. That's literally it..
  5. "TeamAuroraYes it is. Unfortunately this account is being used from another location and I need to change the password once I get back to my computer. The tablet I am using now is having trouble accessing my email. Anyway all posts on the plugin development are probably from an ex-member so I'll let him use it until I return back from vacation and have everything set up."

    Seems this isn't the actual account holder.
  6. This is from the actual user. I was able to get it back.

    Thank's for your worries!
  7. Oh, ok, just making sure :)
  8. Yep, no problem!

    I haven't checked if he made any useless, or stupid posts, but I'll make sure just incase.
  9. Okay I'm failing to understand.

    In my OnEnable I put this:

    new TeamManager();

    Where do I put this?

    privatestatic TeamManager instance;

    public TeamManager(){
    instance =this;

    publicstatic TeamManager getInstance(){
    return instance;
  10. Use somthing like this. The problem is you are creating a new TeamManger that than the one you initially created for creating the teams.I haven't wrote it in a IDE so there might be a slight error.
    Code (Text):
    private TeamManager teamManger;

    public void onEnable(){
    teamManger = new TeamManger();

    public TeamManger getTeamManager(){
    if(teamManager !=null){
    return teamManger;
  11. Just use this as your TeamManager Class then you dont need to mofify your onEnable. Then You just have to use TeamManager.getInstance when you want to use it.

    Code (Text):
    package me.olympus.utc;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;

    * Created by its on 17/04/15.
    public class TeamManager {

       private static TeamManager instance;

       public static TeamManager getInstance() {
          if(instance == null) {
              instance = new TeamManager();
          return instance;

        public TeamManager() {
            instance = this;

        private String prefix = "§3Teams§8§l▐";

        private List<Team> teamAmount = new ArrayList<Team>();

        private List<String> players = new ArrayList<String>();

        public List<String> getPlayers() {
            return players;

        public List<Team> getTeamAmount() {
            return teamAmount;

        public void createTeams(int amount) {
            for (int times = 1; times<=amount; times++) {
                Team teams = new Team(times);
                Bukkit.broadcastMessage(prefix + "§b" + times + "§8/§b" + amount + " §ahave been created!");

        public void addPlayers(int amount) {

            Bukkit.broadcastMessage("addPlayers works!");

            for (Team team : teamAmount) {

                Bukkit.broadcastMessage("teams works");

                for(int times = 0; times<=amount; times++) {

                    int random = new Random().nextInt(players.size());
                    String name = players.get(random);
                    Player p = Bukkit.getServer().getPlayer(name);
                    p.sendMessage(prefix + "§fYou have joined Team " + team.getTeam());

    • Winner Winner x 1
  12. For crying out loud go learn Java. Stop abusing the singleton design pattern just because you don't know how to properly access variables.

    @TeamAurora I suggest you follow what @imjack16 suggested you, that's the proper way of solving your issues.
  13. I know how to access them properly. I just told him how he can solve his problem with his existing code.
    Maybe he wants his TeamManager like that for some reason. You dont know that.

    Also my Posts are at least helpful while yours are not... So please go away and spread your hate somewhere else. <3
    • Funny Funny x 1
  14. You can solve someone's problem and you can solve someone's problem properly. Simply telling them to use static will only cause problems in the near future.
    • Do your research before calling my posts useless.
    • Do your research before calling your posts helpful. (See first part of this post).
    Iit's not like I go around and hate on people just to be hateful. I'm trying to actually help people to become better developers by warning them about invalid usage of language features.
  15. Yeah, I ment not all your posts I only ment this one above. My bad.
    And yes my post is helpful, since it will solve his problem.

    Also you dont help people with stuff like that. You can always criticize in a nice and constructive way, but what you did is just rude. Also you should know as a Dev that there is not a only one right way.