Skip to content

Commit 0a6be0a

Browse files
SpellFilter for SilenceSpell
New option of allowed-spell-tags which accepts a list of spell tags (strings) New option of disallowed-spell-tags which accepts a list of spell tags (strings) Fix compat with NCP's API changes.
1 parent ae81780 commit 0a6be0a

File tree

2 files changed

+9
-36
lines changed

2 files changed

+9
-36
lines changed

src/com/nisovin/magicspells/spells/targeted/SilenceSpell.java

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

33
import java.util.HashMap;
4-
import java.util.HashSet;
54
import java.util.List;
65
import java.util.Map;
7-
import java.util.Set;
86
import java.util.concurrent.ConcurrentHashMap;
97

8+
import com.nisovin.magicspells.util.SpellFilter;
109
import org.bukkit.Bukkit;
1110
import org.bukkit.entity.LivingEntity;
1211
import org.bukkit.entity.Player;
@@ -16,7 +15,6 @@
1615
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
1716

1817
import com.nisovin.magicspells.MagicSpells;
19-
import com.nisovin.magicspells.Spell;
2018
import com.nisovin.magicspells.events.SpellCastEvent;
2119
import com.nisovin.magicspells.spelleffects.EffectPosition;
2220
import com.nisovin.magicspells.spells.TargetedEntitySpell;
@@ -32,11 +30,11 @@ public class SilenceSpell extends TargetedSpell implements TargetedEntitySpell {
3230
private boolean preventCommands;
3331
private int duration;
3432
private List<String> allowedSpellNames;
35-
private Set<Spell> allowedSpells;
3633
private List<String> disallowedSpellNames;
37-
private Set<Spell> disallowedSpells;
3834
private String strSilenced;
3935

36+
private SpellFilter shouldAllow = null;
37+
4038
Map<String,Unsilencer> silenced;
4139

4240
public SilenceSpell(MagicConfig config, String spellName) {
@@ -48,6 +46,8 @@ public SilenceSpell(MagicConfig config, String spellName) {
4846
duration = getConfigInt("duration", 200);
4947
allowedSpellNames = getConfigStringList("allowed-spells", null);
5048
disallowedSpellNames = getConfigStringList("disallowed-spells", null);
49+
List<String> tagList = getConfigStringList("allowed-spell-tags", null);
50+
List<String> deniedTagList = getConfigStringList("disallowed-spell-tags", null);
5151
strSilenced = getConfigString("str-silenced", "You are silenced!");
5252

5353
if (preventChat) {
@@ -57,40 +57,14 @@ public SilenceSpell(MagicConfig config, String spellName) {
5757
}
5858

5959
validTargetList = new ValidTargetList(true, false);
60+
61+
this.shouldAllow = new SpellFilter(allowedSpellNames, disallowedSpellNames, tagList, deniedTagList);
6062
}
6163

6264
@Override
6365
public void initialize() {
6466
super.initialize();
6567

66-
if (allowedSpellNames != null && !allowedSpellNames.isEmpty()) {
67-
allowedSpells = new HashSet<>();
68-
for (String spellName : allowedSpellNames) {
69-
Spell spell = MagicSpells.getSpellByInternalName(spellName);
70-
if (spell != null) {
71-
allowedSpells.add(spell);
72-
} else {
73-
MagicSpells.error("Invalid allowed spell specified on silence spell '" + this.internalName + "': '" + spellName + '\'');
74-
}
75-
}
76-
allowedSpellNames.clear();
77-
}
78-
allowedSpellNames = null;
79-
80-
if (disallowedSpellNames != null && !disallowedSpellNames.isEmpty()) {
81-
disallowedSpells = new HashSet<>();
82-
for (String spellName : disallowedSpellNames) {
83-
Spell spell = MagicSpells.getSpellByInternalName(spellName);
84-
if (spell != null) {
85-
disallowedSpells.add(spell);
86-
} else {
87-
MagicSpells.error("Invalid disallowed spell specified on silence spell '" + this.internalName + "': '" + spellName + '\'');
88-
}
89-
}
90-
disallowedSpellNames.clear();
91-
}
92-
disallowedSpellNames = null;
93-
9468
if (preventCast) registerEvents(new CastListener());
9569
if (preventChat) registerEvents(new ChatListener());
9670
if (preventCommands) registerEvents(new CommandListener());
@@ -144,8 +118,7 @@ public class CastListener implements Listener {
144118
public void onSpellCast(final SpellCastEvent event) {
145119
if (event.getCaster() == null) return;
146120
if (!silenced.containsKey(event.getCaster().getName())) return;
147-
if (!(allowedSpells == null || !allowedSpells.contains(event.getSpell()))) return;
148-
if (!(disallowedSpells == null || disallowedSpells.contains(event.getSpell()))) return;
121+
if (shouldAllow.check(event.getSpell())) return;
149122
event.setCancelled(true);
150123

151124
Bukkit.getScheduler().scheduleSyncDelayedTask(MagicSpells.plugin, () -> sendMessage(strSilenced, event.getCaster(), event.getSpellArgs()));

src/com/nisovin/magicspells/util/compat/nocheatplus/NoCheatPlusExemptionAid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public Collection<Object> optimizeNodes(Object[] nodes) {
5555
private void setupCheckNodes() {
5656
checkNodes = new HashMap<>();
5757
Arrays.stream(CheckType.values())
58-
.forEachOrdered(check -> checkNodes.put(check.getPermission(), check));
58+
.forEachOrdered(check -> checkNodes.put(check.getPermission().toString(), check));
5959
}
6060

6161
private boolean doesntHaveYet(Player player, CheckType checkType) {

0 commit comments

Comments
 (0)