merge #48: fix 1.19 sound + some changes

This commit is contained in:
creeper123123321 2022-09-02 19:51:26 -03:00
parent 3f4830d7e3
commit 649336013e
2 changed files with 28 additions and 12 deletions

View File

@ -34,7 +34,7 @@
<dependency> <dependency>
<groupId>com.viaversion</groupId> <groupId>com.viaversion</groupId>
<artifactId>viaversion-api</artifactId> <artifactId>viaversion-api</artifactId>
<version>4.0.0</version> <version>4.4.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -1,6 +1,7 @@
package de.gerrygames.viarewind.legacysupport.listener; package de.gerrygames.viarewind.legacysupport.listener;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.gerrygames.viarewind.legacysupport.BukkitPlugin; import de.gerrygames.viarewind.legacysupport.BukkitPlugin;
import de.gerrygames.viarewind.legacysupport.injector.NMSReflection; import de.gerrygames.viarewind.legacysupport.injector.NMSReflection;
import de.gerrygames.viarewind.legacysupport.reflection.MethodSignature; import de.gerrygames.viarewind.legacysupport.reflection.MethodSignature;
@ -21,6 +22,7 @@ import org.bukkit.event.player.PlayerExpChangeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.ThreadLocalRandom;
public class SoundListener implements Listener { public class SoundListener implements Listener {
private static boolean isSoundCategory = false; private static boolean isSoundCategory = false;
@ -152,23 +154,37 @@ public class SoundListener implements Listener {
volume = (volume + 1.0f) / 2.0f; volume = (volume + 1.0f) / 2.0f;
pitch *= 0.8; pitch *= 0.8;
playSound(player, soundEffect, soundCategory, block.getX() + 0.5, block.getY() + 0.5, block.getZ() + 0.5, volume, pitch); playSound(player, soundEffect, soundCategory, block.getX() + 0.5, block.getY() + 0.5, block.getZ() + 0.5,
volume, pitch, ThreadLocalRandom.current().nextLong());
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
private static void playSound(Player player, Object soundEffect, Object soundCategory, double x, double y, double z, float volume, float pitch) { private static void playSound(Player player, Object soundEffect, Object soundCategory, double x, double y, double z, float volume, float pitch, long seed) {
try { try {
Object packet = NMSReflection.getGamePacketClass("PacketPlayOutNamedSoundEffect").getConstructor( Object packet;
soundEffect.getClass(), soundCategory.getClass(), if (Via.getAPI().getServerVersion().lowestSupportedVersion() <= ProtocolVersion.v1_18_2.getVersion()) {
double.class, double.class, double.class, packet = NMSReflection.getGamePacketClass("PacketPlayOutNamedSoundEffect").getConstructor(
float.class, float.class soundEffect.getClass(), soundCategory.getClass(),
).newInstance( double.class, double.class, double.class,
soundEffect, soundCategory, float.class, float.class
x, y, z, ).newInstance(
volume, pitch soundEffect, soundCategory,
); x, y, z,
volume, pitch
);
} else {
packet = NMSReflection.getGamePacketClass("PacketPlayOutNamedSoundEffect").getConstructor(
soundEffect.getClass(), soundCategory.getClass(),
double.class, double.class, double.class,
float.class, float.class, long.class
).newInstance(
soundEffect, soundCategory,
x, y, z,
volume, pitch, seed
);
}
NMSReflection.sendPacket(player, packet); NMSReflection.sendPacket(player, packet);
} catch (Exception ex) { } catch (Exception ex) {