mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Added BentoBox reload command
Only reloads locales for now.
This commit is contained in:
parent
94c5ac8e79
commit
4681a0bd7d
@ -1,31 +0,0 @@
|
||||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AdminReloadCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* @param parent - parent command
|
||||
*/
|
||||
public AdminReloadCommand(CompositeCommand parent) {
|
||||
super(parent, "reload", "rl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.reload.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -16,8 +16,10 @@ public class BentoBoxCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("bentobox.admin");
|
||||
new BentoBoxVersionCommand(this);
|
||||
new BentoBoxAboutCommand(this);
|
||||
new BentoBoxReloadCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,44 @@
|
||||
package world.bentobox.bentobox.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* Displays information about Gamemodes, Addons and versioning.
|
||||
*
|
||||
* @author tastybento
|
||||
*/
|
||||
public class BentoBoxReloadCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* Reloads locales command
|
||||
* @param parent - command parent
|
||||
*/
|
||||
public BentoBoxReloadCommand(CompositeCommand parent) {
|
||||
super(parent, "reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.reload");
|
||||
setDescription("commands.bentobox.reload.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
this.askConfirmation(user, () -> reloadLocales(user));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the languages
|
||||
* @param user
|
||||
*/
|
||||
public void reloadLocales(User user) {
|
||||
getPlugin().getLocalesManager().reloadLanguages();
|
||||
user.sendMessage("commands.bentobox.reload.locales-reloaded");
|
||||
}
|
||||
|
||||
}
|
@ -23,7 +23,7 @@ public class BentoBoxVersionCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
// Useless : this command uses the default values.
|
||||
setPermission("bentobox.admin");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -115,7 +115,7 @@ public class AddonsManager {
|
||||
for (String localeFile : listJarYamlFiles(jar, LOCALE_FOLDER)) {
|
||||
addon.saveResource(localeFile, localeDir, false, true);
|
||||
}
|
||||
plugin.getLocalesManager().loadLocales(addon.getDescription().getName());
|
||||
plugin.getLocalesManager().loadLocalesFromFile(addon.getDescription().getName());
|
||||
// Fire the load event
|
||||
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
||||
// Add it to the list of addons
|
||||
|
@ -30,8 +30,8 @@ public class LocalesManager {
|
||||
|
||||
public LocalesManager(BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
loadLocalesFromJar("BentoBox");
|
||||
loadLocales("BentoBox"); // Default
|
||||
copyLocalesFromJar("BentoBox");
|
||||
loadLocalesFromFile("BentoBox"); // Default
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,9 +56,14 @@ public class LocalesManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void loadLocalesFromJar(String parent) {
|
||||
/**
|
||||
* Copies all the locale files from the plugin jar to the filesystem.
|
||||
* Only done if the locale folder does not already exist.
|
||||
* @param folderName - the name of the destination folder
|
||||
*/
|
||||
private void copyLocalesFromJar(String folderName) {
|
||||
// Run through the files and store the locales
|
||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);
|
||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + folderName);
|
||||
// If the folder does not exist, then make it and fill with the locale files from the jar
|
||||
// If it does exist, then new files will NOT be written!
|
||||
if (!localeDir.exists()) {
|
||||
@ -79,20 +84,21 @@ public class LocalesManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all the locales available. If the locale folder does not exist, one will be created and
|
||||
* filled with locale files from the jar.
|
||||
* Loads all the locales available in the locale folder given. Used for loading all locales from plugin and addons
|
||||
*
|
||||
* @param localeFolder - locale folder location relative to the plugin's data folder
|
||||
*/
|
||||
public void loadLocales(String parent) {
|
||||
// Describe the filter - we only want files that are correctly named
|
||||
// Files must be 9 chars long
|
||||
public void loadLocalesFromFile(String localeFolder) {
|
||||
// Filter for files of length 9 and ending with .yml
|
||||
FilenameFilter ymlFilter = (dir, name) -> name.toLowerCase(java.util.Locale.ENGLISH).endsWith(".yml") && name.length() == 9;
|
||||
|
||||
// Run through the files and store the locales
|
||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);
|
||||
// Get the folder
|
||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + localeFolder);
|
||||
if (!localeDir.exists()) {
|
||||
// If there is no locale folder, then return
|
||||
return;
|
||||
}
|
||||
// Store all the locales available
|
||||
// Run through the files and store the locales
|
||||
for (File language : Objects.requireNonNull(localeDir.listFiles(ymlFilter))) {
|
||||
Locale localeObject = Locale.forLanguageTag(language.getName().substring(0, language.getName().length() - 4));
|
||||
|
||||
@ -145,4 +151,13 @@ public class LocalesManager {
|
||||
public Map<Locale, BentoBoxLocale> getLanguages() {
|
||||
return this.languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all the language files from the filesystem
|
||||
*/
|
||||
public void reloadLanguages() {
|
||||
languages.clear();
|
||||
loadLocalesFromFile("BentoBox");
|
||||
plugin.getAddonsManager().getAddons().forEach(addon -> loadLocalesFromFile(addon.getDescription().getName()));
|
||||
}
|
||||
}
|
||||
|
@ -175,6 +175,8 @@ commands:
|
||||
description: "BentoBox admin command"
|
||||
about:
|
||||
description: "display copyright and license info"
|
||||
reload:
|
||||
description: "reloads all locale files"
|
||||
version:
|
||||
description: "display info"
|
||||
loaded-addons: "Loaded Add-Ons"
|
||||
|
@ -8,3 +8,8 @@ authors: [tastybento, Poslovitch]
|
||||
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI]
|
||||
|
||||
loadbefore: [Multiverse-Core]
|
||||
|
||||
permissions:
|
||||
bentobox.admin:
|
||||
description: Allow bentobox command usage
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user