Skip to content

Commit

Permalink
Fixed detection of crops when they grow for block limits (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Mar 24, 2022
1 parent fb81f88 commit cdfae38
Showing 1 changed file with 32 additions and 0 deletions.
Expand Up @@ -10,15 +10,19 @@
import com.bgsoftware.superiorskyblock.utils.ServerVersion;
import com.bgsoftware.superiorskyblock.utils.StringUtils;
import com.bgsoftware.superiorskyblock.utils.legacy.Materials;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.EquipmentSlot;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -120,6 +124,34 @@ public void onBucketEmpty(PlayerBucketEmptyEvent e) {
}
}

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent e) {
Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation());

if (island == null)
return;

Key blockKey = Key.of(e.getNewState());

if (island.hasReachedBlockLimit(blockKey))
e.setCancelled(true);
}

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent e) {
Island island = plugin.getGrid().getIslandAt(e.getLocation());

if (island == null)
return;

List<BlockState> blockStates = new ArrayList<>(e.getBlocks());

blockStates.forEach(blockState -> {
if (island.hasReachedBlockLimit(Key.of(blockState)))
e.getBlocks().remove(blockState);
});
}

}

}

0 comments on commit cdfae38

Please sign in to comment.