From 29830e04055fb4fe7e0f26fdd97033b86a300984 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Fri, 6 Nov 2020 14:52:19 +0100 Subject: [PATCH] Check Cauldron Block Type on Update --- src/com/dre/brewery/BCauldron.java | 118 +++++++----------- src/com/dre/brewery/P.java | 18 ++- .../brewery/listeners/CommandListener.java | 24 ---- 3 files changed, 53 insertions(+), 107 deletions(-) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index 87e3ee2..c92b8b8 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -53,15 +53,36 @@ public class BCauldron { particleLocation = block.getLocation().add(0.5, 0.8, 0.5); } - public void onUpdate() { - // Check if fire still alive - if (!BUtil.isChunkLoaded(block) || LegacyUtil.isCauldronHeatsource(block.getRelative(BlockFace.DOWN))) { - // add a minute to cooking time - state++; - if (changed) { - ingredients = ingredients.copy(); - changed = false; + /** + * Updates this Cauldron, increasing the cook time and checking for Heatsource + * + * @return false if Cauldron needs to be removed + */ + public boolean onUpdate() { + // add a minute to cooking time + if (!BUtil.isChunkLoaded(block)) { + increaseState(); + } else { + if (block.getType() != Material.CAULDRON) { + // Catch any WorldEdit etc. removal + return false; } + // Check if fire still alive + if (LegacyUtil.isCauldronHeatsource(block.getRelative(BlockFace.DOWN))) { + increaseState(); + } + } + return true; + } + + /** + * Will add a minute to the cooking time + */ + public void increaseState() { + state++; + if (changed) { + ingredients = ingredients.copy(); + changed = false; } } @@ -79,9 +100,8 @@ public class BCauldron { state--; } if (BConfig.enableCauldronParticles) { - //block.getWorld().spawnParticle(Particle.SPELL_INSTANT, getRandomized(),0, -0.5 + particleRandom.nextFloat(), 1, -0.5 + particleRandom.nextFloat()); + // Few little sparks and lots of water splashes. Offset by 0.2 in x and z block.getWorld().spawnParticle(Particle.SPELL_INSTANT, particleLocation,3, 0.2, 0, 0.2); - //block.getWorld().spawnParticle(Particle.REDSTONE, pLoc1, 15, 0.5, 0.4, 0.5, new Particle.DustOptions(Color.GREEN, 12f)); block.getWorld().spawnParticle(Particle.WATER_SPLASH, particleLocation, 10, 0.2, 0, 0.2); } } @@ -211,60 +231,29 @@ public class BCauldron { } } - public void createParticlePackets() { - try { - - } catch (Exception ignored) {} - } - - double test = 0; - public void cookEffect() { - long time1 = System.nanoTime(); if (BUtil.isChunkLoaded(block) && LegacyUtil.isCauldronHeatsource(block.getRelative(BlockFace.DOWN))) { - time1 = System.nanoTime() - time1; - long time2 = System.nanoTime(); - //block.getWorld().spawnParticle(particle, pLoc1, 2, 0.2, 1, 0.2, 0); - //block.getWorld().spigot().playEffect(pLoc1, effect, 0, 0, 0.2F, 0, 0.2F, 0, 8, 15); - time2 = System.nanoTime() - time2; - long time3 = System.nanoTime(); - //block.getWorld().spawnParticle(Particle.CAMPFIRE_COSY_SMOKE, pLoc1, 0, 0.01, 1, 0.01, 0.05); - //block.getWorld().spawnParticle(Particle.WATER_SPLASH, getRandomized(), 1, 0.1, 0, 0.1, 0.005); if (particleRandom.nextFloat() > 0.75) { - block.getWorld().spawnParticle(Particle.CLOUD, getRandomized(), 0, 0, 1, 0, 0.07); - //block.getWorld().spawnParticle(Particle.REDSTONE, pLoc2, 3, 0.3, 0, 0.3, 10, new Particle.DustOptions(Color.BLUE, 1)); - //block.getWorld().spawnParticle(Particle.SPELL_INSTANT, getRandomized(), 0, 0, 1, 0, 0.005); + // Pixely cloud at 0.4 random in x and z + // 0 count enables direction, send to y = 1 with speed 0.07 + block.getWorld().spawnParticle(Particle.CLOUD, getRandParticleLoc(), 0, 0, 1, 0, 0.07); } if (particleRandom.nextFloat() > 0.2) { + // A Water Splash with 0.2 offset in x and z block.getWorld().spawnParticle(Particle.WATER_SPLASH, particleLocation, 1, 0.2, 0, 0.2); } - block.getWorld().spawnParticle(Particle.SPELL_MOB, getRandomized(), 0, 180.0/255.0, 40.0/255.0, 1.0/255.0, 1025.0); - //block.getWorld().playEffect(pLoc1, Effect.); - //block.getWorld().spigot().playEffect(pLoc2, Effect.SPELL, 0, 0, 0.2F, 0.2F, 0.2F, 0, 2, 25); - time3 = System.nanoTime() - time3; - //P.p.log("Time: 1: " + time1 + " 2: " + time2 + " 3: " + time3); - //block.getWorld().spigot().playEffect(block.getLocation().add(0.5, 1, 0.5), Effect.COLOURED_DUST, 0, 1, 0.3F, 0.5F, 0.3F, 0, 5, 15); - //block.getWorld().spigot().playEffect(block.getLocation().add(0.5, 0.5, 0.5), Effect.PARTICLE_SMOKE, 0, 0, 0.3F, 0.5F, 0.3F, 0, 8, 20); - //test+=1; - //P.p.log(test + ""); - //test = 512.0; - + // Colorable spirally spell, 0 count enables color instead of the offset variables + // Configurable RGB color. 1025 seems to be the best for color brightness and upwards motion + block.getWorld().spawnParticle(Particle.SPELL_MOB, getRandParticleLoc(), 0, 180.0/255.0, 40.0/255.0, 1.0/255.0, 1025.0); } } - public Location getRandomized() { - return new Location(particleLocation.getWorld(), particleLocation.getX() + (particleRandom.nextDouble() * 0.8) - 0.4, particleLocation.getY(), particleLocation.getZ() + (particleRandom.nextDouble() * 0.8) - 0.4); + private Location getRandParticleLoc() { + return new Location(particleLocation.getWorld(), + particleLocation.getX() + (particleRandom.nextDouble() * 0.8) - 0.4, + particleLocation.getY(), + particleLocation.getZ() + (particleRandom.nextDouble() * 0.8) - 0.4); } - // Item Crack - // Block Dust - // FAlling dust - // CAmpfire - // Explosion normal - - // Water Splash - // Spell Mob - // Spell Witch - // CLoud public static void cookEffects() { if (!BConfig.enableCauldronParticles) return; @@ -314,20 +303,6 @@ public class BCauldron { } } - /*public static void cookEffects() { - int size = bcauldrons.size(); - if (size <= 0) { - return; - } - - int numCauldrons = Math.max(size / 40, 1); - Random r = new Random(); - while (numCauldrons > 0) { - bcauldrons.get(r.nextInt(size)).cookEffect(); - numCauldrons--; - } - }*/ - public static void clickCauldron(PlayerInteractEvent event) { Material materialInHand = event.getMaterial(); ItemStack item = event.getItem(); @@ -447,12 +422,11 @@ public class BCauldron { } } - // reset to normal cauldron + /** + * reset to normal cauldron + */ public static boolean remove(Block block) { - if (LegacyUtil.getFillLevel(block) != EMPTY) { - return bcauldrons.remove(block) != null; - } - return false; + return bcauldrons.remove(block) != null; } // unloads cauldrons that are in a unloading world diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 70f2da7..f332561 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -18,7 +18,6 @@ import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.configuration.file.FileConfiguration; @@ -27,6 +26,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.sql.SQLException; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; public class P extends JavaPlugin { @@ -34,7 +34,6 @@ public class P extends JavaPlugin { public static boolean debug; public static boolean useUUID; public static boolean useNBT; - public boolean hasSpigot; public static boolean use1_9; public static boolean use1_11; public static boolean use1_13; @@ -69,13 +68,6 @@ public class P extends JavaPlugin { use1_13 = !v.matches("(^|.*[^.\\d])1\\.1[0-2]([^\\d].*|$)") && !v.matches("(^|.*[^.\\d])1\\.[0-9]([^\\d].*|$)"); use1_14 = !v.matches("(^|.*[^.\\d])1\\.1[0-3]([^\\d].*|$)") && !v.matches("(^|.*[^.\\d])1\\.[0-9]([^\\d].*|$)"); - try { - Class c = World.Spigot.class; - hasSpigot = true; - } catch (LinkageError e) { - hasSpigot = false; - } - //MC 1.13 uses a different NBT API than the newer versions.. // We decide here which to use, the new or the old or none at all if (LegacyUtil.initNbt()) { @@ -462,8 +454,12 @@ public class P extends JavaPlugin { public void run() { long t1 = System.nanoTime(); BConfig.reloader = null; - for (BCauldron cauldron : BCauldron.bcauldrons.values()) { - cauldron.onUpdate();// runs every min to update cooking time + Iterator iter = BCauldron.bcauldrons.values().iterator(); + while (iter.hasNext()) { + // runs every min to update cooking time + if (!iter.next().onUpdate()) { + iter.remove(); + } } long t2 = System.nanoTime(); Barrel.onUpdate();// runs every min to check and update ageing time diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index 6f13c32..3b2117d 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -7,9 +7,7 @@ import com.dre.brewery.recipe.BRecipe; import com.dre.brewery.recipe.Ingredient; import com.dre.brewery.recipe.RecipeItem; import com.dre.brewery.utility.BUtil; -import org.bukkit.Effect; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -17,7 +15,6 @@ import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -166,33 +163,12 @@ public class CommandListener implements CommandExecutor { return true; } - private Runnable r; - private int pos = 0; - public void cmdHelp(CommandSender sender, String[] args) { int page = 1; if (args.length > 1) { - BCauldron.particle = Particle.valueOf(args[1]); - if (BCauldron.particle != null) { - p.msg(sender, "Effekt: " + BCauldron.particle.name()); - } else { - BCauldron.particle = Particle.REDSTONE; - } page = p.parseInt(args[1]); } - r = new Runnable() { - @Override - public void run() { - pos++; - if (pos >= Particle.values().length) { - pos = 0; - } - BCauldron.particle = Particle.values()[pos]; - sender.sendMessage("Particle: " + BCauldron.particle.name()); - } - }; - P.p.getServer().getScheduler().runTaskTimer(P.p, r, 100, 100); ArrayList commands = getCommands(sender);