Skip to content

Commit

Permalink
Paper API migration
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperdefined committed Dec 16, 2024
1 parent ef8984e commit 45253cc
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ name = "java"
enabled = true

[analyzers.meta]
runtime_version = "8"
runtime_version = "21"
25 changes: 25 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Build with Maven

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Build with Maven
run: mvn -B package --file pom.xml
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<h1 align="center">TimeBar</h1>

<p align="center">
<img src="https://img.shields.io/badge/Minecraft-1.19--1.20.6-orange" alt="Minecraft versions">
<img src="https://img.shields.io/badge/Minecraft-1.21--1.21.4-orange" alt="Minecraft versions">
<img src="https://img.shields.io/github/v/release/hyperdefined/TimeBar" alt="GitHub release (latest by date)">
<a href="https://github.com/hyperdefined/TimeBar/releases"><img src="https://img.shields.io/github/downloads/hyperdefined/TimeBar/total?logo=github" alt="Downloads"></a>
<a href="https://ko-fi.com/hyperdefined"><img src="https://img.shields.io/badge/Donate-Ko--fi-red" alt="Donate via Ko-fi"></a>
<img alt="Discord" src="https://img.shields.io/discord/1267600843356639413?style=flat&logo=discord&label=Discord">
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
</p>

Expand Down
30 changes: 8 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<name>TimeBar</name>

<properties>
<java.version>17</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -67,10 +67,6 @@
<pattern>org.bstats</pattern>
<shadedPattern>lol.hyper.timebar.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>lol.hyper.timebar.adventure</shadedPattern>
</relocation>
<relocation>
<pattern>lol.hyper.githubreleaseapi</pattern>
<shadedPattern>lol.hyper.timebar.updater</shadedPattern>
Expand All @@ -97,8 +93,8 @@

