Solved Switch and case with enums

Discussion in 'Plugin Development' started by AstramG, Aug 29, 2013.

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

    AstramG

    I have a class that I'm trying to create and I want to use a switch statement. However, a part of these lines are underlined red-
    case MessageType.GOOD:

    I don't really now how to fix this since I'm new with both enums and the switch statement, thank you!
    Code:java
    1. import org.bukkit.ChatColor;
    2. import org.bukkit.entity.Player;
    3.  
    4. public class MessageManager {
    5.  
    6. String prefix = ChatColor.DARK_GRAY + "[" + ChatColor.RED + "MCB" + ChatColor.DARK_GRAY + "] ";
    7.  
    8. public enum MessageType {
    9. GOOD, SEVERE, NOTE
    10. }
    11.  
    12. public void sendMessage(Player player, MessageType type, String message) {
    13. switch(type) {
    14. case MessageType.GOOD:
    15. player.sendMessage(prefix + ChatColor.GREEN + message);
    16. break;
    17. case MessageType.SEVERE:
    18. player.sendMessage(prefix + ChatColor.RED + message);
    19. break;
    20. case MessageType.NOTE:
    21. player.sendMessage(prefix + ChatColor.YELLOW + message);
    22. break;
    23. }
    24. }
    25.  
    26. }
    27.  


    Nevermind, I asked someone and I solved it. It appears I didn't need MessageType in the case.
    Oops.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page