Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
SpraxDev committed Oct 2, 2024
2 parents 6053f93 + d7af23b commit 90941db
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 45 deletions.
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.craftaro</groupId>
<artifactId>EpicFarming</artifactId>
<version>4.2.0</version>
<version>4.4.0</version>

<name>EpicFarming</name>
<description>Allow your players to grow crops faster, automatically replant, harvest and store crops and animal produce in the farm's inventory, as well as much more</description>
Expand Down Expand Up @@ -35,7 +35,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<version>3.6.0</version>

<executions>
<execution>
Expand Down Expand Up @@ -74,10 +74,10 @@
<excludeDefaults>false</excludeDefaults>
<includes>
<include>**/nms/v*/**</include>
<include>**/third_party/net/kyori/**</include>
</includes>
<excludes>
<exclude>**/third_party/org/apache/**</exclude>
<exclude>**/third_party/net/kyori/**</exclude>
<exclude>**/third_party/com/zaxxer/**</exclude>
<exclude>**/third_party/org/jooq/**</exclude>
<exclude>**/third_party/org/mariadb/**</exclude>
Expand Down Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>com.craftaro</groupId>
<artifactId>CraftaroCore</artifactId>
<version>3.0.4-SNAPSHOT</version>
<version>3.5.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand All @@ -134,6 +134,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.craftaro</groupId>
<artifactId>UltimateStacker-API</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- TODO: Check if spigot-api can be downgraded to 1.8 -->
<dependency>
<groupId>org.spigotmc</groupId>
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/craftaro/epicfarming/EpicFarming.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.craftaro.epicfarming.listeners.InteractListeners;
import com.craftaro.epicfarming.listeners.InventoryListeners;
import com.craftaro.epicfarming.listeners.MoistureListeners;
import com.craftaro.epicfarming.listeners.UltimateStackerListener;
import com.craftaro.epicfarming.listeners.UnloadListeners;
import com.craftaro.epicfarming.settings.Settings;
import com.craftaro.epicfarming.storage.Storage;
Expand Down Expand Up @@ -74,6 +75,7 @@ public class EpicFarming extends SongodaPlugin {
private FarmTask farmTask;

private EntityUtils entityUtils;
private static EpicFarming instance;

@Override
public void onPluginLoad() {
Expand All @@ -94,6 +96,7 @@ public void onPluginDisable() {

@Override
public void onPluginEnable() {
instance = this;
// Run Songoda Updater
SongodaCore.registerPlugin(this, 21, XMaterial.WHEAT);

Expand Down Expand Up @@ -155,6 +158,10 @@ public void onPluginEnable() {
}
}

if (pluginManager.isPluginEnabled("UltimateStacker")) {
pluginManager.registerEvents(new UltimateStackerListener(this), this);
}

// Start tasks
this.growthTask = new GrowthTask(this);
this.farmTask = new FarmTask(this);
Expand Down Expand Up @@ -347,7 +354,7 @@ public ItemStack makeFarmItem(Level level) {
ItemStack item = Settings.FARM_BLOCK_MATERIAL.getMaterial().parseItem();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(TextUtils.formatText(Methods.formatName(level.getLevel())));
String line = getLocale().getMessage("general.nametag.lore").getMessage();
String line = getLocale().getMessage("general.nametag.lore").toText();
if (!line.equals("")) {
meta.setLore(Collections.singletonList(line));
}
Expand Down Expand Up @@ -390,11 +397,7 @@ public EntityUtils getEntityUtils() {
return this.entityUtils;
}

/**
* @deprecated Use {@link EpicFarming#getPlugin(Class)} instead.
*/
@Deprecated
public static EpicFarming getInstance() {
return getPlugin(EpicFarming.class);
return instance;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/craftaro/epicfarming/boost/BoostData.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ public class BoostData implements Data {
private final long endTime;
private final UUID player;

// Default constructor for deserialization
public BoostData() {
this.multiplier = 0;
this.endTime = 0;
this.player = null;
}

public BoostData(int multiplier, long endTime, UUID player) {
this.multiplier = multiplier;
this.endTime = endTime;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/craftaro/epicfarming/farming/Farm.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void view(Player player, boolean force) {
}

if (Settings.USE_PROTECTION_PLUGINS.getBoolean() && !ProtectionManager.canInteract(player, this.location)) {
player.sendMessage(EpicFarming.getInstance().getLocale().getMessage("event.general.protected").getPrefixedMessage());
EpicFarming.getInstance().getLocale().getMessage("event.general.protected").sendPrefixedMessage(player);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public String translate() {
return EpicFarming.getPlugin(EpicFarming.class)
.getLocale()
.getMessage("general.interface." + name().toLowerCase())
.getMessage();
.toText();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ public void buildDescription() {
EpicFarming instance = EpicFarming.getPlugin(EpicFarming.class);

this.description.add(instance.getLocale().getMessage("interface.button.radius")
.processPlaceholder("radius", this.radius).getMessage());
.processPlaceholder("radius", this.radius).toText());

this.description.add(instance.getLocale().getMessage("interface.button.speed")
.processPlaceholder("speed", this.speedMultiplier).getMessage());
.processPlaceholder("speed", this.speedMultiplier).toText());


if (this.autoReplant) {
this.description.add(instance.getLocale().getMessage("interface.button.autoreplant")
.processPlaceholder("status",
instance.getLocale().getMessage("general.interface.unlocked")
.getMessage()).getMessage());
.toText()).toText());
}

if (this.pages > 1) {
this.description.add(instance.getLocale().getMessage("interface.button.pages")
.processPlaceholder("amount", this.pages).getMessage());
.processPlaceholder("amount", this.pages).toText());
}

for (Module module : this.registeredModules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ public void runFinal(Farm farm, Collection<LivingEntity> entitiesAroundFarm, Lis
}

List<LivingEntity> entities = new ArrayList<>(entitiesAroundFarm);
Collections.shuffle(entities);
if (entities.size() < this.autoBreedCap) {
entities.removeIf(e -> !(e instanceof Ageable) || !((Ageable) e).isAdult() || e.hasMetadata(BREED_COOLDOWN_METADATA) || e.isDead());
int actualAmount = entities.stream().filter(e -> e instanceof Ageable && ((Ageable) e).isAdult() && !e.hasMetadata(BREED_COOLDOWN_METADATA) && !e.isDead()).map(EntityStackerManager::getSize).reduce(Integer::sum).orElse(0);

if (actualAmount < this.autoBreedCap) {
return;
}

entities.removeIf(e -> !(e instanceof Ageable) || !((Ageable) e).isAdult() || e.hasMetadata(BREED_COOLDOWN_METADATA) || e.isDead());
Collections.shuffle(entities);

Map<EntityType, Long> counts = entities.stream()
.collect(Collectors.groupingBy(Entity::getType, Collectors.summingLong(entity -> {
Expand Down Expand Up @@ -100,18 +102,21 @@ public void runFinal(Farm farm, Collection<LivingEntity> entitiesAroundFarm, Lis
handleStackedBreed(entity);
}
} else {
handleBreed(entity);
handleBreedNatural(entity);
spawnParticlesAndAnimation(entity.getLocation(), farm.getLocation());
}

spawnParticlesAndAnimation(entity.getLocation(), farm.getLocation());
return;
}

farm.removeMaterial(breedingItem.getType(), 2);
if (stackSize > 1) {
handleStackedBreed(entity);
} else {
handleBreed(entity);
handleBreedNatural(entity);
}
spawnParticlesAndAnimation(entity.getLocation(), farm.getLocation());
mate1 = true;
break;
}
Expand All @@ -122,8 +127,8 @@ public void runFinal(Farm farm, Collection<LivingEntity> entitiesAroundFarm, Lis
public ItemStack getGUIButton(Farm farm) {
return GuiUtils.createButtonItem(XMaterial.EGG, this.plugin.getLocale().getMessage("interface.button.autobreeding")
.processPlaceholder("status", isEnabled(farm)
? this.plugin.getLocale().getMessage("general.interface.on").getMessage()
: this.plugin.getLocale().getMessage("general.interface.off").getMessage())
? this.plugin.getLocale().getMessage("general.interface.on").toText()
: this.plugin.getLocale().getMessage("general.interface.off").toText())
.getMessage(),
this.plugin.getLocale().getMessage("interface.button.functiontoggle").getMessage());
}
Expand All @@ -138,17 +143,25 @@ public String getDescription() {
return this.plugin.getLocale()
.getMessage("interface.button.autobreeding")
.processPlaceholder("status", this.autoBreedCap)
.getMessage();
.toText();
}

private void handleStackedBreed(LivingEntity entity) {
EntityStackerManager.removeOne(entity);
Bukkit.getScheduler().runTask(this.plugin, () -> {
LivingEntity spawned = (LivingEntity) entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
handleBreed(spawned);
Ageable ageable = (Ageable) spawned;
ageable.setBaby();
handleBreed(entity);
});
}
private void handleBreedNatural(Entity entity) {
Bukkit.getScheduler().runTask(this.plugin, () -> {
LivingEntity spawned = (LivingEntity) entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
Ageable ageable = (Ageable) spawned;
ageable.setBaby();
handleBreed(entity);
});
}

private void handleBreed(Entity entity) {
entity.setMetadata(BREED_COOLDOWN_METADATA, new FixedMetadataValue(this.plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () ->
Expand Down Expand Up @@ -182,4 +195,4 @@ private void spawnParticlesAndAnimation(Location entityLocation, Location farmLo
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.HEART, entityLocation, 5, .5, .5, .5);
Bukkit.getScheduler().runTask(this.plugin, () -> Methods.animate(farmLocation, XMaterial.EGG));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void runFinal(Farm farm, Collection<LivingEntity> entitiesAroundFarm, Lis
public ItemStack getGUIButton(Farm farm) {
return GuiUtils.createButtonItem(XMaterial.STONE_SWORD, this.plugin.getLocale().getMessage("interface.button.autobutcher")
.processPlaceholder("status", isEnabled(farm)
? this.plugin.getLocale().getMessage("general.interface.on").getMessage()
: this.plugin.getLocale().getMessage("general.interface.off").getMessage())
? this.plugin.getLocale().getMessage("general.interface.on").toText()
: this.plugin.getLocale().getMessage("general.interface.off").toText())
.getMessage(),
this.plugin.getLocale().getMessage("interface.button.functiontoggle").getMessage());
}
Expand All @@ -92,7 +92,7 @@ public void runButtonPress(Player player, Farm farm, ClickType type) {
@Override
public String getDescription() {
return this.plugin.getLocale().getMessage("interface.button.autobutcher")
.processPlaceholder("status", this.autoButcherDelay).getMessage();
.processPlaceholder("status", this.autoButcherDelay).toText();
}

private boolean isEnabled(Farm farm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ private void collectLivestock(Farm farm, Collection<LivingEntity> entitiesAround
public ItemStack getGUIButton(Farm farm) {
return GuiUtils.createButtonItem(XMaterial.BUCKET, this.plugin.getLocale().getMessage("interface.button.autocollect")
.processPlaceholder("status", isEnabled(farm)
? this.plugin.getLocale().getMessage("general.interface.on").getMessage()
: this.plugin.getLocale().getMessage("general.interface.off").getMessage()).getMessage(),
? this.plugin.getLocale().getMessage("general.interface.on").toText()
: this.plugin.getLocale().getMessage("general.interface.off").toText()).getMessage(),
this.plugin.getLocale().getMessage("interface.button.collectiontype").processPlaceholder("status", getCollectionType(farm).translate()).getMessage(),
this.plugin.getLocale().getMessage("interface.button.functiontoggle").getMessage());
}
Expand All @@ -175,8 +175,8 @@ public String getDescription() {
return this.plugin.getLocale()
.getMessage("interface.button.autocollect")
.processPlaceholder("status",
this.plugin.getLocale().getMessage("general.interface.unlocked").getMessage())
.getMessage();
this.plugin.getLocale().getMessage("general.interface.unlocked").toText())
.toText();
}

public boolean isEnabled(Farm farm) {
Expand Down Expand Up @@ -283,7 +283,7 @@ public String translate() {
return EpicFarming.getPlugin(EpicFarming.class)
.getLocale()
.getMessage("general.interface." + name().replace("_", "").toLowerCase())
.getMessage();
.toText();
}
}
}
15 changes: 8 additions & 7 deletions src/main/java/com/craftaro/epicfarming/gui/OverviewGui.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.craftaro.epicfarming.gui;

import com.craftaro.core.chat.AdventureUtils;
import com.craftaro.core.gui.CustomizableGui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
Expand Down Expand Up @@ -98,10 +99,10 @@ private void showPage() {
List<String> farmLore = this.level.getDescription();
farmLore.add("");
if (nextLevel == null) {
farmLore.add(this.plugin.getLocale().getMessage("event.upgrade.maxed").getMessage());
farmLore.add(this.plugin.getLocale().getMessage("event.upgrade.maxed").toText());
} else {
farmLore.add(this.plugin.getLocale().getMessage("interface.button.level")
.processPlaceholder("level", nextLevel.getLevel()).getMessage());
.processPlaceholder("level", nextLevel.getLevel()).toText());
farmLore.addAll(nextLevel.getDescription());
}

Expand All @@ -110,16 +111,16 @@ private void showPage() {
String[] parts = this.plugin.getLocale().getMessage("interface.button.boostedstats")
.processPlaceholder("amount", Integer.toString(boostData.getMultiplier()))
.processPlaceholder("time", TimeUtils.makeReadable(boostData.getEndTime() - System.currentTimeMillis()))
.getMessage().split("\\|");
.toText().split("\\|");
farmLore.add("");
for (String line : parts) {
farmLore.add(TextUtils.formatText(line));
farmLore.add(AdventureUtils.formatLegacy(line));
}
}

setItem("farm", 13, GuiUtils.createButtonItem(Settings.FARM_BLOCK_MATERIAL.getMaterial(XMaterial.END_ROD),
this.plugin.getLocale().getMessage("general.nametag.farm")
.processPlaceholder("level", this.level.getLevel()).getMessage(),
.processPlaceholder("level", this.level.getLevel()).toText(),
farmLore));

if (this.player != null && Settings.UPGRADE_WITH_XP.getBoolean() && this.player.hasPermission("EpicFarming.Upgrade.XP")) {
Expand Down Expand Up @@ -162,9 +163,9 @@ private void showPage() {
ItemMeta farmTypeMeta = farmType.getItemMeta();
farmTypeMeta.setDisplayName(this.plugin.getLocale().getMessage("interface.button.farmtype")
.processPlaceholder("type", this.farm.getFarmType().translate())
.getMessage());
.toText());
farmTypeMeta.setLore(Collections.singletonList(this.plugin.getLocale().getMessage("interface.button.farmtypelore")
.getMessage()));
.toText()));
farmType.setItemMeta(farmTypeMeta);

Map<Integer, Integer[]> layouts = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.craftaro.epicfarming.farming.levels.modules.ModuleAutoCollect;
import com.craftaro.epicfarming.settings.Settings;
import com.craftaro.epicfarming.farming.Farm;
import com.craftaro.ultimatestacker.api.events.entity.StackedItemSpawnEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -39,6 +40,7 @@ public EntityListeners(EpicFarming plugin) {

@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDeath(EntityDeathEvent event) {
if (event.getDrops().isEmpty()) return;
LivingEntity entity = event.getEntity();
if (!entity.hasMetadata("EFA-TAGGED")) {
return;
Expand Down
Loading

0 comments on commit 90941db

Please sign in to comment.