3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-17 01:23:43 +02:00

Add collision options, fixes #95. (By default auto teams players until they're added to a team so you can't push!)

Dieser Commit ist enthalten in:
Myles 2016-03-06 23:22:45 +00:00
Ursprung e4288383f4
Commit 528b234d5a
4 geänderte Dateien mit 104 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -18,6 +18,7 @@ public class ConnectionInfo {
private int protocol = 0; private int protocol = 0;
private int compression = 0; private int compression = 0;
private boolean active = true; private boolean active = true;
private String username;
public ConnectionInfo(SocketChannel socketChannel) { public ConnectionInfo(SocketChannel socketChannel) {
this.channel = socketChannel; this.channel = socketChannel;
@ -100,4 +101,12 @@ public class ConnectionInfo {
public void closeWindow() { public void closeWindow() {
this.openWindow = null; this.openWindow = null;
} }
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
} }

Datei anzeigen

@ -28,6 +28,7 @@ import us.myles.ViaVersion.update.UpdateUtil;
import us.myles.ViaVersion.util.ReflectionUtil; import us.myles.ViaVersion.util.ReflectionUtil;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -158,6 +159,16 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
return getConfig().getBoolean("sync-chunks", true); return getConfig().getBoolean("sync-chunks", true);
} }
public boolean isPreventCollision() {
return getConfig().getBoolean("prevent-collision", true);
}
public boolean isAutoTeam() {
// Collision has to be enabled first
if(!isPreventCollision()) return false;
return getConfig().getBoolean("auto-team", true);
}
public void setDebug(boolean value) { public void setDebug(boolean value) {
this.debug = value; this.debug = value;
} }

Datei anzeigen

