diff --git a/.idea/copilot/chatSessions/00000000000.xd b/.idea/copilot/chatSessions/00000000000.xd index 7122368..c566317 100644 Binary files a/.idea/copilot/chatSessions/00000000000.xd and b/.idea/copilot/chatSessions/00000000000.xd differ diff --git a/pom.xml b/pom.xml index 31c840a..0eea259 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,10 @@ papermc https://repo.papermc.io/repository/maven-public/ + + jitpack.io + https://jitpack.io/ + @@ -34,6 +38,18 @@ 1.18.32 provided + + + com.github.megavexnetwork.scoreboard-library + scoreboard-library-api + 2.1.3 + + + com.github.megavexnetwork.scoreboard-library + scoreboard-library-implementation + 2.1.3 + runtime + \ No newline at end of file diff --git a/src/main/java/cc/fascinated/command/Command.java b/src/main/java/cc/fascinated/command/Command.java index 956f07a..e17927f 100644 --- a/src/main/java/cc/fascinated/command/Command.java +++ b/src/main/java/cc/fascinated/command/Command.java @@ -6,16 +6,46 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -@RequiredArgsConstructor @Getter +@Getter public abstract class Command implements CommandExecutor { + /** + * The command name + */ private final String command; + /** + * The permission required to execute the command. + */ + private String permission; + + public Command(String command, String permissions) { + this.command = command; + this.permission = permissions; + } + + public Command(String command) { + this.command = command; + } + @Override public boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) { - execute(commandSender, strings); + if (this.permission != null) { + if (!commandSender.hasPermission(permission)) { + commandSender.sendMessage("§cYou do not have permission to execute this command."); + return true; + } + } + + this.execute(commandSender, strings); return true; } + /** + * Executes the command. + * + * @param commandSender The sender of the command. + * @param args The arguments of the command. + */ public abstract void execute(CommandSender commandSender, String[] args); } diff --git a/src/main/java/cc/fascinated/command/impl/TotalJoinsCommand.java b/src/main/java/cc/fascinated/command/impl/TotalJoinsCommand.java index 82cd511..590d2fc 100644 --- a/src/main/java/cc/fascinated/command/impl/TotalJoinsCommand.java +++ b/src/main/java/cc/fascinated/command/impl/TotalJoinsCommand.java @@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender; public class TotalJoinsCommand extends Command { public TotalJoinsCommand() { - super("totaljoins"); + super("totaljoins", "aetheria.command.totaljoins"); } @Override diff --git a/src/main/java/cc/fascinated/worldsize/WorldSizeManager.java b/src/main/java/cc/fascinated/worldsize/WorldSizeManager.java index 4b30627..07b0671 100644 --- a/src/main/java/cc/fascinated/worldsize/WorldSizeManager.java +++ b/src/main/java/cc/fascinated/worldsize/WorldSizeManager.java @@ -2,7 +2,6 @@ package cc.fascinated.worldsize; import cc.fascinated.Aetheria; import cc.fascinated.command.CommandManager; -import cc.fascinated.utils.FormatterUtils; import cc.fascinated.worldsize.impl.WorldSizeCommand; import lombok.Getter; import org.bukkit.Bukkit; @@ -10,6 +9,8 @@ import org.bukkit.World; import org.codehaus.plexus.util.FileUtils; import java.io.File; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.TimeUnit; public class WorldSizeManager { @@ -20,7 +21,7 @@ public class WorldSizeManager { * The total size of all worlds. */ @Getter - private static long totalWorldSize; + private static final Map worldSizes = new HashMap<>(); /** * The last time the total world size was updated. @@ -31,34 +32,21 @@ public class WorldSizeManager { public WorldSizeManager() { CommandManager.registerCommand(new WorldSizeCommand()); - totalWorldSize = calculateTotalWorldSize(); Aetheria.INSTANCE.getServer().getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> { - totalWorldSize = calculateTotalWorldSize(); - }, INTERVAL, INTERVAL, TimeUnit.MINUTES); - } - - /** - * Get the total size of all worlds formatted. - * - * @return The total size of all worlds formatted. - */ - public static String getWorldSizeFormatted() { - return FormatterUtils.formatBytes(totalWorldSize); + calculateTotalWorldSize(); + }, 0, INTERVAL, TimeUnit.MINUTES); } /** * Calculate the total size of all worlds. - * - * @return The total size of all worlds. */ - public long calculateTotalWorldSize() { - long size = 0; + public void calculateTotalWorldSize() { for (World world : Bukkit.getWorlds()) { File worldFolder = world.getWorldFolder(); - size += FileUtils.sizeOfDirectory(worldFolder); + long size = FileUtils.sizeOfDirectory(worldFolder); + worldSizes.put(world, size); } lastUpdated = System.currentTimeMillis(); - return size; } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/worldsize/impl/WorldSizeCommand.java b/src/main/java/cc/fascinated/worldsize/impl/WorldSizeCommand.java index 23891b5..75d1592 100644 --- a/src/main/java/cc/fascinated/worldsize/impl/WorldSizeCommand.java +++ b/src/main/java/cc/fascinated/worldsize/impl/WorldSizeCommand.java @@ -2,10 +2,14 @@ package cc.fascinated.worldsize.impl; import cc.fascinated.Aetheria; import cc.fascinated.command.Command; +import cc.fascinated.utils.FormatterUtils; import cc.fascinated.utils.TimeUtils; import cc.fascinated.worldsize.WorldSizeManager; +import org.bukkit.World; import org.bukkit.command.CommandSender; +import java.util.Map; + public class WorldSizeCommand extends Command { public WorldSizeCommand() { @@ -14,7 +18,14 @@ public class WorldSizeCommand extends Command { @Override public void execute(CommandSender commandSender, String[] args) { - commandSender.sendPlainMessage(Aetheria.PREFIX + "§fTotal size of all worlds: §e" + WorldSizeManager.getWorldSizeFormatted() + "§f."); - commandSender.sendPlainMessage(Aetheria.PREFIX + "§fLast updated: §e" + TimeUtils.format(System.currentTimeMillis() - WorldSizeManager.getLastUpdated()) + " ago§f."); + commandSender.sendPlainMessage(Aetheria.PREFIX + "§fWorld information:"); + long totalSize = 0; + for (Map.Entry entry : WorldSizeManager.getWorldSizes().entrySet()) { + long size = entry.getValue(); + commandSender.sendPlainMessage(" §7- §f" + entry.getKey().getName() + ": §e" + FormatterUtils.formatBytes(size) + "§f."); + totalSize += size; + } + commandSender.sendPlainMessage(" §fTotal size: §e" + FormatterUtils.formatBytes(totalSize) + "§f."); + commandSender.sendPlainMessage(" §fLast updated: §e" + TimeUtils.format(System.currentTimeMillis() - WorldSizeManager.getLastUpdated()) + " ago§f."); } }