Paintball Game Ending Error

Discussion in 'Plugin Development' started by Booshayy, Nov 24, 2013.

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

    Booshayy

    Hi! On my paintball plugin, players can't leave, win, or the game won't force end without an error.

    Here are the errors the console gives me:
    http://prntscr.com/26j70t

    Here is the code:
    Code:
    [Arena 109]:        players.remove(pd);
     
    [Arena 135]:    }
     
    [ForceStop 37]:        a.stop(null);
     
  2. Offline

    mattrick

    Booshayy
    1) You didn't post your code

    2) What is line 135?

    3) Aren't lists fun?? :p
     
  3. Offline

    Booshayy

  4. Offline

    mattrick

    Full code please, I'm not sure what context the code you posted is.
     
  5. Offline

    Booshayy

    Okay. mattrick16
    Code:
    package me.pierce.Paintball.cmds;
     
    import me.pierce.Paintball.Arena;
    import me.pierce.Paintball.ArenaManager;
    import me.pierce.Paintball.MessageManager;
     
    import org.bukkit.entity.Player;
     
    public class ForceStop extends SubCommand {
     
        public void onCommand(Player p, String[] args) {
            if (args.length == 0) {
                MessageManager.getInstance().severe(p, "You must specify an arena ID.");
                return;
            }
           
            int id = -1;
           
            try { id = Integer.parseInt(args[0]); }
            catch (Exception e) {
                MessageManager.getInstance().severe(p, args[0] + " is not a valid number!");
                return;
            }
           
            Arena a = ArenaManager.getInstance().getArena(id);
           
            if (a == null) {
                MessageManager.getInstance().severe(p, "There is no arena with ID " + id + "!");
                return;
            }
           
            if (!a.isStarted()) {
                MessageManager.getInstance().severe(p, "Arena " + id + " has not yet started!");
                return;
            }
           
            a.stop(null);
            MessageManager.getInstance().good(p, "Force stopped Arena " + a.getID() + "!");
        }
       
        public String name() {
            return "forcestop";
        }
       
        public String info() {
            return "Force stop an arena.";
        }
       
        public String[] aliases() {
            return new String[] { "fstop", "stop" };
        }
    }
    Code:
    package me.pierce.Paintball;
     
    import java.util.ArrayList;
     
    import me.pierce.Paintball.ArenaManager.Team;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.DyeColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.material.Wool;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
     
     
    public class Arena {
     
        private int id;
        private boolean started = false;
        private boolean cd = false;
        private Location redspawn, bluespawn;
        private ArrayList<PlayerData> players = new ArrayList<PlayerData>();
       
        private Scoreboard sb;
        private Objective o;
        private Score red, blue;
       
        public Arena(int id) {
            this.id = id;
           
            ConfigurationSection conf = SettingsManager.getInstance().get(id + "");
           
            this.redspawn = getLocation(conf.getConfigurationSection("redspawn"));
            this.bluespawn = getLocation(conf.getConfigurationSection("bluespawn"));
           
            sb = Bukkit.getServer().getScoreboardManager().getNewScoreboard();
            o = sb.registerNewObjective("Team Scores", "dummy");
            red = o.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.RED + "Red"));
            blue = o.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.BLUE + "Blue"));
        }
       
        private Location getLocation(ConfigurationSection path) {
            return new Location(
                    Bukkit.getServer().getWorld(path.getString("world")),
                    path.getDouble("x"),
                    path.getDouble("y"),
                    path.getDouble("z")
                    );
        }
       
        public int getID() {
            return id;
        }
       
        public boolean isStarted() {
            return started;
        }
       
        public void setStarted(boolean started) {
            this.started = started;
        }
       
        public Location getSpawn(Team team) {
            switch(team) {
            case RED: return redspawn;
            case BLUE: return bluespawn;
            default: return null;
            }
        }
       
        public Team getTeam(Player p) {
            return getData(p).getTeam();
        }
       
        public void addPlayer(Player p) {
            players.add(new PlayerData(p.getName(), getTeamWithLessPlayers(), p.getInventory().getContents(), p.getInventory().getArmorContents(), p.getLocation()));
           
            p.getInventory().clear();
            p.getInventory().addItem(new ItemStack(Material.SNOW_BALL, 32));
            p.getInventory().setHelmet(new Wool(DyeColor.valueOf(getData(p).getTeam().toString())).toItemStack(1));
           
            p.teleport(getSpawn(getData(p).getTeam()));
           
            p.setScoreboard(sb);
           
            p.setGameMode(GameMode.SURVIVAL);
            p.setFlying(false);
           
            MessageManager.getInstance().info(p, "You have joined arena " + getID() + " and are on the " + ChatColor.valueOf(getData(p).getTeam().toString()) + getData(p).getTeam().toString().toLowerCase() + ChatColor.YELLOW + " team!");
           
            if (players.size() >= 2 && !cd) start();
        }
       
        public void removePlayer(Player p, boolean lost) {
            PlayerData pd = getData(p);
           
            p.getInventory().clear();
            for (ItemStack i : pd.getContents()) if (i != null) p.getInventory().addItem(i);
            p.getInventory().setArmorContents(pd.getArmorContents());
           
            p.teleport(pd.getLocation());
           
            players.remove(pd);
           
            if (lost) {
                MessageManager.getInstance().info(p, "You lost the game.");
                msg(p.getName() + " lost the game.");
            }
        }
       
        public void start() {
            cd = true;
            msg(ChatColor.DARK_BLUE + "Game starting in 30 seconds!");
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SettingsManager.getInstance().getPlugin(), new Runnable() {
                public void run() {
                    Arena.this.started = true;
                    Arena.this.cd = false;
                    msg("Good luck!");
                }
            }, 30 * 20);
        }
       
        public void stop(Player winner) {
            msg(winner != null ? winner.getName() + " won the game!" : "The game was ended.");
            for (PlayerData pd : players) {
                Player p = Bukkit.getServer().getPlayer(pd.getPlayerName());
                removePlayer(p, true);
            }
        }
       
        public void addDeath(Player p) {
            Team t = getTeam(p);
            if (t == Team.RED) blue.setScore(blue.getScore() + 1);
            else red.setScore(red.getScore() + 1);
        }
       
        private void msg(String msg) {
            for (PlayerData pd : players) {
                Player p = Bukkit.getServer().getPlayer(pd.getPlayerName());
                MessageManager.getInstance().info(p, msg);
            }
        }
       
        private Team getTeamWithLessPlayers() {
            int red = 0, blue = 0;
            for (PlayerData pd : players) {
                if (pd.getTeam() == Team.RED) red++;
                else blue++;
            }
            if (red > blue) return Team.BLUE;
            else return Team.RED;
        }
       
        public boolean containsPlayer(Player p) {
            return getData(p) != null;
        }
       
        private PlayerData getData(Player p) {
            for (PlayerData pd : players) {
                if (pd.getPlayerName().equalsIgnoreCase(p.getName())) return pd;
            }
            return null;
        }
     
     
    }
     
  6. Offline

    mrkirby153

    Booshayy

    Can I please see the full error log?
     
  7. Offline

    mattrick

    Booshayy
    Sorry, but I need these lines: 109 and 135. Also, you are force stopping the arena in your onCommand method even if the arena has not started.
     
  8. Offline

    Booshayy

  9. Offline

    mrkirby153

    Booshayy

    1. Your scoreboard is null (The error)
    2. What order are you calling the methods?
     
  10. Offline

    Booshayy

    mrkirby153 If I change it to true, it still gives me an error.

    I don't know what you mean by that.
     
  11. Offline

    mrkirby153

    Booshayy

    Like:
    start();
    update();
    end();
    reset();
     
  12. Offline

    L33m4n123

    What does that has to do with the fact that your scoreboard is null?
     
  13. Offline

    Booshayy

    L33m4n123 Woops, thought he was talking about my a.stop(null), and if I change THAT to true, it doesn't work either.
     
Thread Status:
Not open for further replies.

Share This Page