当前位置: 首页>>代码示例>>Java>>正文


Java NucleusAPI.getKitService方法代码示例

本文整理汇总了Java中io.github.nucleuspowered.nucleus.api.NucleusAPI.getKitService方法的典型用法代码示例。如果您正苦于以下问题:Java NucleusAPI.getKitService方法的具体用法?Java NucleusAPI.getKitService怎么用?Java NucleusAPI.getKitService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.github.nucleuspowered.nucleus.api.NucleusAPI的用法示例。


在下文中一共展示了NucleusAPI.getKitService方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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());
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:20,代码来源:NucleusServlet.java

示例2: 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);
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:24,代码来源:NucleusServlet.java

示例3: 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);
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:25,代码来源:NucleusServlet.java

示例4: 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);
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:46,代码来源:NucleusServlet.java

示例5: 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);
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:53,代码来源:NucleusServlet.java


注:本文中的io.github.nucleuspowered.nucleus.api.NucleusAPI.getKitService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。