Skip to content

Commit 590ec57

Browse files
Merge pull request #991 from TonytheMacaroni/glow-spell
Add GlowSpell
2 parents 332bf24 + 2a71c76 commit 590ec57

File tree

21 files changed

+1527
-16
lines changed

21 files changed

+1527
-16
lines changed

NOTICE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ The project includes software developed by third parties. For their full license
5050
- XGlow:
5151
- Repository: `Xezard/XGlow`
5252
- License: **Apache-2.0 License** (See `3rd_party_licenses/LICENSE-Apache_v2`)
53+
54+
- packetevents:
55+
- Repository: `retrooper/packetevents`
56+
- License: **General Public License v3.0** (See `3rd_party_licenses/LICENSE-GPLv3`)

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@ public void apply(Project target) {
2424
repositories.mavenCentral();
2525

2626
String[] mavenUrls = new String[] {
27-
"https://repo.dmulloy2.net/nexus/repository/public/",
28-
"https://repo.md-5.net/content/repositories/releases/",
29-
"https://repo.papermc.io/repository/maven-public/",
30-
"https://repo.aikar.co/content/groups/aikar/",
31-
"https://oss.sonatype.org/content/repositories/central",
32-
"https://oss.sonatype.org/content/repositories/snapshots",
33-
"https://hub.spigotmc.org/nexus/content/repositories/snapshots/",
34-
"https://jitpack.io",
35-
"https://repo.codemc.org/repository/maven-public",
36-
"https://cdn.rawgit.com/Rayzr522/maven-repo/master/",
37-
"https://maven.enginehub.org/repo/",
38-
"https://repo.glaremasters.me/repository/towny/",
39-
"https://repo.extendedclip.com/content/repositories/placeholderapi"
27+
"https://repo.dmulloy2.net/nexus/repository/public/",
28+
"https://repo.md-5.net/content/repositories/releases/",
29+
"https://repo.papermc.io/repository/maven-public/",
30+
"https://repo.aikar.co/content/groups/aikar/",
31+
"https://oss.sonatype.org/content/repositories/central",
32+
"https://oss.sonatype.org/content/repositories/snapshots",
33+
"https://hub.spigotmc.org/nexus/content/repositories/snapshots/",
34+
"https://jitpack.io",
35+
"https://repo.codemc.org/repository/maven-public",
36+
"https://cdn.rawgit.com/Rayzr522/maven-repo/master/",
37+
"https://maven.enginehub.org/repo/",
38+
"https://repo.glaremasters.me/repository/towny/",
39+
"https://repo.extendedclip.com/content/repositories/placeholderapi",
40+
"https://repo.md-5.net/content/repositories/snapshots",
4041
};
4142
for (String url : mavenUrls) {
4243
repositories.maven(mavenArtifactRepository -> mavenArtifactRepository.setUrl(url));

core/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ dependencies {
1515
shadow(project(path: ":nms:shared", configuration: "apiElements"))
1616
shadow(project(path: ":nms:latest")) { transitive = false }
1717

18+
implementation(group: "com.github.retrooper", name: "packetevents-spigot", version: "2.7.0")
1819
implementation(group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.3.0") { transitive = false }
19-
implementation(group: "com.github.libraryaddict", name: "LibsDisguises", version: "v10.0.25") { transitive = false }
20+
implementation(group: "me.libraryaddict.disguises", name: "libsdisguises", version: "10.0.44-SNAPSHOT") { transitive = false }
2021
implementation(group: "net.milkbowl.vault", name: "VaultAPI", version: "1.7") { transitive = false }
2122
implementation(group: "me.clip", name: "placeholderapi", version: "2.11.6") { transitive = false }
2223
implementation(group: "com.github.GriefPrevention", name: "GriefPrevention", version: "17.0.0") { transitive = false }

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.nio.file.Path;
2020
import java.nio.file.Files;
2121

22+
import com.google.common.collect.Sets;
2223
import com.google.common.collect.SetMultimap;
2324
import com.google.common.collect.LinkedHashMultimap;
2425

@@ -1869,9 +1870,13 @@ public static void registerEvents(final Listener listener) {
18691870

18701871
public static void registerEvents(final Listener listener, EventPriority customPriority) {
18711872
if (customPriority == null) customPriority = EventPriority.NORMAL;
1872-
Method[] methods;
1873+
Set<Method> methods;
18731874
try {
1874-
methods = listener.getClass().getDeclaredMethods();
1875+
Class<?> listenerClazz = listener.getClass();
1876+
methods = Sets.union(
1877+
Set.of(listenerClazz.getMethods()),
1878+
Set.of(listenerClazz.getDeclaredMethods())
1879+
);
18751880
} catch (NoClassDefFoundError e) {
18761881
DebugHandler.debugNoClassDefFoundError(e);
18771882
return;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import net.kyori.adventure.key.Key;
99
import net.kyori.adventure.text.Component;
10+
import net.kyori.adventure.text.format.NamedTextColor;
1011

1112
import java.util.*;
1213
import java.util.function.Predicate;
@@ -938,6 +939,14 @@ protected <T extends Keyed> ConfigData<T> getConfigDataRegistryEntry(@NotNull St
938939
return ConfigDataUtil.getRegistryEntry(config.getMainConfig(), internalKey + key, registry, def);
939940
}
940941

942+
protected ConfigData<NamedTextColor> getConfigDataNamedTextColor(String key, NamedTextColor def) {
943+
return ConfigDataUtil.getNamedTextColor(config.getMainConfig(), internalKey + key, def);
944+
}
945+
946+
protected ConfigData<NamespacedKey> getConfigDataNamespacedKey(String key, NamespacedKey def) {
947+
return ConfigDataUtil.getNamespacedKey(config.getMainConfig(), internalKey + key, def);
948+
}
949+
941950
/**
942951
* @param key Path for the string or section format SpellFilter to be read from.
943952
*/
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.nisovin.magicspells.spells.targeted;
2+
3+
import java.util.UUID;
4+
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.entity.Player;
7+
import org.bukkit.NamespacedKey;
8+
import org.bukkit.entity.LivingEntity;
9+
10+
import net.kyori.adventure.text.format.NamedTextColor;
11+
12+
import com.nisovin.magicspells.MagicSpells;
13+
import com.nisovin.magicspells.util.SpellData;
14+
import com.nisovin.magicspells.util.CastResult;
15+
import com.nisovin.magicspells.util.TargetInfo;
16+
import com.nisovin.magicspells.util.MagicConfig;
17+
import com.nisovin.magicspells.spells.TargetedSpell;
18+
import com.nisovin.magicspells.util.config.ConfigData;
19+
import com.nisovin.magicspells.util.glow.GlowManager;
20+
import com.nisovin.magicspells.spells.TargetedEntitySpell;
21+
import com.nisovin.magicspells.util.glow.impl.PacketEventsGlowManager;
22+
23+
public class GlowSpell extends TargetedSpell implements TargetedEntitySpell {
24+
25+
private static GlowManager glowManager;
26+
27+
private final ConfigData<Boolean> global;
28+
private final ConfigData<Boolean> remove;
29+
private final ConfigData<Integer> duration;
30+
private final ConfigData<Integer> priority;
31+
private final ConfigData<NamespacedKey> key;
32+
private final ConfigData<NamedTextColor> color;
33+
34+
public GlowSpell(MagicConfig config, String spellName) {
35+
super(config, spellName);
36+
37+
key = getConfigDataNamespacedKey("key", null);
38+
color = getConfigDataNamedTextColor("color", null);
39+
global = getConfigDataBoolean("global", true);
40+
remove = getConfigDataBoolean("remove", false);
41+
duration = getConfigDataInt("duration", 0);
42+
priority = getConfigDataInt("priority", 0);
43+
44+
if (glowManager == null) {
45+
if (Bukkit.getPluginManager().isPluginEnabled("packetevents")) glowManager = new PacketEventsGlowManager();
46+
else glowManager = MagicSpells.getVolatileCodeHandler().getGlowManager();
47+
48+
glowManager.load();
49+
}
50+
}
51+
52+
@Override
53+
public CastResult cast(SpellData data) {
54+
TargetInfo<LivingEntity> info = getTargetedEntity(data);
55+
if (info.noTarget()) return noTarget(info);
56+
57+
return castAtEntity(info.spellData());
58+
}
59+
60+
@Override
61+
public CastResult castAtEntity(SpellData data) {
62+
if (global.get(data)) {
63+
NamespacedKey key = this.key.get(data);
64+
65+
if (remove.get(data)) {
66+
if (key == null) return new CastResult(PostCastAction.ALREADY_HANDLED, data);
67+
68+
glowManager.removeGlow(data.target(), key);
69+
} else {
70+
glowManager.applyGlow(
71+
data.target(),
72+
key != null ? key : new NamespacedKey(MagicSpells.getInstance(), UUID.randomUUID().toString()),
73+
color.get(data),
74+
priority.get(data),
75+
duration.get(data)
76+
);
77+
}
78+
79+
playSpellEffects(data);
80+
return new CastResult(PostCastAction.HANDLE_NORMALLY, data);
81+
}
82+
83+
if (!(data.caster() instanceof Player caster)) return new CastResult(PostCastAction.ALREADY_HANDLED, data);
84+
85+
NamespacedKey key = this.key.get(data);
86+
87+
if (remove.get(data)) {
88+
if (key == null) return new CastResult(PostCastAction.ALREADY_HANDLED, data);
89+
90+
glowManager.removeGlow(caster, data.target(), key);
91+
} else {
92+
glowManager.applyGlow(
93+
caster,
94+
data.target(),
95+
key != null ? key : new NamespacedKey(MagicSpells.getInstance(), UUID.randomUUID().toString()),
96+
color.get(data),
97+
priority.get(data),
98+
duration.get(data)
99+
);
100+
}
101+
102+
playSpellEffects(data);
103+
return new CastResult(PostCastAction.HANDLE_NORMALLY, data);
104+
}
105+
106+
@Override
107+
protected void turnOff() {
108+
if (glowManager == null) return;
109+
110+
glowManager.unload();
111+
glowManager = null;
112+
}
113+
114+
}

core/src/main/java/com/nisovin/magicspells/spells/targeted/ext/GlowSpell.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
@DependsOn({"ProtocolLib", "XGlow"})
2626
public class GlowSpell extends TargetedSpell implements TargetedEntitySpell {
2727

28+
private static final DeprecationNotice DEPRECATION_NOTICE = new DeprecationNotice(
29+
"The '.targeted.ext.GlowSpell' spell class does not function, as the XGlow plugin is abandoned.",
30+
"Use the '.targeted.GlowSpell' spell class."
31+
);
32+
2833
private final Multimap<UUID, GlowData> glowing;
2934

3035
private final ConfigData<ChatColor> color;
@@ -43,6 +48,8 @@ public GlowSpell(MagicConfig config, String spellName) {
4348
powerAffectsDuration = getConfigDataBoolean("power-affects-duration", true);
4449

4550
color = getConfigDataEnum("color", ChatColor.class, ChatColor.WHITE);
51+
52+
MagicSpells.getDeprecationManager().addDeprecation(this, DEPRECATION_NOTICE);
4653
}
4754

4855
@Override

core/src/main/java/com/nisovin/magicspells/util/config/ConfigDataUtil.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.jetbrains.annotations.Nullable;
88

99
import net.kyori.adventure.text.Component;
10+
import net.kyori.adventure.text.format.NamedTextColor;
1011

1112
import org.bukkit.*;
1213
import org.bukkit.util.Vector;
@@ -19,6 +20,7 @@
1920
import org.bukkit.configuration.ConfigurationSection;
2021

2122
import com.nisovin.magicspells.util.*;
23+
import com.nisovin.magicspells.MagicSpells;
2224
import com.nisovin.magicspells.handlers.PotionEffectHandler;
2325

2426
public class ConfigDataUtil {
@@ -758,6 +760,44 @@ public boolean isConstant() {
758760
};
759761
}
760762

763+
public static ConfigData<NamedTextColor> getNamedTextColor(@NotNull ConfigurationSection config, @NotNull String path, @Nullable NamedTextColor def) {
764+
String value = config.getString(path);
765+
if (value == null) return data -> def;
766+
767+
NamedTextColor val = NamedTextColor.NAMES.value(value.toLowerCase());
768+
if (val != null) return data -> val;
769+
770+
ConfigData<String> supplier = getString(value);
771+
if (supplier.isConstant()) return data -> def;
772+
773+
return (VariableConfigData<NamedTextColor>) data -> {
774+
String string = supplier.get(data);
775+
if (string == null) return def;
776+
777+
NamedTextColor color = NamedTextColor.NAMES.value(string.toLowerCase());
778+
return color == null ? def : color;
779+
};
780+
}
781+
782+
public static ConfigData<NamespacedKey> getNamespacedKey(@NotNull ConfigurationSection config, @NotNull String path, @Nullable NamespacedKey def) {
783+
String value = config.getString(path);
784+
if (value == null) return data -> def;
785+
786+
NamespacedKey val = NamespacedKey.fromString(value.toLowerCase());
787+
if (val != null) return data -> val;
788+
789+
ConfigData<String> supplier = getString(value);
790+
if (supplier.isConstant()) return data -> def;
791+
792+
return (VariableConfigData<NamespacedKey>) data -> {
793+
String string = supplier.get(data);
794+
if (string == null) return def;
795+
796+
NamespacedKey key = NamespacedKey.fromString(string.toLowerCase());
797+
return key == null ? def : key;
798+
};
799+
}
800+
761801
public static ConfigData<Angle> getAngle(@NotNull ConfigurationSection config, @NotNull String path, @Nullable Angle def) {
762802
if (config.isInt(path) || config.isLong(path) || config.isDouble(path)) {
763803
float value = (float) config.getDouble(path);

0 commit comments

Comments
 (0)