11package com .nisovin .magicspells ;
22
3+ import org .jetbrains .annotations .NotNull ;
4+
35import java .io .*;
46
57import java .util .*;
2527import com .google .common .collect .SetMultimap ;
2628import com .google .common .collect .LinkedHashMultimap ;
2729
30+ import net .kyori .adventure .text .format .NamedTextColor ;
31+
2832import de .slikey .effectlib .EffectManager ;
2933
3034import org .bstats .bukkit .Metrics ;
3135import org .bstats .charts .SimplePie ;
3236import org .bstats .charts .AdvancedPie ;
3337import org .bstats .charts .DrilldownPie ;
3438
35- import org .jetbrains .annotations .NotNull ;
36-
37- import co .aikar .commands .PaperCommandManager ;
38-
3939import org .bukkit .*;
4040import org .bukkit .event .Event ;
4141import org .bukkit .entity .Entity ;
5353import org .bukkit .permissions .PermissionDefault ;
5454import org .bukkit .configuration .ConfigurationSection ;
5555
56+ import io .papermc .paper .command .brigadier .CommandSourceStack ;
57+
58+ import org .incendo .cloud .paper .PaperCommandManager ;
59+ import org .incendo .cloud .execution .ExecutionCoordinator ;
60+
5661import me .clip .placeholderapi .PlaceholderAPI ;
5762
5863import com .nisovin .magicspells .util .*;
6469import com .nisovin .magicspells .mana .ManaHandler ;
6570import com .nisovin .magicspells .variables .Variable ;
6671import com .nisovin .magicspells .spells .PassiveSpell ;
67- import com .nisovin .magicspells .commands .MagicCommand ;
6872import com .nisovin .magicspells .util .compat .EventUtil ;
73+ import com .nisovin .magicspells .commands .MagicCommands ;
6974import com .nisovin .magicspells .storage .StorageHandler ;
7075import com .nisovin .magicspells .util .prompt .PromptType ;
7176import com .nisovin .magicspells .util .compat .CompatBasics ;
7277import com .nisovin .magicspells .zones .NoMagicZoneManager ;
7378import com .nisovin .magicspells .spelleffects .SpellEffect ;
7479import com .nisovin .magicspells .util .magicitems .MagicItem ;
7580import com .nisovin .magicspells .castmodifiers .ModifierSet ;
76- import com .nisovin .magicspells .commands .CommandHelpFilter ;
7781import com .nisovin .magicspells .util .magicitems .MagicItems ;
7882import com .nisovin .magicspells .util .recipes .CustomRecipes ;
7983import com .nisovin .magicspells .util .ai .CustomGoalsManager ;
@@ -141,7 +145,8 @@ public class MagicSpells extends JavaPlugin {
141145 private NoMagicZoneManager zoneManager ;
142146 private CleanserManager cleanserManager ;
143147 private CustomGoalsManager customGoalsManager ;
144- private PaperCommandManager commandManager ;
148+ @ SuppressWarnings ("UnstableApiUsage" )
149+ private PaperCommandManager <CommandSourceStack > commandManager ;
145150 private ExperienceBarManager expBarManager ;
146151
147152 private ExpressionDictionary expressionDictionary ;
@@ -212,7 +217,8 @@ public class MagicSpells extends JavaPlugin {
212217
213218 private long lastReloadTime = 0 ;
214219
215- private ChatColor textColor ;
220+ private NamedTextColor textColor ;
221+ private String textFormat ;
216222
217223 private double losRaySize ;
218224 private boolean losIgnorePassableBlocks ;
@@ -238,45 +244,8 @@ public class MagicSpells extends JavaPlugin {
238244 @ Override
239245 public void onEnable () {
240246 load ();
241-
242- Metrics metrics = new Metrics (this , 892 );
243-
244- metrics .addCustomChart (new DrilldownPie ("spells" , () -> {
245- Map <String , Map <String , Integer >> map = new HashMap <>();
246- if (spells == null ) return map ;
247-
248- for (Spell spell : spells .values ()) {
249- String name = spell .getClass ().getName ();
250- if (!name .startsWith ("com.nisovin.magicspells.spells" )) continue ;
251- name = name .replace ("com.nisovin.magicspells.spells." , "" );
252-
253- String [] typeSplit = name .split ("\\ ." , 2 );
254- String formalPackage = typeSplit [0 ].substring (0 , 1 ).toUpperCase () + typeSplit [0 ].substring (1 );
255-
256- String spellPackage = (typeSplit .length == 1 ? "General" : formalPackage ) + " Spells" ;
257- String spellClass = typeSplit .length == 1 ? typeSplit [0 ] : typeSplit [1 ];
258-
259- map .computeIfAbsent (spellPackage , key -> new HashMap <>());
260- map .get (spellPackage ).compute (spellClass , (k , v ) -> (v == null ? 0 : v ) + 1 );
261- }
262- return map ;
263- }));
264- metrics .addCustomChart (new AdvancedPie ("passive_listeners" , () -> {
265- IntMap <String > map = new IntMap <>();
266- if (spells == null ) return map ;
267-
268- for (Spell spell : spells .values ()) {
269- if (!spell .getClass ().getName ().startsWith ("com.nisovin.magicspells.spells" )) continue ;
270- if (!(spell instanceof PassiveSpell passiveSpell )) continue ;
271-
272- for (PassiveListener listener : passiveSpell .getPassiveListeners ()) {
273- String name = listener .getClass ().getSimpleName ();
274- map .increment (name .substring (0 , name .lastIndexOf ("Listener" )));
275- }
276- }
277- return map ;
278- }));
279- metrics .addCustomChart (new SimplePie ("reload_time" , () -> "<" + (lastReloadTime - lastReloadTime % 500 + 500 ) + " ms" ));
247+ initMetrics ();
248+ initCommands ();
280249 }
281250
282251 public void load () {
@@ -287,8 +256,6 @@ public void load() {
287256 effectManager = new EffectManager (this );
288257 effectManager .enableDebug (debug );
289258
290- commandManager = new PaperCommandManager (plugin );
291-
292259 // Create storage stuff
293260 spells = new HashMap <>();
294261 spellNames = new HashMap <>();
@@ -334,7 +301,6 @@ public void load() {
334301 enableErrorLogging = config .getBoolean (path + "enable-error-logging" , true );
335302 errorLogLimit = config .getInt (path + "error-log-limit" , -1 );
336303 enableProfiling = config .getBoolean (path + "enable-profiling" , false );
337- textColor = ChatColor .getByChar (config .getString (path + "text-color" , ChatColor .DARK_AQUA .getChar () + "" ));
338304 broadcastRange = config .getInt (path + "broadcast-range" , 20 );
339305 effectlibInstanceLimit = config .getInt (path + "effectlib-instance-limit" , 20000 );
340306
@@ -405,6 +371,9 @@ public void load() {
405371 }
406372 }
407373
374+ textColor = Util .getLegacyColor (config .getString ("text-color" , null ), NamedTextColor .DARK_AQUA );
375+ textFormat = config .getString ("text-format" , "<" + textColor + "><text></" + textColor + ">" );
376+
408377 soundFailOnCooldown = config .getString (path + "sound-on-cooldown" , null );
409378 soundFailMissingReagents = config .getString (path + "sound-missing-reagents" , null );
410379
@@ -570,12 +539,6 @@ public void load() {
570539 magicLogger = new MagicLogger (this );
571540 }
572541
573- // Register commands
574- commandManager .enableUnstableAPI ("help" );
575- commandManager .registerCommand (new MagicCommand ());
576- commandManager .setValidNamePredicate (string -> true );
577- CommandHelpFilter .mapPerms ();
578-
579542 // Setup profiling
580543 if (enableProfiling ) {
581544 profilingTotalTime = new HashMap <>();
@@ -588,6 +551,56 @@ public void load() {
588551 Bukkit .getScheduler ().runTaskLater (this , this ::loadExternalData , 1 );
589552 }
590553
554+ private void initMetrics () {
555+ Metrics metrics = new Metrics (this , 892 );
556+
557+ metrics .addCustomChart (new DrilldownPie ("spells" , () -> {
558+ Map <String , Map <String , Integer >> map = new HashMap <>();
559+ if (spells == null ) return map ;
560+
561+ for (Spell spell : spells .values ()) {
562+ String name = spell .getClass ().getName ();
563+ if (!name .startsWith ("com.nisovin.magicspells.spells" )) continue ;
564+ name = name .replace ("com.nisovin.magicspells.spells." , "" );
565+
566+ String [] typeSplit = name .split ("\\ ." , 2 );
567+ String formalPackage = typeSplit [0 ].substring (0 , 1 ).toUpperCase () + typeSplit [0 ].substring (1 );
568+
569+ String spellPackage = (typeSplit .length == 1 ? "General" : formalPackage ) + " Spells" ;
570+ String spellClass = typeSplit .length == 1 ? typeSplit [0 ] : typeSplit [1 ];
571+
572+ map .computeIfAbsent (spellPackage , key -> new HashMap <>());
573+ map .get (spellPackage ).compute (spellClass , (k , v ) -> (v == null ? 0 : v ) + 1 );
574+ }
575+ return map ;
576+ }));
577+ metrics .addCustomChart (new AdvancedPie ("passive_listeners" , () -> {
578+ IntMap <String > map = new IntMap <>();
579+ if (spells == null ) return map ;
580+
581+ for (Spell spell : spells .values ()) {
582+ if (!spell .getClass ().getName ().startsWith ("com.nisovin.magicspells.spells" )) continue ;
583+ if (!(spell instanceof PassiveSpell passiveSpell )) continue ;
584+
585+ for (PassiveListener listener : passiveSpell .getPassiveListeners ()) {
586+ String name = listener .getClass ().getSimpleName ();
587+ map .increment (name .substring (0 , name .lastIndexOf ("Listener" )));
588+ }
589+ }
590+ return map ;
591+ }));
592+ metrics .addCustomChart (new SimplePie ("reload_time" , () -> "<" + (lastReloadTime - lastReloadTime % 500 + 500 ) + " ms" ));
593+ }
594+
595+ @ SuppressWarnings ("UnstableApiUsage" )
596+ private void initCommands () {
597+ commandManager = PaperCommandManager .builder ()
598+ .executionCoordinator (ExecutionCoordinator .simpleCoordinator ())
599+ .buildOnEnable (this );
600+
601+ MagicCommands .register (commandManager );
602+ }
603+
591604 private void initializeSpells () {
592605 log ("Initializing spells..." );
593606
@@ -1077,10 +1090,19 @@ public static Spellbook getSpellbook(Player player) {
10771090 return plugin .spellbooks .computeIfAbsent (player .getUniqueId (), uuid -> new Spellbook (player ));
10781091 }
10791092
1093+ @ Deprecated (forRemoval = true )
10801094 public static ChatColor getTextColor () {
1095+ return ChatColor .valueOf (plugin .textColor .toString ().toUpperCase ());
1096+ }
1097+
1098+ public static NamedTextColor getLegacyTextColor () {
10811099 return plugin .textColor ;
10821100 }
10831101
1102+ public static String getTextFormat () {
1103+ return plugin .textFormat ;
1104+ }
1105+
10841106 /**
10851107 * Gets a list of blocks that are considered transparent
10861108 * @return set of block types
@@ -1246,6 +1268,10 @@ public static int getDebugLevelOriginal() {
12461268 return plugin .debugLevelOriginal ;
12471269 }
12481270
1271+ public static int getDebugLevel () {
1272+ return plugin .debugLevel ;
1273+ }
1274+
12491275 public static int getErrorLogLimit () {
12501276 return plugin .errorLogLimit ;
12511277 }
@@ -1584,7 +1610,7 @@ public static void sendMessage(String message, LivingEntity recipient, SpellData
15841610
15851611 message = doReplacements (message , recipient , data , replacements );
15861612
1587- recipient .sendMessage (Util .getMiniMessage ( getTextColor () + message ));
1613+ recipient .sendMessage (Util .getMessageText ( message ));
15881614 }
15891615
15901616 private static final Pattern chatVarMatchPattern = Pattern .compile ("%var:(\\ w+)(?::(\\ d+))?%" , Pattern .CASE_INSENSITIVE | Pattern .MULTILINE );
@@ -1898,13 +1924,13 @@ public static boolean requireReplacement(String message) {
18981924 public static String getTargetName (Entity target ) {
18991925 if (target instanceof Player ) return target .getName ();
19001926
1901- if (target .customName () != null ) return Util .getStrictStringFromComponent (target .customName ());
1927+ if (target .customName () != null ) return Util .getStrictString (target .customName ());
19021928
19031929 EntityType type = target .getType ();
19041930 String name = plugin .entityNames .get (type );
19051931 if (name != null ) return name ;
19061932
1907- return Util .getStrictStringFromComponent (target .name ());
1933+ return Util .getStrictString (target .name ());
19081934 }
19091935
19101936 public static void registerEvents (final Listener listener ) {
0 commit comments