mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-19 15:09:25 +00:00
3.6.39
This commit is contained in:
@@ -72,7 +72,7 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
|
||||
plugin.getPluginLogger().warn("`plant` action is not executed due to crop[" + key + "] not exists");
|
||||
return;
|
||||
}
|
||||
Location cropLocation = requireNonNull(context.arg(ContextKeys.LOCATION)).clone().add(0,y,0);
|
||||
Location cropLocation = requireNonNull(context.arg(ContextKeys.LOCATION)).clone().add(0, y, 0);
|
||||
Location potLocation = cropLocation.clone().subtract(0,1,0);
|
||||
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(cropLocation.getWorld());
|
||||
if (optionalWorld.isEmpty()) {
|
||||
@@ -86,6 +86,7 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
|
||||
CustomCropsBlockState potState = potBlock.fixOrGetState(world, potPos3, potConfig, potItemID);
|
||||
if (potState == null) {
|
||||
plugin.debug(() -> "Pot doesn't exist below the crop when executing `plant` action at location[" + world.worldName() + "," + potPos3 + "]");
|
||||
return;
|
||||
}
|
||||
|
||||
CropBlock cropBlock = (CropBlock) BuiltInBlockMechanics.CROP.mechanic();
|
||||
|
||||
@@ -28,6 +28,7 @@ import net.momirealms.customcrops.api.core.mechanic.pot.PotConfig;
|
||||
import net.momirealms.customcrops.api.core.mechanic.sprinkler.SprinklerConfig;
|
||||
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
||||
import net.momirealms.customcrops.api.core.world.CustomCropsWorld;
|
||||
import net.momirealms.customcrops.api.core.world.ExplosionIndicator;
|
||||
import net.momirealms.customcrops.api.core.world.Pos3;
|
||||
import net.momirealms.customcrops.api.event.BoneMealDispenseEvent;
|
||||
import net.momirealms.customcrops.api.util.EventUtils;
|
||||
@@ -54,11 +55,13 @@ import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractCustomEventListener implements Listener {
|
||||
private final HashSet<EntityType> entities = new HashSet<>();
|
||||
private final HashSet<Material> blocks = new HashSet<>();
|
||||
private final ExplosionIndicator explosionIndicator;
|
||||
|
||||
protected Set<Material> ignoredMaterials() {
|
||||
return blocks;
|
||||
@@ -88,6 +91,17 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
if (VersionHelper.isVersionNewerThan1_20()) {
|
||||
this.blocks.add(Material.CHERRY_LEAVES);
|
||||
}
|
||||
if (!VersionHelper.isVersionNewerThan1_21()) {
|
||||
this.explosionIndicator = new ExplosionIndicator.AlwaysTrue();
|
||||
} else {
|
||||
try {
|
||||
Class<?> clazz = Class.forName("net.momirealms.customcrops.bukkit.j21.ModernExplosionIndicator");
|
||||
Constructor<?> constructor = clazz.getConstructor();
|
||||
this.explosionIndicator = (ExplosionIndicator) constructor.newInstance();
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Failed to init ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -315,6 +329,9 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
|
||||
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onExplosion(EntityExplodeEvent event) {
|
||||
if (!this.explosionIndicator.canDestroyBlocks(event)) {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
for (Block block : event.blockList()) {
|
||||
this.itemManager.handleEntityExplode(entity, block.getLocation(), this.itemManager.blockID(block), event);
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -46,6 +47,8 @@ public interface CropConfig {
|
||||
*/
|
||||
String seed();
|
||||
|
||||
List<String> seeds();
|
||||
|
||||
/**
|
||||
* Gets the maximum growth points for this crop.
|
||||
*
|
||||
@@ -247,7 +250,7 @@ public interface CropConfig {
|
||||
* @param seed The seed item ID.
|
||||
* @return The builder instance for chaining.
|
||||
*/
|
||||
Builder seed(String seed);
|
||||
Builder seed(List<String> seed);
|
||||
|
||||
/**
|
||||
* Sets the maximum growth points for this crop.
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.*;
|
||||
public class CropConfigImpl implements CropConfig {
|
||||
|
||||
private final String id;
|
||||
private final String seed;
|
||||
private final List<String> seed;
|
||||
private final int maxPoints;
|
||||
private final Action<Player>[] wrongPotActions;
|
||||
private final Action<Player>[] interactActions;
|
||||
@@ -55,7 +55,7 @@ public class CropConfigImpl implements CropConfig {
|
||||
|
||||
public CropConfigImpl(
|
||||
String id,
|
||||
String seed,
|
||||
List<String> seed,
|
||||
int maxPoints,
|
||||
Action<Player>[] wrongPotActions,
|
||||
Action<Player>[] interactActions,
|
||||
@@ -125,7 +125,12 @@ public class CropConfigImpl implements CropConfig {
|
||||
|
||||
@Override
|
||||
public String seed() {
|
||||
return seed;
|
||||
return this.seed.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> seeds() {
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -246,7 +251,7 @@ public class CropConfigImpl implements CropConfig {
|
||||
|
||||
public static class BuilderImpl implements Builder {
|
||||
private String id;
|
||||
private String seed;
|
||||
private List<String> seed;
|
||||
private ExistenceForm existenceForm;
|
||||
private int maxPoints;
|
||||
private Action<Player>[] wrongPotActions;
|
||||
@@ -279,7 +284,7 @@ public class CropConfigImpl implements CropConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder seed(String seed) {
|
||||
public Builder seed(List<String> seed) {
|
||||
this.seed = seed;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.momirealms.customcrops.api.core.world;
|
||||
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public interface ExplosionIndicator {
|
||||
|
||||
boolean canDestroyBlocks(EntityExplodeEvent event);
|
||||
|
||||
class AlwaysTrue implements ExplosionIndicator {
|
||||
@Override
|
||||
public boolean canDestroyBlocks(EntityExplodeEvent event) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,27 +87,31 @@ public class VersionHelper {
|
||||
}
|
||||
|
||||
public static boolean isVersionNewerThan1_18() {
|
||||
return version >= 18;
|
||||
return version >= 18f;
|
||||
}
|
||||
|
||||
public static boolean isVersionNewerThan1_19() {
|
||||
return version >= 19;
|
||||
return version >= 19f;
|
||||
}
|
||||
|
||||
public static boolean isVersionNewerThan1_19_4() {
|
||||
return version >= 19.39;
|
||||
return version >= 19.39f;
|
||||
}
|
||||
|
||||
public static boolean isVersionNewerThan1_20() {
|
||||
return version >= 20;
|
||||
return version >= 20f;
|
||||
}
|
||||
|
||||
public static boolean isVersionNewerThan1_21_4() {
|
||||
return version >= 21.39;
|
||||
return version >= 21.39f;
|
||||
}
|
||||
|
||||
public static boolean isVersionNewerThan1_21_2() {
|
||||
return version >= 19;
|
||||
return version >= 21.19f;
|
||||
}
|
||||
|
||||
public static boolean isVersionNewerThan1_21() {
|
||||
return version >= 21f;
|
||||
}
|
||||
|
||||
public static boolean isFolia() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=3.6.38
|
||||
project_version=3.6.39
|
||||
config_version=42
|
||||
project_group=net.momirealms
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ tasks {
|
||||
from(zipTree(project(":compatibility-itemsadder-r2").tasks.jar.get().archiveFile))
|
||||
from(zipTree(project(":compatibility-crucible-r1").tasks.jar.get().archiveFile))
|
||||
from(zipTree(project(":compatibility-craftengine-r1").tasks.jar.get().archiveFile))
|
||||
from(zipTree(project(":plugin:j21").tasks.jar.get().archiveFile))
|
||||
archiveFileName = "CustomCrops-${rootProject.properties["project_version"]}.jar"
|
||||
destinationDirectory.set(file("$rootDir/target"))
|
||||
relocate("net.kyori", "net.momirealms.customcrops.libraries")
|
||||
|
||||
23
plugin/j21/build.gradle.kts
Normal file
23
plugin/j21/build.gradle.kts
Normal file
@@ -0,0 +1,23 @@
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":api"))
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(21)
|
||||
dependsOn(tasks.clean)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.momirealms.customcrops.bukkit.j21;
|
||||
|
||||
import net.momirealms.customcrops.api.core.world.ExplosionIndicator;
|
||||
import org.bukkit.ExplosionResult;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class ModernExplosionIndicator implements ExplosionIndicator {
|
||||
|
||||
public ModernExplosionIndicator() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDestroyBlocks(EntityExplodeEvent event) {
|
||||
return event.getExplosionResult() == ExplosionResult.DESTROY || event.getExplosionResult() == ExplosionResult.DESTROY_WITH_DECAY;
|
||||
}
|
||||
}
|
||||
@@ -294,8 +294,10 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
@Override
|
||||
public void registerCropConfig(CropConfig config) {
|
||||
Registries.CROP.register(config.id(), config);
|
||||
Registries.SEED_TO_CROP.register(config.seed(), config);
|
||||
Registries.ITEMS.register(config.seed(), BuiltInItemMechanics.SEED.mechanic());
|
||||
for (String seed : config.seeds()) {
|
||||
Registries.SEED_TO_CROP.register(seed, config);
|
||||
Registries.ITEMS.register(seed, BuiltInItemMechanics.SEED.mechanic());
|
||||
}
|
||||
for (DeathCondition condition : config.deathConditions()) {
|
||||
String deadStage = condition.deathStage();
|
||||
if (deadStage != null) {
|
||||
|
||||
@@ -41,10 +41,7 @@ import net.momirealms.customcrops.common.util.Pair;
|
||||
import net.momirealms.customcrops.common.util.TriFunction;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Configuration types for various mechanics.
|
||||
@@ -206,7 +203,7 @@ public class ConfigType {
|
||||
|
||||
CropConfig config = CropConfig.builder()
|
||||
.id(id)
|
||||
.seed(section.getString("seed"))
|
||||
.seed(getAsStringList(section.get("seed")))
|
||||
.rotation(section.getBoolean("random-rotation", false))
|
||||
.maxPoints(section.getInt("max-points", 1))
|
||||
.ignoreRandomTick(section.getBoolean("ignore-random-tick", false))
|
||||
@@ -336,4 +333,20 @@ public class ConfigType {
|
||||
public boolean parse(ConfigManager manager, String id, Section section) {
|
||||
return argumentConsumer.apply(manager, id, section);
|
||||
}
|
||||
|
||||
private static List<String> getAsStringList(Object o) {
|
||||
List<String> list = new ArrayList<>();
|
||||
if (o instanceof List<?>) {
|
||||
for (Object object : (List<?>) o) {
|
||||
list.add(object.toString());
|
||||
}
|
||||
} else if (o instanceof String) {
|
||||
list.add((String) o);
|
||||
} else {
|
||||
if (o != null) {
|
||||
list.add(o.toString());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@ import java.util.*;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class BukkitItemManager extends AbstractItemManager {
|
||||
|
||||
private final BukkitCustomCropsPlugin plugin;
|
||||
private CustomItemProvider provider;
|
||||
private AbstractCustomEventListener eventListener;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
rootProject.name = "CustomCrops"
|
||||
include(":api")
|
||||
include(":plugin")
|
||||
include(":plugin:j21")
|
||||
include(":compatibility")
|
||||
include(":compatibility-asp-r1")
|
||||
//include(":compatibility-asp-r2")
|
||||
|
||||
Reference in New Issue
Block a user