Skip to content

Commit

Permalink
Remove sync chunk loading when twerking
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jul 17, 2021
1 parent 71e9e87 commit 1db10a5
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -31,7 +32,7 @@ public class TreeGrowListener implements Listener {
private TwerkingForTrees addon;
private Map<Island, Integer> twerkCount;
private Set<Island> isTwerking;
private Map<Block, Island> plantedTrees;
private Map<Location, Island> plantedTrees;

public TreeGrowListener(@NonNull TwerkingForTrees addon) {
this.addon = addon;
Expand All @@ -46,7 +47,8 @@ protected void runChecker() {
Bukkit.getScheduler().runTaskTimer(addon.getPlugin(), () -> {
isTwerking = twerkCount.entrySet().stream().filter(e -> e.getValue() > addon.getSettings().getMinimumTwerks()).map(Map.Entry::getKey).collect(Collectors.toSet());
twerkCount.clear();
plantedTrees.keySet().removeIf(k -> !Tag.SAPLINGS.isTagged(k.getType()));
// Clear plantedTrees if no one on island is twerking
plantedTrees.values().removeIf(i -> !isTwerking.contains(i));
}
, 0L, 40L);
// Every 20 seconds
Expand All @@ -56,7 +58,7 @@ protected void runChecker() {
.stream()
.filter(e -> isTwerking.contains(e.getValue()))
.map(Map.Entry::getKey)
.forEach(b -> Util.getChunkAtAsync(b.getLocation()).thenRun(() -> growTree(b)))
.forEach(b -> Util.getChunkAtAsync(b).thenRun(() -> growTree(b.getBlock())))
, 10L, 400L);
}

Expand Down Expand Up @@ -119,7 +121,7 @@ private void getNearbySaplings(Player player, Island i) {
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);
plantedTrees.put(block.getLocation(), i);
}
}
}
Expand Down

0 comments on commit 1db10a5

Please sign in to comment.