2023-09-22 15:39:50 +02:00
|
|
|
/*
|
|
|
|
* This file is part of ViaRewind-Legacy-Support - https://github.com/ViaVersion/ViaRewind-Legacy-Support
|
|
|
|
* Copyright (C) 2016-2023 ViaVersion and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-09-22 14:13:03 +02:00
|
|
|
package com.viaversion.viarewind.legacysupport.listener;
|
2018-02-18 14:43:09 +01:00
|
|
|
|
2021-04-27 10:37:41 +02:00
|
|
|
import com.viaversion.viaversion.api.Via;
|
2018-02-18 14:43:09 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
public class ElytraListener implements Listener {
|
|
|
|
|
2023-09-22 15:10:11 +02:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
|
|
public void onPlayerMove(PlayerMoveEvent e) {
|
|
|
|
Player p = e.getPlayer();
|
|
|
|
if (!p.isGliding()) return;
|
|
|
|
if (Via.getAPI().getPlayerVersion(p) > 76) return;
|
2018-02-18 14:43:09 +01:00
|
|
|
|
2023-09-22 15:10:11 +02:00
|
|
|
Location loc = p.getLocation();
|
|
|
|
Vector velocity = p.getVelocity();
|
|
|
|
Vector direction = loc.getDirection();
|
|
|
|
double motionX = velocity.getX();
|
|
|
|
double motionY = velocity.getY();
|
|
|
|
double motionZ = velocity.getZ();
|
2018-02-18 14:43:09 +01:00
|
|
|
|
2023-09-22 15:10:11 +02:00
|
|
|
float pitch = loc.getPitch() * 0.017453292F;
|
|
|
|
double directionH = Math.sqrt(direction.getX() * direction.getX() + direction.getZ() * direction.getZ());
|
|
|
|
double speedH = Math.sqrt(motionX * motionX + motionZ * motionZ);
|
|
|
|
float speedV = (float) Math.cos(pitch);
|
|
|
|
speedV = (float) (speedV * speedV * Math.min(1.0D, direction.length() / 0.4D));
|
|
|
|
motionY += -0.08D + speedV * 0.06D;
|
|
|
|
if ((motionY < 0.0D) && (directionH > 0.0D)) {
|
|
|
|
double d2 = motionY * -0.1D * speedV;
|
|
|
|
motionY += d2;
|
|
|
|
motionX += direction.getX() * d2 / directionH;
|
|
|
|
motionZ += direction.getZ() * d2 / directionH;
|
|
|
|
}
|
|
|
|
if (pitch < 0.0F) {
|
|
|
|
double speed = speedH * -Math.sin(pitch) * 0.04D;
|
|
|
|
motionY += speed * 3.2D;
|
|
|
|
motionX -= direction.getX() * speed / directionH;
|
|
|
|
motionZ -= direction.getZ() * speed / directionH;
|
|
|
|
}
|
|
|
|
if (directionH > 0.0D) {
|
|
|
|
motionX += (direction.getX() / directionH * speedH - motionX) * 0.1D;
|
|
|
|
motionZ += (direction.getZ() / directionH * speedH - motionZ) * 0.1D;
|
|
|
|
}
|
|
|
|
motionX *= 0.9900000095367432D;
|
|
|
|
motionY *= 0.9800000190734863D;
|
|
|
|
motionZ *= 0.9900000095367432D;
|
|
|
|
velocity.setX(motionX);
|
|
|
|
velocity.setY(motionY);
|
|
|
|
velocity.setZ(motionZ);
|
2018-02-18 14:43:09 +01:00
|
|
|
|
2023-09-22 15:10:11 +02:00
|
|
|
p.setVelocity(velocity);
|
|
|
|
}
|
2018-02-18 14:43:09 +01:00
|
|
|
}
|