impl permissions and update
This commit is contained in:
BIN
.idea/copilot/chatSessions/00000000000.xd
generated
BIN
.idea/copilot/chatSessions/00000000000.xd
generated
Binary file not shown.
16
pom.xml
16
pom.xml
@ -19,6 +19,10 @@
|
|||||||
<id>papermc</id>
|
<id>papermc</id>
|
||||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -34,6 +38,18 @@
|
|||||||
<version>1.18.32</version>
|
<version>1.18.32</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -6,16 +6,46 @@ import org.bukkit.command.CommandExecutor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@RequiredArgsConstructor @Getter
|
@Getter
|
||||||
public abstract class Command implements CommandExecutor {
|
public abstract class Command implements CommandExecutor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The command name
|
||||||
|
*/
|
||||||
private final String command;
|
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
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
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;
|
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);
|
public abstract void execute(CommandSender commandSender, String[] args);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
public class TotalJoinsCommand extends Command {
|
public class TotalJoinsCommand extends Command {
|
||||||
|
|
||||||
public TotalJoinsCommand() {
|
public TotalJoinsCommand() {
|
||||||
super("totaljoins");
|
super("totaljoins", "aetheria.command.totaljoins");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,7 +2,6 @@ package cc.fascinated.worldsize;
|
|||||||
|
|
||||||
import cc.fascinated.Aetheria;
|
import cc.fascinated.Aetheria;
|
||||||
import cc.fascinated.command.CommandManager;
|
import cc.fascinated.command.CommandManager;
|
||||||
import cc.fascinated.utils.FormatterUtils;
|
|
||||||
import cc.fascinated.worldsize.impl.WorldSizeCommand;
|
import cc.fascinated.worldsize.impl.WorldSizeCommand;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -10,6 +9,8 @@ import org.bukkit.World;
|
|||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class WorldSizeManager {
|
public class WorldSizeManager {
|
||||||
@ -20,7 +21,7 @@ public class WorldSizeManager {
|
|||||||
* The total size of all worlds.
|
* The total size of all worlds.
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private static long totalWorldSize;
|
private static final Map<World, Long> worldSizes = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last time the total world size was updated.
|
* The last time the total world size was updated.
|
||||||
@ -31,34 +32,21 @@ public class WorldSizeManager {
|
|||||||
public WorldSizeManager() {
|
public WorldSizeManager() {
|
||||||
CommandManager.registerCommand(new WorldSizeCommand());
|
CommandManager.registerCommand(new WorldSizeCommand());
|
||||||
|
|
||||||
totalWorldSize = calculateTotalWorldSize();
|
|
||||||
Aetheria.INSTANCE.getServer().getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> {
|
Aetheria.INSTANCE.getServer().getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> {
|
||||||
totalWorldSize = calculateTotalWorldSize();
|
calculateTotalWorldSize();
|
||||||
}, INTERVAL, INTERVAL, TimeUnit.MINUTES);
|
}, 0, 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the total size of all worlds.
|
* Calculate the total size of all worlds.
|
||||||
*
|
|
||||||
* @return The total size of all worlds.
|
|
||||||
*/
|
*/
|
||||||
public long calculateTotalWorldSize() {
|
public void calculateTotalWorldSize() {
|
||||||
long size = 0;
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
File worldFolder = world.getWorldFolder();
|
File worldFolder = world.getWorldFolder();
|
||||||
|
|
||||||
size += FileUtils.sizeOfDirectory(worldFolder);
|
long size = FileUtils.sizeOfDirectory(worldFolder);
|
||||||
|
worldSizes.put(world, size);
|
||||||
}
|
}
|
||||||
lastUpdated = System.currentTimeMillis();
|
lastUpdated = System.currentTimeMillis();
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,10 +2,14 @@ package cc.fascinated.worldsize.impl;
|
|||||||
|
|
||||||
import cc.fascinated.Aetheria;
|
import cc.fascinated.Aetheria;
|
||||||
import cc.fascinated.command.Command;
|
import cc.fascinated.command.Command;
|
||||||
|
import cc.fascinated.utils.FormatterUtils;
|
||||||
import cc.fascinated.utils.TimeUtils;
|
import cc.fascinated.utils.TimeUtils;
|
||||||
import cc.fascinated.worldsize.WorldSizeManager;
|
import cc.fascinated.worldsize.WorldSizeManager;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class WorldSizeCommand extends Command {
|
public class WorldSizeCommand extends Command {
|
||||||
|
|
||||||
public WorldSizeCommand() {
|
public WorldSizeCommand() {
|
||||||
@ -14,7 +18,14 @@ public class WorldSizeCommand extends Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender commandSender, String[] args) {
|
public void execute(CommandSender commandSender, String[] args) {
|
||||||
commandSender.sendPlainMessage(Aetheria.PREFIX + "§fTotal size of all worlds: §e" + WorldSizeManager.getWorldSizeFormatted() + "§f.");
|
commandSender.sendPlainMessage(Aetheria.PREFIX + "§fWorld information:");
|
||||||
commandSender.sendPlainMessage(Aetheria.PREFIX + "§fLast updated: §e" + TimeUtils.format(System.currentTimeMillis() - WorldSizeManager.getLastUpdated()) + " ago§f.");
|
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user