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 getWrapperClass() to packet type #1159

Open
wants to merge 4 commits into
base: 2.0
Choose a base branch
from

Conversation

spring-dependency-management
Copy link
Contributor

@spring-dependency-management spring-dependency-management commented Mar 6, 2025

There is no other way to get a packet wrapper for a given type other than a huge if else chain

With this, you can do:

PacketWrapper<?> wrapper = ReflectionUtil.createInstance(
    packetReceiveEvent.getPacketType().getWrapperClass(), new Class[]{PacketReceiveEvent.class}, packetReceiveEvent
);


public static <T> T createInstance(Class<T> clazz, Class<?>[] types, Object... args) {
  try {
    Constructor<T> constructor = clazz.getDeclaredConstructor(types);
    constructor.setAccessible(true);
    return (T)constructor.newInstance(args);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

@spring-dependency-management
Copy link
Contributor Author

merge when? Don't want it getting out of date

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

Successfully merging this pull request may close these issues.

2 participants