Skip to content

Commit

Permalink
use TAB-BukkitBridge for registering TAB placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Nov 12, 2024
1 parent 4cc82fa commit 50f311b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
11 changes: 7 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "net.azisaba"
version = "1.3.0"
version = "2.0.0+1.15.2"

repositories {
mavenCentral()
Expand All @@ -14,7 +14,6 @@ repositories {
maven { url = uri("https://jitpack.io/") } // Statz
maven { url = uri("https://mvn.lumine.io/repository/maven-public/") } // for MythicMobs
maven { url = uri("https://nexus.neetgames.com/repository/maven-public/") } // for mcMMO
maven { url = uri("https://repo.kryptonmc.org/releases/") } // for TAB
maven { url = uri("https://repo.azisaba.net/repository/maven-public/") } // LoreEditor, ItemStash
if (properties["azisabaNmsUsername"] != null && properties["azisabaNmsPassword"] != null) {
maven {
Expand All @@ -29,8 +28,8 @@ repositories {
dependencies {
implementation("com.zaxxer:HikariCP:4.0.3")
implementation("org.mariadb.jdbc:mariadb-java-client:3.0.6")
compileOnly("net.azisaba:TAB-BukkitBridge:3.0.0")
compileOnly("org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT")
compileOnly("me.neznamy:tab-api:3.0.2")
compileOnly("org.jetbrains:annotations:23.0.0")
compileOnly("io.lumine:Mythic-Dist:4.13.0")
compileOnly("net.azisaba.loreeditor:api:1.0.0-SNAPSHOT:all")
Expand All @@ -40,8 +39,12 @@ dependencies {
compileOnly("com.github.Staartvin:Statz:v1.5.5") {
exclude("nl.lolmewn.stats", "Stats")
exclude("me.staartvin", "PluginLibrary")
exclude("org.bukkit", "bukkit")
}
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.196") {
exclude("com.sk89q.worldguard", "worldguard-core")
exclude("com.sk89q.worldguard", "worldguard-legacy")
}
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.196")
}

java {
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/net/azisaba/lifepvelevel/SpigotPlugin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.azisaba.lifepvelevel;

import me.neznamy.tab.api.TabAPI;
import me.neznamy.tab.api.event.plugin.TabLoadEvent;
import net.azisaba.lifepvelevel.commands.*;
import net.azisaba.lifepvelevel.listener.MythicMobDeathListener;
import net.azisaba.lifepvelevel.listener.PlayerListener;
Expand All @@ -17,6 +15,8 @@
import net.azisaba.loreeditor.libs.net.kyori.adventure.text.Component;
import net.azisaba.loreeditor.libs.net.kyori.adventure.text.format.TextDecoration;
import net.azisaba.loreeditor.libs.net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.azisaba.tabbukkitbridge.data.DataKey;
import net.azisaba.tabbukkitbridge.tab.TheTAB;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

public final class SpigotPlugin extends JavaPlugin {
private static final DecimalFormat FORMATTER_COMMAS = new DecimalFormat("#,###");
Expand Down Expand Up @@ -102,7 +103,7 @@ public void onEnable() {
});

registerPlaceholders();
TabAPI.getInstance().getEventBus().register(TabLoadEvent.class, e -> registerPlaceholders());
TheTAB.enable();
}

private static @Nullable String getRequiredLevelText(@NotNull Player player, @NotNull ItemStack item) {
Expand Down Expand Up @@ -136,20 +137,26 @@ public void onEnable() {
return Messages.getFormattedText(player, "item.lore.required_level", "" + color + requiredLevel);
}

private static <T> void registerPlayerPlaceholder(@NotNull T defaultValue, @NotNull String placeholder, @NotNull Function<Player, T> valueSupplier) {
DataKey<Player, T> dataKey = new DataKey<>(defaultValue);
dataKey.getPlaceholders().add(placeholder);
dataKey.register(p -> true, valueSupplier);
}

private static void registerPlaceholders() {
TabAPI.getInstance().getPlaceholderManager().registerPlayerPlaceholder(
"%pvelevel_level%",
50 * 20, // milliseconds
registerPlayerPlaceholder(
"0",
"pvelevel_level",
p -> FORMATTER_COMMAS.format(LevelCalculator.toLevel(DBConnector.getExp(p.getUniqueId())))
);
TabAPI.getInstance().getPlaceholderManager().registerPlayerPlaceholder(
"%pvelevel_exp%",
50 * 20, // milliseconds
registerPlayerPlaceholder(
"0",
"pvelevel_exp",
p -> FORMATTER_COMMAS.format(LevelCalculator.toLevel(DBConnector.getExp(p.getUniqueId())))
);
TabAPI.getInstance().getPlaceholderManager().registerPlayerPlaceholder(
"%pvelevel_exp_for_next_level%",
50 * 20, // milliseconds
registerPlayerPlaceholder(
"0",
"pvelevel_exp_for_next_level",
p -> {
long exp = DBConnector.getExp(p.getUniqueId());
return FORMATTER_COMMAS.format(LevelCalculator.toExp(LevelCalculator.toLevel(exp) + 1) - exp);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ permissions:
default: true
lifepvelevel.command.givepvelevelboostitem:
description: Allows the player to use /givepvelevelboostitem
default: op
default: false
lifepvelevel.bypass_level:
description: Allows the player to bypass the level requirement
default: false
Expand Down

0 comments on commit 50f311b

Please sign in to comment.