Java源码示例:org.spongepowered.api.world.Locatable

示例1
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, TimePermissions.UC_TIME_TIME_BASE);
    checkPermission(sender, TimePermissions.UC_TIME_TIME_DAY);

    World world;
    if (sender instanceof Locatable) {
        world = ((Locatable) sender).getWorld();
    } else {
        throw new ErrorMessageException(Messages.getFormatted(sender, "core.noplayer"));
    }
    Long ticks = 24000 - (world.getProperties().getWorldTime() % 24000);
    world.getProperties().setWorldTime(world.getProperties().getWorldTime() + ticks);
    Messages.send(sender, "time.command.time.set.day");
    return CommandResult.success();
}
 
示例2
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, TimePermissions.UC_TIME_TIME_BASE);
    checkPermission(sender, TimePermissions.UC_TIME_TIME_NIGHT);

    World world;
    if (sender instanceof Locatable) {
        world = ((Locatable) sender).getWorld();
    } else {
        throw new ErrorMessageException(Messages.getFormatted(sender, "core.noplayer"));
    }
    //Players can enter their bed at 12541 ticks
    Long ticks = 12541 - (world.getProperties().getWorldTime() % 24000);
    world.getProperties().setWorldTime(world.getProperties().getWorldTime() + ticks);
    Messages.send(sender, "time.command.time.set.night");
    return CommandResult.success();
}
 
示例3
/**
 * Returns a list of all entities which satisfy the string.
 * This can be empty if no entities are found.
 *
 * @param s The string to search for
 * @return All entities which statisfy the string
 */
public static List<Entity> multipleEntities(CommandSource source, String s) {
    List<Entity> matches = new ArrayList<>();

    Optional<Player> match = Sponge.getServer().getPlayer(s);
    match.ifPresent(matches::add);

    try {
        UUID uuid = UUID.fromString(s);
        if (source instanceof Locatable) {
            Locatable loc = (Locatable) source;
            Optional<Entity> en = loc.getWorld().getEntity(uuid);
            en.ifPresent(matches::add);
        }
    } catch (IllegalArgumentException ignored) {
    }

    if (s.startsWith("@")) {
        org.spongepowered.api.text.selector.Selector selector = org.spongepowered.api.text.selector.Selector.parse(s);
        selector.resolve(source).forEach(matches::add);
    }

    return matches;
}
 
示例4
@Override
public Optional<Vector3d> getPosition() {
	if (delegate instanceof Locatable) {
		return Optional.of(((Locatable) delegate).getLocation().getPosition());
	}
	
	return Optional.empty();
}
 
示例5
@Override
public Optional<World> getWorld() {
	if (delegate instanceof Locatable) {
		return Optional.ofNullable(plugin.getWorld(((Locatable) delegate).getLocation().getExtent().getUniqueId()));
	}
	
	return Optional.empty();
}
 
示例6
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, WeatherPermissions.UC_WEATHER_WEATHER_SUN);
    World world;
    if (sender instanceof Locatable) {
        world = ((Locatable) sender).getWorld();
    } else {
        throw new ErrorMessageException(Messages.getFormatted(sender, "core.noplayer"));
    }
    world.setWeather(Weathers.RAIN);
    Messages.send(sender, "weather.command.weather.success", "%weather%", "rain", "%world%", world.getName());
    return CommandResult.success();
}
 
示例7
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, WeatherPermissions.UC_WEATHER_WEATHER_SUN);
    World world;
    if (sender instanceof Locatable) {
        world = ((Locatable) sender).getWorld();
    } else {
        throw new ErrorMessageException(Messages.getFormatted(sender, "core.noplayer"));
    }
    world.setWeather(Weathers.CLEAR);
    Messages.send(sender, "weather.command.weather.success", "%weather%", "sun", "%world%", world.getName());
    return CommandResult.success();
}
 
示例8
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, WeatherPermissions.UC_WEATHER_WEATHER_SUN);
    World world;
    if (sender instanceof Locatable) {
        world = ((Locatable) sender).getWorld();
    } else {
        throw new ErrorMessageException(Messages.getFormatted(sender, "core.noplayer"));
    }
    world.setWeather(Weathers.THUNDER_STORM);
    Messages.send(sender, "weather.command.weather.success", "%weather%", "thunder", "%world%", world.getName());
    return CommandResult.success();
}
 
示例9
/**
 * Saves event records when a player closes or opens an Inventory.
 *
 * @param event  InteractInventoryEvent
 * @param player Player
 */
@Listener(order = Order.POST)
public void onInteractInventory(InteractInventoryEvent event, @Root Player player) {
    if (!(event.getTargetInventory() instanceof CarriedInventory)
            || (!Prism.getInstance().getConfig().getEventCategory().isInventoryClose() && !Prism.getInstance().getConfig().getEventCategory().isInventoryOpen())) {
        return;
    }

    CarriedInventory<? extends Carrier> carriedInventory = (CarriedInventory<? extends Carrier>) event.getTargetInventory();
    if (carriedInventory.getCarrier().filter(Player.class::isInstance).isPresent()) {
        return;
    }

    // Get the location of the inventory otherwise fallback on the players location
    Location<World> location = carriedInventory.getCarrier()
            .filter(Locatable.class::isInstance)
            .map(Locatable.class::cast)
            .map(Locatable::getLocation)
            .orElse(player.getLocation());

    // Get the title of the inventory otherwise fallback on the class name
    String title = carriedInventory.getProperty(InventoryTitle.class, InventoryTitle.PROPERTY_NAME)
            .map(InventoryTitle::getValue)
            .map(Text::toPlain)
            .orElse(carriedInventory.getClass().getSimpleName());

    PrismRecord.EventBuilder eventBuilder = PrismRecord.create()
            .source(event.getCause())
            .container(title)
            .location(location);

    if (event instanceof InteractInventoryEvent.Close && Prism.getInstance().getConfig().getEventCategory().isInventoryClose()) {
        eventBuilder.event(PrismEvents.INVENTORY_CLOSE).buildAndSave();
    } else if (event instanceof InteractInventoryEvent.Open && Prism.getInstance().getConfig().getEventCategory().isInventoryOpen()) {
        eventBuilder.event(PrismEvents.INVENTORY_OPEN).buildAndSave();
    }
}