Skip to content

Instantly share code, notes, and snippets.

@PaulBGD
Created September 28, 2013 15:12
Show Gist options
  • Save PaulBGD/6743025 to your computer and use it in GitHub Desktop.
Save PaulBGD/6743025 to your computer and use it in GitHub Desktop.
ArenaManager Resource 1
package me.ultimate.Arena;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
public class ArenaManager {
// An list to hold all of the arenas
private static List<Arena> arenas = new ArrayList<Arena>();
// Method to register an arena if not registered, just adds it to the list
public static void addArena(Arena arena) {
if (!arenaRegistered(arena)) {
arenas.add(arena);
}
}
/*
* Removing a registered arena, a case of this would be a command to delete
* an arena
*/
public static void removeArena(Arena arena) {
if (arenaRegistered(arena)) {
arenas.remove(arena);
}
}
// Method to check if the arena has already been registered
public static boolean arenaRegistered(Arena arena) {
return arenas.contains(arena);
}
/*
* Method to check if an arena by a name has been registered. Example case
* would be a creation command saying that you can't have two arenas by the
* same name registered
*/
public static boolean arenaRegistered(String name) {
return getArena(name) != null;
}
/*
* Gets the arena by it's name. If you don't want it to return null, check
* if it exists first
*/
public static Arena getArena(String name) {
for (Arena arena : arenas) {
if (arena.getName().equals(name)) {
return arena;
}
}
return null;
}
// A quick method to add the player to an arena by the arena's name
public static void addPlayer(Player p, String arenaName) {
if (arenaRegistered(arenaName)) {
getArena(arenaName).getPlayerManager().addPlayer(p);
} else {
throw new IllegalArgumentException("The arena '" + arenaName + "' doesn't exist!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment