Skip to content

Move away from adventure-platform for Paper #6220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Essentials/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ shadowJar {
relocate 'io.leangen.geantyref', 'com.earth2me.essentials.libs.geantyref'
relocate 'org.checkerframework', 'com.earth2me.essentials.libs.checkerframework'
relocate 'net.kyori', 'com.earth2me.essentials.libs.kyori'
relocate 'net.essentialsx.temp.adventure', 'net.kyori.adventure'
relocate 'net.essentialsx.temp.adventure', 'net.kyori.adventure' // Undo temporary relocation for Paper Provider

minimize {
include(dependency('org.checkerframework:checker-qual'))
Expand Down
5 changes: 2 additions & 3 deletions Essentials/src/main/java/com/earth2me/essentials/Backup.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.earth2me.essentials;

import com.earth2me.essentials.utils.AdventureUtil;
import net.ess3.api.IEssentials;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -80,7 +79,7 @@ public void run() {
taskLock.complete(new Object());
return;
}
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("backupStarted")));
ess.getLogger().log(Level.INFO, ess.getAdventureFacet().miniToLegacy(tlLiteral("backupStarted")));
final CommandSender cs = server.getConsoleSender();
server.dispatchCommand(cs, "save-all");
server.dispatchCommand(cs, "save-off");
Expand Down Expand Up @@ -119,7 +118,7 @@ public void run() {
}
active = false;
taskLock.complete(new Object());
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("backupFinished")));
ess.getLogger().log(Level.INFO, ess.getAdventureFacet().miniToLegacy(tlLiteral("backupFinished")));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.earth2me.essentials;

import com.earth2me.essentials.utils.AdventureUtil;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import com.earth2me.essentials.adventure.ComponentHolder;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -37,7 +35,7 @@ public void sendTl(final String tlKey, final Object... args) {

final String translation = tlLiteral(tlKey, args);
if (!translation.isEmpty()) {
sendComponent(AdventureUtil.miniMessage().deserialize(translation));
sendComponent(ess.getAdventureFacet().deserializeMiniMessage(translation));
}
}

Expand All @@ -49,18 +47,17 @@ public String tl(final String tlKey, final Object... args) {
return tlLiteral(tlKey, args);
}

