From 3e5efd4090340fbf3cb72431957c93f32ade10fd Mon Sep 17 00:00:00 2001 From: Mohamad82Bz Date: Sun, 23 May 2021 21:51:59 +0430 Subject: [PATCH 1/6] Reworked and fixed isDust and isWand check --- src/main/java/com/volmit/iris/Iris.java | 1 + .../com/volmit/iris/manager/WandManager.java | 91 +++++++------------ 2 files changed, 36 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 63b0c4a9b..6dbc1cb7d 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -179,6 +179,7 @@ public class Iris extends VolmitPlugin J.ar(this::checkConfigHotload, 50); PaperLib.suggestPaper(this); getServer().getPluginManager().registerEvents(new CommandLocate(), this); + getServer().getPluginManager().registerEvents(new WandManager() ,this); super.onEnable(); } diff --git a/src/main/java/com/volmit/iris/manager/WandManager.java b/src/main/java/com/volmit/iris/manager/WandManager.java index a5c8d2f81..6a394cc97 100644 --- a/src/main/java/com/volmit/iris/manager/WandManager.java +++ b/src/main/java/com/volmit/iris/manager/WandManager.java @@ -12,7 +12,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -20,13 +19,17 @@ import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; import java.awt.Color; -import java.util.Iterator; import java.util.Objects; -public class WandManager implements Listener -{ +public class WandManager implements Listener { + + private static ItemStack wand; + private static ItemStack dust; + public WandManager() { + wand = createWand(); + dust = createDust(); Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () -> { for(Player i : Bukkit.getOnlinePlayers()) @@ -34,7 +37,6 @@ public class WandManager implements Listener tick(i); } }, 0, 5); - Bukkit.getPluginManager().registerEvents(this, Iris.instance); } public void tick(Player p) @@ -48,7 +50,7 @@ public class WandManager implements Listener } } - catch(Throwable e) + catch(Throwable ignored) { } @@ -94,9 +96,6 @@ public class WandManager implements Listener boolean jj = j == minx || j == maxx; boolean kk = k == miny || k == maxy; boolean ll = l == minz || l == maxz; - double aa = j; - double bb = k; - double cc = l; if((jj && kk) || (jj && ll) || (ll && kk)) { @@ -132,8 +131,8 @@ public class WandManager implements Listener push.add(new Vector(0, 0, 0.55)); } - Location lv = new Location(d[0].getWorld(), aa, bb, cc).clone().add(0.5, 0.5, 0.5).clone().add(push); - Color color = Color.getHSBColor((float) (0.5f + (Math.sin((aa + bb + cc + (p.getTicksLived() / 2)) / 20f) / 2)), 1, 1); + Location lv = new Location(d[0].getWorld(), j, k, l).clone().add(0.5, 0.5, 0.5).clone().add(push); + Color color = Color.getHSBColor((float) (0.5f + (Math.sin((j + k + l + (p.getTicksLived() / 2)) / 20f) / 2)), 1, 1); int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); @@ -150,7 +149,7 @@ public class WandManager implements Listener { try { - if(Objects.equals(e.getHand(), EquipmentSlot.HAND) && isWand(e.getPlayer().getInventory().getItemInMainHand())) + if(isWand(e.getPlayer())) { if(e.getAction().equals(Action.LEFT_CLICK_BLOCK)) { @@ -169,7 +168,7 @@ public class WandManager implements Listener } } - if(e.getHand().equals(EquipmentSlot.HAND) && isDust(e.getPlayer().getInventory().getItemInMainHand())) + if(isDust(e.getPlayer())) { if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { @@ -204,13 +203,8 @@ public class WandManager implements Listener Location[] f = getCuboid(wand); Cuboid c = new Cuboid(f[0], f[1]); IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ()); - Iterator bb = c.iterator(); - while(bb.hasNext()) - { - Block b = bb.next(); - - if(b.getType().equals(Material.AIR)) - { + for (Block b : c) { + if (b.getType().equals(Material.AIR)) { continue; } @@ -235,7 +229,7 @@ public class WandManager implements Listener { String[] f = s.split("\\Q in \\E"); String[] g = f[0].split("\\Q,\\E"); - return new Location(Bukkit.getWorld(f[1]), Integer.valueOf(g[0]), Integer.valueOf(g[1]), Integer.valueOf(g[2])); + return new Location(Bukkit.getWorld(f[1]), Integer.parseInt(g[0]), Integer.parseInt(g[1]), Integer.parseInt(g[2])); } catch(Throwable e) @@ -273,22 +267,18 @@ public class WandManager implements Listener return is; } - public boolean isDust(ItemStack is) + public boolean isDust(Player p) { - if(is == null || is.getType().equals(Material.AIR)) - { - return false; - } - - if(is.getType().equals(Material.GLOWSTONE_DUST)) - { - return true; - } - - return false; + ItemStack is = p.getInventory().getItemInMainHand(); + return is != null && isDust(is); } - public static ItemStack update(boolean left, Location a, ItemStack item) + public boolean isDust(ItemStack is) + { + return is.equals(dust); + } + + public ItemStack update(boolean left, Location a, ItemStack item) { if(!isWand(item)) { @@ -320,35 +310,24 @@ public class WandManager implements Listener return is; } - public static boolean isWand(Player p) - { - ItemStack is = p.getInventory().getItemInMainHand(); - return !(is == null || !isWand(is)); - } - public static Location[] getCuboid(ItemStack is) { ItemMeta im = is.getItemMeta(); return new Location[] {stringToLocation(im.getLore().get(0)), stringToLocation(im.getLore().get(1))}; } - public static boolean isWand(ItemStack item) + public static boolean isWand(Player p) { - if(!item.getType().equals(createWand().getType())) - { - return false; - } + ItemStack is = p.getInventory().getItemInMainHand(); + return is != null && is.equals(wand); + } - if(!item.getItemMeta().getEnchants().equals(createWand().getItemMeta().getEnchants())) - { - return false; - } - - if(!item.getItemMeta().getDisplayName().equals(createWand().getItemMeta().getDisplayName())) - { - return false; - } - - return true; + public static boolean isWand(ItemStack is) + { + if (is.getItemMeta() == null) return false; + return is.getType().equals(wand.getType()) && + is.getItemMeta().getDisplayName().equals(wand.getItemMeta().getDisplayName()) && + is.getItemMeta().getEnchants().equals(wand.getItemMeta().getEnchants()) && + is.getItemMeta().getItemFlags().equals(wand.getItemMeta().getItemFlags()); } } From cee6c7c999ded11a866c259b988fcc33cef87491 Mon Sep 17 00:00:00 2001 From: Mohamad82Bz Date: Sun, 23 May 2021 22:04:41 +0430 Subject: [PATCH 2/6] Reworked and fixed isDust and isWand check #2 --- src/main/java/com/volmit/iris/manager/WandManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/manager/WandManager.java b/src/main/java/com/volmit/iris/manager/WandManager.java index 6a394cc97..d99cafb8f 100644 --- a/src/main/java/com/volmit/iris/manager/WandManager.java +++ b/src/main/java/com/volmit/iris/manager/WandManager.java @@ -319,11 +319,12 @@ public class WandManager implements Listener { public static boolean isWand(Player p) { ItemStack is = p.getInventory().getItemInMainHand(); - return is != null && is.equals(wand); + return is != null && isWand(is); } public static boolean isWand(ItemStack is) { + ItemStack wand = createWand(); if (is.getItemMeta() == null) return false; return is.getType().equals(wand.getType()) && is.getItemMeta().getDisplayName().equals(wand.getItemMeta().getDisplayName()) && From 361b2ed7c7c31298fde16ca30f5f3d9eaab42a13 Mon Sep 17 00:00:00 2001 From: Mohamad82Bz Date: Tue, 25 May 2021 11:43:52 +0430 Subject: [PATCH 3/6] EnginePlayer is now running async --- .../com/volmit/iris/object/IrisEffect.java | 23 ++++++++++++++++--- .../iris/scaffold/engine/EnginePlayer.java | 2 +- src/main/java/com/volmit/iris/util/J.java | 11 +++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/volmit/iris/object/IrisEffect.java b/src/main/java/com/volmit/iris/object/IrisEffect.java index 3da85454c..e1b625912 100644 --- a/src/main/java/com/volmit/iris/object/IrisEffect.java +++ b/src/main/java/com/volmit/iris/object/IrisEffect.java @@ -228,7 +228,10 @@ public class IrisEffect if(sound != null) { Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance)); - p.playSound(part, getSound(), (float) volume, (float) RNG.r.d(minPitch, maxPitch)); + + J.sr(() -> { + p.playSound(part, getSound(), (float) volume, (float) RNG.r.d(minPitch, maxPitch)); + }); } if(particleEffect != null) @@ -239,12 +242,26 @@ public class IrisEffect part.add(RNG.r.d(), 0, RNG.r.d()); if(extra != 0) { - p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ, extra); + J.sr(() -> { + p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), + part.getZ(), + particleCount, + randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, + randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, + randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ, + extra); + }); } else { - p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ); + J.sr(() -> { + p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), + particleCount, + randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, + randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, + randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ); + }); } } diff --git a/src/main/java/com/volmit/iris/scaffold/engine/EnginePlayer.java b/src/main/java/com/volmit/iris/scaffold/engine/EnginePlayer.java index 1dbad0e09..65c9d50e4 100644 --- a/src/main/java/com/volmit/iris/scaffold/engine/EnginePlayer.java +++ b/src/main/java/com/volmit/iris/scaffold/engine/EnginePlayer.java @@ -31,7 +31,7 @@ public class EnginePlayer { { sample(); - J.s(() -> { + J.a(() -> { if(region != null) { for(IrisEffect j : region.getEffects()) diff --git a/src/main/java/com/volmit/iris/util/J.java b/src/main/java/com/volmit/iris/util/J.java index 197041fbb..ee5b0e6f5 100644 --- a/src/main/java/com/volmit/iris/util/J.java +++ b/src/main/java/com/volmit/iris/util/J.java @@ -235,6 +235,17 @@ public class J Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r); } + /** + * Run a sync task + * + * @param r + * the runnable + */ + public static void sr(Runnable r) + { + Bukkit.getScheduler().runTask(Iris.instance, r); + } + /** * Queue a sync task * From 54b5ab6d79f0c01a38b4818ceaa5d1832c1a6692 Mon Sep 17 00:00:00 2001 From: Mohamad82Bz Date: Tue, 25 May 2021 20:24:06 +0430 Subject: [PATCH 4/6] Fixed PotionEffect was adding asynchronously --- .../com/volmit/iris/object/IrisEffect.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/object/IrisEffect.java b/src/main/java/com/volmit/iris/object/IrisEffect.java index e1b625912..3f18839c5 100644 --- a/src/main/java/com/volmit/iris/object/IrisEffect.java +++ b/src/main/java/com/volmit/iris/object/IrisEffect.java @@ -8,6 +8,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.Sound; @@ -231,7 +232,13 @@ public class IrisEffect J.sr(() -> { p.playSound(part, getSound(), (float) volume, (float) RNG.r.d(minPitch, maxPitch)); + Iris.instance.getLogger().info("§bPlayer Location: " + + p.getLocation().getBlockX() + " " + p.getLocation().getBlockY() + " " + p.getLocation().getBlockZ() + + " Sound Location: " + part.getBlockX() + " " + part.getBlockY() + " " + part.getBlockZ() + + " Sound's Name: " + getSound().name()); }); + } else { + Bukkit.getConsoleSender().sendMessage("Sound is null :("); } if(particleEffect != null) @@ -275,10 +282,18 @@ public class IrisEffect return; } - p.removePotionEffect(getRealType()); + J.sr(() -> { + p.removePotionEffect(getRealType()); + }); } - p.addPotionEffect(new PotionEffect(getRealType(), RNG.r.i(Math.min(potionTicksMax, potionTicksMin), Math.max(potionTicksMax, potionTicksMin)), getPotionStrength(), true, false, false)); + J.sr(() -> { + p.addPotionEffect(new PotionEffect(getRealType(), + RNG.r.i(Math.min(potionTicksMax, potionTicksMin), + Math.max(potionTicksMax, potionTicksMin)), + getPotionStrength(), + true, false, false)); + }); } } } From e24a7f887a107966026f1a817b25132c40bc307c Mon Sep 17 00:00:00 2001 From: Mohamad82Bz Date: Tue, 25 May 2021 21:15:51 +0430 Subject: [PATCH 5/6] Using scheduleSyncDelayedTask for sync parts --- src/main/java/com/volmit/iris/object/IrisEffect.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/volmit/iris/object/IrisEffect.java b/src/main/java/com/volmit/iris/object/IrisEffect.java index 3f18839c5..30b1c2a28 100644 --- a/src/main/java/com/volmit/iris/object/IrisEffect.java +++ b/src/main/java/com/volmit/iris/object/IrisEffect.java @@ -230,7 +230,7 @@ public class IrisEffect { Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance)); - J.sr(() -> { + J.s(() -> { p.playSound(part, getSound(), (float) volume, (float) RNG.r.d(minPitch, maxPitch)); Iris.instance.getLogger().info("§bPlayer Location: " + p.getLocation().getBlockX() + " " + p.getLocation().getBlockY() + " " + p.getLocation().getBlockZ() + @@ -249,7 +249,7 @@ public class IrisEffect part.add(RNG.r.d(), 0, RNG.r.d()); if(extra != 0) { - J.sr(() -> { + J.s(() -> { p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), particleCount, @@ -262,7 +262,7 @@ public class IrisEffect else { - J.sr(() -> { + J.s(() -> { p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, @@ -282,12 +282,12 @@ public class IrisEffect return; } - J.sr(() -> { + J.s(() -> { p.removePotionEffect(getRealType()); }); } - J.sr(() -> { + J.s(() -> { p.addPotionEffect(new PotionEffect(getRealType(), RNG.r.i(Math.min(potionTicksMax, potionTicksMin), Math.max(potionTicksMax, potionTicksMin)), From f21685e81d5564d04b5092b22e9fd2ea2d65c1e2 Mon Sep 17 00:00:00 2001 From: Mohamad82Bz Date: Tue, 25 May 2021 21:16:15 +0430 Subject: [PATCH 6/6] Removed J.sr (runTask) as it's no longer needed --- src/main/java/com/volmit/iris/util/J.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/J.java b/src/main/java/com/volmit/iris/util/J.java index ee5b0e6f5..197041fbb 100644 --- a/src/main/java/com/volmit/iris/util/J.java +++ b/src/main/java/com/volmit/iris/util/J.java @@ -235,17 +235,6 @@ public class J Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r); } - /** - * Run a sync task - * - * @param r - * the runnable - */ - public static void sr(Runnable r) - { - Bukkit.getScheduler().runTask(Iris.instance, r); - } - /** * Queue a sync task *