From a9192bae573df8020dbf078516c1d042dee20320 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 21 Mar 2024 17:29:30 +0000 Subject: [PATCH] impl permissions and update --- .idea/copilot/chatSessions/00000000000.xd | Bin 5933 -> 7307 bytes pom.xml | 16 +++++++++ .../java/cc/fascinated/command/Command.java | 34 ++++++++++++++++-- .../command/impl/TotalJoinsCommand.java | 2 +- .../worldsize/WorldSizeManager.java | 28 +++++---------- .../worldsize/impl/WorldSizeCommand.java | 15 ++++++-- 6 files changed, 70 insertions(+), 25 deletions(-) diff --git a/.idea/copilot/chatSessions/00000000000.xd b/.idea/copilot/chatSessions/00000000000.xd index 7122368a3097a77a65a1a699c223fc988b7d27b6..c566317bc3b8cffd5fbb7d897c45f0e93785169c 100644 GIT binary patch delta 496 zcmZ3h*KN5$S6sYpRZAm7Vo%em*2X3#aox7Y)+PZhlXa7;L=`5_6tiFwx0x&}q%%oO zGr(otD$@;ZeLYPKY>f>JjD0Z)?bS_vQ#&Uyaq@6laHevWaJF#H692)uL-=#s?5+-& z8iuCXAhRXp+ZtOM`Pesrt&rB)0J4Hf!esJ65eX&<>&dr8WDu6gIB!^GvI*?Agg%Jd zB)&u3R<{w0MoBi9EBQ99s^5(4$~W2ln68vOgyKq|8mKEJUxHm3xEbQgvdv)2B>#b3 zDa8tQCEPL@-Yu)@wt`(5KLO%Ose=$#dThm_QR)KBl@VK4d2UB?W#at2WK35|_aM6x oqz39rX`u6fVJW>G;!20@V9TUWfL$ql9_&iEWvt=bS9$CN0OK#Q7XSbN delta 7 OcmeCST&uT1R~!Hf!~&E6 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."); } }