Port to adventure and MineDown-adventure

This commit is contained in:
William committed 2022-09-20 13:02:26 +01:00
1 parent c56936d9d5
commit 98c2461c89
17 files changed
+60 -48

No files matched your search

+6 -3
View File
@@ -1,23 +1,25 @@
dependencies { dependencies {
implementation project(path: ':common') implementation project(path: ':common')
implementation 'net.kyori:adventure-platform-bukkit:4.1.2'
implementation 'org.bstats:bstats-bukkit:3.0.0' implementation 'org.bstats:bstats-bukkit:3.0.0'
implementation 'io.papermc:paperlib:1.0.7' implementation 'io.papermc:paperlib:1.0.7'
implementation 'me.lucko:commodore:2.2' implementation 'me.lucko:commodore:2.2'
compileOnly 'org.jetbrains:annotations:23.0.0' compileOnly 'org.jetbrains:annotations:23.0.0'
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'de.themoep:minedown-adventure:1.7.1-SNAPSHOT'
compileOnly 'redis.clients:jedis:' + jedis_version compileOnly 'redis.clients:jedis:' + jedis_version
compileOnly 'commons-io:commons-io:2.11.0' compileOnly 'commons-io:commons-io:2.11.0'
compileOnly 'com.google.guava:guava:31.1-jre' compileOnly 'com.google.guava:guava:31.1-jre'
compileOnly 'de.themoep:minedown:1.7.1-SNAPSHOT'
compileOnly 'net.william278:Annotaml:1.0.3' compileOnly 'net.william278:Annotaml:1.0.3'
compileOnly 'net.william278:DesertWell:1.0' compileOnly 'net.william278:DesertWell:1.1'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1' compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
compileOnly 'us.dynmap:dynmap-api:3.1' compileOnly 'us.dynmap:dynmap-api:3.1'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2' testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2'
testImplementation 'de.themoep:minedown:1.7.1-SNAPSHOT' testImplementation 'de.themoep:minedown-adventure:1.7.1-SNAPSHOT'
testImplementation 'net.kyori:adventure-platform-bukkit:4.1.2'
testImplementation 'redis.clients:jedis:' + jedis_version testImplementation 'redis.clients:jedis:' + jedis_version
testImplementation 'org.xerial:sqlite-jdbc:' + sqlite_driver_version testImplementation 'org.xerial:sqlite-jdbc:' + sqlite_driver_version
testImplementation 'mysql:mysql-connector-java:' + mysql_driver_version testImplementation 'mysql:mysql-connector-java:' + mysql_driver_version
@@ -39,6 +41,7 @@ shadowJar {
relocate 'net.william278.desertwell', 'net.william278.huskhomes.libraries.desertwell' relocate 'net.william278.desertwell', 'net.william278.huskhomes.libraries.desertwell'
relocate 'org.yaml.snakeyaml', 'net.william278.huskhomes.libraries.snakeyaml' relocate 'org.yaml.snakeyaml', 'net.william278.huskhomes.libraries.snakeyaml'
relocate 'com.google.gson', 'net.william278.huskhomes.libraries.gson' relocate 'com.google.gson', 'net.william278.huskhomes.libraries.gson'
relocate 'net.kyori.adventure', 'net.william278.huskhomes.libraries.adventure'
relocate 'org.bstats', 'net.william278.huskhomes.libraries.bstats' relocate 'org.bstats', 'net.william278.huskhomes.libraries.bstats'
relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib' relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib'
@@ -1,6 +1,7 @@
package net.william278.huskhomes; package net.william278.huskhomes;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.william278.annotaml.Annotaml; import net.william278.annotaml.Annotaml;
import net.william278.desertwell.Version; import net.william278.desertwell.Version;
import net.william278.huskhomes.command.BukkitCommand; import net.william278.huskhomes.command.BukkitCommand;
@@ -84,6 +85,9 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
@Nullable @Nullable
private Server server; private Server server;
// Adventure audience
private BukkitAudiences audiences;
// Instance of the plugin // Instance of the plugin
private static BukkitHuskHomes instance; private static BukkitHuskHomes instance;
@@ -106,6 +110,9 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
this.logger = new BukkitLogger(getLogger()); this.logger = new BukkitLogger(getLogger());
this.resourceReader = new BukkitResourceReader(this); this.resourceReader = new BukkitResourceReader(this);
// Create adventure audience
this.audiences = BukkitAudiences.create(this);
// Detect if an upgrade is needed // Detect if an upgrade is needed
final BukkitUpgradeUtil upgradeData = BukkitUpgradeUtil.detect(this); final BukkitUpgradeUtil upgradeData = BukkitUpgradeUtil.detect(this);
@@ -134,7 +141,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
getLoggingAdapter().log(Level.INFO, "Successfully established a connection to the database"); getLoggingAdapter().log(Level.INFO, "Successfully established a connection to the database");
} else { } else {
throw new HuskHomesInitializationException("Failed to establish a connection to the database. " + throw new HuskHomesInitializationException("Failed to establish a connection to the database. " +
"Please check the supplied database credentials in the config file"); "Please check the supplied database credentials in the config file");
} }
// Initialize the network messenger if proxy mode is enabled // Initialize the network messenger if proxy mode is enabled
@@ -196,8 +203,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
if (pluginHooks.size() > 0) { if (pluginHooks.size() > 0) {
pluginHooks.forEach(PluginHook::initialize); pluginHooks.forEach(PluginHook::initialize);
getLoggingAdapter().log(Level.INFO, "Registered " + pluginHooks.size() + " plugin hooks: " + getLoggingAdapter().log(Level.INFO, "Registered " + pluginHooks.size() + " plugin hooks: " +
pluginHooks.stream().map(PluginHook::getHookName) pluginHooks.stream().map(PluginHook::getHookName)
.collect(Collectors.joining(", "))); .collect(Collectors.joining(", ")));
} }
// Register events // Register events
@@ -227,8 +234,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
if (settings.disabledCommands.stream().anyMatch(disabledCommand -> { if (settings.disabledCommands.stream().anyMatch(disabledCommand -> {
final String command = (disabledCommand.startsWith("/") ? disabledCommand.substring(1) : disabledCommand); final String command = (disabledCommand.startsWith("/") ? disabledCommand.substring(1) : disabledCommand);
return command.equalsIgnoreCase(commandType.commandBase.command) || return command.equalsIgnoreCase(commandType.commandBase.command) ||
Arrays.stream(commandType.commandBase.aliases) Arrays.stream(commandType.commandBase.aliases)
.anyMatch(alias -> alias.equalsIgnoreCase(command)); .anyMatch(alias -> alias.equalsIgnoreCase(command));
})) { })) {
new BukkitCommand(new DisabledCommand(this), this).register(pluginCommand); new BukkitCommand(new DisabledCommand(this), this).register(pluginCommand);
return; return;
@@ -255,7 +262,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
getLatestVersionIfOutdated().thenAccept(newestVersion -> getLatestVersionIfOutdated().thenAccept(newestVersion ->
newestVersion.ifPresent(newVersion -> getLoggingAdapter().log(Level.WARNING, newestVersion.ifPresent(newVersion -> getLoggingAdapter().log(Level.WARNING,
"An update is available for HuskHomes, v" + newVersion "An update is available for HuskHomes, v" + newVersion
+ " (Currently running v" + getPluginVersion() + ")"))); + " (Currently running v" + getPluginVersion() + ")")));
} }
// Perform automatic upgrade if detected // Perform automatic upgrade if detected
@@ -297,6 +304,19 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
if (networkMessenger != null) { if (networkMessenger != null) {
networkMessenger.terminate(); networkMessenger.terminate();
} }
if (audiences != null) {
audiences.close();
audiences = null;
}
}
/**
* Returns the adventure Bukkit audiences
*
* @return The adventure Bukkit audiences
*/
public BukkitAudiences getAudiences() {
return audiences;
} }
@NotNull @NotNull
@@ -57,7 +57,7 @@ public class BukkitCommand implements CommandExecutor, TabExecutor {
consoleExecutable.onConsoleExecute(args); consoleExecutable.onConsoleExecute(args);
} else { } else {
plugin.getLocales().getLocale("error_in_game_only"). plugin.getLocales().getLocale("error_in_game_only").
ifPresent(locale -> sender.spigot().sendMessage(locale.toComponent())); ifPresent(locale -> plugin.getAudiences().sender(sender).sendMessage(locale.toComponent()));
} }
} }
return true; return true;
@@ -1,11 +1,11 @@
package net.william278.huskhomes.player; package net.william278.huskhomes.player;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import de.themoep.minedown.MineDownParser; import de.themoep.minedown.adventure.MineDownParser;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import net.md_5.bungee.api.ChatMessageType; import net.kyori.adventure.audience.Audience;
import net.md_5.bungee.api.chat.BaseComponent; import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.chat.TextComponent; import net.kyori.adventure.title.Title;
import net.md_5.bungee.api.chat.TranslatableComponent; import net.md_5.bungee.api.chat.TranslatableComponent;
import net.william278.huskhomes.BukkitHuskHomes; import net.william278.huskhomes.BukkitHuskHomes;
import net.william278.huskhomes.HuskHomesException; import net.william278.huskhomes.HuskHomesException;
@@ -32,10 +32,12 @@ import java.util.stream.Collectors;
public class BukkitPlayer extends OnlineUser { public class BukkitPlayer extends OnlineUser {
private final Player player; private final Player player;
private final Audience audience;
private BukkitPlayer(@NotNull Player player) { private BukkitPlayer(@NotNull Player player) {
super(player.getUniqueId(), player.getName()); super(player.getUniqueId(), player.getName());
this.player = player; this.player = player;
this.audience = BukkitHuskHomes.getInstance().getAudiences().player(player);
} }
/** /**
@@ -96,28 +98,25 @@ public class BukkitPlayer extends OnlineUser {
@Override @Override
public void sendTitle(@NotNull MineDown mineDown, boolean subTitle) { public void sendTitle(@NotNull MineDown mineDown, boolean subTitle) {
final String legacyText = TextComponent.toLegacyText(mineDown final Component text = mineDown
.disable(MineDownParser.Option.SIMPLE_FORMATTING) .disable(MineDownParser.Option.SIMPLE_FORMATTING)
.replace().toComponent()); .replace().toComponent();
player.sendTitle(subTitle ? "" : legacyText, subTitle ? legacyText : "", 10, 70, 20); audience.showTitle(Title.title(subTitle ? Component.empty() : text,
subTitle ? text : Component.empty()));
} }
@Override @Override
public void sendActionBar(@NotNull MineDown mineDown) { public void sendActionBar(@NotNull MineDown mineDown) {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, mineDown audience.sendActionBar(mineDown
.disable(MineDownParser.Option.SIMPLE_FORMATTING) .disable(MineDownParser.Option.SIMPLE_FORMATTING)
.replace().toComponent()); .replace().toComponent());
} }
@Override @Override
public void sendMessage(@NotNull MineDown mineDown) { public void sendMessage(@NotNull MineDown mineDown) {
final BaseComponent[] messageComponents = mineDown audience.sendMessage(mineDown
.disable(MineDownParser.Option.SIMPLE_FORMATTING) .disable(MineDownParser.Option.SIMPLE_FORMATTING)
.replace().toComponent(); .replace().toComponent());
if (messageComponents.length == 0) {
return;
}
player.spigot().sendMessage(messageComponents);
} }
@Override @Override
@@ -1,7 +1,5 @@
package net.william278.huskhomes.util; package net.william278.huskhomes.util;
import de.themoep.minedown.MineDown;
import net.md_5.bungee.api.chat.TextComponent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.logging.Level; import java.util.logging.Level;
@@ -24,11 +22,6 @@ public class BukkitLogger extends Logger {
logger.log(level, message); logger.log(level, message);
} }
@Override
public void log(@NotNull Level level, @NotNull MineDown mineDown) {
logger.log(level, TextComponent.toLegacyText(mineDown.toComponent()));
}
@Override @Override
public void info(@NotNull String message) { public void info(@NotNull String message) {
logger.info(message); logger.info(message);
@@ -3,7 +3,7 @@ package net.william278.huskhomes;
import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock; import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.entity.PlayerMock; import be.seeseemelk.mockbukkit.entity.PlayerMock;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.command.BukkitCommandType; import net.william278.huskhomes.command.BukkitCommandType;
import net.william278.huskhomes.player.BukkitPlayer; import net.william278.huskhomes.player.BukkitPlayer;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
+3 -3
View File
@@ -1,10 +1,10 @@
dependencies { dependencies {
implementation 'commons-io:commons-io:2.11.0' implementation 'commons-io:commons-io:2.11.0'
implementation 'de.themoep:minedown:1.7.1-SNAPSHOT' implementation 'de.themoep:minedown-adventure:1.7.1-SNAPSHOT'
implementation 'com.google.code.gson:gson:2.9.1' implementation 'com.google.code.gson:gson:2.9.1'
implementation 'net.william278:Annotaml:1.0.3' implementation 'net.william278:Annotaml:1.0.3'
implementation 'net.william278:PagineDown:1.0.3' implementation 'net.william278:PagineDown:1.1'
implementation 'net.william278:DesertWell:1.0' implementation 'net.william278:DesertWell:1.1'
implementation('com.zaxxer:HikariCP:5.0.1') { implementation('com.zaxxer:HikariCP:5.0.1') {
exclude module: 'slf4j-api' exclude module: 'slf4j-api'
} }
@@ -1,6 +1,6 @@
package net.william278.huskhomes; package net.william278.huskhomes;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.command.CommandBase; import net.william278.huskhomes.command.CommandBase;
import net.william278.huskhomes.config.Locales; import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.database.Database; import net.william278.huskhomes.database.Database;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.api; package net.william278.huskhomes.api;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Locales; import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.player.OnlineUser;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.command; package net.william278.huskhomes.command;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Locales; import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.config.Settings; import net.william278.huskhomes.config.Settings;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.command; package net.william278.huskhomes.command;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.position.Warp; import net.william278.huskhomes.position.Warp;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.command; package net.william278.huskhomes.command;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.desertwell.AboutMenu; import net.william278.desertwell.AboutMenu;
import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.migrator.Migrator; import net.william278.huskhomes.migrator.Migrator;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.command; package net.william278.huskhomes.command;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.UserData; import net.william278.huskhomes.player.UserData;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.config; package net.william278.huskhomes.config;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.annotaml.RootedMap; import net.william278.annotaml.RootedMap;
import net.william278.annotaml.YamlFile; import net.william278.annotaml.YamlFile;
import org.apache.commons.text.StringEscapeUtils; import org.apache.commons.text.StringEscapeUtils;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.listener; package net.william278.huskhomes.listener;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Settings; import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.player.OnlineUser;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.player; package net.william278.huskhomes.player;
import de.themoep.minedown.MineDown; import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.position.Location; import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.Position; import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.TeleportResult; import net.william278.huskhomes.teleport.TeleportResult;
@@ -1,6 +1,5 @@
package net.william278.huskhomes.util; package net.william278.huskhomes.util;
import de.themoep.minedown.MineDown;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.logging.Level; import java.util.logging.Level;
@@ -16,8 +15,6 @@ public abstract class Logger {
public abstract void log(@NotNull Level level, @NotNull String message); public abstract void log(@NotNull Level level, @NotNull String message);
public abstract void log(@NotNull Level level, @NotNull MineDown mineDown);
public abstract void info(@NotNull String message); public abstract void info(@NotNull String message);
public abstract void severe(@NotNull String message); public abstract void severe(@NotNull String message);