Skip to content

Commit

Permalink
Added scoreboard module
Browse files Browse the repository at this point in the history
  • Loading branch information
PauMAVA committed Dec 28, 2019
1 parent 0b72999 commit 6b9f1ad
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/me/PauMAVA/TTR/TTRCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import me.PauMAVA.TTR.match.MatchStatus;
import me.PauMAVA.TTR.match.TTRMatch;
import me.PauMAVA.TTR.teams.TTRTeamHandler;
import me.PauMAVA.TTR.ui.TTRCustomTab;
import me.PauMAVA.TTR.ui.TTRScoreboard;
import me.PauMAVA.TTR.util.EventListener;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -34,15 +36,20 @@ public class TTRCore extends JavaPlugin {
private TTRTeamHandler teamHandler;
private TTRConfigManager configManager;
private World matchWorld;
private TTRCustomTab customTab;
private TTRScoreboard scoreboard;

@Override
public void onEnable() {
instance = this;
if (this.getConfig().getBoolean("enableOnStart")) {
enabled = true;
}
this.customTab = new TTRCustomTab();
this.scoreboard = new TTRScoreboard();
if(enabled) {
this.match = new TTRMatch(MatchStatus.PREGAME);
this.customTab.runTaskTimer(this, 0L, 20L);
} else {
this.match = new TTRMatch(MatchStatus.DISABLED);
}
Expand All @@ -57,7 +64,8 @@ public void onEnable() {

@Override
public void onDisable() {

this.customTab.cancel();
this.scoreboard.removeScoreboard();
}

public static TTRCore getInstance() {
Expand All @@ -83,4 +91,8 @@ public TTRConfigManager getConfigManager() {
public World getMatchWorld() {
return this.matchWorld;
}

public TTRScoreboard getScoreboard() {
return scoreboard;
}
}
6 changes: 5 additions & 1 deletion src/me/PauMAVA/TTR/teams/TTRTeamHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public TTRTeam getPlayerTeam(Player player) {
return null;
}

private TTRTeam getTeam(String teamIdentifier) {
public TTRTeam getTeam(String teamIdentifier) {
for(TTRTeam team: this.teams) {
teamIdentifier = ChatColor.stripColor(teamIdentifier);
if(teamIdentifier.contentEquals(team.getIdentifier())) {
Expand All @@ -75,6 +75,10 @@ private TTRTeam getTeam(String teamIdentifier) {
return null;
}

public List<TTRTeam> getTeams() {
return this.teams;
}

public void addPlayer(String teamIdentifier, Player player) {
getTeam(teamIdentifier).addPlayer(player);
}
Expand Down
27 changes: 26 additions & 1 deletion src/me/PauMAVA/TTR/ui/TTRCustomTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,41 @@

package me.PauMAVA.TTR.ui;

import me.PauMAVA.TTR.util.TTRPrefix;
import net.minecraft.server.v1_15_R1.PacketPlayOutPlayerListHeaderFooter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.lang.reflect.Field;

public class TTRCustomTab extends BukkitRunnable {

private String prefix;
private String suffix;
private String suffix = ChatColor.AQUA + "(c) 2019-2020" + ChatColor.BOLD + " PauMAVA" + ChatColor.RESET + "\n" + ChatColor.GREEN + "The Towers Remastered (TTR)";
private int i;

@Override
public void run() {
switch (i) {
case 1:
case 3:
case 5: {
this.prefix = TTRPrefix.TTR_GAME + "";
break;
}
case 2:
case 4: {
this.prefix = TTRPrefix.TTR_GAME_DARK + "";
break;
}
case 8: {
i = 1;
}
}
i++;
sendPacket();
}

Expand All @@ -43,6 +65,9 @@ private void sendPacket() {
footer.setAccessible(true);
header.set(packet, this.prefix);
footer.set(packet, this.suffix);
for(Player player: Bukkit.getServer().getOnlinePlayers()) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
Expand Down
65 changes: 65 additions & 0 deletions src/me/PauMAVA/TTR/ui/TTRScoreboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package me.PauMAVA.TTR.ui;

import me.PauMAVA.TTR.TTRCore;
import me.PauMAVA.TTR.teams.TTRTeam;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.*;

public class TTRScoreboard {

private ScoreboardManager scoreboardManager = Bukkit.getScoreboardManager();
private Scoreboard ttrScoreboard;
private Objective kills;
private Objective health;
private Objective points;
private int taskPID;

public TTRScoreboard() {
this.ttrScoreboard = this.scoreboardManager.getNewScoreboard();
this.kills = this.ttrScoreboard.registerNewObjective("kills", "PLAYER_KILLS", ChatColor.LIGHT_PURPLE + "kills");
this.kills.setDisplaySlot(DisplaySlot.PLAYER_LIST);
this.health = this.ttrScoreboard.registerNewObjective("health", "HEALTH", "Health", RenderType.HEARTS);
this.health.setDisplaySlot(DisplaySlot.BELOW_NAME);
this.points = this.ttrScoreboard.registerNewObjective("points", "DUMMY", "Points");
this.points.setDisplaySlot(DisplaySlot.SIDEBAR);
}

public void refreshScoreboard() {
for(Player player: Bukkit.getServer().getOnlinePlayers()) {
player.setScoreboard(this.ttrScoreboard);
}
}

public void removeScoreboard() {
for(Player player: Bukkit.getServer().getOnlinePlayers()) {
player.setScoreboard(this.scoreboardManager.getMainScoreboard());
}
}

public void startScoreboardTask() {
this.taskPID = new BukkitRunnable(){
private int i = 0;
@Override
public void run() {
for(TTRTeam team: TTRCore.getInstance().getTeamHandler().getTeams()) {
points.getScore(team.getIdentifier()).setScore(team.getPoints());
}
points.getScore("------------------").setScore(-1);
points.getScore(ChatColor.GREEN + "Total time: ").setScore(-2);
i++;
}

private void prettyTime(int i) {

}
}.runTaskTimer(TTRCore.getInstance(), 0L, 20L).getTaskId();
}

public void stopScoreboardTask() {
Bukkit.getScheduler().cancelTask(this.taskPID);
}

}
1 change: 1 addition & 0 deletions src/me/PauMAVA/TTR/util/TTRPrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public enum TTRPrefix {

TTR_GAME(ChatColor.GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + ChatColor.GREEN + "" + ChatColor.BOLD + "The Towers" + ChatColor.RESET + ChatColor.GRAY + "" + ChatColor.BOLD + "]" + ChatColor.RESET + " "),
TTR_GAME_DARK(ChatColor.GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "The Towers" + ChatColor.RESET + ChatColor.GRAY + "" + ChatColor.BOLD + "]" + ChatColor.RESET + " "),
TTR_GLOBAL(ChatColor.GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "GLOBAL" + ChatColor.RESET + ChatColor.GRAY + "" + ChatColor.BOLD + "]" + ChatColor.RESET + " "),
TTR_TEAM(ChatColor.GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + ChatColor.GREEN + "" + ChatColor.BOLD + "TEAM" + ChatColor.RESET + ChatColor.GRAY + "" + ChatColor.BOLD + "]" + ChatColor.RESET + " ");

Expand Down

0 comments on commit 6b9f1ad

Please sign in to comment.