Solved Not getting the player correctly?

Discussion in 'Plugin Development' started by WesJD, Dec 8, 2014.

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

    WesJD

    Well, I'm back again, with another problem. This time it's that when a player enters a team's base it doesn't execute. Here's my code so far:

    AttackManager:

    Code:java
    1. static ArrayList<Player> aManager = new ArrayList<Player>();
    2.  
    3. public void pick() {
    4. aManager.clear();
    5.  
    6. final Player randomRed = pPicker.randomRedPlayer();
    7. final Player randomBlue = pPicker.randomBluePlayer();
    8.  
    9. if(OffenseState.isState(OffenseState.BLUE)) {
    10. OffenseState.setState(OffenseState.RED);
    11. aManager.add(randomRed);
    12. Bukkit.getServer().broadcastMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + ">> " + ChatColor.WHITE + randomRed.getDisplayName() + ChatColor.YELLOW + " is now the attack bomber!");
    13. } else if(OffenseState.isState(OffenseState.RED)) {
    14. OffenseState.setState(OffenseState.BLUE);
    15. aManager.add(randomBlue);
    16. Bukkit.getServer().broadcastMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + ">> " + ChatColor.WHITE + randomBlue.getDisplayName() + ChatColor.YELLOW + " is now the attack bomber!");
    17. } else {
    18. List<String> teams = Arrays.asList("RED", "BLUE");
    19.  
    20. String team = teams.get(r.nextInt(teams.size()));
    21.  
    22. if(team.equals("RED")) {
    23. OffenseState.setState(OffenseState.RED);
    24. aManager.add(randomRed);
    25. Bukkit.getServer().broadcastMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + ">> " + ChatColor.WHITE + randomRed.getDisplayName() + ChatColor.YELLOW + " is now the attack bomber!");
    26. } else if(team.equals("BLUE")) {
    27. OffenseState.setState(OffenseState.BLUE);
    28. aManager.add(randomBlue);
    29. Bukkit.getServer().broadcastMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + ">> " + ChatColor.WHITE + randomBlue.getDisplayName() + ChatColor.YELLOW + " is now the attack bomber!");
    30. }
    31. }
    32. }


    RegionHandler:

    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent e) {
    3. Player p = e.getPlayer();
    4. if(GameState.isState(GameState.INGAME)) {
    5. if(e.getFrom().getBlockX() != e.getTo().getBlockX() || e.getFrom().getBlockY() != e.getTo().getBlockY() || e.getFrom().getBlockZ() != e.getTo().getBlockZ()) {
    6. Location pLoc = p.getLocation();
    7. World pWor = p.getWorld();
    8.  
    9. double Y = pLoc.getY() -1;
    10.  
    11. Location block = new Location(pWor, pLoc.getX(), Y, pLoc.getZ());
    12. Block b = block.getBlock();
    13.  
    14. if(b.getType() == Material.WOOL) {
    15. Wool wool = new Wool(b.getType(), b.getData());
    16. if(wool.getColor() == DyeColor.RED) {
    17. if(AttackManager.aManager.contains(p)) {
    18. Bukkit.broadcastMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + ">> " + ChatColor.YELLOW + "The attack bomber has made it into the base! Boom!");
    19. ScoreboardTasks.redLives = ScoreboardTasks.redLives -1;
    20. if(ScoreboardTasks.redLives == 0) {
    21. gManager.end();
    22. } else {
    23. gManager.next();
    24. }
    25. }
    26. } else if(wool.getColor() == DyeColor.BLUE) {
    27. if(AttackManager.aManager.contains(p)) {
    28. Bukkit.broadcastMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + ">> " + ChatColor.YELLOW + "The attack bomber has made it into the base! Boom!");
    29. ScoreboardTasks.blueLives = ScoreboardTasks.blueLives -1;
    30. if(ScoreboardTasks.blueLives == 0) {
    31. gManager.end();
    32. } else {
    33. gManager.next();
    34. }
    35. }
    36. }
    37. }
    38. }
    39. }
    40. }
     
  2. Offline

    Tecno_Wizard

    WesJD, I know this sounds dumb, but is the event registered?
     
  3. Offline

    WesJD

  4. Offline

    mythbusterma

    WesJD

    Add debug statements to see what code is and isn't being reached.
     
  5. Offline

    mine-care

    What is pPicker?
     
  6. Offline

    WesJD

    mine-care My PlayerPicker class, but I know it works because it broadcasts the message correctly.

    mythbusterma Already did, it stops when it trys to check if the player is in the ArrayList.
     
  7. Offline

    Darkpicasa

    I'd compare the two player names.
    Attributes of the player class change over time - like location, and so on.
    Unless the ArrayList updates, they will be two different versions of that player.
     
  8. Offline

    WesJD

    @Darkpicasa Player picker picks a player out of team lists. It shouldn't change.
     
  9. Offline

    mythbusterma

    @WesJD

    Don't you MAYBE think that would've been useful information to put in your original post?

    Make sure that there's players actually in the set you're checking.
     
  10. Offline

    WesJD

    @mythbusterma It had a player in it, and I should have. My bad. Anyways, this is solved, I figured out that I wasn't setting the GameState to ingame... :mad:
     
Thread Status:
Not open for further replies.

Share This Page