Merge branch 'development'

This commit is contained in:
Fernando Pettinelli 2021-12-22 01:33:57 -03:00
commit 1a3775fd83
8 changed files with 34 additions and 16 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.songoda</groupId>
<artifactId>EpicFarming</artifactId>
<version>3.1.4</version>
<version>3.2.0</version>
<build>
<defaultGoal>clean install</defaultGoal>
@ -117,20 +117,21 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.17</version>
<version>1.18</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore</artifactId>
<version>LATEST</version>
<version>2.6.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>skyblock</artifactId>
<version>2.2.13</version>
<version>2.3.30</version>
</dependency>
</dependencies>
</project>

View File

@ -71,7 +71,6 @@ public class EpicFarming extends SongodaPlugin {
private static EpicFarming INSTANCE;
private final Config dataConfig = new Config(this, "data.yml");
private final Config levelsFile = new Config(this, "levels.yml");
private final GuiManager guiManager = new GuiManager(this);
@ -104,7 +103,8 @@ public class EpicFarming extends SongodaPlugin {
saveToFile();
for (Farm farm : farmManager.getFarms().values())
dataManager.updateItems(farm);
if (farm.needsToBeSaved())
dataManager.updateItems(farm);
}
@Override
@ -185,7 +185,8 @@ public class EpicFarming extends SongodaPlugin {
saveToFile();
for (Farm farm : farmManager.getFarms().values())
dataManager.updateItemsAsync(farm);
if (farm.needsToBeSaved())
dataManager.updateItemsAsync(farm);
}, 6000, 6000);
}

View File

@ -155,6 +155,7 @@ public class DataManager extends DataManagerAbstract {
statement.executeBatch();
}
});
farm.setNeedsToBeSaved(false);
}
public void getFarms(Consumer<Map<Integer, Farm>> callback) {

View File

@ -35,6 +35,8 @@ public class Farm {
// Id for database usage.
private int id;
private boolean needsToBeSaved = false;
private static final Random random = new Random();
private final List<Block> cachedCrops = new ArrayList<>();
private final List<ItemStack> items = new ArrayList<>();
@ -85,7 +87,7 @@ public class Farm {
Level level = instance.getLevelManager().getLevel(this.level.getLevel() + 1);
int cost;
if (type == UpgradeType.EXPERIENCE) {
cost = level.getCostExperiance();
cost = level.getCostExperience();
} else {
cost = level.getCostEconomy();
}
@ -191,6 +193,7 @@ public class Farm {
// Should be used in sync.
public void addItem(ItemStack toAdd) {
needsToBeSaved = true;
synchronized (items) {
for (ItemStack item : new ArrayList<>(items)) {
if (item.getType() != toAdd.getType()
@ -207,6 +210,7 @@ public class Farm {
}
public void removeMaterial(Material material, int amount) {
needsToBeSaved = true;
synchronized (items) {
for (ItemStack item : getItems().toArray(new ItemStack[0])) {
if (material == item.getType()) {
@ -238,6 +242,7 @@ public class Farm {
}
public void setItems(List<ItemStack> items) {
needsToBeSaved = true;
synchronized (this.items) {
this.items.clear();
this.items.addAll(items);
@ -356,4 +361,12 @@ public class Farm {
public void setId(int id) {
this.id = id;
}
public boolean needsToBeSaved() {
return needsToBeSaved;
}
public void setNeedsToBeSaved(boolean needsToBeSaved) {
this.needsToBeSaved = needsToBeSaved;
}
}

View File

@ -10,20 +10,21 @@ public class Level {
private final ArrayList<Module> registeredModules;
private List<String> description = new ArrayList<>();
private int level, costExperiance, costEconomy, radius, pages;
private int level, costExperience, costEconomy, radius, pages;
private double speedMultiplier;
private boolean autoReplant;
Level(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoReplant, int pages, ArrayList<Module> registeredModules) {
Level(int level, int costExperience, int costEconomy, double speedMultiplier, int radius, boolean autoReplant, int pages, ArrayList<Module> registeredModules) {
this.level = level;
this.costExperiance = costExperiance;
this.costExperience = costExperience;
this.costEconomy = costEconomy;
this.speedMultiplier = speedMultiplier;
this.radius = radius;
this.autoReplant = autoReplant;
this.pages = pages;
this.registeredModules = registeredModules;
buildDescription();
}
@ -76,8 +77,8 @@ public class Level {
return speedMultiplier;
}
public int getCostExperiance() {
return costExperiance;
public int getCostExperience() {
return costExperience;
}
public int getCostEconomy() {

View File

@ -123,7 +123,7 @@ public class OverviewGui extends CustomizableGui {
plugin.getLocale().getMessage("interface.button.upgradewithxp").getMessage(),
nextLevel != null
? plugin.getLocale().getMessage("interface.button.upgradewithxplore")
.processPlaceholder("cost", nextLevel.getCostExperiance()).getMessage()
.processPlaceholder("cost", nextLevel.getCostExperience()).getMessage()
: plugin.getLocale().getMessage("event.upgrade.maxed").getMessage()),
event -> {
farm.upgrade(UpgradeType.EXPERIENCE, player);

View File

@ -1,6 +1,7 @@
package com.songoda.epicfarming.tasks;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.utils.BlockUtils;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.farming.Crop;
@ -76,7 +77,7 @@ public class FarmTask extends BukkitRunnable {
public void run() {
GrowthTask growthTask = plugin.getGrowthTask();
if (growthTask.isCancelled()) return;
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9) && growthTask.isCancelled()) return;
for (Farm farm : new ArrayList<>(plugin.getFarmManager().getFarms().values())) {
if (!plugin.isEnabled()) return; // Prevent registering a task on plugin disable

View File

@ -2,7 +2,7 @@ name: EpicFarming
description: EpicFarming
main: com.songoda.epicfarming.EpicFarming
version: maven-version-number
softdepend: [FabledSkyBlock, Arconix, SkyBlock, Towny, RedProtect, Kingdoms, PlotSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, PlaceholderAPI, Vault, PlayerPoints, Reserve, StackMob, UltimateStacker, WildStacker]
softdepend: [FabledSkyBlock, Arconix, SkyBlock, Towny, RedProtect, Kingdoms, PlotSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, PlaceholderAPI, Vault, PlayerPoints, Reserve, StackMob, UltimateStacker, WildStacker, DecentHolograms]
author: Songoda
api-version: 1.13
commands: