forked from nisovin/MagicSpells
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #832 from TonytheMacaroni/main
Add startpose/stoppose/insideblock triggers, pose and fixedpose conditions, and PoseSpell
- Loading branch information
Showing
8 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
core/src/main/java/com/nisovin/magicspells/castmodifiers/conditions/FixedPoseCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.nisovin.magicspells.castmodifiers.conditions; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.LivingEntity; | ||
|
||
import com.nisovin.magicspells.castmodifiers.Condition; | ||
|
||
public class FixedPoseCondition extends Condition { | ||
|
||
@Override | ||
public boolean initialize(String var) { | ||
return var.isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean check(LivingEntity caster) { | ||
return caster.hasFixedPose(); | ||
} | ||
|
||
@Override | ||
public boolean check(LivingEntity caster, LivingEntity target) { | ||
return target.hasFixedPose(); | ||
} | ||
|
||
@Override | ||
public boolean check(LivingEntity caster, Location location) { | ||
return false; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
core/src/main/java/com/nisovin/magicspells/castmodifiers/conditions/PoseCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.nisovin.magicspells.castmodifiers.conditions; | ||
|
||
import java.util.Set; | ||
import java.util.EnumSet; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Pose; | ||
import org.bukkit.entity.LivingEntity; | ||
|
||
import com.nisovin.magicspells.castmodifiers.Condition; | ||
|
||
public class PoseCondition extends Condition { | ||
|
||
private final Set<Pose> poses = EnumSet.noneOf(Pose.class); | ||
|
||
@Override | ||
public boolean initialize(String var) { | ||
String[] split = var.split(","); | ||
|
||
for (String pose : split) { | ||
try { | ||
poses.add(Pose.valueOf(pose.trim().toUpperCase())); | ||
} catch (IllegalArgumentException e) { | ||
return false; | ||
} | ||
} | ||
|
||
return !poses.isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean check(LivingEntity caster) { | ||
return poses.contains(caster.getPose()); | ||
} | ||
|
||
@Override | ||
public boolean check(LivingEntity caster, LivingEntity target) { | ||
return poses.contains(target.getPose()); | ||
} | ||
|
||
@Override | ||
public boolean check(LivingEntity caster, Location location) { | ||
return false; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
core/src/main/java/com/nisovin/magicspells/spells/passive/InsideBlockListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.nisovin.magicspells.spells.passive; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.block.data.BlockData; | ||
|
||
import io.papermc.paper.event.entity.EntityInsideBlockEvent; | ||
|
||
import com.nisovin.magicspells.MagicSpells; | ||
import com.nisovin.magicspells.util.OverridePriority; | ||
import com.nisovin.magicspells.spells.passive.util.PassiveListener; | ||
|
||
public class InsideBlockListener extends PassiveListener { | ||
|
||
private List<BlockData> blockData; | ||
|
||
@Override | ||
public void initialize(String var) { | ||
if (var == null || var.isEmpty()) return; | ||
|
||
blockData = new ArrayList<>(); | ||
|
||
for (String data : var.split(",(?![^\\[]*])")) { | ||
try { | ||
blockData.add(Bukkit.createBlockData(data.trim().toLowerCase())); | ||
} catch (IllegalArgumentException e) { | ||
MagicSpells.error("Invalid block data '" + data + "' in insideblock trigger on passive spell '" + passiveSpell.getInternalName() + "'"); | ||
} | ||
} | ||
} | ||
|
||
@OverridePriority | ||
@EventHandler | ||
public void onSwim(EntityInsideBlockEvent event) { | ||
if (!isCancelStateOk(event.isCancelled())) return; | ||
if (!(event.getEntity() instanceof LivingEntity caster) || !canTrigger(caster) || !hasSpell(caster)) return; | ||
|
||
Block block = event.getBlock(); | ||
if (blockData != null && check(block)) return; | ||
|
||
boolean casted = passiveSpell.activate(caster, block.getLocation().add(0.5, 0.5, 0.5)); | ||
if (cancelDefaultAction(casted)) event.setCancelled(true); | ||
} | ||
|
||
private boolean check(Block block) { | ||
BlockData bd = block.getBlockData(); | ||
|
||
for (BlockData data : blockData) | ||
if (bd.matches(data)) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
core/src/main/java/com/nisovin/magicspells/spells/passive/StartPoseListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.nisovin.magicspells.spells.passive; | ||
|
||
import java.util.Set; | ||
import java.util.EnumSet; | ||
|
||
import org.bukkit.entity.Pose; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.event.entity.EntityPoseChangeEvent; | ||
|
||
import com.nisovin.magicspells.MagicSpells; | ||
import com.nisovin.magicspells.util.OverridePriority; | ||
import com.nisovin.magicspells.spells.passive.util.PassiveListener; | ||
|
||
public class StartPoseListener extends PassiveListener { | ||
|
||
private Set<Pose> poses; | ||
|
||
@Override | ||
public void initialize(String var) { | ||
if (var == null || var.isEmpty()) return; | ||
|
||
poses = EnumSet.noneOf(Pose.class); | ||
|
||
for (String pose : var.split(",")) { | ||
try { | ||
poses.add(Pose.valueOf(pose.trim().toUpperCase())); | ||
} catch (IllegalArgumentException e) { | ||
MagicSpells.error("Invalid pose '" + pose + "' in startpose trigger on passive spell '" + passiveSpell.getInternalName() + "'"); | ||
} | ||
} | ||
} | ||
|
||
@OverridePriority | ||
@EventHandler | ||
public void onPoseChange(EntityPoseChangeEvent event) { | ||
if (!(event.getEntity() instanceof LivingEntity caster) || !canTrigger(caster) || !hasSpell(caster)) return; | ||
if (poses != null && !poses.contains(event.getPose())) return; | ||
|
||
passiveSpell.activate(caster); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
core/src/main/java/com/nisovin/magicspells/spells/passive/StopPoseListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.nisovin.magicspells.spells.passive; | ||
|
||
import java.util.Set; | ||
import java.util.EnumSet; | ||
|
||
import org.bukkit.entity.Pose; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.event.entity.EntityPoseChangeEvent; | ||
|
||
import com.nisovin.magicspells.MagicSpells; | ||
import com.nisovin.magicspells.util.OverridePriority; | ||
import com.nisovin.magicspells.spells.passive.util.PassiveListener; | ||
|
||
public class StopPoseListener extends PassiveListener { | ||
|
||
private Set<Pose> poses; | ||
|
||
@Override | ||
public void initialize(String var) { | ||
if (var == null || var.isEmpty()) return; | ||
|
||
poses = EnumSet.noneOf(Pose.class); | ||
|
||
for (String pose : var.split(",")) { | ||
try { | ||
poses.add(Pose.valueOf(pose.trim().toUpperCase())); | ||
} catch (IllegalArgumentException e) { | ||
MagicSpells.error("Invalid pose '" + pose + "' in startpose trigger on passive spell '" + passiveSpell.getInternalName() + "'"); | ||
} | ||
} | ||
} | ||
|
||
@OverridePriority | ||
@EventHandler | ||
public void onPoseChange(EntityPoseChangeEvent event) { | ||
if (!(event.getEntity() instanceof LivingEntity caster) || !canTrigger(caster) || !hasSpell(caster)) return; | ||
if (poses != null && !poses.contains(caster.getPose())) return; | ||
|
||
passiveSpell.activate(caster); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
core/src/main/java/com/nisovin/magicspells/spells/targeted/PoseSpell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.nisovin.magicspells.spells.targeted; | ||
|
||
import org.bukkit.entity.Pose; | ||
import org.bukkit.entity.LivingEntity; | ||
|
||
import com.nisovin.magicspells.util.SpellData; | ||
import com.nisovin.magicspells.util.CastResult; | ||
import com.nisovin.magicspells.util.TargetInfo; | ||
import com.nisovin.magicspells.util.MagicConfig; | ||
import com.nisovin.magicspells.spells.TargetedSpell; | ||
import com.nisovin.magicspells.util.config.ConfigData; | ||
import com.nisovin.magicspells.spells.TargetedEntitySpell; | ||
|
||
public class PoseSpell extends TargetedSpell implements TargetedEntitySpell { | ||
|
||
private final ConfigData<Pose> pose; | ||
|
||
private final ConfigData<Boolean> fixed; | ||
|
||
public PoseSpell(MagicConfig config, String spellName) { | ||
super(config, spellName); | ||
|
||
pose = getConfigDataEnum("pose", Pose.class, null); | ||
fixed = getConfigDataBoolean("fixed", false); | ||
} | ||
|
||
@Override | ||
public CastResult cast(SpellData data) { | ||
TargetInfo<LivingEntity> info = getTargetedEntity(data); | ||
if (info.noTarget()) return noTarget(info); | ||
|
||
return castAtEntity(info.spellData()); | ||
} | ||
|
||
@Override | ||
public CastResult castAtEntity(SpellData data) { | ||
Pose pose = this.pose.get(data); | ||
if (pose == null) return new CastResult(PostCastAction.ALREADY_HANDLED, data); | ||
|
||
data.target().setPose(pose, fixed.get(data)); | ||
|
||
playSpellEffects(data); | ||
return new CastResult(PostCastAction.HANDLE_NORMALLY, data); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters