1
0
mirror of https://github.com/lucko/LuckPerms.git synced 2025-08-22 06:02:49 +02:00

Use builtin Fabric world change event

This commit is contained in:
Luck
2024-07-07 21:31:34 +01:00
parent 9cc129466b
commit b21753f5e9
4 changed files with 5 additions and 52 deletions

View File

@@ -21,7 +21,8 @@ dependencies {
'fabric-api-base',
'fabric-command-api-v2',
'fabric-lifecycle-events-v1',
'fabric-networking-api-v1'
'fabric-networking-api-v1',
'fabric-entity-events-v1'
]
apiModules.forEach {

View File

@@ -29,7 +29,7 @@ import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.ImmutableContextSetImpl;
import me.lucko.luckperms.common.util.EnumNamer;
import me.lucko.luckperms.fabric.LPFabricPlugin;
import me.lucko.luckperms.fabric.event.PlayerChangeWorldCallback;
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityWorldChangeEvents;
import net.luckperms.api.context.Context;
import net.luckperms.api.context.ContextCalculator;
import net.luckperms.api.context.ContextConsumer;
@@ -67,7 +67,7 @@ public class FabricPlayerCalculator implements ContextCalculator<ServerPlayerEnt
}
public void registerListeners() {
PlayerChangeWorldCallback.EVENT.register(this::onWorldChange);
ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register(this::onWorldChange);
}
@Override
@@ -118,7 +118,7 @@ public class FabricPlayerCalculator implements ContextCalculator<ServerPlayerEnt
return key.toString();
}
private void onWorldChange(ServerWorld origin, ServerWorld destination, ServerPlayerEntity player) {
private void onWorldChange(ServerPlayerEntity player, ServerWorld origin, ServerWorld destination) {
if (this.world) {
this.plugin.getContextManager().invalidateCache(player);
this.plugin.getContextManager().signalContextUpdate(player);

View File

@@ -1,42 +0,0 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.fabric.event;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
// TODO: Use Fabric API alternative when merged.
public interface PlayerChangeWorldCallback {
Event<PlayerChangeWorldCallback> EVENT = EventFactory.createArrayBacked(PlayerChangeWorldCallback.class, callbacks -> (originalWorld, destination, player) -> {
for (PlayerChangeWorldCallback callback : callbacks) {
callback.onChangeWorld(originalWorld, destination, player);
}
});
void onChangeWorld(ServerWorld originalWorld, ServerWorld destination, ServerPlayerEntity player);
}

View File

@@ -31,7 +31,6 @@ import me.lucko.luckperms.common.context.manager.QueryOptionsCache;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.verbose.event.CheckOrigin;
import me.lucko.luckperms.fabric.context.FabricContextManager;
import me.lucko.luckperms.fabric.event.PlayerChangeWorldCallback;
import me.lucko.luckperms.fabric.model.MixinUser;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.util.Tristate;
@@ -161,9 +160,4 @@ public abstract class ServerPlayerEntityMixin implements MixinUser {
MixinUser oldMixin = (MixinUser) oldPlayer;
luckperms$initializePermissions(oldMixin.luckperms$getUser());
}
@Inject(at = @At("TAIL"), method = "worldChanged")
private void luckperms$onChangeDimension(ServerWorld targetWorld, CallbackInfo ci) {
PlayerChangeWorldCallback.EVENT.invoker().onChangeWorld(this.getServerWorld(), targetWorld, (ServerPlayerEntity) (Object) this);
}
}