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


Java BanService.addBan方法代码示例

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


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

示例1: handleDeath

import org.spongepowered.api.service.ban.BanService; //导入方法依赖的package包/类
@Override
protected void handleDeath(CauseStack causeStack) {
    // Call the harvest event
    final boolean keepsInventory = getWorld().getOrCreateRule(RuleTypes.KEEP_INVENTORY).getValue();
    final int exp = keepsInventory ? 0 : Math.min(100, get(Keys.EXPERIENCE_LEVEL).orElse(0) * 7);
    // Humanoids get their own sub-interface for the event
    final HarvestEntityEvent.TargetPlayer harvestEvent = SpongeEventFactory.createHarvestEntityEventTargetPlayer(
            causeStack.getCurrentCause(), exp, exp, this, keepsInventory, keepsInventory, 0);
    Sponge.getEventManager().post(harvestEvent);
    if (!harvestEvent.isCancelled()) {
        final List<ItemStackSnapshot> drops = new ArrayList<>();
        if (!harvestEvent.keepsInventory()) {
            getInventory().<AbstractSlot>slots().forEach(slot ->
                    slot.poll().ifPresent(itemStack -> drops.add(LanternItemStackSnapshot.wrap(itemStack))));
        }
        if (!harvestEvent.keepsLevel()) {
            offer(Keys.EXPERIENCE_LEVEL, harvestEvent.getLevel());
        }
        // Finalize the harvest event
        finalizeHarvestEvent(causeStack, harvestEvent, drops);
    }

    // Ban the player if the world is hardcode
    if (getWorld().getProperties().isHardcore()) {
        final BanService banService = Sponge.getServiceManager().provideUnchecked(BanService.class);
        // Add a permanent ban
        banService.addBan(Ban.of(getProfile(), t("gameMode.hardcore.banMessage")));
        // Bye, bye!
        kick(t("deathScreen.title.hardcore"));
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:32,代码来源:LanternPlayer.java

示例2: execute

import org.spongepowered.api.service.ban.BanService; //导入方法依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	User player = ctx.<User> getOne("player").get();
	String time = ctx.<String> getOne("time").get();
	String reason = ctx.<String> getOne("reason").orElse("The BanHammer has spoken!");

	BanService srv = game.getServiceManager().provide(BanService.class).get();

	if (srv.isBanned(player.getProfile()))
	{
		src.sendMessage(Text.of(TextColors.RED, "That player has already been banned."));
		return CommandResult.empty();
	}

	srv.addBan(Ban.builder()
		.type(BanTypes.PROFILE)
		.source(src).profile(player.getProfile())
		.expirationDate(getInstantFromString(time))
		.reason(TextSerializers.formattingCode('&').deserialize(reason))
		.build());

	if (player.isOnline())
	{
		player.getPlayer().get().kick(Text.builder()
			.append(Text.of(TextColors.DARK_RED, "You have been tempbanned!\n", TextColors.RED, "Reason: "))
			.append(TextSerializers.formattingCode('&').deserialize(reason), Text.of("\n"))
			.append(Text.of(TextColors.GOLD, "Time: ", TextColors.GRAY, getFormattedString(time)))
			.build());
	}

	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been banned."));
	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:35,代码来源:TempBanExecutor.java

示例3: execute

import org.spongepowered.api.service.ban.BanService; //导入方法依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	User player = ctx.<User> getOne("player").get();
	String reason = ctx.<String> getOne("reason").orElse("The BanHammer has spoken!");

	BanService srv = game.getServiceManager().provide(BanService.class).get();

	if (srv.isBanned(player.getProfile()))
	{
		src.sendMessage(Text.of(TextColors.RED, "That player has already been banned."));
		return CommandResult.empty();
	}
	
	srv.addBan(Ban.builder().type(BanTypes.PROFILE).source(src).profile(player.getProfile()).reason(TextSerializers.formattingCode('&').deserialize(reason)).build());

	if (player.isOnline())
	{
		player.getPlayer().get().kick(Text.builder()
			.append(Text.of(TextColors.DARK_RED, "You have been banned!\n ", TextColors.RED, "Reason: "))
			.append(TextSerializers.formattingCode('&').deserialize(reason))
			.build());
	}

	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been banned."));
	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:28,代码来源:BanExecutor.java

示例4: execute

import org.spongepowered.api.service.ban.BanService; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    GameProfile profile = args.<GameProfile>getOne("player").orElse(null);
    InetAddress address = args.<InetAddress>getOne("ip").orElse(null);

    Long time = args.<Long>getOne("time").orElse(-1L);
    Text reason = args.<String>getOne("reason").map(Messages::toText).orElse(Messages.getFormatted(src, "ban.command.ban.defaultreason"));

    //Try to find user
    User user = null;
    if (profile != null) {
        user = Sponge.getServiceManager().provide(UserStorageService.class).get().get(profile).get();
    } else {
        //Try to find user from ip address
        for (GameProfile prof : Sponge.getServer().getGameProfileManager().getCache().getProfiles()) {
            PlayerDataFile config = new PlayerDataFile(prof.getUniqueId());
            CommentedConfigurationNode node = config.get();
            if (node.getNode("lastip").getString("").equalsIgnoreCase(address.toString().replace("/", ""))) {
                user = Sponge.getServiceManager().provide(UserStorageService.class).get().get(prof).get();
            }
        }
    }

    //If user is present, check exempt
    if (user != null) {
        if ((BanPermissions.UC_BAN_EXEMPTPOWER.getIntFor(user) > BanPermissions.UC_BAN_POWER.getIntFor(src)) && src instanceof Player) {
            throw new ErrorMessageException(Messages.getFormatted(src, "ban.command.ban.exempt", "%player%", user));
        }
    }

    //Ban user
    BanService bs = Sponge.getServiceManager().provide(BanService.class).get();
    Ban.Builder bb = Ban.builder();
    if (profile != null) {
        bb = bb.type(BanTypes.PROFILE).profile(profile);
    } else {
        bb = bb.type(BanTypes.IP).address(address);
    }
    bb = bb.source(src).startDate(Instant.now());
    if (time > 0) bb = bb.expirationDate(Instant.now().plusMillis(time));
    bb = bb.reason(reason);
    bs.addBan(bb.build());

    //Kick player
    if (user != null && user.getPlayer().isPresent()) {
        if (profile != null) {
            user.getPlayer().get().kick(Messages.getFormatted(user.getPlayer().get(), "ban.banned", "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason));
        } else {
            user.getPlayer().get().kick(Messages.getFormatted(user.getPlayer().get(), "ban.ipbanned", "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason));
        }
    }

    //Send message
    if (profile != null) {
        Messages.send(src, "ban.command.ban.success", "%player%", profile.getName().orElse(""), "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason);
    } else {
        Messages.send(src, "ban.command.ban.success-ip", "%ip%", address.toString().replace("/", ""), "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason);
    }
    return CommandResult.success();
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:61,代码来源:BanCommand.java


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