Started On The Event Management System
This commit is contained in:
parent
36000a7eb8
commit
b804fa27d3
@ -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<Player, PlayerMenuUtil> 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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
*/
|
||||
}
|
@ -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<Team> teams;
|
||||
|
||||
private int amountOfTeams;
|
||||
private int amountPerTeam;
|
||||
|
||||
private List<CustomLocation> teamSpawnPoints;
|
||||
|
||||
private int duration;
|
||||
|
||||
private boolean scoreboardEnabled;
|
||||
private boolean timerEnabled;
|
||||
private boolean blockPlaceEventCancelled;
|
||||
private boolean blockBreakEventCancelled;
|
||||
}
|
@ -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<Team> teams = new ArrayList<Team>();
|
||||
List<CustomLocation> teamSpawnPoints = new ArrayList<CustomLocation>();
|
||||
|
||||
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<UUID> allPlayers = new ArrayList<UUID>();
|
||||
List<UUID> playingPlayers = new ArrayList<UUID>();
|
||||
|
||||
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<Team>(),
|
||||
2,
|
||||
10,
|
||||
new ArrayList<CustomLocation>(),
|
||||
600,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
List<String> teamSpawnPoints = new ArrayList<String>();
|
||||
|
||||
if (this.event.getTeams().size() == 0) {
|
||||
this.config.set("EVENT.TEAMS", null);
|
||||
} else {
|
||||
int index = 0;
|
||||
|
||||
for (Team team : this.event.getTeams()) {
|
||||
List<String> allPlayers = new ArrayList<String>();
|
||||
List<String> playingPlayers = new ArrayList<String>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -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<UUID> allPlayers;
|
||||
private List<UUID> playingPlayers = new ArrayList<>();
|
||||
private UUID leader;
|
||||
|
||||
public Team(UUID leader, List<UUID> allPlayers) {
|
||||
this.leader = leader;
|
||||
this.allPlayers = allPlayers;
|
||||
this.playingPlayers.addAll(allPlayers);
|
||||
}
|
||||
|
||||
public Team(UUID leader, List<UUID> allPlayers, List<UUID> playingPlayers) {
|
||||
this.leader = leader;
|
||||
this.allPlayers = allPlayers;
|
||||
this.playingPlayers = playingPlayers;
|
||||
}
|
||||
|
||||
public void killPlayer(UUID uuid) {
|
||||
this.playingPlayers.remove(uuid);
|
||||
}
|
||||
|
||||
public Stream<Player> allPlayers() {
|
||||
return this.allPlayers.stream().map(this.main.getServer() :: getPlayer).filter(Objects :: nonNull);
|
||||
}
|
||||
|
||||
public Stream<Player> playingPlayers() {
|
||||
return this.playingPlayers.stream().map(this.main.getServer() :: getPlayer).filter(Objects :: nonNull);
|
||||
}
|
||||
}
|
@ -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<String> getScoreboard(Player player, Board board, Set<BoardCooldown> 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<String> getSpawnScoreboard(Player player, PlayerData playerData) {
|
||||
List<String> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user