mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-09-30 23:57:29 +02:00
Fix for an issue where crop blocks are stacked.
This commit is contained in:
parent
86464ce6d5
commit
ff2d771aab
@ -21,25 +21,27 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class EFarm implements Farm {
|
public class EFarm implements Farm {
|
||||||
|
|
||||||
|
private static final Random random = new Random();
|
||||||
|
private final List<Block> cachedCrops = new ArrayList<>();
|
||||||
private Location location;
|
private Location location;
|
||||||
private Level level;
|
private Level level;
|
||||||
private Inventory inventory;
|
private Inventory inventory;
|
||||||
private UUID placedBy;
|
private UUID placedBy;
|
||||||
|
|
||||||
private UUID viewing = null;
|
private UUID viewing = null;
|
||||||
|
|
||||||
private long lastCached = 0;
|
private long lastCached = 0;
|
||||||
private final List<Block> cachedCrops = new ArrayList<>();
|
|
||||||
|
|
||||||
public EFarm(Location location, Level level, UUID placedBy) {
|
public EFarm(Location location, Level level, UUID placedBy) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.placedBy = placedBy;
|
this.placedBy = placedBy;
|
||||||
this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
|
this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void view(Player player) {
|
public void view(Player player) {
|
||||||
@ -66,13 +68,13 @@ public class EFarm implements Farm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupOverview(Player player) {
|
private void setupOverview(Player player) {
|
||||||
Inventory inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
|
Inventory inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(), false));
|
||||||
inventory.setContents(this.inventory.getContents());
|
inventory.setContents(this.inventory.getContents());
|
||||||
this.inventory = inventory;
|
this.inventory = inventory;
|
||||||
|
|
||||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||||
|
|
||||||
ELevel nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel()+1) : null;
|
ELevel nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel() + 1) : null;
|
||||||
|
|
||||||
int level = this.level.getLevel();
|
int level = this.level.getLevel();
|
||||||
|
|
||||||
@ -169,7 +171,7 @@ public class EFarm implements Farm {
|
|||||||
public List<ItemStack> dumpInventory() {
|
public List<ItemStack> dumpInventory() {
|
||||||
List<ItemStack> items = new ArrayList<>();
|
List<ItemStack> items = new ArrayList<>();
|
||||||
|
|
||||||
for(int i=27; i < inventory.getSize(); i++) {
|
for (int i = 27; i < inventory.getSize(); i++) {
|
||||||
items.add(inventory.getItem(i));
|
items.add(inventory.getItem(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,9 +181,9 @@ public class EFarm implements Farm {
|
|||||||
public void upgrade(UpgradeType type, Player player) {
|
public void upgrade(UpgradeType type, Player player) {
|
||||||
try {
|
try {
|
||||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||||
if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel()+1)) {
|
if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) {
|
||||||
|
|
||||||
com.songoda.epicfarming.api.farming.Level level = instance.getLevelManager().getLevel(this.level.getLevel()+1);
|
com.songoda.epicfarming.api.farming.Level level = instance.getLevelManager().getLevel(this.level.getLevel() + 1);
|
||||||
int cost;
|
int cost;
|
||||||
if (type == UpgradeType.EXPERIENCE) {
|
if (type == UpgradeType.EXPERIENCE) {
|
||||||
cost = level.getCostExperiance();
|
cost = level.getCostExperiance();
|
||||||
@ -218,7 +220,6 @@ public class EFarm implements Farm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void upgradeFinal(Level level, Player player) {
|
private void upgradeFinal(Level level, Player player) {
|
||||||
try {
|
try {
|
||||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||||
@ -229,14 +230,14 @@ public class EFarm implements Farm {
|
|||||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.successmaxed", level.getLevel()));
|
player.sendMessage(instance.getLocale().getMessage("event.upgrade.successmaxed", level.getLevel()));
|
||||||
}
|
}
|
||||||
Location loc = location.clone().add(.5, .5, .5);
|
Location loc = location.clone().add(.5, .5, .5);
|
||||||
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.getConfig().getBoolean("Main.Sounds Enabled")) {
|
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||||
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(), org.bukkit.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(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tillLand(location);
|
tillLand(location);
|
||||||
@ -245,8 +246,6 @@ public class EFarm implements Farm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Random random = new Random();
|
|
||||||
|
|
||||||
public boolean tillLand(Location location) {
|
public boolean tillLand(Location location) {
|
||||||
Player player = Bukkit.getPlayer(placedBy);
|
Player player = Bukkit.getPlayer(placedBy);
|
||||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||||
@ -264,12 +263,12 @@ public class EFarm implements Farm {
|
|||||||
|
|
||||||
// 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() == Material.TALL_GRASS || b2.getType() == Material.GRASS || b2.getType().name().contains("TULIP") || b2.getType() == Material.AZURE_BLUET ||
|
||||||
b2.getType() == Material.BLUE_ORCHID || b2.getType() == Material.ALLIUM || b2.getType() == Material.POPPY || b2.getType() == Material.DANDELION) {
|
b2.getType() == Material.BLUE_ORCHID || b2.getType() == Material.ALLIUM || b2.getType() == Material.POPPY || b2.getType() == Material.DANDELION) {
|
||||||
Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> {
|
||||||
b2.getRelative(BlockFace.DOWN).setType(Material.LEGACY_SOIL);
|
b2.getRelative(BlockFace.DOWN).setType(Material.LEGACY_SOIL);
|
||||||
b2.breakNaturally();
|
b2.breakNaturally();
|
||||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||||
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
||||||
}
|
}
|
||||||
}, random.nextInt(30) + 1);
|
}, random.nextInt(30) + 1);
|
||||||
}
|
}
|
||||||
@ -277,7 +276,7 @@ public class EFarm implements Farm {
|
|||||||
Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> {
|
||||||
b2.setType(Material.LEGACY_SOIL);
|
b2.setType(Material.LEGACY_SOIL);
|
||||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||||
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
||||||
}
|
}
|
||||||
}, random.nextInt(30) + 1);
|
}, random.nextInt(30) + 1);
|
||||||
}
|
}
|
||||||
@ -327,13 +326,13 @@ public class EFarm implements Farm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getPlacedBy() {
|
public void setLocation(Location location) {
|
||||||
return placedBy;
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLocation(Location location) {
|
public UUID getPlacedBy() {
|
||||||
this.location = location;
|
return placedBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,7 +53,6 @@ public class FarmTask extends BukkitRunnable {
|
|||||||
if (!CropType.isCrop(block.getType())) continue;
|
if (!CropType.isCrop(block.getType())) continue;
|
||||||
Crops crop = (Crops) block.getState().getData();
|
Crops crop = (Crops) block.getState().getData();
|
||||||
|
|
||||||
|
|
||||||
// Add to GrowthTask
|
// Add to GrowthTask
|
||||||
plugin.getGrowthTask().addLiveCrop(block.getLocation(), new Crop(block.getLocation(), farm));
|
plugin.getGrowthTask().addLiveCrop(block.getLocation(), new Crop(block.getLocation(), farm));
|
||||||
|
|
||||||
@ -120,6 +119,7 @@ public class FarmTask extends BukkitRunnable {
|
|||||||
public List<Block> getCrops(Farm farm, boolean add) {
|
public List<Block> getCrops(Farm farm, boolean add) {
|
||||||
if (System.currentTimeMillis() - ((EFarm)farm).getLastCached() > 30 * 1000 || !add) {
|
if (System.currentTimeMillis() - ((EFarm)farm).getLastCached() > 30 * 1000 || !add) {
|
||||||
((EFarm)farm).setLastCached(System.currentTimeMillis());
|
((EFarm)farm).setLastCached(System.currentTimeMillis());
|
||||||
|
if (add) ((EFarm)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();
|
||||||
|
Loading…
Reference in New Issue
Block a user