9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-28 03:19:15 +00:00

more blocks should be supported

This commit is contained in:
XiaoMoMi
2024-09-05 02:19:21 +08:00
parent 577cd7cb10
commit 660e1d26da
4 changed files with 27 additions and 20 deletions

View File

@@ -114,7 +114,11 @@ public abstract class AbstractCustomEventListener implements Listener {
return;
}
ItemStack itemStack = event.getItem();
if (itemStack != null && itemStack.getType() == Material.BONE_MEAL && ConfigManager.overriddenCrops().contains(type)) {
// Paper API
// prevents player from using bone meals
if (itemStack != null && itemStack.getType() == Material.BONE_MEAL
&& ConfigManager.overriddenCrops().contains(type)
&& ConfigManager.VANILLA_CROPS.contains(type)) {
event.setUseItemInHand(Event.Result.DENY);
}
this.itemManager.handlePlayerInteractBlock(

View File

@@ -26,6 +26,7 @@ import net.momirealms.customcrops.api.misc.water.FillMethod;
import net.momirealms.customcrops.api.misc.water.WateringMethod;
import net.momirealms.customcrops.api.util.PluginUtils;
import net.momirealms.customcrops.common.config.ConfigLoader;
import net.momirealms.customcrops.common.helper.VersionHelper;
import net.momirealms.customcrops.common.plugin.feature.Reloadable;
import net.momirealms.customcrops.common.util.Pair;
import org.bukkit.Material;
@@ -39,6 +40,23 @@ import java.util.*;
public abstract class ConfigManager implements ConfigLoader, Reloadable {
public static final Set<Material> VANILLA_CROPS;
static {
HashSet<Material> set = new HashSet<>(
List.of(Material.WHEAT, Material.CARROTS, Material.POTATOES, Material.BEETROOTS, Material.SWEET_BERRY_BUSH,
Material.MELON_STEM, Material.PUMPKIN_STEM)
);
if (VersionHelper.isVersionNewerThan1_19_4()) {
set.add(Material.TORCHFLOWER_CROP);
}
if (VersionHelper.isVersionNewerThan1_20()) {
set.add(Material.PITCHER_CROP);
}
VANILLA_CROPS = Collections.unmodifiableSet(set);
}
private static ConfigManager instance;
protected final BukkitCustomCropsPlugin plugin;

View File

@@ -38,7 +38,6 @@ import net.momirealms.customcrops.api.core.mechanic.pot.PotConfig;
import net.momirealms.customcrops.api.core.mechanic.sprinkler.SprinklerConfig;
import net.momirealms.customcrops.api.core.mechanic.wateringcan.WateringCanConfig;
import net.momirealms.customcrops.common.helper.AdventureHelper;
import net.momirealms.customcrops.common.helper.VersionHelper;
import net.momirealms.customcrops.common.locale.TranslationManager;
import net.momirealms.customcrops.common.plugin.CustomCropsProperties;
import net.momirealms.customcrops.common.util.ListUtils;
@@ -52,10 +51,6 @@ import java.util.*;
public class BukkitConfigManager extends ConfigManager {
private static final Set<Material> VANILLA_CROPS = new HashSet<>(
List.of(Material.WHEAT, Material.CARROTS, Material.POTATOES, Material.BEETROOTS, Material.SWEET_BERRY_BUSH,
Material.MELON_STEM, Material.PUMPKIN_STEM)
);
private static YamlDocument MAIN_CONFIG;
public static YamlDocument getMainConfig() {
return MAIN_CONFIG;
@@ -63,12 +58,6 @@ public class BukkitConfigManager extends ConfigManager {
public BukkitConfigManager(BukkitCustomCropsPlugin plugin) {
super(plugin);
if (VersionHelper.isVersionNewerThan1_19_4()) {
VANILLA_CROPS.add(Material.TORCHFLOWER_CROP);
}
if (VersionHelper.isVersionNewerThan1_20()) {
VANILLA_CROPS.add(Material.PITCHER_CROP);
}
}
@Override
@@ -168,7 +157,7 @@ public class BukkitConfigManager extends ConfigManager {
}
overriddenCrops.clear();
overriddenCrops.addAll(config.getStringList("mechanics.override-vanilla-crops")
overriddenCrops.addAll(config.getStringList("mechanics.override-vanilla-blocks")
.stream()
.map(it -> {
try {
@@ -180,11 +169,7 @@ public class BukkitConfigManager extends ConfigManager {
})
.filter(it -> {
if (it == Material.AIR) return false;
boolean allow = VANILLA_CROPS.contains(it);
if (!allow) {
plugin.getPluginLogger().warn(it.name() + " is not a supported vanilla crop type");
}
return allow;
return it.isBlock();
})
.toList());
}

View File

@@ -125,8 +125,8 @@ mechanics:
# Set hologram offset correction for other blocks
hologram-offset-correction:
"{0}crop_stage_death": 0
# Set the crop types that would be overridden
override-vanilla-crops: []
# Set the block types that would be overridden
override-vanilla-blocks: []
other-settings:
# It's recommended to use MiniMessage format. If you insist on using legacy color code "&", enable the support below.
# Disable this would improve performance