/** * Saves this current kit's state. * * @throws IllegalStateException if the kit module isn't active. */ default void save() { NucleusAPI.getKitService().orElseThrow(() -> new IllegalStateException("No Kit module")).saveKit(this); }
/** * Obtains a collection of items that a player would obtain when redeeming the kit. * * @see NucleusKitService#getItemsForPlayer(Kit, Player) * * @param player The player * @return The items */ default Collection<ItemStack> getItemsForPlayer(Player player) { return NucleusAPI.getKitService().orElseThrow(() -> new IllegalStateException("No Kit module")).getItemsForPlayer(this, player); }
/** * Attempts to redeem this kit, saving it beforehand. * * @param player The player to redeem the kit for * @return The result * @throws KitRedeemException If the kit was not redeemed. */ default NucleusKitService.RedeemResult redeem(Player player) throws KitRedeemException { save(); NucleusKitService kitService = NucleusAPI.getKitService().orElseThrow(() -> new IllegalStateException("No Kit module")); return kitService.redeemKit(this, player, true); }
@GET @Path("/kit") @Permission({ "kit", "list" }) @ApiOperation(value = "List kits", notes = "Get a list of all the kits on the server.") public Collection<CachedKit> listKits() { Optional<NucleusKitService> optSrv = NucleusAPI.getKitService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues kit service not available"); } NucleusKitService srv = optSrv.get(); return WebAPI.runOnMain( () -> srv.getKitNames().stream() .map(name -> srv.getKit(name).map(CachedKit::new).orElse(null)) .collect(Collectors.toList()) ); }
@GET @Path("/kit/{name}") @Permission({ "kit", "one" }) @ApiOperation(value = "Get a kit", notes = "Get detailed information about a kit.") public CachedKit getKit(@PathParam("name") String name) throws NotFoundException { Optional<NucleusKitService> optSrv = NucleusAPI.getKitService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues kit service not available"); } NucleusKitService srv = optSrv.get(); return WebAPI.runOnMain(() -> { Optional<Kit> optKit = srv.getKit(name); if (!optKit.isPresent()) { throw new NotFoundException("Kit with name " + name + " not found"); } return new CachedKit(optKit.get()); }); }
@DELETE @Path("/kit/{name}") @Permission({ "kit", "delete" }) @ApiOperation(value = "Delete a kit", notes = "Delete an existing kit.") public CachedKit deleteKit(@PathParam("name") String name) throws NotFoundException { Optional<NucleusKitService> optSrv = NucleusAPI.getKitService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues kit service not available"); } NucleusKitService srv = optSrv.get(); return WebAPI.runOnMain(() -> { Optional<Kit> optKit = srv.getKit(name); if (!optKit.isPresent()) { throw new NotFoundException("Kit with name " + name + " not found"); } srv.removeKit(name); return new CachedKit(optKit.get()); }); }
Optional<NucleusKitService> optSrv = NucleusAPI.getKitService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues kit service not available");
Optional<NucleusKitService> optSrv = NucleusAPI.getKitService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues kit service not available");