Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/net/tfminecraft/simplefactions/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import net.tfminecraft.simplefactions.war.battle.enums.DefenderRespawnMode;

public class Cache {
private Cache() {}

public static String mapRef;
/** Chapter slug for a future Archive prefill. Not the live upload folder. */
public static String chapterId = "unknown";
Expand Down
45 changes: 42 additions & 3 deletions src/main/java/net/tfminecraft/simplefactions/SimpleFactions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import net.tfminecraft.simplefactions.vehicles.maintenance.VehicleHealthDecayApi.Vf;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -252,15 +254,24 @@ public class SimpleFactions extends JavaPlugin{
private final VehicleMaintenanceDecayTask vehicleMaintenanceDecayTask =
new VehicleMaintenanceDecayTask();

private boolean startupComplete;

@Override
public void onEnable() {
startupComplete = false;
config = getConfig();
plugin = this;
FactionManager.inv = inventoryManager;
createFolders();
createConfigs();
try {
loadConfigs();
} catch (RuntimeException error) {
getLogger().log(java.util.logging.Level.SEVERE, "Cannot load SimpleFactions configuration; disabling before restoring saved state", error);
getServer().getPluginManager().disablePlugin(this);
return;
}
registerListeners();
loadConfigs();
registerRpCharactersIntegrationHooks();
vehicleRegistryPersistence = new VehicleRegistryPersistence(
new File(getDataFolder(), "Cache"),
Expand Down Expand Up @@ -365,6 +376,7 @@ public void onEnable() {
}
inventoryManager.start();
vehicleMaintenanceDecayTask.start();
startupComplete = true;
}
@Override
public void onDisable() {
Expand All @@ -376,8 +388,12 @@ public void onDisable() {
CampaignViewRefreshService.stop();
BattleManager.shutdown();
net.tfminecraft.simplefactions.war.battle.persistence.BattlePersistenceService.stopAutosave();
net.tfminecraft.simplefactions.war.battle.persistence.BattlePersistenceService.saveAll();
sessionManager.end();
if (!startupComplete) {
net.tfminecraft.simplefactions.identity.LeaderCharacters.reset();
return;
}
net.tfminecraft.simplefactions.war.battle.persistence.BattlePersistenceService.saveAll();
net.tfminecraft.simplefactions.inactivity.InactivityService.save();
saveFactionsForShutdown();
for(War w : WarManager.get()){
Expand Down Expand Up @@ -524,7 +540,30 @@ public static void reloadTitles() {
}

public static void reloadConfigs() {
plugin.loadConfigs();
var previousRanks = new ArrayList<>(RankLoader.getRanks());
var previousTypes = new ArrayList<>(RelationLoader.getTypes());
var previousAttitudes = new ArrayList<>(RelationLoader.getAttitudes());
var previousTiers = new ArrayList<>(TierLoader.get());
var previousTitles = new ArrayList<>(TitleLoader.getTitles());
var previousGuildTypes = new LinkedHashMap<>(GuildLoader.get());
try {
plugin.loadConfigs();
} catch (RuntimeException failure) {
// Live factions still reference these definitions until every loader succeeds.
RankLoader.getRanks().clear();
RankLoader.getRanks().addAll(previousRanks);
RelationLoader.getTypes().clear();
RelationLoader.getTypes().addAll(previousTypes);
RelationLoader.getAttitudes().clear();
RelationLoader.getAttitudes().addAll(previousAttitudes);
TierLoader.get().clear();
TierLoader.get().addAll(previousTiers);
TitleLoader.getTitles().clear();
TitleLoader.getTitles().addAll(previousTitles);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
GuildLoader.get().clear();
GuildLoader.get().putAll(previousGuildTypes);
throw failure;
}
FactionManager.rebindRanks();
FactionManager.rebindDiplomacy();
// loadConfigs rebuilds every Title, so point factions at the new copies or hasTitle stops matching.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ public List<LevyEntry> getLevies() {
if(total+count >= subject.getMembers().size()) {
count = subject.getMembers().size() - total;
}
total+=count;
if(count > 0) r.setSentToOverlord(count);
else continue;
count = Math.max(0, count);
total += count;
r.setSentToOverlord(count);
}
levies.add(new LevyEntry(subject, total));
for(LevyEntry e : subjectLevies) {
Expand Down
Loading