-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor config handling + added /sf reload #3908
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import io.github.bakedlibs.dough.config.Config; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import order |
||
import org.apache.commons.lang.Validate; | ||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
|
@@ -432,21 +433,23 @@ public void register(@Nonnull SlimefunAddon addon) { | |
Slimefun.getRegistry().getAllSlimefunItems().add(this); | ||
Slimefun.getRegistry().getSlimefunItemIds().put(id, this); | ||
|
||
Config config = Slimefun.getConfigManager().getItemsConfig(); | ||
|
||
// Items that are "not-configurable" cannot be configured. | ||
if (!(this instanceof NotConfigurable)) { | ||
Slimefun.getItemCfg().setDefaultValue(id + ".enabled", true); | ||
Slimefun.getItemCfg().setDefaultValue(id + ".can-be-used-in-workbenches", useableInWorkbench); | ||
Slimefun.getItemCfg().setDefaultValue(id + ".hide-in-guide", hidden); | ||
Slimefun.getItemCfg().setDefaultValue(id + ".allow-enchanting", enchantable); | ||
Slimefun.getItemCfg().setDefaultValue(id + ".allow-disenchanting", disenchantable); | ||
config.setDefaultValue(id + ".enabled", true); | ||
config.setDefaultValue(id + ".can-be-used-in-workbenches", useableInWorkbench); | ||
config.setDefaultValue(id + ".hide-in-guide", hidden); | ||
config.setDefaultValue(id + ".allow-enchanting", enchantable); | ||
config.setDefaultValue(id + ".allow-disenchanting", disenchantable); | ||
|
||
// Load all item settings | ||
for (ItemSetting<?> setting : itemSettings) { | ||
setting.reload(); | ||
} | ||
} | ||
|
||
if (ticking && !Slimefun.getCfg().getBoolean("URID.enable-tickers")) { | ||
if (ticking && !Slimefun.getConfigManager().getPluginConfig().getBoolean("URID.enable-tickers")) { | ||
state = ItemState.DISABLED; | ||
return; | ||
} | ||
|
@@ -457,13 +460,13 @@ public void register(@Nonnull SlimefunAddon addon) { | |
* Any other settings will remain as default. | ||
*/ | ||
state = ItemState.ENABLED; | ||
} else if (Slimefun.getItemCfg().getBoolean(id + ".enabled")) { | ||
} else if (config.getBoolean(id + ".enabled")) { | ||
// The item has been enabled. | ||
state = ItemState.ENABLED; | ||
useableInWorkbench = Slimefun.getItemCfg().getBoolean(id + ".can-be-used-in-workbenches"); | ||
hidden = Slimefun.getItemCfg().getBoolean(id + ".hide-in-guide"); | ||
enchantable = Slimefun.getItemCfg().getBoolean(id + ".allow-enchanting"); | ||
disenchantable = Slimefun.getItemCfg().getBoolean(id + ".allow-disenchanting"); | ||
useableInWorkbench = config.getBoolean(id + ".can-be-used-in-workbenches"); | ||
hidden = config.getBoolean(id + ".hide-in-guide"); | ||
enchantable = config.getBoolean(id + ".allow-enchanting"); | ||
disenchantable = config.getBoolean(id + ".allow-disenchanting"); | ||
} else if (this instanceof VanillaItem) { | ||
// This item is a vanilla "mock" but was disabled. | ||
state = ItemState.VANILLA_FALLBACK; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import io.github.bakedlibs.dough.config.Config; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import order |
||
import org.apache.commons.lang.Validate; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
|
@@ -89,7 +90,7 @@ public Research(@Nonnull NamespacedKey key, int id, @Nonnull String defaultName, | |
* @return Whether this {@link Research} is enabled or not | ||
*/ | ||
public boolean isEnabled() { | ||
return Slimefun.getRegistry().isResearchingEnabled() && enabled; | ||
return Slimefun.getConfigManager().isResearchingEnabled() && enabled; | ||
} | ||
|
||
/** | ||
|
@@ -248,7 +249,7 @@ public boolean canUnlock(@Nonnull Player p) { | |
return true; | ||
} | ||
|
||
boolean creativeResearch = p.getGameMode() == GameMode.CREATIVE && Slimefun.getRegistry().isFreeCreativeResearchingEnabled(); | ||
boolean creativeResearch = p.getGameMode() == GameMode.CREATIVE && Slimefun.getConfigManager().isFreeCreativeResearchingEnabled(); | ||
return creativeResearch || p.getLevel() >= cost; | ||
} | ||
|
||
|
@@ -282,10 +283,11 @@ public void unlock(@Nonnull Player p, boolean isInstant, @Nullable Consumer<Play | |
* Registers this {@link Research}. | ||
*/ | ||
public void register() { | ||
Slimefun.getResearchCfg().setDefaultValue("enable-researching", true); | ||
Config pluginConfig = Slimefun.getConfigManager().getPluginConfig(); | ||
pluginConfig.setDefaultValue("enable-researching", true); | ||
String path = key.getNamespace() + '.' + key.getKey(); | ||
|
||
if (Slimefun.getResearchCfg().contains(path + ".enabled") && !Slimefun.getResearchCfg().getBoolean(path + ".enabled")) { | ||
if (pluginConfig.contains(path + ".enabled") && !pluginConfig.getBoolean(path + ".enabled")) { | ||
for (SlimefunItem item : new ArrayList<>(items)) { | ||
if (item != null) { | ||
item.setResearch(null); | ||
|
@@ -296,10 +298,10 @@ public void register() { | |
return; | ||
} | ||
|
||
Slimefun.getResearchCfg().setDefaultValue(path + ".cost", getCost()); | ||
Slimefun.getResearchCfg().setDefaultValue(path + ".enabled", true); | ||
pluginConfig.setDefaultValue(path + ".cost", getCost()); | ||
pluginConfig.setDefaultValue(path + ".enabled", true); | ||
|
||
setCost(Slimefun.getResearchCfg().getInt(path + ".cost")); | ||
setCost(pluginConfig.getInt(path + ".cost")); | ||
enabled = true; | ||
|
||
Slimefun.getRegistry().getResearches().add(this); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ReloadCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; | ||
|
||
import org.bukkit.command.CommandSender; | ||
|
||
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; | ||
import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; | ||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
class ReloadCommand extends SubCommand { | ||
|
||
ReloadCommand(Slimefun plugin, SlimefunCommand cmd) { | ||
super(plugin, cmd, "reload", false); | ||
} | ||
|
||
@Override | ||
protected @Nonnull String getDescription() { | ||
return "commands.reload.description"; | ||
} | ||
|
||
@Override | ||
public void onExecute(CommandSender sender, @Nonnull String[] args) { | ||
if (sender.hasPermission("slimefun.command.reload")) { | ||
Slimefun.getLocalization().sendMessage(sender, "guide.work-in-progress", true); | ||
boolean reloaded = Slimefun.getConfigManager().reload(); | ||
boolean isRestartRequired = Slimefun.getConfigManager(). isRestartRequired(); | ||
|
||
if (reloaded) { | ||
if (isRestartRequired) { | ||
Slimefun.getLocalization().sendMessage(sender, "commands.reload.restart-required", true); | ||
} else { | ||
Slimefun.getLocalization().sendMessage(sender, "commands.reload.success", true); | ||
} | ||
} else { | ||
Slimefun.getLocalization().sendMessage(sender, "commands.reload.errors", true); | ||
} | ||
} else { | ||
Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.