Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Add config option for blocking and fix crash due to synchronization
Dieser Commit ist enthalten in:
Ursprung
a743895c3f
Commit
b0050d4a8d
@ -116,18 +116,21 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
|||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
for (Field field : connection.getClass().getDeclaredFields()) {
|
for (Field field : connection.getClass().getDeclaredFields()) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object value = field.get(connection);
|
final Object value = field.get(connection);
|
||||||
if (value instanceof List) {
|
if (value instanceof List) {
|
||||||
// Inject the list
|
// Inject the list
|
||||||
field.set(connection, new ListWrapper((List) value) {
|
field.set(connection, new ListWrapper((List) value) {
|
||||||
@Override
|
@Override
|
||||||
public void handleAdd(Object o) {
|
public void handleAdd(Object o) {
|
||||||
|
synchronized (value) {
|
||||||
if (o instanceof ChannelFuture) {
|
if (o instanceof ChannelFuture) {
|
||||||
inject((ChannelFuture) o);
|
inject((ChannelFuture) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// Iterate through current list
|
// Iterate through current list
|
||||||
|
synchronized (value) {
|
||||||
for (Object o : (List) value) {
|
for (Object o : (List) value) {
|
||||||
if (o instanceof ChannelFuture) {
|
if (o instanceof ChannelFuture) {
|
||||||
inject((ChannelFuture) o);
|
inject((ChannelFuture) o);
|
||||||
@ -138,6 +141,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
System.setProperty("ViaVersion", getDescription().getVersion());
|
System.setProperty("ViaVersion", getDescription().getVersion());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getLogger().severe("Unable to inject handlers, are you on 1.8? ");
|
getLogger().severe("Unable to inject handlers, are you on 1.8? ");
|
||||||
@ -221,6 +225,10 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
|||||||
return getConfig().getBoolean("suppress-metadata-errors", false);
|
return getConfig().getBoolean("suppress-metadata-errors", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isShieldBlocking() {
|
||||||
|
return getConfig().getBoolean("shield-blocking", true);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAutoTeam() {
|
public boolean isAutoTeam() {
|
||||||
// Collision has to be enabled first
|
// Collision has to be enabled first
|
||||||
if (!isPreventCollision()) return false;
|
if (!isPreventCollision()) return false;
|
||||||
|
@ -16,6 +16,7 @@ import us.myles.ViaVersion.util.PacketUtil;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class IncomingTransformer {
|
public class IncomingTransformer {
|
||||||
|
private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
||||||
private final ConnectionInfo info;
|
private final ConnectionInfo info;
|
||||||
private boolean startedBlocking = false;
|
private boolean startedBlocking = false;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ public class IncomingTransformer {
|
|||||||
if (packet.getPacketID() != -1) {
|
if (packet.getPacketID() != -1) {
|
||||||
packetID = packet.getPacketID();
|
packetID = packet.getPacketID();
|
||||||
}
|
}
|
||||||
if (ViaVersion.getInstance().isDebug()) {
|
if (plugin.isDebug()) {
|
||||||
if (packet != PacketType.PLAY_PLAYER_POSITION_LOOK_REQUEST && packet != PacketType.PLAY_KEEP_ALIVE_REQUEST && packet != PacketType.PLAY_PLAYER_POSITION_REQUEST && packet != PacketType.PLAY_PLAYER_LOOK_REQUEST) {
|
if (packet != PacketType.PLAY_PLAYER_POSITION_LOOK_REQUEST && packet != PacketType.PLAY_KEEP_ALIVE_REQUEST && packet != PacketType.PLAY_PLAYER_POSITION_REQUEST && packet != PacketType.PLAY_PLAYER_LOOK_REQUEST) {
|
||||||
System.out.println("Direction " + packet.getDirection().name() + " Packet Type: " + packet + " New ID: " + packetID + " Original: " + original + " Size: " + input.readableBytes());
|
System.out.println("Direction " + packet.getDirection().name() + " Packet Type: " + packet + " New ID: " + packetID + " Original: " + original + " Size: " + input.readableBytes());
|
||||||
}
|
}
|
||||||
@ -267,7 +268,7 @@ public class IncomingTransformer {
|
|||||||
output.writeByte(face);
|
output.writeByte(face);
|
||||||
PacketUtil.readVarInt(input);
|
PacketUtil.readVarInt(input);
|
||||||
|
|
||||||
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
ItemStack inHand = plugin.getHandItem(info);
|
||||||
try {
|
try {
|
||||||
ItemSlotRewriter.ItemStack item = ItemSlotRewriter.ItemStack.fromBukkit(inHand);
|
ItemSlotRewriter.ItemStack item = ItemSlotRewriter.ItemStack.fromBukkit(inHand);
|
||||||
ItemSlotRewriter.fixIdsFrom1_9To1_8(item);
|
ItemSlotRewriter.fixIdsFrom1_9To1_8(item);
|
||||||
@ -291,8 +292,8 @@ public class IncomingTransformer {
|
|||||||
output.writeLong(-1L);
|
output.writeLong(-1L);
|
||||||
output.writeByte(255);
|
output.writeByte(255);
|
||||||
// write item in hand
|
// write item in hand
|
||||||
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
ItemStack inHand = plugin.getHandItem(info);
|
||||||
if (inHand != null) {
|
if (inHand != null && plugin.isShieldBlocking()) {
|
||||||
if (inHand.getType().name().endsWith("SWORD")) {
|
if (inHand.getType().name().endsWith("SWORD")) {
|
||||||
// blocking?
|
// blocking?
|
||||||
if (hand == 0) {
|
if (hand == 0) {
|
||||||
|
@ -830,7 +830,7 @@ public class OutgoingTransformer {
|
|||||||
if (entry.getOldID() == 0) {
|
if (entry.getOldID() == 0) {
|
||||||
// Byte
|
// Byte
|
||||||
byte data = (byte) entry.getValue();
|
byte data = (byte) entry.getValue();
|
||||||
|
if (entityID != info.getEntityID() && plugin.isShieldBlocking()) {
|
||||||
if ((data & 0x10) == 0x10) {
|
if ((data & 0x10) == 0x10) {
|
||||||
if (validBlocking.contains(entityID)) {
|
if (validBlocking.contains(entityID)) {
|
||||||
ItemSlotRewriter.ItemStack shield = new ItemSlotRewriter.ItemStack();
|
ItemSlotRewriter.ItemStack shield = new ItemSlotRewriter.ItemStack();
|
||||||
@ -845,6 +845,7 @@ public class OutgoingTransformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private UUID getUUID(int id) {
|
private UUID getUUID(int id) {
|
||||||
|
@ -10,3 +10,5 @@ prevent-collision: true
|
|||||||
auto-team: true
|
auto-team: true
|
||||||
# When enabled if certain metadata can't be read we won't tell you about it
|
# When enabled if certain metadata can't be read we won't tell you about it
|
||||||
suppress-metadata-errors: false
|
suppress-metadata-errors: false
|
||||||
|
# When enabled 1.9 will be able to block by using shields
|
||||||
|
shield-blocking: true
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren