/** * Gets the {@link NucleusHomeService}, if it exists. * * <p> * Requires the "home" module. * </p> * * @return The {@link NucleusHomeService} */ public static Optional<NucleusHomeService> getHomeService() { return getService(NucleusHomeService.class); }
/** * 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); }
@GET @Path("/jail") @Permission({ "jail", "list" }) @ApiOperation(value = "List jails", notes = "Get a list of all the jails on the server.") public Collection<CachedNamedLocation> listJails() { Optional<NucleusJailService> optSrv = NucleusAPI.getJailService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues jail service not available"); } NucleusJailService srv = optSrv.get(); return WebAPI.runOnMain( () -> srv.getJails().values().stream() .map(CachedNamedLocation::new) .collect(Collectors.toList()) ); }
if (!NucleusAPI.getStaffChatService().isPresent()) { MagiBridge.getLogger().error("The staff chat module is disabled in the Nucleus config! Please enable it!"); MessageChannel staffChannel = NucleusAPI.getStaffChatService().get().getStaffChat();
@GET @Path("/module") @Permission({ "module", "list" }) @ApiOperation(value = "List modules", notes = "Get a list of loaded Nucleus modules.") public Collection<String> listMail() { NucleusModuleService srv = NucleusAPI.getModuleService(); return WebAPI.runOnMain(srv::getModulesToLoad); } }
/** * Attempts to set the NucleusTextTemplate message using a string. * * <p>See {@link NucleusMessageTokenService#createFromString(String)} for * creating the tokens. Also see {@link #setMessage(NucleusTextTemplate)}.</p> * * @param message The message to send. */ default void setMessage(String message) { try { setMessage(NucleusAPI.getMessageTokenService().createFromString(message)); } catch (NucleusException e) { throw new IllegalArgumentException("Could not create the NucleusTextTemplate", e); } }
public static String getNick(Player p) { if (!Sponge.getPluginManager().getPlugin("nucleus").isPresent()) return p.getName(); return NucleusAPI.getNicknameService() .map(s -> s.getNickname(p).map(Text::toPlain).orElse(null)) .orElse(p.getName()); }
@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()) ); }
@GET @Path("/mail/{player}") @Permission({ "mail", "list" }) @ApiOperation(value = "List mail", notes = "Get a list of all mail messages of a player.") public Collection<CachedMailMessage> listMail( @PathParam("player") @ApiParam("The uuid of the player") CachedPlayer player) throws NotFoundException { Optional<NucleusMailService> optSrv = NucleusAPI.getMailService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues mail service not available"); } NucleusMailService srv = optSrv.get(); Optional<User> optUser = player.getUser(); if (!optUser.isPresent()) { throw new InternalServerErrorException("Could not get user"); } return WebAPI.runOnMain( () -> srv.getMail(optUser.get(), mailMessage -> { return true; }).stream() .map(CachedMailMessage::new) .collect(Collectors.toList()) ); }
/** * 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); }
@GET @Path("/jail/{name}") @Permission({ "jail", "one" }) @ApiOperation(value = "Get a jail", notes = "Get detailed information about a jail.") public CachedNamedLocation getJail(@PathParam("name") String name) throws NotFoundException { Optional<NucleusJailService> optSrv = NucleusAPI.getJailService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues jail service not available"); } NucleusJailService srv = optSrv.get(); return WebAPI.runOnMain(() -> { Optional<NamedLocation> optJail = srv.getJail(name); if (!optJail.isPresent()) { throw new NotFoundException("Jail with name " + name + " not found"); } return new CachedNamedLocation(optJail.get()); }); }
messageChannel = NucleusAPI.getStaffChatService().get().getStaffChat(); format = FormatType.DISCORD_TO_SERVER_STAFF_FORMAT;
/** * 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); }
/** * Gets the {@link NucleusNicknameService}, if it exists. * * <p> * Requires the "nickname" module. * </p> * * @return The {@link NucleusNicknameService} */ public static Optional<NucleusNicknameService> getNicknameService() { return getService(NucleusNicknameService.class); }
@DELETE @Path("/jail/{name}") @Permission({ "jail", "delete" }) @ApiOperation(value = "Delete a jail", notes = "Delete an existing jail.") public CachedNamedLocation deleteJail(@PathParam("name") String name) throws NotFoundException { Optional<NucleusJailService> optSrv = NucleusAPI.getJailService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues jail service not available"); } NucleusJailService srv = optSrv.get(); return WebAPI.runOnMain(() -> { Optional<NamedLocation> optJail = srv.getJail(name); if (!optJail.isPresent()) { throw new NotFoundException("Jail with name " + name + " not found"); } srv.removeJail(name); return new CachedNamedLocation(optJail.get()); }); }
@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()) ); }
/** * Gets the {@link NucleusInvulnerabilityService}, if it exists. * * <p> * Requires the "misc" module. * </p> * * @return The {@link NucleusInvulnerabilityService} */ public static Optional<NucleusInvulnerabilityService> getInvulnerabilityService() { return getService(NucleusInvulnerabilityService.class); }
Optional<NucleusJailService> optSrv = NucleusAPI.getJailService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues jail service not available");
@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()); }); }
/** * Gets the {@link NucleusNoteService}, if it exists. * * <p> * Requires the "note" module. * </p> * * @return The {@link NucleusNoteService} */ public static Optional<NucleusNoteService> getNoteService() { return getService(NucleusNoteService.class); }