Java Code Examples for us.myles.ViaVersion.api.data.UserConnection#has()

The following examples show how to use us.myles.ViaVersion.api.data.UserConnection#has() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ViaVersion   File: BungeeServerHandler.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = 120)
public void onServerConnect(ServerConnectEvent e) {
    if (e.isCancelled()) {
        return;
    }

    UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
    if (user == null) return;
    if (!user.has(BungeeStorage.class)) {
        user.put(new BungeeStorage(user, e.getPlayer()));
    }

    int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName());
    List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId);

    // Check if ViaVersion can support that version
    try {
        //Object pendingConnection = getPendingConnection.invoke(e.getPlayer());
        Object handshake = getHandshake.invoke(e.getPlayer().getPendingConnection());
        setProtocol.invoke(handshake, protocols == null ? user.getProtocolInfo().getProtocolVersion() : protocolId);
    } catch (InvocationTargetException | IllegalAccessException e1) {
        e1.printStackTrace();
    }
}
 
Example 2
Source Project: ViaVersion   File: VelocityServerHandler.java    License: MIT License 6 votes vote down vote up
@Subscribe
public void preServerConnect(ServerPreConnectEvent e) {
    try {
        UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
        if (user == null) return;
        if (!user.has(VelocityStorage.class)) {
            user.put(new VelocityStorage(user, e.getPlayer()));
        }

        int protocolId = ProtocolDetectorService.getProtocolId(e.getOriginalServer().getServerInfo().getName());
        List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId);

        // Check if ViaVersion can support that version
        Object connection = getMinecraftConnection.invoke(e.getPlayer());
        setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null
                ? user.getProtocolInfo().getProtocolVersion()
                : protocolId));

    } catch (IllegalAccessException | InvocationTargetException e1) {
        e1.printStackTrace();
    }
}
 
Example 3
Source Project: ViaBackwards   File: Protocol1_10To1_11.java    License: MIT License 6 votes vote down vote up
@Override
public void init(UserConnection user) {
    // Register ClientWorld
    if (!user.has(ClientWorld.class)) {
        user.put(new ClientWorld(user));
    }

    // Register EntityTracker if it doesn't exist yet.
    if (!user.has(EntityTracker.class)) {
        user.put(new EntityTracker(user));
    }

    if (!user.has(WindowTracker.class)) {
        user.put(new WindowTracker(user));
    }

    // Init protocol in EntityTracker
    user.get(EntityTracker.class).initProtocol(this);
}
 
Example 4
Source Project: ViaBackwards   File: Protocol1_13_2To1_14.java    License: MIT License 6 votes vote down vote up
@Override
public void init(UserConnection user) {
    // Register ClientWorld
    if (!user.has(ClientWorld.class)) {
        user.put(new ClientWorld(user));
    }

    // Register EntityTracker if it doesn't exist yet.
    if (!user.has(EntityTracker.class)) {
        user.put(new EntityTracker(user));
    }

    // Init protocol in EntityTracker
    user.get(EntityTracker.class).initProtocol(this);

    if (!user.has(ChunkLightStorage.class)) {
        user.put(new ChunkLightStorage(user));
    }
}
 
Example 5
Source Project: ViaBackwards   File: Protocol1_11_1To1_12.java    License: MIT License 6 votes vote down vote up
@Override
public void init(UserConnection user) {
    // Register ClientWorld
    if (!user.has(ClientWorld.class)) {
        user.put(new ClientWorld(user));
    }

    // Register EntityTracker if it doesn't exist yet.
    if (!user.has(EntityTracker.class)) {
        user.put(new EntityTracker(user));
    }

    user.put(new ShoulderTracker(user));

    // Init protocol in EntityTracker
    user.get(EntityTracker.class).initProtocol(this);
}
 
Example 6
Source Project: ViaVersion   File: BungeeBossBarProvider.java    License: MIT License 5 votes vote down vote up
@Override
public void handleAdd(UserConnection user, UUID barUUID) {
    if (user.has(BungeeStorage.class)) {
        BungeeStorage storage = user.get(BungeeStorage.class);
        // Check if bossbars are supported by bungee, static maybe
        if (storage.getBossbar() != null) {
            storage.getBossbar().add(barUUID);
        }
    }
}
 
Example 7
Source Project: ViaVersion   File: BungeeBossBarProvider.java    License: MIT License 5 votes vote down vote up
@Override
public void handleRemove(UserConnection user, UUID barUUID) {
    if (user.has(BungeeStorage.class)) {
        BungeeStorage storage = user.get(BungeeStorage.class);
        if (storage.getBossbar() != null) {
            storage.getBossbar().remove(barUUID);
        }
    }
}
 
Example 8
Source Project: ViaVersion   File: VelocityBossBarProvider.java    License: MIT License 5 votes vote down vote up
@Override
public void handleAdd(UserConnection user, UUID barUUID) {
    if (user.has(VelocityStorage.class)) {
        VelocityStorage storage = user.get(VelocityStorage.class);
        // Check if bossbars are supported by bungee, static maybe
        if (storage.getBossbar() != null) {
            storage.getBossbar().add(barUUID);
        }
    }
}
 
