mirror of
https://github.com/songoda/EpicFarming.git
synced 2025-02-21 15:01:25 +01:00
Merge branch 'development'
This commit is contained in:
commit
f40ed2a7be
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>3.0.26</version>
|
||||
<version>3.1</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicFarming-${project.version}</finalName>
|
||||
|
@ -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)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicfarming.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.CustomizableGui;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
@ -25,9 +26,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class OverviewGui extends Gui {
|
||||
public class OverviewGui extends CustomizableGui {
|
||||
|
||||
private final EpicFarming plugin;
|
||||
private static final EpicFarming plugin = EpicFarming.getInstance();
|
||||
private final Farm farm;
|
||||
private final Level level;
|
||||
private final Player player;
|
||||
@ -35,7 +36,7 @@ public class OverviewGui extends Gui {
|
||||
private int task;
|
||||
|
||||
public OverviewGui(Farm farm, Player player) {
|
||||
this.plugin = EpicFarming.getInstance();
|
||||
super(plugin, "overview");
|
||||
this.farm = farm;
|
||||
this.level = farm.getLevel();
|
||||
this.player = player;
|
||||
@ -50,21 +51,21 @@ public class OverviewGui extends Gui {
|
||||
|
||||
this.setDefaultItem(null);
|
||||
|
||||
mirrorFill(0, 0, false, true, glass2);
|
||||
mirrorFill(0, 1, false, true, glass2);
|
||||
mirrorFill(0, 2, false, true, glass3);
|
||||
mirrorFill(1, 0, false, true, glass2);
|
||||
mirrorFill(1, 1, false, true, glass3);
|
||||
mirrorFill(2, 0, false, true, glass2);
|
||||
mirrorFill(2, 1, false, true, glass2);
|
||||
mirrorFill(2, 2, false, true, glass3);
|
||||
mirrorFill("mirrorfill_1", 0, 0, false, true, glass2);
|
||||
mirrorFill("mirrorfill_2", 0, 1, false, true, glass2);
|
||||
mirrorFill("mirrorfill_3", 0, 2, false, true, glass3);
|
||||
mirrorFill("mirrorfill_4", 1, 0, false, true, glass2);
|
||||
mirrorFill("mirrorfill_5", 1, 1, false, true, glass3);
|
||||
mirrorFill("mirrorfill_6", 2, 0, false, true, glass2);
|
||||
mirrorFill("mirrorfill_7", 2, 1, false, true, glass2);
|
||||
mirrorFill("mirrorfill_8", 2, 2, false, true, glass3);
|
||||
|
||||
mirrorFill(0, 3, false, true, glass1);
|
||||
mirrorFill(0, 4, false, false, glass1);
|
||||
mirrorFill(1, 3, false, true, glass1);
|
||||
mirrorFill(1, 2, false, true, glass1);
|
||||
mirrorFill(2, 3, false, true, glass1);
|
||||
mirrorFill(2, 4, false, false, glass1);
|
||||
mirrorFill("mirrorfill_9", 0, 3, false, true, glass1);
|
||||
mirrorFill("mirrorfill_10", 0, 4, false, false, glass1);
|
||||
mirrorFill("mirrorfill_11", 1, 3, false, true, glass1);
|
||||
mirrorFill("mirrorfill_12", 1, 2, false, true, glass1);
|
||||
mirrorFill("mirrorfill_13", 2, 3, false, true, glass1);
|
||||
mirrorFill("mirrorfill_14", 2, 4, false, false, glass1);
|
||||
|
||||
// enable page events
|
||||
if (level.getPages() > 1) {
|
||||
@ -112,14 +113,14 @@ public class OverviewGui extends Gui {
|
||||
farmLore.add(Methods.formatText(line));
|
||||
}
|
||||
|
||||
setItem(13, GuiUtils.createButtonItem(Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD),
|
||||
setItem("farm",13, GuiUtils.createButtonItem(Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD),
|
||||
plugin.getLocale().getMessage("general.nametag.farm")
|
||||
.processPlaceholder("level", level.getLevel()).getMessage(),
|
||||
farmLore));
|
||||
|
||||
if (player != null && Settings.UPGRADE_WITH_XP.getBoolean() && player.hasPermission("EpicFarming.Upgrade.XP")) {
|
||||
|
||||
setButton(11, GuiUtils.createButtonItem(Settings.XP_ICON.getMaterial(CompatibleMaterial.EXPERIENCE_BOTTLE),
|
||||
setButton("xp", 11, GuiUtils.createButtonItem(Settings.XP_ICON.getMaterial(CompatibleMaterial.EXPERIENCE_BOTTLE),
|
||||
plugin.getLocale().getMessage("interface.button.upgradewithxp").getMessage(),
|
||||
nextLevel != null
|
||||
? plugin.getLocale().getMessage("interface.button.upgradewithxplore")
|
||||
@ -135,7 +136,7 @@ public class OverviewGui extends Gui {
|
||||
|
||||
if (Settings.UPGRADE_WITH_ECONOMY.getBoolean() && player != null && player.hasPermission("EpicFarming.Upgrade.ECO")) {
|
||||
|
||||
setButton(15, GuiUtils.createButtonItem(Settings.ECO_ICON.getMaterial(CompatibleMaterial.SUNFLOWER),
|
||||
setButton("eco", 15, GuiUtils.createButtonItem(Settings.ECO_ICON.getMaterial(CompatibleMaterial.SUNFLOWER),
|
||||
plugin.getLocale().getMessage("interface.button.upgradewitheconomy").getMessage(),
|
||||
nextLevel != null
|
||||
? plugin.getLocale().getMessage("interface.button.upgradewitheconomylore")
|
||||
@ -188,9 +189,9 @@ public class OverviewGui extends Gui {
|
||||
for (int ii = 0; ii < amount; ii++) {
|
||||
int slot = layout[ii];
|
||||
if (ii == 0 && level.getRegisteredModules().stream().map(Module::getName).anyMatch(s -> s.equals("AutoCollect"))) {
|
||||
if (level.getRegisteredModules().stream().map(Module::getName).anyMatch(s -> s.equals("AutoButcher"))
|
||||
|| level.getRegisteredModules().stream().map(Module::getName).anyMatch(s -> s.equals("AutoBreeding")))
|
||||
setButton(slot, farmType,
|
||||
if (level.getRegisteredModules().stream().map(Module::getName).anyMatch(s -> s.equals("AutoButcher")
|
||||
|| s.equals("AutoBreeding")))
|
||||
setButton("toggle", slot, farmType,
|
||||
(event) -> {
|
||||
farm.toggleFarmType();
|
||||
if (farm.getFarmType() != FarmType.LIVESTOCK)
|
||||
@ -202,7 +203,7 @@ public class OverviewGui extends Gui {
|
||||
|
||||
Module module = modules.get(0);
|
||||
modules.remove(module);
|
||||
setButton(slot, module.getGUIButton(farm),
|
||||
setButton("module_" + module.getName().toLowerCase(), slot, module.getGUIButton(farm),
|
||||
(event) -> module.runButtonPress(player, farm, event.clickType));
|
||||
}
|
||||
}
|
||||
|
@ -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