Skip to content

Commit 0d23d10

Browse files
author
MagmaGuy
committed
BetterStructures 2.2.0:
- [New] Nightbreak content management integration - content packages can now be downloaded and updated directly through Nightbreak accounts - [New] /bs downloadall command to bulk download all available content packages - [New] /bs updatecontent command to update outdated content packages - [New] Revamped first-time setup menu with three options: Recommended Setup (Nightbreak-guided), Manual Setup, and Use Current Content - [New] Setup menu now shows real-time access info and out-of-date status for content packages - [New] Plugin initialization now uses MagmaCore's async/sync initialization system with progress reporting - [Fix] Fixed content package and treasure config duplication on reload - [Tweak] Updated MagmaCore dependency to 1.28-SNAPSHOT - [Tweak] Adjusted default spawn distances - surface: 31→27, sky: 95→90, liquid: 65→60 - [Tweak] Reload command refactored to use dedicated content reload method instead of full plugin restart - [Tweak] Updated help text and setup menus to reference Nightbreak workflow
1 parent 788dd36 commit 0d23d10

27 files changed

Lines changed: 721 additions & 159 deletions

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'com.magmaguy'
9-
version = '2.1.2'
9+
version = '2.2.0'
1010

1111
repositories {
1212
mavenCentral()
@@ -27,7 +27,7 @@ dependencies {
2727
annotationProcessor 'org.projectlombok:lombok:1.18.30'
2828
compileOnly 'org.projectlombok:lombok:1.18.30'
2929

30-
implementation (group: 'com.magmaguy', name: 'MagmaCore', version: '1.19-SNAPSHOT'){
30+
implementation (group: 'com.magmaguy', name: 'MagmaCore', version: '1.28-SNAPSHOT'){
3131
changing = true
3232
}
3333
implementation group: 'org.bstats', name: 'bstats-bukkit', version: '2.2.1'
@@ -121,4 +121,4 @@ publishing {
121121
}
122122
}
123123
}
124-
}
124+
}

src/main/java/com/magmaguy/betterstructures/BetterStructures.java

Lines changed: 118 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
import com.magmaguy.easyminecraftgoals.NMSManager;
2222
import com.magmaguy.magmacore.MagmaCore;
2323
import com.magmaguy.magmacore.command.CommandManager;
24+
import com.magmaguy.magmacore.initialization.PluginInitializationConfig;
25+
import com.magmaguy.magmacore.initialization.PluginInitializationContext;
26+
import com.magmaguy.magmacore.initialization.PluginInitializationState;
2427
import com.magmaguy.magmacore.util.Logger;
2528
import org.bstats.bukkit.Metrics;
2629
import org.bukkit.Bukkit;
30+
import org.bukkit.command.CommandSender;
2731
import org.bukkit.event.HandlerList;
2832
import org.bukkit.plugin.java.JavaPlugin;
2933

