Is this a good way to structure my arenas

Discussion in 'Plugin Development' started by DividedByZero, Aug 2, 2014.

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

    DividedByZero

    Hello I am kinda new to the bukkit api and to java. I have finished a few classes on java and jumped right in to making bukkit plugins. I was a former php developer that developes the backend of web based games. Usally multiplayer games like mmorps stuff like that. This is basicly my first plugin I have made and I decided to make a minigame plugin to challenge myself. I could use some tips on how to structure my arenas and stuff. I already have the minigame hub coded and this is my arena object. I decide to have an arena object and then have an arena manager handle all the other data.
    Code:
    package org.hiros.laserbattle.Arenas;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    
    public class Arena {
        @SuppressWarnings("unused")
        private Plugin plugin;
        public Arena(Plugin plugin) {
            this.plugin = plugin;
        }
        
        public enum ArenaState {
            STARTED, DISABLED, WAITING
        }
        
        private ArenaState state;
        
        private Integer id;
        private Integer minPlayers;
        private Integer maxPlayers;
        private List<UUID> players;
        
        public Arena(Integer id) {
            this.id = id;
            this.minPlayers = 3;
            this.maxPlayers = 8;
            this.players = new ArrayList<UUID>();
            this.state = ArenaState.WAITING;
        }
        
        public void addPlayer(Player player) {
            UUID playerid = player.getUniqueId();
            players.add(playerid);
        }
        
        public void removePlayer(Player player) {
            UUID playerid = player.getUniqueId();
            players.remove(playerid);
        }
        
        public Integer getId() {
            return id;
        }
        
        public Integer getMinPlayers() {
            return minPlayers;
        }
        
        public Integer getMaxPlayers() {
            return maxPlayers;
        }
        
        public ArenaState getState() {
            return state;
        }
        
        public Integer getNumOfPlayers() {
            return players.size();
        }
        
        public boolean containsPlayer(Player player) {
            return players.contains(player.getUniqueId());
        }
        
    }
    
     
  2. Offline

    fireblast709

    DividedByZero you should use the primitive int instead of Integer. Also you have two constructors that initialize different fields, this doesn't work.
     
  3. Offline

    DividedByZero

    fireblast709 I have to have it so I can get an instance of LaserBattle plugin could I just make a static method that returns the instance?
     
  4. Offline

    TeeePeee

    DividedByZero yes, or condense the two constructors into one.

    public Arena(Plugin plugin, int id) { ... }
     
Thread Status:
Not open for further replies.

Share This Page