Skip to content

Instantly share code, notes, and snippets.

@samuelhnrq
Created January 16, 2014 20:18
Show Gist options
  • Save samuelhnrq/8462650 to your computer and use it in GitHub Desktop.
Save samuelhnrq/8462650 to your computer and use it in GitHub Desktop.
package io.github.samosaara;
import java.util.ArrayList;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.CuboidRegion;
import io.github.samosaara.Exeptions.SpawnOutsideAreaException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
/**
*
* @Author Jake
*/
public class Arena {
private CuboidRegion area;
//A list of all the Arena Objects
public static ArrayList<Arena> arenaObjects = new ArrayList<Arena>();
//Some fields we want each Arena object to store:
private Location joinLocation, startLocation, endLocation; //Some general arena locations
private String name; //Arena name
private ArrayList<String> players = new ArrayList<String>(); //And arraylist of players name
private ArrayList<Location> bombSites = new ArrayList<Location>();
private int maxPlayers;
private boolean inGame = false; //Boolean to determine if an Arena is ingame or not, automaticly make it false
public Vector isInside(Location l){
return new Vector(l.getX(),l.getY(),l.getZ());
}
//Now for a Constructor:
public Arena (CuboidRegion area, String arenaName, Location joinLocation, Location startLocation, Location endLocation, int maxPlayers, Location... bombSite) throws SpawnOutsideAreaException { //So basicly: Arena myArena = new Arena("My Arena", joinLocation, startLocation, endLocation, 17)
//Lets initalize it all:
if (this.area.contains(isInside(joinLocation)) && this.area.contains(isInside(startLocation))){
this.joinLocation = joinLocation;
this.startLocation = startLocation;
} else
throw new SpawnOutsideAreaException("Invalid spawn location");
for(Location location : bombSite){
this.bombSites.add(location);
}
this.area = area;
this.name = arenaName;
this.endLocation = endLocation;
this.maxPlayers = maxPlayers;
//Now lets add this object to the list of objects:
arenaObjects.add(this);
}
//Now for some Getters and Setters, so with our arena object, we can use special methods:
public Location getJoinLocation() {
return this.joinLocation;
}
public void setJoinLocation(Location joinLocation) {
this.joinLocation = joinLocation;
}
public Location getStartLocation() {
return this.startLocation;
}
public void setStartLocation(Location startLocation) {
this.startLocation = startLocation;
}
public Location getEndLocation() {
return this.endLocation;
}
public void setEndLocation(Location endLocation) {
this.endLocation = endLocation;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getMaxPlayers() {
return this.maxPlayers;
}
public void setMaxPlayers(int maxPlayers) {
this.maxPlayers = maxPlayers;
}
public ArrayList<String> getPlayers() {
return this.players;
}
//And finally, some booleans:
public boolean isFull() { //Returns weather the arena is full or not
if (players.size() >= maxPlayers) {
return true;
} else {
return false;
}
}
public boolean isInGame() {
return inGame;
}
public void setInGame(boolean inGame) {
this.inGame = inGame;
}
//To send each player in the arena a message
public void sendMessage(String message) {
for (String s: players) {
Bukkit.getPlayer(s).sendMessage(message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment