Skip to content
Merged
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
19 changes: 19 additions & 0 deletions src/main/java/top/modpotato/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import top.modpotato.listeners.ContainerTransferListener;
import top.modpotato.commands.AntiNetheriteCommand;
import top.modpotato.config.Config;
import top.modpotato.restoration.RestorationProgressTracker;
import top.modpotato.scheduler.NetheriteRemover;
import top.modpotato.util.DebrisStorage;
import top.modpotato.util.NetheriteDetector;
Expand All @@ -25,6 +26,7 @@ public class Main extends JavaPlugin {
private NetheriteRemover netheriteRemover;
private NetheriteDetector netheriteDetector;
private DebrisStorage debrisStorage;
private RestorationProgressTracker restorationProgressTracker;

private CraftListener craftListener;
private EquipListener equipListener;
Expand Down Expand Up @@ -53,6 +55,10 @@ public void onEnable() {
// Initialize debris storage
debrisStorage = new DebrisStorage(this, config);

// Initialize restoration progress tracker
restorationProgressTracker = new RestorationProgressTracker(this);
restorationProgressTracker.start();

// Check if running on Folia
isFolia = checkFolia();
getLogger().info("Running on " + (isFolia ? "Folia" : "Bukkit") + " server");
Expand Down Expand Up @@ -84,6 +90,11 @@ public void onDisable() {
isShuttingDown = true;

try {
// Stop restoration progress tracker
if (restorationProgressTracker != null) {
restorationProgressTracker.stop();
}

// Stop tasks
if (netheriteRemover != null) {
netheriteRemover.stop();
Expand Down Expand Up @@ -330,6 +341,14 @@ public DebrisStorage getDebrisStorage() {
return debrisStorage;
}

/**
* Gets the restoration progress tracker
* @return The restoration progress tracker
*/
public RestorationProgressTracker getRestorationProgressTracker() {
return restorationProgressTracker;
}

/**
* Checks if the plugin is shutting down
* @return true if the plugin is shutting down, false otherwise
Expand Down
108 changes: 84 additions & 24 deletions src/main/java/top/modpotato/commands/AntiNetheriteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;

import top.modpotato.Main;
import top.modpotato.restoration.RestorationSession;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -79,6 +81,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
plugin.reloadPluginConfig();
sender.sendMessage(Component.text("AntiNetherite configuration reloaded.").color(NamedTextColor.GREEN));
return true;
case "restore-feedback":
return handleRestoreFeedback(sender, args);
case "restore-debris":
// Get the configured cooldown in milliseconds
int cooldownSeconds = plugin.getConfig().getInt("anti-netherite.advanced.command-cooldown-seconds", 5);
Expand Down Expand Up @@ -129,19 +133,26 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

sender.sendMessage(Component.text("Restoring " + worldLocations + " Ancient Debris in world " + worldName + "...").color(NamedTextColor.YELLOW));
// Schedule restoration and get session
RestorationSession session = plugin.getDebrisStorage().scheduleRestoreInWorld(sender, world);

// Run the restoration on the main thread (delegating Folia handling to DebrisStorage)
Bukkit.getScheduler().runTask(plugin, () -> {
try {
int count = plugin.getDebrisStorage().restoreDebrisInWorld(world);
sender.sendMessage(Component.text("Restored " + count + " Ancient Debris blocks in world " + worldName + ".").color(NamedTextColor.GREEN));
} catch (Exception e) {
sender.sendMessage(Component.text("Error restoring Ancient Debris: " + e.getMessage()).color(NamedTextColor.RED));
plugin.getLogger().severe("Error restoring Ancient Debris: " + e.getMessage());
e.printStackTrace();
}
});
if (session == null) {
sender.sendMessage(Component.text("No Ancient Debris locations to restore in world " + worldName + ".").color(NamedTextColor.YELLOW));
return true;
}

// Register session with progress tracker
plugin.getRestorationProgressTracker().registerSession(session);

// Send immediate scheduling summary
sender.sendMessage(Component.text("Scheduled restoration for ")
.color(NamedTextColor.GREEN)
.append(Component.text(session.getScheduledChunks()).color(NamedTextColor.GOLD))
.append(Component.text(" chunks, ").color(NamedTextColor.GREEN))
.append(Component.text(session.getTotalLocations()).color(NamedTextColor.GOLD))
.append(Component.text(" locations in world ").color(NamedTextColor.GREEN))
.append(Component.text(worldName).color(NamedTextColor.GOLD))
.append(Component.text(".").color(NamedTextColor.GREEN)));
} else {
// Global restore
// Check if there are any locations to restore
Expand All @@ -151,19 +162,24 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

sender.sendMessage(Component.text("Restoring " + totalLocations + " replaced Ancient Debris...").color(NamedTextColor.YELLOW));
// Schedule restoration and get session
RestorationSession session = plugin.getDebrisStorage().scheduleRestoreAll(sender);

// Run the restoration on the main thread (delegating Folia handling to DebrisStorage)
Bukkit.getScheduler().runTask(plugin, () -> {
try {
int count = plugin.getDebrisStorage().restoreAllDebris();
sender.sendMessage(Component.text("Restored " + count + " Ancient Debris blocks.").color(NamedTextColor.GREEN));
} catch (Exception e) {
sender.sendMessage(Component.text("Error restoring Ancient Debris: " + e.getMessage()).color(NamedTextColor.RED));
plugin.getLogger().severe("Error restoring Ancient Debris: " + e.getMessage());
e.printStackTrace();
}
});
if (session == null) {
sender.sendMessage(Component.text("No Ancient Debris locations to restore.").color(NamedTextColor.YELLOW));
return true;
}

// Register session with progress tracker
plugin.getRestorationProgressTracker().registerSession(session);

// Send immediate scheduling summary
sender.sendMessage(Component.text("Scheduled restoration for ")
.color(NamedTextColor.GREEN)
.append(Component.text(session.getScheduledChunks()).color(NamedTextColor.GOLD))
.append(Component.text(" chunks, ").color(NamedTextColor.GREEN))
.append(Component.text(session.getTotalLocations()).color(NamedTextColor.GOLD))
.append(Component.text(" locations.").color(NamedTextColor.GREEN)));
}
return true;
case "debris-info":
Expand Down Expand Up @@ -303,6 +319,8 @@ private void showHelp(CommandSender sender) {
sender.sendMessage(Component.text("/antinetherite restore-debris [world] - Restore all replaced Ancient Debris").color(NamedTextColor.YELLOW));
sender.sendMessage(Component.text(" - Optional world parameter to restore only in a specific world").color(NamedTextColor.GRAY));
sender.sendMessage(Component.text(" - Only restores blocks that are still Netherrack").color(NamedTextColor.GRAY));
sender.sendMessage(Component.text(" - Shows progress updates with blended time and percentage-based reporting").color(NamedTextColor.GRAY));
sender.sendMessage(Component.text("/antinetherite restore-feedback <on|off> - Toggle restoration progress feedback").color(NamedTextColor.YELLOW));
sender.sendMessage(Component.text("/antinetherite debris-info - Show information about stored Ancient Debris locations").color(NamedTextColor.YELLOW));
sender.sendMessage(Component.text(" - Displays counts per world and current config status").color(NamedTextColor.GRAY));
sender.sendMessage(Component.text("/antinetherite get <setting> - Get a configuration value").color(NamedTextColor.YELLOW));
Expand Down Expand Up @@ -342,13 +360,20 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
if (args.length == 1) {
completions.add("reload");
completions.add("restore-debris");
completions.add("restore-feedback");
completions.add("debris-info");
completions.add("get");
completions.add("set");
return filterCompletions(completions, args[0]);
}

if (args.length == 2) {
if (args[0].equalsIgnoreCase("restore-feedback")) {
completions.add("on");
completions.add("off");
return filterCompletions(completions, args[1]);
}

if (args[0].equalsIgnoreCase("get") || args[0].equalsIgnoreCase("set")) {
// Add global settings
completions.add("global.enable-destructive-actions");
Expand Down Expand Up @@ -463,6 +488,41 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
return completions;
}

/**
* Handles the /antinetherite restore-feedback command
* @param sender The command sender
* @param args The command arguments
* @return true if the command was handled, false otherwise
*/
private boolean handleRestoreFeedback(CommandSender sender, String[] args) {
// Only players can opt in/out of feedback
if (!(sender instanceof Player)) {
sender.sendMessage(Component.text("Only players can use this command.").color(NamedTextColor.RED));
return true;
}

Player player = (Player) sender;

if (args.length < 2) {
sender.sendMessage(Component.text("Usage: /antinetherite restore-feedback <on|off>").color(NamedTextColor.RED));
return true;
}

String action = args[1].toLowerCase();

if (action.equals("on")) {
plugin.getRestorationProgressTracker().setGlobalOptOut(player.getUniqueId(), false);
sender.sendMessage(Component.text("Restoration progress feedback enabled.").color(NamedTextColor.GREEN));
} else if (action.equals("off")) {
plugin.getRestorationProgressTracker().setGlobalOptOut(player.getUniqueId(), true);
sender.sendMessage(Component.text("Restoration progress feedback disabled.").color(NamedTextColor.YELLOW));
} else {
sender.sendMessage(Component.text("Usage: /antinetherite restore-feedback <on|off>").color(NamedTextColor.RED));
}

return true;
}

/**
* Handles the /antinetherite get command
* @param sender The command sender
Expand Down
Loading