Motd help

Discussion in 'Plugin Development' started by thewalkingplay, Nov 24, 2014.

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

    thewalkingplay

    Hi, i'm making a minigame plugin and trying to make a good motd :) the status works fine, but the winner team don't works:

    http://prntscr.com/59mi2x
    if you aren't bazilian(probably) or understand Portuguese, this is the translated motd:

    Status: Post Game
    Winner Team: [com.minigame.handlres.Team@cd03425, ...

    My motd class:
    Code:java
    1. package com.minigame.utils;
    2.  
    3. import java.util.List;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.server.ServerListPingEvent;
    10.  
    11. import com.minigame.GameState;
    12. import com.minigame.handlers.Team;
    13.  
    14. public class MotdUtilities implements Listener {
    15.  
    16. static int players = Bukkit.getOnlinePlayers().length;
    17. static List<Team> teamW = Team.activeTeams;
    18. @EventHandler
    19. public static void MotdInLobby(ServerListPingEvent e) {
    20. if (GameState.isState(GameState.IN_LOBBY))
    21. e.setMotd(ChatColor.WHITE + "Status: " + ChatColor.GREEN + "No Lobby" + "\n" + ChatColor.WHITE + "Players: " + ChatColor.AQUA + players);
    22. if (GameState.isState(GameState.IN_GAME))
    23. e.setMotd(ChatColor.WHITE + "Status: " + ChatColor.RED + "Em jogo" + "\n" + ChatColor.WHITE + "Players Restantes: " + ChatColor.AQUA + players);
    24. if (GameState.isState(GameState.POST_GAME))
    25. e.setMotd(ChatColor.WHITE + "Status: " + ChatColor.YELLOW + "Final de jogo" + "\n" + ChatColor.WHITE + "Time vencedor: " + ChatColor.AQUA + teamW);
    26. }
    27.  
    28. }
    29.  


    My team class:
    Code:java
    1. package com.minigame.handlers;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.List;
    6.  
    7. import org.bukkit.Location;
    8. import org.bukkit.entity.Player;
    9.  
    10. import com.minigame.utils.ChatUtilities;
    11.  
    12. public class Team {
    13.  
    14. private static List<Team> allTeams = new ArrayList<Team>();
    15. public static List<Team> activeTeams = new ArrayList<Team>();
    16. private List<String> members = new ArrayList<String>();
    17. private static HashMap<String, Team> playerTeams = new HashMap<String, Team>();
    18. private String teamName;
    19. private Location spawn;
    20.  
    21. public Team(String teamName, Location spawn){
    22. this.teamName = teamName.trim();
    23. this.spawn = spawn;
    24. activeTeams.add(this);
    25. allTeams.add(this);
    26. }
    27. public String getName(){
    28. return teamName;
    29. }
    30. public Location getSpawn(){
    31. return spawn;
    32. }
    33. public void add(Player player){
    34. playerTeams.put(player.getName(), this);
    35. members.add(player.getName());
    36. }
    37. public boolean remove(Player player){
    38. playerTeams.remove(player.getName());
    39. members.remove(player.getName());
    40. if (members.isEmpty()){
    41. ChatUtilities.broadcast("Time " + getName() + " foi erradicado!");
    42. allTeams.remove(this);
    43. Game.stop();
    44. }
    45. return true;
    46. }
    47. public static boolean hasTeam(Player player){
    48. return playerTeams.containsKey(player.getName());
    49. }
    50. public static Team getTeam(Player player){
    51. if (!hasTeam(player))
    52. return null;
    53. return playerTeams.get(player.getName());
    54. }
    55. public static Team getTeam(String name){
    56. for (Team t : allTeams){
    57. if (t.teamName.equalsIgnoreCase(name))
    58. return t;
    59. }
    60. return null;
    61. }
    62. public static List<Team> getallTeams(){
    63. return allTeams;
    64. }
    65.  
    66. }
    67.  


    Can anyone help me?
    Sorry for my english, i'm brazilian
     
  2. Offline

    Skionz

    thewalkingplay Your printing out an object. Try turning it into a string or checking which team won and printing red or blue.
     
  3. Offline

    thewalkingplay

    Skionz i tryed to make this and don't work:
    Code:java
    1. if (GameState.isState(GameState.POST_GAME)) {
    2. if (teamW.equals("Terrorista")) {
    3. e.setMotd(ChatColor.WHITE + "Status: " + ChatColor.YELLOW + "Final de jogo" + "\n" + ChatColor.WHITE + "Time vencedor: " + ChatColor.RED + "Terroristas");
    4. }
    5. if (teamW.equals("Policial")) {
    6. e.setMotd(ChatColor.WHITE + "Status: " + ChatColor.YELLOW + "Final de jogo" + "\n" + ChatColor.WHITE + "Time vencedor: " + ChatColor.AQUA + "Policiais");
    7. }
    8. }
     
  4. Offline

    Skionz

    thewalkingplay What type of object is teamM? You shouldn't be comparing it to a String if it isn't a String.
     
  5. Offline

    thewalkingplay

    Skionz teamW is a List.

    I don't know a method to check a list and I tryed to make that
     
  6. Offline

    Avygeil

    thewalkingplay teamW is a list of Teams. How do you expect it to display the "winning team" ? Make a method somewhere that returns a single Team somehow, and use getName() to get its name. I'm saying "somewhere" because I can't see any logic in your class. I advice complete recode, a Team class and a TeamManager class implementing getWinningTeam().
     
Thread Status:
Not open for further replies.

Share This Page