use of org.spongepowered.api.service.context.Context in project SpongeCommon by SpongePowered.
the class MixinWorld method getContext.
@Override
public Context getContext() {
if (this.worldContext == null) {
WorldInfo worldInfo = getWorldInfo();
if (worldInfo == null) {
// We still have to consider some mods are making dummy worlds that
// override getWorldInfo with a null, or submit a null value.
worldInfo = new WorldInfo(new WorldSettings(0, GameType.NOT_SET, false, false, WorldType.DEFAULT), "sponge$dummy_World");
}
this.worldContext = new Context(Context.WORLD_KEY, worldInfo.getWorldName());
}
return this.worldContext;
}
use of org.spongepowered.api.service.context.Context in project SpongeCommon by SpongePowered.
the class SpongeContextCalculator method accumulateContexts.
@Override
public void accumulateContexts(Subject subject, Set<Context> accumulator) {
Optional<CommandSource> subjSource = subject.getCommandSource();
if (subjSource.isPresent()) {
CommandSource source = subjSource.get();
if (source instanceof Locatable) {
World currentExt = ((Locatable) source).getWorld();
accumulator.add(currentExt.getContext());
accumulator.add((currentExt.getDimension().getContext()));
}
if (source instanceof RemoteSource) {
RemoteSource rem = (RemoteSource) source;
accumulator.addAll(this.remoteIpCache.getUnchecked(rem));
accumulator.addAll(this.localIpCache.getUnchecked(rem));
accumulator.add(new Context(Context.LOCAL_PORT_KEY, String.valueOf(rem.getConnection().getVirtualHost().getPort())));
accumulator.add(new Context(Context.LOCAL_HOST_KEY, rem.getConnection().getVirtualHost().getHostName()));
}
}
}
use of org.spongepowered.api.service.context.Context in project LuckPerms by lucko.
the class DelegatingMutableContextSet method remove.
@Override
public boolean remove(Object o) {
if (o instanceof Context) {
Context context = (Context) o;
if (context.getKey().isEmpty() || context.getValue().isEmpty()) {
return false;
}
boolean had = this.delegate.has(context);
this.delegate.remove(context.getKey(), context.getValue());
return had;
}
return false;
}
use of org.spongepowered.api.service.context.Context in project LanternServer by LanternPowered.
the class LanternWorld method placeBlock.
@Override
public boolean placeBlock(int x, int y, int z, BlockState block, Direction side, @Nullable GameProfile profile) {
final BehaviorPipeline<Behavior> pipeline = ((LanternBlockType) block.getType()).getPipeline();
final CauseStack causeStack = CauseStack.current();
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
frame.addContext(ContextKeys.USED_BLOCK_STATE, block);
frame.addContext(ContextKeys.INTERACTION_FACE, side);
frame.addContext(ContextKeys.BLOCK_LOCATION, new Location<>(this, x, y, z));
frame.addContext(ContextKeys.BLOCK_TYPE, block.getType());
if (profile != null) {
frame.addContext(EventContextKeys.PLAYER_SIMULATED, profile);
}
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(PlaceBlockBehavior.class), (ctx, behavior) -> behavior.tryPlace(pipeline, ctx)).isSuccess()) {
context.accept();
return true;
}
context.revert();
return false;
}
}
use of org.spongepowered.api.service.context.Context in project LanternServer by LanternPowered.
the class LanternWorld method digBlock.
private boolean digBlock(int x, int y, int z, @Nullable GameProfile profile, @Nullable ItemStack itemStack) {
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.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(BreakBlockBehavior.class), (ctx, behavior) -> behavior.tryBreak(pipeline, ctx)).isSuccess()) {
context.accept();
return true;
}
context.revert();
return false;
}
}
Aggregations