IpBanList.java

net.minecraft.server.players.IpBanList

信息

  • 全限定名:net.minecraft.server.players.IpBanList
  • 类型:public class
  • 包:net.minecraft.server.players
  • 源码路径:src/main/java/net/minecraft/server/players/IpBanList.java
  • 起始行号:L9
  • 继承:StoredUserList<String,IpBanListEntry>
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

public IpBanList(File file, NotificationService notificationService) @ L10

  • 构造器名:IpBanList
  • 源码定位:L10
  • 修饰符:public

参数:

  • file: File
  • notificationService: NotificationService

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected StoredUserEntry<String> createEntry(JsonObject object) @ L14

  • 方法名:createEntry
  • 源码定位:L14
  • 返回类型:StoredUserEntry
  • 修饰符:protected

参数:

  • object: JsonObject

说明:

TODO

public boolean isBanned(SocketAddress address) @ L19

  • 方法名:isBanned
  • 源码定位:L19
  • 返回类型:boolean
  • 修饰符:public

参数:

  • address: SocketAddress

说明:

TODO

public boolean isBanned(String ip) @ L24

  • 方法名:isBanned
  • 源码定位:L24
  • 返回类型:boolean
  • 修饰符:public

参数:

  • ip: String

说明:

TODO

public IpBanListEntry get(SocketAddress address) @ L28

  • 方法名:get
  • 源码定位:L28
  • 返回类型:IpBanListEntry
  • 修饰符:public

参数:

  • address: SocketAddress

说明:

TODO

private String getIpFromAddress(SocketAddress address) @ L33

  • 方法名:getIpFromAddress
  • 源码定位:L33
  • 返回类型:String
  • 修饰符:private

参数:

  • address: SocketAddress

说明:

TODO

public boolean add(IpBanListEntry infos) @ L46

  • 方法名:add
  • 源码定位:L46
  • 返回类型:boolean
  • 修饰符:public

参数:

  • infos: IpBanListEntry

说明:

TODO

public boolean remove(String ip) @ L58

  • 方法名:remove
  • 源码定位:L58
  • 返回类型:boolean
  • 修饰符:public

参数:

  • ip: String

说明:

TODO

public void clear() @ L67

  • 方法名:clear
  • 源码定位:L67
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

public class IpBanList extends StoredUserList<String, IpBanListEntry> {
    public IpBanList(File file, NotificationService notificationService) {
        super(file, notificationService);
    }
 
    @Override
    protected StoredUserEntry<String> createEntry(JsonObject object) {
        return new IpBanListEntry(object);
    }
 
    public boolean isBanned(SocketAddress address) {
        String ip = this.getIpFromAddress(address);
        return this.contains(ip);
    }
 
    public boolean isBanned(String ip) {
        return this.contains(ip);
    }
 
    public @Nullable IpBanListEntry get(SocketAddress address) {
        String ip = this.getIpFromAddress(address);
        return this.get(ip);
    }
 
    private String getIpFromAddress(SocketAddress address) {
        String ip = address.toString();
        if (ip.contains("/")) {
            ip = ip.substring(ip.indexOf(47) + 1);
        }
 
        if (ip.contains(":")) {
            ip = ip.substring(0, ip.indexOf(58));
        }
 
        return ip;
    }
 
    public boolean add(IpBanListEntry infos) {
        if (super.add(infos)) {
            if (infos.getUser() != null) {
                this.notificationService.ipBanned(infos);
            }
 
            return true;
        } else {
            return false;
        }
    }
 
    public boolean remove(String ip) {
        if (super.remove(ip)) {
            this.notificationService.ipUnbanned(ip);
            return true;
        } else {
            return false;
        }
    }
 
    @Override
    public void clear() {
        for (IpBanListEntry user : this.getEntries()) {
            if (user.getUser() != null) {
                this.notificationService.ipUnbanned(user.getUser());
            }
        }
 
        super.clear();
    }
}

引用的其他类