本文整理汇总了Java中org.spongepowered.api.util.ban.Ban.Ip方法的典型用法代码示例。如果您正苦于以下问题:Java Ban.Ip方法的具体用法?Java Ban.Ip怎么用?Java Ban.Ip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.util.ban.Ban
的用法示例。
在下文中一共展示了Ban.Ip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: remove
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
public void remove(Ban.Ip profile) {
BiPredicate<Ban.Ip, String> predicate = (ban, address) -> {
if(!ban.getAddress().equals(profile.getAddress())) {
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_ip, predicate);
}
示例4: getBan
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
public default Ban.Ip getBan(GameProfile profile, InetAddress address) {
Builder builder = Ban.builder()
.type(BanTypes.IP)
.address(address)
.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.Ip) builder.build();
}
示例5: 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;
}
示例6: 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();
}
示例7: 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();
}
示例8: removeBan
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
@Override
public boolean removeBan(Ban ban) {
checkNotNull(ban, "ban");
if (this.entries0.remove(ban)) {
final CauseStack causeStack = CauseStack.currentOrEmpty();
// Post the pardon events
final Event event;
final Cause cause = causeStack.getCurrentCause();
if (ban instanceof Ban.Ip) {
event = SpongeEventFactory.createPardonIpEvent(cause, (Ban.Ip) ban);
} else {
final Ban.Profile profileBan = (Ban.Profile) ban;
// Check if the pardoned player is online (not yet been kicked)
final Optional<Player> optTarget = Sponge.getServer().getPlayer(profileBan.getProfile().getUniqueId());
if (optTarget.isPresent()) {
event = SpongeEventFactory.createPardonUserEventTargetPlayer(cause, profileBan, optTarget.get(), optTarget.get());
} else {
event = SpongeEventFactory.createPardonUserEvent(cause, profileBan, Lantern.getGame().getServiceManager()
.provideUnchecked(UserStorageService.class).getOrCreate(profileBan.getProfile()));
}
}
// Just ignore for now the fact that they may be cancellable,
// only the PardonIpEvent seems to be cancellable
// TODO: Should they all be cancellable or none of them?
Sponge.getEventManager().post(event);
return true;
}
return false;
}
示例9: addBan
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
@Override
public Optional<? extends Ban> addBan(Ban ban) {
checkNotNull(ban, "ban");
final Optional<Ban> oldBan;
if (ban instanceof Ban.Ip) {
oldBan = (Optional) getBanFor(((Ban.Ip) ban).getAddress());
} else {
oldBan = (Optional) getBanFor(((Ban.Profile) ban).getProfile());
}
oldBan.ifPresent(this.entries0::remove);
this.entries0.add((BanEntry) ban);
if (!oldBan.isPresent() || !oldBan.get().equals(ban)) {
final CauseStack causeStack = CauseStack.currentOrEmpty();
// Post the ban events
final Event event;
final Cause cause = causeStack.getCurrentCause();
if (ban instanceof Ban.Ip) {
event = SpongeEventFactory.createBanIpEvent(cause, (Ban.Ip) ban);
} else {
final Ban.Profile profileBan = (Ban.Profile) ban;
// Check if the pardoned player is online (not yet been kicked)
final Optional<Player> optTarget = Sponge.getServer().getPlayer(profileBan.getProfile().getUniqueId());
if (optTarget.isPresent()) {
event = SpongeEventFactory.createBanUserEventTargetPlayer(cause, profileBan, optTarget.get(), optTarget.get());
} else {
event = SpongeEventFactory.createBanUserEvent(cause, profileBan, Lantern.getGame().getServiceManager()
.provideUnchecked(UserStorageService.class).getOrCreate(profileBan.getProfile()));
}
}
// Just ignore for now the fact that they may be cancellable,
// only the PardonIpEvent seems to be cancellable
// TODO: Should they all be cancellable or none of them?
Sponge.getEventManager().post(event);
}
return oldBan;
}
示例10: unbanIP
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
/**
* Unbans an IP address from the server.
*
* @param ip The {@link InetAddress} to unban
*/
@Override
public void unbanIP(InetAddress ip) {
Optional<Ban.Ip> ban = HammerSponge.getBanService().get().getBanFor(ip);
if (ban.isPresent()) {
HammerSponge.getBanService().get().pardon(ip);
}
}
示例11: getBanFor
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
@Override
protected Optional<Ban.Ip> getBanFor(String target) {
try {
return getBanService().getBanFor(InetAddress.getByName(target));
} catch (UnknownHostException e) {
return Optional.empty();
}
}
示例12: getBansIp
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
public Map<Ban.Ip, String> getBansIp(Connection connection) {
Map<Ban.Ip, String> bans = new HashMap<Ban.Ip, String>();
bans.putAll(this.getBanIpProfile(connection));
bans.putAll(this.getBanIp(connection));
return bans;
}
示例13: EBanService
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
public EBanService(final EverSanctions plugin) {
super(plugin);
this.bans_profile = new ConcurrentSkipListMap<Ban.Profile, UUID>(EBanService.COMPARATOR_BAN);
this.bans_ip = new ConcurrentSkipListMap<Ban.Ip, String>(EBanService.COMPARATOR_BAN);
}
示例14: add
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
public void add(Ban.Ip ban) {
this.bans_ip.put(ban, UtilsNetwork.getHostString(ban.getAddress()));
}
示例15: getIpBans
import org.spongepowered.api.util.ban.Ban; //导入方法依赖的package包/类
@Override
public Collection<Ban.Ip> getIpBans() {
return (Collection) this.entries0.stream().filter(e -> e instanceof Ban.Ip).collect(ImmutableList.toImmutableList());
}