3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Better tab support (handle spacing properly)

Dieser Commit ist enthalten in:
Myles 2017-12-14 19:45:29 +00:00
Ursprung 616c9474ce
Commit a948503895
2 geänderte Dateien mit 44 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -55,14 +55,43 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol {
public void registerMap() { public void registerMap() {
create(new ValueCreator() { create(new ValueCreator() {
@Override @Override
public void write(PacketWrapper wrapper) { public void write(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, wrapper.user().get(TabCompleteTracker.class).getTransactionId()); wrapper.write(Type.VAR_INT, wrapper.user().get(TabCompleteTracker.class).getTransactionId());
String input = wrapper.user().get(TabCompleteTracker.class).getInput();
// Start & End // Start & End
wrapper.write(Type.VAR_INT, 0); int index;
wrapper.write(Type.VAR_INT, 0); int length;
// If no input or new word (then it's the start)
if (input.endsWith(" ") || input.length() == 0) {
index = input.length();
length = 0;
} else {
// Otherwise find the last space
int lastSpace = input.lastIndexOf(" ");
if (lastSpace == -1) {
index = 0;
length = input.length();
} else {
index = lastSpace;
length = input.length() - lastSpace;
}
}
// Write index + length
wrapper.write(Type.VAR_INT, index);
wrapper.write(Type.VAR_INT, length);
int count = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < count; i++) {
String suggestion = wrapper.read(Type.STRING);
// If we're at the start then handle removing slash
if (suggestion.startsWith("/") && index == 0) {
suggestion = suggestion.substring(1);
}
wrapper.write(Type.STRING, suggestion);
}
} }
}); });
// Passthrough the reset
} }
}); });
@ -250,7 +279,8 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol {
// Prepend / // Prepend /
map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) { map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) {
@Override @Override
public String transform(PacketWrapper wrapper, String inputValue) throws Exception { public String transform(PacketWrapper wrapper, String inputValue) {
wrapper.user().get(TabCompleteTracker.class).setInput(inputValue);
return "/" + inputValue; return "/" + inputValue;
} }
}); });

Datei anzeigen

@ -5,6 +5,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
public class TabCompleteTracker extends StoredObject { public class TabCompleteTracker extends StoredObject {
private int transactionId; private int transactionId;
private String input;
public TabCompleteTracker(UserConnection user) { public TabCompleteTracker(UserConnection user) {
super(user); super(user);
@ -17,4 +18,12 @@ public class TabCompleteTracker extends StoredObject {
public void setTransactionId(int transactionId) { public void setTransactionId(int transactionId) {
this.transactionId = transactionId; this.transactionId = transactionId;
} }
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
} }