ServerWaypointManager.java

net.minecraft.server.waypoints.ServerWaypointManager

信息

  • 全限定名:net.minecraft.server.waypoints.ServerWaypointManager
  • 类型:public class
  • 包:net.minecraft.server.waypoints
  • 源码路径:src/main/java/net/minecraft/server/waypoints/ServerWaypointManager.java
  • 起始行号:L18
  • 实现:WaypointManager
  • 职责:

    TODO

字段/常量

  • waypoints

    • 类型: Set<WaypointTransmitter>
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

  • players

    • 类型: Set<ServerPlayer>
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

  • connections

    • 类型: Table<ServerPlayer,WaypointTransmitter,WaypointTransmitter.Connection>
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public void trackWaypoint(WaypointTransmitter waypoint) @ L23

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

参数:

  • waypoint: WaypointTransmitter

说明:

TODO

public void updateWaypoint(WaypointTransmitter waypoint) @ L31

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

参数:

  • waypoint: WaypointTransmitter

说明:

TODO

public void untrackWaypoint(WaypointTransmitter waypoint) @ L46

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

参数:

  • waypoint: WaypointTransmitter

说明:

TODO

public void addPlayer(ServerPlayer player) @ L52

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

参数:

  • player: ServerPlayer

说明:

TODO

public void updatePlayer(ServerPlayer player) @ L64

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

参数:

  • player: ServerPlayer

说明:

TODO

public void removePlayer(ServerPlayer player) @ L77

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

参数:

  • player: ServerPlayer

说明:

TODO

public void breakAllConnections() @ L86

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

参数:

说明:

TODO

public void remakeConnections(WaypointTransmitter waypoint) @ L91

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

参数:

  • waypoint: WaypointTransmitter

说明:

TODO

public Set<WaypointTransmitter> transmitters() @ L97

  • 方法名:transmitters
  • 源码定位:L97
  • 返回类型:Set
  • 修饰符:public

参数:

说明:

TODO

private static boolean isLocatorBarEnabledFor(ServerPlayer player) @ L101

  • 方法名:isLocatorBarEnabledFor
  • 源码定位:L101
  • 返回类型:boolean
  • 修饰符:private static

参数:

  • player: ServerPlayer

说明:

TODO

private void createConnection(ServerPlayer player, WaypointTransmitter waypoint) @ L105

  • 方法名:createConnection
  • 源码定位:L105
  • 返回类型:void
  • 修饰符:private

参数:

  • player: ServerPlayer
  • waypoint: WaypointTransmitter

说明:

TODO

private void updateConnection(ServerPlayer player, WaypointTransmitter waypoint, WaypointTransmitter.Connection connection) @ L121

  • 方法名:updateConnection
  • 源码定位:L121
  • 返回类型:void
  • 修饰符:private

参数:

  • player: ServerPlayer
  • waypoint: WaypointTransmitter
  • connection: WaypointTransmitter.Connection

说明:

TODO

代码

public class ServerWaypointManager implements WaypointManager<WaypointTransmitter> {
    private final Set<WaypointTransmitter> waypoints = new HashSet<>();
    private final Set<ServerPlayer> players = new HashSet<>();
    private final Table<ServerPlayer, WaypointTransmitter, WaypointTransmitter.Connection> connections = HashBasedTable.create();
 
    public void trackWaypoint(WaypointTransmitter waypoint) {
        this.waypoints.add(waypoint);
 
        for (ServerPlayer player : this.players) {
            this.createConnection(player, waypoint);
        }
    }
 
    public void updateWaypoint(WaypointTransmitter waypoint) {
        if (this.waypoints.contains(waypoint)) {
            Map<ServerPlayer, WaypointTransmitter.Connection> playerConnection = Tables.transpose(this.connections).row(waypoint);
            SetView<ServerPlayer> potentialPlayers = Sets.difference(this.players, playerConnection.keySet());
 
            for (Entry<ServerPlayer, WaypointTransmitter.Connection> waypointConnection : ImmutableSet.copyOf(playerConnection.entrySet())) {
                this.updateConnection(waypointConnection.getKey(), waypoint, waypointConnection.getValue());
            }
 
            for (ServerPlayer player : potentialPlayers) {
                this.createConnection(player, waypoint);
            }
        }
    }
 
    public void untrackWaypoint(WaypointTransmitter waypoint) {
        this.connections.column(waypoint).forEach((player, connection) -> connection.disconnect());
        Tables.transpose(this.connections).row(waypoint).clear();
        this.waypoints.remove(waypoint);
    }
 
    public void addPlayer(ServerPlayer player) {
        this.players.add(player);
 
        for (WaypointTransmitter waypoint : this.waypoints) {
            this.createConnection(player, waypoint);
        }
 
        if (player.isTransmittingWaypoint()) {
            this.trackWaypoint((WaypointTransmitter)player);
        }
    }
 
    public void updatePlayer(ServerPlayer player) {
        Map<WaypointTransmitter, WaypointTransmitter.Connection> waypointConnections = this.connections.row(player);
        SetView<WaypointTransmitter> potentialWaypoints = Sets.difference(this.waypoints, waypointConnections.keySet());
 
        for (Entry<WaypointTransmitter, WaypointTransmitter.Connection> waypointConnection : ImmutableSet.copyOf(waypointConnections.entrySet())) {
            this.updateConnection(player, waypointConnection.getKey(), waypointConnection.getValue());
        }
 
        for (WaypointTransmitter waypoint : potentialWaypoints) {
            this.createConnection(player, waypoint);
        }
    }
 
    public void removePlayer(ServerPlayer player) {
        this.connections.row(player).values().removeIf(connection -> {
            connection.disconnect();
            return true;
        });
        this.untrackWaypoint((WaypointTransmitter)player);
        this.players.remove(player);
    }
 
    public void breakAllConnections() {
        this.connections.values().forEach(WaypointTransmitter.Connection::disconnect);
        this.connections.clear();
    }
 
    public void remakeConnections(WaypointTransmitter waypoint) {
        for (ServerPlayer player : this.players) {
            this.createConnection(player, waypoint);
        }
    }
 
    public Set<WaypointTransmitter> transmitters() {
        return this.waypoints;
    }
 
    private static boolean isLocatorBarEnabledFor(ServerPlayer player) {
        return player.level().getGameRules().get(GameRules.LOCATOR_BAR);
    }
 
    private void createConnection(ServerPlayer player, WaypointTransmitter waypoint) {
        if (player != waypoint) {
            if (isLocatorBarEnabledFor(player)) {
                waypoint.makeWaypointConnectionWith(player).ifPresentOrElse(connection -> {
                    this.connections.put(player, waypoint, connection);
                    connection.connect();
                }, () -> {
                    WaypointTransmitter.Connection connection = this.connections.remove(player, waypoint);
                    if (connection != null) {
                        connection.disconnect();
                    }
                });
            }
        }
    }
 
    private void updateConnection(ServerPlayer player, WaypointTransmitter waypoint, WaypointTransmitter.Connection connection) {
        if (player != waypoint) {
            if (isLocatorBarEnabledFor(player)) {
                if (!connection.isBroken()) {
                    connection.update();
                } else {
                    waypoint.makeWaypointConnectionWith(player).ifPresentOrElse(newConnection -> {
                        newConnection.connect();
                        this.connections.put(player, waypoint, newConnection);
                    }, () -> {
                        connection.disconnect();
                        this.connections.remove(player, waypoint);
                    });
                }
            }
        }
    }
}

引用的其他类