Skip to content

Commit 07c6cb2

Browse files
Added targeted.CollisionSpell
This spell is for setting if an entity collides with others. It has an option called target-state which accepts a TargetBooleanValue and defaults to toggle Added targeted.CustomNameVisibilitySpell This spell is for setting if the custom name on an entity is visible normally. Accepts an option called target-state which accepts a TargetBooleanValue and defaults to toggle. More information about this format may be found in the MagicSpells Config Objects file.
1 parent 9e25424 commit 07c6cb2

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

MagicSpells Config Objects.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Vector
66
--------
77
The vector format is `x,y,z` where each letter may be replaced with a `double` value.
88

9+
TargetBooleanState
10+
--------
11+
The TargetBooleanState format is just a string which represents a 3 outcome type boolean state, `on`, `off`, and `toggle`.
12+
913
Prompt
1014
--------
1115
- `prompt-type` accepts a `string` and will fail if not set. Current valid values are
@@ -43,4 +47,4 @@ ConversationFactory
4347
- `local-echo` accepts a `boolean` and defaults to `true`.
4448
- `first-prompt` accepts a `configuration section` in `prompt` format.
4549
- `timeout-seconds` accepts an `integer` and defaults to `30`.
46-
- `escape-sequence` accepts a `string` and defaults to nothing.
50+
- `escape-sequence` accepts a `string` and defaults to nothing.
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 CollisionSpell extends TargetedSpell implements TargetedEntitySpell {
12+
13+
private TargetBooleanState targetBooleanState;
14+
15+
public CollisionSpell(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.setCollidable(targetBooleanState.getBooleanState(target.isCollidable()));
29+
}
30+
return PostCastAction.HANDLE_NORMALLY;
31+
}
32+
33+
@Override
34+
public boolean castAtEntity(Player caster, LivingEntity target, float power) {
35+
target.setCollidable(targetBooleanState.getBooleanState(target.isCollidable()));
36+
return true;
37+
}
38+
39+
@Override
40+
public boolean castAtEntity(LivingEntity target, float power) {
41+
target.setCollidable(targetBooleanState.getBooleanState(target.isCollidable()));
42+
return true;
43+
}
44+
45+
}
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 CustomNameVisibilitySpell extends TargetedSpell implements TargetedEntitySpell {
12+
13+
private TargetBooleanState targetBooleanState;
14+
15+
public CustomNameVisibilitySpell(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.setCustomNameVisible(targetBooleanState.getBooleanState(target.isCustomNameVisible()));
29+
}
30+
return PostCastAction.HANDLE_NORMALLY;
31+
}
32+
33+
@Override
34+
public boolean castAtEntity(Player caster, LivingEntity target, float power) {
35+
target.setCustomNameVisible(targetBooleanState.getBooleanState(target.isCustomNameVisible()));
36+
return true;
37+
}
38+
39+
@Override
40+
public boolean castAtEntity(LivingEntity target, float power) {
41+
target.setCustomNameVisible(targetBooleanState.getBooleanState(target.isCustomNameVisible()));
42+
return true;
43+
}
44+
45+
}

0 commit comments

Comments
 (0)