Skip to content

Commit

Permalink
Merged from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed May 6, 2020
1 parent 38de092 commit 6ad87c1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/main/java/world/bentobox/twerk/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.api.configuration.ConfigEntry;
import world.bentobox.bentobox.api.configuration.ConfigObject;
Expand All @@ -19,6 +20,11 @@ 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")
private int range = 5;

@ConfigComment("Toggle on/off the sounds.")
@ConfigEntry(path = "sounds.enabled")
Expand Down Expand Up @@ -173,4 +179,21 @@ public Effect getEffectsTwerk() {
public void setEffectsTwerk(Effect effectsTwerk) {
this.effectsTwerk = effectsTwerk;
}

/**
* @return the range
*/
public int getRange() {
if (range < 0) {
range = 0;
}
return range;
}

/**
* @param range the range to set
*/
public void setRange(int range) {
this.range = range;
}
}
27 changes: 24 additions & 3 deletions src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.eclipse.jdt.annotation.NonNull;
Expand Down Expand Up @@ -154,6 +154,7 @@ 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 onTreePlant(BlockPlaceEvent e) {
if (!e.getBlock().getWorld().getEnvironment().equals(Environment.NORMAL)
Expand All @@ -164,7 +165,7 @@ public void onTreePlant(BlockPlaceEvent e) {
// Add Sapling
addon.getIslands().getIslandAt(e.getBlock().getLocation()).ifPresent(i -> plantedTrees.put(e.getBlock(), i));
}

*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onTreeBreak(BlockBreakEvent e) {
plantedTrees.keySet().removeIf(e.getBlock()::equals);
Expand All @@ -184,11 +185,16 @@ public void onTwerk(PlayerToggleSneakEvent e) {
}
// Get the island
addon.getIslands().getIslandAt(e.getPlayer().getLocation()).ifPresent(i -> {
// Check if there are any planted saplings on the island
// Check if there are any planted saplings around player
if (!twerkCount.containsKey(i) || twerkCount.get(i) == 0) {
// New twerking effort
getNearbySaplings(e.getPlayer(), i);
}
if (!plantedTrees.values().contains(i)) {
// None, so return
return;
}

twerkCount.putIfAbsent(i, 0);
int count = twerkCount.get(i) + 1;
twerkCount.put(i, count);
Expand All @@ -199,4 +205,19 @@ public void onTwerk(PlayerToggleSneakEvent e) {
}
});
}

private void getNearbySaplings(Player player, Island i) {
int range = addon.getSettings().getRange();
for (int x = player.getLocation().getBlockX() - range ; x <= player.getLocation().getBlockX() + range; x++) {
for (int y = player.getLocation().getBlockY() - range ; y <= player.getLocation().getBlockY() + range; y++) {
for (int z = player.getLocation().getBlockZ() - range ; z <= player.getLocation().getBlockZ() + range; z++) {
Block block = player.getWorld().getBlockAt(x, y, z);
if (Tag.SAPLINGS.isTagged(block.getType())) {
plantedTrees.put(block, i);
}
}
}
}

}
}
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# How many times the player must twerk before the tree start growing faster.
# If the player has not twerked enough, then the tree will not grow faster.
minimum-twerks: 4
# Range to look for saplings when twerking. A range of 5 will look +/- 5 blocks in all directions around the player
# Making this too big will lag your server.
range: 5
sounds:
# Toggle on/off the sounds.
enabled: true
Expand Down

0 comments on commit 6ad87c1

Please sign in to comment.