Skip to content

Commit 71e9ac1

Browse files
Transition commands from ACF to Cloud
1 parent 8797c03 commit 71e9ac1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2999
-1307
lines changed

buildSrc/src/main/java/dev/magicspells/gradle/MSJavaPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public void apply(Project target) {
2727
"https://repo.dmulloy2.net/nexus/repository/public/",
2828
"https://repo.md-5.net/content/repositories/releases/",
2929
"https://repo.papermc.io/repository/maven-public/",
30-
"https://repo.aikar.co/content/groups/aikar/",
3130
"https://oss.sonatype.org/content/repositories/central",
3231
"https://oss.sonatype.org/content/repositories/snapshots",
3332
"https://hub.spigotmc.org/nexus/content/repositories/snapshots/",

core/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ plugins {
66
dependencies {
77
shadow(group: "org.apache.commons", name: "commons-math4-core", version: "4.0-beta1")
88
shadow(group: "com.github.Chronoken", name: "EffectLib", version: "753da6c")
9-
shadow(group: "co.aikar", name: "acf-paper", version: "0.5.1-SNAPSHOT")
9+
shadow(group: "org.incendo", name: "cloud-paper", version: "2.0.0-beta.10")
10+
shadow(group: "org.incendo", name: "cloud-minecraft-extras", version: "2.0.0-beta.10")
11+
shadow(group: "org.incendo", name: "cloud-processors-requirements", version: "1.0.0-rc.1")
1012
shadow(group: "org.bstats", name: "bstats-bukkit", version: "3.0.2")
1113

1214
shadow(group: "org.antlr", name: "antlr4-runtime", version: "4.13.2")
@@ -50,8 +52,10 @@ shadowJar {
5052

5153
relocate("org.apache.commons.math4", "com.nisovin.magicspells.shaded.org.apache.commons.math4")
5254
relocate("de.slikey.effectlib", "com.nisovin.magicspells.shaded.effectlib")
53-
relocate("co.aikar.commands", "com.nisovin.magicspells.shaded.acf")
54-
relocate("co.aikar.locales", "com.nisovin.magicspells.shaded.locales")
55+
relocate("org.incendo.cloud", "com.nisovin.magicspells.shaded.cloud")
56+
relocate("io.leangen.geantyref", "com.nisovin.magicspells.shaded.geantyref")
57+
relocate("xyz.jpenilla.reflectionremapper", "com.nisovin.magicspells.shaded.reflectionremapper")
58+
relocate("net.fabricmc.mappingio", "com.nisovin.magicspells.shaded.mappingio")
5559
relocate("org.bstats", "com.nisovin.magicspells.shaded.bstats")
5660

5761
// Included by apache/commons-math, copied by this project.

core/src/main/java/com/nisovin/magicspells/MagicSpells.java

Lines changed: 101 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.nisovin.magicspells;
22

3+
import net.kyori.adventure.text.format.Style;
4+
import net.kyori.adventure.text.format.TextDecoration;
5+
import org.jetbrains.annotations.NotNull;
6+
37
import java.io.*;
48

59
import java.util.*;
@@ -25,17 +29,16 @@
2529
import com.google.common.collect.SetMultimap;
2630
import com.google.common.collect.LinkedHashMultimap;
2731

32+
import net.kyori.adventure.text.format.TextColor;
33+
import net.kyori.adventure.text.format.NamedTextColor;
34+
2835
import de.slikey.effectlib.EffectManager;
2936

3037
import org.bstats.bukkit.Metrics;
3138
import org.bstats.charts.SimplePie;
3239
import org.bstats.charts.AdvancedPie;
3340
import org.bstats.charts.DrilldownPie;
3441

35-
import org.jetbrains.annotations.NotNull;
36-
37-
import co.aikar.commands.PaperCommandManager;
38-
3942
import org.bukkit.*;
4043
import org.bukkit.event.Event;
4144
import org.bukkit.entity.Entity;
@@ -53,6 +56,11 @@
5356
import org.bukkit.permissions.PermissionDefault;
5457
import org.bukkit.configuration.ConfigurationSection;
5558

59+
import io.papermc.paper.command.brigadier.CommandSourceStack;
60+
61+
import org.incendo.cloud.paper.PaperCommandManager;
62+
import org.incendo.cloud.execution.ExecutionCoordinator;
63+
5664
import me.clip.placeholderapi.PlaceholderAPI;
5765

5866
import com.nisovin.magicspells.util.*;
@@ -64,16 +72,15 @@
6472
import com.nisovin.magicspells.mana.ManaHandler;
6573
import com.nisovin.magicspells.variables.Variable;
6674
import com.nisovin.magicspells.spells.PassiveSpell;
67-
import com.nisovin.magicspells.commands.MagicCommand;
6875
import com.nisovin.magicspells.util.compat.EventUtil;
76+
import com.nisovin.magicspells.commands.MagicCommands;
6977
import com.nisovin.magicspells.storage.StorageHandler;
7078
import com.nisovin.magicspells.util.prompt.PromptType;
7179
import com.nisovin.magicspells.util.compat.CompatBasics;
7280
import com.nisovin.magicspells.zones.NoMagicZoneManager;
7381
import com.nisovin.magicspells.spelleffects.SpellEffect;
7482
import com.nisovin.magicspells.util.magicitems.MagicItem;
7583
import com.nisovin.magicspells.castmodifiers.ModifierSet;
76-
import com.nisovin.magicspells.commands.CommandHelpFilter;
7784
import com.nisovin.magicspells.util.magicitems.MagicItems;
7885
import com.nisovin.magicspells.util.recipes.CustomRecipes;
7986
import com.nisovin.magicspells.util.ai.CustomGoalsManager;
@@ -140,7 +147,8 @@ public class MagicSpells extends JavaPlugin {
140147
private NoMagicZoneManager zoneManager;
141148
private CleanserManager cleanserManager;
142149
private CustomGoalsManager customGoalsManager;
143-
private PaperCommandManager commandManager;
150+
@SuppressWarnings("UnstableApiUsage")
151+
private PaperCommandManager<CommandSourceStack> commandManager;
144152
private ExperienceBarManager expBarManager;
145153

146154
private MagicConfig config;
@@ -209,7 +217,7 @@ public class MagicSpells extends JavaPlugin {
209217

210218
private long lastReloadTime = 0;
211219

212-
private ChatColor textColor;
220+
private Style textStyle;
213221

214222
private double losRaySize;
215223
private boolean losIgnorePassableBlocks;
@@ -235,45 +243,8 @@ public class MagicSpells extends JavaPlugin {
235243
@Override
236244
public void onEnable() {
237245
load();
238-
239-
Metrics metrics = new Metrics(this, 892);
240-
241-
metrics.addCustomChart(new DrilldownPie("spells", () -> {
242-
Map<String, Map<String, Integer>> map = new HashMap<>();
243-
if (spells == null) return map;
244-
245-
for (Spell spell : spells.values()) {
246-
String name = spell.getClass().getName();
247-
if (!name.startsWith("com.nisovin.magicspells.spells")) continue;
248-
name = name.replace("com.nisovin.magicspells.spells.", "");
249-
250-
String[] typeSplit = name.split("\\.", 2);
251-
String formalPackage = typeSplit[0].substring(0, 1).toUpperCase() + typeSplit[0].substring(1);
252-
253-
String spellPackage = (typeSplit.length == 1 ? "General" : formalPackage) + " Spells";
254-
String spellClass = typeSplit.length == 1 ? typeSplit[0] : typeSplit[1];
255-
256-
map.computeIfAbsent(spellPackage, key -> new HashMap<>());
257-
map.get(spellPackage).compute(spellClass, (k, v) -> (v == null ? 0 : v) + 1);
258-
}
259-
return map;
260-
}));
261-
metrics.addCustomChart(new AdvancedPie("passive_listeners", () -> {
262-
IntMap<String> map = new IntMap<>();
263-
if (spells == null) return map;
264-
265-
for (Spell spell : spells.values()) {
266-
if (!spell.getClass().getName().startsWith("com.nisovin.magicspells.spells")) continue;
267-
if (!(spell instanceof PassiveSpell passiveSpell)) continue;
268-
269-
for (PassiveListener listener : passiveSpell.getPassiveListeners()) {
270-
String name = listener.getClass().getSimpleName();
271-
map.increment(name.substring(0, name.lastIndexOf("Listener")));
272-
}
273-
}
274-
return map;
275-
}));
276-
metrics.addCustomChart(new SimplePie("reload_time", () -> "<" + (lastReloadTime - lastReloadTime % 500 + 500) + " ms"));
246+
initMetrics();
247+
initCommands();
277248
}
278249

279250
public void load() {
@@ -284,8 +255,6 @@ public void load() {
284255
effectManager = new EffectManager(this);
285256
effectManager.enableDebug(debug);
286257

287-
commandManager = new PaperCommandManager(plugin);
288-
289258
// Create storage stuff
290259
spells = new HashMap<>();
291260
spellNames = new HashMap<>();
@@ -331,7 +300,6 @@ public void load() {
331300
enableErrorLogging = config.getBoolean(path + "enable-error-logging", true);
332301
errorLogLimit = config.getInt(path + "error-log-limit", -1);
333302
enableProfiling = config.getBoolean(path + "enable-profiling", false);
334-
textColor = ChatColor.getByChar(config.getString(path + "text-color", ChatColor.DARK_AQUA.getChar() + ""));
335303
broadcastRange = config.getInt(path + "broadcast-range", 20);
336304
effectlibInstanceLimit = config.getInt(path + "effectlib-instance-limit", 20000);
337305

@@ -402,6 +370,8 @@ public void load() {
402370
}
403371
}
404372

373+
textStyle = Util.getStyle(config.getString(path + "text-style", config.getString("text-color", null)), Style.style(NamedTextColor.DARK_AQUA));
374+
405375
soundFailOnCooldown = config.getString(path + "sound-on-cooldown", null);
406376
soundFailMissingReagents = config.getString(path + "sound-missing-reagents", null);
407377

@@ -574,12 +544,6 @@ public void load() {
574544
magicLogger = new MagicLogger(this);
575545
}
576546

577-
// Register commands
578-
commandManager.enableUnstableAPI("help");
579-
commandManager.registerCommand(new MagicCommand());
580-
commandManager.setValidNamePredicate(string -> true);
581-
CommandHelpFilter.mapPerms();
582-
583547
// Setup profiling
584548
if (enableProfiling) {
585549
profilingTotalTime = new HashMap<>();
@@ -592,6 +556,56 @@ public void load() {
592556
Bukkit.getScheduler().runTaskLater(this, this::loadExternalData, 1);
593557
}
594558

559+
private void initMetrics() {
560+
Metrics metrics = new Metrics(this, 892);
561+
562+
metrics.addCustomChart(new DrilldownPie("spells", () -> {
563+
Map<String, Map<String, Integer>> map = new HashMap<>();
564+
if (spells == null) return map;
565+
566+
for (Spell spell : spells.values()) {
567+
String name = spell.getClass().getName();
568+
if (!name.startsWith("com.nisovin.magicspells.spells")) continue;
569+
name = name.replace("com.nisovin.magicspells.spells.", "");
570+
571+
String[] typeSplit = name.split("\\.", 2);
572+
String formalPackage = typeSplit[0].substring(0, 1).toUpperCase() + typeSplit[0].substring(1);
573+
574+
String spellPackage = (typeSplit.length == 1 ? "General" : formalPackage) + " Spells";
575+
String spellClass = typeSplit.length == 1 ? typeSplit[0] : typeSplit[1];
576+
577+
map.computeIfAbsent(spellPackage, key -> new HashMap<>());
578+
map.get(spellPackage).compute(spellClass, (k, v) -> (v == null ? 0 : v) + 1);
579+
}
580+
return map;
581+
}));
582+
metrics.addCustomChart(new AdvancedPie("passive_listeners", () -> {
583+
IntMap<String> map = new IntMap<>();
584+
if (spells == null) return map;
585+
586+
for (Spell spell : spells.values()) {
587+
if (!spell.getClass().getName().startsWith("com.nisovin.magicspells.spells")) continue;
588+
if (!(spell instanceof PassiveSpell passiveSpell)) continue;
589+
590+
for (PassiveListener listener : passiveSpell.getPassiveListeners()) {
591+
String name = listener.getClass().getSimpleName();
592+
map.increment(name.substring(0, name.lastIndexOf("Listener")));
593+
}
594+
}
595+
return map;
596+
}));
597+
metrics.addCustomChart(new SimplePie("reload_time", () -> "<" + (lastReloadTime - lastReloadTime % 500 + 500) + " ms"));
598+
}
599+
600+
@SuppressWarnings("UnstableApiUsage")
601+
private void initCommands() {
602+
commandManager = PaperCommandManager.builder()
603+
.executionCoordinator(ExecutionCoordinator.simpleCoordinator())
604+
.buildOnEnable(this);
605+
606+
MagicCommands.register(commandManager);
607+
}
608+
595609
private void initializeSpells() {
596610
log("Initializing spells...");
597611

@@ -1081,8 +1095,31 @@ public static Spellbook getSpellbook(Player player) {
10811095
return plugin.spellbooks.computeIfAbsent(player.getName(), playerName -> new Spellbook(player));
10821096
}
10831097

1098+
@Deprecated(forRemoval = true)
10841099
public static ChatColor getTextColor() {
1085-
return plugin.textColor;
1100+
TextColor color = plugin.textStyle.color();
1101+
if (color != null) {
1102+
NamedTextColor nearest = NamedTextColor.nearestTo(color);
1103+
return ChatColor.valueOf(nearest.toString().toUpperCase());
1104+
}
1105+
1106+
return plugin.textStyle.decorations().entrySet().stream()
1107+
.filter(entry -> entry.getValue() == TextDecoration.State.TRUE)
1108+
.map(Map.Entry::getKey)
1109+
.sorted()
1110+
.findFirst()
1111+
.map(decoration -> switch (decoration) {
1112+
case OBFUSCATED -> ChatColor.MAGIC;
1113+
case BOLD -> ChatColor.BOLD;
1114+
case STRIKETHROUGH -> ChatColor.STRIKETHROUGH;
1115+
case UNDERLINED -> ChatColor.UNDERLINE;
1116+
case ITALIC -> ChatColor.ITALIC;
1117+
})
1118+
.orElse(ChatColor.DARK_AQUA);
1119+
}
1120+
1121+
public static Style getTextStyle() {
1122+
return plugin.textStyle;
10861123
}
10871124

10881125
/**
@@ -1250,6 +1287,10 @@ public static int getDebugLevelOriginal() {
12501287
return plugin.debugLevelOriginal;
12511288
}
12521289

1290+
public static int getDebugLevel() {
1291+
return plugin.debugLevel;
1292+
}
1293+
12531294
public static int getErrorLogLimit() {
12541295
return plugin.errorLogLimit;
12551296
}
@@ -1584,7 +1625,7 @@ public static void sendMessage(String message, LivingEntity recipient, SpellData
15841625

15851626
message = doReplacements(message, recipient, data, replacements);
15861627

1587-
recipient.sendMessage(Util.getMiniMessage(getTextColor() + message));
1628+
recipient.sendMessage(Util.getMiniMessage(message).applyFallbackStyle(MagicSpells.getTextStyle()));
15881629
}
15891630

15901631
private static final Pattern chatVarMatchPattern = Pattern.compile("%var:(\\w+)(?::(\\d+))?%", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
@@ -1889,13 +1930,13 @@ public static boolean requireReplacement(String message) {
18891930
public static String getTargetName(Entity target) {
18901931
if (target instanceof Player) return target.getName();
18911932

1892-
if (target.customName() != null) return Util.getStrictStringFromComponent(target.customName());
1933+
if (target.customName() != null) return Util.getStrictString(target.customName());
18931934

18941935
EntityType type = target.getType();
18951936
String name = plugin.entityNames.get(type);
18961937
if (name != null) return name;
18971938

1898-
return Util.getStrictStringFromComponent(target.name());
1939+
return Util.getStrictString(target.name());
18991940
}
19001941

19011942
public static void registerEvents(final Listener listener) {

core/src/main/java/com/nisovin/magicspells/Perm.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.nisovin.magicspells;
22

3+
import org.checkerframework.checker.nullness.qual.NonNull;
4+
35
import org.bukkit.permissions.Permissible;
46

5-
public enum Perm {
7+
import org.incendo.cloud.permission.Permission;
8+
9+
public enum Perm implements Permission {
610

711
SILENT("magicspells.silent"),
812
NO_REAGENTS("magicspells.noreagents"),
@@ -99,5 +103,10 @@ public boolean has(Permissible permissible, Spell spell) {
99103
if (requiresNode() && !permissible.hasPermission(getNode(spell))) return false;
100104
return true;
101105
}
102-
106+
107+
@Override
108+
public @NonNull String permissionString() {
109+
return node;
110+
}
111+
103112
}

core/src/main/java/com/nisovin/magicspells/Spell.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import com.google.common.collect.*;
1717
import com.google.common.base.Functions;
1818

19+
import org.incendo.cloud.suggestion.SuggestionProvider;
20+
1921
import org.bukkit.*;
2022
import org.bukkit.entity.*;
2123
import org.bukkit.util.Vector;
@@ -47,6 +49,7 @@
4749
import io.papermc.paper.registry.RegistryKey;
4850
import io.papermc.paper.block.fluid.FluidData;
4951
import io.papermc.paper.registry.RegistryAccess;
52+
import io.papermc.paper.command.brigadier.CommandSourceStack;
5053

5154
import com.nisovin.magicspells.util.*;
5255
import com.nisovin.magicspells.events.*;
@@ -287,7 +290,7 @@ public Spell(MagicConfig config, String spellName) {
287290
if (spellIcon != null && !spellIcon.getType().isAir()) {
288291
if (!magicItem.getMagicItemData().hasAttribute(MagicItemData.MagicItemAttribute.NAME)) {
289292
ItemMeta iconMeta = spellIcon.getItemMeta();
290-
iconMeta.displayName(Component.text(MagicSpells.getTextColor() + name));
293+
iconMeta.displayName(Util.getMiniMessage(name).applyFallbackStyle(MagicSpells.getTextStyle()));
291294
spellIcon.setItemMeta(iconMeta);
292295
}
293296
}
@@ -1226,8 +1229,9 @@ protected boolean preCastTimeCheck(LivingEntity livingEntity, String[] args) {
12261229
return true;
12271230
}
12281231

1229-
public List<String> tabComplete(CommandSender sender, String[] args) {
1230-
return null;
1232+
@SuppressWarnings({"UnstableApiUsage", "unchecked"})
1233+
public SuggestionProvider<CommandSourceStack> suggestionProvider() {
1234+
return this instanceof SuggestionProvider ? (SuggestionProvider<CommandSourceStack>) this : SuggestionProvider.noSuggestions();
12311235
}
12321236

12331237
// TODO can this safely be made varargs?
@@ -1266,6 +1270,10 @@ public boolean isIgnoringGlobalCooldown() {
12661270
return ignoreGlobalCooldown;
12671271
}
12681272

1273+
public boolean isRequiringCastItemOnCommand() {
1274+
return requireCastItemOnCommand;
1275+
}
1276+
12691277
public boolean isValidItemForCastCommand(ItemStack item) {
12701278
if (!requireCastItemOnCommand || castItems == null) return true;
12711279
if (item == null && castItems.length == 1 && castItems[0].getType().isAir()) return true;

0 commit comments

Comments
 (0)