mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-26 18:33:04 +00:00
Add ContextUpdateEvent and related functionality
This commit is contained in:
30 files changed
+446
-110
No files matched your search
@@ -156,7 +156,10 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
|
||||
@Override
|
||||
protected void setupContextManager() {
|
||||
this.contextManager = new SpongeContextManager(this);
|
||||
this.contextManager.registerCalculator(new WorldCalculator(this));
|
||||
|
||||
WorldCalculator worldCalculator = new WorldCalculator(this);
|
||||
this.bootstrap.getGame().getEventManager().registerListeners(this.bootstrap, worldCalculator);
|
||||
this.contextManager.registerCalculator(worldCalculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,11 +67,7 @@ public class SpongeContextManager extends ContextManager<Subject, Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCache(Subject subject) {
|
||||
if (subject == null) {
|
||||
throw new NullPointerException("subject");
|
||||
}
|
||||
|
||||
protected void invalidateCache(Subject subject) {
|
||||
QueryOptionsCache<Subject> cache = this.subjectCaches.getIfPresent(subject);
|
||||
if (cache != null) {
|
||||
cache.invalidate();
|
||||
|
||||
@@ -38,7 +38,11 @@ import net.luckperms.api.context.ImmutableContextSet;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.entity.MoveEntityEvent;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
@@ -84,4 +88,19 @@ public class WorldCalculator implements ContextCalculator<Subject> {
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Listener(order = Order.LAST)
|
||||
public void onWorldChange(MoveEntityEvent.Teleport e) {
|
||||
Entity targetEntity = e.getTargetEntity();
|
||||
if (!(targetEntity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getFromTransform().getExtent().equals(e.getToTransform().getExtent())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) targetEntity;
|
||||
this.plugin.getContextManager().signalContextUpdate(player);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -64,7 +64,8 @@ public class ContextCalculatorProxy implements ForwardingContextCalculator<Subje
|
||||
|
||||
@Override
|
||||
public boolean add(Context context) {
|
||||
if (context.getKey().isEmpty() || context.getValue().isEmpty()) {
|
||||
if (!net.luckperms.api.context.Context.isValidKey(context.getKey()) ||
|
||||
!net.luckperms.api.context.Context.isValidValue(context.getValue())) {
|
||||
return false;
|
||||
}
|
||||
this.consumer.accept(context.getKey(), context.getValue());
|
||||
|
||||
Reference in new issue
Block a user