Skip to content

Commit

Permalink
implement scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptnSisko committed Jan 2, 2021
1 parent d812f57 commit 4291f7a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<groupId>com.intellectualsites.fawe</groupId>
<artifactId>FAWE-Bukkit</artifactId>
<version>1.16-462</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
Expand All @@ -76,6 +77,11 @@
<version>5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.missionarydev</groupId>
<artifactId>board</artifactId>
<version>-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/me/sisko/partygames/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,35 @@
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;

import me.missionary.board.BoardManager;
import me.missionary.board.settings.BoardSettings;
import me.missionary.board.settings.ScoreDirection;
import me.sisko.partygames.commands.playCommand;
import me.sisko.partygames.util.ConfigManager;
import me.sisko.partygames.util.MinigameManager;
import me.sisko.partygames.util.ScoreboardProvider;

public class Main extends JavaPlugin {
private static Main plugin;

private BoardManager manager;

@Override
public void onEnable() {
plugin = this;
getLogger().info("Hello World!");
getCommand("play").setExecutor(new playCommand());


manager = new BoardManager(this, BoardSettings.builder().boardProvider(new ScoreboardProvider()).scoreDirection(ScoreDirection.UP).build());
Bukkit.getPluginManager().registerEvents(manager, this);
Bukkit.getPluginManager().registerEvents(new DefaultListener(), this);
ConfigManager.load();
MinigameManager.load();

}

@Override
public void onDisable() {
manager.onDisable();
}

public static Main getPlugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import me.sisko.partygames.Main;
import me.sisko.partygames.util.MinigameManager;
import net.md_5.bungee.api.ChatColor;

public class DiggingMinigame extends Minigame {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ public void onMove(PlayerMoveEvent e) {
} else if (!inGame.contains(e.getPlayer())) {
e.setCancelled(false);
addPlayer(e.getPlayer());

// player is in game after winning and has just died
} else {
addPlayer(e.getPlayer());
}
} else if (inGame.contains(e.getPlayer()) && gameStarted) {

Expand Down Expand Up @@ -243,8 +247,6 @@ public void run() {
}
}
// after game ends, winner falls down
} else if (!gameStarted) {
e.getPlayer().teleport(spawn);
}
}
}
51 changes: 50 additions & 1 deletion src/main/java/me/sisko/partygames/util/MinigameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public class MinigameManager {
private static Minigame currentMinigame = null;
private static BukkitRunnable timeout = null;

private static long endTime = 0;

public static enum GameState {
PREGAME,
INGAME,
POSTGAME,
NOGAME
};

private static GameState state = GameState.NOGAME;


public static void load() {
File dataFolder = new File(Main.getPlugin().getDataFolder().getAbsolutePath() + "/games");
Expand Down Expand Up @@ -96,6 +107,9 @@ public static void initializationComplete() {

// called by the minigame when done initializing
public static void prestartComplete() {
endTime = System.currentTimeMillis() + 10*1000;
state = GameState.PREGAME;

Bukkit.broadcastMessage("Game starting in 10 seconds...");

new BukkitRunnable(){
Expand Down Expand Up @@ -130,6 +144,9 @@ public void run() {
};
timeout.runTaskLater(Main.getPlugin(), currentMinigame.getTimeoutTime());
currentMinigame.start();

state = GameState.INGAME;
endTime = System.currentTimeMillis() + currentMinigame.getTimeoutTime()*1000/20;
}
}.runTaskLater(Main.getPlugin(), 10*20);

Expand All @@ -140,7 +157,9 @@ public static void gameComplete(final List<Player> winners) {
timeout.cancel();
timeout = null;
currentMinigame.postgame();

state = GameState.POSTGAME;
endTime = System.currentTimeMillis() + 10*1000;

Bukkit.broadcastMessage("Minigame " + currentMinigame.getName() + " complete!");
Bukkit.broadcastMessage("Map: " + currentMinigame.getMap());
Bukkit.broadcastMessage("Winners: ");
Expand Down Expand Up @@ -175,6 +194,7 @@ public void run() {
HandlerList.unregisterAll(currentMinigame);
currentMinigame.cleanup();
currentMinigame = null;
state = GameState.NOGAME;

for(Player p : Bukkit.getOnlinePlayers()) {
FileConfiguration config = Main.getPlugin().getConfig();
Expand Down Expand Up @@ -216,4 +236,33 @@ private static final JSONObject getJson(File f) {
}
return null;
}


public static final List<String> getScoreboardLines(Player p) {
List<String> lines = new ArrayList<>();
lines.add("&6mc.left4craft.org");
lines.add("&7&m-----------------");
lines.add("&dGame&7: &e" + currentMinigame.getName());
lines.add("");
lines.add("&dMap&7: &e" + currentMinigame.getMap());
lines.add("");

final long diff = 1000 + endTime - System.currentTimeMillis();
final int seconds = (int) Math.floor((diff%60000) / 1000);
final String seconds_str = seconds < 10 ? "0" + seconds : "" + seconds;

if(state == GameState.PREGAME) {
lines.add("&dGame starts&7: &e" + (int) Math.floor(diff/60000.) + ":" + seconds_str);
lines.add("");
} else if (state == GameState.INGAME) {
lines.add("&dGame finishes&7: &e" + (int) Math.floor(diff/60000.) + ":" + seconds_str);
lines.add("");
} else if (state == GameState.POSTGAME) {
lines.add("&dGame ends&7: &e" + (int) Math.floor(diff/60000.) + ":" + seconds_str);
lines.add("");
}

lines.add("&7&m-----------------");
return lines;
}
}
36 changes: 36 additions & 0 deletions src/main/java/me/sisko/partygames/util/ScoreboardProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.sisko.partygames.util;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.entity.Player;

import me.missionary.board.provider.BoardProvider;
import net.md_5.bungee.api.ChatColor;

public class ScoreboardProvider implements BoardProvider {

@Override
public String getTitle(Player player) {
return ChatColor.LIGHT_PURPLE + "Party Games";
}

@Override
public List<String> getLines(Player player) {
if(MinigameManager.inGame()) {
return MinigameManager.getScoreboardLines(player);
}
List<String> lines = new ArrayList<>();
lines.add("&6mc.left4craft.org");
lines.add("&7&m-----------------");
lines.add(ChatColor.LIGHT_PURPLE + "Name" + ChatColor.GRAY + ": " + ChatColor.YELLOW + player.getName());
lines.add("");
lines.add(ChatColor.LIGHT_PURPLE + "Wins" + ChatColor.GRAY + ": " + ChatColor.YELLOW + "5");
lines.add("");
lines.add(ChatColor.LIGHT_PURPLE + "Points" + ChatColor.GRAY + ": " + ChatColor.YELLOW + "432");
lines.add("");
lines.add("&7&m-----------------");
return lines;
}

}

0 comments on commit 4291f7a

Please sign in to comment.