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 ALLOW_PLAYER_CHANGE_WORLD #4104

Open
wants to merge 2 commits into
base: 1.21.1
Choose a base branch
from

Conversation

fishshi
Copy link

@fishshi fishshi commented Sep 20, 2024

ALLOW_PLAYER_CHANGE_WORLD: Called when the player's dimension changes to check if the player is allowed to cross dimensions.

solve issue:
#3294 (comment)

@@ -64,6 +64,16 @@ public void onInitialize() {
LOGGER.info("Entity {} Killed: {}", entity, killed);
});

ServerEntityWorldChangeEvents.ALLOW_PLAYER_CHANGE_WORLD.register((player, origin, destination) -> {
if (player.getStackInHand(Hand.MAIN_HAND).getItem() == Items.END_ROD) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick:

Suggested change
if (player.getStackInHand(Hand.MAIN_HAND).getItem() == Items.END_ROD) {
if (player.getMainHandStack().isOf(Items.END_ROD)) {

*/
public static final Event<AllowPlayerChange> ALLOW_PLAYER_CHANGE_WORLD = EventFactory.createArrayBacked(AllowPlayerChange.class, callbacks -> (player, origin, destination) -> {
for (AllowPlayerChange callback : callbacks) {
if (!callback.allowChangeWorld(player, origin, destination)){
Copy link
Contributor

Choose a reason for hiding this comment

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

Checkstyle will fail:

Suggested change
if (!callback.allowChangeWorld(player, origin, destination)){
if (!callback.allowChangeWorld(player, origin, destination)) {

Copy link
Author

Choose a reason for hiding this comment

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

thank you!

@fishshi fishshi force-pushed the feature/ALLOW_PLAYER_CHANGE_WORLD branch from 1fd397d to e36f266 Compare September 29, 2024 02:25
@@ -75,6 +88,19 @@ public interface AfterEntityChange {
void afterChangeWorld(Entity originalEntity, Entity newEntity, ServerWorld origin, ServerWorld destination);
}

@FunctionalInterface
public interface AllowPlayerChange {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be limited to just players, other entities are allowed to use portals.

I think its also worth looking at 1.21.2 as I know they changed a lot of this teleportation code.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this event is currently only used to restrict players when crossing dimensions; other entities are not affected. I believe there are very few scenarios where restricting entities from crossing dimensions would be necessary.

Copy link
Author

Choose a reason for hiding this comment

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

Additionally, I will read through 1.21.2 as soon as possible, and I may be able to provide feedback by tomorrow.

Copy link
Author

Choose a reason for hiding this comment

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

I have reviewed the relevant source code for 24w39a, and there are not many changes regarding the dimension-crossing code. Through testing, I can assure you that this event works correctly in the latest version as well.

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.

3 participants