Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.pvpmadness.pvpmadness.minigames.minigameutils;
- import com.pvpmadness.pvpmadness.PvPMadness;
- import com.pvpmadness.pvpmadness.minigames.Arena;
- import com.pvpmadness.pvpmadness.minigames.Minigame;
- import com.pvpmadness.pvpmadness.minigames.ffa.FFA;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.configuration.file.FileConfiguration;
- import java.util.ArrayList;
- /**
- * Copyright (c) NullChips 2017. All rights reserved.
- * All code contained within this document is the
- * sole property of NullChips. Distribution, reproduction,
- * taking snippets or claiming any contents as your own will
- * break the terms of the license, and void any agreements with
- * you, the third party.
- * Thanks.
- */
- public class MinigameManager {
- private MinigameManager() {
- }
- private static MinigameManager instance = new MinigameManager();
- public static MinigameManager getInstance() {
- return instance;
- }
- FileConfiguration amf = PvPMadness.getArenaManagementFile().getFile();
- private ArrayList<Minigame> minigames = new ArrayList<Minigame>();
- private int maxSpawnpointTries;
- public ArrayList<Minigame> getMinigames() {
- return minigames;
- }
- private ArrayList<String> minigameTypes;
- public void addMinigame(Minigame m) {
- this.minigames.add(m);
- }
- public void clearMinigames() {
- this.minigames.clear();
- }
- public void registerMinigames() {
- registerTypes();
- int index = 1;
- for(index = 1; index < maxSpawnpointTries; index ++) {
- if(isMinigameInConfig(String.valueOf(index))) {
- //REGISTER FFA GAMES.
- if(amf.get(index + ".minigame-type") == "ffa" ) {
- boolean playable = getBooleanFromArenaFile(index + ".playable");
- int minPlayers = amf.getInt(index + ".min-players");
- String displayName = amf.getString(index + ".display-name");
- ArrayList<Location> locations = getLocations(String.valueOf(index), maxSpawnpointTries);
- Arena arena = new Arena(String.valueOf(index), locations);
- FFA ffa = new FFA(arena, minPlayers, playable, index);
- }
- }
- }
- }
- private boolean getBooleanFromArenaFile(String s) {
- if(amf.getString(s).equalsIgnoreCase("true")) {
- return true;
- } else {
- return false;
- }
- }
- private void registerTypes() {
- minigameTypes.clear();
- FFA ffa = new FFA(null, 0, false, 0);
- minigameTypes.add(ffa.getMinigameType());
- ffa = null;
- }
- public ArrayList<Location> getLocations(String arenaId, int maxSpawnpointTries) {
- int spawnpointIndex = 1;
- ArrayList<Location> locations = new ArrayList<Location>();
- for(spawnpointIndex = 1; spawnpointIndex < maxSpawnpointTries; spawnpointIndex++) {
- if (isSpawnpointInConfig(arenaId, spawnpointIndex)) {
- double x, y, z;
- World w;
- x = amf.getDouble(arenaId + ".spawnpoint" + spawnpointIndex + ".x");
- y = amf.getDouble(arenaId + ".spawnpoint" + spawnpointIndex + ".y");
- z = amf.getDouble(arenaId + ".spawnpoint" + spawnpointIndex + ".z");
- w = Bukkit.getServer().getWorld(amf.getString(arenaId + ".spawnpoint" + spawnpointIndex + "world"));
- Location l = new Location(w, x, y, z);
- locations.add(l);
- }
- }
- if(locations.size() != 0) {
- return locations;
- } else {
- return null;
- }
- }
- public boolean isWorld(String worldName) {
- return Bukkit.getServer().getWorld(worldName) != null;
- }
- public boolean isSpawnpointInConfig(String minigameId, int index) {
- if(amf.contains(minigameId + ".spawnpoint" + index + ".x") && amf.contains(minigameId + ".spawnpoint" + index + ".y")
- && amf.contains(minigameId + ".spawnpoint" + index + ".z") && amf.contains(minigameId + ".spawnpoint" + index + ".world") &&
- amf.get(minigameId + ".spawnpoint" + index + ".x") instanceof Double && amf.get(minigameId + ".spawnpoint" + index + ".y") instanceof Double &&
- amf.get(minigameId + ".spawnpoint" + index + ".z") instanceof Double && isWorld(amf.getString(minigameId + ".spawnpoint" + index + "world"))) {
- return true;
- } else {
- return false;
- }
- }
- public boolean isMinigameInConfig(String minigameId) {
- if (amf.contains(minigameId + ".min-players") && amf.get(minigameId + ".min-players") instanceof Integer &&
- amf.contains(minigameId + ".playable") && amf.get(minigameId + ".playable") instanceof String &&
- amf.contains(minigameId + ".minigame-type") && amf.get(minigameId + ".minigame-type") instanceof String &&
- amf.contains(minigameId + ".display-name") && amf.get(minigameId + ".display-name") instanceof String) {
- if (minigameTypes.contains(amf.getString(minigameId + ".minigame-type"))) {
- return true;
- }
- }
- return false;
- }
- public void setMaxSpawnpointTries(int maxSpawnpointTries) {
- this.maxSpawnpointTries = maxSpawnpointTries;
- }
- public int getMaxSpawnpointTries() {
- return maxSpawnpointTries;
- }
- public String getNewMinigameId() {
- int i;
- for(i = 1; i < maxSpawnpointTries; i++) {
- if(!amf.contains((i + ".playable"))) {
- break;
- }
- }
- if(i == maxSpawnpointTries - 1) {
- return null;
- }
- return String.valueOf(i);
- }
- public Minigame getMinigameFromId(String id) {
- int i = Integer.parseInt(id);
- for(Minigame m : this.minigames) {
- if (m.getId() == i) {
- return m;
- }
- }
- return null;
- }
- public int getNewSpawnId(String minigameId) {
- int newSpawnId;
- for(newSpawnId = 1; newSpawnId < maxSpawnpointTries; newSpawnId++) {
- if (!isSpawnpointInConfig(minigameId, newSpawnId)) {
- return newSpawnId;
- }
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement