Enums

Discussion in 'Plugin Development' started by Starfire1337, Aug 7, 2014.

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

    Starfire1337

    I've just learned a bit about enums, and I want to give them a try in my new minigame, currently, I am using them to tell the state of a current arena. From my understanding, if I were to use enums to tell the state of an arena instead of a HashMap etc., would I only be able to have 1 arena per server? If this isn't the case, How do I set it up so that I can have multiple arenas?
     
  2. Offline

    FabeGabeMC

    Starfire1337
    First of all, create an arena object. (Main step on creating arenas).
    After that, store all your variables (name, id, maxPlayers, spawns, etc...)
    And to apply that enum, make sure you add the enum class as a variable.
    ex:
    Code:java
    1. package me.FabeGabe;
    2.  
    3. public class Arena {
    4.  
    5. // All your variables...
    6. private State s;
    7.  
    8. public Arena(**YOUR VARIABLES HERE**) {
    9. // Make sure your arena's state is set to
    10. // lobby once it's created so players can join.
    11. s = State.LOBBY;
    12. }
    13.  
    14. //Get the arena's state.
    15. public State getState() {
    16. return s;
    17. }
    18.  
    19. }
     
  3. Offline

    Starfire1337

    FabeGabeMC
    Will this work if there are multiple arenas?
     
  4. Offline

    fireblast709

  5. Offline

    Forseth11

    Enums can be used like classes. What I mean by this is that you can use them as objects. So yes you can do it for multiple arenas. Simple do new(enumName(AnyValuesIfYouRequireFromEnum)). You will then have an instance of that enum.
     
  6. Offline

    fireblast709

    Forseth11 wat. You don't seem to know what an enum is yourself
     
    AoH_Ruthless likes this.
  7. Offline

    FabeGabeMC

  8. Offline

    mazentheamazin

    Forseth11
    You can't initialize an enum. Please know what you're talking about before giving advice to others.

    Starfire1337
    I would recommend you look at the link fireblast709 for more information about enums, however I'll give you a simplified one which answers your question. If you store the state of an arena in the arena class you do not require to have a HashMap containing the enum and the arena (as that wouldn't be the smartest idea anyways).

    When you're comparing enums it is recommended to use '==' or switch statements.
     
  9. Offline

    Forseth11

    fireblast709 mazentheamazin
    Oh my gosh I can not believe I even said something that stupid last night!
    Why did I say us an enum like: new enum?
    I meant to say something like: enumName var = enumName.value.
     
Thread Status:
Not open for further replies.

Share This Page