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> <groupId>com.craftaro</groupId>
<artifactId>EpicFarming</artifactId> <artifactId>EpicFarming</artifactId>
<version>4.1.1</version> <version>4.2.0</version>
<name>EpicFarming</name> <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> <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> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version> <version>3.5.2</version>
<executions> <executions>
<execution> <execution>
@ -123,14 +123,14 @@
<dependency> <dependency>
<groupId>com.craftaro</groupId> <groupId>com.craftaro</groupId>
<artifactId>CraftaroCore</artifactId> <artifactId>CraftaroCore</artifactId>
<version>3.0.0-SNAPSHOT</version> <version>3.0.4-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.craftaro</groupId> <groupId>com.craftaro</groupId>
<artifactId>FabledSkyBlock</artifactId> <artifactId>FabledSkyBlock</artifactId>
<version>3.0.0-b6-SNAPSHOT</version> <version>3.0.4</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -1,6 +1,6 @@
package com.craftaro.epicfarming.compatibility; 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.BasicPermission;
import com.craftaro.skyblock.permission.PermissionType; 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.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
public class Farm implements Data { public class Farm implements Data {
// This is the unique identifier for this farm. // This is the unique identifier for this farm.
@ -198,20 +192,27 @@ public class Farm implements Data {
for (int fz = -radius; fz <= radius; fz++) { for (int fz = -radius; fz <= radius; fz++) {
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz); Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
// ToDo: enum for all flowers. // Check if the block is a grass block or dirt
if (Settings.BREAKABLE_BLOCKS.getStringList().contains(CompatibleMaterial.getMaterial(b2.getType()).get().name())) { if (b2.getType() == XMaterial.GRASS_BLOCK.parseMaterial() || b2.getType() == Material.DIRT) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> { // Check if the block above is junk (grass or a flower)
XBlock.setType(b2.getRelative(BlockFace.DOWN), XMaterial.FARMLAND); Block blockAbove = b2.getRelative(BlockFace.UP);
b2.breakNaturally(); if (isJunk(blockAbove.getType())) {
XSound.BLOCK_GRASS_BREAK.play(b2.getLocation(), 10, 15); Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
}, random.nextInt(30) + 1); XBlock.setType(b2, XMaterial.FARMLAND);
} Collection<ItemStack> drops = blockAbove.getDrops();
if ((b2.getType() == XMaterial.GRASS_BLOCK.parseMaterial() if (!drops.isEmpty()) {
|| b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) { blockAbove.breakNaturally(drops.iterator().next());
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> { } else {
XBlock.setType(b2, XMaterial.FARMLAND); blockAbove.breakNaturally();
XSound.BLOCK_GRASS_BREAK.play(b2.getLocation(), 10, 15); }
}, random.nextInt(30) + 1); 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; 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. //Don't use getUniqueId here as it conflicts with the Data interface.
public UUID getFarmUUID() { public UUID getFarmUUID() {
return this.uniqueId; return this.uniqueId;

View File

@ -29,6 +29,9 @@ import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ModuleAutoBreeding extends Module { 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; private final int autoBreedCap;
public ModuleAutoBreeding(EpicFarming plugin, int autoBreedCap) { public ModuleAutoBreeding(EpicFarming plugin, int autoBreedCap) {
@ -58,73 +61,59 @@ public class ModuleAutoBreeding extends Module {
return; 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 = Map<EntityType, Long> counts = entities.stream()
entities.stream().collect(Collectors.groupingBy(Entity::getType, Collectors.counting())); .collect(Collectors.groupingBy(Entity::getType, Collectors.summingLong(entity -> {
int stackSize = EntityStackerManager.getSize(entity);
for (LivingEntity entity : entities) { return stackSize > 0 ? stackSize : 1;
int stackSize = EntityStackerManager.getSize(entity); })));
if (stackSize == 0) {
stackSize = 1;
}
counts.put(entity.getType(), counts.get(entity.getType()) - 1 + stackSize);
}
boolean mate1 = false; boolean mate1 = false;
for (Map.Entry<EntityType, Long> entry : counts.entrySet()) { 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) { for (LivingEntity entity : entities) {
if (entry.getKey() != entity.getType()) { if (entity.getType() != entityType) {
continue; continue;
} }
int count = EntityStackerManager.getSize(entity) == 0 ? 1 : EntityStackerManager.getSize(entity);
int stackSize = EntityStackerManager.getSize(entity);
if (stackSize == 0) {
stackSize = 1;
}
if (mate1) { if (mate1) {
if (count > 1) { farm.removeMaterial(breedingItem.getType(), 2);
if (stackSize > 1) {
handleStackedBreed(entity); handleStackedBreed(entity);
if (stackSize > 2) {
handleStackedBreed(entity);
}
} else { } else {
handleBreed(entity); handleBreed(entity);
} }
Bukkit.getScheduler().runTask(this.plugin, () -> Methods.animate(farm.getLocation(), XMaterial.EGG));
spawnParticlesAndAnimation(entity.getLocation(), farm.getLocation());
return; return;
} }
if (entry.getValue() >= 2) { if (stackSize > 1) {
EntityType entityType = entry.getKey(); handleStackedBreed(entity);
} else {
for (ItemStack item : farm.getItems().toArray(new ItemStack[0])) { handleBreed(entity);
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;
}
} }
mate1 = true;
break;
} }
} }
} }
@ -161,9 +150,9 @@ public class ModuleAutoBreeding extends Module {
} }
private void handleBreed(Entity entity) { private void handleBreed(Entity entity) {
entity.setMetadata(BREED_COOLDOWN_METADATA, new FixedMetadataValue(this.plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () ->
entity.removeMetadata("breedCooldown", this.plugin), 5 * 20 * 60); entity.removeMetadata(BREED_COOLDOWN_METADATA, this.plugin), BREED_COOLDOWN_TICKS);
entity.setMetadata("breedCooldown", new FixedMetadataValue(this.plugin, true));
} }
private boolean isEnabled(Farm farm) { private boolean isEnabled(Farm farm) {
@ -174,4 +163,23 @@ public class ModuleAutoBreeding extends Module {
private void toggleEnabled(Farm farm) { private void toggleEnabled(Farm farm) {
saveData(farm, "enabled", !isEnabled(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));
}
}