mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-11-30 22:43:35 +01:00
Multi compatibility.
This commit is contained in:
parent
5a9e93d9da
commit
f59cf66635
@ -1,15 +1,16 @@
|
|||||||
package com.songoda.epicfarming.farming;
|
package com.songoda.epicfarming.farming;
|
||||||
|
|
||||||
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||||
|
import com.songoda.core.compatibility.CompatibleSound;
|
||||||
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
import com.songoda.core.hooks.EconomyManager;
|
import com.songoda.core.hooks.EconomyManager;
|
||||||
import com.songoda.epicfarming.EpicFarming;
|
import com.songoda.epicfarming.EpicFarming;
|
||||||
import com.songoda.epicfarming.boost.BoostData;
|
import com.songoda.epicfarming.boost.BoostData;
|
||||||
import com.songoda.epicfarming.player.PlayerData;
|
import com.songoda.epicfarming.player.PlayerData;
|
||||||
import com.songoda.epicfarming.settings.Settings;
|
import com.songoda.epicfarming.settings.Settings;
|
||||||
import com.songoda.epicfarming.utils.Methods;
|
import com.songoda.epicfarming.utils.Methods;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -96,7 +97,7 @@ public class Farm {
|
|||||||
itemmeta.setLore(lore);
|
itemmeta.setLore(lore);
|
||||||
item.setItemMeta(itemmeta);
|
item.setItemMeta(itemmeta);
|
||||||
|
|
||||||
ItemStack itemXP = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1);
|
ItemStack itemXP = Settings.XP_ICON.getMaterial().getItem();
|
||||||
ItemMeta itemmetaXP = itemXP.getItemMeta();
|
ItemMeta itemmetaXP = itemXP.getItemMeta();
|
||||||
itemmetaXP.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewithxp").getMessage());
|
itemmetaXP.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewithxp").getMessage());
|
||||||
ArrayList<String> loreXP = new ArrayList<>();
|
ArrayList<String> loreXP = new ArrayList<>();
|
||||||
@ -108,7 +109,7 @@ public class Farm {
|
|||||||
itemmetaXP.setLore(loreXP);
|
itemmetaXP.setLore(loreXP);
|
||||||
itemXP.setItemMeta(itemmetaXP);
|
itemXP.setItemMeta(itemmetaXP);
|
||||||
|
|
||||||
ItemStack itemECO = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Economy Icon")), 1);
|
ItemStack itemECO = Settings.ECO_ICON.getMaterial().getItem();
|
||||||
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
||||||
itemmetaECO.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewitheconomy").getMessage());
|
itemmetaECO.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewitheconomy").getMessage());
|
||||||
ArrayList<String> loreECO = new ArrayList<>();
|
ArrayList<String> loreECO = new ArrayList<>();
|
||||||
@ -217,20 +218,25 @@ public class Farm {
|
|||||||
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
|
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
|
||||||
}
|
}
|
||||||
Location loc = location.clone().add(.5, .5, .5);
|
Location loc = location.clone().add(.5, .5, .5);
|
||||||
|
tillLand(location);
|
||||||
|
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) return;
|
||||||
|
|
||||||
player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), loc, 200, .5, .5, .5);
|
player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), loc, 200, .5, .5, .5);
|
||||||
|
|
||||||
if (instance.getLevelManager().getHighestLevel() != level) {
|
if (instance.getLevelManager().getHighestLevel() != level) {
|
||||||
player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F);
|
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F);
|
||||||
|
|
||||||
|
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) return;
|
||||||
|
|
||||||
|
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 2F, 25.0F);
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1.2F, 35.0F), 5L);
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1.8F, 35.0F), 10L);
|
||||||
}
|
}
|
||||||
tillLand(location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tillLand(Location location) {
|
public boolean tillLand(Location location) {
|
||||||
Player player = Bukkit.getPlayer(placedBy);
|
|
||||||
EpicFarming instance = EpicFarming.getInstance();
|
|
||||||
if (Settings.DISABLE_AUTO_TIL_LAND.getBoolean()) return true;
|
if (Settings.DISABLE_AUTO_TIL_LAND.getBoolean()) return true;
|
||||||
Block block = location.getBlock();
|
Block block = location.getBlock();
|
||||||
int radius = level.getRadius();
|
int radius = level.getRadius();
|
||||||
@ -243,18 +249,25 @@ public class Farm {
|
|||||||
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.
|
// ToDo: enum for all flowers.
|
||||||
if (b2.getType() == Material.TALL_GRASS || b2.getType() == Material.GRASS || b2.getType().name().contains("TULIP") || b2.getType() == Material.AZURE_BLUET ||
|
if (b2.getType() == CompatibleMaterial.TALL_GRASS.getMaterial()
|
||||||
b2.getType() == Material.BLUE_ORCHID || b2.getType() == Material.ALLIUM || b2.getType() == Material.POPPY || b2.getType() == Material.DANDELION) {
|
|| b2.getType() == CompatibleMaterial.GRASS.getMaterial()
|
||||||
|
|| b2.getType().name().contains("TULIP")
|
||||||
|
|| b2.getType().name().contains("ORCHID")
|
||||||
|
|| b2.getType() == CompatibleMaterial.AZURE_BLUET.getMaterial()
|
||||||
|
|| b2.getType() == CompatibleMaterial.ALLIUM.getMaterial()
|
||||||
|
|| b2.getType() == CompatibleMaterial.POPPY.getMaterial()
|
||||||
|
|| b2.getType() == CompatibleMaterial.DANDELION.getMaterial()) {
|
||||||
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
|
||||||
b2.getRelative(BlockFace.DOWN).setType(Material.LEGACY_SOIL);
|
b2.getRelative(BlockFace.DOWN).setType(CompatibleMaterial.FARMLAND.getMaterial());
|
||||||
b2.breakNaturally();
|
b2.breakNaturally();
|
||||||
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
b2.getWorld().playSound(b2.getLocation(), CompatibleSound.BLOCK_GRASS_BREAK.getSound(), 10, 15);
|
||||||
}, random.nextInt(30) + 1);
|
}, random.nextInt(30) + 1);
|
||||||
}
|
}
|
||||||
if ((b2.getType() == Material.GRASS_BLOCK || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
|
if ((b2.getType() == CompatibleMaterial.GRASS_BLOCK.getMaterial()
|
||||||
|
|| b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
|
||||||
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
|
||||||
b2.setType(Material.LEGACY_SOIL);
|
b2.setType(CompatibleMaterial.FARMLAND.getMaterial());
|
||||||
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
b2.getWorld().playSound(b2.getLocation(), CompatibleSound.BLOCK_GRASS_BREAK.getSound(), 10, 15);
|
||||||
}, random.nextInt(30) + 1);
|
}, random.nextInt(30) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.songoda.epicfarming.listeners;
|
package com.songoda.epicfarming.listeners;
|
||||||
|
|
||||||
import com.songoda.epicfarming.EpicFarming;
|
import com.songoda.epicfarming.EpicFarming;
|
||||||
|
import com.songoda.epicfarming.settings.Settings;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -22,7 +23,8 @@ public class InteractListeners implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockInteract(PlayerInteractEvent e) {
|
public void onBlockInteract(PlayerInteractEvent e) {
|
||||||
if (e.getClickedBlock() == null || e.getClickedBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
|
if (e.getClickedBlock() == null
|
||||||
|
|| e.getClickedBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.songoda.epicfarming.settings;
|
package com.songoda.epicfarming.settings;
|
||||||
|
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
import com.songoda.core.configuration.Config;
|
import com.songoda.core.configuration.Config;
|
||||||
import com.songoda.core.configuration.ConfigSetting;
|
import com.songoda.core.configuration.ConfigSetting;
|
||||||
import com.songoda.core.hooks.EconomyManager;
|
import com.songoda.core.hooks.EconomyManager;
|
||||||
@ -30,7 +31,7 @@ public class Settings {
|
|||||||
public static final ConfigSetting GROWTH_TICK_SPEED = new ConfigSetting(config, "Main.Growth Tick Speed", 20,
|
public static final ConfigSetting GROWTH_TICK_SPEED = new ConfigSetting(config, "Main.Growth Tick Speed", 20,
|
||||||
"The delay in ticks between each farm entity event.");
|
"The delay in ticks between each farm entity event.");
|
||||||
|
|
||||||
public static final ConfigSetting FARM_BLOCK_MATERIAL = new ConfigSetting(config, "Main.Farm Block Material", "END_ROD",
|
public static final ConfigSetting FARM_BLOCK_MATERIAL = new ConfigSetting(config, "Main.Farm Block Material", ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9) ? "END_ROD" : "TORCH",
|
||||||
"What material should be used as a farm item?");
|
"What material should be used as a farm item?");
|
||||||
|
|
||||||
public static final ConfigSetting NON_COMMAND_FARMS = new ConfigSetting(config, "Main.Allow Non Command Issued Farm Items", false,
|
public static final ConfigSetting NON_COMMAND_FARMS = new ConfigSetting(config, "Main.Allow Non Command Issued Farm Items", false,
|
||||||
|
@ -61,11 +61,7 @@ public class FarmTask extends BukkitRunnable {
|
|||||||
if (!doDrop(farm, block.getType())) continue main;
|
if (!doDrop(farm, block.getType())) continue main;
|
||||||
|
|
||||||
if (farm.getLevel().isAutoReplant()) {
|
if (farm.getLevel().isAutoReplant()) {
|
||||||
BlockState cropState = block.getState();
|
CropType.replant(block);
|
||||||
Crops cropData = (Crops) cropState.getData();
|
|
||||||
cropData.setState(CropState.VERY_SMALL);
|
|
||||||
cropState.setData(cropData);
|
|
||||||
cropState.update();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
@ -116,9 +112,9 @@ public class FarmTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Block> getCrops(Farm farm, boolean add) {
|
public List<Block> getCrops(Farm farm, boolean add) {
|
||||||
if (System.currentTimeMillis() - ((Farm) farm).getLastCached() > 30 * 1000 || !add) {
|
if (((System.currentTimeMillis() - farm.getLastCached()) > (30 * 1000)) || !add) {
|
||||||
((Farm) farm).setLastCached(System.currentTimeMillis());
|
farm.setLastCached(System.currentTimeMillis());
|
||||||
if (add) ((Farm) farm).clearCache();
|
if (add) farm.clearCache();
|
||||||
Block block = farm.getLocation().getBlock();
|
Block block = farm.getLocation().getBlock();
|
||||||
int radius = farm.getLevel().getRadius();
|
int radius = farm.getLevel().getRadius();
|
||||||
int bx = block.getX();
|
int bx = block.getX();
|
||||||
@ -132,10 +128,10 @@ public class FarmTask extends BukkitRunnable {
|
|||||||
if (!(b2.getState().getData() instanceof Crops)) continue;
|
if (!(b2.getState().getData() instanceof Crops)) continue;
|
||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
((Farm) farm).addCachedCrop(b2);
|
farm.addCachedCrop(b2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
((Farm) farm).removeCachedCrop(b2);
|
farm.removeCachedCrop(b2);
|
||||||
plugin.getGrowthTask().removeCropByLocation(b2.getLocation());
|
plugin.getGrowthTask().removeCropByLocation(b2.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package com.songoda.epicfarming.tasks;
|
|||||||
|
|
||||||
import com.songoda.epicfarming.EpicFarming;
|
import com.songoda.epicfarming.EpicFarming;
|
||||||
import com.songoda.epicfarming.farming.Crop;
|
import com.songoda.epicfarming.farming.Crop;
|
||||||
|
import com.songoda.epicfarming.utils.CropHandler;
|
||||||
|
import com.songoda.epicfarming.utils.CropType;
|
||||||
import org.bukkit.CropState;
|
import org.bukkit.CropState;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -42,63 +44,30 @@ public class GrowthTask extends BukkitRunnable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(crop.getLocation().getBlock().getState().getData() instanceof Crops)) {
|
if (!CropType.isGrowableCrop(crop.getLocation().getBlock().getType())) {
|
||||||
toRemove.add(crop);
|
toRemove.add(crop);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ToDO: This should be in config.
|
// TODO: This should be in config.
|
||||||
int cap = (int)Math.ceil(60 / crop.getFarm().getLevel().getSpeedMultiplier()) - crop.getTicksLived();
|
int cap = (int)Math.ceil(60 / crop.getFarm().getLevel().getSpeedMultiplier()) - crop.getTicksLived();
|
||||||
if (cap > 2) {
|
if (cap > 2) {
|
||||||
int rand = random.nextInt(cap) + 1;
|
int rand = random.nextInt(cap) + 1;
|
||||||
|
|
||||||
crop.setTicksLived(crop.getTicksLived() + 1);
|
crop.setTicksLived(crop.getTicksLived() + 1);
|
||||||
if (rand != cap - 1 && crop.getTicksLived() != cap / 2) continue;
|
if (rand != cap - 1 && crop.getTicksLived() != cap / 2) continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockState cropState = crop.getLocation().getBlock().getState();
|
CropType.grow(crop);
|
||||||
Crops cropData = (Crops) cropState.getData();
|
|
||||||
|
|
||||||
Material material = crop.getLocation().getBlock().getType();
|
|
||||||
|
|
||||||
switch(cropData.getState()) {
|
|
||||||
case SEEDED:
|
|
||||||
if (material == Material.BEETROOTS)
|
|
||||||
cropData.setState(CropState.VERY_SMALL);
|
|
||||||
else
|
|
||||||
cropData.setState(CropState.GERMINATED);
|
|
||||||
break;
|
|
||||||
case GERMINATED:
|
|
||||||
cropData.setState(CropState.VERY_SMALL);
|
|
||||||
break;
|
|
||||||
case VERY_SMALL:
|
|
||||||
cropData.setState(CropState.SMALL);
|
|
||||||
break;
|
|
||||||
case SMALL:
|
|
||||||
cropData.setState(CropState.MEDIUM);
|
|
||||||
break;
|
|
||||||
case MEDIUM:
|
|
||||||
cropData.setState(CropState.TALL);
|
|
||||||
break;
|
|
||||||
case TALL:
|
|
||||||
cropData.setState(CropState.VERY_TALL);
|
|
||||||
break;
|
|
||||||
case VERY_TALL:
|
|
||||||
cropData.setState(CropState.RIPE);
|
|
||||||
break;
|
|
||||||
case RIPE:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cropState.setData(cropData);
|
|
||||||
cropState.update();
|
|
||||||
crop.setTicksLived(1);
|
crop.setTicksLived(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
for (Crop crop : toRemove)
|
for (Crop crop : toRemove)
|
||||||
liveCrops.remove(crop);
|
liveCrops.remove(crop.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addLiveCrop(Location location, Crop crop) {
|
public void addLiveCrop(Location location, Crop crop) {
|
||||||
if (!liveCrops.containsKey(location))
|
if (!liveCrops.containsKey(location))
|
||||||
liveCrops.put(location, crop);
|
liveCrops.put(location, crop);
|
||||||
|
@ -1,27 +1,34 @@
|
|||||||
package com.songoda.epicfarming.utils;
|
package com.songoda.epicfarming.utils;
|
||||||
|
|
||||||
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
|
import com.songoda.epicfarming.farming.Crop;
|
||||||
|
import org.bukkit.CropState;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.material.Crops;
|
||||||
|
|
||||||
public enum CropType {
|
public enum CropType {
|
||||||
|
|
||||||
WHEAT("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS),
|
WHEAT("Wheat", CompatibleMaterial.WHEAT, CompatibleMaterial.WHEAT, CompatibleMaterial.WHEAT_SEEDS),
|
||||||
|
|
||||||
CARROT("Carrot", Material.CARROTS, Material.CARROT, Material.CARROT),
|
CARROT("Carrot", CompatibleMaterial.CARROTS, CompatibleMaterial.CARROT, CompatibleMaterial.CARROT),
|
||||||
|
|
||||||
POTATO("Potato", Material.POTATOES, Material.POTATO, Material.POTATO),
|
POTATO("Potato", CompatibleMaterial.POTATOES, CompatibleMaterial.POTATO, CompatibleMaterial.POTATO),
|
||||||
|
|
||||||
BEETROOT("Beetroot", Material.BEETROOTS, Material.BEETROOT, Material.BEETROOT_SEEDS),
|
BEETROOT("Beetroot", CompatibleMaterial.BEETROOTS, CompatibleMaterial.BEETROOT, CompatibleMaterial.BEETROOT_SEEDS),
|
||||||
|
|
||||||
WATER_MELON_STEM("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS),
|
WATER_MELON_STEM("Watermelon", CompatibleMaterial.MELON_STEM, CompatibleMaterial.MELON, CompatibleMaterial.MELON_SEEDS),
|
||||||
|
|
||||||
PUMPKIN_STEM("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS),
|
PUMPKIN_STEM("Pumpkin", CompatibleMaterial.PUMPKIN_STEM, CompatibleMaterial.PUMPKIN, CompatibleMaterial.PUMPKIN_SEEDS),
|
||||||
|
|
||||||
NETHER_WARTS("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WART, Material.NETHER_WART);
|
NETHER_WARTS("Nether Wart", CompatibleMaterial.NETHER_WART_BLOCK, CompatibleMaterial.NETHER_WART, CompatibleMaterial.NETHER_WART);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Material yieldMaterial, blockMaterial, seedMaterial;
|
private final CompatibleMaterial yieldMaterial, blockMaterial, seedMaterial;
|
||||||
|
|
||||||
CropType(String name, Material blockMaterial, Material yieldMaterial, Material seedMaterial) {
|
CropType(String name, CompatibleMaterial blockMaterial, CompatibleMaterial yieldMaterial, CompatibleMaterial seedMaterial) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.blockMaterial = blockMaterial;
|
this.blockMaterial = blockMaterial;
|
||||||
this.seedMaterial = seedMaterial;
|
this.seedMaterial = seedMaterial;
|
||||||
@ -44,7 +51,7 @@ public enum CropType {
|
|||||||
* @return the represented blockMaterial
|
* @return the represented blockMaterial
|
||||||
*/
|
*/
|
||||||
public Material getBlockMaterial() {
|
public Material getBlockMaterial() {
|
||||||
return blockMaterial;
|
return blockMaterial.getMaterial();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +60,7 @@ public enum CropType {
|
|||||||
* @return the represented yieldMaterial
|
* @return the represented yieldMaterial
|
||||||
*/
|
*/
|
||||||
public Material getYieldMaterial() {
|
public Material getYieldMaterial() {
|
||||||
return yieldMaterial;
|
return yieldMaterial.getMaterial();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +69,7 @@ public enum CropType {
|
|||||||
* @return the represented seed blockMaterial
|
* @return the represented seed blockMaterial
|
||||||
*/
|
*/
|
||||||
public Material getSeedMaterial() {
|
public Material getSeedMaterial() {
|
||||||
return seedMaterial;
|
return seedMaterial.getMaterial();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,4 +108,121 @@ public enum CropType {
|
|||||||
return null;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a crop is at its max growth stage
|
||||||
|
*
|
||||||
|
* @param block The crop block to check
|
||||||
|
* @return True if the crop is at its max growth stage, otherwise false
|
||||||
|
*/
|
||||||
|
public static boolean isMaxGrowthStage(Block block) {
|
||||||
|
if (!isGrowableCrop(block.getType()))
|
||||||
|
throw new IllegalArgumentException("Block given was not a valid crop");
|
||||||
|
|
||||||
|
return block.getData() >= getMaxGrowthStage(block.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the max growth stage for the given material
|
||||||
|
*
|
||||||
|
* @param material The material of the crop
|
||||||
|
* @return The max growth stage of the given crop type
|
||||||
|
*/
|
||||||
|
public static int getMaxGrowthStage(Material material) {
|
||||||
|
if (!isGrowableCrop(material))
|
||||||
|
throw new IllegalArgumentException("Block given was not a valid crop");
|
||||||
|
|
||||||
|
if (material.equals(CompatibleMaterial.BEETROOTS.getMaterial()))
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grows a crop by 1 growth stage
|
||||||
|
*
|
||||||
|
* @param crop The crop to grow
|
||||||
|
*/
|
||||||
|
public static void grow(Crop crop) {
|
||||||
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||||
|
BlockState cropState = crop.getLocation().getBlock().getState();
|
||||||
|
Crops cropData = (Crops) cropState.getData();
|
||||||
|
|
||||||
|
Material material = crop.getLocation().getBlock().getType();
|
||||||
|
|
||||||
|
switch (cropData.getState()) {
|
||||||
|
case SEEDED:
|
||||||
|
if (material == Material.BEETROOTS)
|
||||||
|
cropData.setState(CropState.VERY_SMALL);
|
||||||
|
else
|
||||||
|
cropData.setState(CropState.GERMINATED);
|
||||||
|
break;
|
||||||
|
case GERMINATED:
|
||||||
|
cropData.setState(CropState.VERY_SMALL);
|
||||||
|
break;
|
||||||
|
case VERY_SMALL:
|
||||||
|
cropData.setState(CropState.SMALL);
|
||||||
|
break;
|
||||||
|
case SMALL:
|
||||||
|
cropData.setState(CropState.MEDIUM);
|
||||||
|
break;
|
||||||
|
case MEDIUM:
|
||||||
|
cropData.setState(CropState.TALL);
|
||||||
|
break;
|
||||||
|
case TALL:
|
||||||
|
cropData.setState(CropState.VERY_TALL);
|
||||||
|
break;
|
||||||
|
case VERY_TALL:
|
||||||
|
cropData.setState(CropState.RIPE);
|
||||||
|
break;
|
||||||
|
case RIPE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cropState.setData(cropData);
|
||||||
|
cropState.update();
|
||||||
|
crop.setTicksLived(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block block = crop.getLocation().getBlock();
|
||||||
|
|
||||||
|
if (!isGrowableCrop(block.getType()))
|
||||||
|
throw new IllegalArgumentException("Block given was not a valid crop");
|
||||||
|
|
||||||
|
byte data = block.getData();
|
||||||
|
|
||||||
|
if (isMaxGrowthStage(block))
|
||||||
|
return;
|
||||||
|
|
||||||
|
block.setData((byte) (data + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a crop's growth back to stage 0
|
||||||
|
*
|
||||||
|
* @param block The crop block to set
|
||||||
|
*/
|
||||||
|
public static void replant(Block block) {
|
||||||
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||||
|
BlockState cropState = block.getState();
|
||||||
|
Crops cropData = (Crops) cropState.getData();
|
||||||
|
cropData.setState(CropState.SEEDED);
|
||||||
|
cropState.setData(cropData);
|
||||||
|
cropState.update();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isGrowableCrop(block.getType()))
|
||||||
|
throw new IllegalArgumentException("Block given was not a valid crop");
|
||||||
|
|
||||||
|
block.setData((byte) 0);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user