diff --git a/build.gradle b/build.gradle index 8e9f960..ca3a463 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '2.2.3' +version = '2.2.4' repositories { mavenCentral() @@ -74,6 +74,7 @@ dependencies { implementation('net.kyori:adventure-text-minimessage:4.12.0') implementation("de.tr7zw:item-nbt-api:2.11.1") implementation("org.bstats:bstats-bukkit:3.0.0") + implementation fileTree(dir:'libs',includes:['BiomeAPI.jar']) } def targetJavaVersion = 17 @@ -109,6 +110,7 @@ shadowJar { relocate ('de.tr7zw', 'net.momirealms.customcrops.libs.de.tr7zw') relocate ('net.kyori', 'net.momirealms.customcrops.libs.net.kyori') relocate ('org.bstats', 'net.momirealms.customcrops.libs.org.bstats') + relocate 'net.momirealms.biomeapi', 'net.momirealms.customcrops.libs.net.momirealms.biomeapi' } tasks.register("delete", Delete).get().delete("build/libs/"+project.name+"-"+project.version+".jar") diff --git a/libs/BiomeAPI.jar b/libs/BiomeAPI.jar new file mode 100644 index 0000000..a9c346d Binary files /dev/null and b/libs/BiomeAPI.jar differ diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java index 31ba350..00e460a 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java @@ -641,6 +641,7 @@ public abstract class HandlerP extends Function { } protected boolean checkHarvestRequirements(Player player, Location location, Crop crop) { + if (player.getGameMode() == GameMode.CREATIVE) return true; PlayerCondition playerCondition = new PlayerCondition(location, player); if (crop.getHarvestRequirements() != null) { for (RequirementInterface requirement : crop.getHarvestRequirements()) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java index dcd6667..b4c12c6 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java @@ -17,6 +17,9 @@ package net.momirealms.customcrops.integrations.customplugin.oraxen; +import dev.lone.itemsadder.api.CustomBlock; +import dev.lone.itemsadder.api.CustomStack; +import io.th0rgal.oraxen.api.OraxenBlocks; import io.th0rgal.oraxen.api.OraxenItems; import io.th0rgal.oraxen.api.events.OraxenFurnitureBreakEvent; import io.th0rgal.oraxen.api.events.OraxenFurnitureInteractEvent; @@ -24,6 +27,7 @@ import io.th0rgal.oraxen.api.events.OraxenNoteBlockBreakEvent; import io.th0rgal.oraxen.api.events.OraxenNoteBlockInteractEvent; import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureFactory; import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic; +import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic; import io.th0rgal.oraxen.utils.drops.Drop; import net.momirealms.customcrops.api.crop.Crop; import net.momirealms.customcrops.config.BasicItemConfig; @@ -43,6 +47,9 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; @@ -136,33 +143,65 @@ public class OraxenFrameHandler extends OraxenHandler { } } +// @Override +// public void onInteractNoteBlock(OraxenNoteBlockInteractEvent event) { +// final Player player = event.getPlayer(); +// final ItemStack itemInHand = event.getItemInHand(); +// final Block block = event.getBlock(); +// +// String blockID = event.getMechanic().getItemID(); +// if (!blockID.equals(BasicItemConfig.dryPot) && !blockID.equals(BasicItemConfig.wetPot)) return; +// +// Location potLoc = block.getLocation(); +// Location seedLoc = potLoc.clone().add(0,1,0); +// +// if (super.tryMisc(player, itemInHand, potLoc)) return; +// if (event.getBlockFace() != BlockFace.UP) return; +// +// String id = OraxenItems.getIdByItem(itemInHand); +// if (id != null) { +// if (id.endsWith("_seeds")) { +// String cropName = id.substring(0, id.length() - 6); +// plantSeed(seedLoc, cropName, player, itemInHand); +// } +// } +// else if (MainConfig.enableConvert) { +// String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType()); +// if (cropName == null) return; +// plantSeed(seedLoc, cropName, player, itemInHand); +// } +// } + @Override - public void onInteractNoteBlock(OraxenNoteBlockInteractEvent event) { + public void onPlayerInteract(PlayerInteractEvent event) { final Player player = event.getPlayer(); - final ItemStack itemInHand = event.getItemInHand(); - final Block block = event.getBlock(); - - String blockID = event.getMechanic().getItemID(); - if (!blockID.equals(BasicItemConfig.dryPot) && !blockID.equals(BasicItemConfig.wetPot)) return; - - Location potLoc = block.getLocation(); - Location seedLoc = potLoc.clone().add(0,1,0); - - if (super.tryMisc(player, itemInHand, potLoc)) return; + if (event.getHand() != EquipmentSlot.HAND) return; + super.onPlayerInteract(event); + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getBlockFace() != BlockFace.UP) return; - - String id = OraxenItems.getIdByItem(itemInHand); - if (id != null) { - if (id.endsWith("_seeds")) { - String cropName = id.substring(0, id.length() - 6); + Block block = event.getClickedBlock(); + if (block == null) return; + NoteBlockMechanic noteBlockMechanic = OraxenBlocks.getNoteBlockMechanic(block); + if (noteBlockMechanic != null) { + final String blockID = noteBlockMechanic.getItemID(); + if (!blockID.equals(BasicItemConfig.wetPot) && !blockID.equals(BasicItemConfig.dryPot)) return; + Location seedLoc = block.getLocation().clone().add(0,1,0); + ItemStack itemInHand = event.getItem(); + Location potLoc = block.getLocation(); + if (super.tryMisc(player, itemInHand, potLoc)) return; + String id = OraxenItems.getIdByItem(itemInHand); + if (id != null) { + if (id.endsWith("_seeds")) { + String cropName = id.substring(0, id.length() - 6); + plantSeed(seedLoc, cropName, player, itemInHand); + } + } + else if (MainConfig.enableConvert) { + String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType()); + if (cropName == null) return; plantSeed(seedLoc, cropName, player, itemInHand); } } - else if (MainConfig.enableConvert) { - String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType()); - if (cropName == null) return; - plantSeed(seedLoc, cropName, player, itemInHand); - } } @Override diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java index 037eeef..ab8a76e 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java @@ -17,12 +17,12 @@ package net.momirealms.customcrops.integrations.customplugin.oraxen; +import io.th0rgal.oraxen.api.OraxenBlocks; import io.th0rgal.oraxen.api.OraxenItems; import io.th0rgal.oraxen.api.events.*; import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureFactory; import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic; import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanic; -import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory; import io.th0rgal.oraxen.utils.drops.Drop; import net.momirealms.customcrops.api.crop.Crop; import net.momirealms.customcrops.config.BasicItemConfig; @@ -40,6 +40,9 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; public class OraxenWireHandler extends OraxenHandler{ @@ -122,83 +125,159 @@ public class OraxenWireHandler extends OraxenHandler{ } } - @Override - public void onInteractNoteBlock(OraxenNoteBlockInteractEvent event) { - if (event.isCancelled()) return; - - final ItemStack itemInHand = event.getItemInHand(); - final Location potLoc = event.getBlock().getLocation(); - final Player player = event.getPlayer(); - - if (super.tryMisc(event.getPlayer(), itemInHand, potLoc)) return; - if (event.getBlockFace() != BlockFace.UP) return; - - Location seedLoc = potLoc.clone().add(0,1,0); - - String id = OraxenItems.getIdByItem(itemInHand); - if (id != null) { - if (id.endsWith("_seeds")) { - String cropName = id.substring(0, id.length() - 6); - plantSeed(seedLoc, cropName, player, itemInHand); - } - } - else if (MainConfig.enableConvert) { - String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType()); - if (cropName == null) return; - plantSeed(seedLoc, cropName, player, itemInHand); - } - } +// @Override +// public void onInteractNoteBlock(OraxenNoteBlockInteractEvent event) { +// if (event.isCancelled()) return; +// if (event.getHand() != EquipmentSlot.HAND) return; +// +// final ItemStack itemInHand = event.getItemInHand(); +// final Location potLoc = event.getBlock().getLocation(); +// final Player player = event.getPlayer(); +// +// if (super.tryMisc(event.getPlayer(), itemInHand, potLoc)) return; +// if (event.getBlockFace() != BlockFace.UP) return; +// +// Location seedLoc = potLoc.clone().add(0,1,0); +// +// String id = OraxenItems.getIdByItem(itemInHand); +// if (id != null) { +// if (id.endsWith("_seeds")) { +// String cropName = id.substring(0, id.length() - 6); +// plantSeed(seedLoc, cropName, player, itemInHand); +// } +// } +// else if (MainConfig.enableConvert) { +// String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType()); +// if (cropName == null) return; +// plantSeed(seedLoc, cropName, player, itemInHand); +// } +// } @Override - public void onInteractStringBlock(OraxenStringBlockInteractEvent event) { - if (event.isCancelled()) return; - + public void onPlayerInteract(PlayerInteractEvent event) { final Player player = event.getPlayer(); - final Block block = event.getBlock(); - final String id = event.getMechanic().getItemID(); - - if (!id.contains("_stage_")) return; - - Location seedLoc = block.getLocation(); - ItemStack itemInHand = event.getItemInHand(); - if (!id.equals(BasicItemConfig.deadCrop)) { - if (isRipe(id)) { - if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand != null && itemInHand.getType() != Material.AIR)) { - if (!CCAntiGrief.testBreak(player, seedLoc)) return; - Crop crop = customInterface.getCropFromID(id); - if (crop == null) return; - if (!checkHarvestRequirements(player, seedLoc, crop)) { - event.setCancelled(true); + if (event.getHand() != EquipmentSlot.HAND) return; + super.onPlayerInteract(event); + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; + Block block = event.getClickedBlock(); + if (block == null) return; + Location location = block.getLocation(); + final String blockID = customInterface.getBlockID(location); + if (blockID == null) return; + if (blockID.contains("_stage_")) { + ItemStack itemInHand = event.getItem(); + if (!blockID.equals(BasicItemConfig.deadCrop)) { + if (isRipe(blockID)) { + ItemStack mainHand = player.getInventory().getItemInMainHand(); + ItemStack offHand = player.getInventory().getItemInOffHand(); + if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && (mainHand.getType() != Material.AIR || offHand.getType() != Material.AIR))) { + if (!CCAntiGrief.testBreak(player, location)) return; + Crop crop = customInterface.getCropFromID(blockID); + if (crop == null) return; + if (!checkHarvestRequirements(player, location, crop)) { + event.setCancelled(true); + return; + } + block.setType(Material.AIR); + super.onInteractRipeCrop(location, crop, player); + if (crop.getReturnStage() != null) customInterface.placeWire(location, crop.getReturnStage()); return; } - block.setType(Material.AIR); - super.onInteractRipeCrop(seedLoc, crop, player); - if (crop.getReturnStage() != null) StringBlockMechanicFactory.setBlockModel(seedLoc.getBlock(), crop.getReturnStage()); + } + //has next stage + else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) { + if (!CCAntiGrief.testPlace(player, location)) return; + if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); + if (Math.random() < MainConfig.boneMealChance) { + location.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0.5,0.5, 0.5),3,0.2,0.2,0.2); + if (SoundConfig.boneMeal.isEnable()) { + AdventureUtil.playerSound( + player, + SoundConfig.boneMeal.getSource(), + SoundConfig.boneMeal.getKey(), + 1,1 + ); + } + block.setType(Material.AIR); + customInterface.placeWire(location, customInterface.getNextStage(blockID)); + } return; } } - //has next stage - else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) { - if (!CCAntiGrief.testPlace(player, seedLoc)) return; - if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); - if (Math.random() < MainConfig.boneMealChance) { - seedLoc.getWorld().spawnParticle(MainConfig.boneMealSuccess, seedLoc.clone().add(0.5,0.5, 0.5),3,0.2,0.2,0.2); - if (SoundConfig.boneMeal.isEnable()) { - AdventureUtil.playerSound( - player, - SoundConfig.boneMeal.getSource(), - SoundConfig.boneMeal.getKey(), - 1,1 - ); - } - StringBlockMechanicFactory.setBlockModel(block, customInterface.getNextStage(id)); + super.tryMisc(player, itemInHand, location.clone().subtract(0,1,0)); + } + //interact pot (must have an item) + else if (blockID.equals(BasicItemConfig.wetPot) || blockID.equals(BasicItemConfig.dryPot)) { + ItemStack itemInHand = event.getItem(); + if (super.tryMisc(player, itemInHand, location)) return; + if (event.getBlockFace() != BlockFace.UP) return; + Location seedLoc = location.clone().add(0,1,0); + String id = OraxenItems.getIdByItem(itemInHand); + if (id != null) { + if (id.endsWith("_seeds")) { + String cropName = id.substring(0, id.length() - 6); + plantSeed(seedLoc, cropName, player, itemInHand); } - return; + } + else if (MainConfig.enableConvert) { + String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType()); + if (cropName == null) return; + plantSeed(seedLoc, cropName, player, itemInHand); } } - super.tryMisc(player, event.getItemInHand(), block.getLocation().clone().subtract(0,1,0)); } +// @Override +// public void onInteractStringBlock(OraxenStringBlockInteractEvent event) { +// if (event.isCancelled()) return; +// if (event.getHand() != EquipmentSlot.HAND) return; +// +// final Player player = event.getPlayer(); +// final Block block = event.getBlock(); +// final String id = event.getMechanic().getItemID(); +// +// if (!id.contains("_stage_")) return; +// +// Location seedLoc = block.getLocation(); +// ItemStack itemInHand = event.getItemInHand(); +// if (!id.equals(BasicItemConfig.deadCrop)) { +// if (isRipe(id)) { +// if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand != null && itemInHand.getType() != Material.AIR)) { +// if (!CCAntiGrief.testBreak(player, seedLoc)) return; +// Crop crop = customInterface.getCropFromID(id); +// if (crop == null) return; +// if (!checkHarvestRequirements(player, seedLoc, crop)) { +// event.setCancelled(true); +// return; +// } +// block.setType(Material.AIR); +// super.onInteractRipeCrop(seedLoc, crop, player); +// if (crop.getReturnStage() != null) StringBlockMechanicFactory.setBlockModel(seedLoc.getBlock(), crop.getReturnStage()); +// return; +// } +// } +// //has next stage +// else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) { +// if (!CCAntiGrief.testPlace(player, seedLoc)) return; +// if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); +// if (Math.random() < MainConfig.boneMealChance) { +// seedLoc.getWorld().spawnParticle(MainConfig.boneMealSuccess, seedLoc.clone().add(0.5,0.5, 0.5),3,0.2,0.2,0.2); +// if (SoundConfig.boneMeal.isEnable()) { +// AdventureUtil.playerSound( +// player, +// SoundConfig.boneMeal.getSource(), +// SoundConfig.boneMeal.getKey(), +// 1,1 +// ); +// } +// StringBlockMechanicFactory.setBlockModel(block, customInterface.getNextStage(id)); +// } +// return; +// } +// } +// super.tryMisc(player, event.getItemInHand(), block.getLocation().clone().subtract(0,1,0)); +// } + @Override public void onBreakNoteBlock(OraxenNoteBlockBreakEvent event) { if (event.isCancelled()) return; diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementBiome.java b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementBiome.java index 98a49cc..1131b22 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementBiome.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementBiome.java @@ -17,6 +17,8 @@ package net.momirealms.customcrops.objects.requirements; +import net.momirealms.biomeapi.BiomeAPI; + public class RequirementBiome extends Requirement implements RequirementInterface { public RequirementBiome(String[] values, boolean mode, String msg) { @@ -25,7 +27,7 @@ public class RequirementBiome extends Requirement implements RequirementInterfac @Override public boolean isConditionMet(PlayerCondition playerCondition) { - String currentBiome = playerCondition.getLocation().getBlock().getBiome().getKey().toString(); + String currentBiome = BiomeAPI.getBiome(playerCondition.getLocation()); if (mode) { for (String value : values) { if (!(currentBiome.equalsIgnoreCase(value))) {