forked from nisovin/MagicSpells
-
Notifications
You must be signed in to change notification settings - Fork 72
Add GlowSpell #991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TonytheMacaroni
merged 2 commits into
TheComputerGeek2:main
from
TonytheMacaroni:glow-spell
Mar 29, 2025
Merged
Add GlowSpell #991
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
core/src/main/java/com/nisovin/magicspells/spells/targeted/GlowSpell.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
TonytheMacaroni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| protected void turnOff() { | ||
| if (glowManager == null) return; | ||
|
|
||
| glowManager.unload(); | ||
| glowManager = null; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.