Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.niko302</groupId>
<artifactId>AutoReplant</artifactId>
<version>2.4</version>
<version>2.5</version>
<packaging>jar</packaging>

<name>AutoReplant</name>
Expand All @@ -30,9 +30,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<version>3.6.2</version>
<configuration>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>com.tcoded:FoliaLib</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
Expand All @@ -42,6 +50,10 @@
<pattern>com.jeff_media.updatechecker</pattern>
<shadedPattern>me.niko302.autoreplant.updatechecker</shadedPattern>
</relocation>
<relocation>
<pattern>com.tcoded.folialib</pattern>
<shadedPattern>me.niko302.autoreplant.folialib</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
Expand All @@ -65,23 +77,23 @@
<repositories>
<!-- Spigot -->
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>

<!-- UpdateChecker -->
<!-- TCoded FoliaLib -->
<repository>
<id>jeff-media-public</id>
<url>https://hub.jeff-media.com/nexus/repository/jeff-media-public/</url>
<id>tcoded-releases</id>
<url>https://repo.tcoded.com/releases</url>
</repository>
</repositories>

<dependencies>
<!-- Spigot -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand All @@ -93,19 +105,11 @@
<scope>compile</scope>
</dependency>

<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>

<!-- Update Checker -->
<!-- FoliaLib -->
<dependency>
<groupId>com.jeff_media</groupId>
<artifactId>SpigotUpdateChecker</artifactId>
<version>3.0.3</version>
<groupId>com.tcoded</groupId>
<artifactId>FoliaLib</artifactId>
<version>0.5.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
51 changes: 13 additions & 38 deletions src/main/java/me/niko302/autoreplant/AutoReplant.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package me.niko302.autoreplant;

import com.jeff_media.updatechecker.UpdateCheckSource;
import com.jeff_media.updatechecker.UpdateChecker;
import com.jeff_media.updatechecker.UserAgentBuilder;
import lombok.Getter;
import com.tcoded.folialib.FoliaLib;
import me.niko302.autoreplant.commands.AutoReplantCommand;
import me.niko302.autoreplant.config.ConfigManager;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -18,7 +14,6 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.ServerOperator;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
Expand All @@ -27,16 +22,20 @@
import java.util.List;
import java.util.UUID;

@Getter
public class AutoReplant extends JavaPlugin implements Listener {

private final List<UUID> enabledPlayers = new ArrayList<>();

private ConfigManager configManager;

private FoliaLib foliaLib;

@Override
public void onEnable() {
super.onEnable();

configManager = new ConfigManager(this);
foliaLib = new FoliaLib(this);

getCommand("autoreplant").setExecutor(new AutoReplantCommand(this)); // Registering the command executor
getServer().getPluginManager().registerEvents(this, this);
Expand All @@ -45,40 +44,12 @@ public void onEnable() {

// Load autoreplant state from data.yml
loadPlayerStates();

new UpdateChecker(this, UpdateCheckSource.SPIGOT, "117106")
.setNotifyRequesters(false)
.setNotifyOpsOnJoin(false)
.setUserAgent(UserAgentBuilder.getDefaultUserAgent())
.checkEveryXHours(12)
.onSuccess((commandSenders, latestVersion) -> {
String messagePrefix = "&8[&6Auto Replant&8] ";
String currentVersion = getDescription().getVersion();

if (currentVersion.equalsIgnoreCase(latestVersion)) {
String updateMessage = color(messagePrefix + "&aYou are using the latest version of AutoReplant!");

Bukkit.getConsoleSender().sendMessage(updateMessage);
Bukkit.getOnlinePlayers().stream().filter(ServerOperator::isOp).forEach(player -> player.sendMessage(updateMessage));
return;
}

List<String> updateMessages = List.of(
color(messagePrefix + "&cYour version of AutoReplant is outdated!"),
color(String.format(messagePrefix + "&cYou are using %s, latest is %s!", currentVersion, latestVersion)),
color(messagePrefix + "&cDownload latest here:"),
color("&6https://www.spigotmc.org/resources/autoreplant-1-20.117106/")
);

Bukkit.getConsoleSender().sendMessage(updateMessages.toArray(new String[]{}));
Bukkit.getOnlinePlayers().stream().filter(ServerOperator::isOp).forEach(player -> player.sendMessage(updateMessages.toArray(new String[]{})));
})
.onFail((commandSenders, e) -> {}).checkNow();
}

@Override
public void onDisable() {

super.onDisable();
foliaLib.getScheduler().cancelAllTasks();
}

private String color(String message) {
Expand Down Expand Up @@ -117,7 +88,7 @@ public void onBlockBreak(BlockBreakEvent event) {
// Capture the direction of the cocoa block before breaking it

// Schedule the replanting task
getServer().getScheduler().runTaskLater(this, () -> {
foliaLib.getScheduler().runAtLocationLater(block.getLocation(), () -> {
block.setType(blockType);

ageable.setAge(0);
Expand Down Expand Up @@ -157,4 +128,8 @@ private void loadPlayerStates() {
}
}

public List<UUID> getEnabledPlayers() {
return enabledPlayers;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.niko302.autoreplant.commands;

import lombok.AccessLevel;
import lombok.Getter;
import me.niko302.autoreplant.AutoReplant;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.Command;
Expand All @@ -16,7 +14,6 @@ public class AutoReplantCommand implements CommandExecutor {

private final AutoReplant plugin;

@Getter(AccessLevel.NONE)
private final Pattern hexColorExtractor = Pattern.compile("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})");

public AutoReplantCommand(AutoReplant plugin) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/me/niko302/autoreplant/config/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
package me.niko302.autoreplant.config;

import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.List;
import java.util.stream.Collectors;

@Getter
public class ConfigManager {

@Getter(AccessLevel.NONE)
private final JavaPlugin plugin;
private final Plugin plugin;

@Getter(AccessLevel.NONE)
private FileConfiguration config;

private boolean useFortune; // Variable to store the use-fortune setting
private boolean autoreplantEnabled; // Variable to store the autoreplant status
private boolean ignoreToolRestrictions; // Variable to store the ignore-tool-restrictions status

public ConfigManager(JavaPlugin plugin) {
public ConfigManager(Plugin plugin) {
this.plugin = plugin;
loadConfig();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ description: Automatically replants crops when harvested with specific tools.
main: me.niko302.autoreplant.AutoReplant
api-version: '1.20'
authors: [ Niko302, BitByLogic ]
folia-supported: true

commands:
autoreplant:
description: 'Toggle autoreplant feature'
usage: /autoreplant
permission: autoreplant.use

permissions:
autoreplant.use:
Expand Down