<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>placeholderapi</id>
Expand All @@ -108,9 +104,9 @@

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.4-R0.1-SNAPSHOT</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -125,22 +121,12 @@
<version>1.0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.17.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.4</version>
</dependency>
<dependency>
<groupId>me.casperge.realisticseasons</groupId>
<artifactId>RealisticSeasons</artifactId>
<version>10.5.1</version>
<version>11.5.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/RealisticSeasons-10.5.1.jar</systemPath>
<systemPath>${project.basedir}/RealisticSeasons-11.5.2.jar</systemPath>
</dependency>
<dependency>
<groupId>net.advancedplugins</groupId>
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/lol/hyper/timebar/TimeBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import lol.hyper.timebar.papi.TimeBarExpansion;
import lol.hyper.timebar.tracker.WorldTimeTracker;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -54,7 +53,6 @@ public final class TimeBar extends JavaPlugin {
public final List<WorldTimeTracker> worldTimeTrackers = new ArrayList<>();

public final MiniMessage miniMessage = MiniMessage.miniMessage();
private BukkitAudiences adventure;

public PlayerJoinLeave playerJoinLeave;
public WorldChange worldChange;
Expand All @@ -67,8 +65,6 @@ public final class TimeBar extends JavaPlugin {

@Override
public void onEnable() {
adventure = BukkitAudiences.create(this);

if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
papiSupport = true;
logger.info("PlaceholderAPI is detected! Enabling support.");
Expand Down Expand Up @@ -200,7 +196,7 @@ public void checkForUpdates() {
e.printStackTrace();
return;
}
GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion());
GitHubRelease current = api.getReleaseByTag(this.getPluginMeta().getVersion());
GitHubRelease latest = api.getLatestVersion();
if (current == null) {
logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!");
Expand All @@ -214,13 +210,6 @@ public void checkForUpdates() {
}
}

public BukkitAudiences getAdventure() {
if (this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}
return this.adventure;
}

public WorldTimeTracker getPlayerTracker(Player player) {
return worldTimeTrackers.stream().filter(worldTimeTracker -> worldTimeTracker.worldGroup().contains(player.getWorld())).findFirst().orElse(null);
}
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/lol/hyper/timebar/commands/CommandTimeBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import lol.hyper.timebar.TimeBar;
import lol.hyper.timebar.tracker.WorldTimeTracker;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
Expand All @@ -36,23 +35,21 @@

public class CommandTimeBar implements TabExecutor {

private final TimeBar timeBar;
private final BukkitAudiences audiences;
private final TimeBar timeBar;;

public CommandTimeBar(TimeBar timeBar) {
this.timeBar = timeBar;
this.audiences = timeBar.getAdventure();
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 0) {
audiences.sender(sender).sendMessage(Component.text("TimeBar version " + timeBar.getDescription().getVersion() + ". Created by hyperdefined.", NamedTextColor.GREEN));
sender.sendMessage(Component.text("TimeBar version " + timeBar.getDescription().getVersion() + ". Created by hyperdefined.", NamedTextColor.GREEN));
return true;
}

if (!sender.hasPermission("timebar.command")) {
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
return true;
}

Expand All @@ -74,23 +71,23 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
for (WorldTimeTracker worldTimeTracker : timeBar.worldTimeTrackers) {
worldTimeTracker.startTimer();
}
audiences.sender(sender).sendMessage(Component.text("Configuration reloaded!", NamedTextColor.GREEN));
sender.sendMessage(Component.text("Configuration reloaded!", NamedTextColor.GREEN));
} else {
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
}
return true;
}
case "on" -> {
if (sender instanceof ConsoleCommandSender) {
audiences.sender(sender).sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
return true;
}
if (!sender.hasPermission("timebar.enable")) {
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
return true;
}
if (timeBar.config.getBoolean("hold-clock-to-show")) {
audiences.sender(sender).sendMessage(Component.text("You must be holding a clock to show/hide the TimeBar.", NamedTextColor.RED));
sender.sendMessage(Component.text("You must be holding a clock to show/hide the TimeBar.", NamedTextColor.RED));
return true;
}
Player player = (Player) sender;
Expand All @@ -104,20 +101,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
} else {
timeBar.enabledBossBar.add(player);
}
audiences.player(player).sendMessage(Component.text("TimeBar is now enabled.", NamedTextColor.GREEN));
player.sendMessage(Component.text("TimeBar is now enabled.", NamedTextColor.GREEN));
return true;
}
case "off" -> {
if (sender instanceof ConsoleCommandSender) {
audiences.sender(sender).sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
return true;
}
if (!sender.hasPermission("timebar.disable")) {
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
return true;
}
if (timeBar.config.getBoolean("hold-clock-to-show")) {
audiences.sender(sender).sendMessage(Component.text("You must be holding a clock to show/hide the TimeBar.", NamedTextColor.RED));
sender.sendMessage(Component.text("You must be holding a clock to show/hide the TimeBar.", NamedTextColor.RED));
return true;
}
Player player = (Player) sender;
Expand All @@ -131,10 +128,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
} else {
timeBar.enabledBossBar.remove(player);
}
audiences.player(player).sendMessage(Component.text("TimeBar is now disabled.", NamedTextColor.GREEN));
player.sendMessage(Component.text("TimeBar is now disabled.", NamedTextColor.GREEN));
return true;
}
default -> audiences.sender(sender).sendMessage(Component.text("Invalid sub-command. Valid options are: reload, on, off.", NamedTextColor.RED));
default -> sender.sendMessage(Component.text("Invalid sub-command. Valid options are: reload, on, off.", NamedTextColor.RED));
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/lol/hyper/timebar/papi/TimeBarExpansion.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public TimeBarExpansion(TimeBar timeBar) {

@Override
public @NotNull String getAuthor() {
return String.join(", ", timeBar.getDescription().getAuthors());
return String.join(", ", timeBar.getPluginMeta().getAuthors());
}

@Override
public @NotNull String getVersion() {
return timeBar.getDescription().getVersion();
return timeBar.getPluginMeta().getVersion();
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/lol/hyper/timebar/tracker/WorldTimeTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import lol.hyper.timebar.utils.NumberFormat;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
Expand Down Expand Up @@ -86,7 +85,7 @@ public void addPlayer(Player player) {
if (worldGroup.contains(player.getWorld())) {
// if they have it enabled
if (timeBar.enabledBossBar.contains(player)) {
timeBar.getAdventure().player(player).showBossBar(bossBar);
player.showBossBar(bossBar);
}
}
}
Expand All @@ -98,7 +97,7 @@ public void addPlayer(Player player) {
*/
public void removePlayer(Player player) {
BossBar bossBar = bossBars.get(player);
timeBar.getAdventure().player(player).hideBossBar(bossBar);
player.hideBossBar(bossBar);
bossBars.remove(player);
}

Expand Down Expand Up @@ -145,7 +144,7 @@ public void hideBossBars() {
continue;
}
BossBar bossBar = entry.getValue();
timeBar.getAdventure().player(player).hideBossBar(bossBar);
player.hideBossBar(bossBar);
}
}

Expand All @@ -156,7 +155,7 @@ public void hideBossBars() {
*/
public void hidePlayer(Player player) {
BossBar bossBar = bossBars.get(player);
timeBar.getAdventure().player(player).hideBossBar(bossBar);
player.hideBossBar(bossBar);
if (!timeBar.config.getBoolean("hold-clock-to-show")) {
timeBar.enabledBossBar.remove(player);
}
Expand All @@ -172,7 +171,7 @@ public void showPlayer(Player player) {
// they are in a display world, show them timebar
if (worldGroup.contains(player.getWorld())) {
BossBar bossBar = bossBars.get(player);
timeBar.getAdventure().player(player).showBossBar(bossBar);
player.showBossBar(bossBar);
}
if (!timeBar.config.getBoolean("hold-clock-to-show")) {
timeBar.enabledBossBar.add(player);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: TimeBar
version: ${project.version}
main: lol.hyper.timebar.TimeBar
api-version: 1.19
api-version: 1.21
author: hyperdefined
website: https://www.spigotmc.org/resources/timebar.90179/
website: https://github.com/hyperdefined/TimeBar
description: See the world's time as a bossbar.
softdepend: [Multiverse-Core, RealisticSeasons, AdvancedSeasons, PlaceholderAPI]
load: POSTWORLD
Expand Down

0 comments on commit 45253cc

Please sign in to comment.