Alot of shit
This commit is contained in:
@ -1,55 +0,0 @@
|
||||
package rip.tilly.bedwars.managers;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
import rip.tilly.bedwars.game.arena.CopiedArena;
|
||||
import rip.tilly.bedwars.utils.config.file.Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArenaManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
private final Config config = this.plugin.getArenasConfig();
|
||||
|
||||
@Getter private final Map<String, Arena> arenas = new HashMap<>();
|
||||
@Getter private final Map<CopiedArena, UUID> arenaMatchUUIDs = new HashMap<>();
|
||||
|
||||
@Getter @Setter private int generatingArenaRunnable;
|
||||
|
||||
public ArenaManager() {
|
||||
|
||||
}
|
||||
|
||||
private void loadArenas() {
|
||||
FileConfiguration fileConfig = config.getConfig();
|
||||
ConfigurationSection section = fileConfig.getConfigurationSection("arenas");
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
section.getKeys(false).forEach(name -> {
|
||||
String icon = section.getString(name + ".icon") == null ? Material.PAPER.name() : section.getString(name + ".icon");
|
||||
int iconData = section.getInt(name + ".icon-data");
|
||||
|
||||
String a = section.getString(name + ".a");
|
||||
String b = section.getString(name + ".b");
|
||||
String min = section.getString(name + ".min");
|
||||
String max = section.getString(name + ".max");
|
||||
String teamAmin = section.getString(name + ".teamAmin");
|
||||
String teamAmax = section.getString(name + ".teamAmax");
|
||||
String teamBmin = section.getString(name + ".teamBmin");
|
||||
String teamBmax = section.getString(name + ".teamBmax");
|
||||
|
||||
int deadZone = section.getInt(name + ".deadZone");
|
||||
int buildMax = section.getInt(name + ".buildMax");
|
||||
});
|
||||
}
|
||||
}
|
96
src/main/java/rip/tilly/bedwars/managers/GameManager.java
Normal file
96
src/main/java/rip/tilly/bedwars/managers/GameManager.java
Normal file
@ -0,0 +1,96 @@
|
||||
package rip.tilly.bedwars.managers;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameRequest;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
import rip.tilly.bedwars.game.events.GameEndEvent;
|
||||
import rip.tilly.bedwars.game.events.GameStartEvent;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.utils.TtlHashMap;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class GameManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
private final Map<UUID, Set<GameRequest>> gameRequests = new TtlHashMap<>(TimeUnit.SECONDS, 30);
|
||||
@Getter private final Map<UUID, Game> games = new ConcurrentHashMap<>();
|
||||
|
||||
public Game getGame(PlayerData playerData) {
|
||||
return this.games.get(playerData.getCurrentGameId());
|
||||
}
|
||||
|
||||
public Game getGame(UUID uuid) {
|
||||
return this.getGame(this.plugin.getPlayerDataManager().getPlayerData(uuid));
|
||||
}
|
||||
|
||||
public Game getGameFromUUID(UUID uuid) {
|
||||
return this.games.get(uuid);
|
||||
}
|
||||
|
||||
public void createGameRequest(Player requester, Player requested, Arena arena, boolean party) {
|
||||
GameRequest request = new GameRequest(requester.getUniqueId(), requested.getUniqueId(), arena, party);
|
||||
this.gameRequests.computeIfAbsent(requested.getUniqueId(), k -> new HashSet<>()).add(request);
|
||||
}
|
||||
|
||||
public GameRequest getGameRequest(UUID requester, UUID requested) {
|
||||
Set<GameRequest> requests = this.gameRequests.get(requested);
|
||||
if (requests == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return requests.stream().filter(req -> req.getRequester().equals(requester)).findAny().orElse(null);
|
||||
}
|
||||
|
||||
public void removeGameRequests(UUID uuid) {
|
||||
this.gameRequests.remove(uuid);
|
||||
}
|
||||
|
||||
public void createGame(Game game) {
|
||||
this.games.put(game.getGameId(), game);
|
||||
this.plugin.getServer().getPluginManager().callEvent(new GameStartEvent(game));
|
||||
}
|
||||
|
||||
public void removeGame(Game game) {
|
||||
this.games.remove(game.getGameId());
|
||||
}
|
||||
|
||||
public void removePlayerFromGame(Player player, PlayerData playerData) {
|
||||
Game game = this.games.get(playerData.getCurrentGameId());
|
||||
Player killer = player.getKiller();
|
||||
|
||||
if (player.isOnline() && killer != null) {
|
||||
killer.hidePlayer(player);
|
||||
}
|
||||
|
||||
GameTeam losingTeam = game.getTeams().get(playerData.getTeamId());
|
||||
GameTeam winningTeam = game.getTeams().get(losingTeam.getId() == 0 ? 1 : 0);
|
||||
|
||||
if (killer != null) {
|
||||
game.broadcast(losingTeam.getPlayerTeam().getChatColor() + player.getName() + " &ehas been killed by " + winningTeam.getPlayerTeam().getChatColor() + killer.getName() + "&e! &b&lFINAL KILL!");
|
||||
} else {
|
||||
game.broadcast(losingTeam.getPlayerTeam().getChatColor() + player.getName() + " &ehas died! &b&lFINAL KILL!");
|
||||
}
|
||||
|
||||
losingTeam.killPlayer(player.getUniqueId());
|
||||
int remaining = losingTeam.getPlayingPlayers().size();
|
||||
|
||||
if (remaining == 0) {
|
||||
this.plugin.getServer().getPluginManager().callEvent(new GameEndEvent(game, winningTeam, losingTeam));
|
||||
}
|
||||
}
|
||||
}
|
110
src/main/java/rip/tilly/bedwars/managers/PlayerDataManager.java
Normal file
110
src/main/java/rip/tilly/bedwars/managers/PlayerDataManager.java
Normal file
@ -0,0 +1,110 @@
|
||||
package rip.tilly.bedwars.managers;
|
||||
|
||||
import com.mongodb.client.MongoCursor;
|
||||
import com.mongodb.client.model.Filters;
|
||||
import com.mongodb.client.model.UpdateOptions;
|
||||
import lombok.Getter;
|
||||
import org.bson.Document;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.player.PlayerState;
|
||||
import rip.tilly.bedwars.utils.PlayerUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class PlayerDataManager {
|
||||
|
||||
@Getter private final Map<UUID, PlayerData> players = new HashMap<>();
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
public PlayerData getOrCreate(UUID uniqueId) {
|
||||
return this.players.computeIfAbsent(uniqueId, PlayerData::new);
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(UUID uniqueId) {
|
||||
return this.players.getOrDefault(uniqueId, new PlayerData(uniqueId));
|
||||
}
|
||||
|
||||
public Collection<PlayerData> getAllPlayers() {
|
||||
return this.players.values();
|
||||
}
|
||||
|
||||
public void loadPlayerData(PlayerData playerData) {
|
||||
Document document = this.plugin.getMongoManager().getPlayers().find(Filters.eq("uniqueId", playerData.getUniqueId().toString())).first();
|
||||
|
||||
if (document != null) {
|
||||
playerData.setKills(document.getInteger("kills"));
|
||||
playerData.setDeaths(document.getInteger("deaths"));
|
||||
playerData.setXp(document.getDouble("xp"));
|
||||
playerData.setLevel(document.getInteger("level"));
|
||||
playerData.setWins(document.getInteger("wins"));
|
||||
playerData.setLosses(document.getInteger("losses"));
|
||||
playerData.setGamesPlayed(document.getInteger("gamesPlayed"));
|
||||
}
|
||||
|
||||
playerData.setLoaded(true);
|
||||
}
|
||||
|
||||
public void savePlayerData(PlayerData playerData) {
|
||||
Document document = new Document();
|
||||
|
||||
document.put("uniqueId", playerData.getUniqueId().toString());
|
||||
|
||||
document.put("kills", playerData.getKills());
|
||||
document.put("deaths", playerData.getDeaths());
|
||||
document.put("xp", playerData.getXp());
|
||||
document.put("level", playerData.getLevel());
|
||||
document.put("wins", playerData.getWins());
|
||||
document.put("losses", playerData.getLosses());
|
||||
document.put("gamesPlayed", playerData.getGamesPlayed());
|
||||
|
||||
this.plugin.getMongoManager().getPlayers().replaceOne(Filters.eq("uniqueId", playerData.getUniqueId().toString()), document, new UpdateOptions().upsert(true));
|
||||
}
|
||||
|
||||
public void deletePlayer(UUID uniqueId) {
|
||||
this.savePlayerData(getPlayerData(uniqueId));
|
||||
this.getPlayers().remove(uniqueId);
|
||||
}
|
||||
|
||||
public MongoCursor<Document> getPlayersSorted(String stat, int limit) {
|
||||
final Document document = new Document();
|
||||
document.put(stat, -1);
|
||||
|
||||
return this.plugin.getMongoManager().getPlayers().find().sort(document).limit(limit).iterator();
|
||||
}
|
||||
|
||||
public void resetPlayer(Player player, boolean toSpawn) {
|
||||
PlayerData playerData = this.getPlayerData(player.getUniqueId());
|
||||
playerData.setPlayerState(PlayerState.SPAWN);
|
||||
|
||||
PlayerUtil.clearPlayer(player);
|
||||
|
||||
this.giveSpawnItems(player);
|
||||
|
||||
if (toSpawn) {
|
||||
player.teleport(this.plugin.getSpawnManager().getSpawnLocation().toBukkitLocation());
|
||||
}
|
||||
}
|
||||
|
||||
public void giveSpawnItems(Player player) {
|
||||
boolean inParty = false; // check if the player is in a party
|
||||
|
||||
if (inParty) {
|
||||
this.plugin.getHotbarManager().getPartyItems().stream().filter(HotbarItem::isEnabled).forEach(item -> player.getInventory().setItem(item.getSlot(), item.getItemStack()));
|
||||
} else {
|
||||
this.plugin.getHotbarManager().getSpawnItems().stream().filter(HotbarItem::isEnabled).forEach(item -> player.getInventory().setItem(item.getSlot(), item.getItemStack()));
|
||||
}
|
||||
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package rip.tilly.bedwars.managers;
|
||||
|
||||
import assemble.AssembleAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScoreboardManager implements AssembleAdapter {
|
||||
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
@Override
|
||||
public String getTitle(Player player) {
|
||||
return CC.translate("&d&lBedWars");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLines(Player player) {
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
lines.add(CC.translate(CC.scoreboardBar));
|
||||
lines.add(CC.translate("&fOnline: &d" + this.main.getServer().getOnlinePlayers().size()));
|
||||
lines.add(CC.translate("&fPlaying: &d"));
|
||||
lines.add(CC.translate(""));
|
||||
|
||||
if (true) {
|
||||
lines.add(CC.translate("&fLevel: &d" + playerData.getLevel()));
|
||||
|
||||
String finishedProgress = "";
|
||||
|
||||
int notFinishedProgress = 10;
|
||||
|
||||
for (int i = 0; i < playerData.getXp() * 100; i++) {
|
||||
if (i % 10 == 0) {
|
||||
finishedProgress += "⬛";
|
||||
|
||||
notFinishedProgress--;
|
||||
}
|
||||
}
|
||||
|
||||
String leftOverProgress = "";
|
||||
|
||||
for (int i = 1; i <= notFinishedProgress; i++) {
|
||||
leftOverProgress += "⬛";
|
||||
}
|
||||
|
||||
lines.add(CC.translate("&8" + finishedProgress + "&7" + leftOverProgress + " &7(" + ((int) (playerData.getXp() * 100)) + "%&7)"));
|
||||
lines.add(CC.translate(""));
|
||||
}
|
||||
|
||||
lines.add(CC.translate("&dtilly.rip"));
|
||||
lines.add(CC.translate(CC.scoreboardBar));
|
||||
|
||||
return lines;
|
||||
}
|
||||
}
|
49
src/main/java/rip/tilly/bedwars/managers/SpawnManager.java
Normal file
49
src/main/java/rip/tilly/bedwars/managers/SpawnManager.java
Normal file
@ -0,0 +1,49 @@
|
||||
package rip.tilly.bedwars.managers;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.CustomLocation;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SpawnManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
private final FileConfiguration config = this.plugin.getMainConfig().getConfig();
|
||||
|
||||
private CustomLocation spawnLocation;
|
||||
private CustomLocation spawnMin;
|
||||
private CustomLocation spawnMax;
|
||||
|
||||
public SpawnManager() {
|
||||
this.loadConfig();
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
if (this.config.contains("SPAWN.LOCATION")) {
|
||||
try {
|
||||
this.spawnLocation = CustomLocation.stringToLocation(this.config.getString("SPAWN.LOCATION"));
|
||||
this.spawnMin = CustomLocation.stringToLocation(this.config.getString("SPAWN.MIN"));
|
||||
this.spawnMax = CustomLocation.stringToLocation(this.config.getString("SPAWN.MAX"));
|
||||
} catch (NullPointerException exception) {
|
||||
Bukkit.getConsoleSender().sendMessage(CC.translate("&cSpawn min & max locations not found!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
this.config.set("SPAWN.LOCATION", CustomLocation.locationToString(this.spawnLocation));
|
||||
this.config.set("SPAWN.MIN", CustomLocation.locationToString(this.spawnMin));
|
||||
this.config.set("SPAWN.MAX", CustomLocation.locationToString(this.spawnMax));
|
||||
|
||||
this.plugin.getMainConfig().save();
|
||||
}
|
||||
}
|
247
src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java
Normal file
247
src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java
Normal file
@ -0,0 +1,247 @@
|
||||
package rip.tilly.bedwars.managers.arena;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
import rip.tilly.bedwars.game.arena.CopiedArena;
|
||||
import rip.tilly.bedwars.utils.CustomLocation;
|
||||
import rip.tilly.bedwars.utils.config.file.Config;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class ArenaManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
private final Config config = this.plugin.getArenasConfig();
|
||||
|
||||
@Getter private final Map<String, Arena> arenas = new HashMap<>();
|
||||
@Getter private final Map<CopiedArena, UUID> arenaGameUUIDs = new HashMap<>();
|
||||
|
||||
@Getter @Setter private int generatingArenaRunnable;
|
||||
|
||||
public ArenaManager() {
|
||||
this.loadArenas();
|
||||
}
|
||||
|
||||
private void loadArenas() {
|
||||
FileConfiguration fileConfig = this.config.getConfig();
|
||||
ConfigurationSection section = fileConfig.getConfigurationSection("arenas");
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
section.getKeys(false).forEach(name -> {
|
||||
String icon = section.getString(name + ".icon") == null ? Material.PAPER.name() : section.getString(name + ".icon");
|
||||
int iconData = section.getInt(name + ".icon-data");
|
||||
|
||||
String a = section.getString(name + ".a");
|
||||
String b = section.getString(name + ".b");
|
||||
String min = section.getString(name + ".min");
|
||||
String max = section.getString(name + ".max");
|
||||
String teamAmin = section.getString(name + ".teamAmin");
|
||||
String teamAmax = section.getString(name + ".teamAmax");
|
||||
String teamBmin = section.getString(name + ".teamBmin");
|
||||
String teamBmax = section.getString(name + ".teamBmax");
|
||||
|
||||
int deadZone = section.getInt(name + ".deadZone");
|
||||
int buildMax = section.getInt(name + ".buildMax");
|
||||
|
||||
CustomLocation spawnA = CustomLocation.stringToLocation(a);
|
||||
CustomLocation spawnB = CustomLocation.stringToLocation(b);
|
||||
CustomLocation locMin = CustomLocation.stringToLocation(min);
|
||||
CustomLocation locMax = CustomLocation.stringToLocation(max);
|
||||
CustomLocation locTeamAmin = CustomLocation.stringToLocation(teamAmin);
|
||||
CustomLocation locTeamAmax = CustomLocation.stringToLocation(teamAmax);
|
||||
CustomLocation locTeamBmin = CustomLocation.stringToLocation(teamBmin);
|
||||
CustomLocation locTeamBmax = CustomLocation.stringToLocation(teamBmax);
|
||||
|
||||
List<CopiedArena> copiedArenas = new ArrayList<>();
|
||||
ConfigurationSection copiedSection = section.getConfigurationSection(name + ".copiedArenas");
|
||||
if (copiedSection != null) {
|
||||
copiedSection.getKeys(false).forEach(copy -> {
|
||||
String copyA = copiedSection.getString(copy + ".a");
|
||||
String copyB = copiedSection.getString(copy + ".b");
|
||||
String copyMin = copiedSection.getString(copy + ".min");
|
||||
String copyMax = copiedSection.getString(copy + ".max");
|
||||
String copyTeamAmin = copiedSection.getString(copy + ".teamAmin");
|
||||
String copyTeamAmax = copiedSection.getString(copy + ".teamAmax");
|
||||
String copyTeamBmin = copiedSection.getString(copy + ".teamBmin");
|
||||
String copyTeamBmax = copiedSection.getString(copy + ".teamBmax");
|
||||
|
||||
CustomLocation copySpawnA = CustomLocation.stringToLocation(copyA);
|
||||
CustomLocation copySpawnB = CustomLocation.stringToLocation(copyB);
|
||||
CustomLocation copyLocMin = CustomLocation.stringToLocation(copyMin);
|
||||
CustomLocation copyLocMax = CustomLocation.stringToLocation(copyMax);
|
||||
CustomLocation copyLocTeamAmin = CustomLocation.stringToLocation(copyTeamAmin);
|
||||
CustomLocation copyLocTeamAmax = CustomLocation.stringToLocation(copyTeamAmax);
|
||||
CustomLocation copyLocTeamBmin = CustomLocation.stringToLocation(copyTeamBmin);
|
||||
CustomLocation copyLocTeamBmax = CustomLocation.stringToLocation(copyTeamBmax);
|
||||
|
||||
CopiedArena copiedArena = new CopiedArena(
|
||||
copySpawnA,
|
||||
copySpawnB,
|
||||
copyLocMin,
|
||||
copyLocMax,
|
||||
copyLocTeamAmin,
|
||||
copyLocTeamAmax,
|
||||
copyLocTeamBmin,
|
||||
copyLocTeamBmax
|
||||
);
|
||||
|
||||
this.plugin.getChunkClearingManager().copyArena(copiedArena);
|
||||
|
||||
copiedArenas.add(copiedArena);
|
||||
});
|
||||
}
|
||||
|
||||
boolean enabled = section.getBoolean(name + ".enabled", false);
|
||||
|
||||
Arena arena = new Arena(
|
||||
name,
|
||||
copiedArenas,
|
||||
new ArrayList<>(copiedArenas),
|
||||
icon,
|
||||
iconData,
|
||||
spawnA,
|
||||
spawnB,
|
||||
locMin,
|
||||
locMax,
|
||||
locTeamAmin,
|
||||
locTeamAmax,
|
||||
locTeamBmin,
|
||||
locTeamBmax,
|
||||
deadZone,
|
||||
buildMax,
|
||||
enabled
|
||||
);
|
||||
|
||||
this.arenas.put(name, arena);
|
||||
});
|
||||
}
|
||||
|
||||
public void saveArenas() {
|
||||
FileConfiguration fileConfig = this.config.getConfig();
|
||||
fileConfig.set("arenas", null);
|
||||
arenas.forEach((name, arena) -> {
|
||||
String icon = arena.getIcon();
|
||||
int iconData = arena.getIconData();
|
||||
|
||||
String a = CustomLocation.locationToString(arena.getA());
|
||||
String b = CustomLocation.locationToString(arena.getB());
|
||||
String min = CustomLocation.locationToString(arena.getMin());
|
||||
String max = CustomLocation.locationToString(arena.getMax());
|
||||
String teamAmin = CustomLocation.locationToString(arena.getTeamAmin());
|
||||
String teamAmax = CustomLocation.locationToString(arena.getTeamAmax());
|
||||
String teamBmin = CustomLocation.locationToString(arena.getTeamBmin());
|
||||
String teamBmax = CustomLocation.locationToString(arena.getTeamBmax());
|
||||
|
||||
int deadZone = arena.getDeadZone();
|
||||
int buildMax = arena.getBuildMax();
|
||||
|
||||
String root = "arenas." + name;
|
||||
|
||||
fileConfig.set(root + ".icon", icon);
|
||||
fileConfig.set(root + ".icon-data", iconData);
|
||||
|
||||
fileConfig.set(root + ".a", a);
|
||||
fileConfig.set(root + ".b", b);
|
||||
fileConfig.set(root + ".min", min);
|
||||
fileConfig.set(root + ".max", max);
|
||||
fileConfig.set(root + ".teamAmin", teamAmin);
|
||||
fileConfig.set(root + ".teamAmax", teamAmax);
|
||||
fileConfig.set(root + ".teamBmin", teamBmin);
|
||||
fileConfig.set(root + ".teamBmax", teamBmax);
|
||||
|
||||
fileConfig.set(root + ".deadZone", deadZone);
|
||||
fileConfig.set(root + ".buildMax", buildMax);
|
||||
|
||||
fileConfig.set(root + ".enabled", arena.isEnabled());
|
||||
fileConfig.set(root + ".copiedArenas", null);
|
||||
|
||||
int i = 0;
|
||||
if (arena.getCopiedArenas() != null) {
|
||||
for (CopiedArena copiedArena : arena.getCopiedArenas()) {
|
||||
String copyA = CustomLocation.locationToString(copiedArena.getA());
|
||||
String copyB = CustomLocation.locationToString(copiedArena.getB());
|
||||
String copyMin = CustomLocation.locationToString(copiedArena.getMin());
|
||||
String copyMax = CustomLocation.locationToString(copiedArena.getMax());
|
||||
String copyTeamAmin = CustomLocation.locationToString(copiedArena.getTeamAmin());
|
||||
String copyTeamAmax = CustomLocation.locationToString(copiedArena.getTeamAmax());
|
||||
String copyTeamBmin = CustomLocation.locationToString(copiedArena.getTeamBmin());
|
||||
String copyTeamBmax = CustomLocation.locationToString(copiedArena.getTeamBmax());
|
||||
|
||||
String copyRoot = root + ".copiedArenas" + i;
|
||||
|
||||
fileConfig.set(copyRoot + ".a", copyA);
|
||||
fileConfig.set(copyRoot + ".b", copyB);
|
||||
fileConfig.set(copyRoot + ".min", copyMin);
|
||||
fileConfig.set(copyRoot + ".max", copyMax);
|
||||
fileConfig.set(copyRoot + ".teamAmin", copyTeamAmin);
|
||||
fileConfig.set(copyRoot + ".teamAmax", copyTeamAmax);
|
||||
fileConfig.set(copyRoot + ".teamBmin", copyTeamBmin);
|
||||
fileConfig.set(copyRoot + ".teamBmax", copyTeamBmax);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.config.save();
|
||||
}
|
||||
|
||||
public void reloadArenas() {
|
||||
this.saveArenas();
|
||||
this.arenas.clear();
|
||||
this.loadArenas();
|
||||
}
|
||||
|
||||
public void createArena(String name) {
|
||||
this.arenas.put(name, new Arena(name));
|
||||
}
|
||||
|
||||
public void deleteArena(String name) {
|
||||
this.arenas.remove(name);
|
||||
}
|
||||
|
||||
public Arena getArena(String name) {
|
||||
return this.arenas.get(name);
|
||||
}
|
||||
|
||||
public Arena getRandomArena() {
|
||||
List<Arena> enabledArenas = new ArrayList<>();
|
||||
|
||||
for (Arena arena : this.arenas.values()) {
|
||||
if (!arena.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
enabledArenas.add(arena);
|
||||
}
|
||||
|
||||
if (enabledArenas.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return enabledArenas.get(ThreadLocalRandom.current().nextInt(enabledArenas.size()));
|
||||
}
|
||||
|
||||
public void removeArenaGameUUID(CopiedArena copiedArena) {
|
||||
this.arenaGameUUIDs.remove(copiedArena);
|
||||
}
|
||||
|
||||
public UUID getArenaGameUUID(CopiedArena copiedArena) {
|
||||
return this.arenaGameUUIDs.get(copiedArena);
|
||||
}
|
||||
|
||||
public void setArenaGameUUIDs(CopiedArena copiedArena, UUID uuid) {
|
||||
this.arenaGameUUIDs.put(copiedArena, uuid);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package rip.tilly.bedwars.managers.arena.chunk;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.Chunk;
|
||||
import net.minecraft.server.v1_8_R3.ChunkSection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
|
||||
import rip.tilly.bedwars.game.arena.CopiedArena;
|
||||
import rip.tilly.bedwars.managers.arena.chunk.data.BedWarsChunk;
|
||||
import rip.tilly.bedwars.managers.arena.chunk.data.BedWarsChunkData;
|
||||
import rip.tilly.bedwars.managers.arena.chunk.data.BedWarsNMSUtil;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.cuboid.Cuboid;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* This code has been created by
|
||||
* gatogamer#6666 A.K.A. gatogamer.
|
||||
* If you want to use my code, please
|
||||
* don't remove this messages and
|
||||
* give me the credits. Arigato! n.n
|
||||
*/
|
||||
public class ChunkClearingManager {
|
||||
|
||||
public Map<CopiedArena, BedWarsChunkData> chunks = new ConcurrentHashMap<>();
|
||||
|
||||
public void copyArena(CopiedArena copiedArena) {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
Cuboid cuboid = new Cuboid(copiedArena.getMin().toBukkitLocation(), copiedArena.getMax().toBukkitLocation());
|
||||
BedWarsChunkData data = new BedWarsChunkData();
|
||||
|
||||
cuboid.getChunks().forEach(chunk -> {
|
||||
chunk.load();
|
||||
Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
|
||||
ChunkSection[] nmsSection = BedWarsNMSUtil.cloneSections(nmsChunk.getSections());
|
||||
data.chunks.put(new BedWarsChunk(chunk.getX(), chunk.getZ()), BedWarsNMSUtil.cloneSections(nmsSection));
|
||||
});
|
||||
|
||||
chunks.put(copiedArena, data);
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(CC.translate("&aArena copied! &a&l(" + (System.currentTimeMillis() - time) + "ms)"));
|
||||
}
|
||||
|
||||
public void resetArena(CopiedArena copiedArena) {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
Cuboid cuboid = new Cuboid(copiedArena.getMin().toBukkitLocation(), copiedArena.getMax().toBukkitLocation());
|
||||
cuboid.getChunks().forEach(chunk -> {
|
||||
try {
|
||||
chunk.load();
|
||||
BedWarsNMSUtil.setSections(((CraftChunk) chunk).getHandle(), BedWarsNMSUtil.cloneSections(chunks.get(copiedArena).getBedWarsChunk(chunk.getX(), chunk.getZ())));
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(CC.translate("&aArena reset! &a&l(" + (System.currentTimeMillis() - time) + "ms)"));
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package rip.tilly.bedwars.managers.arena.chunk;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
import rip.tilly.bedwars.game.arena.CopiedArena;
|
||||
import rip.tilly.bedwars.utils.CustomLocation;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class ChunkManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
public ChunkManager() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadChunks();
|
||||
}
|
||||
}.runTaskLater(this.plugin, 1);
|
||||
}
|
||||
|
||||
private void loadChunks() {
|
||||
CustomLocation spawnMin = this.plugin.getSpawnManager().getSpawnMin();
|
||||
CustomLocation spawnMax = this.plugin.getSpawnManager().getSpawnMax();
|
||||
if (spawnMin != null && spawnMax != null) {
|
||||
int spawnMinX = spawnMin.toBukkitLocation().getBlockX() >> 4;
|
||||
int spawnMinZ = spawnMin.toBukkitLocation().getBlockZ() >> 4;
|
||||
int spawnMaxX = spawnMax.toBukkitLocation().getBlockX() >> 4;
|
||||
int spawnMaxZ = spawnMax.toBukkitLocation().getBlockZ() >> 4;
|
||||
|
||||
if (spawnMinX > spawnMaxX) {
|
||||
int lastSpawnMinX = spawnMinX;
|
||||
spawnMinX = spawnMaxX;
|
||||
spawnMaxX = lastSpawnMinX;
|
||||
}
|
||||
|
||||
if (spawnMinZ > spawnMaxZ) {
|
||||
int lastSpawnMinZ = spawnMinZ;
|
||||
spawnMinZ = spawnMaxZ;
|
||||
spawnMaxZ = lastSpawnMinZ;
|
||||
}
|
||||
|
||||
for (int x = spawnMinX; x <= spawnMaxX; x++) {
|
||||
for (int z = spawnMinZ; z <= spawnMaxZ; z++) {
|
||||
Chunk chunk = spawnMin.toBukkitWorld().getChunkAt(x, z);
|
||||
if (!chunk.isLoaded()) {
|
||||
chunk.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Arena arena : this.plugin.getArenaManager().getArenas().values()) {
|
||||
if (!arena.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int arenaMinX = arena.getMin().toBukkitLocation().getBlockX() >> 4;
|
||||
int arenaMinZ = arena.getMin().toBukkitLocation().getBlockZ() >> 4;
|
||||
int arenaMaxX = arena.getMax().toBukkitLocation().getBlockX() >> 4;
|
||||
int arenaMaxZ = arena.getMax().toBukkitLocation().getBlockZ() >> 4;
|
||||
|
||||
if (arenaMinX > arenaMaxX) {
|
||||
int lastArenaMinX = arenaMinX;
|
||||
arenaMinX = arenaMaxX;
|
||||
arenaMaxX = lastArenaMinX;
|
||||
}
|
||||
|
||||
if (arenaMinZ > arenaMaxZ) {
|
||||
int lastArenaMinZ = arenaMinZ;
|
||||
arenaMinZ = arenaMaxZ;
|
||||
arenaMaxZ = lastArenaMinZ;
|
||||
}
|
||||
|
||||
for (int x = arenaMinX; x <= arenaMaxX; x++) {
|
||||
for (int z = arenaMinZ; z <= arenaMaxZ; z++) {
|
||||
Chunk chunk = arena.getMin().toBukkitWorld().getChunkAt(x, z);
|
||||
if (!chunk.isLoaded()) {
|
||||
chunk.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (CopiedArena copiedArena : arena.getCopiedArenas()) {
|
||||
arenaMinX = copiedArena.getMin().toBukkitLocation().getBlockX() >> 4;
|
||||
arenaMinZ = copiedArena.getMin().toBukkitLocation().getBlockZ() >> 4;
|
||||
arenaMaxX = copiedArena.getMax().toBukkitLocation().getBlockX() >> 4;
|
||||
arenaMaxZ = copiedArena.getMax().toBukkitLocation().getBlockZ() >> 4;
|
||||
|
||||
if (arenaMinX > arenaMaxX) {
|
||||
int lastArenaMinX = arenaMinX;
|
||||
arenaMinX = arenaMaxX;
|
||||
arenaMaxX = lastArenaMinX;
|
||||
}
|
||||
|
||||
if (arenaMinZ > arenaMaxZ) {
|
||||
int lastArenaMinZ = arenaMinZ;
|
||||
arenaMinZ = arenaMaxZ;
|
||||
arenaMaxZ = lastArenaMinZ;
|
||||
}
|
||||
|
||||
for (int x = arenaMinX; x <= arenaMaxX; x++) {
|
||||
for (int z = arenaMinZ; z <= arenaMaxZ; z++) {
|
||||
Chunk chunk = copiedArena.getMin().toBukkitWorld().getChunkAt(x, z);
|
||||
if (!chunk.isLoaded()) {
|
||||
chunk.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package rip.tilly.bedwars.managers.arena.chunk.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* This code has been created by
|
||||
* gatogamer#6666 A.K.A. gatogamer.
|
||||
* If you want to use my code, please
|
||||
* don't remove this messages and
|
||||
* give me the credits. Arigato! n.n
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class BedWarsChunk {
|
||||
private int x, z;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package rip.tilly.bedwars.managers.arena.chunk.data;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.server.v1_8_R3.ChunkSection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* This code has been created by
|
||||
* gatogamer#6666 A.K.A. gatogamer.
|
||||
* If you want to use my code, please
|
||||
* don't remove this messages and
|
||||
* give me the credits. Arigato! n.n
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class BedWarsChunkData {
|
||||
|
||||
public Map<BedWarsChunk, ChunkSection[]> chunks = new ConcurrentHashMap<>();
|
||||
|
||||
public ChunkSection[] getBedWarsChunk(int x, int z) {
|
||||
for (Map.Entry<BedWarsChunk, ChunkSection[]> chunksEntry : chunks.entrySet()) {
|
||||
if (chunksEntry.getKey().getX() == x && chunksEntry.getKey().getZ() == z) {
|
||||
return chunksEntry.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package rip.tilly.bedwars.managers.arena.chunk.data;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.server.v1_8_R3.Chunk;
|
||||
import net.minecraft.server.v1_8_R3.ChunkSection;
|
||||
import net.minecraft.server.v1_8_R3.NibbleArray;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* This code has been created by
|
||||
* gatogamer#6666 A.K.A. gatogamer.
|
||||
* If you want to use my code, please
|
||||
* don't remove this messages and
|
||||
* give me the credits. Arigato! n.n
|
||||
*/
|
||||
public class BedWarsNMSUtil {
|
||||
|
||||
@SneakyThrows
|
||||
public static void setField(String fieldName, Object clazz, Object value) {
|
||||
Field field = clazz.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.set(clazz, value);
|
||||
}
|
||||
|
||||
public static Object getFromField(String fieldName, Object clazz) throws IllegalAccessException, NoSuchFieldException {
|
||||
Field field = clazz.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
|
||||
return field.get(clazz);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static ChunkSection cloneSection(ChunkSection chunkSection) {
|
||||
ChunkSection section = new ChunkSection(chunkSection.getYPosition(), chunkSection.getSkyLightArray() != null);
|
||||
|
||||
setField("nonEmptyBlockCount", section, getFromField("nonEmptyBlockCount", chunkSection));
|
||||
setField("tickingBlockCount", section, getFromField("tickingBlockCount", chunkSection));
|
||||
setField("blockIds", section, chunkSection.getIdArray().clone());
|
||||
if (chunkSection.getEmittedLightArray() != null) {
|
||||
section.a(cloneNibbleArray(chunkSection.getEmittedLightArray()));
|
||||
}
|
||||
|
||||
if (chunkSection.getSkyLightArray() != null) {
|
||||
section.b(cloneNibbleArray(chunkSection.getSkyLightArray()));
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void setSections(Chunk nmsChunk, ChunkSection[] sections) {
|
||||
setField("sections", nmsChunk, sections);
|
||||
|
||||
nmsChunk.getWorld().getWorld().refreshChunk(nmsChunk.locX, nmsChunk.locZ);
|
||||
}
|
||||
|
||||
public static ChunkSection[] cloneSections(ChunkSection[] sections) {
|
||||
ChunkSection[] newSections = new ChunkSection[sections.length];
|
||||
|
||||
for (int i = 0; i < sections.length; ++i) {
|
||||
if (sections[i] != null) {
|
||||
newSections[i] = cloneSection(sections[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return newSections;
|
||||
}
|
||||
|
||||
public static NibbleArray cloneNibbleArray(NibbleArray nibbleArray) {
|
||||
return new NibbleArray(nibbleArray.a().clone());
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package rip.tilly.bedwars.managers.hotbar;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.ItemUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
public class HotbarManager {
|
||||
|
||||
private final List<HotbarItem> spawnItems = new ArrayList<>();
|
||||
private final List<HotbarItem> queueItems = new ArrayList<>();
|
||||
private final List<HotbarItem> partyItems = new ArrayList<>();
|
||||
private final List<HotbarItem> spectatorItems = new ArrayList<>();
|
||||
|
||||
public HotbarManager() {
|
||||
this.loadSpawnItems();
|
||||
this.loadQueueItems();
|
||||
this.loadPartyItems();
|
||||
this.loadSpectatorItems();
|
||||
}
|
||||
|
||||
private void loadSpawnItems() {
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.IRON_SWORD, CC.translate("&e&l» &dPlay A Game &e&l«"), 1, (short) 0
|
||||
), 0, true, "QUEUE_MENU")
|
||||
);
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.NAME_TAG, CC.translate("&e&l» &dCreate Party &e&l«"), 1, (short) 0
|
||||
), 1, true, "CREATE_PARTY")
|
||||
);
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.EMERALD, CC.translate("&e&l» &dCosmetics &e&l«"), 1, (short) 0
|
||||
), 4, true, "COSMETICS_MENU")
|
||||
);
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.BOOK, CC.translate("&e&l» &dHotbar Preference &e&l«"), 1, (short) 0
|
||||
), 7, true, "PREFERENCES_MENU")
|
||||
);
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.WATCH, CC.translate("&e&l» &dSettings &e&l«"), 1, (short) 0
|
||||
), 8, true, "SETTINGS_MENU")
|
||||
);
|
||||
}
|
||||
|
||||
private void loadQueueItems() {
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.INK_SACK, CC.translate("&e&l» &cLeave Queue &e&l«"), 1, (short) 1
|
||||
), 8, true, "LEAVE_QUEUE")
|
||||
);
|
||||
}
|
||||
|
||||
private void loadPartyItems() {
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.GOLD_SWORD, CC.translate("&e&l» &dParty Games &e&l«"), 1, (short) 0
|
||||
), 0, true, "PARTY_GAMES")
|
||||
);
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.NETHER_STAR, CC.translate("&e&l» &dParty Info &e&l«"), 1, (short) 0
|
||||
), 4, true, "PARTY_INFO")
|
||||
);
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.INK_SACK, CC.translate("&e&l» &cLeave Party &e&l«"), 1, (short) 1
|
||||
), 8, true, "PARTY_LEAVE")
|
||||
);
|
||||
}
|
||||
|
||||
private void loadSpectatorItems() {
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.COMPASS, CC.translate("&e&l» &dPlayer Tracker &e&l«"), 1, (short) 0
|
||||
), 0, true, "SPECTATOR_MENU")
|
||||
);
|
||||
spawnItems.add(new HotbarItem(
|
||||
ItemUtil.createUnbreakableItem(
|
||||
Material.INK_SACK, CC.translate("&e&l» &cLeave Spectator Mode &e&l«"), 1, (short) 1
|
||||
), 8, true, "SPECTATOR_LEAVE")
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package rip.tilly.bedwars.managers.hotbar.impl;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public enum ActionType {
|
||||
|
||||
QUEUE_MENU,
|
||||
SETTINGS_MENU,
|
||||
CREATE_PARTY,
|
||||
COSMETICS_MENU,
|
||||
PREFERENCES_MENU,
|
||||
|
||||
LEAVE_QUEUE,
|
||||
|
||||
PARTY_GAMES,
|
||||
PARTY_INFO,
|
||||
PARTY_LEAVE,
|
||||
|
||||
SPECTATOR_MENU,
|
||||
SPECTATOR_LEAVE
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package rip.tilly.bedwars.managers.hotbar.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class HotbarItem {
|
||||
|
||||
private static List<HotbarItem> items = Lists.newArrayList();
|
||||
private ItemStack itemStack;
|
||||
private int slot;
|
||||
private boolean enabled;
|
||||
private ActionType actionType;
|
||||
|
||||
public HotbarItem(ItemStack itemStack, int slot, boolean enabled, String action) {
|
||||
this.itemStack = itemStack;
|
||||
this.slot = slot;
|
||||
this.enabled = enabled;
|
||||
this.actionType = ActionType.valueOf(action);
|
||||
|
||||
items.add(this);
|
||||
}
|
||||
|
||||
public static HotbarItem getItemByItemStack(ItemStack itemStack) {
|
||||
return items.stream().filter(item -> item.getItemStack().isSimilar(itemStack)).findFirst().orElse(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package rip.tilly.bedwars.managers.mongo;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoCredential;
|
||||
import com.mongodb.ServerAddress;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import lombok.Getter;
|
||||
import org.bson.Document;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.config.file.Config;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
public class MongoManager {
|
||||
|
||||
private final MongoManager instance;
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
private final Config configFile = this.plugin.getMainConfig();
|
||||
private final FileConfiguration fileConfig = configFile.getConfig();
|
||||
private final ConfigurationSection config = fileConfig.getConfigurationSection("MONGO");
|
||||
|
||||
private MongoClient mongoClient;
|
||||
private MongoDatabase mongoDatabase;
|
||||
|
||||
private final String host = config.getString("HOST");
|
||||
private final int port = config.getInt("PORT");
|
||||
private final String database = config.getString("DATABASE");
|
||||
private final boolean auth = config.getBoolean("AUTH.ENABLED");
|
||||
private final String user = config.getString("AUTH.USERNAME");
|
||||
private final String password = config.getString("AUTH.PASSWORD");
|
||||
private final String authDatabase = config.getString("AUTH.AUTH-DATABASE");
|
||||
|
||||
private boolean connected;
|
||||
|
||||
private MongoCollection<Document> players;
|
||||
|
||||
public MongoManager() {
|
||||
instance = this;
|
||||
try {
|
||||
if (auth) {
|
||||
final MongoCredential credential = MongoCredential.createCredential(user, authDatabase, password.toCharArray());
|
||||
mongoClient = new MongoClient(new ServerAddress(host, port), Collections.singletonList(credential));
|
||||
} else {
|
||||
mongoClient = new MongoClient(host, port);
|
||||
}
|
||||
connected = true;
|
||||
mongoDatabase = mongoClient.getDatabase(database);
|
||||
Bukkit.getConsoleSender().sendMessage(CC.translate("&d[BedWars] &aSuccessfully connected to the database!"));
|
||||
this.players = this.mongoDatabase.getCollection("players");
|
||||
} catch (Exception exception) {
|
||||
connected = false;
|
||||
Bukkit.getConsoleSender().sendMessage(CC.translate("&d[BedWars] &cFailed to connect to the database!"));
|
||||
exception.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(this.plugin);
|
||||
Bukkit.getConsoleSender().sendMessage(CC.translate("&b[BedWars] &cDisabling BedWars..."));
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (this.mongoClient != null) {
|
||||
this.mongoClient.close();
|
||||
this.connected = false;
|
||||
Bukkit.getConsoleSender().sendMessage(CC.translate("&d[BedWars] &aSuccessfully disconnected from the database!"));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user