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 File: BungeeServerHandler.java    From ViaVersion with 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 File: VelocityServerHandler.java    From ViaVersion with 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 File: Protocol1_13_2To1_14.java    From ViaBackwards with 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 File: Protocol1_16To1_15_2.java    From ViaVersion with 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 5
Source File: Protocol1_15_2To1_16.java    From ViaBackwards with 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 6
Source File: Protocol1_12_2To1_13.java    From ViaBackwards with 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 7
Source File: Protocol1_9_4To1_10.java    From ViaBackwards with 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 8
Source File: Protocol1_14To1_14_1.java    From ViaBackwards with 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 9
Source File: Protocol1_13To1_12_2.java    From ViaVersion with 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 10
Source File: Protocol1_14_4To1_15.java    From ViaBackwards with 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 11
Source File: Protocol1_13To1_13_1.java    From ViaBackwards with 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 12
Source File: Protocol1_9To1_8.java    From ViaVersion with 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 13
Source File: Protocol1_11To1_11_1.java    From ViaBackwards with 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 14
Source File: Protocol1_8TO1_9.java    From ViaRewind with 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 15
Source File: Protocol1_10To1_9_3_4.java    From ViaVersion with MIT License 4 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    userConnection.put(new ResourcePackTracker(userConnection));
}
 
Example 16
Source File: Protocol1_14To1_13_2.java    From ViaVersion with 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 17
Source File: Protocol1_9_3To1_9_1_2.java    From ViaVersion with 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 18
Source File: Protocol1_12To1_11_1.java    From ViaVersion with 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));
}
 
Example 19
Source File: Protocol1_9_1_2To1_9_3_4.java    From ViaVersion with 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 20
Source File: Protocol1_15To1_14_4.java    From ViaVersion with 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));
}