bob
This commit is contained in:
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
5
.idea/.gitignore
generated
vendored
Normal file
5
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
BIN
.idea/copilot/chatSessions/00000000000.xd
generated
Normal file
BIN
.idea/copilot/chatSessions/00000000000.xd
generated
Normal file
Binary file not shown.
BIN
.idea/copilot/chatSessions/blobs/version
generated
Normal file
BIN
.idea/copilot/chatSessions/blobs/version
generated
Normal file
Binary file not shown.
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="CodeBlock2Expr" enabled="true" level="INFORMATION" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
19
.idea/misc.xml
generated
Normal file
19
.idea/misc.xml
generated
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="azul-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
39
pom.xml
Normal file
39
pom.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>cc.fascinated</groupId>
|
||||
<artifactId>aetheria</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.32</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
26
src/main/java/cc/fascinated/Aetheria.java
Normal file
26
src/main/java/cc/fascinated/Aetheria.java
Normal file
@ -0,0 +1,26 @@
|
||||
package cc.fascinated;
|
||||
|
||||
import cc.fascinated.command.CommandManager;
|
||||
import cc.fascinated.worldsize.WorldSizeManager;
|
||||
import cc.fascinated.worldsize.impl.WorldSizeCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Aetheria extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* The instance of the plugin.
|
||||
*/
|
||||
public static Aetheria INSTANCE;
|
||||
|
||||
public static final String PREFIX = "§6§lAetheria §7» §f";
|
||||
|
||||
public Aetheria() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new CommandManager();
|
||||
new WorldSizeManager();
|
||||
}
|
||||
}
|
23
src/main/java/cc/fascinated/command/Command.java
Normal file
23
src/main/java/cc/fascinated/command/Command.java
Normal file
@ -0,0 +1,23 @@
|
||||
package cc.fascinated.command;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@RequiredArgsConstructor @Getter
|
||||
public abstract class Command implements CommandExecutor {
|
||||
|
||||
private final String command;
|
||||
|
||||
private final String[] permissions;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
execute(commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void execute(CommandSender commandSender, String[] args);
|
||||
}
|
21
src/main/java/cc/fascinated/command/CommandManager.java
Normal file
21
src/main/java/cc/fascinated/command/CommandManager.java
Normal file
@ -0,0 +1,21 @@
|
||||
package cc.fascinated.command;
|
||||
|
||||
import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.command.impl.TotalJoinsCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
public CommandManager() {
|
||||
registerCommand(new TotalJoinsCommand());
|
||||
}
|
||||
|
||||
public static void registerCommand(Command command) {
|
||||
if (command == null) {
|
||||
throw new IllegalArgumentException("Command cannot be null.");
|
||||
}
|
||||
Objects.requireNonNull(Aetheria.INSTANCE.getCommand(command.getCommand())).setExecutor(command);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package cc.fascinated.command.impl;
|
||||
|
||||
import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.command.Command;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class TotalJoinsCommand extends Command {
|
||||
|
||||
public TotalJoinsCommand() {
|
||||
super("totaljoins", new String[]{ "aetheria.command.totaljoins" });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender commandSender, String[] args) {
|
||||
commandSender.sendPlainMessage(Aetheria.PREFIX + "§fTotal joins: §e" + Bukkit.getOfflinePlayers().length + "§f.");
|
||||
}
|
||||
}
|
13
src/main/java/cc/fascinated/utils/FormatterUtils.java
Normal file
13
src/main/java/cc/fascinated/utils/FormatterUtils.java
Normal file
@ -0,0 +1,13 @@
|
||||
package cc.fascinated.utils;
|
||||
|
||||
public class FormatterUtils {
|
||||
|
||||
public static String formatBytes(long bytes) {
|
||||
if (bytes < 1024) {
|
||||
return bytes + " B";
|
||||
}
|
||||
int exp = (int) (Math.log(bytes) / Math.log(1024));
|
||||
char pre = "KMGTPE".charAt(exp - 1);
|
||||
return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre);
|
||||
}
|
||||
}
|
22
src/main/java/cc/fascinated/utils/MathUtils.java
Normal file
22
src/main/java/cc/fascinated/utils/MathUtils.java
Normal file
@ -0,0 +1,22 @@
|
||||
package cc.fascinated.utils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
|
||||
public class MathUtils {
|
||||
|
||||
/**
|
||||
* Format a number to a specific amount of decimal places.
|
||||
*
|
||||
* @param number the number to format
|
||||
* @param additional the additional decimal places to format
|
||||
* @return the formatted number
|
||||
*/
|
||||
public static double format(double number, int additional) {
|
||||
return Double.parseDouble(
|
||||
new DecimalFormat("#.#" + "#".repeat(Math.max(0, additional - 1)),
|
||||
new DecimalFormatSymbols()
|
||||
).format(number)
|
||||
);
|
||||
}
|
||||
}
|
162
src/main/java/cc/fascinated/utils/TimeUtils.java
Normal file
162
src/main/java/cc/fascinated/utils/TimeUtils.java
Normal file
@ -0,0 +1,162 @@
|
||||
package cc.fascinated.utils;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@UtilityClass
|
||||
public final class TimeUtils {
|
||||
/**
|
||||
* Format a time in millis to a readable time format.
|
||||
*
|
||||
* @param millis the millis to format
|
||||
* @return the formatted time
|
||||
*/
|
||||
public static String format(long millis) {
|
||||
return format(millis, WildTimeUnit.FIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a time in millis to a readable time format.
|
||||
*
|
||||
* @param millis the millis to format
|
||||
* @param timeUnit the time unit to format the millis to
|
||||
* @return the formatted time
|
||||
*/
|
||||
public static String format(long millis, WildTimeUnit timeUnit) {
|
||||
return format(millis, timeUnit, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a time in millis to a readable time format.
|
||||
*
|
||||
* @param millis the millis to format
|
||||
* @param timeUnit the time unit to format the millis to
|
||||
* @param compact whether to use a compact display
|
||||
* @return the formatted time
|
||||
*/
|
||||
public static String format(long millis, WildTimeUnit timeUnit, boolean compact) {
|
||||
return format(millis, timeUnit, true, compact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a time in millis to a readable time format.
|
||||
*
|
||||
* @param millis the millis to format
|
||||
* @param timeUnit the time unit to format the millis to
|
||||
* @param decimals whether to include decimals
|
||||
* @param compact whether to use a compact display
|
||||
* @return the formatted time
|
||||
*/
|
||||
public static String format(long millis, WildTimeUnit timeUnit, boolean decimals, boolean compact) {
|
||||
if (millis == -1L) { // Format permanent
|
||||
return "Perm" + (compact ? "" : "anent");
|
||||
}
|
||||
// Format the time to the best fitting time unit
|
||||
if (timeUnit == WildTimeUnit.FIT) {
|
||||
for (WildTimeUnit otherTimeUnit : WildTimeUnit.VALUES) {
|
||||
if (otherTimeUnit != WildTimeUnit.FIT && millis >= otherTimeUnit.getMillis()) {
|
||||
timeUnit = otherTimeUnit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
double time = MathUtils.format((double) millis / timeUnit.getMillis(), 1); // Format the time
|
||||
if (!decimals) { // Remove decimals
|
||||
time = (int) time;
|
||||
}
|
||||
String formatted = time + (compact ? timeUnit.getSuffix() : " " + timeUnit.getDisplay()); // Append the time unit
|
||||
if (time != 1.0 && !compact) { // Pluralize the time unit
|
||||
formatted+= "s";
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given input into a time in millis.
|
||||
* <p>
|
||||
* E.g: 1d, 1h, 1d1h, etc
|
||||
* </p>
|
||||
*
|
||||
* @param input the input to parse
|
||||
* @return the time in millis
|
||||
*/
|
||||
public static long fromString(String input) {
|
||||
Matcher matcher = WildTimeUnit.SUFFIX_PATTERN.matcher(input); // Match the given input
|
||||
long millis = 0; // The total millis
|
||||
|
||||
// Match corresponding suffixes and add up the total millis
|
||||
while (matcher.find()) {
|
||||
int amount = Integer.parseInt(matcher.group(1)); // The amount of time to add
|
||||
String suffix = matcher.group(2); // The unit suffix
|
||||
WildTimeUnit timeUnit = WildTimeUnit.fromSuffix(suffix); // The time unit to add
|
||||
if (timeUnit != null) { // Increment the total millis
|
||||
millis+= amount * timeUnit.getMillis();
|
||||
}
|
||||
}
|
||||
return millis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a unit of time.
|
||||
*/
|
||||
@NoArgsConstructor @AllArgsConstructor
|
||||
@Getter(AccessLevel.PRIVATE) @ToString
|
||||
public enum WildTimeUnit {
|
||||
FIT,
|
||||
YEARS("Year", "y", TimeUnit.DAYS.toMillis(365L)),
|
||||
MONTHS("Month", "mo", TimeUnit.DAYS.toMillis(30L)),
|
||||
WEEKS("Week", "w", TimeUnit.DAYS.toMillis(7L)),
|
||||
DAYS("Day", "d", TimeUnit.DAYS.toMillis(1L)),
|
||||
HOURS("Hour", "h", TimeUnit.HOURS.toMillis(1L)),
|
||||
MINUTES("Minute", "m", TimeUnit.MINUTES.toMillis(1L)),
|
||||
SECONDS("Second", "s", TimeUnit.SECONDS.toMillis(1L)),
|
||||
MILLISECONDS("Millisecond", "ms", 1L);
|
||||
|
||||
/**
|
||||
* Our cached unit values.
|
||||
*/
|
||||
public static final WildTimeUnit[] VALUES = values();
|
||||
|
||||
/**
|
||||
* Our cached suffix pattern.
|
||||
*/
|
||||
public static final Pattern SUFFIX_PATTERN = Pattern.compile("(\\d+)(mo|ms|[ywdhms])");
|
||||
|
||||
/**
|
||||
* The display of this time unit.
|
||||
*/
|
||||
private String display;
|
||||
|
||||
/**
|
||||
* The suffix of this time unit.
|
||||
*/
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* The amount of millis in this time unit.
|
||||
*/
|
||||
private long millis;
|
||||
|
||||
/**
|
||||
* Get the time unit with the given suffix.
|
||||
*
|
||||
* @param suffix the time unit suffix
|
||||
* @return the time unit, null if not found
|
||||
*/
|
||||
@Nullable
|
||||
public static WildTimeUnit fromSuffix(String suffix) {
|
||||
for (WildTimeUnit unit : VALUES) {
|
||||
if (unit != FIT && unit.getSuffix().equals(suffix)) {
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
64
src/main/java/cc/fascinated/worldsize/WorldSizeManager.java
Normal file
64
src/main/java/cc/fascinated/worldsize/WorldSizeManager.java
Normal file
@ -0,0 +1,64 @@
|
||||
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;
|
||||
import org.bukkit.World;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WorldSizeManager {
|
||||
|
||||
private static final int INTERVAL = 30; // 30 mins
|
||||
|
||||
/**
|
||||
* The total size of all worlds.
|
||||
*/
|
||||
@Getter
|
||||
private static long totalWorldSize;
|
||||
|
||||
/**
|
||||
* The last time the total world size was updated.
|
||||
*/
|
||||
@Getter
|
||||
private static long lastUpdated;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the total size of all worlds.
|
||||
*
|
||||
* @return The total size of all worlds.
|
||||
*/
|
||||
public long calculateTotalWorldSize() {
|
||||
long size = 0;
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
File worldFolder = world.getWorldFolder();
|
||||
|
||||
size += FileUtils.sizeOfDirectory(worldFolder);
|
||||
}
|
||||
lastUpdated = System.currentTimeMillis();
|
||||
return size;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cc.fascinated.worldsize.impl;
|
||||
|
||||
import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.command.Command;
|
||||
import cc.fascinated.utils.TimeUtils;
|
||||
import cc.fascinated.worldsize.WorldSizeManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class WorldSizeCommand extends Command {
|
||||
|
||||
public WorldSizeCommand() {
|
||||
super("worldsize", new String[]{ "aetheria.command.worldsize" });
|
||||
}
|
||||
|
||||
@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.");
|
||||
}
|
||||
}
|
10
src/main/resources/plugin.yml
Normal file
10
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,10 @@
|
||||
name: Aetheria
|
||||
main: cc.fascinated.Aetheria
|
||||
version: 1.0
|
||||
commands:
|
||||
totaljoins:
|
||||
description: "Shows the total amount of joins"
|
||||
usage: "/totaljoins"
|
||||
worldsize:
|
||||
description: "Shows the size of all worlds"
|
||||
usage: "/worldsize"
|
Reference in New Issue
Block a user