@@ -41,30 +45,100 @@ public void onEnable() {
4145
Bukkit.getLogger().info("/_____/\\___/\\__/\\__/\\___/_/ /____/\\__/_/ \\__,_/\\___/\\__/\\__,_/_/ \\___/____/");
4246
// Plugin startup logic
4347
Bukkit.getLogger().info("[BetterStructures] Initialized version " + this.getDescription().getVersion() + "!");
44-
Bukkit.getPluginManager().registerEvents(new NewChunkLoadEvent(), this);
45-
Bukkit.getPluginManager().registerEvents(new FirstTimeSetupWarner(), this);
46-
Bukkit.getPluginManager().registerEvents(new ValidWorldsConfig.ValidWorldsConfigEvents(), this);
4748
try {
4849
this.getConfig().save("config.yml");
4950
} catch (IOException e) {
5051
throw new RuntimeException(e);
5152
}
53+
MagmaCore.onEnable(this);
54+
MagmaCore.startInitialization(this,
55+
new PluginInitializationConfig("BetterStructures", "betterstructures.*", 16),
56+
this::asyncInitialization,
57+
this::syncInitialization,
58+
() -> {
59+
Logger.info("BetterStructures fully initialized!");
60+
if (MetadataHandler.pendingReloadSender != null) {
61+
Logger.sendMessage(MetadataHandler.pendingReloadSender, "Reloaded BetterStructures.");
62+
MetadataHandler.pendingReloadSender = null;
63+
}
64+
},
65+
throwable -> {
66+
MetadataHandler.pendingReloadSender = null;
67+
throwable.printStackTrace();
68+
});
69+
}
70+
71+
@Override
72+
public void onLoad() {
73+
MagmaCore.createInstance(this);
74+
try {
75+
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null &&
76+
Bukkit.getPluginManager().getPlugin("EliteMobs") != null)
77+
WorldGuard.initializeFlag();
78+
else
79+
Logger.info("WorldGuard is not enabled! WorldGuard is recommended when using the EliteMobs integration.");
80+
} catch (Exception ex) {
81+
Logger.info("WorldGuard could not be detected! Some BetterStructures features use WorldGuard, and they will not work until it is installed.");
82+
}
83+
}
84+
85+
@Override
86+
public void onDisable() {
87+
MagmaCore.requestInitializationShutdown(this);
88+
if (MagmaCore.getInitializationState(this.getName()) == PluginInitializationState.INITIALIZING) {
89+
Bukkit.getServer().getScheduler().cancelTasks(MetadataHandler.PLUGIN);
90+
MagmaCore.shutdown(this);
91+
Bukkit.getLogger().info("[BetterStructures] Shutdown during initialization.");
92+
return;
93+
}
94+
// Plugin shutdown logic
95+
SchematicContainer.shutdown();
96+
Bukkit.getServer().getScheduler().cancelTasks(MetadataHandler.PLUGIN);
97+
MagmaCore.shutdown(this);
98+
HandlerList.unregisterAll(MetadataHandler.PLUGIN);
99+
BSPackage.shutdown();
100+
ModulesContainer.shutdown();
101+
WFCGenerator.shutdown();
102+
Bukkit.getLogger().info("[BetterStructures] Shutdown!");
103+
}
104+
105+
private void asyncInitialization(PluginInitializationContext initializationContext) {
106+
initializationContext.step("Base Configs");
52107
new DefaultConfig();
53108
new ValidWorldsConfig();
54-
//Creates import folder if one doesn't exist, imports any content inside
55-
MagmaCore.onEnable();
56-
MagmaCore.initializeImporter();
57109

58-
NMSManager.initializeAdapter(this);
110+
initializationContext.step("Content Importer");
111+
MagmaCore.initializeImporter(this);
59112

113+
initializationContext.step("Treasure Config");
60114
new TreasureConfig();
115+
initializationContext.step("Generator Config");
61116
new GeneratorConfig();
117+
initializationContext.step("Module Generators");
62118
new ModuleGeneratorsConfig();
119+
initializationContext.step("Spawn Pools");
63120
new SpawnPoolsConfig();
121+
initializationContext.step("Schematics");
64122
new SchematicConfig();
123+
initializationContext.step("Modules");
65124
new ModulesConfig();
125+
initializationContext.step("Content Packages");
66126
new ContentPackageConfig();
127+
}
128+
129+
private void syncInitialization(PluginInitializationContext initializationContext) {
130+
initializationContext.step("NMS Adapter");
131+
NMSManager.initializeAdapter(this);
132+
133+
initializationContext.step("Components Folder");
67134
ComponentsConfigFolder.initialize();
135+
136+
initializationContext.step("Event Listeners");
137+
Bukkit.getPluginManager().registerEvents(new NewChunkLoadEvent(), this);
138+
Bukkit.getPluginManager().registerEvents(new FirstTimeSetupWarner(), this);
139+
Bukkit.getPluginManager().registerEvents(new ValidWorldsConfig.ValidWorldsConfigEvents(), this);
140+
141+
initializationContext.step("Commands");
68142
CommandManager commandManager = new CommandManager(this, "betterstructures");
69143
commandManager.registerCommand(new LootifyCommand());
70144
commandManager.registerCommand(new PlaceCommand());
@@ -76,41 +150,57 @@ public void onEnable() {
76150
commandManager.registerCommand(new VersionCommand());
77151
commandManager.registerCommand(new SetupCommand());
78152
commandManager.registerCommand(new FirstTimeSetupCommand());
153+
commandManager.registerCommand(new DownloadAllContentCommand());
154+
commandManager.registerCommand(new UpdateContentCommand());
79155
commandManager.registerCommand(new GenerateModulesCommand());
80156
commandManager.registerCommand(new BetterStructuresCommand());
81157

158+
initializationContext.step("Version Check");
82159
MagmaCore.checkVersionUpdate("103241", "https://nightbreak.io/plugin/betterstructures/");
83160

161+
initializationContext.step("WorldGuard Integration");
84162
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null &&
85-
Bukkit.getPluginManager().getPlugin("EliteMobs") != null)
163+
Bukkit.getPluginManager().getPlugin("EliteMobs") != null) {
86164
Bukkit.getPluginManager().registerEvents(new WorldGuard(), this);
87-
new Metrics(this, 19523);
88-
}
89-
90-
@Override
91-
public void onLoad() {
92-
MagmaCore.createInstance(this);
93-
try {
94-
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null &&
95-
Bukkit.getPluginManager().getPlugin("EliteMobs") != null)
96-
WorldGuard.initializeFlag();
97-
else
98-
Logger.info("WorldGuard is not enabled! WorldGuard is recommended when using the EliteMobs integration.");
99-
} catch (Exception ex) {
100-
Logger.info("WorldGuard could not be detected! Some BetterStructures features use WorldGuard, and they will not work until it is installed.");
101165
}
166+
167+
initializationContext.step("Metrics");
168+
new Metrics(this, 19523);
102169
}
103170

