1
1
package com .nisovin .magicspells .spells .targeted ;
2
2
3
3
import java .util .HashMap ;
4
- import java .util .HashSet ;
5
4
import java .util .List ;
6
5
import java .util .Map ;
7
- import java .util .Set ;
8
6
import java .util .concurrent .ConcurrentHashMap ;
9
7
8
+ import com .nisovin .magicspells .util .SpellFilter ;
10
9
import org .bukkit .Bukkit ;
11
10
import org .bukkit .entity .LivingEntity ;
12
11
import org .bukkit .entity .Player ;
16
15
import org .bukkit .event .player .PlayerCommandPreprocessEvent ;
17
16
18
17
import com .nisovin .magicspells .MagicSpells ;
19
- import com .nisovin .magicspells .Spell ;
20
18
import com .nisovin .magicspells .events .SpellCastEvent ;
21
19
import com .nisovin .magicspells .spelleffects .EffectPosition ;
22
20
import com .nisovin .magicspells .spells .TargetedEntitySpell ;
@@ -32,11 +30,11 @@ public class SilenceSpell extends TargetedSpell implements TargetedEntitySpell {
32
30
private boolean preventCommands ;
33
31
private int duration ;
34
32
private List <String > allowedSpellNames ;
35
- private Set <Spell > allowedSpells ;
36
33
private List <String > disallowedSpellNames ;
37
- private Set <Spell > disallowedSpells ;
38
34
private String strSilenced ;
39
35
36
+ private SpellFilter shouldAllow = null ;
37
+
40
38
Map <String ,Unsilencer > silenced ;
41
39
42
40
public SilenceSpell (MagicConfig config , String spellName ) {
@@ -48,6 +46,8 @@ public SilenceSpell(MagicConfig config, String spellName) {
48
46
duration = getConfigInt ("duration" , 200 );
49
47
allowedSpellNames = getConfigStringList ("allowed-spells" , null );
50
48
disallowedSpellNames = getConfigStringList ("disallowed-spells" , null );
49
+ List <String > tagList = getConfigStringList ("allowed-spell-tags" , null );
50
+ List <String > deniedTagList = getConfigStringList ("disallowed-spell-tags" , null );
51
51
strSilenced = getConfigString ("str-silenced" , "You are silenced!" );
52
52
53
53
if (preventChat ) {
@@ -57,40 +57,14 @@ public SilenceSpell(MagicConfig config, String spellName) {
57
57
}
58
58
59
59
validTargetList = new ValidTargetList (true , false );
60
+
61
+ this .shouldAllow = new SpellFilter (allowedSpellNames , disallowedSpellNames , tagList , deniedTagList );
60
62
}
61
63
62
64
@ Override
63
65
public void initialize () {
64
66
super .initialize ();
65
67
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
-
94
68
if (preventCast ) registerEvents (new CastListener ());
95
69
if (preventChat ) registerEvents (new ChatListener ());
96
70
if (preventCommands ) registerEvents (new CommandListener ());
@@ -144,8 +118,7 @@ public class CastListener implements Listener {
144
118
public void onSpellCast (final SpellCastEvent event ) {
145
119
if (event .getCaster () == null ) return ;
146
120
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 ;
149
122
event .setCancelled (true );
150
123
151
124
Bukkit .getScheduler ().scheduleSyncDelayedTask (MagicSpells .plugin , () -> sendMessage (strSilenced , event .getCaster (), event .getSpellArgs ()));
0 commit comments