diff --git a/src/main/java/com/loganmagnan/eventcore/EventCore.java b/src/main/java/com/loganmagnan/eventcore/EventCore.java index e2c7448..be4977e 100644 --- a/src/main/java/com/loganmagnan/eventcore/EventCore.java +++ b/src/main/java/com/loganmagnan/eventcore/EventCore.java @@ -1,11 +1,14 @@ package com.loganmagnan.eventcore; +import aether.Aether; import com.loganmagnan.eventcore.managers.*; +import com.loganmagnan.eventcore.managers.event.EventManager; import com.loganmagnan.eventcore.managers.hotbar.HotBarManager; import com.loganmagnan.eventcore.managers.mongo.MongoManager; import com.loganmagnan.eventcore.menusystem.PlayerMenuUtil; import com.loganmagnan.eventcore.playerdata.PlayerData; import com.loganmagnan.eventcore.runnables.CooldownRunnable; +import com.loganmagnan.eventcore.scoreboard.ScoreboardProvider; import com.loganmagnan.eventcore.utils.ClassRegistrationUtils; import com.loganmagnan.eventcore.utils.ColorUtils; import com.loganmagnan.eventcore.utils.Constants; @@ -39,6 +42,7 @@ public class EventCore extends JavaPlugin { private CooldownManager cooldownManager; private HotBarManager hotBarManager; private StaffManager staffManager; + private EventManager eventManager; // Menu System private HashMap playerMenuUtilMap = new HashMap<>(); @@ -84,6 +88,7 @@ public class EventCore extends JavaPlugin { this.staffManager.setStaffMode(playerInStaffMode, false); } + this.eventManager.saveConfig(); this.mongoManager.disconnect(); instance = null; @@ -101,6 +106,7 @@ public class EventCore extends JavaPlugin { this.cooldownManager = new CooldownManager(); this.hotBarManager = new HotBarManager(); this.staffManager = new StaffManager(); + this.eventManager = new EventManager(); } private void loadListeners() { @@ -108,6 +114,8 @@ public class EventCore extends JavaPlugin { } private void loadRunnables() { + new Aether(this, new ScoreboardProvider()); + this.getServer().getScheduler().runTaskTimerAsynchronously(this, new CooldownRunnable(), 0, 20); } diff --git a/src/main/java/com/loganmagnan/eventcore/managers/EventManager.java b/src/main/java/com/loganmagnan/eventcore/managers/EventManager.java deleted file mode 100644 index 8b17b79..0000000 --- a/src/main/java/com/loganmagnan/eventcore/managers/EventManager.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.loganmagnan.eventcore.managers; - -import com.loganmagnan.eventcore.EventCore; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class EventManager { - - private EventCore main = EventCore.getInstance(); - - // To Do: Event Management System - - /* - * Ability to make an Event for any situation. - * Ability to customize: - - Event Name - - Event Teams - - Event Amount of Teams - - Event Spawn Point - - Event Team Spawn Points - - Toggleable Scoreboard System - - Toggleable Event Timer - - Toggleable Events (BlockPlaceEvent, BlockBreakEvent, etc) - */ -} diff --git a/src/main/java/com/loganmagnan/eventcore/managers/event/Event.java b/src/main/java/com/loganmagnan/eventcore/managers/event/Event.java new file mode 100644 index 0000000..746ce24 --- /dev/null +++ b/src/main/java/com/loganmagnan/eventcore/managers/event/Event.java @@ -0,0 +1,35 @@ +package com.loganmagnan.eventcore.managers.event; + +import com.loganmagnan.eventcore.managers.event.teams.Team; +import com.loganmagnan.eventcore.utils.CustomLocation; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class Event { + + private String name; + + private CustomLocation spawnPoint; + + private List teams; + + private int amountOfTeams; + private int amountPerTeam; + + private List teamSpawnPoints; + + private int duration; + + private boolean scoreboardEnabled; + private boolean timerEnabled; + private boolean blockPlaceEventCancelled; + private boolean blockBreakEventCancelled; +} diff --git a/src/main/java/com/loganmagnan/eventcore/managers/event/EventManager.java b/src/main/java/com/loganmagnan/eventcore/managers/event/EventManager.java new file mode 100644 index 0000000..b6bd146 --- /dev/null +++ b/src/main/java/com/loganmagnan/eventcore/managers/event/EventManager.java @@ -0,0 +1,146 @@ +package com.loganmagnan.eventcore.managers.event; + +import com.loganmagnan.eventcore.EventCore; +import com.loganmagnan.eventcore.managers.event.teams.Team; +import com.loganmagnan.eventcore.utils.ColorUtils; +import com.loganmagnan.eventcore.utils.CustomLocation; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +@Getter +@Setter +public class EventManager { + + private EventCore main = EventCore.getInstance(); + + private FileConfiguration config = this.main.getMainConfig().getConfig(); + + private Event event; + + public EventManager() { + this.loadConfig(); + } + + private void loadConfig() { + if (this.config.contains("EVENT.NAME")) { + try { + List teams = new ArrayList(); + List teamSpawnPoints = new ArrayList(); + + if (this.config.get("EVENT.TEAMS") != null) { + if (this.config.getConfigurationSection("EVENT.TEAMS") != null) { + ConfigurationSection configurationSection = this.config.getConfigurationSection("EVENT.TEAMS"); + + if (configurationSection != null) { + configurationSection.getKeys(false).forEach((name) -> { + UUID leader = null; + + List allPlayers = new ArrayList(); + List playingPlayers = new ArrayList(); + + if (configurationSection.getString(name + ".LEADER") != null) { + leader = UUID.fromString(configurationSection.getString(name + ".LEADER")); + } + + for (String allPlayerUUID : configurationSection.getStringList(name + ".ALL-PLAYERS")) { + allPlayers.add(UUID.fromString(allPlayerUUID)); + } + + for (String playingPlayerUUID : configurationSection.getStringList(name + ".PLAYING-PLAYERS")) { + playingPlayers.add(UUID.fromString(playingPlayerUUID)); + } + + teams.add(new Team(leader, allPlayers, playingPlayers)); + }); + } + } + } + + for (String teamSpawnPoint : this.config.getStringList("EVENT.TEAM-SPAWN-POINTS")) { + teamSpawnPoints.add(CustomLocation.stringToLocation(teamSpawnPoint)); + } + + this.event = new Event( + this.config.getString("EVENT.NAME"), + CustomLocation.stringToLocation(this.config.getString("EVENT.SPAWN-POINT")), + teams, + this.config.getInt("EVENT.AMOUNT-OF-TEAMS"), + this.config.getInt("EVENT.AMOUNT-PER-TEAM"), + teamSpawnPoints, + this.config.getInt("EVENT.DURATION"), + this.config.getBoolean("EVENT.TOGGLEABLE-OPTIONS.SCOREBOARD-ENABLED"), + this.config.getBoolean("EVENT.TOGGLEABLE-OPTIONS.TIMER-ENABLED"), + this.config.getBoolean("EVENT.TOGGLEABLE-OPTIONS.EVENTS.BLOCK-PLACE.CANCELLED"), + this.config.getBoolean("EVENT.TOGGLEABLE-OPTIONS.EVENTS.BLOCK-BREAK.CANCELLED") + ); + } catch (NullPointerException exception) { + this.main.getServer().getConsoleSender().sendMessage(ColorUtils.getMessageType("&cEvent information not found")); + } + } else { + this.event = new Event( + "Event", + this.main.getSpawnManager().getSpawnLocation(), + new ArrayList(), + 2, + 10, + new ArrayList(), + 600, + true, + true, + false, + false + ); + } + } + + public void saveConfig() { + List teamSpawnPoints = new ArrayList(); + + if (this.event.getTeams().size() == 0) { + this.config.set("EVENT.TEAMS", null); + } else { + int index = 0; + + for (Team team : this.event.getTeams()) { + List allPlayers = new ArrayList(); + List playingPlayers = new ArrayList(); + + for (UUID allPlayerUUID : team.getAllPlayers()) { + allPlayers.add(allPlayerUUID.toString()); + } + + for (UUID playingPlayerUUID : team.getPlayingPlayers()) { + playingPlayers.add(playingPlayerUUID.toString()); + } + + this.config.set("EVENT.TEAMS." + index + ".LEADER", team.getLeader().toString()); + this.config.set("EVENT.TEAMS." + index + ".ALL-PLAYERS", allPlayers); + this.config.set("EVENT.TEAMS." + index + ".PLAYING-PLAYERS", playingPlayers); + + index++; + } + } + + for (CustomLocation teamSpawnPoint : this.event.getTeamSpawnPoints()) { + teamSpawnPoints.add(CustomLocation.locationToString(teamSpawnPoint)); + } + + this.config.set("EVENT.NAME", this.event.getName()); + this.config.set("EVENT.SPAWN-POINT", CustomLocation.locationToString(this.event.getSpawnPoint())); + this.config.set("EVENT.AMOUNT-OF-TEAMS", this.event.getAmountOfTeams()); + this.config.set("EVENT.AMOUNT-PER-TEAM", this.event.getAmountPerTeam()); + this.config.set("EVENT.TEAM-SPAWN-POINTS", teamSpawnPoints); + this.config.set("EVENT.DURATION", this.event.getDuration()); + this.config.set("EVENT.TOGGLEABLE-OPTIONS.SCOREBOARD-ENABLED", this.event.isScoreboardEnabled()); + this.config.set("EVENT.TOGGLEABLE-OPTIONS.TIMER-ENABLED", this.event.isTimerEnabled()); + this.config.set("EVENT.TOGGLEABLE-OPTIONS.EVENTS.BLOCK-PLACE.CANCELLED", this.event.isBlockPlaceEventCancelled()); + this.config.set("EVENT.TOGGLEABLE-OPTIONS.EVENTS.BLOCK-BREAK.CANCELLED", this.event.isBlockBreakEventCancelled()); + this.main.getMainConfig().save(); + } +} diff --git a/src/main/java/com/loganmagnan/eventcore/managers/event/teams/Team.java b/src/main/java/com/loganmagnan/eventcore/managers/event/teams/Team.java new file mode 100644 index 0000000..edd2f78 --- /dev/null +++ b/src/main/java/com/loganmagnan/eventcore/managers/event/teams/Team.java @@ -0,0 +1,46 @@ +package com.loganmagnan.eventcore.managers.event.teams; + +import com.loganmagnan.eventcore.EventCore; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import java.util.stream.Stream; + +@Getter +@Setter +public class Team { + + private EventCore main = EventCore.getInstance(); + + private List allPlayers; + private List playingPlayers = new ArrayList<>(); + private UUID leader; + + public Team(UUID leader, List allPlayers) { + this.leader = leader; + this.allPlayers = allPlayers; + this.playingPlayers.addAll(allPlayers); + } + + public Team(UUID leader, List allPlayers, List playingPlayers) { + this.leader = leader; + this.allPlayers = allPlayers; + this.playingPlayers = playingPlayers; + } + + public void killPlayer(UUID uuid) { + this.playingPlayers.remove(uuid); + } + + public Stream allPlayers() { + return this.allPlayers.stream().map(this.main.getServer() :: getPlayer).filter(Objects :: nonNull); + } + + public Stream playingPlayers() { + return this.playingPlayers.stream().map(this.main.getServer() :: getPlayer).filter(Objects :: nonNull); + } +} diff --git a/src/main/java/com/loganmagnan/eventcore/scoreboard/ScoreboardProvider.java b/src/main/java/com/loganmagnan/eventcore/scoreboard/ScoreboardProvider.java new file mode 100644 index 0000000..08ff23f --- /dev/null +++ b/src/main/java/com/loganmagnan/eventcore/scoreboard/ScoreboardProvider.java @@ -0,0 +1,61 @@ +package com.loganmagnan.eventcore.scoreboard; + +import aether.scoreboard.Board; +import aether.scoreboard.BoardAdapter; +import aether.scoreboard.cooldown.BoardCooldown; +import com.loganmagnan.eventcore.EventCore; +import com.loganmagnan.eventcore.playerdata.PlayerData; +import com.loganmagnan.eventcore.playerdata.PlayerSettings; +import com.loganmagnan.eventcore.utils.ColorUtils; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Scoreboard; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class ScoreboardProvider implements BoardAdapter { + + private EventCore main = EventCore.getInstance(); + + @Override + public String getTitle(Player player) { + return ColorUtils.getMessageType("&b&lEvent Core"); + } + + @Override + public List getScoreboard(Player player, Board board, Set cooldowns) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData == null) { + return null; + } + + PlayerSettings playerSettings = playerData.getPlayerSettings(); + + if (!playerSettings.isScoreboardEnabled()) { + return null; + } + + switch (playerData.getPlayerState()) { + case SPAWN: + return this.getSpawnScoreboard(player, playerData); + } + + return null; + } + + @Override + public void onScoreboardCreate(Player player, Scoreboard scoreboard) { + + } + + private List getSpawnScoreboard(Player player, PlayerData playerData) { + List lines = new ArrayList<>(); + + lines.add(ColorUtils.getMessageType("")); + lines.add(ColorUtils.getMessageType("&b&l" + player.getName())); + lines.add(ColorUtils.getMessageType("&7┃ &fOnline: &b" + this.main.getServer().getOnlinePlayers())); + + return lines; + } +}