Skip to content

Commit 359f6c7

Browse files
authored
Merge pull request #795 from TonytheMacaroni/main
Remove totems on stop, allow totems to be cleansed by CleanseSpell
2 parents f0a1bf2 + 2e655c5 commit 359f6c7

2 files changed

Lines changed: 46 additions & 17 deletions

File tree

core/src/main/java/com/nisovin/magicspells/spells/targeted/CleanseSpell.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class CleanseSpell extends TargetedSpell implements TargetedEntitySpell {
2525
private final List<BuffSpell> buffSpells;
2626
private final List<LoopSpell> loopSpells;
2727
private final List<OrbitSpell> orbitSpells;
28+
private final List<TotemSpell> totemSpells;
2829
private final List<SilenceSpell> silenceSpells;
2930
private final List<LevitateSpell> levitateSpells;
3031
private final List<PotionEffectType> potionEffectTypes;
@@ -40,6 +41,7 @@ public CleanseSpell(MagicConfig config, String spellName) {
4041
buffSpells = new ArrayList<>();
4142
loopSpells = new ArrayList<>();
4243
orbitSpells = new ArrayList<>();
44+
totemSpells = new ArrayList<>();
4345
silenceSpells = new ArrayList<>();
4446
levitateSpells = new ArrayList<>();
4547
potionEffectTypes = new ArrayList<>();
@@ -104,6 +106,18 @@ public void initialize() {
104106
continue;
105107
}
106108

109+
if (s.startsWith("totem:")) {
110+
if (s.replace("totem:", "").equalsIgnoreCase("*")) {
111+
for (Spell spell : MagicSpells.getSpellsOrdered()) {
112+
if (spell instanceof TotemSpell) totemSpells.add((TotemSpell) spell);
113+
}
114+
continue;
115+
}
116+
Spell spell = MagicSpells.getSpellByInternalName(s.replace("totem:", ""));
117+
if (spell instanceof TotemSpell) totemSpells.add((TotemSpell) spell);
118+
continue;
119+
}
120+
107121
if (s.startsWith("silence:")) {
108122
if (s.replace("silence:", "").equalsIgnoreCase("*")) {
109123
for (Spell spell : MagicSpells.getSpellsOrdered()) {
@@ -167,6 +181,10 @@ public void initialize() {
167181
if (spell.hasOrbit(entity)) return true;
168182
}
169183

184+
for (TotemSpell spell : totemSpells) {
185+
if (spell.hasTotem(entity)) return true;
186+
}
187+
170188
for (SilenceSpell spell : silenceSpells) {
171189
if (spell.isSilenced(entity)) return true;
172190
}
@@ -207,6 +225,7 @@ public CastResult castAtEntity(SpellData data) {
207225
stunSpells.forEach(spell -> spell.removeStun(target));
208226
loopSpells.forEach(spell -> spell.cancelLoops(target));
209227
orbitSpells.forEach(spell -> spell.removeOrbits(target));
228+
totemSpells.forEach(spell -> spell.removeTotems(target));
210229
silenceSpells.forEach(spell -> spell.removeSilence(target));
211230
levitateSpells.forEach(spell -> spell.removeLevitate(target));
212231

core/src/main/java/com/nisovin/magicspells/spells/targeted/TotemSpell.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ public void initialize() {
186186

187187
@Override
188188
public void turnOff() {
189-
for (Totem t : totems) {
190-
t.stop();
191-
}
189+
for (Totem t : totems) t.stop(false);
192190

193191
totems.clear();
194192
ticker.stop();
@@ -258,12 +256,7 @@ private void createTotem(SpellData data) {
258256
totems.add(totem);
259257

260258
int maxDuration = this.maxDuration.get(data);
261-
if (maxDuration > 0) {
262-
MagicSpells.scheduleDelayedTask(() -> {
263-
totem.stop();
264-
totems.remove(totem);
265-
}, maxDuration);
266-
}
259+
if (maxDuration > 0) MagicSpells.scheduleDelayedTask(totem::stop, maxDuration);
267260

268261
ticker.start();
269262
playSpellEffects(data);
@@ -272,14 +265,7 @@ private void createTotem(SpellData data) {
272265
@EventHandler
273266
public void onPlayerDeath(PlayerDeathEvent event) {
274267
if (totems.isEmpty()) return;
275-
Player player = event.getEntity();
276-
Iterator<Totem> iter = totems.iterator();
277-
while (iter.hasNext()) {
278-
Totem pulser = iter.next();
279-
if (!pulser.data.caster().equals(player)) continue;
280-
pulser.stop();
281-
iter.remove();
282-
}
268+
removeTotems(event.getPlayer());
283269
}
284270

285271
@EventHandler
@@ -301,6 +287,25 @@ public void onArmorStandManipulate(PlayerArmorStandManipulateEvent e) {
301287
}
302288
}
303289

290+
public boolean hasTotem(LivingEntity caster) {
291+
for (Totem totem : totems)
292+
if (caster.equals(totem.data.caster()))
293+
return true;
294+
295+
return false;
296+
}
297+
298+
public void removeTotems(LivingEntity caster) {
299+
Iterator<Totem> it = totems.iterator();
300+
while (it.hasNext()) {
301+
Totem totem = it.next();
302+
if (caster.equals(totem.data.caster())) {
303+
totem.stop(false);
304+
it.remove();
305+
}
306+
}
307+
}
308+
304309
private class Totem {
305310

306311
private final ArmorStand armorStand;
@@ -393,8 +398,13 @@ private boolean activate() {
393398
}
394399

395400
private void stop() {
401+
stop(true);
402+
}
403+
404+
private void stop(boolean remove) {
396405
if (!totemLocation.getChunk().isLoaded()) totemLocation.getChunk().load();
397406
armorStand.remove();
407+
if (remove) totems.remove(this);
398408
playSpellEffects(EffectPosition.DISABLED, totemLocation, data);
399409
if (spellOnBreak != null) spellOnBreak.subcast(data);
400410
}

0 commit comments

Comments
 (0)