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


Java BanService类代码示例

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


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

示例1: execute

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    AbstractTagObject target = entry.getArgumentObject(queue, 0);
    if (target instanceof PlayerTag) {
        GameProfile profile = ((PlayerTag) target).getInternal().getProfile();
        if (queue.shouldShowGood()) {
            queue.outGood("Pardoning player " + ColorSet.emphasis + profile.getName().get() + ColorSet.good + "!");
        }
        Sponge.getServiceManager().provide(BanService.class).get().pardon(profile);
    }
    else {
        try {
            InetAddress address = InetAddress.getByName(target.toString());
            if (queue.shouldShowGood()) {
                queue.outGood("Pardoning IP " + ColorSet.emphasis + address.getHostName() + ColorSet.good + "!");
            }
            Sponge.getServiceManager().provide(BanService.class).get().pardon(address);
        }
        catch (UnknownHostException e) {
            queue.handleError(entry, "Invalid IP address provided!");
        }
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:24,代码来源:PardonCommand.java

示例2: completeSpec

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder
            .arguments(
                    GenericArguments.string(Text.of("player"))
            )
            .executor((src, args) -> {
                final String target = args.<String>getOne("player").get();

                Lantern.getGame().getGameProfileManager().get(target).whenComplete(((gameProfile, throwable) -> {
                    if (throwable == null) {
                        final BanService banService = Sponge.getServiceManager().provideUnchecked(BanService.class);
                        banService.pardon(gameProfile);
                        src.sendMessage(t("commands.unban.success", target));
                    } else {
                        src.sendMessage(t("commands.unban.failed", target));
                        Lantern.getLogger().warn("Failed to unban the player: {}", target, throwable);
                    }
                }));
                return CommandResult.success();
            });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:CommandPardon.java

示例3: completeSpec

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder
            .arguments(
                    GenericArguments.string(Text.of("address"))
            )
            .executor((src, args) -> {
                final String target = args.<String>getOne("address").get();
                InetAddress address;
                if (CommandBanIp.IP_PATTERN.matcher(target).matches()) {
                    try {
                        address = InetAddress.getByName(target);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Unable to parse a valid InetAddress: " + target, e);
                    }
                } else {
                    throw new CommandException(t("commands.unbanip.invalid"));
                }
                final BanService banService = Sponge.getServiceManager().provideUnchecked(BanService.class);
                banService.pardon(address);
                src.sendMessage(t("commands.banip.success", address.toString()));
                return CommandResult.success();
            });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:CommandPardonIp.java

示例4: 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();

	BanService srv = game.getServiceManager().provide(BanService.class).get();
	if (!srv.isBanned(player.getProfile()))
	{
		src.sendMessage(Text.of(TextColors.RED, "That player is not currently banned."));
		return CommandResult.empty();
	}

	srv.removeBan(srv.getBanFor(player.getProfile()).get());
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been unbanned."));
	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:17,代码来源:PardonExecutor.java

示例5: 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);

    //Unban user + Send message
    BanService bs = Sponge.getServiceManager().provide(BanService.class).get();
    if (profile != null && bs.getBanFor(profile).isPresent()) {
        bs.removeBan(bs.getBanFor(profile).get());
        Messages.send(src, "ban.command.unban.success", "%player%", profile.getName().orElse(""));
        return CommandResult.success();
    }
    if (address != null && bs.getBanFor(address).isPresent()) {
        bs.removeBan(bs.getBanFor(address).get());
        Messages.send(src, "ban.command.unban.success-ip", "%ip%", address.toString().replace("/", ""));
        return CommandResult.success();
    }

    //Not banned
    throw Messages.error(src, "ban.command.unban.notbanned");
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:22,代码来源:UnbanCommand.java

示例6: addDefaultAddons

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
private void addDefaultAddons(Player player) {
    TextFormat link = TextFormat.of(TextColors.BLUE, TextStyles.UNDERLINE);
    if (player.hasPermission(PERM_KICK)) {
        addAddon(listPlayer -> Text.builder("Kick").format(link).onClick(Utils.execClick(view -> listPlayer.kick())).build());
    }
    if (player.hasPermission(PERM_BAN)) {
        addAddon(listPlayer -> Text.builder("Ban").format(link)
                .onClick(Utils.execClick(view -> Sponge.getServiceManager().provideUnchecked(BanService.class).addBan(Ban.of(listPlayer.getProfile()))))
                .build());
    }
}
 
开发者ID:simon816,项目名称:ChatUI,代码行数:12,代码来源:PlayerList.java

示例7: onEnable

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
@Override
protected void onEnable() throws PluginDisableException {
	this.ban_service = new EBanService(this);
	this.jail_service = new EJailService(this);
	
	this.getGame().getServiceManager().setProvider(this, BanService.class, this.ban_service);
	this.getGame().getServiceManager().setProvider(this, SanctionService.class, this.ban_service);
	this.getGame().getServiceManager().setProvider(this, JailService.class, this.jail_service);
}
 
