Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-24 23:30:15 +01:00
Use constants for heights
Dieser Commit ist enthalten in:
Ursprung
b58cbf85e5
Commit
bf523c93d1
@ -17,6 +17,11 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PlayerSneakListener extends ViaBukkitListener {
|
public class PlayerSneakListener extends ViaBukkitListener {
|
||||||
|
private static final float STANDING_HEIGHT = 1.8F;
|
||||||
|
private static final float HEIGHT_1_14 = 1.5F;
|
||||||
|
private static final float HEIGHT_1_9 = 1.6F;
|
||||||
|
private static final float DEFAULT_WIDTH = 0.6F;
|
||||||
|
|
||||||
private Map<Player, Boolean> sneaking; // true = 1.14+, else false
|
private Map<Player, Boolean> sneaking; // true = 1.14+, else false
|
||||||
private Method getHandle;
|
private Method getHandle;
|
||||||
private Method setSize;
|
private Method setSize;
|
||||||
@ -49,7 +54,7 @@ public class PlayerSneakListener extends ViaBukkitListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (Map.Entry<Player, Boolean> entry : sneaking.entrySet()) {
|
for (Map.Entry<Player, Boolean> entry : sneaking.entrySet()) {
|
||||||
setHight(entry.getKey(), entry.getValue() ? 1.5F : 1.6F);
|
setHeight(entry.getKey(), entry.getValue() ? HEIGHT_1_14 : HEIGHT_1_9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1, 1);
|
}, 1, 1);
|
||||||
@ -61,14 +66,14 @@ public class PlayerSneakListener extends ViaBukkitListener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
int protocolVersion = getUserConnection(player).get(ProtocolInfo.class).getProtocolVersion();
|
int protocolVersion = getUserConnection(player).get(ProtocolInfo.class).getProtocolVersion();
|
||||||
if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
|
if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
|
||||||
setHight(player, event.isSneaking() ? 1.5F : 1.8F);
|
setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT);
|
||||||
if (!useCache) return;
|
if (!useCache) return;
|
||||||
if (event.isSneaking())
|
if (event.isSneaking())
|
||||||
sneaking.put(player, true);
|
sneaking.put(player, true);
|
||||||
else
|
else
|
||||||
sneaking.remove(player);
|
sneaking.remove(player);
|
||||||
} else if (is1_9Fix && protocolVersion >= ProtocolVersion.v1_9.getId()) {
|
} else if (is1_9Fix && protocolVersion >= ProtocolVersion.v1_9.getId()) {
|
||||||
setHight(player, event.isSneaking() ? 1.6F : 1.8F);
|
setHeight(player, event.isSneaking() ? HEIGHT_1_9 : STANDING_HEIGHT);
|
||||||
if (!useCache) return;
|
if (!useCache) return;
|
||||||
if (event.isSneaking())
|
if (event.isSneaking())
|
||||||
sneaking.put(player, false);
|
sneaking.put(player, false);
|
||||||
@ -77,9 +82,9 @@ public class PlayerSneakListener extends ViaBukkitListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setHight(Player player, float hight) {
|
private void setHeight(Player player, float height) {
|
||||||
try {
|
try {
|
||||||
setSize.invoke(getHandle.invoke(player), 0.6F, hight);
|
setSize.invoke(getHandle.invoke(player), DEFAULT_WIDTH, height);
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren