本文整理汇总了Java中org.spongepowered.api.util.ban.Ban.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Ban.Builder方法的具体用法?Java Ban.Builder怎么用?Java Ban.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.util.ban.Ban
的用法示例。
在下文中一共展示了Ban.Builder方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ban
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
/**
* Bans the player with the specified reason
*
* @param reason The reason
*/
@Override
public void ban(WrappedCommandSource source, HammerText reason) {
Ban.Builder builder = Ban.builder().type(BanTypes.PROFILE)
.reason(HammerTextConverter.constructLiteral(reason)).profile(player.getProfile());
if (source instanceof SpongeWrappedPlayer) {
Optional<Player> sourceplayer = ((SpongeWrappedPlayer) source).getSpongePlayer();
if (sourceplayer.isPresent()) {
builder.source(sourceplayer.get());
}
} else if (source instanceof SpongeWrappedConsole) {
builder.source(((SpongeWrappedConsole) source).getSpongeSource());
}
HammerSponge.getBanService().get().addBan(builder.build());
kick(reason);
}
示例2: save
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
@Override
public void save() {
Ban.Builder builder = Ban.builder();
if (!banList.setTarget(builder, target)) {
return;
}
if (reason != null) {
builder.reason(PoreText.convert(reason));
}
if (expiration != null) {
builder.expirationDate(expiration.toInstant());
}
if (source != null) {
builder.source(PoreText.convert(source));
}
PoreBanList.getBanService().addBan(builder.build());
}
示例3: setTarget
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
@Override
protected boolean setTarget(Ban.Builder builder, String target) {
Optional<GameProfile> profile = getGameProfile(target);
if (!profile.isPresent()) {
return false;
}
builder.profile(profile.get());
return true;
}
示例4: setTarget
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
@Override
protected boolean setTarget(Ban.Builder builder, String target) {
try {
builder.address(InetAddress.getByName(target));
return true;
} catch (UnknownHostException e) {
return false;
}
}
示例5: execute
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的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();
}
示例6: setTarget
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
protected abstract boolean setTarget(Ban.Builder builder, String target);