Skip to content

Commit

Permalink
Rank API stuff added
Browse files Browse the repository at this point in the history
Added Rank API event but not fully finished yet - I need some way to
either execute the event asynchronously or to wait for the sync task so
the scoreboard %player_rank% placeholder will be replaced.

Also did some other changes and improvements.
  • Loading branch information
Xitee committed Jul 20, 2022
1 parent 94e3fb0 commit 050d95b
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 137 deletions.
104 changes: 71 additions & 33 deletions src/de/xite/scoreboard/api/TeamSetEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ public class TeamSetEvent extends Event implements Cancellable{
private ChatColor nameColor;
private String chatPrefix;
private String rankDisplayName;
private int weight;
private String playerListName;
private int weight = 0;

public TeamSetEvent(Player p) {
this.p = p;
this.prefix = "";
this.suffix = "";
this.nameColor = ChatColor.WHITE;
this.chatPrefix = "";
this.rankDisplayName = "";
this.weight = 0;
}

@Override
Expand All @@ -53,40 +48,80 @@ public Player getPlayer() {
return this.p;
}
public String getPrefix() {
Teams t = Teams.get(p);
if(t != null && this.prefix.length() == 0)
this.prefix = t.getPrefix();
return this.prefix;
if(prefix == null) {
Teams t = Teams.get(p);
if(t != null) {
prefix = t.getPrefix();
}else
prefix = "Not defined";
}

return prefix;
}
public String getSuffix() {
Teams t = Teams.get(p);
if(t != null && this.suffix.length() == 0)
this.suffix = t.getSuffix();
return this.suffix;
}
public ChatColor getNameColorChar() {
Teams t = Teams.get(p);
if(t != null && this.nameColor == ChatColor.WHITE)
this.nameColor = t.getNameColor();
return this.nameColor;
if(suffix == null) {
Teams t = Teams.get(p);
if(t != null) {
suffix = t.getSuffix();
}else
suffix = "Not defined";
}

return suffix;
}
public ChatColor getNameColor() {
if(nameColor == null) {
Teams t = Teams.get(p);
if(t != null) {
nameColor = t.getNameColor();
}else
nameColor = ChatColor.WHITE;
}

return nameColor;
}
public String getChatPrefix() {
Teams t = Teams.get(p);
if(t != null && this.chatPrefix.length() == 0)
this.chatPrefix = t.getChatPrefix();
return this.chatPrefix;
if(chatPrefix == null) {
Teams t = Teams.get(p);
if(t != null) {
chatPrefix = t.getChatPrefix();
}else
chatPrefix = "Not defined";
}

return chatPrefix;
}
public String getRankDisplayName() {
Teams t = Teams.get(p);
if(t != null && this.rankDisplayName.length() == 0)
this.rankDisplayName = t.getRankDisplayName();
return this.rankDisplayName;
if(rankDisplayName == null) {
Teams t = Teams.get(p);
if(t != null) {
rankDisplayName = t.getRankDisplayName();
}else
rankDisplayName = "Not defined";
}

return rankDisplayName;
}
public String getPlayerListName() {
if(playerListName == null) {
Teams t = Teams.get(p);
if(t != null)
playerListName = t.getPlayerListName();
// Not setting to "Not defined" because it can be null and is optional
}

return playerListName;
}
public Integer getWeight() {
Teams t = Teams.get(p);
if(t != null && this.weight == 0)
this.weight = t.getWeight();
return this.weight;
if(weight == 0) {
Teams t = Teams.get(p);
if(t != null) {
weight = t.getWeight();
}else
weight = 0;
}

return weight;
}

public void setPrefix(String prefix) {
Expand All @@ -104,6 +139,9 @@ public void setChatPrefix(String chatPrefix) {
public void setRankDisplayName(String rankDisplayName) {
this.rankDisplayName = rankDisplayName;
}
public void setPlayerListName(String playerListName) {
this.playerListName = playerListName;
}
public void setWeight(int weight) {
this.weight = weight;
}
Expand Down
2 changes: 1 addition & 1 deletion src/de/xite/scoreboard/depend/LuckPermsRanks.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static boolean registerLuckPermsAPIRank(Player p) {

// Register the player with all the collected data
try {
Teams.addPlayer(p, prefix, suffix, nameColor, chat, displayname, weight);
Teams.addPlayer(p, prefix, suffix, nameColor, chat, displayname, null, weight);
return true;
}catch (Exception e) {
// If somehow something does no work, send a error message to configure the rank properly.
Expand Down
2 changes: 1 addition & 1 deletion src/de/xite/scoreboard/depend/VaultAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class VaultAPI {
public static boolean setupEconomy() {
RegisteredServiceProvider<Economy> rsp = pl.getServer().getServicesManager().getRegistration(Economy.class);
if(rsp == null) {
pl.getLogger().warning("Error hooking into Vault-Economy! <- Ignore if you don't have a economy plugin installed on your server, otherwise check, if your money system supports Vault.");
pl.getLogger().warning("Error hooking into Vault-Economy! <- Ignore if you don't need PB's %player_money% placeholder, otherwise check, if your money system supports Vault.");
return false;
}
econ = rsp.getProvider();
Expand Down
19 changes: 17 additions & 2 deletions src/de/xite/scoreboard/listeners/ConditionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;

import de.xite.scoreboard.api.TeamSetEvent;
import de.xite.scoreboard.main.PowerBoard;
import de.xite.scoreboard.modules.board.ScoreboardPlayer;
import de.xite.scoreboard.modules.ranks.RankManager;
Expand Down Expand Up @@ -43,8 +45,21 @@ public void run() {
}
});
}


/*
@EventHandler
public void onRankEvent(TeamSetEvent e) {
Player p = e.getPlayer();
if(p.getName().equals("Xitecraft")) {
e.setChatPrefix("Chat Prefix : ");
e.setNameColor(ChatColor.BLUE);
e.setPrefix(ChatColor.RED+"[OWNER]");
e.setSuffix(ChatColor.AQUA+"[SUFFIX]");
e.setRankDisplayName("Owner's Displayname");
e.setPlayerListName("HEY");
e.setWeight(999);
}
}
*/
public static boolean checkConditions(Player p, List<String> conditions) {
for(String condition : conditions) { // For all "OR" conditions (lines)
ArrayList<String> andConditions = new ArrayList<>();
Expand Down
9 changes: 2 additions & 7 deletions src/de/xite/scoreboard/listeners/JoinQuitListener.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.xite.scoreboard.listeners;

import java.util.ArrayList;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
Expand All @@ -10,7 +8,6 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import de.xite.scoreboard.api.PowerBoardAPI;
import de.xite.scoreboard.main.PowerBoard;
import de.xite.scoreboard.modules.board.ScoreboardPlayer;
import de.xite.scoreboard.modules.ranks.RankManager;
Expand Down Expand Up @@ -43,7 +40,8 @@ public void run() {
// Set a new scoreboard for the player to prevent bugs
if(pl.getConfig().getBoolean("tablist.ranks") || pl.getConfig().getBoolean("scoreboard"))
p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
Bukkit.getScheduler().runTaskLater(pl, new Runnable() {

Bukkit.getScheduler().runTaskLaterAsynchronously(pl, new Runnable() {
@Override
public void run() {
// Register Teams if chat ranks or tablist ranks are used
Expand All @@ -54,9 +52,6 @@ public void run() {
if(pl.getConfig().getBoolean("scoreboard"))
ScoreboardPlayer.setScoreboard(p, false, null);

if(pl.getConfig().getBoolean("tablist.ranks"))
RankManager.setTablistRanks(p);

if(pl.getConfig().getBoolean("tablist.text"))
TablistPlayer.addPlayer(p, null);

Expand Down
24 changes: 16 additions & 8 deletions src/de/xite/scoreboard/main/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,15 @@ public void run() {
}
}, 40);
// General config
s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"config"+ChatColor.GRAY+"...");
sendConfigReloadMessage(s, ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"config"+ChatColor.GRAY+"...");
Config.loadConfig();

// Load all external plugin APIs
sendConfigReloadMessage(s, ChatColor.YELLOW+"Initializing external plugins"+ChatColor.GRAY+"...");
ExternalPlugins.initializePlugins();

// Scoreboards
s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"scoreboards"+ChatColor.GRAY+"...");
sendConfigReloadMessage(s, ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"scoreboards"+ChatColor.GRAY+"...");
ArrayList<Player> players = new ArrayList<Player>();
players.addAll(ScoreboardPlayer.players.keySet());
for(Player p : players)
Expand All @@ -422,25 +426,29 @@ public void run() {
}

// Ranks
boolean tabRanks = pl.getConfig().getBoolean("tablist.ranks");
if(tabRanks || PowerBoard.pl.getConfig().getBoolean("chat.ranks")) {
if(pl.getConfig().getBoolean("tablist.ranks") || PowerBoard.pl.getConfig().getBoolean("chat.ranks")) {
sendConfigReloadMessage(s, ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"ranks"+ChatColor.GRAY+"...");
for(Player all : Bukkit.getOnlinePlayers()) {
Teams.removePlayer(all);
RankManager.register(all);
if(tabRanks)
RankManager.setTablistRanks(all);
}
}

if(PowerBoard.pl.getConfig().getBoolean("tablist.text")) {
s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"tablist"+ChatColor.GRAY+"...");
sendConfigReloadMessage(s, ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"tablists"+ChatColor.GRAY+"...");
TablistManager.unregisterAllTablists();
TablistManager.registerAllTablists();
for(Player all : Bukkit.getOnlinePlayers())
TablistPlayer.addPlayer(all, null);
}
s.sendMessage(PowerBoard.pr+ChatColor.GREEN+"Plugin reloaded!");

sendConfigReloadMessage(s, ChatColor.GREEN+"Plugin reloaded!");
}
});
}
private static void sendConfigReloadMessage(CommandSender s, String message) {
if(s instanceof Player)
s.sendMessage(PowerBoard.pr+"Config Reload: "+message);
pl.getLogger().info("Config Reload: "+message);
}
}
12 changes: 8 additions & 4 deletions src/de/xite/scoreboard/main/ExternalPlugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ public static void initializePlugins() {

if(Bukkit.getPluginManager().isPluginEnabled("LuckPerms")) {
hasLuckPerms = true;
RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
if(provider != null)
luckPerms = provider.getProvider();
new LuckPermsListener(pl, luckPerms);
if(pl.getConfig().getBoolean("ranks.luckperms-api.enable") || pl.getConfig().getString("ranks.permissionsystem").equalsIgnoreCase("luckperms")) {
RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
if(provider != null)
luckPerms = provider.getProvider();
new LuckPermsListener(pl, luckPerms);
}else
if(luckPerms != null)
pl.getLogger().warning("You have changed the rank permissions system from LuckPerms to something different. LuckPerms cannot be completely disabled whith a PB reload. Please restart your server soon.");
}
// BStats analytics
try {
Expand Down
5 changes: 2 additions & 3 deletions src/de/xite/scoreboard/main/PowerBoard.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.xite.scoreboard.main;

import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -105,10 +104,10 @@ public void run() {
Teams teams = Teams.get(all);
if(teams == null)
RankManager.register(all);
RankManager.startTablistRanksUpdateScheduler();

}
if(pl.getConfig().getBoolean("tablist.ranks"))
RankManager.setTablistRanks(all);
RankManager.startTablistRanksUpdateScheduler();

if(pl.getConfig().getBoolean("scoreboard"))
ScoreboardPlayer.setScoreboard(all, false, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public boolean accept(File f, String name) {
}
for(String board : boards) {
ScoreboardManager.get(board);
pl.getLogger().info("Registered scoreboard "+board+".");
pl.getLogger().info("Registered scoreboard '"+board+"'.");
}
}
public static void unregisterAllScoreboards() {
Expand Down
2 changes: 1 addition & 1 deletion src/de/xite/scoreboard/modules/board/ScoreboardPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void setScoreboard(Player p, boolean API, ScoreboardManager sm) {
}
obj.setDisplaySlot(DisplaySlot.SIDEBAR);

p.setScoreboard(board); // Set the scoreboard
//p.setScoreboard(board); // Set the scoreboard

// Set the scores if the API isn't used
if(!API) {
Expand Down
Loading

0 comments on commit 050d95b

Please sign in to comment.