Skip to content

Commit ebea21b

Browse files
added modifier collections
in the general config, you can define a set of modifiers like this general: modifiers: modifier_name: checks: - condition condition_var action action_var - condition condition_var action action_var pass-condition: a string value that can be one of the following ANY, ALL You can also define some in the spell*.yml files as follows modifiers: modifier_name: checks: - condition condition_var action action_var - condition condition_var action action_var pass-condition: a string value that can be one of the following ANY, ALL to reference the modifier collection, you just slip this into your modifiers listed on a spell - collection <modifier_name> action action_var where <modifier_name> is the name that you assigned to the modifier collection as shown above Just a heads up that for the modifier actions inside this, I recommend that you use stop rather than denied most of the time, because the denied action will actually cancel the event being processed whereas the stop action will just say that this specific check counts as a fail.
1 parent ea931e0 commit ebea21b

File tree

6 files changed

+326
-7
lines changed

6 files changed

+326
-7
lines changed

src/com/nisovin/magicspells/MagicSpells.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public class MagicSpells extends JavaPlugin {
159159
MagicLogger magicLogger;
160160
LifeLengthTracker lifeLengthTracker;
161161

162+
MagicConfig config;
163+
162164
// profiling
163165
HashMap<String, Long> profilingTotalTime;
164166
HashMap<String, Integer> profilingRuns;
@@ -197,7 +199,7 @@ void load() {
197199
if (!(new File(getDataFolder(), "spells-regular.yml")).exists()) saveResource("spells-regular.yml", false);
198200
if (!(new File(getDataFolder(), "zones.yml")).exists()) saveResource("zones.yml", false);
199201
}
200-
MagicConfig config = new MagicConfig(this);
202+
config = new MagicConfig(this);
201203
if (!config.isLoaded()) {
202204
MagicSpells.log(Level.SEVERE, "Error in config file, stopping config load");
203205
return;
@@ -1233,6 +1235,8 @@ void unload() {
12331235
strCantBind = null;
12341236
strConsoleName = null;
12351237

1238+
config = null;
1239+
12361240
// remove star permissions (to allow new spells to be added to them)
12371241
getServer().getPluginManager().removePermission("magicspells.grant.*");
12381242
getServer().getPluginManager().removePermission("magicspells.cast.*");
@@ -1259,6 +1263,10 @@ public ClassLoader getPluginClassLoader() {
12591263
return getClassLoader();
12601264
}
12611265

1266+
public MagicConfig getMagicConfig() {
1267+
return config;
1268+
}
1269+
12621270
}
12631271

12641272
/*

src/com/nisovin/magicspells/castmodifiers/Condition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ static Condition getConditionByName(String name) {
134134
conditions.put("saturationbelow", SaturationBelowCondition.class);
135135
conditions.put("moneymorethan", MoneyMoreThanCondition.class);
136136
conditions.put("moneylessthan", MoneyLessThanCondition.class);
137+
conditions.put("collection", MultiCondition.class);
137138
}
138139

139140
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.nisovin.magicspells.castmodifiers;
2+
3+
import org.bukkit.entity.Player;
4+
5+
import com.nisovin.magicspells.events.MagicSpellsGenericPlayerEvent;
6+
import com.nisovin.magicspells.events.ManaChangeEvent;
7+
import com.nisovin.magicspells.events.SpellCastEvent;
8+
import com.nisovin.magicspells.events.SpellTargetEvent;
9+
import com.nisovin.magicspells.events.SpellTargetLocationEvent;
10+
11+
public interface IModifier {
12+
public boolean apply(SpellCastEvent event);
13+
public boolean apply(ManaChangeEvent event);
14+
public boolean apply(SpellTargetEvent event);
15+
public boolean apply(SpellTargetLocationEvent event);
16+
public boolean apply(MagicSpellsGenericPlayerEvent event);
17+
public boolean check(Player player);
18+
19+
}

src/com/nisovin/magicspells/castmodifiers/Modifier.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.nisovin.magicspells.spells.TargetedLocationSpell;
1818
import com.nisovin.magicspells.util.Util;
1919

20-
public class Modifier {
20+
public class Modifier implements IModifier {
2121

2222
boolean negated = false;
2323
Condition condition;
@@ -28,6 +28,9 @@ public class Modifier {
2828
String modifierVarString;
2929
String strModifierFailed = null;
3030

31+
//is this a condition that will want to access the events directly?
32+
boolean alertCondition = false;
33+
3134
public static Modifier factory(String s) {
3235
Modifier m = new Modifier();
3336
String[] s1 = s.split("\\$\\$");
@@ -75,13 +78,24 @@ public static Modifier factory(String s) {
7578
m.strModifierFailed = s1[1].trim();
7679
}
7780

81+
//check for the alert condition
82+
if (m.condition instanceof IModifier) {
83+
m.alertCondition = true;
84+
}
85+
7886
// done
7987
return m;
8088
}
8189

90+
@Override
8291
public boolean apply(SpellCastEvent event) {
8392
Player player = event.getCaster();
84-
boolean check = condition.check(player);
93+
boolean check;
94+
if (alertCondition) {
95+
check = ((IModifier)condition).apply(event);
96+
} else {
97+
check = condition.check(player);
98+
}
8599
if (negated) check = !check;
86100
if (!check && type == ModifierType.REQUIRED) {
87101
event.setCancelled(true);
@@ -120,9 +134,15 @@ public boolean apply(SpellCastEvent event) {
120134
return true;
121135
}
122136

137+
@Override
123138
public boolean apply(ManaChangeEvent event) {
124139
Player player = event.getPlayer();
125-
boolean check = condition.check(player);
140+
boolean check;
141+
if (alertCondition) {
142+
check = ((IModifier)condition).apply(event);
143+
} else {
144+
check = condition.check(player);
145+
}
126146
if (negated) check = !check;
127147
if (!check && type == ModifierType.REQUIRED) {
128148
event.setNewAmount(event.getOldAmount());
@@ -154,9 +174,17 @@ public boolean apply(ManaChangeEvent event) {
154174
return true;
155175
}
156176

177+
@Override
157178
public boolean apply(SpellTargetEvent event) {
158179
Player player = event.getCaster();
159-
boolean check = condition.check(player, event.getTarget());
180+
181+
boolean check;
182+
if (alertCondition) {
183+
check = ((IModifier)condition).apply(event);
184+
} else {
185+
check = condition.check(player, event.getTarget());
186+
}
187+
160188
if (negated) check = !check;
161189
if (!check && type == ModifierType.REQUIRED) {
162190
event.setCancelled(true);
@@ -190,9 +218,15 @@ public boolean apply(SpellTargetEvent event) {
190218
return true;
191219
}
192220

221+
@Override
193222
public boolean apply(SpellTargetLocationEvent event) {
194223
Player player = event.getCaster();
195-
boolean check = condition.check(player, event.getTargetLocation());
224+
boolean check;
225+
if (alertCondition) {
226+
check = ((IModifier)condition).apply(event);
227+
} else {
228+
check = condition.check(player, event.getTargetLocation());
229+
}
196230
if (negated) check = !check;
197231
if (!check && type == ModifierType.REQUIRED) {
198232
event.setCancelled(true);
@@ -216,8 +250,14 @@ public boolean apply(SpellTargetLocationEvent event) {
216250
return true;
217251
}
218252

253+
@Override
219254
public boolean apply(MagicSpellsGenericPlayerEvent event) {
220-
boolean check = condition.check(event.getPlayer());
255+
boolean check;
256+
if (alertCondition) {
257+
check = ((IModifier)condition).check(event.getPlayer());
258+
} else {
259+
check = condition.check(event.getPlayer());
260+
}
221261
if (negated) check = !check;
222262
if (!check && type == ModifierType.REQUIRED) {
223263
event.setCancelled(true);
@@ -243,6 +283,7 @@ public boolean apply(MagicSpellsGenericPlayerEvent event) {
243283
return true;
244284
}
245285

286+
@Override
246287
public boolean check(Player player) {
247288
boolean check = condition.check(player);
248289
if (negated) check = !check;

0 commit comments

Comments
 (0)