Skip to content

Commit

Permalink
Add ability to place glowberry cave vines if planting allowed.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 15, 2024
1 parent 2d44c5d commit 7c3056b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;

Expand Down Expand Up @@ -81,7 +80,6 @@ public void onPlayerInteract(final PlayerInteractEvent e)
Player p = e.getPlayer();
Location l = e.getClickedBlock().getLocation();
Material m = e.getClickedBlock().getType();
BentoBox.getInstance().logDebug(m);
// Check for berry picking
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && (e.getClickedBlock().getType() == Material.CAVE_VINES || e.getClickedBlock().getType() == Material.CAVE_VINES_PLANT)) {
if (!((CaveVinesPlant) e.getClickedBlock().getBlockData()).isBerries()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -15,6 +16,7 @@
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;

Expand All @@ -23,7 +25,8 @@
*/
public class PlaceBlocksListener extends FlagListener
{
public static final Set<Material> SEEDS = Set.of(Material.BEETROOT_SEEDS, Material.MELON_SEEDS, Material.WHEAT_SEEDS);
public static final Set<Material> SEEDS = Set.of(Material.MELON_SEEDS, Material.WHEAT_SEEDS,
Material.SWEET_BERRIES);
/**
* Check blocks being placed in general
*
Expand All @@ -42,8 +45,15 @@ public void onBlockPlace(final BlockPlaceEvent e)
// Books can only be placed on lecterns and as such are protected by the LECTERN flag.
return;
}
// Glowberries
if (e.getItemInHand().getType() == Material.GLOW_BERRIES
&& e.getBlock().getRelative(BlockFace.UP).equals(e.getBlockAgainst())) {
this.checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.CROP_PLANTING);
return;
}
// Crops
if (against.equals(Material.FARMLAND) && SEEDS.contains(e.getItemInHand().getType())) {
if (against.equals(Material.FARMLAND) && (SEEDS.contains(e.getItemInHand().getType())
|| Tag.ITEMS_VILLAGER_PLANTABLE_SEEDS.isTagged(e.getItemInHand().getType()))) {
this.checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.CROP_PLANTING);
} else {
this.checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.PLACE_BLOCKS);
Expand All @@ -59,6 +69,7 @@ public void onBlockPlace(final BlockPlaceEvent e)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onHangingPlace(final HangingPlaceEvent e)
{
BentoBox.getInstance().logDebug(e.getEventName());
this.checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.PLACE_BLOCKS);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/world/bentobox/bentobox/lists/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ private Flags() {}
/**
* Crop Planting
* Controls who gets to plant crops on tilled soil.
* Listener is {@link PlaceBlockListener}
* @since 1.23.0
*/
public static final Flag CROP_PLANTING = new Flag.Builder("CROP_PLANTING", Material.PUMPKIN_SEEDS).mode(Flag.Mode.BASIC).type(Type.PROTECTION).build();
Expand Down

0 comments on commit 7c3056b

Please sign in to comment.