9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 00:19:24 +00:00
This commit is contained in:
Xiao-MoMi
2022-10-06 18:14:37 +08:00
parent ea707be872
commit 1bc99a34a0
9 changed files with 157 additions and 30 deletions

View File

@@ -38,6 +38,7 @@ import net.momirealms.customcrops.integrations.season.RealisticSeasonsHook;
import net.momirealms.customcrops.integrations.season.SeasonInterface;
import net.momirealms.customcrops.managers.listener.ItemSpawnListener;
import net.momirealms.customcrops.managers.listener.WorldListener;
import net.momirealms.customcrops.managers.timer.CrowTask;
import net.momirealms.customcrops.managers.timer.TimerTask;
import net.momirealms.customcrops.objects.OtherLoot;
import net.momirealms.customcrops.objects.QualityLoot;
@@ -53,6 +54,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
@@ -194,6 +196,12 @@ public class CropManager extends Function {
return false;
}
public boolean hasScarecrow(Location location) {
CustomWorld customWorld = customWorlds.get(location.getWorld());
if (customWorld == null) return true;
return customWorld.hasScarecrow(location);
}
public CustomInterface getCustomInterface() {
return customInterface;
}
@@ -324,6 +332,36 @@ public class CropManager extends Function {
}
}
public boolean crowJudge(Location location, ItemFrame itemFrame) {
if (Math.random() < MainConfig.crowChance && !hasScarecrow(location)) {
for (Player player : location.getNearbyPlayers(48)) {
CrowTask crowTask = new CrowTask(player, location.clone().add(0.4,0,0.4), getArmorStandUtil());
crowTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1, 1);
}
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, () -> {
customInterface.removeFurniture(itemFrame);
}, 125);
return true;
}
return false;
}
public boolean crowJudge(Location location) {
if (Math.random() < MainConfig.crowChance && !hasScarecrow(location)) {
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
for (Player player : location.getNearbyPlayers(48)) {
CrowTask crowTask = new CrowTask(player, location.clone().add(0.4,0,0.4), getArmorStandUtil());
crowTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1, 1);
}
});
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, () -> {
customInterface.removeBlock(location);
}, 125);
return true;
}
return false;
}
public ArmorStandUtil getArmorStandUtil() {
return armorStandUtil;
}