Skip to content

Commit

Permalink
SidebarLib implementation and 1.19.3 support (andrei1058#617)
Browse files Browse the repository at this point in the history
implement sidebar lib, add 1.19.3 support
  • Loading branch information
andrei1058 authored Dec 20, 2022
1 parent b1e7634 commit e864bef
Show file tree
Hide file tree
Showing 54 changed files with 2,388 additions and 968 deletions.
16 changes: 15 additions & 1 deletion bedwars-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>22.3-SNAPSHOT</version>
<version>22.9-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bedwars-api</artifactId>
Expand Down Expand Up @@ -36,6 +36,12 @@
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -51,6 +57,14 @@
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Language extends ConfigManager {
private static final HashMap<UUID, Language> langByPlayer = new HashMap<>();
private static final List<Language> languages = new ArrayList<>();
private static Language defaultLanguage;
private String serverIp;

public Language(Plugin plugin, String iso) {
super(plugin, "messages_" + iso, plugin.getDataFolder().getPath() + "/Languages");
Expand Down Expand Up @@ -136,7 +137,17 @@ public String m(String path) {
System.err.println("Missing message key " + path + " in language " + getIso());
message = "MISSING_LANG";
}
return ChatColor.translateAlternateColorCodes('&', message.replace("{prefix}", prefix));
if (null == serverIp) {
BedWars api = Bukkit.getServicesManager().getRegistration(BedWars.class).getProvider();
if (null != api.getConfigs().getMainConfig()) {
serverIp = api.getConfigs().getMainConfig().
getString(ConfigPath.GENERAL_CONFIG_PLACEHOLDERS_REPLACEMENTS_SERVER_IP);
}
}

return ChatColor.translateAlternateColorCodes('&', message.replace("{prefix}", (prefix == null? "":prefix))
.replace("{serverIp}", serverIp == null ? "" : serverIp)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.andrei1058.bedwars.api.configuration.ConfigPath;

@SuppressWarnings("WeakerAccess")
@Deprecated
public class Messages {

public static String PREFIX = "prefix";
Expand Down Expand Up @@ -169,10 +170,32 @@ public class Messages {
public static String FORMATTING_SCOREBOARD_TAB_SUFFIX_STARTING = "format-sb-tab-suffix.starting";
public static String FORMATTING_SCOREBOARD_TAB_PREFIX_PLAYING = "format-sb-tab-prefix.playing";
public static String FORMATTING_SCOREBOARD_TAB_SUFFIX_PLAYING = "format-sb-tab-suffix.playing";

public static String FORMATTING_SIDEBAR_TAB_HEADER_LOBBY = "format-sb-tab-header.lobby";
public static String FORMATTING_SIDEBAR_TAB_HEADER_WAITING = "format-sb-tab-header.waiting";
public static String FORMATTING_SIDEBAR_TAB_HEADER_STARTING = "format-sb-tab-header.starting";
public static String FORMATTING_SIDEBAR_TAB_HEADER_PLAYING = "format-sb-tab-header.playing";
public static String FORMATTING_SIDEBAR_TAB_HEADER_RESTARTING = "format-sb-tab-header.restarting";
public static String FORMATTING_SIDEBAR_TAB_HEADER_SPECTATOR = "format-sb-tab-header.spectator";

public static String FORMATTING_SIDEBAR_TAB_FOOTER_LOBBY = "format-sb-tab-footer.lobby";
public static String FORMATTING_SIDEBAR_TAB_FOOTER_WAITING = "format-sb-tab-footer.waiting";
public static String FORMATTING_SIDEBAR_TAB_FOOTER_STARTING = "format-sb-tab-footer.starting";
public static String FORMATTING_SIDEBAR_TAB_FOOTER_PLAYING = "format-sb-tab-footer.playing";
public static String FORMATTING_SIDEBAR_TAB_FOOTER_RESTARTING = "format-sb-tab-footer.restarting";
public static String FORMATTING_SIDEBAR_TAB_FOOTER_SPECTATOR = "format-sb-tab-footer.spectator";
@Deprecated
public static String FORMATTING_SCOREBOARD_TAB_PREFIX_PRESTARTING = "format-sb-tab-prefix.restarting";
public static String FORMATTING_SCOREBOARD_TAB_PREFIX_RESTARTING = "format-sb-tab-prefix.restarting";
@Deprecated
public static String FORMATTING_SCOREBOARD_TAB_SUFFIX_PRESTARTING = "format-sb-tab-suffix.restarting";
public static String FORMATTING_SCOREBOARD_TAB_SUFFIX_RESTARTING = "format-sb-tab-suffix.restarting";
public static String FORMATTING_SCOREBOARD_TAB_PREFIX_SPECTATOR = "format-sb-tab-prefix.spectator";
public static String FORMATTING_SCOREBOARD_TAB_SUFFIX_SPECTATOR = "format-sb-tab-suffix.spectator";
public static String FORMATTING_SPECTATOR_TEAM = "format-spectator-team";
@Deprecated
public static String FORMATTING_SPECTATOR_COLOR = "format-spectator-color";

public static String FORMATTING_SCOREBOARD_TEAM_ELIMINATED = "format-sb-team-eliminated";
public static String FORMATTING_SCOREBOARD_BED_DESTROYED = "format-sb-bed-destroyed";
public static String FORMATTING_SCOREBOARD_TEAM_ALIVE = "format-sb-team-alive";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
public abstract class VersionSupport {

private static String name2;
public static String PLUGIN_TAG_GENERIC_KEY = "BedWars1058";
public static String PLUGIN_TAG_TIER_KEY = "tierIdentifier";

private Effect eggBridge;

Expand Down
55 changes: 50 additions & 5 deletions bedwars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>22.3-SNAPSHOT</version>
<version>22.9-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bedwars-plugin</artifactId>
Expand Down Expand Up @@ -60,7 +60,11 @@
</repository>
<repository>
<id>andrei1058-releases</id>
<url>https://repo.andrei1058.com/releases/</url>
<url>https://repo.andrei1058.dev/releases/</url>
</repository>
<repository>
<id>citizens-repo</id>
<url>https://maven.citizensnpcs.co/repo</url>
</repository>
</repositories>

Expand Down Expand Up @@ -155,7 +159,12 @@
</dependency>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>versionsupport_v1_18_R1</artifactId>
<artifactId>versionsupport_v1_18_R2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>versionsupport_v1_19_R2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -212,8 +221,44 @@
<!-- Sidebar LIB-->
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-api</artifactId>
<version>0.3.2-SNAPSHOT</version>
<artifactId>sidebar-base</artifactId>
<version>22.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-eight</artifactId>
<version>22.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-twelve</artifactId>
<version>22.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-sixteen</artifactId>
<version>22.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-seventeen</artifactId>
<version>22.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-eighteen</artifactId>
<version>22.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-nineteen</artifactId>
<version>22.12</version>
<scope>compile</scope>
</dependency>
<!-- End of Sidebar LIB-->
Expand Down
16 changes: 5 additions & 11 deletions bedwars-plugin/src/main/java/com/andrei1058/bedwars/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
import com.andrei1058.bedwars.arena.SetupSession;
import com.andrei1058.bedwars.commands.bedwars.MainCommand;
import com.andrei1058.bedwars.shop.main.CategoryContent;
import com.andrei1058.bedwars.sidebar.BedWarsScoreboard;
import com.andrei1058.bedwars.sidebar.SidebarService;
import com.andrei1058.bedwars.stats.StatsAPI;
import com.andrei1058.bedwars.upgrades.UpgradesManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.HashMap;
Expand Down Expand Up @@ -416,19 +417,12 @@ public File getAddonsPath() {

@Override
public void removePlayerScoreboard(Player player) {
BedWarsScoreboard scoreboard = BedWarsScoreboard.getSBoard(player.getUniqueId());
if (null != scoreboard){
scoreboard.remove();
}
SidebarService.getInstance().remove(player);
}

@Override
public void givePlayerScoreboard(Player player, boolean delay) {
BedWarsScoreboard scoreboard = BedWarsScoreboard.getSBoard(player.getUniqueId());
if (null == scoreboard){
IArena arena = Arena.getArenaByPlayer(player);
BedWarsScoreboard.giveScoreboard(player, arena, delay);
}
public void givePlayerScoreboard(@NotNull Player player, boolean delay) {
SidebarService.getInstance().giveSidebar(player, Arena.getArenaByPlayer(player), delay);
}
};

Expand Down
21 changes: 17 additions & 4 deletions bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
import com.andrei1058.bedwars.money.internal.MoneyListeners;
import com.andrei1058.bedwars.shop.ShopManager;
import com.andrei1058.bedwars.sidebar.*;
import com.andrei1058.bedwars.sidebar.thread.RefreshTitleTask;
import com.andrei1058.bedwars.sidebar.thread.RefreshPlaceholdersTask;
import com.andrei1058.bedwars.sidebar.thread.RefreshLifeTask;
import com.andrei1058.bedwars.sidebar.thread.RefreshTabListTask;
import com.andrei1058.bedwars.stats.StatsManager;
import com.andrei1058.bedwars.support.citizens.CitizensListener;
import com.andrei1058.bedwars.support.citizens.JoinNPC;
Expand Down Expand Up @@ -538,6 +542,15 @@ public void onEnable() {
// Initialize team upgrades
com.andrei1058.bedwars.upgrades.UpgradesManager.init();

// Initialize sidebar manager
if (SidebarService.init()) {
this.getLogger().info("Initializing SidebarLib by andrei1058");
} else {
this.getLogger().severe("SidebarLib by andrei1058 does not support your server version");
Bukkit.getPluginManager().disablePlugin(this);
return;
}

int playerListRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_LIST_REFRESH);
if (playerListRefreshInterval < 1) {
Bukkit.getLogger().info("Scoreboard names list refresh is disabled. (Is set to " + playerListRefreshInterval + ").");
Expand All @@ -547,7 +560,7 @@ public void onEnable() {
Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks.");
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().runTaskTimer(this, new SidebarListRefresh(), 23L, playerListRefreshInterval);
Bukkit.getScheduler().runTaskTimer(this, new RefreshTabListTask(), 23L, playerListRefreshInterval);
}

int placeholdersRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_PLACEHOLDERS_REFRESH_INTERVAL);
Expand All @@ -559,7 +572,7 @@ public void onEnable() {
Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks.");
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().runTaskTimer(this, new SidebarPlaceholderRefresh(), 28L, placeholdersRefreshInterval);
Bukkit.getScheduler().runTaskTimer(this, new RefreshPlaceholdersTask(), 28L, placeholdersRefreshInterval);
}

int titleRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_TITLE_REFRESH_INTERVAL);
Expand All @@ -570,7 +583,7 @@ public void onEnable() {
Bukkit.getLogger().warning("Scoreboard title refresh interval is set to: " + titleRefreshInterval);
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new SidebarTitleRefresh(), 32L, titleRefreshInterval);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new RefreshTitleTask(), 32L, titleRefreshInterval);
}

int healthAnimationInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_HEALTH_REFRESH);
Expand All @@ -582,7 +595,7 @@ public void onEnable() {
Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks.");
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new SidebarLifeRefresh(), 40L, healthAnimationInterval);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshLifeTask(), 40L, healthAnimationInterval);
}

registerEvents(new ScoreboardListener());
Expand Down
Loading

0 comments on commit e864bef

Please sign in to comment.