Team Class Example

Discussion in 'Plugin Development' started by BurnerDiamond, Apr 16, 2015.

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

    BurnerDiamond

    Hello Bukkit community.

    I was wondering if anyone could make me an example of a Team class.

    So far I have the method :

    public Teams(String color, int team) {

    Can anyone give me a code example, of a full team code.

    This is a request of a spoonfeed, but I swear to god I will not copy or use any piece of code that is given without fully understanding it!

    Thanks

    - BurnerDiamond
     
  2. Offline

    teej107

    Create a class
    Inside the class....
    Use a Collection to put the Players in that are part of the team
    Maybe have a getter method to identify the team
     
    bwfcwalshy likes this.
  3. Offline

    BurnerDiamond

    I'm asking for a code example.

    I've spent hours and hours using and trying multiple codes, constructors, methods and much more. This is what I have so far.

    It's for a UHC plugin so here:

    Team:

    Code:
    package me.olympusmc.utc;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.UUID;
    
    /**
    *
    */
    public class Team {
    
        private String color;
        private int number;
    
        private List<UUID> player = new ArrayList<UUID>();
    
        private List<Team> teams = new ArrayList<Team>();
    
        public String getColor() {
            return color;
        }
    
        public int getNumber() {
            return number;
        }
    
        public List<UUID> getPlayer() {
            return player;
        }
    
        public List<Team> getTeams() {
            return teams;
        }
    
        public HashMap<Team, UUID> getMembers1() {
            return members1;
        }
    
        public HashMap<Team, UUID> getMembers2() {
            return members2;
        }
    
        public HashMap<Team, UUID> getMembers3() {
            return members3;
        }
    
        public HashMap<Team, UUID> getMembers4() {
            return members4;
        }
    
        public HashMap<Team, UUID> getMembers5() {
            return members5;
        }
    
        private HashMap<Team, UUID> members1 = new HashMap<Team, UUID>();
        private HashMap<Team, UUID> members2 = new HashMap<Team, UUID>();
        private HashMap<Team, UUID> members3 = new HashMap<Team, UUID>();
        private HashMap<Team, UUID> members4 = new HashMap<Team, UUID>();
        private HashMap<Team, UUID> members5 = new HashMap<Team, UUID>();
    
        public Team(String color, int number) {
            this.color = color;
            this.number = number;
    
            teams.add(this);
        }
    
      
    
    }
    
    Then the main class:

    Code:
    package me.olympusmc.utc;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
    * 
    */
    public class Core extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
    
            Team team1 = new Team("§0", 1);
            Team team2 = new Team("§1", 1);
            Team team3 = new Team("§2", 1);
            Team team4 = new Team("§3", 1);
            Team team5 = new Team("§4", 1);
            Team team6 = new Team("§5", 1);
            Team team7 = new Team("§6", 1);
            Team team8 = new Team("§7", 1);
            Team team9 = new Team("§8", 1);
            Team team10 = new Team("§9", 1);
            Team team11 = new Team("§a", 1);
            Team team12 = new Team("§b", 1);
            Team team13 = new Team("§c", 1);
            Team team14 = new Team("§d", 1);
            Team team15 = new Team("§e", 1);
            Team team16 = new Team("§f", 1);
            Team team17 = new Team("§n§1", 1);
            Team team18 = new Team("§n§2", 1);
            Team team19 = new Team("§n§3", 1);
            Team team20 = new Team("§n§4", 1);
            Team team21 = new Team("§n§5", 1);
            Team team22 = new Team("§n§6", 1);
            Team team23 = new Team("§n§7", 1);
            Team team24 = new Team("§n§8", 1);
            Team team25 = new Team("§n§9", 1);
            Team team26 = new Team("§n§a", 1);
            Team team27 = new Team("§n§b", 1);
            Team team28 = new Team("§n§c", 1);
            Team team29 = new Team("§n§d", 1);
            Team team30 = new Team("§n§e", 1);
            Team team31 = new Team("§n§f", 1);
            Team team32 = new Team("§m§1", 1);
            Team team33 = new Team("§m§2", 1);
            Team team34 = new Team("§m§3", 1);
            Team team35 = new Team("§m§4", 1);
            Team team36 = new Team("§m§5", 1);
            Team team37 = new Team("§m§6", 1);
            Team team38 = new Team("§m§7", 1);
            Team team39 = new Team("§m§8", 1);
            Team team40 = new Team("§m§9", 1);
            Team team41 = new Team("§m§a", 1);
            Team team42 = new Team("§m§b", 1);
            Team team43 = new Team("§m§c", 1);
            Team team44 = new Team("§m§d", 1);
            Team team45 = new Team("§m§e", 1);
            Team team46 = new Team("§m§f", 1);
            Team team47 = new Team("§l", 1);
            Team team48 = new Team("§l", 1);
            Team team49 = new Team("§l", 1);
            Team team50 = new Team("§l", 1);
    
            getCommand("team").setExecutor(new Commands(this));
            getCommand("teamscatter").setExecutor(new Commands(this));
    
            getServer().getPluginManager().registerEvents(this, this);
    
            saveDefaultConfig();
        }
    
    
        @Override
        public void onDisable() {
    
        }
    }
    
     
  4. Offline

    Rocoty

    :confused:

    You're severely overthinking this. Have you heard of the single responsibility principle, and why you should strive to make classes as simple as possible?

    Really sit down and think about what a team needs to have, and what it does not need to know about. For instance, does it make sense for a team to always keep a reference to all other teams, or at all? What is the number field supposed to represent?
     
    The Fancy Whale likes this.
Thread Status:
Not open for further replies.

Share This Page