本文整理汇总了Java中org.spongepowered.api.util.ban.Ban类的典型用法代码示例。如果您正苦于以下问题:Java Ban类的具体用法?Java Ban怎么用?Java Ban使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ban类属于org.spongepowered.api.util.ban包,在下文中一共展示了Ban类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pardonBan
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
@Override
public Optional<SanctionManualProfile.Ban> pardonBan(long date, Text reason, CommandSource source) {
Preconditions.checkNotNull(reason, "reason");
Preconditions.checkNotNull(source, "source");
Optional<EManualProfileBan> manual = this.findFirst(EManualProfileBan.class);
// Aucun manual
if(!manual.isPresent()) {
return Optional.empty();
}
final Optional<EUser> user = this.plugin.getEServer().getOrCreateEUser(this.getUniqueId());
if (!user.isPresent()) {
return Optional.empty();
}
manual.get().pardon(date, reason, source.getIdentifier());
final Ban.Profile ban = manual.get().getBan(user.get().getProfile());
this.plugin.getSanctionService().remove(ban);
this.ban = this.findFirst(SanctionBanProfile.class);
this.plugin.getThreadAsync().execute(() -> this.sqlPardonManual(manual.get()));
return Optional.of(manual.get());
}
示例2: pardonBanIp
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
@Override
public Optional<SanctionManualProfile.BanIp> pardonBanIp(InetAddress address, long date, Text reason, CommandSource source) {
Preconditions.checkNotNull(address, "address");
Preconditions.checkNotNull(reason, "reason");
Preconditions.checkNotNull(source, "source");
Optional<EManualProfileBanIp> optManual = this.findFirst(EManualProfileBanIp.class, sanction -> UtilsNetwork.equals(sanction.getAddress(), address));
if(!optManual.isPresent()) {
return Optional.empty();
}
EManualProfileBanIp manual = optManual.get();
final Optional<EUser> user = this.plugin.getEServer().getOrCreateEUser(this.getUniqueId());
if (!user.isPresent()) {
return Optional.empty();
}
manual.pardon(date, reason, source.getIdentifier());
final Ban.Ip ban = manual.getBan();
this.plugin.getSanctionService().remove(ban);
this.plugin.getThreadAsync().execute(() -> this.sqlPardonManual(manual));
return Optional.of(manual);
}
示例3: getBanFor
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
@Override
public Optional<Ban.Ip> getBanFor(InetAddress address) {
this.removeExpired();
String address_string = UtilsNetwork.getHostString(address);
Optional<Ban.Ip> ban = Optional.empty();
Iterator<Entry<Ban.Ip, String>> iterator = this.bans_ip.entrySet().iterator();
this.plugin.getELogger().warn("size : " + this.bans_ip.size());
while(!ban.isPresent() && iterator.hasNext()) {
Entry<Ban.Ip, String> element = iterator.next();
this.plugin.getELogger().warn(address_string + " : " + element.getValue());
if(element.getValue().equalsIgnoreCase(address_string)) {
ban = Optional.of(element.getKey());
this.plugin.getELogger().warn("true");
}
}
return ban;
}
示例4: remove
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
public void remove(Ban.Profile profile) {
BiPredicate<Ban.Profile, UUID> predicate = (ban, uuid) -> {
if (!ban.getProfile().getUniqueId().equals(profile.getProfile().getUniqueId())) {
return false;
}
if (ban.getCreationDate().toEpochMilli() != profile.getCreationDate().toEpochMilli()) {
return false;
}
if(ban.getExpirationDate().isPresent() || profile.getExpirationDate().isPresent()) {
if (!ban.getExpirationDate().isPresent() || !profile.getExpirationDate().isPresent() ||
ban.getExpirationDate().get().toEpochMilli() != profile.getExpirationDate().get().toEpochMilli()) {
return false;
}
}
if(!ban.getReason().orElse(Text.EMPTY).toPlain().equals(profile.getReason().orElse(Text.EMPTY).toPlain())) {
return false;
}
if(!ban.getBanSource().orElse(Text.EMPTY).toPlain().equals(profile.getBanSource().orElse(Text.EMPTY).toPlain())) {
return false;
}
return true;
};
UtilsMap.removeIf(this.bans_profile, predicate);
}
示例5: 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);
}
示例6: banlistPlayer
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
private void banlistPlayer(CommandSource context, String filter)
{
// TODO filter
Collection<Ban.Profile> userBans = this.banService.getProfileBans();
if (userBans.isEmpty())
{
i18n.send(context, POSITIVE, "There are no players banned on this server!");
return;
}
if (userBans.size() == 1)
{
Ban.Profile next = userBans.iterator().next();
i18n.send(context, POSITIVE, "Only {user}({name#uuid}) is banned on this server",
next.getProfile().getName().orElse("?"), next.getProfile().getUniqueId().toString());
return;
}
i18n.send(context, POSITIVE, "The following {amount} players are banned from this server",
userBans.size());
context.sendMessage(Text.of(StringUtils.implode(GREY + ", ", userBans)));
// TODO implode on Text
}
示例7: 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());
}
示例8: addDefaultAddons
import org.spongepowered.api.util.ban.Ban; //导入依赖的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());
}
}
示例9: getBan
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
public default Ban.Profile getBan(GameProfile profile) {
Builder builder = Ban.builder()
.type(BanTypes.PROFILE)
.profile(profile)
.reason(this.getReason())
.startDate(Instant.ofEpochMilli(this.getCreationDate()))
.source(EChat.of(this.getSource()));
if(this.getExpirationDate().isPresent()) {
builder = builder.expirationDate(Instant.ofEpochMilli(this.getExpirationDate().get()));
}
return (Ban.Profile) builder.build();
}
示例10: BanView
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
public BanView(Ban value) {
super(value);
this.createdOn = value.getCreationDate();
this.expiresOn = value.getExpirationDate().orElse(null);
this.reason = value.getReason().orElse(null);
this.banSource = value.getBanSource().orElse(null);
this.commandSource = value.getBanCommandSource().orElse(null);
}
示例11: banIp
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
@Override
public boolean banIp(InetAddress address, long creation, Optional<Long> expiration, Text reason, final CommandSource source) {
Preconditions.checkNotNull(address, "address");
Preconditions.checkNotNull(expiration, "expiration");
Preconditions.checkNotNull(reason, "reason");
Preconditions.checkNotNull(source, "source");
// Le joueur a déjà une saction
if (this.findFirst(EManualProfileBanIp.class, sanction -> UtilsNetwork.equals(sanction.getAddress(), address)).isPresent()) {
return false;
}
// User inconnu
final Optional<EUser> user = this.plugin.getEServer().getOrCreateEUser(this.getUniqueId());
if (!user.isPresent()) {
return false;
}
// SubjectIP inconnu
final Optional<EIpSubject> subject_ip = this.plugin.getSanctionService().getSubject(address);
if (!subject_ip.isPresent()) {
return false;
}
final EManualProfileBanIp manual = new EManualProfileBanIp(this.getUniqueId(), address, creation, expiration, reason, source.getIdentifier());
final Ban.Ip ban = manual.getBan();
// Event cancel
if (Sponge.getEventManager().post(SpongeEventFactory.createBanIpEvent(Cause.source(this).build(), ban))) {
return false;
}
this.sanctions.add(manual);
subject_ip.get().add(manual);
this.plugin.getSanctionService().add(ban);
this.plugin.getThreadAsync().execute(() -> this.sqlAddManual(manual));
return true;
}
示例12: getBan
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
public Ban.Ip getBan(InetAddress address) {
Builder builder = Ban.builder()
.address(address)
.reason(this.getReason())
.startDate(Instant.ofEpochMilli(this.getCreationDate()))
.type(BanTypes.IP)
.source(EChat.of(this.getSource()));
if(this.getExpirationDate().isPresent()) {
builder = builder.expirationDate(Instant.ofEpochMilli(this.getExpirationDate().get()));
}
return (Ban.Ip) builder.build();
}
示例13: getBans
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
@Override
public Collection<Ban> getBans() {
this.removeExpired();
Builder<Ban> builder = ImmutableSet.builder();
builder.addAll(this.bans_profile.keySet());
builder.addAll(this.bans_ip.keySet());
return builder.build();
}
示例14: getProfileBans
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
@Override
public Collection<Ban.Profile> getProfileBans() {
this.removeExpired();
Builder<Ban.Profile> builder = ImmutableSet.builder();
builder.addAll(this.bans_profile.keySet());
return builder.build();
}
示例15: getIpBans
import org.spongepowered.api.util.ban.Ban; //导入依赖的package包/类
@Override
public Collection<Ban.Ip> getIpBans() {
this.removeExpired();
Builder<Ban.Ip> builder = ImmutableSet.builder();
builder.addAll(this.bans_ip.keySet());
return builder.build();
}