@@ -53,55 +53,51 @@ public class EffEnchant extends Effect {
53
53
}
54
54
55
55
@ SuppressWarnings ("null" )
56
- private Expression <ItemType > item ;
56
+ private Expression <ItemType > items ;
57
57
@ Nullable
58
- private Expression <EnchantmentType > enchs ;
58
+ private Expression <EnchantmentType > enchantments ;
59
59
60
- @ SuppressWarnings ({"unchecked" , "null" })
61
60
@ Override
62
- public boolean init (final Expression <?>[] exprs , final int matchedPattern , final Kleenean isDelayed , final ParseResult parseResult ) {
63
- item = (Expression <ItemType >) exprs [0 ];
64
- if (!ChangerUtils .acceptsChange (item , ChangeMode .SET , ItemStack .class )) {
65
- Skript .error (item + " cannot be changed, thus it cannot be (dis)enchanted" );
61
+ @ SuppressWarnings ("unchecked" )
62
+ public boolean init (Expression <?>[] exprs , int matchedPattern , Kleenean isDelayed , ParseResult parseResult ) {
63
+ items = (Expression <ItemType >) exprs [0 ];
64
+ if (!ChangerUtils .acceptsChange (items , ChangeMode .SET , ItemStack .class )) {
65
+ Skript .error (items + " cannot be changed, thus it cannot be (dis)enchanted" );
66
66
return false ;
67
67
}
68
68
if (matchedPattern == 0 )
69
- enchs = (Expression <EnchantmentType >) exprs [1 ];
69
+ enchantments = (Expression <EnchantmentType >) exprs [1 ];
70
70
return true ;
71
71
}
72
72
73
73
@ Override
74
- protected void execute (final Event e ) {
75
- final ItemType i = item . getSingle ( e );
76
- if (i == null )
74
+ protected void execute (Event event ) {
75
+ ItemType [] items = this . items . getArray ( event );
76
+ if (items . length == 0 ) // short circuit
77
77
return ;
78
- if (enchs != null ) {
79
- final EnchantmentType [] types = enchs .getArray (e );
78
+
79
+ if (enchantments != null ) {
80
+ EnchantmentType [] types = enchantments .getArray (event );
80
81
if (types .length == 0 )
81
82
return ;
82
-
83
- for (final EnchantmentType type : types ) {
84
- Enchantment ench = type .getType ();
85
- assert ench != null ;
86
- i .addEnchantments (new EnchantmentType (ench , type .getLevel ()));
83
+ for (ItemType item : items ) {
84
+ for (EnchantmentType type : types ) {
85
+ Enchantment enchantment = type .getType ();
86
+ assert enchantment != null ;
87
+ item .addEnchantments (new EnchantmentType (enchantment , type .getLevel ()));
88
+ }
87
89
}
88
- item .change (e , new ItemType [] {i }, ChangeMode .SET );
89
90
} else {
90
- final EnchantmentType [] types = i .getEnchantmentTypes ();
91
- if (types == null )
92
- return ;
93
-
94
- for (final EnchantmentType ench : types ) {
95
- assert ench != null ;
96
- i .removeEnchantments (ench );
91
+ for (ItemType item : items ) {
92
+ item .clearEnchantments ();
97
93
}
98
- item .change (e , new ItemType [] {i }, ChangeMode .SET );
99
94
}
95
+ this .items .change (event , items .clone (), ChangeMode .SET );
100
96
}
101
97
102
98
@ Override
103
- public String toString (final @ Nullable Event e , final boolean debug ) {
104
- return enchs == null ? "disenchant " + item .toString (e , debug ) : "enchant " + item .toString (e , debug ) + " with " + enchs ;
99
+ public String toString (@ Nullable Event event , boolean debug ) {
100
+ return enchantments == null ? "disenchant " + items .toString (event , debug ) : "enchant " + items .toString (event , debug ) + " with " + enchantments ;
105
101
}
106
102
107
103
}
0 commit comments