@ -253,10 +253,6 @@ public class OutgoingTransformer {
return; return;
} }
// If login success
if (packet == PacketType.LOGIN_SUCCESS) {
info.setState(State.PLAY);
}
if (packet == PacketType.LOGIN_SETCOMPRESSION) { if (packet == PacketType.LOGIN_SETCOMPRESSION) {
int factor = PacketUtil.readVarInt(input); int factor = PacketUtil.readVarInt(input);
info.setCompression(factor); info.setCompression(factor);
@ -277,12 +273,16 @@ public class OutgoingTransformer {
return; return;
} }
if (packet == PacketType.LOGIN_SUCCESS) { if (packet == PacketType.LOGIN_SUCCESS) {
String uu = PacketUtil.readString(input); info.setState(State.PLAY);
PacketUtil.writeString(uu, output);
UUID uniqueId = UUID.fromString(uu); String uuid = PacketUtil.readString(input);
PacketUtil.writeString(uuid, output);
UUID uniqueId = UUID.fromString(uuid);
info.setUUID(uniqueId); info.setUUID(uniqueId);
plugin.addPortedClient(info); plugin.addPortedClient(info);
output.writeBytes(input); String username = PacketUtil.readString(input);
info.setUsername(username);
PacketUtil.writeString(username, output);
return; return;
} }
@ -548,6 +548,10 @@ public class OutgoingTransformer {
clientEntityTypes.put(id, EntityType.PLAYER); clientEntityTypes.put(id, EntityType.PLAYER);
output.writeInt(id); output.writeInt(id);
output.writeBytes(input); output.writeBytes(input);
// send fake team
if (plugin.isAutoTeam()) {
sendTeamPacket(true);
}
return; return;
} }
if (packet == PacketType.PLAY_SPAWN_PLAYER) { if (packet == PacketType.PLAY_SPAWN_PLAYER) {
@ -612,7 +616,33 @@ public class OutgoingTransformer {
output.writeByte(input.readByte()); output.writeByte(input.readByte());
PacketUtil.writeString(PacketUtil.readString(input), output); PacketUtil.writeString(PacketUtil.readString(input), output);
PacketUtil.writeString("", output); // collission rule :) PacketUtil.writeString(plugin.isPreventCollision() ? "never" : "", output); // collission rule :)
output.writeByte(input.readByte());
}
if (mode == 0 || mode == 3 || mode == 4) {
// add players
int count = PacketUtil.readVarInt(input);
PacketUtil.writeVarInt(count, output);
for (int i = 0; i < count; i++) {
String name = PacketUtil.readString(input);
if (plugin.isAutoTeam() && name.equalsIgnoreCase(info.getUsername())) {
if (mode == 4) {
// since removing add to auto team
plugin.run(new Runnable() {
@Override
public void run() {
sendTeamPacket(true);
}
}, false);
} else {
// since adding remove from auto team
sendTeamPacket(false);
}
}
PacketUtil.writeString(name, output);
}
} }
output.writeBytes(input); output.writeBytes(input);
return; return;
@ -627,22 +657,20 @@ public class OutgoingTransformer {
int index = input.readerIndex(); int index = input.readerIndex();
DataInputStream stream = new DataInputStream(new ByteBufInputStream(input)); DataInputStream stream = new DataInputStream(new ByteBufInputStream(input));
CompoundTag tag = (CompoundTag) NBTIO.readTag(stream); CompoundTag tag = (CompoundTag) NBTIO.readTag(stream);
if(tag != null && tag.contains("EntityId")) { if (tag != null && tag.contains("EntityId")) {
String entity = (String) tag.get("EntityId").getValue(); String entity = (String) tag.get("EntityId").getValue();
CompoundTag spawn = new CompoundTag("SpawnData"); CompoundTag spawn = new CompoundTag("SpawnData");
spawn.put(new StringTag("id", entity)); spawn.put(new StringTag("id", entity));
tag.put(spawn); tag.put(spawn);
DataOutputStream out = new DataOutputStream(new ByteBufOutputStream(output)); DataOutputStream out = new DataOutputStream(new ByteBufOutputStream(output));
NBTIO.writeTag(out, tag); NBTIO.writeTag(out, tag);
} } else if (tag != null) { // EntityID does not exist
else if(tag != null) { // EntityID does not exist
CompoundTag spawn = new CompoundTag("SpawnData"); CompoundTag spawn = new CompoundTag("SpawnData");
spawn.put(new StringTag("id", "AreaEffectCloud")); //Make spawners show up as empty when no EntityId is given. spawn.put(new StringTag("id", "AreaEffectCloud")); //Make spawners show up as empty when no EntityId is given.
tag.put(spawn); tag.put(spawn);
DataOutputStream out = new DataOutputStream(new ByteBufOutputStream(output)); DataOutputStream out = new DataOutputStream(new ByteBufOutputStream(output));
NBTIO.writeTag(out, tag); NBTIO.writeTag(out, tag);
} } else { //There doesn't exist any NBT tag
else { //There doesn't exist any NBT tag
input.readerIndex(index); input.readerIndex(index);
output.writeBytes(input, input.readableBytes()); output.writeBytes(input, input.readableBytes());
} }
@ -720,12 +748,48 @@ public class OutgoingTransformer {
} }
output.writeBytes(input); output.writeBytes(input);
} }
private void sendCreateTeam() {
ByteBuf buf = info.getChannel().alloc().buffer();
PacketUtil.writeVarInt(PacketType.PLAY_TEAM.getNewPacketID(), buf);
PacketUtil.writeString("viaversion", buf);
buf.writeByte(0); // make team
PacketUtil.writeString("viaversion", buf);
PacketUtil.writeString("", buf); // prefix
PacketUtil.writeString("", buf); // suffix
buf.writeByte(0); // friendly fire
PacketUtil.writeString("", buf); // nametags
PacketUtil.writeString("never", buf); // collision rule :)
buf.writeByte(0); // color
PacketUtil.writeVarInt(0, buf); // player count
info.sendRawPacket(buf);
}
private void sendTeamPacket(boolean b) {
ByteBuf buf = info.getChannel().alloc().buffer();
PacketUtil.writeVarInt(PacketType.PLAY_TEAM.getNewPacketID(), buf);
PacketUtil.writeString("viaversion", buf); // Use viaversion as name
if (b) {
// add
buf.writeByte(0); // make team
PacketUtil.writeString("viaversion", buf);
PacketUtil.writeString("", buf); // prefix
PacketUtil.writeString("", buf); // suffix
buf.writeByte(0); // friendly fire
PacketUtil.writeString("", buf); // nametags
PacketUtil.writeString("never", buf); // collision rule :)
buf.writeByte(0); // color
PacketUtil.writeVarInt(1, buf); // player count
PacketUtil.writeString(info.getUsername(), buf); // us
} else {
buf.writeByte(1); // remove team
}
info.sendRawPacket(buf);
}
public static String fixJson(String line) { public static String fixJson(String line) {
if (line == null || line.equalsIgnoreCase("null")) { if (line == null || line.equalsIgnoreCase("null")) {
line = "{\"text\":\"\"}"; line = "{\"text\":\"\"}";
} else { } else {
if ((!line.startsWith("\"") || !line.endsWith("\"")) && (!line.startsWith("{")|| !line.endsWith("}"))) { if ((!line.startsWith("\"") || !line.endsWith("\"")) && (!line.startsWith("{") || !line.endsWith("}"))) {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put("text", line); obj.put("text", line);
return obj.toJSONString(); return obj.toJSONString();

Datei anzeigen

@ -3,3 +3,8 @@ checkforupdates: true
# Should we send any bulk chunks, in sync (may be slower but fixes timings) # Should we send any bulk chunks, in sync (may be slower but fixes timings)
# Currently broken due to sign updates, possibly will return # Currently broken due to sign updates, possibly will return
sync-chunks: true sync-chunks: true
# No collide options, these allow you to configure how collision works.
# Do you want us to prevent collision?
prevent-collision: true
# If the above is true, should we automatically team players until you do?
auto-team: true