Skip to content

Instantly share code, notes, and snippets.

@DarkSeraphim DarkSeraphim/Arena.java Secret
Created Aug 29, 2014

Embed
What would you like to do?
A gist for the rest of the readers of the thread. Code is written by yupie_123 (Bukkit fora)
package me.Yupie.YuPball;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import me.Yupie.YuPball.Teams.Team;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class Arena {
public YuPball plugin;
public static Arena a = new Arena();
public static Arena get(){
return a;
}
Random rnd = new Random();
private List<String> allArenas = new ArrayList<String>();
public List<String> getAllArenas() {
for (String str : plugin.arenadata.getConfig().getKeys(false)) {
allArenas.add(str);
}
return allArenas;
}
/*
* public int getAmount(String type, String arena) { ConfigAccessor conf =
* new ConfigAccessor(plugin, "Arenas.yml");
*
* ConfigurationSection section = conf.getConfig()
* .getConfigurationSection(arena);
*
* if (!type.equalsIgnoreCase("red") || !type.equalsIgnoreCase("blue") ||
* !type.equalsIgnoreCase("random") || !type.equalsIgnoreCase("center"))
* return 0;
*
* type = type.toLowerCase();
*
* if (!section.contains(type)) return 0;
*
* ConfigurationSection types = conf.getConfig().getConfigurationSection(
* arena + "." + type);
*
* List<String> list = new ArrayList<String>();
*
* for (String str : types.getKeys(false)) { list.add(str); }
*
* return list.size(); }
*/
public List<Location> getAllRed(String arena) {
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena + ".red");
List<Location> list = new ArrayList<Location>();
for (String str : section.getKeys(false)) {
int x = section.getInt(str + ".x"), y = section.getInt(str + ".y"), z = section
.getInt(str + ".z");
float pitch = (float) section.getDouble(str + ".pitch"), yaw = (float) section
.getDouble(str + ".yaw");
World world = plugin.getServer().getWorld(
section.getString(str + ".world"));
Location loc = new Location(world, x, y, z, yaw, pitch);
list.add(loc);
}
return list;
}
public List<Location> getAllBlue(String arena) {
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena + ".blue");
List<Location> list = new ArrayList<Location>();
for (String str : section.getKeys(false)) {
int x = section.getInt(str + ".x"), y = section.getInt(str + ".y"), z = section
.getInt(str + ".z");
float pitch = (float) section.getDouble(str + ".pitch"), yaw = (float) section
.getDouble(str + ".yaw");
World world = plugin.getServer().getWorld(
section.getString(str + ".world"));
Location loc = new Location(world, x, y, z, yaw, pitch);
list.add(loc);
}
return list;
}
public List<Location> getAllRandom(String arena) {
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena + ".random");
List<Location> list = new ArrayList<Location>();
for (String str : section.getKeys(false)) {
int x = section.getInt(str + ".x"), y = section.getInt(str + ".y"), z = section
.getInt(str + ".z");
float pitch = (float) section.getDouble(str + ".pitch"), yaw = (float) section
.getDouble(str + ".yaw");
World world = plugin.getServer().getWorld(
section.getString(str + ".world"));
Location loc = new Location(world, x, y, z, yaw, pitch);
list.add(loc);
}
return list;
}
public void addArena(String name) {
plugin.arenadata.getConfig().createSection(name);
plugin.arenadata.saveConfig();
}
public void addRedLocation(Location loc, String arena) {
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena);
int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
double pitch = loc.getPitch(), yaw = loc.getYaw();
String world = loc.getWorld().getName();
if (!section.contains("red")) {
section.set("red.1.x", x);
section.set("red.1.y", y);
section.set("red.1.z", z);
section.set("red.1.pitch", pitch);
section.set("red.1.yaw", yaw);
section.set("red.1.world", world);
plugin.arenadata.saveConfig();
} else {
ConfigurationSection amount = plugin.arenadata.getConfig()
.getConfigurationSection(arena + ".red");
List<String> list = new ArrayList<String>();
for (String str : amount.getKeys(false)) {
list.add(str);
}
int count = list.size() + 1;
section.set("red." + count + ".x", x);
section.set("red." + count + ".y", y);
section.set("red." + count + ".z", z);
section.set("red." + count + ".pitch", pitch);
section.set("red." + count + ".yaw", yaw);
section.set("red." + count + ".world", world);
plugin.arenadata.saveConfig();
}
}
public void addBlueLocation(Location loc, String arena) {
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena);
int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
double pitch = loc.getPitch(), yaw = loc.getYaw();
String world = loc.getWorld().getName();
if (!section.contains("blue")) {
section.set("blue.1.x", x);
section.set("blue.1.y", y);
section.set("blue.1.z", z);
section.set("blue.1.pitch", pitch);
section.set("blue.1.yaw", yaw);
section.set("blue.1.world", world);
plugin.arenadata.saveConfig();
} else {
ConfigurationSection amount = plugin.arenadata.getConfig()
.getConfigurationSection(arena + ".blue");
List<String> list = new ArrayList<String>();
for (String str : amount.getKeys(false)) {
list.add(str);
}
int count = list.size() + 1;
section.set("blue." + count + ".x", x);
section.set("blue." + count + ".y", y);
section.set("blue." + count + ".z", z);
section.set("blue." + count + ".pitch", pitch);
section.set("blue." + count + ".yaw", yaw);
section.set("blue." + count + ".world", world);
plugin.arenadata.saveConfig();
}
}
public void addRandomLocation(Location loc, String arena) {
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena);
int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
double pitch = loc.getPitch(), yaw = loc.getYaw();
String world = loc.getWorld().getName();
if (!section.contains("random")) {
section.set("random.1.x", x);
section.set("random.1.y", y);
section.set("random.1.z", z);
section.set("random.1.pitch", pitch);
section.set("random.1.yaw", yaw);
section.set("random.1.world", world);
plugin.arenadata.saveConfig();
} else {
ConfigurationSection amount = plugin.arenadata.getConfig()
.getConfigurationSection(arena + ".random");
List<String> list = new ArrayList<String>();
for (String str : amount.getKeys(false)) {
list.add(str);
}
int count = list.size() + 1;
section.set("random." + count + ".x", x);
section.set("random." + count + ".y", y);
section.set("random." + count + ".z", z);
section.set("random." + count + ".pitch", pitch);
section.set("random." + count + ".yaw", yaw);
section.set("random." + count + ".world", world);
plugin.arenadata.saveConfig();
}
}
public void setRespawnBox(Location loc, String arena){
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena);
int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
double pitch = loc.getPitch(), yaw = loc.getYaw();
String world = loc.getWorld().getName();
section.set("respawn.x", x);
section.set("respawn.y", y);
section.set("respawn.z", z);
section.set("respawn.pitch", pitch);
section.set("respawn.yaw", yaw);
section.set("respawn.world", world);
plugin.arenadata.saveConfig();
}
public void removeLocations(String type, String arena) {
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena);
if (!type.equalsIgnoreCase("red") || !type.equalsIgnoreCase("blue")
|| !type.equalsIgnoreCase("random")
)
return;
type = type.toLowerCase();
if (!section.contains(type))
return;
section.set(type, null);
plugin.arenadata.saveConfig();
}
public void removeArena(String arena) {
if (!plugin.arenadata.getConfig().contains(arena))
return;
plugin.arenadata.getConfig().set(arena, null);
plugin.arenadata.saveConfig();
}
public boolean exists(String arena) {
if (plugin.arenadata.getConfig().contains(arena))
return true;
else
return false;
}
public boolean hasRed(String arena) {
if (plugin.arenadata.getConfig().contains(arena + ".red"))
return true;
else
return false;
}
public boolean hasBlue(String arena) {
if (plugin.arenadata.getConfig().contains(arena + ".blue"))
return true;
else
return false;
}
public boolean hasRandom(String arena) {
if (plugin.arenadata.getConfig().contains(arena + ".random"))
return true;
else
return false;
}
public Location getRndRedLocation(String arena) {
List<Location> allRed = getAllRed(arena);
return allRed.get(rnd.nextInt(allRed.size()));
}
public Location getRndBlueLocation(String arena) {
List<Location> allBlue = getAllBlue(arena);
return allBlue.get(rnd.nextInt(allBlue.size()));
}
public Location getRndRandomLocation(String arena) {
List<Location> allRandom = getAllRandom(arena);
return allRandom.get(rnd.nextInt(allRandom.size()));
}
public Location getRespawnBox(String arena){
ConfigurationSection section = plugin.arenadata.getConfig()
.getConfigurationSection(arena + ".respawn");
int x = section.getInt("x"), y = section.getInt("y"),z = section.getInt("z");
float yaw = (float) section.getDouble("yaw"), pitch = (float) section.getDouble("pitch");
World world = Bukkit.getWorld(section.getString("world"));
return new Location(world,x,y,z,yaw,pitch);
}
public void sendToArena(Player p){
String arena = ArenaVoting.get().CurrentArena;
if(plugin.queued.containsKey(p.getUniqueId())){
Kits.get().giveKit(p, Kits.get().getKit(p));
if(GameStateUtil.get().getCurrentGame() == GameState.TDM || GameStateUtil.get().getCurrentGame() == GameState.FT500){
p.teleport(getRndRandomLocation(arena));
}else{
if(Teams.get().getTeam(p) == Team.RED){
p.teleport(getRndRedLocation(arena));
}else{
p.teleport(getRndBlueLocation(arena));
}
}
if(Teams.get().getTeam(p) == Team.RED){
plugin.amountOfRedPlayers++;
}else{
plugin.amountOfBluePlayers++;
}
plugin.addSpawnProtection(p);
}
}
public void setLobby(Location loc){
plugin.arenadata.getConfig().set("Lobby.x", loc.getBlockX());
plugin.arenadata.getConfig().set("Lobby.y", loc.getBlockY());
plugin.arenadata.getConfig().set("Lobby.z", loc.getBlockZ());
plugin.arenadata.getConfig().set("Lobby.yaw", loc.getYaw());
plugin.arenadata.getConfig().set("Lobby.pitch", loc.getPitch());
plugin.arenadata.getConfig().set("Lobby.world", loc.getWorld().toString());
plugin.arenadata.saveConfig();
}
public Location getLobby(){
int x = plugin.arenadata.getConfig().getInt("Lobby.x"), y = plugin.arenadata.getConfig().getInt("Lobby.y"), z = plugin.arenadata.getConfig().getInt("Lobby.z");
float yaw = (float) plugin.arenadata.getConfig().getDouble("Lobby.yaw"), pitch = (float) plugin.arenadata.getConfig().getDouble("Lobby.pitch");
World world = plugin.getServer().getWorld(plugin.arenadata.getConfig().getString("Lobby.world"));
return new Location(world,x,y,z,yaw,pitch);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.