removed useless shit

This commit is contained in:
Luca 2021-11-22 19:24:13 +01:00
parent e1fa2ad04c
commit 25e646e93c
13 changed files with 0 additions and 841 deletions

View File

@ -79,12 +79,6 @@ public final class BedWars extends JavaPlugin {
this.loadListeners();
this.loadRunnables();
/*
Assemble assemble = new Assemble(this, new ScoreboardProvider());
assemble.setTicks(2);
assemble.setAssembleStyle(AssembleStyle.VIPER);
*/
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PlaceholderAPIProvider(this).register();
Bukkit.getConsoleSender().sendMessage(CC.translate("&aPlaceholderAPI successfully registered!"));

View File

@ -1,149 +0,0 @@
package rip.tilly.bedwars.providers.scoreboard.old;
import org.bukkit.Bukkit;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameTeam;
import rip.tilly.bedwars.managers.party.Party;
import rip.tilly.bedwars.managers.queue.QueueEntry;
import rip.tilly.bedwars.playerdata.PlayerState;
import rip.tilly.bedwars.utils.TimeUtils;
import rip.tilly.bedwars.utils.assemble.AssembleAdapter;
import org.bukkit.entity.Player;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.utils.CC;
import java.util.ArrayList;
import java.util.List;
public class ScoreboardProvider implements AssembleAdapter {
private BedWars main = BedWars.getInstance();
@Override
public String getTitle(Player player) {
return CC.translate("&d&lBedWars");
}
@Override
public List<String> getLines(Player player) {
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
if (!playerData.getPlayerSettings().isScoreboardEnabled()) {
return null;
}
switch (playerData.getPlayerState()) {
case SPAWN:
case QUEUE:
return this.spawnScoreboard(playerData);
case RESPAWNING:
case PLAYING:
return this.playingScoreboard(playerData);
case SPECTATING:
return null;
}
return null;
}
private List<String> spawnScoreboard(PlayerData playerData) {
List<String> lines = new ArrayList<String>();
lines.add(CC.scoreboardBar);
if (this.main.getPartyManager().getParty(playerData.getUniqueId()) != null) {
Party party = this.main.getPartyManager().getParty(playerData.getUniqueId());
lines.add("&9Party Leader: &d" + Bukkit.getPlayer(party.getLeader()).getName());
lines.add("&9Party Members: &d" + party.getMembers().size() + "&7/&d" + party.getLimit());
lines.add(CC.scoreboardBar);
}
if (playerData.getPlayerState() == PlayerState.QUEUE) {
QueueEntry queueEntry = this.main.getQueueManager().getQueueEntry(playerData.getUniqueId());
if (queueEntry != null) {
long queueTime = System.currentTimeMillis() - (this.main.getQueueManager().getPlayerQueueTime(playerData.getUniqueId()));
String formattedQueueTime = TimeUtils.formatIntoMMSS(Math.round(queueTime / 1000L));
lines.add("&e" + queueEntry.getGameType().getName() + " Queue");
lines.add("&fTime: &d" + formattedQueueTime);
lines.add(CC.scoreboardBar);
}
}
lines.add("&fOnline: &d" + this.main.getServer().getOnlinePlayers().size());
lines.add("&fQueueing: &d" + this.main.getQueueManager().getAllQueueSize());
lines.add("&fPlaying: &d" + this.main.getGameManager().getPlaying());
lines.add(" ");
lines.add("&fLevel: &d" + playerData.getLevel());
String finishedProgress = "";
int notFinishedProgress = 10;
for (int i = 0; i < playerData.getXp() * 100; i++) {
if (i % 10 == 0) {
finishedProgress += "";
notFinishedProgress--;
}
}
String leftOverProgress = "";
for (int i = 1; i <= notFinishedProgress; i++) {
leftOverProgress += "";
}
lines.add("&8" + finishedProgress + "&7" + leftOverProgress + " &7(" + ((int) (playerData.getXp() * 100)) + "%&7)");
lines.add(" ");
lines.add("&dtilly.rip");
lines.add(CC.scoreboardBar);
return CC.translate(lines);
}
private List<String> playingScoreboard(PlayerData playerData) {
List<String> lines = new ArrayList<String>();
Game game = this.main.getGameManager().getGame(playerData);
GameTeam yourTeam = game.getTeamByName(playerData.getPlayerTeam().getName());
GameTeam opposingTeam = game.getTeams().get(playerData.getTeamId() == 1 ? 0 : 1);
lines.add(CC.scoreboardBar);
lines.add("&fDuration: &d" + game.getDuration());
lines.add(" ");
if (yourTeam.isHasBed()) {
lines.add("&7[" + yourTeam.getPlayerTeam().getChatColor() + yourTeam.getPlayerTeam().getSmallName() + "&7] &a&l✓ &7(You)");
} else if (yourTeam.getPlayingPlayers().size() > 0) {
lines.add("&7[" + yourTeam.getPlayerTeam().getChatColor() + yourTeam.getPlayerTeam().getSmallName() + "&7] &f" + yourTeam.getPlayingPlayers().size() + " &7(YOU)");
} else {
lines.add("&7[" + yourTeam.getPlayerTeam().getChatColor() + yourTeam.getPlayerTeam().getSmallName() + "&7] &c&l✗ &7(You)");
}
if (opposingTeam.isHasBed()) {
lines.add("&7[" + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getSmallName() + "&7] &a&l✓");
} else if (opposingTeam.getPlayingPlayers().size() > 0) {
lines.add("&7[" + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getSmallName() + "&7] &f" + yourTeam.getPlayingPlayers().size());
} else {
lines.add("&7[" + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getSmallName() + "&7] &c&l✗");
}
lines.add(" ");
lines.add("&fKills: &d" + playerData.getGameKills());
lines.add("&fBeds Destroyed: &d" + playerData.getGameBedsDestroyed());
lines.add(" ");
lines.add("&dtilly.rip");
lines.add(CC.scoreboardBar);
return CC.translate(lines);
}
private List<String> spectatingScoreboard(PlayerData playerData) {
List<String> lines = new ArrayList<String>();
lines.add(CC.scoreboardBar);
lines.add(CC.scoreboardBar);
return CC.translate(lines);
}
}

View File

@ -1,108 +0,0 @@
package rip.tilly.bedwars.utils.assemble;
import rip.tilly.bedwars.utils.assemble.events.AssembleBoardCreateEvent;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@Getter @Setter
public class Assemble {
private JavaPlugin plugin;
private AssembleAdapter adapter;
private AssembleThread thread;
private AssembleListener listeners;
private AssembleStyle assembleStyle = AssembleStyle.MODERN;
private Map<UUID, AssembleBoard> boards;
private long ticks = 2;
private boolean hook = false, debugMode = true;
/**
* Assemble.
*
* @param plugin instance.
* @param adapter
*/
public Assemble(JavaPlugin plugin, AssembleAdapter adapter) {
if (plugin == null) {
throw new RuntimeException("Assemble can not be instantiated without a plugin instance!");
}
this.plugin = plugin;
this.adapter = adapter;
this.boards = new ConcurrentHashMap<>();
this.setup();
}
/**
* Setup Assemble.
*/
public void setup() {
// Register Events.
this.listeners = new AssembleListener(this);
this.plugin.getServer().getPluginManager().registerEvents(listeners, this.plugin);
// Ensure that the thread has stopped running.
if (this.thread != null) {
this.thread.stop();
this.thread = null;
}
// Register new boards for existing online players.
for (Player player : Bukkit.getOnlinePlayers()) {
// Make sure it doesn't double up.
AssembleBoardCreateEvent createEvent = new AssembleBoardCreateEvent(player);
Bukkit.getPluginManager().callEvent(createEvent);
if (createEvent.isCancelled()) {
return;
}
getBoards().putIfAbsent(player.getUniqueId(), new AssembleBoard(player, this));
}
// Start Thread.
this.thread = new AssembleThread(this);
}
/**
*
*/
public void cleanup() {
// Stop thread.
if (this.thread != null) {
this.thread.stop();
this.thread = null;
}
// Unregister listeners.
if (listeners != null) {
HandlerList.unregisterAll(listeners);
listeners = null;
}
// Destroy player scoreboards.
for (UUID uuid : getBoards().keySet()) {
Player player = Bukkit.getPlayer(uuid);
if (player == null || !player.isOnline()) {
continue;
}
getBoards().remove(uuid);
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
}
}
}

View File

@ -1,25 +0,0 @@
package rip.tilly.bedwars.utils.assemble;
import org.bukkit.entity.Player;
import java.util.List;
public interface AssembleAdapter {
/**
* Get's the scoreboard title.
*
* @param player who's title is being displayed.
* @return title.
*/
String getTitle(Player player);
/**
* Get's the scoreboard lines.
*
* @param player who's lines are being displayed.
* @return lines.
*/
List<String> getLines(Player player);
}

View File

@ -1,127 +0,0 @@
package rip.tilly.bedwars.utils.assemble;
import rip.tilly.bedwars.utils.assemble.events.AssembleBoardCreatedEvent;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class AssembleBoard {
@Getter private Assemble assemble;
@Getter private final List<AssembleBoardEntry> entries = new ArrayList<>();
@Getter private final List<String> identifiers = new ArrayList<>();
@Getter private final UUID uuid;
/**
* Assemble Board.
*
* @param player that the board belongs to.
* @param assemble instance.
*/
public AssembleBoard(Player player, Assemble assemble) {
this.uuid = player.getUniqueId();
this.assemble = assemble;
this.setup(player);
}
/**
* Get's a player's bukkit scoreboard.
*
* @return either existing scoreboard or new scoreboard.
*/
public Scoreboard getScoreboard() {
Player player = Bukkit.getPlayer(getUuid());
if (getAssemble().isHook() || player.getScoreboard() != Bukkit.getScoreboardManager().getMainScoreboard()) {
return player.getScoreboard();
} else {
return Bukkit.getScoreboardManager().getNewScoreboard();
}
}
/**
* Get's the player's scoreboard objective.
*
* @return either existing objecting or new objective.
*/
public Objective getObjective() {
Scoreboard scoreboard = getScoreboard();
if (scoreboard.getObjective("Assemble") == null) {
Objective objective = scoreboard.registerNewObjective("Assemble", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(getAssemble().getAdapter().getTitle(Bukkit.getPlayer(getUuid())));
return objective;
} else {
return scoreboard.getObjective("Assemble");
}
}
/**
* Setup the board.
*
* @param player who's board to setup.
*/
private void setup(Player player) {
Scoreboard scoreboard = getScoreboard();
player.setScoreboard(scoreboard);
getObjective();
// Send Update.
AssembleBoardCreatedEvent createdEvent = new AssembleBoardCreatedEvent(this);
Bukkit.getPluginManager().callEvent(createdEvent);
}
/**
* Get the board entry at a specific position.
*
* @param pos to find entry.
* @return entry if it isn't out of range.
*/
public AssembleBoardEntry getEntryAtPosition(int pos) {
return pos >= this.entries.size() ? null : this.entries.get(pos);
}
/**
* Get the unique identifier for position in scoreboard.
*
* @param position for identifier.
* @return unique identifier.
*/
public String getUniqueIdentifier(int position) {
String identifier = getRandomChatColor(position) + ChatColor.WHITE;
while (this.identifiers.contains(identifier)) {
identifier = identifier + getRandomChatColor(position) + ChatColor.WHITE;
}
// This is rare, but just in case, make the method recursive
if (identifier.length() > 16) {
return this.getUniqueIdentifier(position);
}
// Add our identifier to the list so there are no duplicates
this.identifiers.add(identifier);
return identifier;
}
/**
* Gets a ChatColor based off the position in the collection.
*
* @param position of entry.
* @return ChatColor adjacent to position.
*/
private static String getRandomChatColor(int position) {
return ChatColor.values()[position].toString();
}
}

View File

@ -1,116 +0,0 @@
package rip.tilly.bedwars.utils.assemble;
import lombok.Setter;
import org.bukkit.ChatColor;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
public class AssembleBoardEntry {
private final AssembleBoard board;
@Setter private String text, identifier;
private Team team;
private int position;
/**
* Assemble Board Entry
*
* @param board that entry belongs to.
* @param text of entry.
* @param position of entry.
*/
public AssembleBoardEntry(AssembleBoard board, String text, int position) {
this.board = board;
this.text = text;
this.position = position;
this.identifier = this.board.getUniqueIdentifier(position);
this.setup();
}
/**
* Setup Board Entry.
*/
public void setup() {
final Scoreboard scoreboard = this.board.getScoreboard();
if (scoreboard == null) {
return;
}
String teamName = this.identifier;
// This shouldn't happen, but just in case.
if (teamName.length() > 16) {
teamName = teamName.substring(0, 16);
}
Team team = scoreboard.getTeam(teamName);
// Register the team if it does not exist.
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
}
// Add the entry to the team.
if (team.getEntries() == null || team.getEntries().isEmpty() || !team.getEntries().contains(this.identifier)) {
team.addEntry(this.identifier);
}
// Add the entry if it does not exist.
if (!this.board.getEntries().contains(this)) {
this.board.getEntries().add(this);
}
this.team = team;
}
/**
* Send Board Entry Update.
*
* @param position of entry.
*/
public void send(int position) {
if (this.text.length() > 16) {
String prefix = this.text.substring(0, 16);
String suffix;
if (prefix.charAt(15) == ChatColor.COLOR_CHAR) {
prefix = prefix.substring(0, 15);
suffix = this.text.substring(15, this.text.length());
} else if (prefix.charAt(14) == ChatColor.COLOR_CHAR) {
prefix = prefix.substring(0, 14);
suffix = this.text.substring(14, this.text.length());
} else {
if (ChatColor.getLastColors(prefix).equalsIgnoreCase(ChatColor.getLastColors(this.identifier))) {
suffix = this.text.substring(16, this.text.length());
} else {
suffix = ChatColor.getLastColors(prefix) + this.text.substring(16, this.text.length());
}
}
if (suffix.length() > 16) {
suffix = suffix.substring(0, 16);
}
this.team.setPrefix(prefix);
this.team.setSuffix(suffix);
} else {
this.team.setPrefix(this.text);
this.team.setSuffix("");
}
Score score = this.board.getObjective().getScore(this.identifier);
score.setScore(position);
}
/**
* Remove Board Entry from Board.
*/
public void remove() {
this.board.getIdentifiers().remove(this.identifier);
this.board.getScoreboard().resetScores(this.identifier);
}
}

View File

@ -1,14 +0,0 @@
package rip.tilly.bedwars.utils.assemble;
public class AssembleException extends RuntimeException {
/**
* Assemble Exception.
*
* @param message attributed to exception.
*/
public AssembleException(String message) {
super(message);
}
}

View File

@ -1,51 +0,0 @@
package rip.tilly.bedwars.utils.assemble;
import rip.tilly.bedwars.utils.assemble.events.AssembleBoardCreateEvent;
import rip.tilly.bedwars.utils.assemble.events.AssembleBoardDestroyEvent;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@Getter
public class AssembleListener implements Listener {
private Assemble assemble;
/**
* Assemble Listener.
*
* @param assemble instance.
*/
public AssembleListener(Assemble assemble) {
this.assemble = assemble;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
AssembleBoardCreateEvent createEvent = new AssembleBoardCreateEvent(event.getPlayer());
Bukkit.getPluginManager().callEvent(createEvent);
if (createEvent.isCancelled()) {
return;
}
getAssemble().getBoards().put(event.getPlayer().getUniqueId(), new AssembleBoard(event.getPlayer(), getAssemble()));
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
AssembleBoardDestroyEvent destroyEvent = new AssembleBoardDestroyEvent(event.getPlayer());
Bukkit.getPluginManager().callEvent(destroyEvent);
if (destroyEvent.isCancelled()) {
return;
}
getAssemble().getBoards().remove(event.getPlayer().getUniqueId());
event.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
}
}

View File

@ -1,26 +0,0 @@
package rip.tilly.bedwars.utils.assemble;
import lombok.Getter;
@Getter
public enum AssembleStyle {
KOHI(true, 15),
VIPER(true, -1),
MODERN(false, 1);
private boolean descending;
private int startNumber;
/**
* Assemble Style.
*
* @param descending whether the positions are going down or up.
* @param startNumber from where to loop from.
*/
AssembleStyle(boolean descending, int startNumber) {
this.descending = descending;
this.startNumber = startNumber;
}
}

View File

@ -1,127 +0,0 @@
package rip.tilly.bedwars.utils.assemble;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import java.util.Collections;
import java.util.List;
public class AssembleThread extends Thread {
private Assemble assemble;
/**
* Assemble Thread.
*
* @param assemble instance.
*/
AssembleThread(Assemble assemble) {
this.assemble = assemble;
this.start();
}
@Override
public void run() {
while(true) {
try {
tick();
sleep(assemble.getTicks() * 50);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Tick logic for thread.
*/
private void tick() {
for (Player player : this.assemble.getPlugin().getServer().getOnlinePlayers()) {
try {
AssembleBoard board = this.assemble.getBoards().get(player.getUniqueId());
// This shouldn't happen, but just in case.
if (board == null) {
continue;
}
Scoreboard scoreboard = board.getScoreboard();
Objective objective = board.getObjective();
if (scoreboard == null || objective == null) {
continue;
}
// Just make a variable so we don't have to
// process the same thing twice.
String title = ChatColor.translateAlternateColorCodes('&', this.assemble.getAdapter().getTitle(player));
// Update the title if needed.
if (!objective.getDisplayName().equals(title)) {
objective.setDisplayName(title);
}
List<String> newLines = this.assemble.getAdapter().getLines(player);
// Allow adapter to return null/empty list to display nothing.
if (newLines == null || newLines.isEmpty()) {
board.getEntries().forEach(AssembleBoardEntry::remove);
board.getEntries().clear();
} else {
if (newLines.size() > 15) {
newLines = this.assemble.getAdapter().getLines(player).subList(0, 15);
}
// Reverse the lines because scoreboard scores are in descending order.
if (!this.assemble.getAssembleStyle().isDescending()) {
Collections.reverse(newLines);
}
// Remove excessive amount of board entries.
if (board.getEntries().size() > newLines.size()) {
for (int i = newLines.size(); i < board.getEntries().size(); i++) {
AssembleBoardEntry entry = board.getEntryAtPosition(i);
if (entry != null) {
entry.remove();
}
}
}
// Update existing entries / add new entries.
int cache = this.assemble.getAssembleStyle().getStartNumber();
for (int i = 0; i < newLines.size(); i++) {
AssembleBoardEntry entry = board.getEntryAtPosition(i);
// Translate any colors.
String line = ChatColor.translateAlternateColorCodes('&', newLines.get(i));
// If the entry is null, just create a new one.
// Creating a new AssembleBoardEntry instance will add
// itself to the provided board's entries list.
if (entry == null) {
entry = new AssembleBoardEntry(board, line, i);
}
// Update text, setup the team, and update the display values.
entry.setText(line);
entry.setup();
entry.send(
this.assemble.getAssembleStyle().isDescending() ? cache-- : cache++
);
}
}
if (player.getScoreboard() != scoreboard && !assemble.isHook()) {
player.setScoreboard(scoreboard);
}
} catch(Exception e) {
e.printStackTrace();
throw new AssembleException("There was an error updating " + player.getName() + "'s scoreboard.");
}
}
}
}

View File

@ -1,31 +0,0 @@
package rip.tilly.bedwars.utils.assemble.events;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter @Setter
public class AssembleBoardCreateEvent extends Event implements Cancellable {
@Getter public static HandlerList handlerList = new HandlerList();
private Player player;
private boolean cancelled = false;
/**
* Assemble Board Create Event.
*
* @param player that the board is being created for.
*/
public AssembleBoardCreateEvent(Player player) {
this.player = player;
}
@Override
public HandlerList getHandlers() {
return handlerList;
}
}

View File

@ -1,30 +0,0 @@
package rip.tilly.bedwars.utils.assemble.events;
import rip.tilly.bedwars.utils.assemble.AssembleBoard;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter @Setter
public class AssembleBoardCreatedEvent extends Event {
@Getter public static HandlerList handlerList = new HandlerList();
private boolean cancelled = false;
private final AssembleBoard board;
/**
* Assemble Board Created Event.
*
* @param board of player.
*/
public AssembleBoardCreatedEvent(AssembleBoard board) {
this.board = board;
}
@Override
public HandlerList getHandlers() {
return handlerList;
}
}

View File

@ -1,31 +0,0 @@
package rip.tilly.bedwars.utils.assemble.events;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter @Setter
public class AssembleBoardDestroyEvent extends Event implements Cancellable {
@Getter public static HandlerList handlerList = new HandlerList();
private Player player;
private boolean cancelled = false;
/**
* Assemble Board Destroy Event.
*
* @param player who's board got destroyed.
*/
public AssembleBoardDestroyEvent(Player player) {
this.player = player;
}
@Override
public HandlerList getHandlers() {
return handlerList;
}
}