3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Hitbox fix options

Dieser Commit ist enthalten in:
KennyTV 2019-04-22 14:38:22 +02:00
Ursprung 89a01b3997
Commit e38bdffc84
9 geänderte Dateien mit 155 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,73 @@
package us.myles.ViaVersion.bukkit.listeners.multiversion;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class PlayerSneakListener extends ViaBukkitListener {
private Method getHandle;
private Method setSize;
private boolean is1_9Fix;
private boolean is1_14Fix;
public PlayerSneakListener(ViaVersionPlugin plugin, boolean is1_9Fix, boolean is1_14Fix) {
super(plugin, null);
this.is1_9Fix = is1_9Fix;
this.is1_14Fix = is1_14Fix;
try {
getHandle = Class.forName(plugin.getServer().getClass().getPackage().getName() + ".entity.CraftPlayer").getMethod("getHandle");
setSize = Class.forName(plugin.getServer().getClass().getPackage().getName()
.replace("org.bukkit.craftbukkit", "net.minecraft.server") + ".EntityPlayer").getMethod("setSize", Float.TYPE, Float.TYPE);
} catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
getPlugin().getServer().getScheduler().runTaskTimer(getPlugin(), new Runnable() {
@Override
public void run() {
for (Player onlinePlayer : getPlugin().getServer().getOnlinePlayers()) {
try {
final Object handle = getHandle.invoke(onlinePlayer);
final Class<?> aClass = Class.forName(getPlugin().getServer().getClass().getPackage().getName()
.replace("org.bukkit.craftbukkit", "net.minecraft.server") + ".EntityPlayer");
System.out.println(aClass.getField("length").get(handle));
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
}
}, 1, 1);
}
@EventHandler(ignoreCancelled = true)
public void playerToggleSneak(final PlayerToggleSneakEvent event) {
final Player player = event.getPlayer();
final int protocolVersion = getUserConnection(player).get(ProtocolInfo.class).getProtocolVersion();
if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
setHight(player, event.isSneaking() ? 1.5F : 1.8F);
} else if (is1_9Fix && protocolVersion >= ProtocolVersion.v1_9.getId()) {
setHight(player, event.isSneaking() ? 1.6F : 1.8F);
}
}
private void setHight(Player player, float hight) {
try {
setSize.invoke(getHandle.invoke(player), 0.6F, hight);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}

Datei anzeigen

@ -255,7 +255,18 @@ public class BukkitViaConfig extends Config implements ViaVersionConfig {
return getBoolean("truncate-1_14-books", false);
}
@Override
public boolean isLeftHandedHandling() {
return getBoolean("left-handed-handling", true);
}
@Override
public boolean is1_9HitboxFix() {
return getBoolean("change-1_9-hitbox", false);
}
@Override
public boolean is1_14HitboxFix() {
return getBoolean("change-1_14-hitbox", false);
}
}

Datei anzeigen

@ -15,6 +15,7 @@ import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
import us.myles.ViaVersion.bukkit.listeners.UpdateListener;
import us.myles.ViaVersion.bukkit.listeners.multiversion.PlayerSneakListener;
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.*;
import us.myles.ViaVersion.bukkit.providers.BukkitBlockConnectionProvider;
import us.myles.ViaVersion.bukkit.providers.BukkitInventoryQuickMoveProvider;
@ -76,6 +77,13 @@ public class BukkitViaLoader implements ViaPlatformLoader {
storeListener(new DeathListener(plugin)).register();
storeListener(new BlockListener(plugin)).register();
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getId()) {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId();
if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) {
storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register();
}
}
if ((Bukkit.getVersion().toLowerCase().contains("paper")
|| Bukkit.getVersion().toLowerCase().contains("taco")
|| Bukkit.getVersion().toLowerCase().contains("torch"))

Datei anzeigen

@ -10,7 +10,7 @@ import java.net.URL;
import java.util.*;
public class BungeeViaConfig extends Config implements ViaVersionConfig {
private static List<String> UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch", "quick-move-action-fix", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "blockconnection-method");
private static List<String> UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch", "quick-move-action-fix", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox");
public BungeeViaConfig(File configFile) {
super(new File(configFile, "config.yml"));
@ -308,7 +308,18 @@ public class BungeeViaConfig extends Config implements ViaVersionConfig {
return getBoolean("truncate-1_14-books", false);
}
@Override
public boolean isLeftHandedHandling() {
return getBoolean("left-handed-handling", true);
}
@Override
public boolean is1_9HitboxFix() {
return false;
}
@Override
public boolean is1_14HitboxFix() {
return false;
}
}

Datei anzeigen

@ -33,7 +33,7 @@ public abstract class ViaListener {
protected boolean isOnPipe(UUID uuid) {
UserConnection userConnection = getUserConnection(uuid);
return userConnection != null &&
userConnection.get(ProtocolInfo.class).getPipeline().contains(requiredPipeline);
(requiredPipeline == null || userConnection.get(ProtocolInfo.class).getPipeline().contains(requiredPipeline));
}
/**

Datei anzeigen

@ -323,4 +323,18 @@ public interface ViaVersionConfig {
* @return True if enabled
*/
boolean isLeftHandedHandling();
/**
* Fixes velocity bugs due to different hitbox for 1.9-1.13 clients on 1.8 servers.
*
* @return True if enabled
*/
boolean is1_9HitboxFix();
/**
* Fixes velocity bugs due to different hitbox for 1.14+ clients on sub 1.14 servers.
*
* @return True if enabled
*/
boolean is1_14HitboxFix();
}

Datei anzeigen

@ -120,6 +120,12 @@ disable-1_13-auto-complete: false
fix-low-snow-collision: false
# In 1.14 the client page limit has been upped to 100 (from 50). Some anti-exploit plugins ban when clients go higher than 50. This option cuts edited books to 50 pages.
truncate-1_14-books: false
# This prevents clients using 1.9-1.13 on 1.8 servers from receiving no knockback/having velocity bugs whilst sneaking under a block.
change-1_9-hitbox: false
# Similar to the above, but for 1.14+ players on 1.8-1.13 servers.
# WARNING: This gives 1.14+ players the ability to sneak under blocks, that players under that version cannot (sneaking in places that are only 1.5 blocks high)!
# Another thing to remember is that those players might be missed by projectiles and other hits directed at the very top of their head whilst sneaking.
change-1_14-hitbox: false
#
# Enable serverside block-connections for 1.13+ clients
serverside-blockconnections: false

Datei anzeigen

@ -13,7 +13,7 @@ import java.util.Map;
import java.util.Optional;
public class SpongeViaConfig extends Config implements ViaVersionConfig {
private static List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval", "bungee-ping-save", "bungee-servers", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "quick-move-action-fix");
private static List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval", "bungee-ping-save", "bungee-servers", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "quick-move-action-fix", "change-1_9-hitbox", "change-1_14-hitbox");
private final PluginContainer pluginContainer;
public SpongeViaConfig(PluginContainer pluginContainer, File configFile) {
@ -261,7 +261,18 @@ public class SpongeViaConfig extends Config implements ViaVersionConfig {
return getBoolean("truncate-1_14-books", false);
}
@Override
public boolean isLeftHandedHandling() {
return getBoolean("left-handed-handling", true);
}
@Override
public boolean is1_9HitboxFix() {
return false;
}
@Override
public boolean is1_14HitboxFix() {
return false;
}
}

Datei anzeigen

@ -9,7 +9,7 @@ import java.net.URL;
import java.util.*;
public class VelocityViaConfig extends Config implements ViaVersionConfig {
private static List<String> UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch", "quick-move-action-fix", "bungee-ping-interval", "bungee-ping-save", "bungee-servers", "blockconnection-method");
private static List<String> UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch", "quick-move-action-fix", "bungee-ping-interval", "bungee-ping-save", "bungee-servers", "blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox");
public VelocityViaConfig(File configFile) {
super(new File(configFile, "config.yml"));
@ -313,7 +313,19 @@ public class VelocityViaConfig extends Config implements ViaVersionConfig {
return getBoolean("truncate-1_14-books", false);
}
@Override
public boolean isLeftHandedHandling() {
return getBoolean("left-handed-handling", true);
}
@Override
public boolean is1_9HitboxFix() {
return false;
}
@Override
public boolean is1_14HitboxFix() {
return false;
}
}