mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 09:59:20 +00:00
2.2.2-hotfix
This commit is contained in:
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import com.iridium.iridiumskyblock.PermissionType;
|
||||
|
||||
@@ -363,15 +363,15 @@ public class CustomWorld {
|
||||
if (cropData == null) return;
|
||||
Random randomGenerator = new Random();
|
||||
if (force) {
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
growSingleWire(entry.getKey(), entry.getValue(), randomGenerator.nextInt(cropTime));
|
||||
for (SimpleLocation location : cropData.keySet()) {
|
||||
growSingleWire(location, randomGenerator.nextInt(cropTime));
|
||||
}
|
||||
}
|
||||
else if (!compensation) {
|
||||
route(sprinklerTime);
|
||||
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
growSingleWire(entry.getKey(), entry.getValue(), sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
||||
for (SimpleLocation location : cropData.keySet()) {
|
||||
growSingleWire(location, sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
|
||||
@@ -381,17 +381,19 @@ public class CustomWorld {
|
||||
else {
|
||||
int delay = (int) (24000 - world.getTime());
|
||||
double chance = (double) (24000 - world.getTime()) / 24000;
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
for (SimpleLocation location : cropData.keySet()) {
|
||||
if (Math.random() < chance) {
|
||||
growSingleWire(entry.getKey(), entry.getValue(), randomGenerator.nextInt(delay));
|
||||
growSingleWire(location, randomGenerator.nextInt(delay));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void growSingleWire(SimpleLocation simpleLocation, GrowingCrop growingCrop, long delay) {
|
||||
private void growSingleWire(SimpleLocation simpleLocation, long delay) {
|
||||
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
|
||||
Location location = MiscUtils.getLocation(simpleLocation);
|
||||
GrowingCrop growingCrop = cropData.get(simpleLocation);
|
||||
if (growingCrop == null) return;
|
||||
if (cropManager.wireGrowJudge(location, growingCrop)) {
|
||||
cropData.remove(simpleLocation);
|
||||
}
|
||||
@@ -402,17 +404,15 @@ public class CustomWorld {
|
||||
if (cropData == null) return;
|
||||
Random randomGenerator = new Random();
|
||||
if (force) {
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
growSingleFrame(entry.getKey(), entry.getValue(), randomGenerator.nextInt(cropTime));
|
||||
for (SimpleLocation location : cropData.keySet()) {
|
||||
growSingleFrame(location, randomGenerator.nextInt(cropTime));
|
||||
}
|
||||
}
|
||||
else if (!compensation) {
|
||||
route(sprinklerTime);
|
||||
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
growSingleFrame(entry.getKey(), entry.getValue(), sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
||||
for (SimpleLocation location : cropData.keySet()) {
|
||||
growSingleFrame(location, sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
|
||||
potDryJudge(dryTime);
|
||||
}, sprinklerTime);
|
||||
@@ -420,30 +420,29 @@ public class CustomWorld {
|
||||
else {
|
||||
int delay = (int) (24000 - world.getTime());
|
||||
double chance = (double) (24000 - world.getTime()) / 24000;
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
for (SimpleLocation location : cropData.keySet()) {
|
||||
if (Math.random() < chance) {
|
||||
growSingleFrame(entry.getKey(), entry.getValue(), randomGenerator.nextInt(delay));
|
||||
growSingleFrame(location, randomGenerator.nextInt(delay));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void growSingleFrame(SimpleLocation simpleLocation, GrowingCrop growingCrop, long delay) {
|
||||
private void growSingleFrame(SimpleLocation simpleLocation, long delay) {
|
||||
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
|
||||
Location location = MiscUtils.getLocation(simpleLocation);
|
||||
if (location == null) return;
|
||||
GrowingCrop growingCrop = cropData.get(simpleLocation);
|
||||
if (growingCrop == null) return;
|
||||
location.getChunk().load();
|
||||
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
|
||||
if (cropManager.itemFrameGrowJudge(location, growingCrop)) {
|
||||
cropData.remove(simpleLocation);
|
||||
}
|
||||
}, 5);
|
||||
}, delay);
|
||||
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
|
||||
Location location = MiscUtils.getLocation(simpleLocation);
|
||||
if (location == null) return;
|
||||
if (cropManager.itemFrameGrowJudge(location, growingCrop)) {
|
||||
cropData.remove(simpleLocation);
|
||||
}
|
||||
}, delay + 5);
|
||||
}
|
||||
|
||||
|
||||
private void route(int sprinklerTime) {
|
||||
//先将湿润的种植盆放入等待判断的种植盆列表中
|
||||
tempWatered = new HashSet<>(watered);
|
||||
@@ -556,8 +555,8 @@ public class CustomWorld {
|
||||
double chance = (double) (24000 - world.getTime()) / 24000;
|
||||
plantedToday.add(simpleLocation);
|
||||
if (Math.random() > chance) return;
|
||||
if (MainConfig.cropMode) growSingleWire(simpleLocation, growingCrop, new Random().nextInt(delay));
|
||||
else growSingleFrame(simpleLocation, growingCrop, new Random().nextInt(delay));
|
||||
if (MainConfig.cropMode) growSingleWire(simpleLocation, new Random().nextInt(delay));
|
||||
else growSingleFrame(simpleLocation, new Random().nextInt(delay));
|
||||
}
|
||||
}
|
||||
@Nullable
|
||||
|
||||
@@ -62,10 +62,10 @@ public class CustomPapi implements RequirementInterface {
|
||||
switch (type){
|
||||
case "==" -> papiRequirement = new PapiEquals(papi, value);
|
||||
case "!=" -> papiRequirement = new PapiNotEquals(papi, value);
|
||||
case ">=" -> papiRequirement = new PapiNoLess(papi, Double.parseDouble(value));
|
||||
case "<=" -> papiRequirement = new PapiNoLarger(papi, Double.parseDouble(value));
|
||||
case "<" -> papiRequirement = new PapiSmaller(papi, Double.parseDouble(value));
|
||||
case ">" -> papiRequirement = new PapiGreater(papi, Double.parseDouble(value));
|
||||
case ">=" -> papiRequirement = new PapiNoLess(papi, value);
|
||||
case "<=" -> papiRequirement = new PapiNoLarger(papi, value);
|
||||
case "<" -> papiRequirement = new PapiSmaller(papi, value);
|
||||
case ">" -> papiRequirement = new PapiGreater(papi, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class CustomPapi implements RequirementInterface {
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlantingCondition plantingCondition) {
|
||||
if (!papiRequirement.isMet(plantingCondition.getPapiMap())) {
|
||||
if (!papiRequirement.isMet(plantingCondition.getPapiMap(), plantingCondition.getPlayer())) {
|
||||
if (msg != null) AdventureUtil.playerMessage(plantingCondition.getPlayer(), msg);
|
||||
return false;
|
||||
}
|
||||
@@ -112,10 +112,10 @@ public class CustomPapi implements RequirementInterface {
|
||||
switch (type){
|
||||
case "==" -> papiRequirements.add(new PapiEquals(papi, value));
|
||||
case "!=" -> papiRequirements.add(new PapiNotEquals(papi, value));
|
||||
case ">=" -> papiRequirements.add(new PapiNoLess(papi, Double.parseDouble(value)));
|
||||
case "<=" -> papiRequirements.add(new PapiNoLarger(papi, Double.parseDouble(value)));
|
||||
case "<" -> papiRequirements.add(new PapiSmaller(papi, Double.parseDouble(value)));
|
||||
case ">" -> papiRequirements.add(new PapiGreater(papi, Double.parseDouble(value)));
|
||||
case ">=" -> papiRequirements.add(new PapiNoLess(papi, value));
|
||||
case "<=" -> papiRequirements.add(new PapiNoLarger(papi, value));
|
||||
case "<" -> papiRequirements.add(new PapiSmaller(papi, value));
|
||||
case ">" -> papiRequirements.add(new PapiGreater(papi, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,17 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public record ExpressionAnd(List<PapiRequirement> requirements) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
||||
for (PapiRequirement requirement : requirements) {
|
||||
if (!requirement.isMet(papiMap)) return false;
|
||||
if (!requirement.isMet(papiMap, player)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,15 +17,17 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public record ExpressionOr(List<PapiRequirement> requirements) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
||||
for (PapiRequirement requirement : requirements) {
|
||||
if (requirement.isMet(papiMap)) return true;
|
||||
if (requirement.isMet(papiMap, player)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,14 +17,17 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public record PapiEquals(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
||||
String value = papiMap.get(papi);
|
||||
return Objects.equals(value, requirement);
|
||||
return Objects.equals(value, PlaceholderAPI.setPlaceholders(player, requirement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiGreater(String papi, double requirement) implements PapiRequirement{
|
||||
public record PapiGreater(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value > requirement;
|
||||
return value > Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiNoLarger(String papi, double requirement) implements PapiRequirement{
|
||||
public record PapiNoLarger(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value <= requirement;
|
||||
return value <= Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiNoLess(String papi, double requirement) implements PapiRequirement{
|
||||
public record PapiNoLess(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value >= requirement;
|
||||
return value >= Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,17 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public record PapiNotEquals(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
||||
String value = papiMap.get(papi);
|
||||
return !Objects.equals(value, requirement);
|
||||
return !Objects.equals(value, PlaceholderAPI.setPlaceholders(player, requirement));
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,10 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface PapiRequirement {
|
||||
boolean isMet(HashMap<String, String> papiMap);
|
||||
boolean isMet(HashMap<String, String> papiMap, Player player);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
|
||||
package net.momirealms.customcrops.objects.requirements.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiSmaller(String papi, double requirement) implements PapiRequirement{
|
||||
public record PapiSmaller(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value < requirement;
|
||||
return value < Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user