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

Add DamageType RegistryEvent #11783

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Chaosdave34
Copy link

Add RegistryEvent for DamageType

Changes:

  • Add DamageTypeRegistryEntry
  • Add PaperDamageTypeRegistryEntry
  • Make DamageType PaperRegistry writeable
  • Add DamageType Event to RegistryEvents

But I ran into the problem, that DamageEffect uses Bukkit.getUnsafe() for initialization and that seems to be not available at bootstrap. I fixed that with the following changes, but I am not sure if that's the correct way to do is as it may break plugins:

  • Turn DamageType interface into an enum
  • Add CraftDamageType damageEffectToBukkit() and damageEffectToNMS() to CraftDamageType
  • Add getSoundForDamageEffect() to UnsafeValues (and CraftMagicNumbers)
  • Deprecated CraftDamageEffect, UnsafeValues#getDamageEffect() and DamageEffect#getDamageEffect()

The only breaking change I see is when someone tries to cast DamageType to CraftDamageType which is no longer possible with my approach.

@Chaosdave34 Chaosdave34 requested a review from a team as a code owner December 23, 2024 12:29
/**
* Represents a type of effect that occurs when damage is inflicted. Currently,
* effects only determine the sound that plays.
*/
@ApiStatus.Experimental
public interface DamageEffect {
public enum DamageEffect {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why downgrade a perfectly working interface to enum? Not only this brings a lot of issues that both spigot and paper are fighting right now, but it breaks plugins without any added rewriting in this pr.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an enum instead of an interface was the first idea that came to my mind. I know that it comes with the mentioned problems.

Maybe use the id of the damage effect as String instead of the Bukkit Interface for DamageTypeRegistryEntry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, either other form of reference, or trying to resolve it not using CraftServer.

I think a pretty valid solution could be providing another access to unsafe values other than trough craft server. There was already a discussion of making some static access method in a pr, including to get the data and protocol versions in bootstrap, but that died down. Basically a provider class, implementation of that, retrieve it with https://www.baeldung.com/java-spi and hold it in a local class within the static getter method in UnsafeValues class

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with that sentiment ^
Making this an enum is not something I'd like to see.
We'll end up with some version of unsafe values at bootstrap time down the line anyway so, yea.

Alternatively, we can attempt to predict that damage effects might be a registry value at some point?
Which would mean we could just move this to keys instead of the actual resolved value.
That would need a generated key class tho.
I'd personally be semi in favour of that approach as it means we won't have to break API there if that ever changes and it does get rid of the bootstrap issue. Will poke MM about it tho for his ideas.

Copy link
Author

@Chaosdave34 Chaosdave34 Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be a solution.

Additionally instead of having an extra class (StaticUnsafeValues), Bukkit's UnsafeValues interface could have a static getter.
The point where the provider is initialized is probably not the best, but it's loaded before the plugin bootstrapper runs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want a separate type called something like “APIBridge” that uses the service loader API for stuff like this, so we can move actual API out of UnsafeValues. UnsafeValues should be for actual “unsafe” api, not just a place to store “bridge” methods.

But either way, yeah, this shouldn’t be changed back to an enum.

@kennytv kennytv added the type: feature Request for a new Feature. label Dec 23, 2024
Copy link
Member

@Machine-Maker Machine-Maker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the StaticUnsafeValues, I have a slightly different idea on how to solve it, but it can just be left in for now, not a big deal.

There should be a standardized way to interact with the "pseudo-registries" types of which DamageEffect is part of. All the types on the server that implement StringRepresentable are a different sort of registry where there is a defined mapping between a string and an instance. There will be/already are other cases where a way to convert between them would be useful if we don't want to use an enum on the API side.

But this isn't something you have to figure out, that'll be for us to decide on.

…fects and deathMessageType no longer nullable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Request for a new Feature.
Projects
Status: Changes required
Development

Successfully merging this pull request may close these issues.

5 participants