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");
|
plugin.getPluginLogger().warn("`plant` action is not executed due to crop[" + key + "] not exists");
|
||||||
return;
|
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);
|
Location potLocation = cropLocation.clone().subtract(0,1,0);
|
||||||
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(cropLocation.getWorld());
|
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(cropLocation.getWorld());
|
||||||
if (optionalWorld.isEmpty()) {
|
if (optionalWorld.isEmpty()) {
|
||||||
@@ -86,6 +86,7 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
|
|||||||
CustomCropsBlockState potState = potBlock.fixOrGetState(world, potPos3, potConfig, potItemID);
|
CustomCropsBlockState potState = potBlock.fixOrGetState(world, potPos3, potConfig, potItemID);
|
||||||
if (potState == null) {
|
if (potState == null) {
|
||||||
plugin.debug(() -> "Pot doesn't exist below the crop when executing `plant` action at location[" + world.worldName() + "," + potPos3 + "]");
|
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();
|
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.mechanic.sprinkler.SprinklerConfig;
|
||||||
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
||||||
import net.momirealms.customcrops.api.core.world.CustomCropsWorld;
|
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.core.world.Pos3;
|
||||||
import net.momirealms.customcrops.api.event.BoneMealDispenseEvent;
|
import net.momirealms.customcrops.api.event.BoneMealDispenseEvent;
|
||||||
import net.momirealms.customcrops.api.util.EventUtils;
|
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.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public abstract class AbstractCustomEventListener implements Listener {
|
public abstract class AbstractCustomEventListener implements Listener {
|
||||||
private final HashSet<EntityType> entities = new HashSet<>();
|
private final HashSet<EntityType> entities = new HashSet<>();
|
||||||
private final HashSet<Material> blocks = new HashSet<>();
|
private final HashSet<Material> blocks = new HashSet<>();
|
||||||
|
private final ExplosionIndicator explosionIndicator;
|
||||||
|
|
||||||
protected Set<Material> ignoredMaterials() {
|
protected Set<Material> ignoredMaterials() {
|
||||||
return blocks;
|
return blocks;
|
||||||
@@ -88,6 +91,17 @@ public abstract class AbstractCustomEventListener implements Listener {
|
|||||||
if (VersionHelper.isVersionNewerThan1_20()) {
|
if (VersionHelper.isVersionNewerThan1_20()) {
|
||||||
this.blocks.add(Material.CHERRY_LEAVES);
|
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
|
@EventHandler
|
||||||
@@ -315,6 +329,9 @@ public abstract class AbstractCustomEventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onExplosion(EntityExplodeEvent event) {
|
public void onExplosion(EntityExplodeEvent event) {
|
||||||
|
if (!this.explosionIndicator.canDestroyBlocks(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
for (Block block : event.blockList()) {
|
for (Block block : event.blockList()) {
|
||||||
this.itemManager.handleEntityExplode(entity, block.getLocation(), this.itemManager.blockID(block), event);
|
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 org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -46,6 +47,8 @@ public interface CropConfig {
|
|||||||
*/
|
*/
|
||||||
String seed();
|
String seed();
|
||||||
|
|
||||||
|
List<String> seeds();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the maximum growth points for this crop.
|
* Gets the maximum growth points for this crop.
|
||||||
*
|
*
|
||||||
@@ -247,7 +250,7 @@ public interface CropConfig {
|
|||||||
* @param seed The seed item ID.
|
* @param seed The seed item ID.
|
||||||
* @return The builder instance for chaining.
|
* @return The builder instance for chaining.
|
||||||
*/
|
*/
|
||||||
Builder seed(String seed);
|
Builder seed(List<String> seed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the maximum growth points for this crop.
|
* Sets the maximum growth points for this crop.
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import java.util.*;
|
|||||||
public class CropConfigImpl implements CropConfig {
|
public class CropConfigImpl implements CropConfig {
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String seed;
|
private final List<String> seed;
|
||||||
private final int maxPoints;
|
private final int maxPoints;
|
||||||
private final Action<Player>[] wrongPotActions;
|
private final Action<Player>[] wrongPotActions;
|
||||||
private final Action<Player>[] interactActions;
|
private final Action<Player>[] interactActions;
|
||||||
@@ -55,7 +55,7 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
|
|
||||||
public CropConfigImpl(
|
public CropConfigImpl(
|
||||||
String id,
|
String id,
|
||||||
String seed,
|
List<String> seed,
|
||||||
int maxPoints,
|
int maxPoints,
|
||||||
Action<Player>[] wrongPotActions,
|
Action<Player>[] wrongPotActions,
|
||||||
Action<Player>[] interactActions,
|
Action<Player>[] interactActions,
|
||||||
@@ -125,7 +125,12 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String seed() {
|
public String seed() {
|
||||||
return seed;
|
return this.seed.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> seeds() {
|
||||||
|
return this.seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -246,7 +251,7 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
|
|
||||||
public static class BuilderImpl implements Builder {
|
public static class BuilderImpl implements Builder {
|
||||||
private String id;
|
private String id;
|
||||||
private String seed;
|
private List<String> seed;
|
||||||
private ExistenceForm existenceForm;
|
private ExistenceForm existenceForm;
|
||||||
private int maxPoints;
|
private int maxPoints;
|
||||||
private Action<Player>[] wrongPotActions;
|
private Action<Player>[] wrongPotActions;
|
||||||
@@ -279,7 +284,7 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder seed(String seed) {
|
public Builder seed(List<String> seed) {
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
return this;
|
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() {
|
public static boolean isVersionNewerThan1_18() {
|
||||||
return version >= 18;
|
return version >= 18f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVersionNewerThan1_19() {
|
public static boolean isVersionNewerThan1_19() {
|
||||||
return version >= 19;
|
return version >= 19f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVersionNewerThan1_19_4() {
|
public static boolean isVersionNewerThan1_19_4() {
|
||||||
return version >= 19.39;
|
return version >= 19.39f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVersionNewerThan1_20() {
|
public static boolean isVersionNewerThan1_20() {
|
||||||
return version >= 20;
|
return version >= 20f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVersionNewerThan1_21_4() {
|
public static boolean isVersionNewerThan1_21_4() {
|
||||||
return version >= 21.39;
|
return version >= 21.39f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVersionNewerThan1_21_2() {
|
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() {
|
public static boolean isFolia() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Project settings
|
# Project settings
|
||||||
# Rule: [major update].[feature update].[bug fix]
|
# Rule: [major update].[feature update].[bug fix]
|
||||||
project_version=3.6.38
|
project_version=3.6.39
|
||||||
config_version=42
|
config_version=42
|
||||||
project_group=net.momirealms
|
project_group=net.momirealms
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ tasks {
|
|||||||
from(zipTree(project(":compatibility-itemsadder-r2").tasks.jar.get().archiveFile))
|
from(zipTree(project(":compatibility-itemsadder-r2").tasks.jar.get().archiveFile))
|
||||||
from(zipTree(project(":compatibility-crucible-r1").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(":compatibility-craftengine-r1").tasks.jar.get().archiveFile))
|
||||||
|
from(zipTree(project(":plugin:j21").tasks.jar.get().archiveFile))
|
||||||
archiveFileName = "CustomCrops-${rootProject.properties["project_version"]}.jar"
|
archiveFileName = "CustomCrops-${rootProject.properties["project_version"]}.jar"
|
||||||
destinationDirectory.set(file("$rootDir/target"))
|
destinationDirectory.set(file("$rootDir/target"))
|
||||||
relocate("net.kyori", "net.momirealms.customcrops.libraries")
|
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
|
@Override
|
||||||
public void registerCropConfig(CropConfig config) {
|
public void registerCropConfig(CropConfig config) {
|
||||||
Registries.CROP.register(config.id(), config);
|
Registries.CROP.register(config.id(), config);
|
||||||
Registries.SEED_TO_CROP.register(config.seed(), config);
|
for (String seed : config.seeds()) {
|
||||||
Registries.ITEMS.register(config.seed(), BuiltInItemMechanics.SEED.mechanic());
|
Registries.SEED_TO_CROP.register(seed, config);
|
||||||
|
Registries.ITEMS.register(seed, BuiltInItemMechanics.SEED.mechanic());
|
||||||
|
}
|
||||||
for (DeathCondition condition : config.deathConditions()) {
|
for (DeathCondition condition : config.deathConditions()) {
|
||||||
String deadStage = condition.deathStage();
|
String deadStage = condition.deathStage();
|
||||||
if (deadStage != null) {
|
if (deadStage != null) {
|
||||||
|
|||||||
@@ -41,10 +41,7 @@ import net.momirealms.customcrops.common.util.Pair;
|
|||||||
import net.momirealms.customcrops.common.util.TriFunction;
|
import net.momirealms.customcrops.common.util.TriFunction;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration types for various mechanics.
|
* Configuration types for various mechanics.
|
||||||
@@ -206,7 +203,7 @@ public class ConfigType {
|
|||||||
|
|
||||||
CropConfig config = CropConfig.builder()
|
CropConfig config = CropConfig.builder()
|
||||||
.id(id)
|
.id(id)
|
||||||
.seed(section.getString("seed"))
|
.seed(getAsStringList(section.get("seed")))
|
||||||
.rotation(section.getBoolean("random-rotation", false))
|
.rotation(section.getBoolean("random-rotation", false))
|
||||||
.maxPoints(section.getInt("max-points", 1))
|
.maxPoints(section.getInt("max-points", 1))
|
||||||
.ignoreRandomTick(section.getBoolean("ignore-random-tick", false))
|
.ignoreRandomTick(section.getBoolean("ignore-random-tick", false))
|
||||||
@@ -336,4 +333,20 @@ public class ConfigType {
|
|||||||
public boolean parse(ConfigManager manager, String id, Section section) {
|
public boolean parse(ConfigManager manager, String id, Section section) {
|
||||||
return argumentConsumer.apply(manager, id, 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;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
public class BukkitItemManager extends AbstractItemManager {
|
public class BukkitItemManager extends AbstractItemManager {
|
||||||
|
|
||||||
private final BukkitCustomCropsPlugin plugin;
|
private final BukkitCustomCropsPlugin plugin;
|
||||||
private CustomItemProvider provider;
|
private CustomItemProvider provider;
|
||||||
private AbstractCustomEventListener eventListener;
|
private AbstractCustomEventListener eventListener;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
rootProject.name = "CustomCrops"
|
rootProject.name = "CustomCrops"
|
||||||
include(":api")
|
include(":api")
|
||||||
include(":plugin")
|
include(":plugin")
|
||||||
|
include(":plugin:j21")
|
||||||
include(":compatibility")
|
include(":compatibility")
|
||||||
include(":compatibility-asp-r1")
|
include(":compatibility-asp-r1")
|
||||||
//include(":compatibility-asp-r2")
|
//include(":compatibility-asp-r2")
|
||||||
|
|||||||
Reference in New Issue
Block a user