Code Patterns
Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.
All
225
Command
60
Damage
2
Ecs
27
Entity
5
Gui
75
Interaction
2
Inventory
4
Moderation
3
Permission
2
Player
9
Plugin
4
Storage
2
Teleport
3
Ui
22
Util
5
← Back to Patterns
java
moderation
Backup System
Server backup management with configuration and manual trigger
Example Code
// Trigger backup
Universe.get().runBackup().thenAccept(unused -> {
player.sendMessage(Message.raw("Backup completed!"));
});
// Check if backup is enabled via command line
if (Options.getOptionSet().has(Options.BACKUP)) {
String backupDir = Options.getOptionSet().valueOf(Options.BACKUP_DIRECTORY).toString();
int maxCount = Options.getOptionSet().valueOf(Options.BACKUP_MAX_COUNT);
int frequency = Options.getOptionSet().valueOf(Options.BACKUP_FREQUENCY_MINUTES);
}
// List backup files
File folder = new File(backupPath);
if (folder.exists() && folder.isDirectory()) {
for (String s : folder.list()) {
File file = new File(folder, s);
if (file.isFile() && file.getName().endsWith(".zip")) {
String name = file.getName();
String size = FormatUtil.bytesToString(file.length());
long ageMs = Instant.now().toEpochMilli() - file.lastModified();
String age = FormatUtil.timeUnitToString(ageMs / 1000, TimeUnit.SECONDS);
}
}
}