Compare commits
9 Commits
da747ce50e
...
6f479c6455
Author | SHA1 | Date |
---|---|---|
FlorianMichael | 6f479c6455 | |
FlorianMichael | 8a92b4d1df | |
FlorianMichael | 560b84e3f5 | |
FlorianMichael | b95e03512e | |
FlorianMichael | 8db6375a8e | |
FlorianMichael | 4d2505d9ee | |
FlorianMichael | 6e55a60a47 | |
FlorianMichael | e580177856 | |
FlorianMichael | 1c6be03d58 |
|
@ -23,7 +23,7 @@ version = project.maven_version
|
|||
group = project.maven_group
|
||||
|
||||
dependencies {
|
||||
compileOnly "com.viaversion:viaversion-api:4.10.0-24w09a-SNAPSHOT"
|
||||
compileOnly "com.viaversion:viaversion-api:4.10.0"
|
||||
compileOnly "org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ org.gradle.parallel=true
|
|||
|
||||
|
||||
# project
|
||||
maven_version=1.5.0-SNAPSHOT
|
||||
maven_version=1.5.1
|
||||
maven_group=com.viaversion
|
||||
|
||||
mcVersionRange=1.8-1.20.4
|
||||
mcVersionRange=1.8-1.20.6
|
|
@ -31,7 +31,6 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class BukkitPlugin extends JavaPlugin {
|
||||
|
||||
|
@ -44,53 +43,55 @@ public class BukkitPlugin extends JavaPlugin {
|
|||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
|
||||
// Load VR LS
|
||||
if (Via.getManager().getInjector().lateProtocolVersionSetting()) {
|
||||
// Enable in the next tick
|
||||
Via.getPlatform().runSync(this::enable, 1);
|
||||
} else {
|
||||
enable();
|
||||
}
|
||||
}
|
||||
|
||||
private void enable() {
|
||||
serverProtocol = Via.getAPI().getServerVersion().lowestSupportedProtocolVersion();
|
||||
if (!serverProtocol.isKnown()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final FileConfiguration config = getConfig();
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
serverProtocol = Via.getAPI().getServerVersion().lowestSupportedProtocolVersion();
|
||||
if (!serverProtocol.isKnown()) return;
|
||||
cancel();
|
||||
|
||||
if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (config.getBoolean("enchanting-gui-fix")) {
|
||||
Bukkit.getPluginManager().registerEvents(new EnchantingGuiEmulator(), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("slime-fix")) {
|
||||
Bukkit.getPluginManager().registerEvents(new SlimeBounceEmulator(), BukkitPlugin.this);
|
||||
}
|
||||
}
|
||||
if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_9)) {
|
||||
if (config.getBoolean("sound-fix")) {
|
||||
Bukkit.getPluginManager().registerEvents(new BlockPlaceSoundEmulator(BukkitPlugin.this), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("ladder-fix")) { // 15w31a
|
||||
BlockCollisionChanges.fixLadder(getLogger(), serverProtocol);
|
||||
}
|
||||
if (config.getBoolean("area-effect-cloud-particles")) { // 15w32c
|
||||
Bukkit.getPluginManager().registerEvents(new AreaEffectCloudEmulator(BukkitPlugin.this), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("elytra-fix")) { // 15w40b
|
||||
Bukkit.getPluginManager().registerEvents(new ElytraVelocityEmulator(), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("brewing-stand-gui-fix")) { // 15w41b
|
||||
Bukkit.getPluginManager().registerEvents(new BrewingInteractionEmulator(), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("lily-pad-fix")) { // 15w44b
|
||||
BlockCollisionChanges.fixLilyPad(getLogger(), serverProtocol);
|
||||
}
|
||||
}
|
||||
if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_14_4) && config.getBoolean("carpet-fix")) {
|
||||
BlockCollisionChanges.fixCarpet(getLogger(), serverProtocol);
|
||||
}
|
||||
if (config.getBoolean("versioninfo.active")) {
|
||||
new VersionInformer(BukkitPlugin.this, config);
|
||||
}
|
||||
if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (config.getBoolean("enchanting-gui-fix")) {
|
||||
Bukkit.getPluginManager().registerEvents(new EnchantingGuiEmulator(), BukkitPlugin.this);
|
||||
}
|
||||
}.runTaskTimer(this, 1L, 1L);
|
||||
if (config.getBoolean("slime-fix")) {
|
||||
Bukkit.getPluginManager().registerEvents(new SlimeBounceEmulator(), BukkitPlugin.this);
|
||||
}
|
||||
}
|
||||
if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_9)) {
|
||||
if (config.getBoolean("sound-fix")) {
|
||||
Bukkit.getPluginManager().registerEvents(new BlockPlaceSoundEmulator(BukkitPlugin.this), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("ladder-fix")) { // 15w31a
|
||||
BlockCollisionChanges.fixLadder(getLogger(), serverProtocol);
|
||||
}
|
||||
if (config.getBoolean("area-effect-cloud-particles")) { // 15w32c
|
||||
Bukkit.getPluginManager().registerEvents(new AreaEffectCloudEmulator(BukkitPlugin.this), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("elytra-fix")) { // 15w40b
|
||||
Bukkit.getPluginManager().registerEvents(new ElytraVelocityEmulator(), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("brewing-stand-gui-fix")) { // 15w41b
|
||||
Bukkit.getPluginManager().registerEvents(new BrewingInteractionEmulator(), BukkitPlugin.this);
|
||||
}
|
||||
if (config.getBoolean("lily-pad-fix")) { // 15w44b
|
||||
BlockCollisionChanges.fixLilyPad(getLogger(), serverProtocol);
|
||||
}
|
||||
}
|
||||
if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_14_4) && config.getBoolean("carpet-fix")) {
|
||||
BlockCollisionChanges.fixCarpet(getLogger(), serverProtocol);
|
||||
}
|
||||
if (config.getBoolean("versioninfo.active")) {
|
||||
new VersionInformer(BukkitPlugin.this, config);
|
||||
}
|
||||
}
|
||||
|
||||
public ProtocolVersion getServerProtocol() {
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package com.viaversion.viarewind.legacysupport.feature;
|
||||
|
||||
import com.viaversion.viarewind.legacysupport.BukkitPlugin;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -82,7 +81,8 @@ public class BlockCollisionChanges {
|
|||
case "AxisAlignedBB": // Legacy NMS
|
||||
setAxisAlignedBB(boundingBox, values);
|
||||
break;
|
||||
case "VoxelShapeArray": // Paper
|
||||
case "VoxelShapeArray": // Paper 1.20.4-
|
||||
case "ArrayVoxelShape": // Paper 1.20.5+
|
||||
setVoxelShapeArray(boundingBox, values);
|
||||
break;
|
||||
case "AABBVoxelShape": // Tuinity
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
package com.viaversion.viarewind.legacysupport.feature;
|
||||
|
||||
import com.viaversion.viarewind.legacysupport.BukkitPlugin;
|
||||
import com.viaversion.viarewind.legacysupport.util.NMSUtil;
|
||||
import com.viaversion.viarewind.legacysupport.util.ReflectionUtil;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -27,15 +30,38 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ElytraVelocityEmulator implements Listener {
|
||||
|
||||
private boolean isGliding(final ProtocolVersion version, final Player player) {
|
||||
if (version.olderThanOrEqualTo(ProtocolVersion.v1_9_1)) {
|
||||
final Object nmsPlayer = NMSUtil.getNMSPlayer(player);
|
||||
if (nmsPlayer == null) return false;
|
||||
|
||||
try {
|
||||
final Method getFlag = ReflectionUtil.getMethod(nmsPlayer.getClass(), "getFlag", int.class);
|
||||
return (boolean) getFlag.invoke(nmsPlayer, 7);
|
||||
} catch (Exception e) {
|
||||
BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to get player flag", e);
|
||||
}
|
||||
}
|
||||
return player.isGliding();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
|
||||
if (Via.getAPI().getPlayerProtocolVersion(player).newerThanOrEqualTo(ProtocolVersion.v1_9)) return; // Only apply for 1.8 and below players
|
||||
if (!player.isGliding()) return; // Only apply if the player is gliding
|
||||
if (Via.getAPI().getPlayerProtocolVersion(player).newerThanOrEqualTo(ProtocolVersion.v1_9)) {
|
||||
return; // Only apply for 1.8 and below players
|
||||
}
|
||||
final ProtocolVersion serverVersion = BukkitPlugin.getInstance().getServerProtocol();
|
||||
if (!isGliding(serverVersion, player)) {
|
||||
return; // Only apply if the player is gliding
|
||||
}
|
||||
|
||||
final Vector direction = player.getLocation().getDirection();
|
||||
final Vector velocity = player.getVelocity();
|
||||
|
|
|
@ -35,7 +35,9 @@ public class NMSUtil {
|
|||
private static Field playerConnectionField;
|
||||
|
||||
static {
|
||||
nmsVersionPackage = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
if (BukkitPlugin.getInstance().getServerProtocol().olderThan(ProtocolVersion.v1_17)) {
|
||||
nmsVersionPackage = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getBlockPositionClass() {
|
||||
|
@ -86,12 +88,18 @@ public class NMSUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static void sendPacket(final Player player, final Object packet) {
|
||||
Object nmsPlayer = null;
|
||||
public static Object getNMSPlayer(final Player player) {
|
||||
try {
|
||||
player.getClass().getMethod("getHandle").invoke(player);
|
||||
return player.getClass().getMethod("getHandle").invoke(player);
|
||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||
BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to get EntityPlayer from player", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacket(final Player player, final Object packet) {
|
||||
final Object nmsPlayer = getNMSPlayer(player);
|
||||
if (nmsPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -120,7 +128,7 @@ public class NMSUtil {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
final Method sendPacket = ReflectionUtil.findMethod(player.getClass(), new String[] {"sendPacket", "a"}, getPacketClass());
|
||||
final Method sendPacket = ReflectionUtil.findMethod(playerConnection.getClass(), new String[] {"sendPacket", "a"}, getPacketClass());
|
||||
sendPacket.invoke(playerConnection, packet);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NullPointerException e) {
|
||||
BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to send packet to player", e);
|
||||
|
|
|
@ -65,7 +65,9 @@ public class ReflectionUtil {
|
|||
return clazz.getDeclaredMethod(methodName, parameterTypes);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
final Class<?> superClass = clazz.getSuperclass();
|
||||
if (superClass == null) return null;
|
||||
if (superClass == null) {
|
||||
return null;
|
||||
}
|
||||
return getMethod(superClass, methodName, parameterTypes);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue