mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 16:39:36 +00:00
1.5.14
This commit is contained in:
@@ -73,6 +73,7 @@ public class ConfigReader {
|
||||
public static boolean asyncCheck;
|
||||
public static boolean enableLimit;
|
||||
public static boolean hasParticle;
|
||||
public static boolean rightClickHarvest;
|
||||
public static int cropLimit;
|
||||
public static int sprinklerLimit;
|
||||
public static int yMin;
|
||||
@@ -114,6 +115,7 @@ public class ConfigReader {
|
||||
onlyLoadedGrow = !config.getBoolean("config.only-grow-in-loaded-chunks",true);
|
||||
allWorld = config.getBoolean("config.all-world-grow",false);
|
||||
hasParticle = config.getBoolean("config.water-particles", true);
|
||||
rightClickHarvest = config.getBoolean("config.right-click-harvest", true);
|
||||
|
||||
//数量与高度限制
|
||||
enableLimit = config.getBoolean("config.limit.enable",true);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Residence implements Integration {
|
||||
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
|
||||
if(res!=null){
|
||||
ResidencePermissions perms = res.getPermissions();
|
||||
return perms.playerHas(player, Flags.build, true);
|
||||
return perms.playerHas(player, Flags.destroy, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class Residence implements Integration {
|
||||
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
|
||||
if(res!=null){
|
||||
ResidencePermissions perms = res.getPermissions();
|
||||
return perms.playerHas(player, Flags.destroy, true);
|
||||
return perms.playerHas(player, Flags.build, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import dev.lone.itemsadder.api.CustomBlock;
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent;
|
||||
import net.momirealms.customcrops.ConfigReader;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.datamanager.PotManager;
|
||||
import net.momirealms.customcrops.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.fertilizer.QualityCrop;
|
||||
@@ -28,6 +29,7 @@ import net.momirealms.customcrops.integrations.Integration;
|
||||
import net.momirealms.customcrops.utils.CropInstance;
|
||||
import net.momirealms.customcrops.utils.SimpleLocation;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -46,7 +48,7 @@ public class BreakBlock implements Listener {
|
||||
public void onBreak(CustomBlockBreakEvent event){
|
||||
String namespacedId = event.getNamespacedID();
|
||||
if(namespacedId.contains("_stage_")){
|
||||
Player player =event.getPlayer();
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getBlock().getLocation();
|
||||
for (Integration integration : ConfigReader.Config.integration){
|
||||
if(!integration.canBreak(location, player)) return;
|
||||
@@ -64,35 +66,51 @@ public class BreakBlock implements Listener {
|
||||
String[] cropNameList = StringUtils.split(StringUtils.split(namespacedId, ":")[1], "_");
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
if (CustomBlock.getInstance(StringUtils.chop(namespacedId) + nextStage) == null) {
|
||||
CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]);
|
||||
ThreadLocalRandom current = ThreadLocalRandom.current();
|
||||
int random = current.nextInt(cropInstance.getMin(), cropInstance.getMax() + 1);
|
||||
Location itemLoc = location.clone().add(0.5,0.2,0.5);
|
||||
World world = location.getWorld();
|
||||
Fertilizer fertilizer = PotManager.Cache.get(SimpleLocation.fromLocation(location.clone().subtract(0,1,0)));
|
||||
if (fertilizer != null){
|
||||
if (fertilizer instanceof QualityCrop qualityCrop){
|
||||
int[] weights = qualityCrop.getChance();
|
||||
double weightTotal = weights[0] + weights[1] + weights[2];
|
||||
double rank_1 = weights[0]/(weightTotal);
|
||||
double rank_2 = 1 - weights[1]/(weightTotal);
|
||||
for (int i = 0; i < random; i++){
|
||||
double ran = Math.random();
|
||||
if (ran < rank_1){
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_1()).getItemStack());
|
||||
}else if(ran > rank_2){
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_2()).getItemStack());
|
||||
}else {
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_3()).getItemStack());
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, ()-> {
|
||||
if (location.getBlock().getType() != Material.AIR) return;
|
||||
CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]);
|
||||
ThreadLocalRandom current = ThreadLocalRandom.current();
|
||||
int random = current.nextInt(cropInstance.getMin(), cropInstance.getMax() + 1);
|
||||
Location itemLoc = location.clone().add(0.5,0.2,0.5);
|
||||
World world = location.getWorld();
|
||||
Fertilizer fertilizer = PotManager.Cache.get(SimpleLocation.fromLocation(location.clone().subtract(0,1,0)));
|
||||
if (fertilizer != null){
|
||||
if (fertilizer instanceof QualityCrop qualityCrop){
|
||||
int[] weights = qualityCrop.getChance();
|
||||
double weightTotal = weights[0] + weights[1] + weights[2];
|
||||
double rank_1 = weights[0]/(weightTotal);
|
||||
double rank_2 = 1 - weights[1]/(weightTotal);
|
||||
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, ()-> {
|
||||
for (int i = 0; i < random; i++){
|
||||
double ran = Math.random();
|
||||
if (ran < rank_1){
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_1()).getItemStack());
|
||||
}else if(ran > rank_2){
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_2()).getItemStack());
|
||||
}else {
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_3()).getItemStack());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
}else {
|
||||
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, ()-> {
|
||||
normalDrop(cropInstance, random, itemLoc, world);
|
||||
return null;
|
||||
});
|
||||
|
||||
}
|
||||
}else {
|
||||
normalDrop(cropInstance, random, itemLoc, world);
|
||||
}
|
||||
}
|
||||
else {
|
||||
normalDrop(cropInstance, random, itemLoc, world);
|
||||
}
|
||||
else {
|
||||
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, ()-> {
|
||||
normalDrop(cropInstance, random, itemLoc, world);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
else if(namespacedId.equalsIgnoreCase(ConfigReader.Basic.watered_pot) || namespacedId.equalsIgnoreCase(ConfigReader.Basic.pot)){
|
||||
|
||||
@@ -318,7 +318,7 @@ public class RightClick implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action == Action.RIGHT_CLICK_BLOCK) {
|
||||
else if (ConfigReader.Config.rightClickHarvest && action == Action.RIGHT_CLICK_BLOCK) {
|
||||
Block block = event.getClickedBlock();
|
||||
Location location = block.getLocation();
|
||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||
|
||||
@@ -73,4 +73,8 @@ config:
|
||||
#Should all the worlds' crops grow?
|
||||
#This is useful for per player per world server.
|
||||
#In this mode, whitelist world can only have one as the standard of time & season judgment.
|
||||
all-world-grow: false
|
||||
all-world-grow: false
|
||||
|
||||
#can player harvest crops with right click?
|
||||
#if set "false" crops can't be harvested repeatedly
|
||||
right-click-harvest: true
|
||||
Reference in New Issue
Block a user