9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-25 09:59:20 +00:00

Try implementing some events

This commit is contained in:
XiaoMoMi
2024-09-02 01:18:25 +08:00
parent 3f98c117fc
commit 32a4ab166f
7 changed files with 455 additions and 18 deletions

View File

@@ -36,7 +36,6 @@ import net.momirealms.customcrops.api.core.block.PotConfig;
import net.momirealms.customcrops.api.core.block.SprinklerConfig;
import net.momirealms.customcrops.api.core.item.FertilizerConfig;
import net.momirealms.customcrops.api.core.item.WateringCanConfig;
import net.momirealms.customcrops.api.util.PluginUtils;
import net.momirealms.customcrops.common.helper.AdventureHelper;
import net.momirealms.customcrops.common.locale.TranslationManager;
import net.momirealms.customcrops.common.plugin.CustomCropsProperties;
@@ -131,7 +130,8 @@ public class BukkitConfigManager extends ConfigManager {
defaultQualityRatio = getQualityRatio(config.getString("mechanics.default-quality-ratio", "17/2/1"));
hasNamespace = PluginUtils.isEnabled("ItemsAdder");
preventTrampling = config.getBoolean("mechanics.vanilla-farmland.prevent-trampling", false);
disableMoistureMechanic = config.getBoolean("mechanics.vanilla-farmland.disable-moisture-mechanic", false);
}
@Override

View File

@@ -449,6 +449,51 @@ public class BukkitItemManager extends AbstractItemManager {
}
}
@Override
public void handleEntityTrample(Entity entity, Location location, String brokenID, Cancellable event) {
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(entity.getWorld());
if (optionalWorld.isEmpty()) {
return;
}
CustomCropsWorld<?> world = optionalWorld.get();
WrappedBreakEvent wrapped = new WrappedBreakEvent(entity, null, world, location, brokenID, null, null, BreakReason.TRAMPLE, event);
CustomCropsBlock customCropsBlock = Registries.BLOCKS.get(brokenID);
if (customCropsBlock != null) {
customCropsBlock.onBreak(wrapped);
}
}
@Override
public void handleEntityExplode(Entity entity, Location location, String brokenID, Cancellable event) {
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(entity.getWorld());
if (optionalWorld.isEmpty()) {
return;
}
CustomCropsWorld<?> world = optionalWorld.get();
WrappedBreakEvent wrapped = new WrappedBreakEvent(entity, null, world, location, brokenID, null, null, BreakReason.EXPLODE, event);
CustomCropsBlock customCropsBlock = Registries.BLOCKS.get(brokenID);
if (customCropsBlock != null) {
customCropsBlock.onBreak(wrapped);
}
}
@Override
public void handleBlockExplode(Block block, Location location, String brokenID, Cancellable event) {
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(block.getWorld());
if (optionalWorld.isEmpty()) {
return;
}
CustomCropsWorld<?> world = optionalWorld.get();
WrappedBreakEvent wrapped = new WrappedBreakEvent(null, block, world, location, brokenID, null, null, BreakReason.EXPLODE, event);
CustomCropsBlock customCropsBlock = Registries.BLOCKS.get(brokenID);
if (customCropsBlock != null) {
customCropsBlock.onBreak(wrapped);
}
}
@Override
public void handlePlayerPlace(Player player, Location location, String placedID, EquipmentSlot hand, ItemStack itemInHand, Cancellable event) {
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(player.getWorld());
@@ -461,9 +506,18 @@ public class BukkitItemManager extends AbstractItemManager {
Optional<CustomCropsBlockState> optionalState = world.getBlockState(pos3);
if (optionalState.isPresent()) {
CustomCropsBlockState customCropsBlockState = optionalState.get();
String anyID = anyID(location);
System.out.println(anyID);
if (!customCropsBlockState.type().isBlockInstance(anyID)) {
String anyFurnitureID = furnitureID(location);
if (anyFurnitureID != null) {
if (!customCropsBlockState.type().isBlockInstance(anyFurnitureID)) {
world.removeBlockState(pos3);
plugin.debug("[" + location.getWorld().getName() + "] Removed inconsistent block data at " + pos3 + " which used to be " + customCropsBlockState);
} else {
event.setCancelled(true);
return;
}
}
String anyBlockID = blockID(location);
if (!customCropsBlockState.type().isBlockInstance(anyBlockID)) {
world.removeBlockState(pos3);
plugin.debug("[" + location.getWorld().getName() + "] Removed inconsistent block data at " + pos3 + " which used to be " + customCropsBlockState);
} else {