Skip to content

Commit f8af07f

Browse files
Added targeted.EntitySilenceSpell
This spell controls the "silent" flag on living entities which may suppress sounds they usually make. There is an option called target-state which accepts a target boolean state and defaults to toggle. Added targeted.SlimeSizeSpell This spell is for changing the size of slimes. It accepts an option called size which accepts a variable mod format (operation along with integer or variable name) It accepts an option called min-size which accepts an integer and the minimum allowed value is 0. This is the minimum value to set a slime to. It accepts an integer called max-size which defaults to 20 and is the maximum size a slime may be set to. If the maximum size is smaller than the minimum size, it is set to be equal to the minimum size.
1 parent 07c6cb2 commit f8af07f

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.nisovin.magicspells.spells.targeted;
2+
3+
import com.nisovin.magicspells.spells.TargetedEntitySpell;
4+
import com.nisovin.magicspells.spells.TargetedSpell;
5+
import com.nisovin.magicspells.util.MagicConfig;
6+
import com.nisovin.magicspells.util.TargetBooleanState;
7+
import com.nisovin.magicspells.util.TargetInfo;
8+
import org.bukkit.entity.LivingEntity;
9+
import org.bukkit.entity.Player;
10+
11+
public class EntitySilenceSpell extends TargetedSpell implements TargetedEntitySpell {
12+
13+
private TargetBooleanState targetBooleanState;
14+
15+
public EntitySilenceSpell(MagicConfig config, String spellName) {
16+
super(config, spellName);
17+
18+
this.targetBooleanState = TargetBooleanState.getFromName(getConfigString("target-state", "toggle"));
19+
}
20+
21+
@Override
22+
public PostCastAction castSpell(Player player, SpellCastState state, float power, String[] args) {
23+
if (state == SpellCastState.NORMAL) {
24+
TargetInfo<LivingEntity> targetInfo = getTargetedEntity(player, power);
25+
if (targetInfo == null) return noTarget(player);
26+
LivingEntity target = targetInfo.getTarget();
27+
if (target == null) return noTarget(player);
28+
target.setSilent(targetBooleanState.getBooleanState(target.isSilent()));
29+
}
30+
return PostCastAction.HANDLE_NORMALLY;
31+
}
32+
33+
@Override
34+
public boolean castAtEntity(Player caster, LivingEntity target, float power) {
35+
target.setSilent(targetBooleanState.getBooleanState(target.isSilent()));
36+
return true;
37+
}
38+
39+
@Override
40+
public boolean castAtEntity(LivingEntity target, float power) {
41+
target.setSilent(targetBooleanState.getBooleanState(target.isSilent()));
42+
return true;
43+
}
44+
45+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.nisovin.magicspells.spells.targeted;
2+
3+
import com.nisovin.magicspells.spells.TargetedEntitySpell;
4+
import com.nisovin.magicspells.spells.TargetedSpell;
5+
import com.nisovin.magicspells.util.MagicConfig;
6+
import com.nisovin.magicspells.util.TargetInfo;
7+
import com.nisovin.magicspells.util.Util;
8+
import com.nisovin.magicspells.util.VariableMod;
9+
import org.bukkit.entity.LivingEntity;
10+
import org.bukkit.entity.Player;
11+
import org.bukkit.entity.Slime;
12+
13+
public class SlimeSizeSpell extends TargetedSpell implements TargetedEntitySpell {
14+
15+
private VariableMod variableMod;
16+
private int minSize;
17+
private int maxSize;
18+
19+
private static ValidTargetChecker isSlimeChecker = (LivingEntity entity) -> entity instanceof Slime;
20+
21+
public SlimeSizeSpell(MagicConfig config, String spellName) {
22+
super(config, spellName);
23+
24+
variableMod = new VariableMod(getConfigString("size", "=5"));
25+
26+
minSize = getConfigInt("min-size", 0);
27+
28+
// Just a little safety check
29+
if (minSize < 0) minSize = 0;
30+
31+
maxSize = getConfigInt("max-size", 20);
32+
33+
// Little sanity check
34+
if (maxSize < minSize) maxSize = minSize;
35+
}
36+
37+
@Override
38+
public PostCastAction castSpell(Player player, SpellCastState state, float power, String[] args) {
39+
if (state == SpellCastState.NORMAL) {
40+
TargetInfo<LivingEntity> targetInfo = getTargetedEntity(player, power);
41+
if (targetInfo == null) return noTarget(player);
42+
LivingEntity targetEntity = targetInfo.getTarget();
43+
if (!(targetEntity instanceof Slime)) return noTarget(player);
44+
Slime slime = (Slime) targetEntity;
45+
double rawOutputValue = variableMod.getValue(player, null, slime.getSize());
46+
int finalSize = Util.clampValue(minSize, maxSize, (int)rawOutputValue);
47+
slime.setSize(finalSize);
48+
}
49+
return PostCastAction.HANDLE_NORMALLY;
50+
}
51+
52+
@Override
53+
public ValidTargetChecker getValidTargetChecker() {
54+
return isSlimeChecker;
55+
}
56+
57+
@Override
58+
public boolean castAtEntity(Player caster, LivingEntity target, float power) {
59+
if (!(target instanceof Slime)) return false;
60+
Slime slime = (Slime) target;
61+
double rawOutputValue = variableMod.getValue(caster, null, slime.getSize());
62+
int finalSize = Util.clampValue(minSize, maxSize, (int)rawOutputValue);
63+
slime.setSize(finalSize);
64+
return true;
65+
}
66+
67+
@Override
68+
public boolean castAtEntity(LivingEntity target, float power) {
69+
return castAtEntity(null, target, power);
70+
}
71+
72+
}

src/com/nisovin/magicspells/util/Util.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,4 +769,11 @@ public static void forEachPlayerOnline(Consumer<? super Player> consumer) {
769769
forEachOrdered(Bukkit.getOnlinePlayers(), consumer);
770770
}
771771

772+
public static int clampValue(int min, int max, int value) {
773+
if (value < min) return min;
774+
if (value > max) return max;
775+
return value;
776+
}
777+
778+
772779
}

0 commit comments

Comments
 (0)