Setting GameStates within same Server?

Discussion in 'Plugin Development' started by BeefySticks, Nov 8, 2014.

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

    BeefySticks

    Hello! What I'm trying to do is make GameStates. I'm currently trying to do it with enums however, if you have a better way of trying to do it feel free to tell me!
     
  2. Offline

    teej107

    What? Do you mean set the gamestate for the players in a List?
     
  3. Offline

    BeefySticks

    teej107
    Yes, and also set it even if players aren't in it.
    Such as if it's restarting or in a lobby where no one is in it.
     
  4. Offline

    teej107

  5. Offline

    BeefySticks

    I know, but what if the server is restarting? I wouldn't be able to check if no one is in the arraylist. Would it be possible to make lists as GameStates and set the lists to the Arraylist?
     
  6. Offline

    BetaNyan

    If you're doing something will multiple games on one server, have a class called Game or Arena.
    Put an enum inside of it.
     
  7. Offline

    tommyhoogstra

    Give the players a perm, then on join check if they have the permission and give the appropriate gamestate?
    Not sure what you mean.
     
  8. Offline

    BeefySticks

    Okay, I'm going to do that right now.

    What I'm trying to do is make GameStates for a minigame. However, the minigame is only supposed to be for one server, and I don't want to create arenas, I just want them pre-made in the code, so I'm trying to use game states so when you right click a sign you get teleported into the lobby or if its full you don't, etc.

    tommyhoogstra
    BetaNyan
    teej107

    So I've started creating the game and I wanted to get the gamestate for signs, to change it. Here it is.

    Sign:
    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent e) {
    3. Player p = e.getPlayer();
    4. if(e.getLine(0).equalsIgnoreCase("Deathrun")) {
    5. if(e.getLine(1) != null) {
    6. e.setLine(0, ChatColor.LIGHT_PURPLE + "[Join-" + e.getLine(1) + "]");
    7. e.setLine(1, "Voting");
    8. e.setLine(2, "/4");
    9. e.setLine(3, ChatColor.LIGHT_PURPLE + "· Lobby ·")
    10.  
    11. }
    12. }
    13. }
    14. }


    Game:
    Code:java
    1. public class Game {
    2.  
    3. private Core plugin;
    4. private gameState currentState = gameState.LOBBY;
    5. private Location lobby;
    6. private Location game;
    7.  
    8. public Game(Player player) {
    9.  
    10. lobby = new Location(player.getWorld(), 0, 25, 0);
    11. game = new Location(player.getWorld(), 100, 25, 0);
    12.  
    13.  
    14. }
    15.  
    16. public void joinLobby(Player player) {
    17. player.setGameMode(GameMode.SURVIVAL);
    18. player.getInventory().clear();
    19. player.getInventory().setHelmet(null);
    20. player.getInventory().setChestplate(null);
    21. player.getInventory().setLeggings(null);
    22. player.getInventory().setBoots(null);
    23. player.setHealth(20.0);
    24. player.setFoodLevel(20);
    25. player.setExhaustion(0);
    26. player.getInventory().setHeldItemSlot(0);
    27.  
    28. player.sendMessage(plugin.prefix + ChatColor.YELLOW + "You have just joined Deathrun " + "!");
    29.  
    30. player.teleport(lobby);
    31.  
    32.  
    33. }
    34.  
    35. public void startGame() {
    36.  
    37. }
    38.  
    39. public void stopGame() {
    40.  
    41. }
    42.  
    43. public gameState getState() {
    44. return currentState;
    45.  
    46. }
    47.  
    48. public enum gameState {
    49. LOBBY, INGAME, FULL, RESTARTING;
    50. }
    51.  
    52. }


    Arraylists:
    Code:java
    1. public class Arraylists {
    2.  
    3. public static List<Player> lobby = new ArrayList<Player>();
    4. public static List<Player> game = new ArrayList<Player>();
    5.  
    6. // DEATHRUN GAMES
    7.  
    8. HashMap<String, Player> dr1 = new HashMap<String, Player>();
    9. HashMap<String, Player> dr2 = new HashMap<String, Player>();
    10.  
    11.  
    12. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  9. Offline

    BetaNyan

    For if (e.getLine(1) != null) change null to ""
     
  10. Offline

    BeefySticks

    Okay I've changed it. So now, how would I check if the first line was equal to a hashmap in my arraylist class and then put them in it.
     
  11. Offline

    BetaNyan

    Also stop saving Player in a HashMap/ArrayList. It causes Memory Leaks. Use the Player name.
     
  12. Offline

    teej107

    Not entirely true. There is more to it. It would only have a chance of causing leaks if you didn't remove the player from the collection and the player leaves.
     
Thread Status:
Not open for further replies.

Share This Page