UserBanList.java

net.minecraft.server.players.UserBanList

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public UserBanList(File file, NotificationService notificationService) @ L9

  • 构造器名:UserBanList
  • 源码定位:L9
  • 修饰符:public

参数:

  • file: File
  • notificationService: NotificationService

说明:

TODO

方法

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

protected StoredUserEntry<NameAndId> createEntry(JsonObject object) @ L13

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

参数:

  • object: JsonObject

说明:

TODO

public boolean isBanned(NameAndId user) @ L18

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

参数:

  • user: NameAndId

说明:

TODO

public String[] getUserList() @ L22

  • 方法名:getUserList
  • 源码定位:L22
  • 返回类型:String[]
  • 修饰符:public

参数:

说明:

TODO

protected String getKeyForUser(NameAndId user) @ L27

  • 方法名:getKeyForUser
  • 源码定位:L27
  • 返回类型:String
  • 修饰符:protected

参数:

  • user: NameAndId

说明:

TODO

public boolean add(UserBanListEntry infos) @ L31

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

参数:

  • infos: UserBanListEntry

说明:

TODO

public boolean remove(NameAndId user) @ L43

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

参数:

  • user: NameAndId

说明:

TODO

public void clear() @ L52

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

参数:

说明:

TODO

代码

public class UserBanList extends StoredUserList<NameAndId, UserBanListEntry> {
    public UserBanList(File file, NotificationService notificationService) {
        super(file, notificationService);
    }
 
    @Override
    protected StoredUserEntry<NameAndId> createEntry(JsonObject object) {
        return new UserBanListEntry(object);
    }
 
    public boolean isBanned(NameAndId user) {
        return this.contains(user);
    }
 
    @Override
    public String[] getUserList() {
        return this.getEntries().stream().map(StoredUserEntry::getUser).filter(Objects::nonNull).map(NameAndId::name).toArray(String[]::new);
    }
 
    protected String getKeyForUser(NameAndId user) {
        return user.id().toString();
    }
 
    public boolean add(UserBanListEntry infos) {
        if (super.add(infos)) {
            if (infos.getUser() != null) {
                this.notificationService.playerBanned(infos);
            }
 
            return true;
        } else {
            return false;
        }
    }
 
    public boolean remove(NameAndId user) {
        if (super.remove(user)) {
            this.notificationService.playerUnbanned(user);
            return true;
        } else {
            return false;
        }
    }
 
    @Override
    public void clear() {
        for (UserBanListEntry user : this.getEntries()) {
            if (user.getUser() != null) {
                this.notificationService.playerUnbanned(user.getUser());
            }
        }
 
        super.clear();
    }
}

引用的其他类