use of org.spongepowered.api.profile.GameProfile 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.profile.GameProfile 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;
}
}
use of org.spongepowered.api.profile.GameProfile 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.profile.GameProfile in project LanternServer by LanternPowered.
the class UserCollection method get.
@Override
public LanternSubject get(String identifier) {
final UUID uuid = parseUUID(identifier);
checkArgument(uuid != null, "Provided identifier must be a uuid, was %s", identifier);
final GameProfile profile;
try {
profile = Sponge.getServer().getGameProfileManager().get(uuid, true).get();
} catch (Exception e) {
throw new IllegalArgumentException("Failed to lookup game profile for " + uuid, e);
}
return new UserSubject(profile, this);
}
use of org.spongepowered.api.profile.GameProfile in project Nucleus by NucleusPowered.
the class GetUserCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
CompletableFuture<GameProfile> profile;
final String toGet;
final GameProfileManager manager = Sponge.getServer().getGameProfileManager();
if (args.hasAny(uuidKey)) {
UUID u = args.<UUID>getOne(uuidKey).get();
toGet = u.toString();
profile = manager.get(u, false);
} else {
toGet = args.<String>getOne(playerKey).get();
profile = manager.get(toGet, false);
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.getuser.starting", toGet));
profile.handle((gp, th) -> {
if (th != null || gp == null) {
if (th != null && Nucleus.getNucleus().isDebugMode()) {
th.printStackTrace();
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.getuser.failed", toGet));
// I have to return something, even though I don't care about it.
return 0;
}
// We have a game profile, it's been added to the cache. Create the user too, just in case.
Sponge.getServiceManager().provideUnchecked(UserStorageService.class).getOrCreate(gp);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.getuser.success", gp.getUniqueId().toString(), gp.getName().orElse("unknown")));
return 0;
});
return CommandResult.success();
}
Aggregations