Files
src
pom.xml
README.md
Code
29 3,224
src/main/java/com/accountswitcher/AccountSwitcher.java
package com.accountswitcher;
import com.accountswitcher.backup.BackupManager;
import com.accountswitcher.command.SwitchCommand;
import com.accountswitcher.command.SwitchTabCompleter;
import com.accountswitcher.logging.TransferLogger;
import com.accountswitcher.preview.PreviewManager;
import com.accountswitcher.rollback.RollbackManager;
import com.accountswitcher.transfer.TransferManager;
import com.accountswitcher.uuid.UUIDMigration;
import com.accountswitcher.util.PlayerDataUtil;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
public final class AccountSwitcher extends JavaPlugin {
private static AccountSwitcher instance;
private BackupManager backupManager;
private RollbackManager rollbackManager;
private TransferManager transferManager;
private PreviewManager previewManager;
private TransferLogger transferLogger;
private UUIDMigration uuidMigration;
private PlayerDataUtil playerDataUtil;
private ScheduledExecutorService executor;
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
this.executor = Executors.newScheduledThreadPool(4);
this.playerDataUtil = new PlayerDataUtil();
this.backupManager = new BackupManager(this);
this.rollbackManager = new RollbackManager(this);
this.transferManager = new TransferManager(this);
this.previewManager = new PreviewManager(this);
this.transferLogger = new TransferLogger(this);
this.uuidMigration = new UUIDMigration(this);
SwitchCommand switchCommand = new SwitchCommand(this);
Bukkit.getPluginCommand("switch").setExecutor(switchCommand);
Bukkit.getPluginCommand("switch").setTabCompleter(new SwitchTabCompleter(this));
scheduleBackupCleanup();
getLogger().info("AccountSwitcher v" + getDescription().getVersion() + " enabled.");
}
@Override
public void onDisable() {
if (executor != null && !executor.isShutdown()) {
executor.shutdown();
try {
executor.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
getLogger().log(Level.WARNING, "Executor shutdown interrupted", e);
}
}
instance = null;
}
private void scheduleBackupCleanup() {
int retentionDays = getConfig().getInt("backup-retention-days", 30);
executor.scheduleAtFixedRate(() -> {
try {
backupManager.cleanOldBackups(retentionDays);
} catch (Exception e) {
getLogger().log(Level.WARNING, "Backup cleanup failed", e);
}
}, 1, 24, TimeUnit.HOURS);
}
public static AccountSwitcher getInstance() {
return instance;
}
public BackupManager getBackupManager() {
return backupManager;
}
public RollbackManager getRollbackManager() {
return rollbackManager;
}
public TransferManager getTransferManager() {
return transferManager;
}
public PreviewManager getPreviewManager() {
return previewManager;
}
public TransferLogger getTransferLogger() {
return transferLogger;
}
public UUIDMigration getUuidMigration() {
return uuidMigration;
}
public PlayerDataUtil getPlayerDataUtil() {
return playerDataUtil;
}
public ScheduledExecutorService getExecutor() {
return executor;
}
}