mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-10-31 23:59:33 +01:00
Fix 1.15 EntityToggleGlideEvent cancelling on Bukkit
Since 1.15, cancelling can only be done by updating the player's metadata
This commit is contained in:
parent
4d30cc2309
commit
f173cf73d4
@ -13,7 +13,7 @@
|
||||
|
||||
<properties>
|
||||
<!-- Change Bukkit Version HERE! -->
|
||||
<bukkitVersion>1.8.8-R0.1-SNAPSHOT</bukkitVersion>
|
||||
<bukkitVersion>1.12.2-R0.1-SNAPSHOT</bukkitVersion>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -0,0 +1,68 @@
|
||||
package us.myles.ViaVersion.bukkit.listeners.protocol1_15to1_14_4;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
||||
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class EntityToggleGlideListener extends ViaBukkitListener {
|
||||
|
||||
public EntityToggleGlideListener(ViaVersionPlugin plugin) {
|
||||
super(plugin, Protocol1_15To1_14_4.class);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void entityToggleGlide(EntityToggleGlideEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
if (!isOnPipe(player)) return;
|
||||
|
||||
// Cancelling can only be done by updating the player's metadata
|
||||
if (event.isGliding() && event.isCancelled()) {
|
||||
PacketWrapper packet = new PacketWrapper(0x44, null, getUserConnection(player));
|
||||
try {
|
||||
packet.write(Type.VAR_INT, player.getEntityId());
|
||||
|
||||
byte bitmask = 0;
|
||||
if (player.getFireTicks() > 0) {
|
||||
bitmask |= 0x01;
|
||||
}
|
||||
if (player.isSneaking()) {
|
||||
bitmask |= 0x02;
|
||||
}
|
||||
// 0x04 is unused
|
||||
if (player.isSprinting()) {
|
||||
bitmask |= 0x08;
|
||||
}
|
||||
//TODO isswimming
|
||||
/*if (player.isSprinting()) {
|
||||
bitmask |= 0x10;
|
||||
}*/
|
||||
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
|
||||
bitmask |= 0x20;
|
||||
}
|
||||
if (player.isGlowing()) {
|
||||
bitmask |= 0x40;
|
||||
}
|
||||
|
||||
// leave 0x80 as 0 to stop gliding
|
||||
packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, MetaType1_14.Byte, bitmask)));
|
||||
packet.send(Protocol1_15To1_14_4.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,6 @@ public class ArmorListener extends ViaBukkitListener {
|
||||
// Ensure that the player is on our pipe
|
||||
if (!isOnPipe(player)) return;
|
||||
|
||||
|
||||
int armor = 0;
|
||||
for (ItemStack stack : player.getInventory().getArmorContents()) {
|
||||
armor += ArmorType.findById(stack.getTypeId()).getArmorPoints();
|
||||
@ -114,11 +113,6 @@ public class ArmorListener extends ViaBukkitListener {
|
||||
|
||||
public void sendDelayedArmorUpdate(final Player player) {
|
||||
if (!isOnPipe(player)) return; // Don't start a task if the player is not on the pipe
|
||||
Via.getPlatform().runSync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendArmorUpdate(player);
|
||||
}
|
||||
});
|
||||
Via.getPlatform().runSync(() -> sendArmorUpdate(player));
|
||||
}
|
||||
}
|
@ -17,7 +17,12 @@ 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.listeners.protocol1_15to1_14_4.EntityToggleGlideListener;
|
||||
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.ArmorListener;
|
||||
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.BlockListener;
|
||||
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.DeathListener;
|
||||
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.HandItemCache;
|
||||
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.PaperPatch;
|
||||
import us.myles.ViaVersion.bukkit.providers.BukkitBlockConnectionProvider;
|
||||
import us.myles.ViaVersion.bukkit.providers.BukkitInventoryQuickMoveProvider;
|
||||
import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator;
|
||||
@ -99,6 +104,14 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
}
|
||||
}
|
||||
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_15.getId()) {
|
||||
try {
|
||||
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
|
||||
storeListener(new EntityToggleGlideListener(plugin)).register();
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper")
|
||||
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco")
|
||||
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch"))
|
||||
|
Loading…
Reference in New Issue
Block a user