1
0

impl permissions and update

This commit is contained in:
Lee
2024-03-21 17:29:30 +00:00
parent 640a4b6392
commit a9192bae57
6 changed files with 70 additions and 25 deletions

Binary file not shown.

16
pom.xml
View File

@ -19,6 +19,10 @@
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io/</url>
</repository>
</repositories>
<dependencies>
@ -34,6 +38,18 @@
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.megavexnetwork.scoreboard-library</groupId>
<artifactId>scoreboard-library-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.github.megavexnetwork.scoreboard-library</groupId>
<artifactId>scoreboard-library-implementation</artifactId>
<version>2.1.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>

View File

@ -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);
}

View File

@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
public class TotalJoinsCommand extends Command {
public TotalJoinsCommand() {
super("totaljoins");
super("totaljoins", "aetheria.command.totaljoins");
}
@Override

View File

@ -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<World, Long> 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;
}
}

View File

@ -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<World, Long> 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.");
}
}