Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ The project includes software developed by third parties. For their full license
- XGlow:
- Repository: `Xezard/XGlow`
- License: **Apache-2.0 License** (See `3rd_party_licenses/LICENSE-Apache_v2`)

- packetevents:
- Repository: `retrooper/packetevents`
- License: **General Public License v3.0** (See `3rd_party_licenses/LICENSE-GPLv3`)
27 changes: 14 additions & 13 deletions buildSrc/src/main/java/dev/magicspells/gradle/MSJavaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ public void apply(Project target) {
repositories.mavenCentral();

String[] mavenUrls = new String[] {
"https://repo.dmulloy2.net/nexus/repository/public/",
"https://repo.md-5.net/content/repositories/releases/",
"https://repo.papermc.io/repository/maven-public/",
"https://repo.aikar.co/content/groups/aikar/",
"https://oss.sonatype.org/content/repositories/central",
"https://oss.sonatype.org/content/repositories/snapshots",
"https://hub.spigotmc.org/nexus/content/repositories/snapshots/",
"https://jitpack.io",
"https://repo.codemc.org/repository/maven-public",
"https://cdn.rawgit.com/Rayzr522/maven-repo/master/",
"https://maven.enginehub.org/repo/",
"https://repo.glaremasters.me/repository/towny/",
"https://repo.extendedclip.com/content/repositories/placeholderapi"
"https://repo.dmulloy2.net/nexus/repository/public/",
"https://repo.md-5.net/content/repositories/releases/",
"https://repo.papermc.io/repository/maven-public/",
"https://repo.aikar.co/content/groups/aikar/",
"https://oss.sonatype.org/content/repositories/central",
"https://oss.sonatype.org/content/repositories/snapshots",
"https://hub.spigotmc.org/nexus/content/repositories/snapshots/",
"https://jitpack.io",
"https://repo.codemc.org/repository/maven-public",
"https://cdn.rawgit.com/Rayzr522/maven-repo/master/",
"https://maven.enginehub.org/repo/",
"https://repo.glaremasters.me/repository/towny/",
"https://repo.extendedclip.com/content/repositories/placeholderapi",
"https://repo.md-5.net/content/repositories/snapshots",
};
for (String url : mavenUrls) {
repositories.maven(mavenArtifactRepository -> mavenArtifactRepository.setUrl(url));
Expand Down
3 changes: 2 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ dependencies {
shadow(project(path: ":nms:shared", configuration: "apiElements"))
shadow(project(path: ":nms:latest")) { transitive = false }

implementation(group: "com.github.retrooper", name: "packetevents-spigot", version: "2.7.0")
implementation(group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.3.0") { transitive = false }
implementation(group: "com.github.libraryaddict", name: "LibsDisguises", version: "v10.0.25") { transitive = false }
implementation(group: "me.libraryaddict.disguises", name: "libsdisguises", version: "10.0.44-SNAPSHOT") { transitive = false }
implementation(group: "net.milkbowl.vault", name: "VaultAPI", version: "1.7") { transitive = false }
implementation(group: "me.clip", name: "placeholderapi", version: "2.11.6") { transitive = false }
implementation(group: "com.github.GriefPrevention", name: "GriefPrevention", version: "17.0.0") { transitive = false }
Expand Down
9 changes: 7 additions & 2 deletions core/src/main/java/com/nisovin/magicspells/MagicSpells.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.file.Path;
import java.nio.file.Files;

import com.google.common.collect.Sets;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.LinkedHashMultimap;

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

public static void registerEvents(final Listener listener, EventPriority customPriority) {
if (customPriority == null) customPriority = EventPriority.NORMAL;
Method[] methods;
Set<Method> methods;
try {
methods = listener.getClass().getDeclaredMethods();
Class<?> listenerClazz = listener.getClass();
methods = Sets.union(
Set.of(listenerClazz.getMethods()),
Set.of(listenerClazz.getDeclaredMethods())
);
} catch (NoClassDefFoundError e) {
DebugHandler.debugNoClassDefFoundError(e);
return;
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/com/nisovin/magicspells/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;

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

protected ConfigData<NamedTextColor> getConfigDataNamedTextColor(String key, NamedTextColor def) {
return ConfigDataUtil.getNamedTextColor(config.getMainConfig(), internalKey + key, def);
}

protected ConfigData<NamespacedKey> getConfigDataNamespacedKey(String key, NamespacedKey def) {
return ConfigDataUtil.getNamespacedKey(config.getMainConfig(), internalKey + key, def);
}

/**
* @param key Path for the string or section format SpellFilter to be read from.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.nisovin.magicspells.spells.targeted;

import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.LivingEntity;

import net.kyori.adventure.text.format.NamedTextColor;

import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.util.SpellData;
import com.nisovin.magicspells.util.CastResult;
import com.nisovin.magicspells.util.TargetInfo;
import com.nisovin.magicspells.util.MagicConfig;
import com.nisovin.magicspells.spells.TargetedSpell;
import com.nisovin.magicspells.util.config.ConfigData;
import com.nisovin.magicspells.util.glow.GlowManager;
import com.nisovin.magicspells.spells.TargetedEntitySpell;
import com.nisovin.magicspells.util.glow.impl.PacketEventsGlowManager;

public class GlowSpell extends TargetedSpell implements TargetedEntitySpell {

private static GlowManager glowManager;

private final ConfigData<Boolean> global;
private final ConfigData<Boolean> remove;
private final ConfigData<Integer> duration;
private final ConfigData<Integer> priority;
private final ConfigData<NamespacedKey> key;
private final ConfigData<NamedTextColor> color;

public GlowSpell(MagicConfig config, String spellName) {
super(config, spellName);

key = getConfigDataNamespacedKey("key", null);
color = getConfigDataNamedTextColor("color", null);
global = getConfigDataBoolean("global", true);
remove = getConfigDataBoolean("remove", false);
duration = getConfigDataInt("duration", 0);
priority = getConfigDataInt("priority", 0);

if (glowManager == null) {
if (Bukkit.getPluginManager().isPluginEnabled("packetevents")) glowManager = new PacketEventsGlowManager();
else glowManager = MagicSpells.getVolatileCodeHandler().getGlowManager();

glowManager.load();
}
}

@Override
public CastResult cast(SpellData data) {
TargetInfo<LivingEntity> info = getTargetedEntity(data);
if (info.noTarget()) return noTarget(info);

return castAtEntity(info.spellData());
}

@Override
public CastResult castAtEntity(SpellData data) {
if (global.get(data)) {
NamespacedKey key = this.key.get(data);

if (remove.get(data)) {
if (key == null) return new CastResult(PostCastAction.ALREADY_HANDLED, data);

glowManager.removeGlow(data.target(), key);
} else {
glowManager.applyGlow(
data.target(),
key != null ? key : new NamespacedKey(MagicSpells.getInstance(), UUID.randomUUID().toString()),
color.get(data),
priority.get(data),
duration.get(data)
);
}

playSpellEffects(data);
return new CastResult(PostCastAction.HANDLE_NORMALLY, data);
}

if (!(data.caster() instanceof Player caster)) return new CastResult(PostCastAction.ALREADY_HANDLED, data);

NamespacedKey key = this.key.get(data);

if (remove.get(data)) {
if (key == null) return new CastResult(PostCastAction.ALREADY_HANDLED, data);

glowManager.removeGlow(caster, data.target(), key);
} else {
glowManager.applyGlow(
caster,
data.target(),
key != null ? key : new NamespacedKey(MagicSpells.getInstance(), UUID.randomUUID().toString()),
color.get(data),
priority.get(data),
duration.get(data)
);
}

playSpellEffects(data);
return new CastResult(PostCastAction.HANDLE_NORMALLY, data);
}

@Override
protected void turnOff() {
if (glowManager == null) return;

glowManager.unload();
glowManager = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
@DependsOn({"ProtocolLib", "XGlow"})
public class GlowSpell extends TargetedSpell implements TargetedEntitySpell {

private static final DeprecationNotice DEPRECATION_NOTICE = new DeprecationNotice(
"The '.targeted.ext.GlowSpell' spell class does not function, as the XGlow plugin is abandoned.",
"Use the '.targeted.GlowSpell' spell class."
);

private final Multimap<UUID, GlowData> glowing;

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

color = getConfigDataEnum("color", ChatColor.class, ChatColor.WHITE);

MagicSpells.getDeprecationManager().addDeprecation(this, DEPRECATION_NOTICE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jetbrains.annotations.Nullable;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;

import org.bukkit.*;
import org.bukkit.util.Vector;
Expand All @@ -19,6 +20,7 @@
import org.bukkit.configuration.ConfigurationSection;

import com.nisovin.magicspells.util.*;
import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.handlers.PotionEffectHandler;

public class ConfigDataUtil {
Expand Down Expand Up @@ -758,6 +760,44 @@ public boolean isConstant() {
};
}

public static ConfigData<NamedTextColor> getNamedTextColor(@NotNull ConfigurationSection config, @NotNull String path, @Nullable NamedTextColor def) {
String value = config.getString(path);
if (value == null) return data -> def;

NamedTextColor val = NamedTextColor.NAMES.value(value.toLowerCase());
if (val != null) return data -> val;

ConfigData<String> supplier = getString(value);
if (supplier.isConstant()) return data -> def;

return (VariableConfigData<NamedTextColor>) data -> {
String string = supplier.get(data);
if (string == null) return def;

NamedTextColor color = NamedTextColor.NAMES.value(string.toLowerCase());
return color == null ? def : color;
};
}

public static ConfigData<NamespacedKey> getNamespacedKey(@NotNull ConfigurationSection config, @NotNull String path, @Nullable NamespacedKey def) {
String value = config.getString(path);
if (value == null) return data -> def;

NamespacedKey val = NamespacedKey.fromString(value.toLowerCase());
if (val != null) return data -> val;

ConfigData<String> supplier = getString(value);
if (supplier.isConstant()) return data -> def;

return (VariableConfigData<NamespacedKey>) data -> {
String string = supplier.get(data);
if (string == null) return def;

NamespacedKey key = NamespacedKey.fromString(string.toLowerCase());
return key == null ? def : key;
};
}

public static ConfigData<Angle> getAngle(@NotNull ConfigurationSection config, @NotNull String path, @Nullable Angle def) {
if (config.isInt(path) || config.isLong(path) || config.isDouble(path)) {
float value = (float) config.getDouble(path);
Expand Down
Loading