From 9a0e46193c1eef1634caa7b368f3d3d417248447 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 26 Jun 2020 16:30:02 -0700 Subject: [PATCH 1/4] Version 1.4.1 1.16.1 Spigot API 1.14.0 BentoBox API --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 8fc442c..e6c33ba 100644 --- a/pom.xml +++ b/pom.xml @@ -49,12 +49,12 @@ 1.8 2.0.4 - 1.15-R0.1-SNAPSHOT - 1.9.0 + 1.16.1-R0.1-SNAPSHOT + 1.14.0-SNAPSHOT ${build.version}-SNAPSHOT - 1.4.0 + 1.4.1 -LOCAL From f66c2755b9673abb741e696b513e798b20a1d95d Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 6 Mar 2021 17:53:10 -0800 Subject: [PATCH 2/4] Version 1.4.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e6c33ba..9b878ab 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ ${build.version}-SNAPSHOT - 1.4.1 + 1.4.2 -LOCAL From d4e62b82e67a8f9bd4d0b58778c19bf44d65d8fa Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 10 Jun 2021 20:51:57 -0700 Subject: [PATCH 3/4] Use bonemeal for twerking. WIP - no sounds or effects when the trees grow. https://github.com/BentoBoxWorld/TwerkingForTrees/issues/23#issuecomment-858681016 --- pom.xml | 2 +- .../twerk/listeners/TreeGrowListener.java | 74 +------------------ 2 files changed, 5 insertions(+), 71 deletions(-) diff --git a/pom.xml b/pom.xml index 9b878ab..76d3ccc 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 1.8 2.0.4 - 1.16.1-R0.1-SNAPSHOT + 1.16.5-R0.1-SNAPSHOT 1.14.0-SNAPSHOT ${build.version}-SNAPSHOT diff --git a/src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java b/src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java index af582eb..1e687de 100644 --- a/src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java +++ b/src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java @@ -1,8 +1,6 @@ package world.bentobox.twerk.listeners; import java.util.Arrays; -import java.util.Collections; -import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -11,11 +9,9 @@ import java.util.stream.Collectors; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Tag; -import org.bukkit.TreeType; import org.bukkit.World.Environment; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -34,38 +30,9 @@ public class TreeGrowListener implements Listener { - // The first entry in the list of the quads is where the big tree should be planted - always most positive x and z. - private static final List QUAD1 = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.NORTH_EAST, BlockFace.SELF); - private static final List QUAD2 = Arrays.asList(BlockFace.NORTH_WEST, BlockFace.SELF, BlockFace.WEST, BlockFace.NORTH); - private static final List QUAD3 = Arrays.asList(BlockFace.WEST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.SELF); - private static final List QUAD4 = Arrays.asList(BlockFace.SELF, BlockFace.SOUTH_EAST, BlockFace.EAST, BlockFace.SOUTH); - private static final List> QUADS = Arrays.asList(QUAD1, QUAD2, QUAD3, QUAD4); - private static final List AROUND = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.NORTH_EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH_WEST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST); - /** - * Converts between sapling and tree type. Why doesn't this API exist already I wonder? - */ - private static final Map SAPLING_TO_TREE_TYPE; - static { - Map conv = new EnumMap<>(Material.class); - conv.put(Material.ACACIA_SAPLING, TreeType.ACACIA); - conv.put(Material.BIRCH_SAPLING, TreeType.BIRCH); - conv.put(Material.JUNGLE_SAPLING, TreeType.SMALL_JUNGLE); - conv.put(Material.OAK_SAPLING, TreeType.TREE); - conv.put(Material.SPRUCE_SAPLING, TreeType.REDWOOD); - SAPLING_TO_TREE_TYPE = Collections.unmodifiableMap(conv); - } - private static final Map SAPLING_TO_BIG_TREE_TYPE; - static { - Map conv = new EnumMap<>(Material.class); - conv.put(Material.DARK_OAK_SAPLING, TreeType.DARK_OAK); - conv.put(Material.SPRUCE_SAPLING, TreeType.MEGA_REDWOOD); - conv.put(Material.JUNGLE_SAPLING, TreeType.JUNGLE); - SAPLING_TO_BIG_TREE_TYPE = Collections.unmodifiableMap(conv); - } - private TwerkingForTrees addon; private Map twerkCount; private Set isTwerking; @@ -103,13 +70,9 @@ protected void growTree(Block b) { if (!Tag.SAPLINGS.isTagged(t)) { return; } - // Try to grow big tree if possible - if (SAPLING_TO_BIG_TREE_TYPE.containsKey(t) && bigTreeSaplings(b)) { - return; - } else if (SAPLING_TO_TREE_TYPE.containsKey(t)) { - TreeType type = SAPLING_TO_TREE_TYPE.getOrDefault(b.getType(), TreeType.TREE); - b.setType(Material.AIR); - if (b.getWorld().generateTree(b.getLocation(), type, new BlockChangeHandler(addon, b.getWorld()))) { + for (int i = 0; i < 100; i++) { + if (b.applyBoneMeal(BlockFace.UP)) { + // TODO : this never gets called. if (addon.getSettings().isEffectsEnabled()) { showSparkles(b); } @@ -117,38 +80,9 @@ protected void growTree(Block b) { b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingSmallTreeSound(), (float)addon.getSettings().getSoundsGrowingSmallTreeVolume(), (float)addon.getSettings().getSoundsGrowingSmallTreePitch()); } - } else { - // Tree generation failed, so reset block - b.setType(t); - } - } - } - - protected boolean bigTreeSaplings(Block b) { - Material treeType = b.getType(); - TreeType type = SAPLING_TO_BIG_TREE_TYPE.get(treeType); - for (List q : QUADS) { - if (q.stream().map(b::getRelative).allMatch(c -> c.getType().equals(treeType))) { - // All the same sapling type found in this quad - q.stream().map(b::getRelative).forEach(c -> c.setType(Material.AIR)); - // Get the tree planting location - Location l = b.getRelative(q.get(0)).getLocation(); - if (b.getWorld().generateTree(l, type, new BlockChangeHandler(addon, b.getWorld()))) { - if (addon.getSettings().isEffectsEnabled()) { - showSparkles(b); - } - if (addon.getSettings().isSoundsEnabled()) { - b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingBigTreeSound(), - (float)addon.getSettings().getSoundsGrowingBigTreeVolume(), (float)addon.getSettings().getSoundsGrowingBigTreePitch()); - } - return true; - } else { - // Generation failed, reset saplings - q.stream().map(b::getRelative).forEach(c -> c.setType(treeType)); - } + return; } } - return false; } protected void showSparkles(Block b) { From 2287794ecb449f461edbdfabbf91cc32a74688d8 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 3 Jul 2021 16:16:59 -0700 Subject: [PATCH 4/4] Removed sounds and effects when trees grown. It is not possible to know if a tree is successfully grown or not as the bonemeal method never returns true. This might be a bug in Spigot or vanilla. Either way, the bonemeal approach is much simpler and should be used. --- .../java/world/bentobox/twerk/Settings.java | 125 ++++++------------ .../twerk/listeners/TreeGrowListener.java | 26 +--- src/main/resources/config.yml | 21 --- 3 files changed, 41 insertions(+), 131 deletions(-) diff --git a/src/main/java/world/bentobox/twerk/Settings.java b/src/main/java/world/bentobox/twerk/Settings.java index 19a3b8e..b22aa2a 100644 --- a/src/main/java/world/bentobox/twerk/Settings.java +++ b/src/main/java/world/bentobox/twerk/Settings.java @@ -1,6 +1,5 @@ package world.bentobox.twerk; -import org.bukkit.Effect; import org.bukkit.Sound; import world.bentobox.bentobox.api.configuration.ConfigComment; @@ -20,7 +19,7 @@ public class Settings implements ConfigObject { @ConfigComment("If the player has not twerked enough, then the tree will not grow faster.") @ConfigEntry(path = "minimum-twerks") private int minimumTwerks = 4; - + @ConfigComment("Range to look for saplings when twerking. A range of 5 will look +/- 5 blocks in all directions around the player") @ConfigComment("Making this too big will lag your server.") @ConfigEntry(path = "range") @@ -42,144 +41,94 @@ public class Settings implements ConfigObject { @ConfigEntry(path = "sounds.twerk.pitch") private double soundsTwerkPitch = 2.0F; - @ConfigComment("Sound that plays when a small tree (1x1) grows.") - @ConfigComment("Available sounds are the following:") - @ConfigComment(" https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html") - @ConfigEntry(path = "sounds.growing-small-tree.sound") - private Sound soundsGrowingSmallTreeSound = Sound.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT; - - @ConfigEntry(path = "sounds.growing-small-tree.volume") - private double soundsGrowingSmallTreeVolume = 1.0F; - - @ConfigEntry(path = "sounds.growing-small-tree.pitch") - private double soundsGrowingSmallTreePitch = 1.0F; - - @ConfigComment("Sound that plays when a big tree (2x2) grows.") - @ConfigComment("Available sounds are the following:") - @ConfigComment(" https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html") - @ConfigEntry(path = "sounds.growing-big-tree.sound") - private Sound soundsGrowingBigTreeSound = Sound.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT; - - @ConfigEntry(path = "sounds.growing-big-tree.volume") - private double soundsGrowingBigTreeVolume = 1.0F; - - @ConfigEntry(path = "sounds.growing-big-tree.pitch") - private double soundsGrowingBigTreePitch = 1.0F; - @ConfigComment("Toggle on/off the particle effects.") @ConfigEntry(path = "effects.enabled") private boolean effectsEnabled = true; - @ConfigComment("Effect that plays each time the player twerks.") - @ConfigComment("Available effects are the following:") - @ConfigComment(" https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Effect.html") - @ConfigEntry(path = "effects.twerk") - private Effect effectsTwerk = Effect.MOBSPAWNER_FLAMES; - + /** + * @return the minimumTwerks + */ public int getMinimumTwerks() { return minimumTwerks; } + /** + * @param minimumTwerks the minimumTwerks to set + */ public void setMinimumTwerks(int minimumTwerks) { this.minimumTwerks = minimumTwerks; } + /** + * @return the soundsEnabled + */ public boolean isSoundsEnabled() { return soundsEnabled; } + /** + * @param soundsEnabled the soundsEnabled to set + */ public void setSoundsEnabled(boolean soundsEnabled) { this.soundsEnabled = soundsEnabled; } + /** + * @return the soundsTwerkSound + */ public Sound getSoundsTwerkSound() { return soundsTwerkSound; } + /** + * @param soundsTwerkSound the soundsTwerkSound to set + */ public void setSoundsTwerkSound(Sound soundsTwerkSound) { this.soundsTwerkSound = soundsTwerkSound; } + /** + * @return the soundsTwerkVolume + */ public double getSoundsTwerkVolume() { return soundsTwerkVolume; } + /** + * @param soundsTwerkVolume the soundsTwerkVolume to set + */ public void setSoundsTwerkVolume(double soundsTwerkVolume) { this.soundsTwerkVolume = soundsTwerkVolume; } + /** + * @return the soundsTwerkPitch + */ public double getSoundsTwerkPitch() { return soundsTwerkPitch; } + /** + * @param soundsTwerkPitch the soundsTwerkPitch to set + */ public void setSoundsTwerkPitch(double soundsTwerkPitch) { this.soundsTwerkPitch = soundsTwerkPitch; } - public Sound getSoundsGrowingSmallTreeSound() { - return soundsGrowingSmallTreeSound; - } - - public void setSoundsGrowingSmallTreeSound(Sound soundsGrowingSmallTreeSound) { - this.soundsGrowingSmallTreeSound = soundsGrowingSmallTreeSound; - } - - public double getSoundsGrowingSmallTreeVolume() { - return soundsGrowingSmallTreeVolume; - } - - public void setSoundsGrowingSmallTreeVolume(double soundsGrowingSmallTreeVolume) { - this.soundsGrowingSmallTreeVolume = soundsGrowingSmallTreeVolume; - } - - public double getSoundsGrowingSmallTreePitch() { - return soundsGrowingSmallTreePitch; - } - - public void setSoundsGrowingSmallTreePitch(double soundsGrowingSmallTreePitch) { - this.soundsGrowingSmallTreePitch = soundsGrowingSmallTreePitch; - } - - public Sound getSoundsGrowingBigTreeSound() { - return soundsGrowingBigTreeSound; - } - - public void setSoundsGrowingBigTreeSound(Sound soundsGrowingBigTreeSound) { - this.soundsGrowingBigTreeSound = soundsGrowingBigTreeSound; - } - - public double getSoundsGrowingBigTreeVolume() { - return soundsGrowingBigTreeVolume; - } - - public void setSoundsGrowingBigTreeVolume(double soundsGrowingBigTreeVolume) { - this.soundsGrowingBigTreeVolume = soundsGrowingBigTreeVolume; - } - - public double getSoundsGrowingBigTreePitch() { - return soundsGrowingBigTreePitch; - } - - public void setSoundsGrowingBigTreePitch(double soundsGrowingBigTreePitch) { - this.soundsGrowingBigTreePitch = soundsGrowingBigTreePitch; - } - + /** + * @return the effectsEnabled + */ public boolean isEffectsEnabled() { return effectsEnabled; } + /** + * @param effectsEnabled the effectsEnabled to set + */ public void setEffectsEnabled(boolean effectsEnabled) { this.effectsEnabled = effectsEnabled; } - public Effect getEffectsTwerk() { - return effectsTwerk; - } - - public void setEffectsTwerk(Effect effectsTwerk) { - this.effectsTwerk = effectsTwerk; - } - /** * @return the range */ diff --git a/src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java b/src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java index 1e687de..d9fd0bf 100644 --- a/src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java +++ b/src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java @@ -1,9 +1,7 @@ package world.bentobox.twerk.listeners; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -30,9 +28,6 @@ public class TreeGrowListener implements Listener { - private static final List AROUND = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.NORTH_EAST, - BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH_WEST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST); - private TwerkingForTrees addon; private Map twerkCount; private Set isTwerking; @@ -70,25 +65,12 @@ protected void growTree(Block b) { if (!Tag.SAPLINGS.isTagged(t)) { return; } + // Apply 100 bonemeals - this seems to be enough for (int i = 0; i < 100; i++) { - if (b.applyBoneMeal(BlockFace.UP)) { - // TODO : this never gets called. - if (addon.getSettings().isEffectsEnabled()) { - showSparkles(b); - } - if (addon.getSettings().isSoundsEnabled()) { - b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingSmallTreeSound(), - (float)addon.getSettings().getSoundsGrowingSmallTreeVolume(), (float)addon.getSettings().getSoundsGrowingSmallTreePitch()); - } - return; - } + b.applyBoneMeal(BlockFace.UP); } } - protected void showSparkles(Block b) { - AROUND.stream().map(b::getRelative).map(Block::getLocation).forEach(x -> x.getWorld().playEffect(x, addon.getSettings().getEffectsTwerk(), 0)); - } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onTreeBreak(BlockBreakEvent e) { plantedTrees.keySet().removeIf(e.getBlock()::equals); @@ -123,9 +105,9 @@ public void onTwerk(PlayerToggleSneakEvent e) { int count = twerkCount.get(i) + 1; twerkCount.put(i, count); if (count == addon.getSettings().getMinimumTwerks()) { - e.getPlayer().playSound(e.getPlayer().getLocation(), addon.getSettings().getSoundsTwerkSound(), + e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), addon.getSettings().getSoundsTwerkSound(), (float)addon.getSettings().getSoundsTwerkVolume(), (float)addon.getSettings().getSoundsTwerkPitch()); - e.getPlayer().spawnParticle(Particle.SPELL, e.getPlayer().getLocation(), 20, 3D, 0D, 3D); + e.getPlayer().getWorld().spawnParticle(Particle.SPELL, e.getPlayer().getLocation(), 20, 3D, 0D, 3D); } }); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ed85884..eb3a63c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -16,24 +16,3 @@ sounds: sound: BLOCK_NOTE_BLOCK_BASS volume: 1.0 pitch: 2.0 - growing-small-tree: - # Sound that plays when a small tree (1x1) grows. - # Available sounds are the following: - # https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html - sound: BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT - volume: 1.0 - pitch: 1.0 - growing-big-tree: - # Sound that plays when a big tree (2x2) grows. - # Available sounds are the following: - # https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html - sound: BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT - volume: 1.0 - pitch: 1.0 -effects: - # Toggle on/off the particle effects. - enabled: true - # Effect that plays each time the player twerks. - # Available effects are the following: - # https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Effect.html - twerk: MOBSPAWNER_FLAMES