use of org.spongepowered.api.service.context.Context in project LanternServer by LanternPowered.
the class LanternWorld method interactBlock.
private boolean interactBlock(int x, int y, int z, Direction side, @Nullable GameProfile profile, @Nullable ItemStack itemStack) {
checkNotNull(side, "side");
final LanternBlockType blockType = ((LanternBlockType) getBlockType(x, y, z));
final BehaviorPipeline<Behavior> pipeline = blockType.getPipeline();
final CauseStack causeStack = CauseStack.current();
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
frame.addContext(ContextKeys.INTERACTION_FACE, side);
frame.addContext(ContextKeys.BLOCK_LOCATION, new Location<>(this, x, y, z));
frame.addContext(ContextKeys.BLOCK_TYPE, blockType);
if (profile != null) {
frame.addContext(EventContextKeys.PLAYER_SIMULATED, profile);
}
if (itemStack != null) {
frame.addContext(ContextKeys.USED_ITEM_STACK, itemStack);
}
final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
// Just pass an object trough to make sure that a value is present when successful
if (context.process(pipeline.pipeline(InteractWithBlockBehavior.class), (ctx, behavior) -> behavior.tryInteract(pipeline, ctx)).isSuccess()) {
context.accept();
return true;
}
context.revert();
return false;
}
}
use of org.spongepowered.api.service.context.Context in project Nucleus by NucleusPowered.
the class JailHandler method jailPlayer.
public boolean jailPlayer(User user, JailData data) {
ModularUserService modularUserService = plugin.getUserDataManager().getUnchecked(user);
JailUserDataModule jailUserDataModule = modularUserService.get(JailUserDataModule.class);
if (jailUserDataModule.getJailData().isPresent()) {
return false;
}
// Get the jail.
Optional<NamedLocation> owl = getJail(data.getJailName());
NamedLocation wl = owl.filter(x -> x.getLocation().isPresent()).orElseGet(() -> {
if (!getJails().isEmpty()) {
return null;
}
return getJails().entrySet().stream().findFirst().get().getValue();
});
if (wl == null) {
return false;
}
jailUserDataModule.setJailData(data);
if (user.isOnline()) {
Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
Player player = user.getPlayer().get();
plugin.getTeleportHandler().teleportPlayer(player, owl.get().getLocation().get(), owl.get().getRotation(), NucleusTeleportHandler.StandardTeleportMode.NO_CHECK, Sponge.getCauseStackManager().getCurrentCause());
modularUserService.get(FlyUserDataModule.class).setFlying(false);
});
} else {
jailUserDataModule.setJailOnNextLogin(true);
}
this.jailDataCache.put(user.getUniqueId(), new Context(NucleusJailService.JAIL_CONTEXT, data.getJailName()));
Sponge.getEventManager().post(new JailEvent.Jailed(user, CauseStackHelper.createCause(Util.getObjectFromUUID(data.getJailerInternal())), data.getJailName(), TextSerializers.FORMATTING_CODE.deserialize(data.getReason()), data.getRemainingTime().orElse(null)));
return true;
}
use of org.spongepowered.api.service.context.Context in project Nucleus by NucleusPowered.
the class JailHandler method accumulateContexts.
@Override
public void accumulateContexts(Subject calculable, Set<Context> accumulator) {
if (calculable instanceof User) {
UUID c = ((User) calculable).getUniqueId();
if (!jailDataCache.containsKey(c)) {
getPlayerJailDataInternal((User) calculable);
}
Context co = jailDataCache.get(c);
if (co != null) {
accumulator.add(co);
accumulator.add(jailContext);
}
}
}
Aggregations