Merge branch 'development'

This commit is contained in:
Christian Koop 2024-03-28 15:09:06 +01:00
commit a791802465
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
4 changed files with 123 additions and 80 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.craftaro</groupId>
<artifactId>EpicFarming</artifactId>
<version>4.1.1</version>
<version>4.2.0</version>
<name>EpicFarming</name>
<description>Allow your players to grow crops faster, automatically replant, harvest and store crops and animal produce in the farm's inventory, as well as much more</description>
@ -35,7 +35,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.2</version>
<executions>
<execution>
@ -123,14 +123,14 @@
<dependency>
<groupId>com.craftaro</groupId>
<artifactId>CraftaroCore</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.craftaro</groupId>
<artifactId>FabledSkyBlock</artifactId>
<version>3.0.0-b6-SNAPSHOT</version>
<version>3.0.4</version>
<scope>provided</scope>
</dependency>

View File

@ -1,6 +1,6 @@
package com.craftaro.epicfarming.compatibility;
import com.craftaro.skyblock.core.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.skyblock.permission.BasicPermission;
import com.craftaro.skyblock.permission.PermissionType;

View File

@ -22,13 +22,7 @@ import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.*;
public class Farm implements Data {
// This is the unique identifier for this farm.
@ -198,20 +192,27 @@ public class Farm implements Data {
for (int fz = -radius; fz <= radius; fz++) {
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
// ToDo: enum for all flowers.
if (Settings.BREAKABLE_BLOCKS.getStringList().contains(CompatibleMaterial.getMaterial(b2.getType()).get().name())) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
XBlock.setType(b2.getRelative(BlockFace.DOWN), XMaterial.FARMLAND);
b2.breakNaturally();
XSound.BLOCK_GRASS_BREAK.play(b2.getLocation(), 10, 15);
}, random.nextInt(30) + 1);
}
if ((b2.getType() == XMaterial.GRASS_BLOCK.parseMaterial()
|| b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
XBlock.setType(b2, XMaterial.FARMLAND);
XSound.BLOCK_GRASS_BREAK.play(b2.getLocation(), 10, 15);
}, random.nextInt(30) + 1);
// Check if the block is a grass block or dirt
if (b2.getType() == XMaterial.GRASS_BLOCK.parseMaterial() || b2.getType() == Material.DIRT) {
// Check if the block above is junk (grass or a flower)
Block blockAbove = b2.getRelative(BlockFace.UP);
if (isJunk(blockAbove.getType())) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
XBlock.setType(b2, XMaterial.FARMLAND);
Collection<ItemStack> drops = blockAbove.getDrops();
if (!drops.isEmpty()) {
blockAbove.breakNaturally(drops.iterator().next());
} else {
blockAbove.breakNaturally();
}
XSound.BLOCK_GRASS_BREAK.play(b2.getLocation(), 10, 15);
}, random.nextInt(30) + 1);
} else if (blockAbove.getType() == Material.AIR) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
XBlock.setType(b2, XMaterial.FARMLAND);
XSound.BLOCK_GRASS_BREAK.play(b2.getLocation(), 10, 15);
}, random.nextInt(30) + 1);
}
}
}
}
@ -219,6 +220,40 @@ public class Farm implements Data {
return false;
}
private boolean isJunk(Material material) {
XMaterial xMaterial = XMaterial.matchXMaterial(material);
if (xMaterial == null) {
return false;
}
switch (xMaterial) {
case SHORT_GRASS:
case TALL_GRASS:
case FERN:
case LARGE_FERN:
case DANDELION:
case POPPY:
case BLUE_ORCHID:
case ALLIUM:
case AZURE_BLUET:
case RED_TULIP:
case ORANGE_TULIP:
case WHITE_TULIP:
case PINK_TULIP:
case OXEYE_DAISY:
case CORNFLOWER:
case LILY_OF_THE_VALLEY:
case WITHER_ROSE:
case SUNFLOWER:
case LILAC:
case ROSE_BUSH:
case PEONY:
return true;
default:
return false;
}
}
//Don't use getUniqueId here as it conflicts with the Data interface.
public UUID getFarmUUID() {
return this.uniqueId;

View File

@ -29,6 +29,9 @@ import java.util.Map;
import java.util.stream.Collectors;
public class ModuleAutoBreeding extends Module {
private static final String BREED_COOLDOWN_METADATA = "breedCooldown";
private static final int BREED_COOLDOWN_TICKS = 5 * 20 * 60;
private final int autoBreedCap;
public ModuleAutoBreeding(EpicFarming plugin, int autoBreedCap) {
@ -58,73 +61,59 @@ public class ModuleAutoBreeding extends Module {
return;
}
entities.removeIf(e -> !(e instanceof Ageable) || !((Ageable) e).isAdult() || e.hasMetadata("breedCooldown") || e.isDead());
entities.removeIf(e -> !(e instanceof Ageable) || !((Ageable) e).isAdult() || e.hasMetadata(BREED_COOLDOWN_METADATA) || e.isDead());
Map<EntityType, Long> counts =
entities.stream().collect(Collectors.groupingBy(Entity::getType, Collectors.counting()));
for (LivingEntity entity : entities) {
int stackSize = EntityStackerManager.getSize(entity);
if (stackSize == 0) {
stackSize = 1;
}
counts.put(entity.getType(), counts.get(entity.getType()) - 1 + stackSize);
}
Map<EntityType, Long> counts = entities.stream()
.collect(Collectors.groupingBy(Entity::getType, Collectors.summingLong(entity -> {
int stackSize = EntityStackerManager.getSize(entity);
return stackSize > 0 ? stackSize : 1;
})));
boolean mate1 = false;
for (Map.Entry<EntityType, Long> entry : counts.entrySet()) {
if (entry.getValue() < 2) {
continue;
}
EntityType entityType = entry.getKey();
ItemStack breedingItem = getBreedingItem(farm, entityType);
if (breedingItem == null || breedingItem.getAmount() < 2) {
continue;
}
for (LivingEntity entity : entities) {
if (entry.getKey() != entity.getType()) {
if (entity.getType() != entityType) {
continue;
}
int count = EntityStackerManager.getSize(entity) == 0 ? 1 : EntityStackerManager.getSize(entity);
int stackSize = EntityStackerManager.getSize(entity);
if (stackSize == 0) {
stackSize = 1;
}
if (mate1) {
if (count > 1) {
farm.removeMaterial(breedingItem.getType(), 2);
if (stackSize > 1) {
handleStackedBreed(entity);
if (stackSize > 2) {
handleStackedBreed(entity);
}
} else {
handleBreed(entity);
}
Bukkit.getScheduler().runTask(this.plugin, () -> Methods.animate(farm.getLocation(), XMaterial.EGG));
spawnParticlesAndAnimation(entity.getLocation(), farm.getLocation());
return;
}
if (entry.getValue() >= 2) {
EntityType entityType = entry.getKey();
for (ItemStack item : farm.getItems().toArray(new ItemStack[0])) {
EntityInfo info = EntityInfo.of(entityType);
try {
if (info == null || item.getType() != info.getMaterial() || item.getAmount() < 2) {
continue;
}
} catch (IllegalArgumentException e) {
continue;
}
farm.removeMaterial(item.getType(), 2);
Location location = entity.getLocation();
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.HEART,
location, 5, .5, .5, .5);
Bukkit.getScheduler().runTask(this.plugin, () -> {
Entity newSpawn = location.getWorld().spawnEntity(location, entityType);
((Ageable) newSpawn).setBaby();
});
if (count > 1) {
handleStackedBreed(entity);
if (count - 1 > 1) {
handleStackedBreed(entity);
} else {
handleBreed(entity);
}
return;
}
handleBreed(entity);
mate1 = true;
break;
}
if (stackSize > 1) {
handleStackedBreed(entity);
} else {
handleBreed(entity);
}
mate1 = true;
break;
}
}
}
@ -161,9 +150,9 @@ public class ModuleAutoBreeding extends Module {
}
private void handleBreed(Entity entity) {
entity.setMetadata(BREED_COOLDOWN_METADATA, new FixedMetadataValue(this.plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () ->
entity.removeMetadata("breedCooldown", this.plugin), 5 * 20 * 60);
entity.setMetadata("breedCooldown", new FixedMetadataValue(this.plugin, true));
entity.removeMetadata(BREED_COOLDOWN_METADATA, this.plugin), BREED_COOLDOWN_TICKS);
}
private boolean isEnabled(Farm farm) {
@ -174,4 +163,23 @@ public class ModuleAutoBreeding extends Module {
private void toggleEnabled(Farm farm) {
saveData(farm, "enabled", !isEnabled(farm));
}
}
private ItemStack getBreedingItem(Farm farm, EntityType entityType) {
EntityInfo info = EntityInfo.of(entityType);
if (info == null) {
return null;
}
for (ItemStack item : farm.getItems().toArray(new ItemStack[0])) {
if (item.getType() == info.getMaterial()) {
return item;
}
}
return null;
}
private void spawnParticlesAndAnimation(Location entityLocation, Location farmLocation) {
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.HEART, entityLocation, 5, .5, .5, .5);
Bukkit.getScheduler().runTask(this.plugin, () -> Methods.animate(farmLocation, XMaterial.EGG));
}
}