Example 9
Source Project: ViaVersion   File: VelocityBossBarProvider.java    License: MIT License 5 votes vote down vote up
@Override
public void handleRemove(UserConnection user, UUID barUUID) {
    if (user.has(VelocityStorage.class)) {
        VelocityStorage storage = user.get(VelocityStorage.class);
        if (storage.getBossbar() != null) {
            storage.getBossbar().remove(barUUID);
        }
    }
}
 
Example 10
Source Project: ViaBackwards   File: Protocol1_11To1_11_1.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection user) {
    // Register ClientWorld
    if (!user.has(ClientWorld.class)) {
        user.put(new ClientWorld(user));
    }

    // Register EntityTracker if it doesn't exist yet.
    if (!user.has(EntityTracker.class)) {
        user.put(new EntityTracker(user));
    }

    // Init protocol in EntityTracker
    user.get(EntityTracker.class).initProtocol(this);
}
 
Example 11
Source Project: ViaBackwards   File: Protocol1_14_4To1_15.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection user) {
    if (!user.has(ClientWorld.class))
        user.put(new ClientWorld(user));
    if (!user.has(ImmediateRespawn.class))
        user.put(new ImmediateRespawn(user));
    if (!user.has(EntityTracker.class))
        user.put(new EntityTracker(user));
    user.get(EntityTracker.class).initProtocol(this);
}
 
Example 12
Source Project: ViaVersion   File: Protocol1_16To1_15_2.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    userConnection.put(new EntityTracker1_16(userConnection));
    if (!userConnection.has(ClientWorld.class)) {
        userConnection.put(new ClientWorld(userConnection));
    }
}
 
Example 13
Source Project: ViaBackwards   File: Protocol1_12_2To1_13.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection user) {
    // Register ClientWorld
    if (!user.has(ClientWorld.class)) {
        user.put(new ClientWorld(user));
    }

    // Register EntityTracker if it doesn't exist yet.
    if (!user.has(EntityTracker.class)) {
        user.put(new EntityTracker(user));
    }

    // Init protocol in EntityTracker
    user.get(EntityTracker.class).initProtocol(this);

    // Register Block Storage
    if (!user.has(BackwardsBlockStorage.class)) {
        user.put(new BackwardsBlockStorage(user));
    }
    // Register Block Storage
    if (!user.has(TabCompleteStorage.class)) {
        user.put(new TabCompleteStorage(user));
    }

    if (ViaBackwards.getConfig().isFix1_13FacePlayer() && !user.has(PlayerPositionStorage1_13.class)) {
        user.put(new PlayerPositionStorage1_13(user));
    }
}
 
Example 14
Source Project: ViaBackwards   File: Protocol1_15_2To1_16.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection user) {
    if (!user.has(ClientWorld.class)) {
        user.put(new ClientWorld(user));
    }
    if (!user.has(EntityTracker.class)) {
        user.put(new EntityTracker(user));
    }
    user.put(new PlayerSneakStorage(user));
    user.get(EntityTracker.class).initProtocol(this);
}
 
Example 15
Source Project: ViaBackwards   File: Protocol1_13To1_13_1.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection user) {
    // Register EntityTracker if it doesn't exist yet.
    if (!user.has(EntityTracker.class))
        user.put(new EntityTracker(user));

    // Init protocol in EntityTracker
    user.get(EntityTracker.class).initProtocol(this);

    if (!user.has(ClientWorld.class))
        user.put(new ClientWorld(user));
}
 
Example 16
Source Project: ViaBackwards   File: Protocol1_9_4To1_10.java    License: MIT License 5 votes vote down vote up
public void init(UserConnection user) {
    // Register ClientWorld
    if (!user.has(ClientWorld.class)) {
        user.put(new ClientWorld(user));
    }

    // Register EntityTracker if it doesn't exist yet.
    if (!user.has(EntityTracker.class)) {
        user.put(new EntityTracker(user));
    }

    // Init protocol in EntityTracker
    user.get(EntityTracker.class).initProtocol(this);
}
 
Example 17
Source Project: ViaVersion   File: Protocol1_15To1_14_4.java    License: MIT License 4 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    userConnection.put(new EntityTracker1_15(userConnection));
    if (!userConnection.has(ClientWorld.class))
        userConnection.put(new ClientWorld(userConnection));
}
 
Example 18
Source Project: ViaVersion   File: Protocol1_14To1_13_2.java    License: MIT License 4 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    userConnection.put(new EntityTracker1_14(userConnection));
    if (!userConnection.has(ClientWorld.class))
        userConnection.put(new ClientWorld(userConnection));
}
 
Example 19
Source Project: ViaVersion   File: Protocol1_9_3To1_9_1_2.java    License: MIT License 4 votes vote down vote up
@Override
public void init(UserConnection user) {
    if (!user.has(ClientWorld.class)) {
        user.put(new ClientWorld(user));
    }
}
 
Example 20
Source Project: ViaVersion   File: Protocol1_12To1_11_1.java    License: MIT License 4 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    userConnection.put(new EntityTracker1_12(userConnection));
    if (!userConnection.has(ClientWorld.class))
        userConnection.put(new ClientWorld(userConnection));
}