Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/main/java/wueffi/MiniGameCore/MiniGameCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import java.util.UUID;

public class MiniGameCore extends JavaPlugin {
private final MiniGameCore plugin = this;
private static MiniGameCore plugin;
private List<String> availableGames;
private List<UUID> bannedPlayers;

@Override
public void onEnable() {
getLogger().info("MinigameCore enabled!");
plugin.getLogger().info("MinigameCore enabled!");
saveDefaultConfig();

List<String> availableGames = getConfig().getStringList("available-games");
Expand All @@ -35,14 +35,14 @@ public void onEnable() {
}
this.availableGames = availableGames;
this.bannedPlayers = bannedPlayers;
getLogger().info("Config loaded!");
plugin.getLogger().info("Config loaded!");

Stats.setup();
getLogger().info("Stats loaded!");
plugin.getLogger().info("Stats loaded!");

getCommand("mg").setExecutor(new MiniGameCommand(this));
getCommand("mg").setTabCompleter(new MiniGameTabCompleter(this));
getLogger().info("Commands registered!");
plugin.getLogger().info("Commands registered!");

ScoreBoardManager.startAnimationLoop();

Expand All @@ -54,17 +54,17 @@ public void onEnable() {
public void onDisable() {
for (Lobby lobby : LobbyManager.getInstance().getOpenLobbies()) {
String lobbyid = lobby.getLobbyId();
getLogger().info("Lobby: " + lobbyid);
plugin.getLogger().info("Lobby: " + lobbyid);
for (Player player : LobbyManager.getInstance().getLobby(lobbyid).getPlayers()) {
getLogger().info("Player: " + lobbyid);
plugin.getLogger().info("Player: " + lobbyid);
PlayerHandler.PlayerReset(player);
}
getLogger().info("Lobby disabling: " + lobbyid);
plugin.getLogger().info("Lobby disabling: " + lobbyid);
LobbyHandler.LobbyReset(LobbyManager.getInstance().getLobby(lobbyid));
getLogger().info("Shut down Lobby: " + lobbyid);
plugin.getLogger().info("Shut down Lobby: " + lobbyid);
}
GameManager.frozenPlayers.clear();
getLogger().info("MinigameCore disabled!");
plugin.getLogger().info("MinigameCore disabled!");
}

public List<String> getAvailableGames() {
Expand Down Expand Up @@ -94,7 +94,10 @@ public void unbanPlayer(UUID player) {
writeBannedPlayers();
}

public MiniGameCore getPlugin() {
public static MiniGameCore getPlugin() {
if (plugin == null) {
plugin = JavaPlugin.getPlugin(MiniGameCore.class);
}
return plugin;
}
}
204 changes: 111 additions & 93 deletions src/main/java/wueffi/MiniGameCore/commands/MiniGameCommand.java

Large diffs are not rendered by default.

44 changes: 36 additions & 8 deletions src/main/java/wueffi/MiniGameCore/managers/GameManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package wueffi.MiniGameCore.managers;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
Expand All @@ -21,10 +24,9 @@

import java.io.File;
import java.nio.file.Files;
import java.time.Duration;
import java.util.*;

import static org.bukkit.Bukkit.getLogger;

public class GameManager implements Listener {
static final Map<Lobby, List<Player>> alivePlayers = new HashMap<>();
public static final Set<Player> frozenPlayers = new HashSet<>();
Expand All @@ -45,8 +47,10 @@ public static void startGame(Lobby lobby) {
}

public static void winGame(Lobby lobby, Player winner) {
Title wonTitle = Title.title(Component.text(winner.getName(), NamedTextColor.GOLD),
Component.text("won the Game!", NamedTextColor.RED));
for (Player player : lobby.getPlayers()) {
player.sendTitle("§6" + winner.getName(), "won the Game!", 10, 70, 20);
player.showTitle(wonTitle);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 1.0f);
Stats.win(lobby.getGameName(), winner);
if (!player.equals(winner)) {
Expand Down Expand Up @@ -87,7 +91,8 @@ private static void startCountdown(Lobby lobby) {

for (Player teamPlayer : teamPlayers) {
if (teamSpawns.isEmpty()) {
getLogger().warning("Not enough SpawnPoints for Team " + (teamIndex + 1) + " in Lobby " + lobby.getLobbyId());
MiniGameCore.getPlugin().getLogger().warning("Not enough SpawnPoints for Team " + (teamIndex + 1) +
" in Lobby " + lobby.getLobbyId());
continue;
}

Expand Down Expand Up @@ -121,15 +126,25 @@ private static void startCountdown(Lobby lobby) {
@Override
public void run() {
if (timeLeft > 0) {
Title countdownTitle = Title.title(
Component.text("Game starting in " + timeLeft, NamedTextColor.GREEN),
Component.text("Get ready!", NamedTextColor.RED),
Title.Times.times(Duration.ofMillis(10), Duration.ofMillis(70), Duration.ofMillis(20))
);
for (Player player : lobby.getPlayers()) {
player.sendTitle("§aGame starting in " + timeLeft, "", 10, 70, 20);
player.showTitle(countdownTitle);
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_HAT, 1.0f, 2.0f);
}
timeLeft--;
} else {
lobby.setLobbyState("GAME");
Title startTitle = Title.title(
Component.text("Game Started!", NamedTextColor.GREEN),
Component.text("Teaming / Cheating is bannable!", NamedTextColor.RED),
Title.Times.times(Duration.ofMillis(10), Duration.ofMillis(70), Duration.ofMillis(20))
);
for (Player player : lobby.getPlayers()) {
player.sendTitle("§aGame Started!", "§cTeaming / Cheating is bannable!");
player.showTitle(startTitle);
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL, 1.0f, 5.0f);
ScoreBoardManager.setPlayerStatus(player, "GAME");
player.getInventory().clear();
Expand Down Expand Up @@ -323,10 +338,23 @@ public void run() {
if (secondsLeft <= 0) {
player.teleport(respawnLocation);
player.setGameMode(GameMode.SURVIVAL);
player.sendTitle("§aRespawned!", "", 10, 20, 10);
player.showTitle(
Title.title(Component.text("Respawned!", NamedTextColor.GREEN),
Component.empty(),
Title.Times.times(
Duration.ofMillis(10), Duration.ofMillis(70), Duration.ofMillis(20))
)
);
this.cancel();
} else {
player.sendTitle("§cRespawning in", "§c" + secondsLeft + " s", 0, 20, 0);
player.showTitle(
Title.title(
Component.text("Respawning in!", NamedTextColor.RED),
Component.text(secondsLeft + " s", NamedTextColor.RED),
Title.Times.times(
Duration.ofMillis(0), Duration.ofMillis(20), Duration.ofMillis(0))
)
);
secondsLeft--;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/wueffi/MiniGameCore/managers/LobbyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.entity.Player;
import wueffi.MiniGameCore.utils.Lobby;

import javax.annotation.Nullable;
import java.io.File;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -44,6 +45,7 @@ public Lobby createLobby(String gameName, int maxPlayers, Player owner, File new
return lobby;
}

@Nullable
public Lobby getLobby(String lobbyId) {
return lobbies.get(lobbyId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.HashMap;
import java.util.Map;

import static org.bukkit.Bukkit.getLogger;
import static wueffi.MiniGameCore.managers.GameManager.alivePlayers;

public class ScoreBoardManager implements Listener {
Expand Down Expand Up @@ -50,7 +49,6 @@ public void run() {

public static void updatePlayerBoard(Player player) {
String status = playerGameStatus.getOrDefault(player, "NONE");
// getLogger().info(status);
switch (status) {
case "WAITING":
Lobby lobby = LobbyManager.getLobbyByPlayer(player);
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/wueffi/MiniGameCore/utils/ComponentFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package wueffi.MiniGameCore.utils;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;

public class ComponentFactory {
private final TextComponent.Builder component;

public ComponentFactory() {
component = Component.text();
this.addColorText("[", NamedTextColor.DARK_GRAY);
this.addColorText("MiniGameCore", NamedTextColor.GOLD);
this.addColorText("] ", NamedTextColor.DARK_GRAY);
}

public ComponentFactory(String text) {
this();
this.addText(text);
}

public ComponentFactory(String text, NamedTextColor color) {
this();
this.addColorText(text, color);
}

public ComponentFactory addText(String text) {
component.append(Component.text(text));
return this;
}

public ComponentFactory addColorText(String text, NamedTextColor color) {
component.append(Component.text(text).color(color));
return this;
}

public ComponentFactory addColorText(String text, TextColor color) {
component.append(Component.text(text).color(color));
return this;
}

public TextComponent toComponent() {
return component.build();
}
}
6 changes: 3 additions & 3 deletions src/main/java/wueffi/MiniGameCore/utils/LobbyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import org.bukkit.Bukkit;
import org.bukkit.World;
import wueffi.MiniGameCore.MiniGameCore;

import java.io.File;
import java.util.Objects;

import static org.bukkit.Bukkit.getLogger;
import static wueffi.MiniGameCore.managers.LobbyManager.removeLobby;

public class LobbyHandler {

public static void LobbyReset(Lobby lobby) {
if (lobby == null) {
getLogger().warning("Lobby was null!");
MiniGameCore.getPlugin().getLogger().warning("Lobby was null!");
return;
}
deleteWorldFolder(lobby);
Expand All @@ -27,7 +27,7 @@ private static void deleteWorldFolder(Lobby lobby) {
Bukkit.unloadWorld(world, false);
}
delete(lobby.getWorldFolder());
getLogger().info("Deleted world: " + lobby.getWorldFolder().getName());
MiniGameCore.getPlugin().getLogger().info("Deleted world: " + lobby.getWorldFolder().getName());
}

private static void delete(File file) {
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/wueffi/MiniGameCore/utils/ScoreBoard.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package wueffi.MiniGameCore.utils;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Criteria;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
Expand All @@ -14,12 +18,12 @@
public class ScoreBoard {

private static final List<String> animations = Arrays.asList("§b§l» Lobbies", "§b§l» Stats");
private static final String TITLE = "§6§lMiniGameCore";
private static final Component TITLE = Component.text("MiniGameCore", NamedTextColor.GOLD, TextDecoration.BOLD);
private static int animationIndex = 0;

public static void createGameBoard(Player player, List<Player> alive) {
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
Objective obj = board.registerNewObjective("game", "dummy", TITLE);
Objective obj = board.registerNewObjective("game", Criteria.DUMMY, TITLE);
obj.setDisplaySlot(DisplaySlot.SIDEBAR);

int count = alive != null ? alive.size() : 0;
Expand All @@ -44,7 +48,7 @@ public static void createGameBoard(Player player, List<Player> alive) {

public static void createLobbyBoard(Player player, Lobby lobby) {
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
Objective obj = board.registerNewObjective("lobby", "dummy", TITLE);
Objective obj = board.registerNewObjective("lobby", Criteria.DUMMY, TITLE);
obj.setDisplaySlot(DisplaySlot.SIDEBAR);

List<Player> players = new ArrayList<>(lobby.getPlayers());
Expand Down Expand Up @@ -76,7 +80,7 @@ public static void createLobbyBoard(Player player, Lobby lobby) {
public static void createIdleBoard(Player player, String mostPlayed, int played, int won, int lost, List<Lobby> openLobbies, List<Lobby> closedLobbies) {
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
String title = animations.get(animationIndex);
Objective obj = board.registerNewObjective("idle", "dummy", TITLE);
Objective obj = board.registerNewObjective("idle", Criteria.DUMMY, TITLE);
obj.setDisplaySlot(DisplaySlot.SIDEBAR);

if (animationIndex == 0) {
Expand Down