9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 16:39:36 +00:00
This commit is contained in:
Xiao-MoMi
2022-07-21 13:47:14 +08:00
parent 99f941eed0
commit 1955677b06
5 changed files with 56 additions and 32 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;
@@ -64,6 +66,9 @@ 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) {
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);
@@ -76,6 +81,7 @@ public class BreakBlock implements Listener {
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){
@@ -86,13 +92,25 @@ public class BreakBlock implements Listener {
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 {
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)){

View File

@@ -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);

View File

@@ -74,3 +74,7 @@ config:
#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
#can player harvest crops with right click?
#if set "false" crops can't be harvested repeatedly
right-click-harvest: true