hyperlib demo

This commit is contained in:
hyperdefined
2025-08-04 13:29:26 -04:00
parent c0d79fd740
commit e48be6ba20
17 changed files with 61 additions and 184 deletions

24
pom.xml
View File

@@ -64,12 +64,8 @@
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>lol.hyper.toolstats.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>lol.hyper.githubreleaseapi</pattern>
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
<pattern>lol.hyper.hyperlib</pattern>
<shadedPattern>lol.hyper.toolstats.hyperlib</shadedPattern>
</relocation>
</relocations>
</configuration>
@@ -99,6 +95,10 @@
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
@@ -109,15 +109,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>lol.hyper</groupId>
<artifactId>github-release-api</artifactId>
<version>1.0.5</version>
<groupId>com.github.hyperdefined</groupId>
<artifactId>hyperlib</artifactId>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@@ -17,15 +17,17 @@
package lol.hyper.toolstats;
import lol.hyper.githubreleaseapi.GitHubRelease;
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
import lol.hyper.githubreleaseapi.ReleaseNotFoundException;
import lol.hyper.hyperlib.HyperLib;
import lol.hyper.hyperlib.bstats.bStats;
import lol.hyper.hyperlib.releases.hangar.HangarRelease;
import lol.hyper.hyperlib.releases.modrinth.ModrinthPlugin;
import lol.hyper.hyperlib.releases.modrinth.ModrinthRelease;
import lol.hyper.hyperlib.utils.TextUtils;
import lol.hyper.toolstats.commands.CommandToolStats;
import lol.hyper.toolstats.events.*;
import lol.hyper.toolstats.tools.*;
import lol.hyper.toolstats.tools.config.ConfigTools;
import lol.hyper.toolstats.tools.config.ConfigUpdater;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -33,7 +35,6 @@ import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
@@ -152,9 +153,19 @@ public final class ToolStats extends JavaPlugin {
public TokenData tokenData;
public AnvilEvent anvilEvent;
public PrepareCraft prepareCraft;
public HyperLib hyperLib;
public TextUtils textUtils;
@Override
public void onEnable() {
hyperLib = new HyperLib(this);
hyperLib.setup();
bStats bstats = new bStats(hyperLib, 14110);
bstats.setup();
textUtils = new TextUtils(hyperLib);
if (!configFile.exists()) {
this.saveResource("config.yml", true);
logger.info("Copying default config!");
@@ -225,8 +236,27 @@ public final class ToolStats extends JavaPlugin {
this.getCommand("toolstats").setExecutor(commandToolStats);
new Metrics(this, 14110);
Bukkit.getAsyncScheduler().runNow(this, scheduledTask -> checkForUpdates());
Bukkit.getAsyncScheduler().runNow(this, scheduledTask -> {
ModrinthPlugin modrinthPlugin = new ModrinthPlugin("oBZj9E15");
modrinthPlugin.get();
ModrinthRelease release = modrinthPlugin.getReleaseByVersion(this.getPluginMeta().getVersion());
if (release == null) {
logger.warning("You are running a version not published.");
} else {
int buildsBehind = modrinthPlugin.buildsVersionsBehind(release);
if (buildsBehind > 0) {
ModrinthRelease latest = modrinthPlugin.getLatestRelease();
if (latest != null) {
logger.info("You are " + buildsBehind + " versions behind. Please update!");
logger.info("The latest version is " + latest.getVersion());
logger.info(latest.getVersionPage());
}
} else {
logger.info("Yay! You are running the latest version.");
}
}
});
}
public void loadConfig() {
@@ -247,29 +277,4 @@ public final class ToolStats extends JavaPlugin {
numberFormat = new NumberFormat(this);
}
public void checkForUpdates() {
GitHubReleaseAPI api;
try {
api = new GitHubReleaseAPI("ToolStats", "hyperdefined");
} catch (IOException e) {
logger.warning("Unable to check updates!");
e.printStackTrace();
return;
}
GitHubRelease current;
try {
current = api.getReleaseByTag(this.getPluginMeta().getVersion());
} catch (ReleaseNotFoundException e) {
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!");
return;
}
GitHubRelease latest = api.getLatestVersion();
int buildsBehind = api.getBuildsBehind(current);
if (buildsBehind == 0) {
logger.info("You are running the latest version.");
} else {
logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
}
}
}

View File

@@ -17,12 +17,11 @@
package lol.hyper.toolstats.commands;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@@ -18,7 +18,6 @@
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;

View File

@@ -17,8 +17,8 @@
package lol.hyper.toolstats.events;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.Material;

View File

@@ -17,8 +17,8 @@
package lol.hyper.toolstats.events;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;

View File

@@ -18,7 +18,6 @@
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@@ -17,8 +17,8 @@
package lol.hyper.toolstats.events;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.Material;

View File

@@ -17,8 +17,8 @@
package lol.hyper.toolstats.events;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

View File

@@ -17,8 +17,8 @@
package lol.hyper.toolstats.events;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.Material;

View File

@@ -17,8 +17,8 @@
package lol.hyper.toolstats.events;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.Material;

View File

@@ -17,8 +17,8 @@
package lol.hyper.toolstats.events;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

View File

@@ -17,8 +17,8 @@
package lol.hyper.toolstats.events;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.Material;

View File

@@ -17,13 +17,11 @@
package lol.hyper.toolstats.tools;
import lol.hyper.hyperlib.datatypes.UUIDDataType;
import lol.hyper.toolstats.ToolStats;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;

View File

@@ -170,7 +170,8 @@ public class TokenData {
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data." + tokenType + ".title");
String titleFromConfig = toolStats.config.getString("tokens.data." + tokenType + ".title");
Component title = toolStats.textUtils.format(titleFromConfig);
List<Component> lore = toolStats.configTools.getTokenLore(tokenType);
tokenMeta.displayName(title);
tokenMeta.lore(lore);

View File

@@ -1,54 +0,0 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.tools;
import org.bukkit.persistence.PersistentDataAdapterContext;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import java.nio.ByteBuffer;
import java.util.UUID;
public class UUIDDataType implements PersistentDataType<byte[], UUID> {
@Override
public @NotNull Class<byte[]> getPrimitiveType() {
return byte[].class;
}
@Override
public @NotNull Class<UUID> getComplexType() {
return UUID.class;
}
@Override
public byte @NotNull [] toPrimitive(UUID complex, @NotNull PersistentDataAdapterContext context) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(complex.getMostSignificantBits());
bb.putLong(complex.getLeastSignificantBits());
return bb.array();
}
@Override
public @NotNull UUID fromPrimitive(byte @NotNull [] primitive, @NotNull PersistentDataAdapterContext context) {
ByteBuffer bb = ByteBuffer.wrap(primitive);
long firstLong = bb.getLong();
long secondLong = bb.getLong();
return new UUID(firstLong, secondLong);
}
}

View File

@@ -20,8 +20,6 @@ package lol.hyper.toolstats.tools.config;
import lol.hyper.toolstats.ToolStats;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Material;
import java.util.ArrayList;
@@ -34,8 +32,6 @@ import java.util.regex.Pattern;
public class ConfigTools {
private final ToolStats toolStats;
public static final Pattern COLOR_CODES = Pattern.compile("[&§]([0-9a-fk-or])");
public static final Pattern CONFIG_HEX_PATTERN = Pattern.compile("[&§]#([A-Fa-f0-9]{6})");
public ConfigTools(ToolStats toolStats) {
this.toolStats = toolStats;
@@ -125,16 +121,7 @@ public class ConfigTools {
lore = lore.replace(placeHolder, String.valueOf(value));
}
// if we match the old color codes, then format them as so
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(lore);
Matcher colorMatcher = COLOR_CODES.matcher(lore);
if (hexMatcher.find() || colorMatcher.find()) {
component = LegacyComponentSerializer.legacyAmpersand().deserialize(lore);
} else {
// otherwise format them normally
component = MiniMessage.miniMessage().deserialize(lore);
}
component = toolStats.textUtils.format(lore);
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
}
@@ -183,49 +170,7 @@ public class ConfigTools {
Component component;
// Clean output text
String outputText = result.toString().replaceAll("\\s+", " ").trim();
// if we match the old color codes, then format them as so
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(outputText);
Matcher colorMatcher = COLOR_CODES.matcher(outputText);
if (hexMatcher.find() || colorMatcher.find()) {
component = LegacyComponentSerializer.legacyAmpersand().deserialize(outputText);
} else {
// otherwise format them normally
component = MiniMessage.miniMessage().deserialize(outputText);
}
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
}
/**
* Format a string from the config.
*
* @param configName The config to format.
* @return Formatted string, null if the configName doesn't exist.
*/
public Component format(String configName) {
String message = toolStats.config.getString(configName);
if (message == null) {
toolStats.logger.warning("Unable to find config message for: " + configName);
return null;
}
// if the config message is empty, don't send it
if (message.isEmpty()) {
return null;
}
// the final component for this lore
Component component;
// if we match the old color codes, then format them as so
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(message);
Matcher colorMatcher = COLOR_CODES.matcher(message);
if (hexMatcher.find() || colorMatcher.find()) {
component = LegacyComponentSerializer.legacyAmpersand().deserialize(message);
} else {
// otherwise format them normally
component = MiniMessage.miniMessage().deserialize(message);
}
component = toolStats.textUtils.format(outputText);
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
}
@@ -251,16 +196,7 @@ public class ConfigTools {
line = line.replace("{levels}", String.valueOf(levels));
}
}
Component component;
// if we match the old color codes, then format them as so
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(line);
Matcher colorMatcher = COLOR_CODES.matcher(line);
if (hexMatcher.find() || colorMatcher.find()) {
component = LegacyComponentSerializer.legacyAmpersand().deserialize(line);
} else {
// otherwise format them normally
component = MiniMessage.miniMessage().deserialize(line);
}
Component component = toolStats.textUtils.format(line);
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
finalLore.add(component);
}