Skip to content

Commit

Permalink
fix NoSuchMethodException issue in ParticleWrapper_v1_20_R2
Browse files Browse the repository at this point in the history
  • Loading branch information
hakan-krgn committed Nov 2, 2023
1 parent 04046ca commit d8c99b0
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.hakan.core.particle.wrapper;

import com.hakan.core.HCore;
import com.hakan.core.particle.Particle;
import com.hakan.core.utils.Validate;
import net.minecraft.core.particles.ParticleParam;
import net.minecraft.network.protocol.game.PacketPlayOutWorldParticles;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R2.CraftParticle;
import org.bukkit.entity.Player;

import javax.annotation.Nonnull;
Expand All @@ -25,19 +21,25 @@ public void play(@Nonnull Player player, @Nonnull Location location, @Nonnull Pa
Validate.notNull(location, "location cannot be null!");
Validate.notNull(particle, "particle class cannot be null!");

ParticleParam particleParam = null;
org.bukkit.Particle particleParam = null;
try {
particleParam = CraftParticle.toNMS(org.bukkit.Particle.valueOf(particle.getName()));
particleParam = org.bukkit.Particle.valueOf(particle.getName());
} catch (Exception e) {
for (org.bukkit.Particle _particle : org.bukkit.Particle.values()) {
if (_particle.name().toLowerCase().contains(particle.getName().toLowerCase())) {
particleParam = CraftParticle.toNMS(_particle);
particleParam = _particle;
break;
}
}
}

Validate.notNull(particleParam, "particle couldn't find!");
HCore.sendPacket(player, new PacketPlayOutWorldParticles(particleParam, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), (float) particle.getOffset().getX(), (float) particle.getOffset().getY(), (float) particle.getOffset().getZ(), (float) particle.getSpeed(), particle.getAmount()));
player.spawnParticle(particleParam, location,
particle.getAmount(),
particle.getOffset().getX(),
particle.getOffset().getY(),
particle.getOffset().getZ(),
particle.getSpeed()
);
}
}

0 comments on commit d8c99b0

Please sign in to comment.