Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel spells casted on players? API? #1405

Open
CouleeDev opened this issue Feb 1, 2025 · 3 comments
Open

Cancel spells casted on players? API? #1405

CouleeDev opened this issue Feb 1, 2025 · 3 comments
Assignees
Labels
API Questions about API use

Comments

@CouleeDev
Copy link

Hi! Thank you for your awesome plugin! I have a custom PvP timer system and I have already canceled damage-related spells listening for Projectiles, however, there are some spells, like the Blinding, Poison, Wind (Flipendo?) that still target other players. How can I listen or cancel them to act on other players?

@NathanWolf NathanWolf self-assigned this Feb 1, 2025
@NathanWolf NathanWolf added the API Questions about API use label Feb 1, 2025
@NathanWolf
Copy link
Member

Hello!

Thanks for your interest :)

The cleanest way to do that is to use the Magic API, so that your plugin can work as a PVP status provider.

If that's something you're up for doing, it's pretty easy, especially if your plugin already uses Maven for building.

Here are the general instructions for using the API, including Maven repository and dependency information:

https://github.com/elBukkit/MagicPlugin/tree/master/MagicAPI

This also shows how to get a reference to the MageController instance from the plugin.

Then what you would do is implement the PVPController interface in your plugin. This interface just has one method:

boolean isPVPAllowed(Player player, Location location);

This is asking if a player can PVP in a specific location. The location will be the target of the spell, so not necessarily in the same place as the player. This could be important if you have pvp-free zones that a player could try to shoot at from outside the zone. If location is irrelevant for your plugin then of course you can just ignore that parameter.

And then finally you call MageController.register, passing the instance to your class where you've implemented PVPController.

If you do all of that, then Magic will ask your plugin any time a player casts a spell, whether or not that spell can target another player. This will prevent the spell from hitting players at all, the same as if you were using WorldGuard or some other supported PVP / Protection plugin.

Note that some spells are tagged as "friendly", such as the heal spell, and will be allowed either way. This can be changed in the spell's configs if that ends up being a problem.

I hope that helps, let me know if you get stuck or have any questions!

@CouleeDev
Copy link
Author

I have a survival server, in which at some times of the day, PvP is activated. However, I don't want to disable the spells entirely, because my players use them to hit mobs and sometimes PvP will be active. Is there a way to get if the spell will target specifically on a player with that method?
As I said, my problem at the moment is spells that act on players but don't do damage, like Flipendo, I want it to move away mobs but not players, or the Poison one, which even though I disabled Projectile damage when PvP is disabled, the Poison effect still applies.

@NathanWolf
Copy link
Member

Yup, if you do what I outlined above all of the spells will still work, they just wont' target other players.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Questions about API use
Projects
None yet
Development

No branches or pull requests

2 participants