mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-09-28 22:57:30 +02:00
Added support for the new SongodaCore update.
This commit is contained in:
parent
e056c845d8
commit
8b61e4373c
@ -82,7 +82,7 @@ public class ModuleAutoBreeding extends Module {
|
||||
else
|
||||
handleBreed(entity);
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
Methods.animate(farm.getLocation(), Material.EGG));
|
||||
Methods.animate(farm.getLocation(), CompatibleMaterial.EGG));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class ModuleAutoButcher extends Module {
|
||||
count += stackSize;
|
||||
}
|
||||
|
||||
if (count <= 2 || !farm.willFit(new ItemStack(Material.STONE))) return;
|
||||
if (count <= 2 || !farm.willFit(CompatibleMaterial.STONE.getItem())) return;
|
||||
|
||||
for (LivingEntity entity : entities) {
|
||||
entity.setMetadata("EFA-TAGGED", new FixedMetadataValue(plugin, farm.getLocation()));
|
||||
@ -65,7 +65,7 @@ public class ModuleAutoButcher extends Module {
|
||||
CompatibleSound.ENTITY_PLAYER_ATTACK_SWEEP.getSound(), 1L, 1L);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
entity.damage(99999999, entity);
|
||||
Methods.animate(farm.getLocation(), Material.IRON_SWORD);
|
||||
Methods.animate(farm.getLocation(), CompatibleMaterial.IRON_SWORD);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.boost.BoostData;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.FarmType;
|
||||
import com.songoda.epicfarming.utils.CropType;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -63,7 +62,7 @@ public class ModuleAutoCollect extends Module {
|
||||
|
||||
private void collectCrops(Farm farm, List<Block> crops) {
|
||||
for (Block block : crops) {
|
||||
if (BlockUtils.isCropFullyGrown(block) && isEnabled(farm) && doCropDrop(farm, CompatibleMaterial.getMaterial(block).getBlockMaterial())) {
|
||||
if (BlockUtils.isCropFullyGrown(block) && isEnabled(farm) && doCropDrop(farm, CompatibleMaterial.getBlockMaterial(block.getType()))) {
|
||||
if (farm.getLevel().isAutoReplant()) {
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
BlockUtils.resetGrowthStage(block));
|
||||
@ -102,7 +101,7 @@ public class ModuleAutoCollect extends Module {
|
||||
doLivestockDrop(farm, new ItemStack(Material.EGG, 1));
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
Methods.animate(farm.getLocation(), Material.EGG));
|
||||
Methods.animate(farm.getLocation(), CompatibleMaterial.EGG));
|
||||
} else if (entity instanceof Sheep) {
|
||||
if (!((Ageable) entity).isAdult()) continue;
|
||||
((Sheep) entity).setSheared(true);
|
||||
@ -116,7 +115,7 @@ public class ModuleAutoCollect extends Module {
|
||||
doLivestockDrop(farm, wool);
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
Methods.animate(farm.getLocation(), wool.getType()));
|
||||
Methods.animate(farm.getLocation(), CompatibleMaterial.getMaterial(wool)));
|
||||
}
|
||||
ticksLived.put(entity, 0);
|
||||
}
|
||||
@ -209,19 +208,20 @@ public class ModuleAutoCollect extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doCropDrop(Farm farm, Material material) {
|
||||
CropType cropTypeData = CropType.getCropType(material);
|
||||
private boolean doCropDrop(Farm farm, CompatibleMaterial material) {
|
||||
|
||||
if (material == null || farm == null || cropTypeData == null) return false;
|
||||
if (material == null || farm == null || !material.isCrop()) return false;
|
||||
|
||||
BoostData boostData = plugin.getBoostManager().getBoost(farm.getPlacedBy());
|
||||
|
||||
ItemStack stack = new ItemStack(cropTypeData.getYieldMaterial(), (useBoneMeal(farm) ? random.nextInt(2) + 2 : 1) * (boostData == null ? 1 : boostData.getMultiplier()));
|
||||
ItemStack seedStack = new ItemStack(cropTypeData.getSeedMaterial(), random.nextInt(3) + 1 + (useBoneMeal(farm) ? 1 : 0));
|
||||
CompatibleMaterial yield = material.getCropYield();
|
||||
|
||||
ItemStack stack = yield.getItem((useBoneMeal(farm) ? random.nextInt(2) + 2 : 1) * (boostData == null ? 1 : boostData.getMultiplier()));
|
||||
ItemStack seedStack = material.getCropSeed().getItem(random.nextInt(3) + 1 + (useBoneMeal(farm) ? 1 : 0));
|
||||
|
||||
if (!farm.willFit(stack) || !farm.willFit(seedStack)) return false;
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Methods.animate(farm.getLocation(), cropTypeData.getYieldMaterial());
|
||||
Methods.animate(farm.getLocation(), yield);
|
||||
farm.addItem(stack);
|
||||
});
|
||||
if (getCollectionType(farm) != CollectionType.NO_SEEDS)
|
||||
|
@ -7,7 +7,6 @@ import com.songoda.epicfarming.farming.Crop;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.FarmType;
|
||||
import com.songoda.epicfarming.settings.Settings;
|
||||
import com.songoda.epicfarming.utils.CropType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@ -55,10 +54,13 @@ public class FarmTask extends BukkitRunnable {
|
||||
for (int fy = -2; fy <= 1; fy++) {
|
||||
for (int fz = -radius; fz <= radius; fz++) {
|
||||
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
|
||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(b2);
|
||||
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(b2.getType());
|
||||
|
||||
if (mat == null || !mat.isCrop() || !CropType.isGrowableCrop(mat.getBlockMaterial()))
|
||||
if (mat == null || !mat.isCrop()) {
|
||||
if (mat == CompatibleMaterial.STONE || mat == CompatibleMaterial.DIRT || mat == CompatibleMaterial.GRASS_BLOCK)
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (add) {
|
||||
farm.addCachedCrop(b2);
|
||||
|
@ -6,7 +6,6 @@ import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Crop;
|
||||
import com.songoda.epicfarming.farming.FarmType;
|
||||
import com.songoda.epicfarming.settings.Settings;
|
||||
import com.songoda.epicfarming.utils.CropType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -19,18 +18,17 @@ import java.util.Random;
|
||||
public class GrowthTask extends BukkitRunnable {
|
||||
|
||||
private static GrowthTask instance;
|
||||
private static EpicFarming plugin;
|
||||
|
||||
private final Map<Location, Crop> liveCrops = new HashMap<>();
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
public static GrowthTask startTask(EpicFarming pl) {
|
||||
public static GrowthTask startTask(EpicFarming plugin) {
|
||||
if (instance != null) {
|
||||
instance.cancel();
|
||||
}
|
||||
instance = new GrowthTask();
|
||||
instance.runTaskTimer(plugin = pl, 0, Settings.GROWTH_TICK_SPEED.getInt());
|
||||
instance.runTaskTimer(plugin, 0, Settings.GROWTH_TICK_SPEED.getInt());
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -43,8 +41,8 @@ public class GrowthTask extends BukkitRunnable {
|
||||
|| !crop.getFarm().isInLoadedChunk())
|
||||
continue;
|
||||
|
||||
CompatibleMaterial blockMat = CompatibleMaterial.getMaterial(crop.getLocation().getBlock());
|
||||
if (!blockMat.isCrop() || !CropType.isGrowableCrop(blockMat.getBlockMaterial())) {
|
||||
CompatibleMaterial blockMat = CompatibleMaterial.getBlockMaterial(crop.getLocation().getBlock().getType());
|
||||
if (!blockMat.isCrop()) {
|
||||
toRemove.add(crop);
|
||||
continue;
|
||||
}
|
||||
|
@ -1,114 +0,0 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public enum CropType {
|
||||
|
||||
WHEAT("Wheat", CompatibleMaterial.WHEAT, CompatibleMaterial.WHEAT, CompatibleMaterial.WHEAT_SEEDS),
|
||||
|
||||
CARROT("Carrot", CompatibleMaterial.CARROTS, CompatibleMaterial.CARROT, CompatibleMaterial.CARROT),
|
||||
|
||||
POTATO("Potato", CompatibleMaterial.POTATOES, CompatibleMaterial.POTATO, CompatibleMaterial.POTATO),
|
||||
|
||||
BEETROOT("Beetroot", CompatibleMaterial.BEETROOTS, CompatibleMaterial.BEETROOT, CompatibleMaterial.BEETROOT_SEEDS),
|
||||
|
||||
WATER_MELON_STEM("Watermelon", CompatibleMaterial.MELON_STEM, CompatibleMaterial.MELON, CompatibleMaterial.MELON_SEEDS),
|
||||
|
||||
PUMPKIN_STEM("Pumpkin", CompatibleMaterial.PUMPKIN_STEM, CompatibleMaterial.PUMPKIN, CompatibleMaterial.PUMPKIN_SEEDS),
|
||||
|
||||
NETHER_WARTS("Nether Wart", CompatibleMaterial.NETHER_WART, CompatibleMaterial.NETHER_WART, CompatibleMaterial.NETHER_WART);
|
||||
|
||||
private final String name;
|
||||
private final Material yieldMaterial, blockMaterial, seedMaterial;
|
||||
|
||||
CropType(String name, CompatibleMaterial blockMaterial, CompatibleMaterial yieldMaterial, CompatibleMaterial seedMaterial) {
|
||||
this.name = name;
|
||||
this.blockMaterial = blockMaterial.getBlockMaterial();
|
||||
this.seedMaterial = seedMaterial.getMaterial();
|
||||
this.yieldMaterial = yieldMaterial.getMaterial();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the friendly name of the crop
|
||||
*
|
||||
* @return the name of the crop
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blockMaterial that represents this crop type
|
||||
*
|
||||
* @return the represented blockMaterial
|
||||
*/
|
||||
public Material getBlockMaterial() {
|
||||
return blockMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the yield Material that represents this crop type
|
||||
*
|
||||
* @return the represented yieldMaterial
|
||||
*/
|
||||
public Material getYieldMaterial() {
|
||||
return yieldMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blockMaterial that represents the seed item for this crop type
|
||||
*
|
||||
* @return the represented seed blockMaterial
|
||||
*/
|
||||
public Material getSeedMaterial() {
|
||||
return seedMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a specific blockMaterial is an enumerated crop type or not
|
||||
*
|
||||
* @param material the blockMaterial to check
|
||||
* @return true if it is a crop, false otherwise
|
||||
*/
|
||||
public static boolean isCrop(Material material) {
|
||||
for (CropType type : values())
|
||||
if (type.getBlockMaterial() == material) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a specific blockMaterial is an enumerated crop type seed or not
|
||||
*
|
||||
* @param material the blockMaterial to check
|
||||
* @return true if it is a seed, false otherwise
|
||||
*/
|
||||
public static boolean isCropSeed(Material material) {
|
||||
for (CropType type : values())
|
||||
if (type.getSeedMaterial() == material) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the crop type based on the specified blockMaterial
|
||||
*
|
||||
* @param material the crop blockMaterial
|
||||
* @return the respective CropType. null if none found
|
||||
*/
|
||||
public static CropType getCropType(Material material) {
|
||||
for (CropType type : values())
|
||||
if (type.getBlockMaterial() == material) return type;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a crop is growable
|
||||
*
|
||||
* @param material The material to check
|
||||
* @return True if the material is of a growable crop, otherwise false
|
||||
*/
|
||||
public static boolean isGrowableCrop(Material material) {
|
||||
return CropType.isCrop(material);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -30,12 +31,12 @@ public class Methods {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static void animate(Location location, Material mat) {
|
||||
public static void animate(Location location, CompatibleMaterial mat) {
|
||||
if (!Settings.ANIMATE.getBoolean()) return;
|
||||
Block block = location.getBlock();
|
||||
if (block.getRelative(0, 1, 0).getType() != Material.AIR)
|
||||
return;
|
||||
Item i = block.getWorld().dropItem(block.getLocation().add(0.5, 1, 0.5), new ItemStack(mat));
|
||||
Item i = block.getWorld().dropItem(block.getLocation().add(0.5, 1, 0.5), mat.getItem());
|
||||
|
||||
// Support for EpicHoppers suction.
|
||||
i.setMetadata("grabbed", new FixedMetadataValue(EpicFarming.getInstance(), "true"));
|
||||
|
Loading…
Reference in New Issue
Block a user