2021-03-22 23:06:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
2024-01-01 12:39:45 +01:00
|
|
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
2021-03-22 23:06:40 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-26 20:52:34 +02:00
|
|
|
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage;
|
2017-12-14 19:45:16 +01:00
|
|
|
|
2023-04-19 12:04:17 +02:00
|
|
|
import com.viaversion.viaversion.api.Via;
|
2021-05-26 21:35:28 +02:00
|
|
|
import com.viaversion.viaversion.api.connection.StorableObject;
|
2021-04-26 21:35:29 +02:00
|
|
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
2023-04-19 12:04:17 +02:00
|
|
|
import com.viaversion.viaversion.api.minecraft.Position;
|
2021-04-27 13:41:39 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.type.Type;
|
2021-07-31 12:43:07 +02:00
|
|
|
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
2023-04-19 12:04:17 +02:00
|
|
|
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
|
2024-03-09 13:57:41 +01:00
|
|
|
import java.util.logging.Level;
|
2017-12-14 19:45:16 +01:00
|
|
|
|
2021-05-26 21:35:28 +02:00
|
|
|
public class TabCompleteTracker implements StorableObject {
|
2017-12-14 19:45:16 +01:00
|
|
|
private int transactionId;
|
2017-12-14 20:45:29 +01:00
|
|
|
private String input;
|
2019-02-07 17:07:30 +01:00
|
|
|
private String lastTabComplete;
|
|
|
|
private long timeToSend;
|
2017-12-14 19:45:16 +01:00
|
|
|
|
2021-05-26 21:35:28 +02:00
|
|
|
public void sendPacketToServer(UserConnection connection) {
|
2019-02-07 17:07:30 +01:00
|
|
|
if (lastTabComplete == null || timeToSend > System.currentTimeMillis()) return;
|
2021-07-31 12:43:07 +02:00
|
|
|
PacketWrapper wrapper = PacketWrapper.create(ServerboundPackets1_12_1.TAB_COMPLETE, null, connection);
|
2019-02-07 17:07:30 +01:00
|
|
|
wrapper.write(Type.STRING, lastTabComplete);
|
|
|
|
wrapper.write(Type.BOOLEAN, false);
|
2023-04-19 12:04:17 +02:00
|
|
|
final Position playerLookTarget = Via.getManager().getProviders().get(PlayerLookTargetProvider.class).getPlayerLookTarget(connection);
|
2023-10-19 13:15:26 +02:00
|
|
|
wrapper.write(Type.OPTIONAL_POSITION1_8, playerLookTarget);
|
2019-02-07 17:07:30 +01:00
|
|
|
try {
|
2021-05-31 22:58:47 +02:00
|
|
|
wrapper.scheduleSendToServer(Protocol1_13To1_12_2.class);
|
2019-02-07 17:07:30 +01:00
|
|
|
} catch (Exception e) {
|
2024-03-09 13:57:41 +01:00
|
|
|
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to send tab complete packet", e);
|
2019-02-07 17:07:30 +01:00
|
|
|
}
|
|
|
|
lastTabComplete = null;
|
|
|
|
}
|
2020-04-13 20:58:24 +02:00
|
|
|
|
|
|
|
public int getTransactionId() {
|
|
|
|
return transactionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTransactionId(int transactionId) {
|
|
|
|
this.transactionId = transactionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getInput() {
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setInput(final String input) {
|
|
|
|
this.input = input;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLastTabComplete() {
|
|
|
|
return lastTabComplete;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLastTabComplete(String lastTabComplete) {
|
|
|
|
this.lastTabComplete = lastTabComplete;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getTimeToSend() {
|
|
|
|
return timeToSend;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTimeToSend(long timeToSend) {
|
|
|
|
this.timeToSend = timeToSend;
|
|
|
|
}
|
2017-12-14 19:45:16 +01:00
|
|
|
}
|