1717 */
1818package com .earth2me .essentials ;
1919
20+ import com .earth2me .essentials .adventure .AdventureFacet ;
21+ import com .earth2me .essentials .adventure .AdventureUtil ;
22+ import com .earth2me .essentials .adventure .ComponentHolder ;
23+ import com .earth2me .essentials .adventure .PaperAdventureFacet ;
24+ import com .earth2me .essentials .adventure .SpigotAdventureFacet ;
2025import com .earth2me .essentials .commands .EssentialsCommand ;
2126import com .earth2me .essentials .commands .IEssentialsCommand ;
2227import com .earth2me .essentials .commands .NoChargeException ;
4045import com .earth2me .essentials .textreader .SimpleTextInput ;
4146import com .earth2me .essentials .updatecheck .UpdateChecker ;
4247import com .earth2me .essentials .userstorage .ModernUserMap ;
43- import com .earth2me .essentials .utils .AdventureUtil ;
4448import com .earth2me .essentials .utils .FormatUtil ;
4549import com .earth2me .essentials .utils .VersionUtil ;
4650import io .papermc .lib .PaperLib ;
101105import net .ess3 .provider .providers .PrehistoricPotionMetaProvider ;
102106import net .essentialsx .api .v2 .services .BalanceTop ;
103107import net .essentialsx .api .v2 .services .mail .MailService ;
104- import net .kyori .adventure .platform .bukkit .BukkitAudiences ;
105- import net .kyori .adventure .text .Component ;
106108import org .bukkit .Bukkit ;
107109import org .bukkit .Server ;
108110import org .bukkit .World ;
@@ -179,7 +181,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
179181 private transient Kits kits ;
180182 private transient RandomTeleport randomTeleport ;
181183 private transient UpdateChecker updateChecker ;
182- private transient BukkitAudiences bukkitAudience ;
184+ private transient AdventureFacet adventureFacet ;
183185
184186 static {
185187 EconomyLayers .init ();
@@ -210,6 +212,8 @@ public void onEnable() {
210212 LOGGER = EssentialsLogger .getLoggerProvider (this );
211213 EssentialsLogger .updatePluginLogger (this );
212214
215+ initAdventureFacet ();
216+
213217 execTimer = new ExecuteTimer ();
214218 execTimer .start ();
215219
@@ -225,37 +229,37 @@ public void onEnable() {
225229
226230 switch (VersionUtil .getServerSupportStatus ()) {
227231 case NMS_CLEANROOM :
228- getLogger ().severe (AdventureUtil .miniToLegacy (tlLiteral ("serverUnsupportedCleanroom" )));
232+ getLogger ().severe (getAdventureFacet () .miniToLegacy (tlLiteral ("serverUnsupportedCleanroom" )));
229233 break ;
230234 case DANGEROUS_FORK :
231- getLogger ().severe (AdventureUtil .miniToLegacy (tlLiteral ("serverUnsupportedDangerous" )));
235+ getLogger ().severe (getAdventureFacet () .miniToLegacy (tlLiteral ("serverUnsupportedDangerous" )));
232236 break ;
233237 case STUPID_PLUGIN :
234- getLogger ().severe (AdventureUtil .miniToLegacy (tlLiteral ("serverUnsupportedDumbPlugins" )));
238+ getLogger ().severe (getAdventureFacet () .miniToLegacy (tlLiteral ("serverUnsupportedDumbPlugins" )));
235239 break ;
236240 case UNSTABLE :
237- getLogger ().severe (AdventureUtil .miniToLegacy (tlLiteral ("serverUnsupportedMods" )));
241+ getLogger ().severe (getAdventureFacet () .miniToLegacy (tlLiteral ("serverUnsupportedMods" )));
238242 break ;
239243 case OUTDATED :
240- getLogger ().severe (AdventureUtil .miniToLegacy (tlLiteral ("serverUnsupported" )));
244+ getLogger ().severe (getAdventureFacet () .miniToLegacy (tlLiteral ("serverUnsupported" )));
241245 break ;
242246 case LIMITED :
243- getLogger ().info (AdventureUtil .miniToLegacy (tlLiteral ("serverUnsupportedLimitedApi" )));
247+ getLogger ().info (getAdventureFacet () .miniToLegacy (tlLiteral ("serverUnsupportedLimitedApi" )));
244248 break ;
245249 }
246250
247251 if (VersionUtil .getSupportStatusClass () != null ) {
248- getLogger ().info (AdventureUtil .miniToLegacy (tlLiteral ("serverUnsupportedClass" , VersionUtil .getSupportStatusClass ())));
252+ getLogger ().info (getAdventureFacet () .miniToLegacy (tlLiteral ("serverUnsupportedClass" , VersionUtil .getSupportStatusClass ())));
249253 }
250254
251255 if (VersionUtil .getServerBukkitVersion ().isSnapshot ()) {
252- getLogger ().severe (AdventureUtil .miniToLegacy (tlLiteral ("serverSnapshot" )));
256+ getLogger ().severe (getAdventureFacet () .miniToLegacy (tlLiteral ("serverSnapshot" )));
253257 }
254258
255259 final PluginManager pm = getServer ().getPluginManager ();
256260 for (final Plugin plugin : pm .getPlugins ()) {
257261 if (plugin .getDescription ().getName ().startsWith ("Essentials" ) && !plugin .getDescription ().getVersion ().equals (this .getDescription ().getVersion ()) && !plugin .getDescription ().getName ().equals ("EssentialsAntiCheat" )) {
258- getLogger ().warning (AdventureUtil .miniToLegacy (tlLiteral ("versionMismatch" , plugin .getDescription ().getName ())));
262+ getLogger ().warning (getAdventureFacet () .miniToLegacy (tlLiteral ("versionMismatch" , plugin .getDescription ().getName ())));
259263 }
260264 }
261265
@@ -436,9 +440,9 @@ public void onEnable() {
436440 if (!TESTING ) {
437441 updateChecker = new UpdateChecker (this );
438442 runTaskAsynchronously (() -> {
439- getLogger ().log (Level .INFO , AdventureUtil .miniToLegacy (tlLiteral ("versionFetching" )));
440- for (final Component component : updateChecker .getVersionMessages (false , true , new CommandSource (this , Bukkit .getConsoleSender ()))) {
441- getLogger ().log (getSettings ().isUpdateCheckEnabled () ? Level .WARNING : Level .INFO , AdventureUtil .adventureToLegacy (component ));
443+ getLogger ().log (Level .INFO , getAdventureFacet () .miniToLegacy (tlLiteral ("versionFetching" )));
444+ for (final ComponentHolder component : updateChecker .getVersionMessages (false , true , new CommandSource (this , Bukkit .getConsoleSender ()))) {
445+ getLogger ().log (getSettings ().isUpdateCheckEnabled () ? Level .WARNING : Level .INFO , getAdventureFacet () .adventureToLegacy (component ));
442446 }
443447 });
444448
@@ -527,13 +531,13 @@ public ProviderFactory getProviders() {
527531
528532 @ Override
529533 public void onDisable () {
530- if (bukkitAudience != null ) {
531- bukkitAudience .close ();
534+ if (adventureFacet != null ) {
535+ adventureFacet .close ();
532536 }
533537
534538 final boolean stopping = TESTING || provider (ServerStateProvider .class ).isStopping ();
535539 if (!stopping ) {
536- LOGGER .log (Level .SEVERE , AdventureUtil .miniToLegacy (tlLiteral ("serverReloading" )));
540+ LOGGER .log (Level .SEVERE , getAdventureFacet () .miniToLegacy (tlLiteral ("serverReloading" )));
537541 }
538542
539543 if (!TESTING ) {
@@ -557,7 +561,7 @@ public void onDisable() {
557561 }
558562 cleanupOpenInventories ();
559563 if (!TESTING && getBackup ().getTaskLock () != null && !getBackup ().getTaskLock ().isDone ()) {
560- LOGGER .log (Level .SEVERE , AdventureUtil .miniToLegacy (tlLiteral ("backupInProgress" )));
564+ LOGGER .log (Level .SEVERE , getAdventureFacet () .miniToLegacy (tlLiteral ("backupInProgress" )));
561565 getBackup ().getTaskLock ().join ();
562566 }
563567 if (i18n != null ) {
@@ -572,7 +576,6 @@ public void onDisable() {
572576 }
573577
574578 Economy .setEss (null );
575- AdventureUtil .setEss (null );
576579 Trade .closeLog ();
577580 getUsers ().shutdown ();
578581
@@ -585,11 +588,6 @@ public void onDisable() {
585588 public void reload () {
586589 Trade .closeLog ();
587590
588- if (bukkitAudience != null ) {
589- bukkitAudience .close ();
590- bukkitAudience = null ;
591- }
592-
593591 for (final IConf iConf : confList ) {
594592 iConf .reloadConfig ();
595593 execTimer .mark ("Reload(" + iConf .getClass ().getSimpleName () + ")" );
@@ -599,16 +597,29 @@ public void reload() {
599597 for (final String commandName : this .getDescription ().getCommands ().keySet ()) {
600598 final Command command = this .getCommand (commandName );
601599 if (command != null ) {
602- command .setDescription (AdventureUtil .miniToLegacy (tlLiteral (commandName + "CommandDescription" )));
603- command .setUsage (AdventureUtil .miniToLegacy (tlLiteral (commandName + "CommandUsage" )));
600+ command .setDescription (getAdventureFacet () .miniToLegacy (tlLiteral (commandName + "CommandDescription" )));
601+ command .setUsage (getAdventureFacet () .miniToLegacy (tlLiteral (commandName + "CommandUsage" )));
604602 }
605603 }
606604
607605 final PluginManager pm = getServer ().getPluginManager ();
608606 registerListeners (pm );
609607
610- AdventureUtil .setEss (this );
611- bukkitAudience = BukkitAudiences .create (this );
608+ initAdventureFacet ();
609+ }
610+
611+ private void initAdventureFacet () {
612+ if (adventureFacet != null ) {
613+ adventureFacet .close ();
614+ }
615+
616+ if (VersionUtil .isPaper () && VersionUtil .getServerBukkitVersion ().isHigherThanOrEqualTo (VersionUtil .v1_16_5_R01 )) {
617+ adventureFacet = new PaperAdventureFacet (getSettings () != null ? getSettings ().getPrimaryColor () : null , getSettings () != null ? getSettings ().getSecondaryColor () : null );
618+ } else {
619+ adventureFacet = new SpigotAdventureFacet (this );
620+ }
621+
622+ AdventureUtil .setAdventureFacet (adventureFacet );
612623 }
613624
614625 private IEssentialsCommand loadCommand (final String path , final String name , final IEssentialsModule module , final ClassLoader classLoader ) throws Exception {
@@ -673,7 +684,7 @@ public List<String> onTabCompleteEssentials(final CommandSender cSender, final C
673684 cmd = loadCommand (commandPath , command .getName (), module , classLoader );
674685 } catch (final Exception ex ) {
675686 sender .sendTl ("commandNotLoaded" , commandLabel );
676- LOGGER .log (Level .SEVERE , AdventureUtil .miniToLegacy (tlLiteral ("commandNotLoaded" , commandLabel )), ex );
687+ LOGGER .log (Level .SEVERE , getAdventureFacet () .miniToLegacy (tlLiteral ("commandNotLoaded" , commandLabel )), ex );
677688 return Collections .emptyList ();
678689 }
679690
@@ -696,11 +707,11 @@ public List<String> onTabCompleteEssentials(final CommandSender cSender, final C
696707 } catch (final Exception ex ) {
697708 showError (sender , ex , commandLabel );
698709 // Tab completion shouldn't fail
699- LOGGER .log (Level .SEVERE , AdventureUtil .miniToLegacy (tlLiteral ("commandFailed" , commandLabel )), ex );
710+ LOGGER .log (Level .SEVERE , getAdventureFacet () .miniToLegacy (tlLiteral ("commandFailed" , commandLabel )), ex );
700711 return Collections .emptyList ();
701712 }
702713 } catch (final Throwable ex ) {
703- LOGGER .log (Level .SEVERE , AdventureUtil .miniToLegacy (tlLiteral ("commandFailed" , commandLabel )), ex );
714+ LOGGER .log (Level .SEVERE , getAdventureFacet () .miniToLegacy (tlLiteral ("commandFailed" , commandLabel )), ex );
704715 return Collections .emptyList ();
705716 }
706717 }
@@ -727,7 +738,8 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
727738 LOGGER .log (Level .SEVERE , ex .getMessage (), ex );
728739 if (cSender instanceof Player ) {
729740 final PlayerLocaleProvider localeProvider = provider (PlayerLocaleProvider .class );
730- getBukkitAudience ().sender (cSender ).sendMessage (AdventureUtil .miniMessage ().deserialize (tlLocale (I18n .getLocale (localeProvider .getLocale ((Player ) cSender )), "internalError" )));
741+ final String miniMessageStr = tlLocale (I18n .getLocale (localeProvider .getLocale ((Player ) cSender )), "internalError" );
742+ getAdventureFacet ().send (cSender , getAdventureFacet ().deserializeMiniMessage (miniMessageStr ));
731743 } else {
732744 cSender .sendMessage (tlLiteral ("internalError" ));
733745 }
@@ -785,13 +797,13 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
785797 cmd = loadCommand (commandPath , command .getName (), module , classLoader );
786798 } catch (final Exception ex ) {
787799 sender .sendTl ("commandNotLoaded" , commandLabel );
788- LOGGER .log (Level .SEVERE , AdventureUtil .miniToLegacy (tlLiteral ("commandNotLoaded" , commandLabel )), ex );
800+ LOGGER .log (Level .SEVERE , getAdventureFacet () .miniToLegacy (tlLiteral ("commandNotLoaded" , commandLabel )), ex );
789801 return true ;
790802 }
791803
792804 // Check authorization
793805 if (user != null && !user .isAuthorized (cmd , permissionPrefix )) {
794- LOGGER .log (Level .INFO , AdventureUtil .miniToLegacy (tlLiteral ("deniedAccessCommand" , user .getName ())));
806+ LOGGER .log (Level .INFO , getAdventureFacet () .miniToLegacy (tlLiteral ("deniedAccessCommand" , user .getName ())));
795807 user .sendTl ("noAccessCommand" );
796808 return true ;
797809 }
@@ -832,7 +844,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
832844 sender .sendMessage (command .getUsage ().replace ("<command>" , commandLabel ));
833845 }
834846 if (!ex .getMessage ().isEmpty ()) {
835- sender .sendComponent (AdventureUtil . miniMessage ().deserialize (ex .getMessage ()));
847+ sender .sendComponent (getAdventureFacet ().deserializeMiniMessage (ex .getMessage ()));
836848 }
837849 if (ex .getCause () != null && settings .isDebug ()) {
838850 ex .getCause ().printStackTrace ();
@@ -846,7 +858,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
846858 return true ;
847859 }
848860 } catch (final Throwable ex ) {
849- LOGGER .log (Level .SEVERE , AdventureUtil .miniToLegacy (tlLiteral ("commandFailed" , commandLabel )), ex );
861+ LOGGER .log (Level .SEVERE , getAdventureFacet () .miniToLegacy (tlLiteral ("commandFailed" , commandLabel )), ex );
850862 return true ;
851863 }
852864 }
@@ -882,7 +894,7 @@ public void showError(final CommandSource sender, final Throwable exception, fin
882894 sender .sendTl ("errorWithMessage" , exception .getMessage ());
883895 }
884896 if (getSettings ().isDebug ()) {
885- LOGGER .log (Level .INFO , AdventureUtil .miniToLegacy (tlLiteral ("errorCallingCommand" , commandLabel )), exception );
897+ LOGGER .log (Level .INFO , getAdventureFacet () .miniToLegacy (tlLiteral ("errorCallingCommand" , commandLabel )), exception );
886898 }
887899 }
888900
@@ -1151,7 +1163,7 @@ private int broadcastMessage(final IUser sender, final String permission, final
11511163 final Collection <Player > players = getOnlinePlayers ();
11521164 for (final Player player : players ) {
11531165 final User user = getUser (player );
1154- if (( permission == null && (sender == null || !user .isIgnoredPlayer (sender ))) || ( permission != null && user .isAuthorized (permission ) )) {
1166+ if (permission == null && (sender == null || !user .isIgnoredPlayer (sender )) || permission != null && user .isAuthorized (permission )) {
11551167 if (shouldExclude != null && shouldExclude .test (user )) {
11561168 continue ;
11571169 }
@@ -1323,8 +1335,9 @@ public PluginCommand getPluginCommand(final String cmd) {
13231335 return this .getCommand (cmd );
13241336 }
13251337
1326- public BukkitAudiences getBukkitAudience () {
1327- return bukkitAudience ;
1338+ @ Override
1339+ public AdventureFacet getAdventureFacet () {
1340+ return adventureFacet ;
13281341 }
13291342
13301343 private AbstractItemDb getItemDbFromConfig () {
0 commit comments