9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-28 11:29:19 +00:00
This commit is contained in:
XiaoMoMi
2023-06-26 00:54:31 +08:00
parent 1856dc75b1
commit a7dbe913bc
33 changed files with 304 additions and 196 deletions

View File

@@ -4,20 +4,19 @@ plugins {
}
group = 'net.momirealms'
version = '3.2.5.0-beta'
version = '3.2.5.0'
repositories {
mavenCentral()
maven {name = "enginehub repo"; url = "https://maven.enginehub.org/repo/"}
maven {name = "aliyun repo"; url = "https://maven.aliyun.com/repository/public/"}
maven {name = 'papermc repo'; url = 'https://papermc.io/repo/repository/maven-public/'}
maven {name = 'sonatype'; url = 'https://oss.sonatype.org/content/groups/public/'}
maven {name = "dmulloy2 repo"; url = "https://repo.dmulloy2.net/repository/public/"}
maven {name = "clip repo"; url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'}
maven {name = "codemc repo"; url = "https://repo.codemc.org/repository/maven-public/"}
maven {name = "enginehub repo"; url = "https://maven.enginehub.org/repo/"}
maven {name = "Lumine repo"; url = "https://mvn.lumine.io/repository/maven-public"}
maven {name = "jitpack repo"; url = "https://jitpack.io"}
maven {name = 'glaremasters repo'; url = 'https://repo.glaremasters.me/repository/towny/'}
maven {name = 'bg-software repo'; url = 'https://repo.bg-software.com/repository/api/'}
maven {name = 'aswm repo'; url = 'https://repo.infernalsuite.com/repository/maven-snapshots/' }
maven {name = 'aswm repo'; url = 'https://repo.rapture.pw/repository/maven-releases/' }
@@ -25,20 +24,19 @@ repositories {
}
dependencies {
compileOnly ('dev.dejvokep:boosted-yaml:1.3')
compileOnly ('dev.dejvokep:boosted-yaml:1.3.1')
compileOnly ('commons-io:commons-io:2.11.0')
compileOnly ('dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT')
compileOnly ('io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT')
compileOnly ('io.papermc.paper:paper-api:1.20-R0.1-SNAPSHOT')
compileOnly ('me.clip:placeholderapi:2.11.3')
compileOnly ('com.github.LoneDev6:api-itemsadder:3.4.1e')
compileOnly ('io.lumine:Mythic-Dist:5.0.3-SNAPSHOT')
//compileOnly ('com.willfp:EcoSkills:3.0.0-b2') No read access
compileOnly ('com.willfp:eco:6.60.0')
compileOnly ('com.willfp:EcoJobs:3.13.0')
compileOnly ('net.objecthunter:exp4j:0.4.8')
compileOnly ('io.lumine:Mythic-Dist:5.2.1')
compileOnly ('com.infernalsuite.aswm:api:1.19.4-R0.1-SNAPSHOT')
compileOnly ('net.Indyuce:MMOItems-API:6.9.2-SNAPSHOT')
compileOnly ('com.google.code.gson:gson:2.10.1')
compileOnly fileTree (dir:'libs',includes:['*.jar'])
implementation ('net.kyori:adventure-api:4.14.0')
implementation ('net.kyori:adventure-platform-bukkit:4.3.0')
@@ -62,12 +60,12 @@ tasks.withType(JavaCompile).configureEach {
}
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 ('org.apache.commons.pool2', 'net.momirealms.customcrops.libs.org.apache.commons.pool2')
relocate ('net.momirealms.biomeapi', 'net.momirealms.customcrops.libs.net.momirealms.biomeapi')
relocate ('net.momirealms.protectionlib', 'net.momirealms.customcrops.libs.net.momirealms.protectionlib')
relocate ('de.tr7zw', 'net.momirealms.customcrops.libraries.tr7zw')
relocate ('net.kyori', 'net.momirealms.customcrops.libraries.kyori')
relocate ('org.bstats', 'net.momirealms.customcrops.libraries.bstats')
relocate ('org.apache.commons.pool2', 'net.momirealms.customcrops.libraries.commons.pool2')
relocate ('net.momirealms.biomeapi', 'net.momirealms.customcrops.libraries.biomeapi')
relocate ('net.momirealms.protectionlib', 'net.momirealms.customcrops.libraries.protectionlib')
}
tasks.register("delete", Delete).get().delete("build/libs/"+project.name+"-"+project.version+".jar")

Binary file not shown.

Binary file not shown.

View File

@@ -177,7 +177,7 @@ public final class CustomCrops extends JavaPlugin {
private void loadLibs() {
TimeZone timeZone = TimeZone.getDefault();
String libRepo = timeZone.getID().startsWith("Asia") ? "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/";
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3", libRepo);
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3.1", libRepo);
LibraryLoader.load("commons-io","commons-io","2.11.0", libRepo);
LibraryLoader.load("net.objecthunter","exp4j","0.4.8", libRepo);
}

View File

@@ -179,8 +179,11 @@ public interface PlatformInterface {
* @param location location
*/
default void removeCustomItemAt(Location location) {
removeCustomBlock(location);
removeAnyBlock(location);
removeItemFrame(location);
if (CustomCrops.getInstance().getVersionHelper().isVersionNewerThan1_19_R3()) {
removeItemDisplay(location);
}
}
/**
@@ -262,7 +265,7 @@ public interface PlatformInterface {
*/
@Nullable
default ItemDisplay getItemDisplayAt(Location location) {
Collection<ItemDisplay> itemDisplays = location.clone().add(0.5,0.25,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.4, 0.5, 0.4);
Collection<ItemDisplay> itemDisplays = location.clone().add(0.5,0,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.4, 0.5, 0.4);
int i = itemDisplays.size();
int j = 1;
for (ItemDisplay itemDisplay : itemDisplays) {

View File

@@ -751,7 +751,7 @@ public class PlatformManager extends Function {
switch (cropConfig.getCropMode()) {
case ITEM_DISPLAY -> {
ItemDisplay itemDisplay = CustomCrops.getInstance().getPlatformInterface().placeItemDisplay(crop_loc, cropPlantEvent.getCropModel());
if (itemDisplay != null && cropConfig.isRotationEnabled()) itemDisplay.setRotation(RotationUtils.getRandomFloatRotation(), 0);
if (itemDisplay != null && cropConfig.isRotationEnabled()) itemDisplay.setRotation(RotationUtils.getRandomFloatRotation(), itemDisplay.getLocation().getPitch());
}
case ITEM_FRAME -> {
ItemFrame itemFrame = CustomCrops.getInstance().getPlatformInterface().placeItemFrame(crop_loc, cropPlantEvent.getCropModel());

View File

@@ -27,7 +27,7 @@ public class SeasonChangeEvent extends WorldEvent {
return getHandlerList();
}
public CCSeason getCcSeason() {
public CCSeason getCCSeason() {
return ccSeason;
}
}

View File

@@ -34,7 +34,13 @@ public class BoneMeal {
private final Sound sound;
private final Particle particle;
public BoneMeal(String item, @Nullable String returned, @NotNull ArrayList<Pair<Double, Integer>> pairs, @Nullable Sound sound, @Nullable Particle particle) {
public BoneMeal(
String item,
@Nullable String returned,
@NotNull ArrayList<Pair<Double, Integer>> pairs,
@Nullable Sound sound,
@Nullable Particle particle
) {
this.item = item;
this.returned = returned;
this.pairs = pairs;

View File

@@ -43,18 +43,19 @@ public class CropConfig {
private final Action[] plantActions;
private final boolean rotation;
public CropConfig(String key,
ItemMode itemMode,
int max_points,
String[] bottom_blocks,
Requirement[] plantRequirements,
Requirement[] breakRequirements,
DeathCondition[] deathConditions,
Condition[] growConditions,
HashMap<Integer, StageConfig> stageMap,
BoneMeal[] boneMeals,
Action[] plantActions,
boolean rotation
public CropConfig(
String key,
ItemMode itemMode,
int max_points,
String[] bottom_blocks,
Requirement[] plantRequirements,
Requirement[] breakRequirements,
DeathCondition[] deathConditions,
Condition[] growConditions,
HashMap<Integer, StageConfig> stageMap,
BoneMeal[] boneMeals,
Action[] plantActions,
boolean rotation
) {
this.key = key;
this.itemMode = itemMode;

View File

@@ -35,7 +35,18 @@ public abstract class FertilizerConfig {
private final String icon;
private final Requirement[] requirements;
public FertilizerConfig(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, @Nullable String icon, Requirement[] requirements) {
public FertilizerConfig(
String key,
FertilizerType fertilizerType,
int times,
double chance,
@Nullable String[] pot_whitelist,
boolean beforePlant,
@Nullable Particle particle,
@Nullable Sound sound,
@Nullable String icon,
Requirement[] requirements
) {
this.times = times;
this.chance = chance;
this.key = key;

View File

@@ -18,7 +18,9 @@
package net.momirealms.customcrops.api.object.fertilizer;
import net.kyori.adventure.sound.Sound;
import net.momirealms.customcrops.api.object.basic.ConfigManager;
import net.momirealms.customcrops.api.object.requirement.Requirement;
import net.momirealms.customcrops.api.util.AdventureUtils;
import org.bukkit.Particle;
import org.jetbrains.annotations.Nullable;
@@ -26,10 +28,24 @@ public class Quality extends FertilizerConfig {
private final double[] ratio;
public Quality(String key, FertilizerType fertilizerType, int times, double chance, double[] ratio,
@Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, @Nullable String icon, Requirement[] requirements) {
public Quality(
String key,
FertilizerType fertilizerType,
int times,
double chance,
double[] ratio,
@Nullable String[] pot_whitelist,
boolean beforePlant,
@Nullable Particle particle,
@Nullable Sound sound,
@Nullable String icon,
Requirement[] requirements
) {
super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon, requirements);
this.ratio = ratio;
if (this.ratio.length != ConfigManager.defaultRatio.length) {
AdventureUtils.consoleMessage("<red>[CustomCrops] Wrong format found at fertilizer: " + key + ". You should make sure that all the quality ratio are in the same format. For example when you set default-ratio to x/x/x/x/x in config.yml. You should set ratio to x/x/x/x/x in fertilizers to work");
}
}
public double[] getRatio() {

View File

@@ -24,8 +24,18 @@ import org.jetbrains.annotations.Nullable;
public class SoilRetain extends FertilizerConfig {
public SoilRetain(String key, FertilizerType fertilizerType, int times, double chance,
@Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, String icon, Requirement[] requirements) {
public SoilRetain(
String key,
FertilizerType fertilizerType,
int times,
double chance,
@Nullable String[] pot_whitelist,
boolean beforePlant,
@Nullable Particle particle,
@Nullable Sound sound,
String icon,
Requirement[] requirements
) {
super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon, requirements);
}
}

View File

@@ -29,8 +29,18 @@ public class SpeedGrow extends FertilizerConfig {
private final List<Pair<Double, Integer>> pairs;
public SpeedGrow(String key, FertilizerType fertilizerType, int times, List<Pair<Double, Integer>> pairs,
@Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, String icon, Requirement[] requirements) {
public SpeedGrow(
String key,
FertilizerType fertilizerType,
int times,
List<Pair<Double, Integer>> pairs,
@Nullable String[] pot_whitelist,
boolean beforePlant,
@Nullable Particle particle,
@Nullable Sound sound,
String icon,
Requirement[] requirements
) {
super(key, fertilizerType, times, 1, pot_whitelist, beforePlant, particle, sound, icon, requirements);
this.pairs = pairs;
}

View File

@@ -24,9 +24,18 @@ import org.jetbrains.annotations.Nullable;
public class Variation extends FertilizerConfig {
public Variation(String key, FertilizerType fertilizerType, int times, double chance,
@Nullable String[] pot_whitelist, boolean beforePlant,
@Nullable Particle particle, @Nullable Sound sound, String icon, Requirement[] requirements) {
public Variation(
String key,
FertilizerType fertilizerType,
int times,
double chance,
@Nullable String[] pot_whitelist,
boolean beforePlant,
@Nullable Particle particle,
@Nullable Sound sound,
String icon,
Requirement[] requirements
) {
super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon, requirements);
}
}

View File

@@ -29,9 +29,19 @@ public class YieldIncrease extends FertilizerConfig {
private final List<Pair<Double, Integer>> pairs;
public YieldIncrease(String key, FertilizerType fertilizerType, int times, double chance,
List<Pair<Double, Integer>> pairs, @Nullable String[] pot_whitelist, boolean beforePlant,
@Nullable Particle particle, @Nullable Sound sound, String icon, Requirement[] requirements) {
public YieldIncrease(
String key,
FertilizerType fertilizerType,
int times,
double chance,
List<Pair<Double, Integer>> pairs,
@Nullable String[] pot_whitelist,
boolean beforePlant,
@Nullable Particle particle,
@Nullable Sound sound,
String icon,
Requirement[] requirements
) {
super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon, requirements);
this.pairs = pairs;
}

View File

@@ -52,7 +52,7 @@ public class OtherLoot extends Loot {
if (pot != null && pot.getFertilizer() != null && pot.getFertilizer().getConfig() instanceof YieldIncrease increase) {
random += increase.getAmountBonus();
}
ItemStack drop = CustomCrops.getInstance().getIntegrationManager().build(getItemID());
ItemStack drop = CustomCrops.getInstance().getIntegrationManager().build(getItemID(), player);
if (drop.getType() == Material.AIR) return;
drop.setAmount(random);
location.getWorld().dropItemNaturally(location, drop);

View File

@@ -24,6 +24,7 @@ import net.momirealms.customcrops.api.object.fertilizer.Quality;
import net.momirealms.customcrops.api.object.fertilizer.YieldIncrease;
import net.momirealms.customcrops.api.object.pot.Pot;
import net.momirealms.customcrops.api.object.world.SimpleLocation;
import net.momirealms.customcrops.api.util.AdventureUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -31,15 +32,11 @@ import org.bukkit.inventory.ItemStack;
public class QualityLoot extends Loot {
private final String quality_1;
private final String quality_2;
private final String quality_3;
private final String[] qualityLoots;
public QualityLoot(int min, int max, String quality_1, String quality_2, String quality_3) {
public QualityLoot(int min, int max, String... qualityLoots) {
super(min, max);
this.quality_1 = quality_1;
this.quality_2 = quality_2;
this.quality_3 = quality_3;
this.qualityLoots = qualityLoots;
}
@Override
@@ -58,14 +55,16 @@ public class QualityLoot extends Loot {
}
for (int i = 0; i < amount; i++) {
double random = Math.random();
if (random < qualityRatio[0]) dropItem(location, quality_1);
else if (random > qualityRatio[1]) dropItem(location, quality_2);
else dropItem(location, quality_3);
for (int j = 0; j < qualityRatio.length; j++) {
if (random < qualityRatio[j]) {
dropItem(location, qualityLoots[j], player);
}
}
}
}
private void dropItem(Location location, String id) {
ItemStack drop = CustomCrops.getInstance().getIntegrationManager().build(id);
private void dropItem(Location location, String id, Player player) {
ItemStack drop = CustomCrops.getInstance().getIntegrationManager().build(id, player);
if (drop.getType() == Material.AIR) return;
location.getWorld().dropItemNaturally(location, drop);
}

View File

@@ -1,33 +1,33 @@
package net.momirealms.customcrops.api.object.scheduler;
import net.momirealms.customcrops.CustomCrops;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
public class FoliaSchedulerImpl implements SchedulerPlatform {
private final CustomCrops plugin;
public FoliaSchedulerImpl(CustomCrops plugin) {
this.plugin = plugin;
}
@Override
public <T> Future<T> callSyncMethod(@NotNull Callable<T> task) {
return null;
}
@Override
public void runTask(Runnable runnable) {
Bukkit.getGlobalRegionScheduler().execute(plugin, runnable);
}
@Override
public void runTask(Runnable runnable, Location location) {
Bukkit.getRegionScheduler().execute(plugin, location, runnable);
}
}
//package net.momirealms.customcrops.api.object.scheduler;
//
//import net.momirealms.customcrops.CustomCrops;
//import org.bukkit.Bukkit;
//import org.bukkit.Location;
//import org.jetbrains.annotations.NotNull;
//
//import java.util.concurrent.Callable;
//import java.util.concurrent.Future;
//
//public class FoliaSchedulerImpl implements SchedulerPlatform {
//
// private final CustomCrops plugin;
//
// public FoliaSchedulerImpl(CustomCrops plugin) {
// this.plugin = plugin;
// }
//
// @Override
// public <T> Future<T> callSyncMethod(@NotNull Callable<T> task) {
// return null;
// }
//
// @Override
// public void runTask(Runnable runnable) {
// Bukkit.getGlobalRegionScheduler().execute(plugin, runnable);
// }
//
// @Override
// public void runTask(Runnable runnable, Location location) {
// Bukkit.getRegionScheduler().execute(plugin, location, runnable);
// }
//}

View File

@@ -25,7 +25,9 @@ import org.bukkit.Particle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
public class WateringCanConfig {
@@ -45,11 +47,27 @@ public class WateringCanConfig {
private final String bar_empty;
private final String bar_right;
private final PositiveFillMethod[] positiveFillMethods;
private final HashMap<Integer, Integer> appearanceMap;
public WateringCanConfig(int width, int length, int storage,
boolean hasDynamicLore, boolean hasActionBar, @Nullable List<String> loreTemplate, @Nullable String actionBarMsg,
@Nullable String bar_left, @Nullable String bar_full, @Nullable String bar_empty, @Nullable String bar_right,
String[] potWhitelist, String[] sprinkler_whitelist, @Nullable Sound sound, @Nullable Particle particle, @NotNull PositiveFillMethod[] positiveFillMethods) {
public WateringCanConfig(
int width,
int length,
int storage,
boolean hasDynamicLore,
boolean hasActionBar,
@Nullable List<String> loreTemplate,
@Nullable String actionBarMsg,
@Nullable String bar_left,
@Nullable String bar_full,
@Nullable String bar_empty,
@Nullable String bar_right,
String[] potWhitelist,
String[] sprinkler_whitelist,
@Nullable Sound sound,
@Nullable Particle particle,
@NotNull PositiveFillMethod[] positiveFillMethods,
@NotNull HashMap<Integer, Integer> appearanceMap
) {
this.width = width;
this.length = length;
this.storage = storage;
@@ -66,6 +84,7 @@ public class WateringCanConfig {
this.sound = sound;
this.particle = particle;
this.positiveFillMethods = positiveFillMethods;
this.appearanceMap = appearanceMap;
}
public int getWidth() {
@@ -135,4 +154,8 @@ public class WateringCanConfig {
public PositiveFillMethod[] getPositiveFillMethods() {
return positiveFillMethods;
}
public int getModelDataByWater(int water) {
return Optional.ofNullable(appearanceMap.get(water)).orElse(0);
}
}

View File

@@ -38,6 +38,7 @@ import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class WateringCanManager extends Function {
@@ -82,6 +83,13 @@ public class WateringCanManager extends Function {
AdventureUtils.consoleMessage("<red>[CustomCrops] You need to at least one fill-method for: " + key);
continue;
}
ConfigurationSection appearSec = canSec.getConfigurationSection("appearance");
HashMap<Integer, Integer> appearanceMap = new HashMap<>();
if (appearSec != null) {
for (Map.Entry<String, Object> entry : appearSec.getValues(false).entrySet()) {
appearanceMap.put(Integer.parseInt(entry.getKey()), (Integer) entry.getValue());
}
}
@Subst("namespace:key") String soundKey = canSec.getString("sound", "minecraft:block.water.ambient");
Sound sound = canSec.contains("sound") ? Sound.sound(Key.key(soundKey), Sound.Source.PLAYER, 1, 1) : null;
WateringCanConfig wateringCanConfig = new WateringCanConfig(
@@ -100,7 +108,8 @@ public class WateringCanManager extends Function {
canSec.contains("sprinkler-whitelist") ? canSec.getStringList("sprinkler-whitelist").toArray(new String[0]) : null,
sound,
canSec.contains("particle") ? Particle.valueOf(canSec.getString("particle", "WATER_SPLASH").toUpperCase(Locale.ENGLISH)) : null,
methods
methods,
appearanceMap
);
wateringCanConfigMap.put(canSec.getString("item"), wateringCanConfig);
}
@@ -124,6 +133,10 @@ public class WateringCanManager extends Function {
lore.clear();
lore.addAll(config.getLore(water));
}
int cmd = config.getModelDataByWater(water);
if (cmd != 0) {
nbtItem.setInteger("CustomModelData", cmd);
}
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
}
}

View File

@@ -73,7 +73,7 @@ public class CCWorld extends Function {
private int workCounter;
private int consumeCounter;
private final Set<SimpleLocation> plantInPoint;
private Set<ChunkCoordinate> loadInPoint;
private final Set<ChunkCoordinate> loadInPoint;
private final ConcurrentHashMap<SimpleLocation, String> corruptedPot;
private final File chunksFolder;
private final File dateFile;
@@ -284,8 +284,11 @@ public class CCWorld extends Function {
if (ConfigManager.enableScheduleSystem) {
// clear the locations where crops are planted in a point interval
plantInPoint.clear();
// clear the chunk coordinates that has grown in a point interval
loadInPoint = Collections.synchronizedSet(new HashSet<>(chunkMap.keySet()));
// log the chunk coordinates that has grown in a point interval
if (ConfigManager.onlyInLoadedChunks) {
loadInPoint.clear();
loadInPoint.addAll(chunkMap.keySet());
}
// clear the queue if there exists unhandled tasks
schedule.getQueue().clear();
// arrange crop grow check task
@@ -710,7 +713,7 @@ public class CCWorld extends Function {
plugin.getScheduler().runTask(() -> {
if (plugin.getPlatformInterface().removeCustomItem(location, itemMode)) {
ItemDisplay itemDisplay = plugin.getPlatformInterface().placeItemDisplay(location, finalNextModel);
if (itemDisplay != null && cropConfig.isRotationEnabled()) itemDisplay.setRotation(RotationUtils.getRandomFloatRotation(), 0);
if (itemDisplay != null && cropConfig.isRotationEnabled()) itemDisplay.setRotation(RotationUtils.getRandomFloatRotation(), itemDisplay.getLocation().getPitch());
} else {
removeCropData(simpleLocation);
}

View File

@@ -297,12 +297,17 @@ public class ConfigUtils {
if (lootSec == null) continue;
ArrayList<Loot> loots = new ArrayList<>();
if (lootSec.contains("quality-crops")) {
String[] qualityLoots = new String[ConfigManager.defaultRatio.length];
for (int i = 0; i < ConfigManager.defaultRatio.length; i++) {
qualityLoots[i] = lootSec.getString("quality-crops.items." + (i+1));
if (qualityLoots[i] == null) {
AdventureUtils.consoleMessage("<red>[CustomCrops] Error found at: " + model_id + " quality-crops.items." + (i+1) + ", which can't be null");
}
}
loots.add(new QualityLoot(
lootSec.getInt("quality-crops.min"),
lootSec.getInt("quality-crops.max"),
lootSec.getString("quality-crops.items.1"),
lootSec.getString("quality-crops.items.2"),
lootSec.getString("quality-crops.items.3")
qualityLoots
));
}
if (lootSec.contains("other-items")) {
@@ -381,15 +386,14 @@ public class ConfigUtils {
}
public static double[] getQualityRatio(String str) {
double[] ratio = new double[2];
String[] split = str.split("/", 3);
double[] weight = new double[3];
weight[0] = Double.parseDouble(split[0]);
weight[1] = Double.parseDouble(split[1]);
weight[2] = Double.parseDouble(split[2]);
double weightTotal = weight[0] + weight[1] + weight[2];
ratio[0] = weight[0]/(weightTotal);
ratio[1] = 1 - weight[1]/(weightTotal);
String[] split = str.split("/");
double[] ratio = new double[split.length];
double weightTotal = Arrays.stream(split).mapToInt(Integer::parseInt).sum();
double temp = 0;
for (int i = 0; i < ratio.length; i++) {
temp += Integer.parseInt(split[i]);
ratio[i] = temp / weightTotal;
}
return ratio;
}

View File

@@ -1,44 +0,0 @@
//package net.momirealms.customcrops.command.subcmd;
//
//import net.momirealms.customcrops.CustomCrops;
//import net.momirealms.customcrops.command.AbstractSubCommand;
//import org.bukkit.Bukkit;
//import org.bukkit.Location;
//import org.bukkit.command.CommandSender;
//
//import java.util.List;
//
//public class CorruptionTest extends AbstractSubCommand {
//
// public static final CorruptionTest INSTANCE = new CorruptionTest();
//
// public CorruptionTest() {
// super("test");
// }
//
// @Override
// public boolean onCommand(CommandSender sender, List<String> args) {
// Location location = new Location(Bukkit.getWorld("world"), 1604, 100, 1604);
// for (int i = 0; i < 8; i++) {
// for (int j = 0; j < 8; j++) {
// Location newLoc = location.clone().add(i, 0, j);
// Thread t1 = new Thread(() -> CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
// CustomCrops.getInstance().getPlatformInterface().placeNoteBlock(newLoc, "customcrops:wet_pot");
// return null;
// }));
// Thread t2 = new Thread(() -> CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
// CustomCrops.getInstance().getPlatformInterface().placeNoteBlock(newLoc, "customcrops:dry_pot");
// return null;
// }));
// Thread t3 = new Thread(() -> CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
// CustomCrops.getInstance().getPlatformInterface().removeAnyBlock(newLoc);
// return null;
// }));
// t1.start();
// t2.start();
// t3.start();
// }
// }
// return true;
// }
//}

View File

@@ -25,6 +25,7 @@ import net.momirealms.customcrops.api.util.ConfigUtils;
import net.momirealms.customcrops.integration.item.DefaultImpl;
import net.momirealms.customcrops.integration.item.MMOItemsItemImpl;
import net.momirealms.customcrops.integration.item.MythicMobsItemImpl;
import net.momirealms.customcrops.integration.item.NeigeItemsImpl;
import net.momirealms.customcrops.integration.job.EcoJobsImpl;
import net.momirealms.customcrops.integration.job.JobsRebornImpl;
import net.momirealms.customcrops.integration.papi.PlaceholderManager;
@@ -40,6 +41,7 @@ import net.momirealms.customcrops.integration.skill.MMOCoreImpl;
import net.momirealms.customcrops.integration.skill.mcMMOImpl;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
@@ -101,6 +103,10 @@ public class IntegrationManager extends Function {
itemInterfaceList.add(new MMOItemsItemImpl());
hookMessage("MMOItems");
}
if (pluginManager.isPluginEnabled("NeigeItems")) {
itemInterfaceList.add(new NeigeItemsImpl());
hookMessage("NeigeItems");
}
itemInterfaceList.add(new DefaultImpl());
this.itemInterfaces = itemInterfaceList.toArray(new ItemInterface[0]);
}
@@ -151,9 +157,14 @@ public class IntegrationManager extends Function {
@NotNull
public ItemStack build(String key) {
return build(key, null);
}
@NotNull
public ItemStack build(String key, Player player) {
if (key != null) {
for (ItemInterface itemInterface : itemInterfaces) {
ItemStack itemStack = itemInterface.build(key);
ItemStack itemStack = itemInterface.build(key, player);
if (itemStack != null) {
return itemStack;
}

View File

@@ -17,11 +17,12 @@
package net.momirealms.customcrops.integration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
public interface ItemInterface {
@Nullable
ItemStack build(String id);
ItemStack build(String id, Player player);
}

View File

@@ -21,6 +21,7 @@ import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.api.util.ConfigUtils;
import net.momirealms.customcrops.integration.ItemInterface;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
@@ -28,7 +29,7 @@ public class DefaultImpl implements ItemInterface {
@Nullable
@Override
public ItemStack build(String id) {
public ItemStack build(String id, Player player) {
if (ConfigUtils.isVanillaItem(id)) {
return new ItemStack(Material.valueOf(id));
} else {

View File

@@ -21,6 +21,7 @@ import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.momirealms.customcrops.integration.ItemInterface;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
@@ -30,7 +31,7 @@ public class MMOItemsItemImpl implements ItemInterface {
@Nullable
@Override
public ItemStack build(String material) {
public ItemStack build(String material, Player player) {
if (!material.startsWith("MMOItems:")) return null;
material = material.substring(9);
String[] split = material.split(":", 2);

View File

@@ -19,6 +19,7 @@ package net.momirealms.customcrops.integration.item;
import io.lumine.mythic.bukkit.MythicBukkit;
import net.momirealms.customcrops.integration.ItemInterface;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
@@ -32,7 +33,7 @@ public class MythicMobsItemImpl implements ItemInterface {
@Override
@Nullable
public ItemStack build(String material) {
public ItemStack build(String material, Player player) {
if (!material.startsWith("MythicMobs:")) return null;
material = material.substring(11);
if (mythicBukkit == null || mythicBukkit.isClosed()) {

View File

@@ -0,0 +1,17 @@
package net.momirealms.customcrops.integration.item;
import net.momirealms.customcrops.integration.ItemInterface;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import pers.neige.neigeitems.manager.ItemManager;
public class NeigeItemsImpl implements ItemInterface {
@Override
public @Nullable ItemStack build(String material, Player player) {
if (!material.startsWith("NeigeItems:")) return null;
material = material.substring(11);
return ItemManager.INSTANCE.getItemStack(material, player);
}
}

View File

@@ -55,38 +55,35 @@ public class SeasonPapi extends PlaceholderExpansion {
@Override
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
String[] split = params.split("_");
switch (split.length) {
case 1 -> {
switch (split[0]) {
case "season" -> {
Player online_player = player.getPlayer();
if (online_player == null) return null;
return plugin.getIntegrationManager().getSeasonInterface().getSeason(player.getPlayer().getWorld().getName()).getDisplay();
}
case "date" -> {
Player online_player = player.getPlayer();
if (online_player == null) return null;
return String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(player.getPlayer().getWorld().getName()));
}
case "daysleft" -> {
Player online_player = player.getPlayer();
if (online_player == null) return null;
return String.valueOf(1 + ConfigManager.seasonInterval - plugin.getIntegrationManager().getSeasonInterface().getDate(player.getPlayer().getWorld().getName()));
}
String[] split = params.split("_", 2);
if (split[1] == null) {
switch (split[0]) {
case "season" -> {
Player online_player = player.getPlayer();
if (online_player == null) return null;
return plugin.getIntegrationManager().getSeasonInterface().getSeason(player.getPlayer().getWorld().getName()).getDisplay();
}
case "date" -> {
Player online_player = player.getPlayer();
if (online_player == null) return null;
return String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(player.getPlayer().getWorld().getName()));
}
case "daysleft" -> {
Player online_player = player.getPlayer();
if (online_player == null) return null;
return String.valueOf(1 + ConfigManager.seasonInterval - plugin.getIntegrationManager().getSeasonInterface().getDate(player.getPlayer().getWorld().getName()));
}
}
case 2 -> {
switch (split[0]) {
case "season" -> {
return plugin.getIntegrationManager().getSeasonInterface().getSeason(split[1]).getDisplay();
}
case "date" -> {
return String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(split[1]));
}
case "daysleft" -> {
return String.valueOf(1 + ConfigManager.seasonInterval - plugin.getIntegrationManager().getSeasonInterface().getDate(split[1]));
}
} else {
switch (split[0]) {
case "season" -> {
return plugin.getIntegrationManager().getSeasonInterface().getSeason(split[1]).getDisplay();
}
case "date" -> {
return String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(split[1]));
}
case "daysleft" -> {
return String.valueOf(1 + ConfigManager.seasonInterval - plugin.getIntegrationManager().getSeasonInterface().getDate(split[1]));
}
}
}

View File

@@ -48,8 +48,8 @@ public class BetonQuestCCQuest extends CountingObjective implements Listener {
super(instruction, "crop_to_harvest");
crop_ids = new HashSet<>();
Collections.addAll(crop_ids, instruction.getArray());
targetAmount = instruction.getInt();
targetAmount = instruction.getVarNum();
preCheckAmountNotLessThanOne(targetAmount);
final String pack = instruction.getPackage().getQuestPath();
final String loc = instruction.getOptional("playerLocation");
final String range = instruction.getOptional("range");
@@ -60,10 +60,6 @@ public class BetonQuestCCQuest extends CountingObjective implements Listener {
playerLocation = null;
rangeVar = null;
}
if (targetAmount <= 0) {
throw new InstructionParseException("Crop amount cannot be less than 0");
}
}
public static void register() {

View File

@@ -17,6 +17,9 @@ tomato:
# 农作物的种子,如果你想用原版物品做种子,就使用大写字母
seed: customcrops:tomato_seeds
# Only works in ITEM_FRAME / ITEM_DISPLAY mode
random-rotation: true
# break/plant requirements
# 破坏/种植农作物的需求
requirements:

View File

@@ -2,6 +2,14 @@
watering_can_1:
# 物品 id
item: customcrops:watering_can_1
# This is optional. It would decide the look of the watering can when having different water amount
# 可选配置,他会影响水壶在不同水量情况下的外观
#appearance:
# # custom-model-data
# 0: 1000
# 1: 1001
# 2: 1002
# 3: 1003
# 储水量
capacity: 3
# Effective Range