From c7eb47c0589fe17ee530c2a81f5bb6017ea0db30 Mon Sep 17 00:00:00 2001 From: IamTheDefender <72926871+IamTheDefender@users.noreply.github.com> Date: Sun, 28 May 2023 18:19:24 +0530 Subject: [PATCH] Plugin will no longer download glyphs, they came embedded in the JAR. --- pom.xml | 12 +++---- .../api/category/glyphs/items/GlyphItems.java | 2 +- .../category/glyphs/util/ImageParticles.java | 16 ++++----- .../api/category/glyphs/util/glyphUtil.java | 35 +++++++++++-------- .../cosmetics/api/util/StartupUtils.java | 2 +- .../listener/PlayerLeaveListener.java | 10 ++++-- 6 files changed, 44 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index 808bd16b..bf19c95d 100644 --- a/pom.xml +++ b/pom.xml @@ -118,12 +118,6 @@ system ${project.basedir}/lib/proxy-plugin-1.2.4.jar - - fr.mrmicky - FastParticles - 1.2.4 - compile - com.github.MilkBowl VaultAPI @@ -159,5 +153,11 @@ 5.0.1 compile + + xyz.xenondevs + particle + 1.8.4 + compile + diff --git a/src/main/java/me/defender/cosmetics/api/category/glyphs/items/GlyphItems.java b/src/main/java/me/defender/cosmetics/api/category/glyphs/items/GlyphItems.java index 6a9cada3..b3d0449e 100644 --- a/src/main/java/me/defender/cosmetics/api/category/glyphs/items/GlyphItems.java +++ b/src/main/java/me/defender/cosmetics/api/category/glyphs/items/GlyphItems.java @@ -69,7 +69,7 @@ public RarityType getRarity() { public void execute(Player player, Location location) { String fileLocation = config.getString(path + "file"); File file = new File(Utility.plugin().getDataFolder().getPath() + "/Glyphs/" + fileLocation); - HCore.syncScheduler().every(500, TimeUnit.MILLISECONDS).limit(10).run(()-> { + HCore.asyncScheduler().every(500, TimeUnit.MILLISECONDS).limit(10).run(()-> { glyphUtil.sendglyphs(player, file, location); }); } diff --git a/src/main/java/me/defender/cosmetics/api/category/glyphs/util/ImageParticles.java b/src/main/java/me/defender/cosmetics/api/category/glyphs/util/ImageParticles.java index ec503e90..fc4bbec4 100644 --- a/src/main/java/me/defender/cosmetics/api/category/glyphs/util/ImageParticles.java +++ b/src/main/java/me/defender/cosmetics/api/category/glyphs/util/ImageParticles.java @@ -17,7 +17,7 @@ public class ImageParticles private double ratio; private final BufferedImage image; private final int clearence; - + public ImageParticles(final BufferedImage image, final int scanQuality) { this.particles = new HashMap(); this.anchor = new Vector(0, 0, 0); @@ -26,15 +26,15 @@ public ImageParticles(final BufferedImage image, final int scanQuality) { this.image = image; this.renderParticles(Math.abs(scanQuality)); } - + public void setAnchor(final int x, final int y) { this.anchor = new Vector(x, y, 0); } - + public void setDisplayRatio(final double ratio) { this.ratio = ratio; } - + public Map getParticles(final Location location, final double pitch, final double yaw) { final Map map = new HashMap(); for (final Vector vector : this.particles.keySet()) { @@ -46,11 +46,11 @@ public Map getParticles(final Location location, final double p } return map; } - + public Map getParticles(final Location location) { return this.getParticles(location, location.getPitch(), location.getYaw()); } - + private void renderParticles(final int sensitivity) { final int height = this.image.getHeight(); for (int width = this.image.getWidth(), x = 0; x < width; x += sensitivity) { @@ -64,7 +64,7 @@ private void renderParticles(final int sensitivity) { } } } - + private Vector rotateAroundAxisX(final Vector v, double angle) { angle = Math.toRadians(angle); final double cos = Math.cos(angle); @@ -73,7 +73,7 @@ private Vector rotateAroundAxisX(final Vector v, double angle) { final double z = v.getY() * sin + v.getZ() * cos; return v.setY(y).setZ(z); } - + private Vector rotateAroundAxisY(final Vector v, double angle) { angle = -angle; angle = Math.toRadians(angle); diff --git a/src/main/java/me/defender/cosmetics/api/category/glyphs/util/glyphUtil.java b/src/main/java/me/defender/cosmetics/api/category/glyphs/util/glyphUtil.java index 0e104798..f7fa1c75 100644 --- a/src/main/java/me/defender/cosmetics/api/category/glyphs/util/glyphUtil.java +++ b/src/main/java/me/defender/cosmetics/api/category/glyphs/util/glyphUtil.java @@ -2,12 +2,14 @@ package me.defender.cosmetics.api.category.glyphs.util; -import fr.mrmicky.fastparticle.FastParticle; -import fr.mrmicky.fastparticle.ParticleType; +import com.hakan.core.HCore; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; +import xyz.xenondevs.particle.ParticleBuilder; +import xyz.xenondevs.particle.ParticleEffect; +import xyz.xenondevs.particle.data.color.RegularColor; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -20,19 +22,24 @@ public class glyphUtil public static BukkitTask task = null; public static void sendglyphs(Player p, File file, Location loc) { - BufferedImage image = null; try { - image = ImageIO.read(file); - } - catch (final IOException e) { - e.printStackTrace(); - } - ImageParticles particles = new ImageParticles(image, 1); - particles.setAnchor(50, 10); - particles.setDisplayRatio(0.1); - Map particle = particles.getParticles(loc, loc.getPitch(), 180.0); - for (Location spot : particle.keySet()) { - FastParticle.spawnParticle(p.getWorld(), ParticleType.REDSTONE, spot, 1, particle.get(spot)); + BufferedImage image = null; + try { + image = ImageIO.read(file); + } catch (final IOException e) { + e.printStackTrace(); + } + ImageParticles particles = new ImageParticles(image, 1); + particles.setAnchor(50, 10); + particles.setDisplayRatio(0.1); + Map particle = particles.getParticles(loc, loc.getPitch(), 180.0f); + for (Location spot : particle.keySet()) { + HCore.syncScheduler().run(() -> new ParticleBuilder(ParticleEffect.REDSTONE, spot) + .setParticleData(new RegularColor(particle.get(spot).getRed(), particle.get(spot).getGreen(), particle.get(spot).getBlue())) + .display()); + } + }catch (Exception exception){ + } } diff --git a/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java b/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java index 10838feb..c0fff05b 100644 --- a/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java +++ b/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java @@ -142,7 +142,7 @@ public static void downloadGlyphs() { tempFile.delete(); } String[] filesInFolder = folder.list(); - if (filesInFolder != null && filesInFolder.length != 0) { + if (filesInFolder != null && filesInFolder.length == 0) { return; } JavaPlugin plugin = Utility.plugin(); diff --git a/src/main/java/me/defender/cosmetics/listener/PlayerLeaveListener.java b/src/main/java/me/defender/cosmetics/listener/PlayerLeaveListener.java index d770d85f..ddff8bfe 100644 --- a/src/main/java/me/defender/cosmetics/listener/PlayerLeaveListener.java +++ b/src/main/java/me/defender/cosmetics/listener/PlayerLeaveListener.java @@ -1,5 +1,6 @@ package me.defender.cosmetics.listener; +import com.hakan.core.HCore; import me.defender.cosmetics.api.BwcAPI; import me.defender.cosmetics.api.util.Utility; import org.bukkit.event.EventHandler; @@ -12,9 +13,12 @@ public class PlayerLeaveListener implements Listener { public void onLeave(PlayerQuitEvent e){ BwcAPI api = new BwcAPI(); // Saving for SQLite will be on shutdown. - if(api.isMySQL()) { - Utility.playerDataList.get(e.getPlayer().getUniqueId()).save(); - Utility.playerOwnedDataList.get(e.getPlayer().getUniqueId()).save(); + if(api.isMySQL() && Utility.playerDataList.containsKey(e.getPlayer().getUniqueId())) { + HCore.asyncScheduler().run(() -> Utility.playerDataList.get(e.getPlayer().getUniqueId()).save()); + // Didn't use && for playerOwnedData because it's okay for it to be null, I guess... + if(Utility.playerOwnedDataList.containsKey(e.getPlayer().getUniqueId())) { + HCore.asyncScheduler().run(() -> Utility.playerOwnedDataList.get(e.getPlayer().getUniqueId()).save()); + } } } }