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,7 @@ public class MagicSpells extends JavaPlugin {
141145 private NoMagicZoneManager zoneManager ;
142146 private CleanserManager cleanserManager ;
143147 private CustomGoalsManager customGoalsManager ;
144- private PaperCommandManager commandManager ;
148+ private PaperCommandManager < CommandSourceStack > commandManager ;
145149 private ExperienceBarManager expBarManager ;
146150
147151 private ExpressionDictionary expressionDictionary ;
@@ -212,7 +216,8 @@ public class MagicSpells extends JavaPlugin {
212216
213217 private long lastReloadTime = 0 ;
214218
215- private ChatColor textColor ;
219+ private NamedTextColor textColor ;
220+ private String textFormat ;
216221
217222 private double losRaySize ;
218223 private boolean losIgnorePassableBlocks ;
@@ -238,45 +243,8 @@ public class MagicSpells extends JavaPlugin {
238243 @ Override
239244 public void onEnable () {
240245 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" ));
246+ initMetrics ();
247+ initCommands ();
280248 }
281249
282250 public void load () {
@@ -287,8 +255,6 @@ public void load() {
287255 effectManager = new EffectManager (this );
288256 effectManager .enableDebug (debug );
289257
290- commandManager = new PaperCommandManager (plugin );
291-
292258 // Create storage stuff
293259 spells = new HashMap <>();
294260 spellNames = new HashMap <>();
@@ -334,7 +300,6 @@ public void load() {
334300 enableErrorLogging = config .getBoolean (path + "enable-error-logging" , true );
335301 errorLogLimit = config .getInt (path + "error-log-limit" , -1 );
336302 enableProfiling = config .getBoolean (path + "enable-profiling" , false );
337- textColor = ChatColor .getByChar (config .getString (path + "text-color" , ChatColor .DARK_AQUA .getChar () + "" ));
338303 broadcastRange = config .getInt (path + "broadcast-range" , 20 );
339304 effectlibInstanceLimit = config .getInt (path + "effectlib-instance-limit" , 20000 );
340305
@@ -405,6 +370,9 @@ public void load() {
405370 }
406371 }
407372
373+ textColor = Util .getLegacyColor (config .getString ("text-color" , null ), NamedTextColor .DARK_AQUA );
374+ textFormat = config .getString ("text-format" , "<" + textColor + "><text></" + textColor + ">" );
375+
408376 soundFailOnCooldown = config .getString (path + "sound-on-cooldown" , null );
409377 soundFailMissingReagents = config .getString (path + "sound-missing-reagents" , null );
410378
@@ -570,12 +538,6 @@ public void load() {
570538 magicLogger = new MagicLogger (this );
571539 }
572540
573- // Register commands
574- commandManager .enableUnstableAPI ("help" );
575- commandManager .registerCommand (new MagicCommand ());
576- commandManager .setValidNamePredicate (string -> true );
577- CommandHelpFilter .mapPerms ();
578-
579541 // Setup profiling
580542 if (enableProfiling ) {
581543 profilingTotalTime = new HashMap <>();
@@ -588,6 +550,55 @@ public void load() {
588550 Bukkit .getScheduler ().runTaskLater (this , this ::loadExternalData , 1 );
589551 }
590552
553+ private void initMetrics () {
554+ Metrics metrics = new Metrics (this , 892 );
555+
556+ metrics .addCustomChart (new DrilldownPie ("spells" , () -> {
557+ Map <String , Map <String , Integer >> map = new HashMap <>();
558+ if (spells == null ) return map ;
559+
560+ for (Spell spell : spells .values ()) {
561+ String name = spell .getClass ().getName ();
562+ if (!name .startsWith ("com.nisovin.magicspells.spells" )) continue ;
563+ name = name .replace ("com.nisovin.magicspells.spells." , "" );
564+
565+ String [] typeSplit = name .split ("\\ ." , 2 );
566+ String formalPackage = typeSplit [0 ].substring (0 , 1 ).toUpperCase () + typeSplit [0 ].substring (1 );
567+
568+ String spellPackage = (typeSplit .length == 1 ? "General" : formalPackage ) + " Spells" ;
569+ String spellClass = typeSplit .length == 1 ? typeSplit [0 ] : typeSplit [1 ];
570+
571+ map .computeIfAbsent (spellPackage , key -> new HashMap <>());
572+ map .get (spellPackage ).compute (spellClass , (k , v ) -> (v == null ? 0 : v ) + 1 );
573+ }
574+ return map ;
575+ }));
576+ metrics .addCustomChart (new AdvancedPie ("passive_listeners" , () -> {
577+ IntMap <String > map = new IntMap <>();
578+ if (spells == null ) return map ;
579+
580+ for (Spell spell : spells .values ()) {
581+ if (!spell .getClass ().getName ().startsWith ("com.nisovin.magicspells.spells" )) continue ;
582+ if (!(spell instanceof PassiveSpell passiveSpell )) continue ;
583+
584+ for (PassiveListener listener : passiveSpell .getPassiveListeners ()) {
585+ String name = listener .getClass ().getSimpleName ();
586+ map .increment (name .substring (0 , name .lastIndexOf ("Listener" )));
587+ }
588+ }
589+ return map ;
590+ }));
591+ metrics .addCustomChart (new SimplePie ("reload_time" , () -> "<" + (lastReloadTime - lastReloadTime % 500 + 500 ) + " ms" ));
592+ }
593+
594+ private void initCommands () {
595+ commandManager = PaperCommandManager .builder ()
596+ .executionCoordinator (ExecutionCoordinator .simpleCoordinator ())
597+ .buildOnEnable (this );
598+
599+ MagicCommands .register (commandManager );
600+ }
601+
591602 private void initializeSpells () {
592603 log ("Initializing spells..." );
593604
@@ -1077,10 +1088,19 @@ public static Spellbook getSpellbook(Player player) {
10771088 return plugin .spellbooks .computeIfAbsent (player .getUniqueId (), uuid -> new Spellbook (player ));
10781089 }
10791090
1091+ @ Deprecated (forRemoval = true )
10801092 public static ChatColor getTextColor () {
1093+ return ChatColor .valueOf (plugin .textColor .toString ().toUpperCase ());
1094+ }
1095+
1096+ public static NamedTextColor getLegacyTextColor () {
10811097 return plugin .textColor ;
10821098 }
10831099
1100+ public static String getTextFormat () {
1101+ return plugin .textFormat ;
1102+ }
1103+
10841104 /**
10851105 * Gets a list of blocks that are considered transparent
10861106 * @return set of block types
@@ -1246,6 +1266,10 @@ public static int getDebugLevelOriginal() {
12461266 return plugin .debugLevelOriginal ;
12471267 }
12481268
1269+ public static int getDebugLevel () {
1270+ return plugin .debugLevel ;
1271+ }
1272+
12491273 public static int getErrorLogLimit () {
12501274 return plugin .errorLogLimit ;
12511275 }
@@ -1584,7 +1608,7 @@ public static void sendMessage(String message, LivingEntity recipient, SpellData
15841608
15851609 message = doReplacements (message , recipient , data , replacements );
15861610
1587- recipient .sendMessage (Util .getMiniMessage ( getTextColor () + message ));
1611+ recipient .sendMessage (Util .getMessageText ( message ));
15881612 }
15891613
15901614 private static final Pattern chatVarMatchPattern = Pattern .compile ("%var:(\\ w+)(?::(\\ d+))?%" , Pattern .CASE_INSENSITIVE | Pattern .MULTILINE );
@@ -1898,13 +1922,13 @@ public static boolean requireReplacement(String message) {
18981922 public static String getTargetName (Entity target ) {
18991923 if (target instanceof Player ) return target .getName ();
19001924
1901- if (target .customName () != null ) return Util .getStrictStringFromComponent (target .customName ());
1925+ if (target .customName () != null ) return Util .getStrictString (target .customName ());
19021926
19031927 EntityType type = target .getType ();
19041928 String name = plugin .entityNames .get (type );
19051929 if (name != null ) return name ;
19061930
1907- return Util .getStrictStringFromComponent (target .name ());
1931+ return Util .getStrictString (target .name ());
19081932 }
19091933
19101934 public static void registerEvents (final Listener listener ) {
0 commit comments