Skip to content

Instantly share code, notes, and snippets.

@phase
Created May 24, 2015 03:57
Show Gist options
  • Save phase/85d26f86fca90b9d8ffd to your computer and use it in GitHub Desktop.
Save phase/85d26f86fca90b9d8ffd to your computer and use it in GitHub Desktop.
How to make a Bukkit Minigame

#How to make a Bukkit minigame This is a tutorial on how to make a Bukkit minigame plugin for 1.7/1.8. You should have some basic knowledge of Java, OOP, and Bukkit.

##Arenas Arenas are the base to any minigame (unless you only want one instance of the game). These can be implemented in many different ways, but my favorite is to have an Arena class with a static ArrayList<Arena> inside it.

public class Arena {
  //global list
  private static ArrayList<Arena> arenaList = new ArrayList<Arena>();
  
  //local variables
  private String name;
  private Location spawn;
  private Location lobby;
  private ArrayList<UUID> players;

  public Arena(String name, Location spawn, Location lobby){
    this.name = name;
    this.spawn = spawn;
    this.lobby = lobby;
    this.players = new ArrayList<UUID>();
    arenaList.add(this);
  }

  //Getters for variables and arenaList
}

You'll want different variables, such as Locations, for different games. Here I have a main game spawn and a lobby for in between games. We also use UUIDs to store Players instead of the Player object due to memory leaks.

Now for some methods which we can use in Listeners (put these in your Arena class).

public static getArena(String name){
  for(Arena a : arenaList){
    //put .equalsIgnoreCase() if you want to ignore case in commands and such
    if(a.getName().equals(name)){
      return a;
    }
  }
  return null;
}

public static getArena(Player p){
  for(Arena a : arenaList){
    if(a.getPlayers().contains(p.getUniqueId)){
      return a;
    }
  }
  return null;
}

public static isInGame(Player p){
  return getArena(p) != null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment