/** * Gets the number of homes the player currently has. * * @param user The {@link UUID} of the player * @return The number of homes. */ default int getHomeCount(UUID user) { return getHomes(user).size(); }
/** * Modifies a home's location, if it exists, otherwise creates a home. This is subject to Nucleus' standard checks. * * @param cause The {@link Cause} of the change. The {@link PluginContainer} must be the root cause. * @param user The {@link UUID} of the user to modify the home for. * @param name The name of the home to modify or create. * @param location The location of the home. * @param rotation The rotation of the player when they return to this home. * @throws NucleusException if the home could not be created, due to home limits, or a plugin cancelled the event. */ default void modifyOrCreateHome(Cause cause, User user, String name, Location<World> location, Vector3d rotation) throws NucleusException { if (getHome(user, name).isPresent()) { modifyHome(cause, user, name, location, rotation); } else { createHome(cause, user, name, location, rotation); } }
/** * Gets the number of homes the player currently has. * * @param user The {@link User} * @return The number of homes. */ default int getHomeCount(User user) { return getHomeCount(user.getUniqueId()); }
/** * Removes a home. * * @param cause The {@link Cause} of the change. The {@link PluginContainer} must be the root cause. * @param user The {@link UUID} of the user to remove the home of. * @param name The name of the home to remove. * @throws NucleusException if the home could not be found, or a plugin cancelled the event. */ default void removeHome(Cause cause, UUID user, String name) throws NucleusException { removeHome(cause, getHome(user, name).orElseThrow(() -> new NucleusException(Text.of("Home does not exist"), NucleusException.ExceptionType.DOES_NOT_EXIST))); }
/** * Modifies a home's location. * * @param cause The {@link Cause} of the change. The {@link PluginContainer} must be the root cause. * @param user The {@link UUID} of the user to modify the home for. * @param name The name of the home to modify. * @param location The location of the home. * @param rotation The rotation of the player when they return to this home. * @throws NucleusException if the home could not be found, or a plugin cancelled the event. */ default void modifyHome(Cause cause, UUID user, String name, Location<World> location, Vector3d rotation) throws NucleusException { modifyHome(cause, getHome(user, name).orElseThrow(() -> new NucleusException(Text.of("Home does not exist"), NucleusException.ExceptionType.DOES_NOT_EXIST)), location, rotation); }
default void modifyHome(Cause cause, User user, String name, Location<World> location, Vector3d rotation) throws NucleusException { modifyHome(cause, user.getUniqueId(), name, location, rotation); }
default Optional<Home> getHome(User user, String name) { return getHome(user.getUniqueId(), name); }
/** * Modifies a home's location, if it exists, otherwise creates a home. This is subject to Nucleus' standard checks. * * @param cause The {@link Cause} of the change. The {@link PluginContainer} must be the root cause. * @param user The {@link UUID} of the user to modify the home for. * @param name The name of the home to modify or create. * @param location The location of the home. * @param rotation The rotation of the player when they return to this home. * @throws NucleusException if the home could not be created, due to home limits, or a plugin cancelled the event. * @throws NoSuchPlayerException if the supplied UUID does not map to a known user */ default void modifyOrCreateHome(Cause cause, UUID user, String name, Location<World> location, Vector3d rotation) throws NucleusException, NoSuchPlayerException { modifyOrCreateHome(cause, Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(user).orElseThrow(NoSuchPlayerException::new), name, location, rotation); }
default void createHome(Cause cause, UUID user, String name, Location<World> location, Vector3d rotation) throws NucleusException, NoSuchPlayerException { createHome(cause, Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(user).orElseThrow(NoSuchPlayerException::new), name, location, rotation); }
/** * Gets the {@link Home}s for the specified user, identified by their UUID. * * @param user The {@link UUID} * @return The homes. */ default List<Home> getHomes(User user) { return getHomes(user.getUniqueId()); }
@GET @Path("/home/{player}") @Permission({ "home", "list" }) @ApiOperation(value = "List homes", notes = "Get a list of all the homes of a player.") public Collection<CachedNamedLocation> listHomes( @PathParam("player") @ApiParam("The uuid of the player") CachedPlayer player) throws NotFoundException { Optional<NucleusHomeService> optSrv = NucleusAPI.getHomeService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues home service not available"); } NucleusHomeService srv = optSrv.get(); return WebAPI.runOnMain( () -> srv.getHomes(player.getUUID()).stream() .map(CachedNamedLocation::new) .collect(Collectors.toList()) ); }