104-
@Override
105-
public void onDisable() {
106-
// Plugin shutdown logic
171+
public void reloadImportedContent(CommandSender commandSender) {
107172
SchematicContainer.shutdown();
108173
Bukkit.getServer().getScheduler().cancelTasks(MetadataHandler.PLUGIN);
109-
MagmaCore.shutdown();
110-
HandlerList.unregisterAll(MetadataHandler.PLUGIN);
111174
BSPackage.shutdown();
112175
ModulesContainer.shutdown();
113176
WFCGenerator.shutdown();
114-
Bukkit.getLogger().info("[BetterStructures] Shutdown!");
177+
178+
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
179+
try {
180+
MagmaCore.initializeImporter(this);
181+
new TreasureConfig();
182+
new GeneratorConfig();
183+
new ModuleGeneratorsConfig();
184+
new SpawnPoolsConfig();
185+
new SchematicConfig();
186+
new ModulesConfig();
187+
new ContentPackageConfig();
188+
ComponentsConfigFolder.initialize();
189+
190+
Bukkit.getScheduler().runTask(this, () -> {
191+
if (commandSender != null) {
192+
Logger.sendMessage(commandSender, "Reloaded BetterStructures content.");
193+
}
194+
});
195+
} catch (Exception exception) {
196+
Logger.warn("Failed to reload BetterStructures content asynchronously.");
197+
exception.printStackTrace();
198+
Bukkit.getScheduler().runTask(this, () -> {
199+
if (commandSender != null) {
200+
Logger.sendMessage(commandSender, "&cFailed to reload BetterStructures content. Check the console.");
201+
}
202+
});
203+
}
204+
});
115205
}
116206
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.magmaguy.betterstructures;
22

3+
import org.bukkit.command.CommandSender;
34
import org.bukkit.plugin.Plugin;
45

56
public class MetadataHandler {
67
public static Plugin PLUGIN = null;
8+
public static CommandSender pendingReloadSender = null;
79
}

src/main/java/com/magmaguy/betterstructures/commands/BetterStructuresCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public BetterStructuresCommand() {
1919
@Override
2020
public void execute(CommandData commandData) {
2121
Logger.sendMessage(commandData.getCommandSender(), "BetterStructures is a plugin that adds random structures to your Minecraft world!");
22-
Logger.sendMessage(commandData.getCommandSender(), "You can check the structures you have and download structures in the &2/betterstructures setup &fcommand.");
22+
Logger.sendMessage(commandData.getCommandSender(), "You can check installed content and download structure packs in the &2/betterstructures setup &fcommand.");
23+
Logger.sendMessage(commandData.getCommandSender(), "If your Nightbreak account is linked, you can install everything with &2/betterstructures downloadall&f.");
2324
Logger.sendMessage(commandData.getCommandSender(), "Once a pack is installed, structures will automatically generate in freshly generated chunks. You do not have to run any commands for this to happen.");
2425
Logger.sendMessage(commandData.getCommandSender(), "By default, OPs will get notified about new structures generating until they disable these messages.");
2526
}

0 commit comments

Comments
 (0)