Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
Conflicts:
	pom.xml
  • Loading branch information
tastybento committed Jul 3, 2021
2 parents dacbd19 + 2287794 commit 8bce29e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 201 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
<java.version>1.8</java.version>
<powermock.version>2.0.4</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.15-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.13.0</bentobox.version>
<spigot.version>1.16.5-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.14.0-SNAPSHOT</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.4.1</build.version>
<build.version>1.4.2</build.version>
<build.number>-LOCAL</build.number>
</properties>

Expand Down
125 changes: 37 additions & 88 deletions src/main/java/world/bentobox/twerk/Settings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package world.bentobox.twerk;

import org.bukkit.Effect;
import org.bukkit.Sound;

import world.bentobox.bentobox.api.configuration.ConfigComment;
Expand All @@ -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")
Expand All @@ -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
*/
Expand Down
94 changes: 5 additions & 89 deletions src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
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;
import java.util.Map;
import java.util.Set;
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;
Expand All @@ -34,38 +28,6 @@

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<BlockFace> QUAD1 = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.NORTH_EAST, BlockFace.SELF);
private static final List<BlockFace> QUAD2 = Arrays.asList(BlockFace.NORTH_WEST, BlockFace.SELF, BlockFace.WEST, BlockFace.NORTH);
private static final List<BlockFace> QUAD3 = Arrays.asList(BlockFace.WEST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.SELF);
private static final List<BlockFace> QUAD4 = Arrays.asList(BlockFace.SELF, BlockFace.SOUTH_EAST, BlockFace.EAST, BlockFace.SOUTH);
private static final List<List<BlockFace>> QUADS = Arrays.asList(QUAD1, QUAD2, QUAD3, QUAD4);

private static final List<BlockFace> 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<Material, TreeType> SAPLING_TO_TREE_TYPE;
static {
Map<Material, TreeType> 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<Material, TreeType> SAPLING_TO_BIG_TREE_TYPE;
static {
Map<Material, TreeType> 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<Island, Integer> twerkCount;
private Set<Island> isTwerking;
Expand Down Expand Up @@ -103,56 +65,10 @@ 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()))) {
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());
}
} 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<BlockFace> 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));
}
}
// Apply 100 bonemeals - this seems to be enough
for (int i = 0; i < 100; i++) {
b.applyBoneMeal(BlockFace.UP);
}
return false;
}

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)
Expand Down Expand Up @@ -189,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);
}
});
}
Expand Down
21 changes: 0 additions & 21 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8bce29e

Please sign in to comment.