开发者ID:EverCraft,项目名称:EverSanctions,代码行数:10,代码来源:EverSanctions.java

示例8: 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

示例9: getFromBanService

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
/**
 * Attempts to get a {@link User} from the {@link BanService}.
 *
 * @param uniqueId The unique id
 * @return The user
 */
@Nullable
private ProxyUser getFromBanService(UUID uniqueId) {
    final LanternGameProfile gameProfile;
    final BanService banService = this.banService.get();
    if (banService instanceof BanConfig) {
        gameProfile = ((BanConfig) banService).getEntryByUUID(uniqueId)
                .map(entry -> ((BanEntry.Profile) entry).getProfile()).orElse(null);
    } else {
        gameProfile = banService.getBanFor(new LanternGameProfile(uniqueId, null))
                .map(entry -> ((BanEntry.Profile) entry).getProfile()).orElse(null);
    }
    return gameProfile == null ? null : new ProxyUser(gameProfile);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:LanternUserStorageService.java

示例10: delete

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
@Override
public boolean delete(GameProfile profile) {
    // Ops Config
    this.opsConfig.removeEntry(profile.getUniqueId());
    // Whitelist Service
    this.whitelistService.get().removeProfile(profile);
    // Ban Service
    final BanService banService = this.banService.get();
    banService.getBanFor(profile).ifPresent(banService::removeBan);
    return true;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:12,代码来源:LanternUserStorageService.java

示例11: completeSpec

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder
            .arguments(
                    GenericArguments.string(Text.of("player")),
                    GenericArguments.optional(GenericArguments2.remainingString(Text.of("reason")))
            )
            .executor((src, args) -> {
                final String target = args.<String>getOne("player").get();
                final String reason = args.<String>getOne("reason").orElse(null);

                Lantern.getGame().getGameProfileManager().get(target).whenComplete(((gameProfile, throwable) -> {
                    if (throwable == null) {
                        final BanService banService = Sponge.getServiceManager().provideUnchecked(BanService.class);
                        final Ban ban = Ban.builder()
                                .type(BanTypes.PROFILE)
                                .profile(gameProfile)
                                .reason(reason == null ? null : Text.of(reason))
                                .source(src)
                                .build();
                        banService.addBan(ban);
                        Lantern.getServer().getPlayer(gameProfile.getUniqueId()).ifPresent(
                                player -> player.kick(t("multiplayer.disconnect.banned")));
                        src.sendMessage(t("commands.ban.success", target));
                    } else {
                        src.sendMessage(t("commands.ban.failed", target));
                        Lantern.getLogger().warn("Failed to ban the player: {}", target, throwable);
                    }
                }));
                return CommandResult.success();
            });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:33,代码来源:CommandBan.java

示例12: 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

示例13: 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

示例14: unban

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
/**
 * Unbans the player
 */
@Override
public void unban() {
    BanService service = HammerSponge.getBanService().get();
    Optional<Ban.Profile> obp = service.getBanFor(player.getProfile());
    if (obp.isPresent()) {
        service.removeBan(obp.get());
    }
}
 
开发者ID:dualspiral,项目名称:Hammer,代码行数:12,代码来源:SpongeWrappedPlayer.java

示例15: onMotd

import org.spongepowered.api.service.ban.BanService; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void onMotd(ClientPingServerEvent event) {
    try {
        ModuleConfig config = Modules.BAN.get().getConfig().get();
        if (!config.get().getNode("ban-motd", "enabled").getBoolean()) return;

        String ip = event.getClient().getAddress().getAddress().toString().replace("/", "");
        GlobalDataFile file = new GlobalDataFile("ipcache");
        if (file.get().getChildrenMap().keySet().contains(ip)) {
            //Player
            GameProfile profile = Sponge.getServer().getGameProfileManager().get(UUID.fromString(file.get().getNode(ip, "uuid").getString())).get();
            InetAddress address = InetAddress.getByName(ip);

            //Check if banned
            BanService bs = Sponge.getServiceManager().provide(BanService.class).get();
            UserStorageService us = Sponge.getServiceManager().provide(UserStorageService.class).get();
            if (bs.isBanned(profile) || bs.isBanned(address)) {
                Text motd = VariableUtil.replaceVariables(Messages.toText(config.get().getNode("ban-motd", "text").getString()), us.get(profile.getUniqueId()).orElse(null));

                //Replace ban vars
                Ban ban = bs.isBanned(profile) ? bs.getBanFor(profile).get() : bs.getBanFor(address).get();
                Long time = ban.getExpirationDate().map(date -> (date.toEpochMilli() - System.currentTimeMillis())).orElse(-1L);
                motd = TextUtil.replace(motd, "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : Text.of(TimeUtil.format(time))));
                motd = TextUtil.replace(motd, "%reason%", ban.getReason().orElse(Messages.getFormatted("ban.command.ban.defaultreason")));

                event.getResponse().setDescription(motd);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:33,代码来源:BanListener.java


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