本文整理汇总了Java中io.github.nucleuspowered.nucleus.api.NucleusAPI类的典型用法代码示例。如果您正苦于以下问题:Java NucleusAPI类的具体用法?Java NucleusAPI怎么用?Java NucleusAPI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NucleusAPI类属于io.github.nucleuspowered.nucleus.api包,在下文中一共展示了NucleusAPI类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJails
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.GET, path = "jail", perm = "jail.list")
public void getJails(IServletData data) {
Optional<NucleusJailService> optSrv = NucleusAPI.getJailService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues jail service not available");
return;
}
NucleusJailService srv = optSrv.get();
Optional<List<CachedNamedLocation>> optRes = WebAPIAPI.runOnMain(
() -> srv.getJails().values().stream().map(CachedNamedLocation::new).collect(Collectors.toList())
);
data.addData("ok", optRes.isPresent(), false);
data.addData("jails", optRes.orElse(null), data.getQueryParam("details").isPresent());
}
示例2: getJail
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.GET, path = "jail/:name", perm = "jail.one")
public void getJail(IServletData data, String name) {
Optional<NucleusJailService> optSrv = NucleusAPI.getJailService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues jail service not available");
return;
}
NucleusJailService srv = optSrv.get();
Optional<CachedNamedLocation> optRes = WebAPIAPI.runOnMain(() -> {
Optional<NamedLocation> optJail = srv.getJail(name);
if (!optJail.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Jail not found");
return null;
}
return new CachedNamedLocation(optJail.get());
});
data.addData("ok", optRes.isPresent(), false);
data.addData("jail", optRes.orElse(null), true);
}
示例3: deleteJail
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.DELETE, path = "jail/:name", perm = "jail.delete")
public void deleteJail(IServletData data, String name) {
Optional<NucleusJailService> optSrv = NucleusAPI.getJailService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues jail service not available");
return;
}
NucleusJailService srv = optSrv.get();
Optional<CachedNamedLocation> optRes = WebAPIAPI.runOnMain(() -> {
Optional<NamedLocation> optJail = srv.getJail(name);
if (!optJail.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Jail not found");
return null;
}
srv.removeJail(name);
return new CachedNamedLocation(optJail.get());
});
data.addData("ok", optRes.isPresent(), false);
data.addData("jail", optRes.orElse(null), true);
}
示例4: getKits
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.GET, path = "kit", perm = "kit.list")
public void getKits(IServletData data) {
Optional<NucleusKitService> optSrv = NucleusAPI.getKitService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues kit service not available");
return;
}
NucleusKitService srv = optSrv.get();
Optional<List<CachedKit>> kits = WebAPIAPI.runOnMain(
() -> srv.getKitNames().stream()
.map(name -> srv.getKit(name).map(CachedKit::new).orElse(null))
.collect(Collectors.toList())
);
data.addData("ok", kits.isPresent(), false);
data.addData("kits", kits.orElse(null), data.getQueryParam("details").isPresent());
}
示例5: getKit
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.GET, path = "kit/:name", perm = "kit.one")
public void getKit(IServletData data, String name) {
Optional<NucleusKitService> optSrv = NucleusAPI.getKitService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues kit service not available");
return;
}
NucleusKitService srv = optSrv.get();
Optional<CachedKit> optRes = WebAPIAPI.runOnMain(() -> {
Optional<Kit> optKit = srv.getKit(name);
if (!optKit.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Kit not found");
return null;
}
return new CachedKit(optKit.get());
});
data.addData("ok", optRes.isPresent(), false);
data.addData("kit", optRes.orElse(null), true);
}
示例6: deleteKit
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.DELETE, path = "kit/:name", perm = "kit.delete")
public void deleteKit(IServletData data, String name) {
Optional<NucleusKitService> optSrv = NucleusAPI.getKitService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues kit service not available");
return;
}
NucleusKitService srv = optSrv.get();
Optional<CachedKit> optRes = WebAPIAPI.runOnMain(() -> {
Optional<Kit> optKit = srv.getKit(name);
if (!optKit.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Kit not found");
return null;
}
srv.removeKit(name);
return new CachedKit(optKit.get());
});
data.addData("ok", optRes.isPresent(), false);
data.addData("kit", optRes.orElse(null), true);
}
示例7: createJail
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.POST, path = "jail", perm = "jail.create")
public void createJail(IServletData data) {
Optional<NucleusJailService> optSrv = NucleusAPI.getJailService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues jail service not available");
return;
}
NucleusJailService srv = optSrv.get();
Optional<CreateJailRequest> optReq = data.getRequestBody(CreateJailRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid jail data: " + data.getLastParseError().getMessage());
return;
}
CreateJailRequest req = optReq.get();
if (!req.getWorld().isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid world provided");
return;
}
ICachedWorld world = req.getWorld().get();
if (req.getPosition() == null) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid position provided");
return;
}
Optional<CachedNamedLocation> optRes = WebAPIAPI.runOnMain(() -> {
Optional<World> optWorld = world.getLive();
if (!optWorld.isPresent())
return null;
World w = optWorld.get();
srv.setJail(req.getName(), new Location<>(w, req.getPosition()), req.getRotation());
Optional<NamedLocation> optJail = srv.getJail(req.getName());
return optJail.map(CachedNamedLocation::new).orElse(null);
});
data.setStatus(HttpServletResponse.SC_CREATED);
data.addData("ok", optRes.isPresent(), false);
data.addData("jail", optRes.orElse(null), true);
}
示例8: createKit
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.POST, path = "kit", perm = "kit.create")
public void createKit(IServletData data) {
Optional<NucleusKitService> optSrv = NucleusAPI.getKitService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues kit service not available");
return;
}
NucleusKitService srv = optSrv.get();
Optional<CreateKitRequest> optReq = data.getRequestBody(CreateKitRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid kit data: " + data.getLastParseError().getMessage());
return;
}
CreateKitRequest req = optReq.get();
if (req.getName().isEmpty()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid kit name");
return;
}
Optional<CachedKit> resKit = WebAPIAPI.runOnMain(() -> {
Kit kit = srv.createKit(req.getName());
kit.setCost(req.getCost());
kit.setCooldown(req.getCooldown());
if (req.hasStacks()) {
try {
kit.setStacks(req.getStacks().stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));
} catch (Exception e) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not process item stack: " + e.getMessage());
return null;
}
}
if (req.hasCommands()) {
kit.setCommands(req.getCommands());
}
srv.saveKit(kit);
return new CachedKit(kit);
});
data.addData("ok", resKit.isPresent(), false);
data.addData("kit", resKit.orElse(null), true);
}
示例9: changeKit
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
@Endpoint(method = HttpMethod.PUT, path = "kit/:name", perm = "kit.change")
public void changeKit(IServletData data, String name) {
Optional<NucleusKitService> optSrv = NucleusAPI.getKitService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues kit service not available");
return;
}
NucleusKitService srv = optSrv.get();
Optional<BaseKitRequest> optReq = data.getRequestBody(BaseKitRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid kit data: " + data.getLastParseError().getMessage());
return;
}
BaseKitRequest req = optReq.get();
Optional<CachedKit> optRes = WebAPIAPI.runOnMain(() -> {
Optional<Kit> optKit = srv.getKit(name);
if (!optKit.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Kit not found");
return null;
}
Kit kit = optKit.get();
if (req.hasCost()) {
kit.setCost(req.getCost());
}
if (req.hasCooldown()) {
kit.setCooldown(req.getCooldown());
}
if (req.hasCommands()) {
kit.setCommands(req.getCommands());
}
if (req.hasStacks()) {
try {
kit.setStacks(req.getStacks().stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));
} catch (Exception e) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not process item stack: " + e.getMessage());
return null;
}
}
srv.saveKit(kit);
return new CachedKit(kit);
});
data.addData("ok", optRes.isPresent(), false);
data.addData("kit", optRes.orElse(null), true);
}
示例10: getPrivateMessagingService
import io.github.nucleuspowered.nucleus.api.NucleusAPI; //导入依赖的package包/类
public static Optional<NucleusPrivateMessagingService> getPrivateMessagingService() {
return NucleusAPI.getPrivateMessagingService();
}