public Component tlComponent(final String tlKey, final Object... args) {
public ComponentHolder tlComponent(final String tlKey, final Object... args) {
if (isPlayer()) {
//noinspection ConstantConditions
return getUser().tlComponent(tlKey, args);
}
final String translation = tlLiteral(tlKey, args);
return AdventureUtil.miniMessage().deserialize(translation);
return ess.getAdventureFacet().deserializeMiniMessage(translation);
}

public void sendComponent(final Component component) {
final BukkitAudiences audiences = ess.getBukkitAudience();
audiences.sender(sender).sendMessage(component);
public void sendComponent(final ComponentHolder component) {
ess.getAdventureFacet().send(sender, component);
}

public final net.ess3.api.IUser getUser() {
Expand Down
10 changes: 3 additions & 7 deletions Essentials/src/main/java/com/earth2me/essentials/Console.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.earth2me.essentials;

import com.earth2me.essentials.adventure.AdventureFacet;
import com.earth2me.essentials.messaging.IMessageRecipient;
import com.earth2me.essentials.messaging.SimpleMessageRecipient;
import com.earth2me.essentials.utils.AdventureUtil;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -73,10 +71,8 @@ public void sendTl(String tlKey, Object... args) {
return;
}

final Audience consoleAudience = ((Essentials) ess).getBukkitAudience().sender(getCommandSender());
final Component component = AdventureUtil.miniMessage()
.deserialize(translation);
consoleAudience.sendMessage(component);
final AdventureFacet adventureFacet = ess.getAdventureFacet();
adventureFacet.send(getCommandSender(), adventureFacet.deserializeMiniMessage(translation));
}

@Override
Expand Down
95 changes: 54 additions & 41 deletions Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
package com.earth2me.essentials;

import com.earth2me.essentials.adventure.AdventureFacet;
import com.earth2me.essentials.adventure.AdventureUtil;
import com.earth2me.essentials.adventure.ComponentHolder;
import com.earth2me.essentials.adventure.PaperAdventureFacet;
import com.earth2me.essentials.adventure.SpigotAdventureFacet;
import com.earth2me.essentials.commands.EssentialsCommand;
import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.NoChargeException;
Expand All @@ -40,7 +45,6 @@
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.updatecheck.UpdateChecker;
import com.earth2me.essentials.userstorage.ModernUserMap;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.VersionUtil;
import io.papermc.lib.PaperLib;
Expand Down Expand Up @@ -98,8 +102,6 @@
import net.ess3.provider.providers.PrehistoricPotionMetaProvider;
import net.essentialsx.api.v2.services.BalanceTop;
import net.essentialsx.api.v2.services.mail.MailService;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
Expand Down Expand Up @@ -176,7 +178,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
private transient Kits kits;
private transient RandomTeleport randomTeleport;
private transient UpdateChecker updateChecker;
private transient BukkitAudiences bukkitAudience;
private transient AdventureFacet adventureFacet;

static {
EconomyLayers.init();
Expand Down Expand Up @@ -207,6 +209,8 @@ public void onEnable() {
LOGGER = EssentialsLogger.getLoggerProvider(this);
EssentialsLogger.updatePluginLogger(this);

initAdventureFacet();

execTimer = new ExecuteTimer();
execTimer.start();

Expand All @@ -222,33 +226,33 @@ public void onEnable() {

switch (VersionUtil.getServerSupportStatus()) {
case NMS_CLEANROOM:
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedCleanroom")));
getLogger().severe(getAdventureFacet().miniToLegacy(tlLiteral("serverUnsupportedCleanroom")));
break;
case DANGEROUS_FORK:
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedDangerous")));
getLogger().severe(getAdventureFacet().miniToLegacy(tlLiteral("serverUnsupportedDangerous")));
break;
case STUPID_PLUGIN:
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedDumbPlugins")));
getLogger().severe(getAdventureFacet().miniToLegacy(tlLiteral("serverUnsupportedDumbPlugins")));
break;
case UNSTABLE:
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedMods")));
getLogger().severe(getAdventureFacet().miniToLegacy(tlLiteral("serverUnsupportedMods")));
break;
case OUTDATED:
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupported")));
getLogger().severe(getAdventureFacet().miniToLegacy(tlLiteral("serverUnsupported")));
break;
case LIMITED:
getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedLimitedApi")));
getLogger().info(getAdventureFacet().miniToLegacy(tlLiteral("serverUnsupportedLimitedApi")));
break;
}

if (VersionUtil.getSupportStatusClass() != null) {
getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedClass", VersionUtil.getSupportStatusClass())));
getLogger().info(getAdventureFacet().miniToLegacy(tlLiteral("serverUnsupportedClass", VersionUtil.getSupportStatusClass())));
}

final PluginManager pm = getServer().getPluginManager();
for (final Plugin plugin : pm.getPlugins()) {
if (plugin.getDescription().getName().startsWith("Essentials") && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) {
getLogger().warning(AdventureUtil.miniToLegacy(tlLiteral("versionMismatch", plugin.getDescription().getName())));
getLogger().warning(getAdventureFacet().miniToLegacy(tlLiteral("versionMismatch", plugin.getDescription().getName())));
}
}

Expand Down Expand Up @@ -426,9 +430,9 @@ public void onEnable() {
if (!TESTING) {
updateChecker = new UpdateChecker(this);
runTaskAsynchronously(() -> {
getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("versionFetching")));
for (final Component component : updateChecker.getVersionMessages(false, true, new CommandSource(this, Bukkit.getConsoleSender()))) {
getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, AdventureUtil.adventureToLegacy(component));
getLogger().log(Level.INFO, getAdventureFacet().miniToLegacy(tlLiteral("versionFetching")));
for (final ComponentHolder component : updateChecker.getVersionMessages(false, true, new CommandSource(this, Bukkit.getConsoleSender()))) {
getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, getAdventureFacet().adventureToLegacy(component));
}
});

Expand Down Expand Up @@ -517,13 +521,13 @@ public ProviderFactory getProviders() {

@Override
public void onDisable() {
if (bukkitAudience != null) {
bukkitAudience.close();
if (adventureFacet != null) {
adventureFacet.close();
}

final boolean stopping = TESTING || provider(ServerStateProvider.class).isStopping();
if (!stopping) {
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("serverReloading")));
LOGGER.log(Level.SEVERE, getAdventureFacet().miniToLegacy(tlLiteral("serverReloading")));
}

if (!TESTING) {
Expand All @@ -547,7 +551,7 @@ public void onDisable() {
}
cleanupOpenInventories();
if (!TESTING && getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) {
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("backupInProgress")));
LOGGER.log(Level.SEVERE, getAdventureFacet().miniToLegacy(tlLiteral("backupInProgress")));
getBackup().getTaskLock().join();
}
if (i18n != null) {
Expand All @@ -562,7 +566,6 @@ public void onDisable() {
}

Economy.setEss(null);
AdventureUtil.setEss(null);
Trade.closeLog();
getUsers().shutdown();

Expand All @@ -573,11 +576,6 @@ public void onDisable() {
public void reload() {
Trade.closeLog();

if (bukkitAudience != null) {
bukkitAudience.close();
bukkitAudience = null;
}

for (final IConf iConf : confList) {
iConf.reloadConfig();
execTimer.mark("Reload(" + iConf.getClass().getSimpleName() + ")");
Expand All @@ -587,16 +585,29 @@ public void reload() {
for (final String commandName : this.getDescription().getCommands().keySet()) {
final Command command = this.getCommand(commandName);
if (command != null) {
command.setDescription(AdventureUtil.miniToLegacy(tlLiteral(commandName + "CommandDescription")));
command.setUsage(AdventureUtil.miniToLegacy(tlLiteral(commandName + "CommandUsage")));
command.setDescription(getAdventureFacet().miniToLegacy(tlLiteral(commandName + "CommandDescription")));
command.setUsage(getAdventureFacet().miniToLegacy(tlLiteral(commandName + "CommandUsage")));
}
}

final PluginManager pm = getServer().getPluginManager();
registerListeners(pm);

AdventureUtil.setEss(this);
bukkitAudience = BukkitAudiences.create(this);
initAdventureFacet();
}

private void initAdventureFacet() {
if (adventureFacet != null) {
adventureFacet.close();
}

if (VersionUtil.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_5_R01)) {
adventureFacet = new PaperAdventureFacet(getSettings() != null ? getSettings().getPrimaryColor() : null, getSettings() != null ? getSettings().getSecondaryColor() : null);
} else {
adventureFacet = new SpigotAdventureFacet(this);
}

AdventureUtil.setAdventureFacet(adventureFacet);
}

private IEssentialsCommand loadCommand(final String path, final String name, final IEssentialsModule module, final ClassLoader classLoader) throws Exception {
Expand Down Expand Up @@ -661,7 +672,7 @@ public List<String> onTabCompleteEssentials(final CommandSender cSender, final C
cmd = loadCommand(commandPath, command.getName(), module, classLoader);
} catch (final Exception ex) {
sender.sendTl("commandNotLoaded", commandLabel);
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandNotLoaded", commandLabel)), ex);
LOGGER.log(Level.SEVERE, getAdventureFacet().miniToLegacy(tlLiteral("commandNotLoaded", commandLabel)), ex);
return Collections.emptyList();
}

Expand All @@ -684,11 +695,11 @@ public List<String> onTabCompleteEssentials(final CommandSender cSender, final C
} catch (final Exception ex) {
showError(sender, ex, commandLabel);
// Tab completion shouldn't fail
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
LOGGER.log(Level.SEVERE, getAdventureFacet().miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
return Collections.emptyList();
}
} catch (final Throwable ex) {
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
LOGGER.log(Level.SEVERE, getAdventureFacet().miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
return Collections.emptyList();
}
}
Expand All @@ -715,7 +726,8 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
if (cSender instanceof Player) {
final PlayerLocaleProvider localeProvider = provider(PlayerLocaleProvider.class);
getBukkitAudience().sender(cSender).sendMessage(AdventureUtil.miniMessage().deserialize(tlLocale(I18n.getLocale(localeProvider.getLocale((Player) cSender)), "internalError")));
final String miniMessageStr = tlLocale(I18n.getLocale(localeProvider.getLocale((Player) cSender)), "internalError");
getAdventureFacet().send(cSender, getAdventureFacet().deserializeMiniMessage(miniMessageStr));
} else {
cSender.sendMessage(tlLiteral("internalError"));
}
Expand Down Expand Up @@ -771,13 +783,13 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
cmd = loadCommand(commandPath, command.getName(), module, classLoader);
} catch (final Exception ex) {
sender.sendTl("commandNotLoaded", commandLabel);
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandNotLoaded", commandLabel)), ex);
LOGGER.log(Level.SEVERE, getAdventureFacet().miniToLegacy(tlLiteral("commandNotLoaded", commandLabel)), ex);
return true;
}

// Check authorization
if (user != null && !user.isAuthorized(cmd, permissionPrefix)) {
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("deniedAccessCommand", user.getName())));
LOGGER.log(Level.INFO, getAdventureFacet().miniToLegacy(tlLiteral("deniedAccessCommand", user.getName())));
user.sendTl("noAccessCommand");
return true;
}
Expand Down Expand Up @@ -818,7 +830,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
sender.sendMessage(command.getUsage().replace("<command>", commandLabel));
}
if (!ex.getMessage().isEmpty()) {
sender.sendComponent(AdventureUtil.miniMessage().deserialize(ex.getMessage()));
sender.sendComponent(getAdventureFacet().deserializeMiniMessage(ex.getMessage()));
}
if (ex.getCause() != null && settings.isDebug()) {
ex.getCause().printStackTrace();
Expand All @@ -832,7 +844,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
return true;
}
} catch (final Throwable ex) {
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
LOGGER.log(Level.SEVERE, getAdventureFacet().miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
return true;
}
}
Expand Down Expand Up @@ -868,7 +880,7 @@ public void showError(final CommandSource sender, final Throwable exception, fin
sender.sendTl("errorWithMessage", exception.getMessage());
}
if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("errorCallingCommand", commandLabel)), exception);
LOGGER.log(Level.INFO, getAdventureFacet().miniToLegacy(tlLiteral("errorCallingCommand", commandLabel)), exception);
}
}

Expand Down Expand Up @@ -1117,7 +1129,7 @@ private int broadcastMessage(final IUser sender, final String permission, final
final Collection<Player> players = getOnlinePlayers();
for (final Player player : players) {
final User user = getUser(player);
if ((permission == null && (sender == null || !user.isIgnoredPlayer(sender))) || (permission != null && user.isAuthorized(permission))) {
if (permission == null && (sender == null || !user.isIgnoredPlayer(sender)) || permission != null && user.isAuthorized(permission)) {
if (shouldExclude != null && shouldExclude.test(user)) {
continue;
}
Expand Down Expand Up @@ -1289,8 +1301,9 @@ public PluginCommand getPluginCommand(final String cmd) {
return this.getCommand(cmd);
}

public BukkitAudiences getBukkitAudience() {
return bukkitAudience;
@Override
public AdventureFacet getAdventureFacet() {
return adventureFacet;
}

private AbstractItemDb getItemDbFromConfig() {
Expand Down
Loading
Loading