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

The following examples show how to use us.myles.ViaVersion.api.data.UserConnection#put() . 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_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 4
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 5
Source Project: ViaRewind   File: Protocol1_8TO1_9.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
	Ticker.init();

	userConnection.put(new Windows(userConnection));
	userConnection.put(new EntityTracker(userConnection));
	userConnection.put(new Levitation(userConnection));
	userConnection.put(new PlayerPosition(userConnection));
	userConnection.put(new Cooldown(userConnection));
	userConnection.put(new BlockPlaceDestroyTracker(userConnection));
	userConnection.put(new BossBarStorage(userConnection));
	userConnection.put(new ClientWorld(userConnection));
}
 
Example 6
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 7
Source Project: ViaVersion   File: Protocol1_9To1_8.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    // Entity tracker
    userConnection.put(new EntityTracker1_9(userConnection));
    // Chunk tracker
    userConnection.put(new ClientChunks(userConnection));
    // Movement tracker
    userConnection.put(new MovementTracker(userConnection));
    // Inventory tracker
    userConnection.put(new InventoryTracker(userConnection));
    // Place block tracker
    userConnection.put(new PlaceBlockTracker(userConnection));
    // CommandBlock storage
    userConnection.put(new CommandBlockStorage(userConnection));
}
 
Example 8
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 9
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 10
Source Project: ViaVersion   File: Protocol1_13To1_12_2.java    License: MIT License 5 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    userConnection.put(new EntityTracker1_13(userConnection));
    userConnection.put(new TabCompleteTracker(userConnection));
    if (!userConnection.has(ClientWorld.class))
        userConnection.put(new ClientWorld(userConnection));
    userConnection.put(new BlockStorage(userConnection));
    if (Via.getConfig().isServersideBlockConnections()) {
        if (Via.getManager().getProviders().get(BlockConnectionProvider.class) instanceof PacketBlockConnectionProvider) {
            userConnection.put(new BlockConnectionStorage(userConnection));
        }
    }
}
 
Example 11
Source Project: ViaBackwards   File: Protocol1_14To1_14_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);
}
 
Example 12
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 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: 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 16
Source Project: ViaVersion   File: Protocol1_9_1_2To1_9_3_4.java    License: MIT License 4 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    if (!userConnection.has(ClientWorld.class)) {
        userConnection.put(new ClientWorld(userConnection));
    }
}
 
Example 17
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 18
Source Project: ViaVersion   File: Protocol1_10To1_9_3_4.java    License: MIT License 4 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    userConnection.put(new ResourcePackTracker(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));
}