mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixed #3400
This commit is contained in:
parent
3993f48499
commit
3d87cb3df1
@ -35,6 +35,12 @@
|
||||
|
||||
#### Additions
|
||||
* Added Armored Jetpack
|
||||
* Added Cocoa Beans as a fuel type for the Bio-Generator
|
||||
* Added Beetroots and Beetroot seeds as fuel types for the Bio-Generator
|
||||
* Added small and big dripleaves as fuel types for the Bio-Generator
|
||||
* Added Glow Berries as a fuel type for the Bio-Generator
|
||||
* Added Glow Lichen as a fuel type for the Bio-Generator
|
||||
* Added Spore Blossom as a fuel type for the Bio-Generator
|
||||
|
||||
#### Changes
|
||||
|
||||
@ -43,6 +49,8 @@
|
||||
* Fixed research issues for vanilla items, e.g. Trident or Totem of Undying
|
||||
* Fixed #3368
|
||||
* Fixed #1315
|
||||
* Fixed #3400
|
||||
* Fixed rare issue where Slimefun would not load at all
|
||||
|
||||
## Release Candidate 30 (31 Dec 2021)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#30
|
||||
|
@ -10,6 +10,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -18,6 +19,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -29,6 +31,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.localization.LanguageFil
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
|
||||
/**
|
||||
* As the name suggests, this Service is responsible for Localization.
|
||||
@ -97,7 +100,7 @@ public class LocalizationService extends SlimefunLocalization {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
public String getChatPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
@ -126,7 +129,7 @@ public class LocalizationService extends SlimefunLocalization {
|
||||
|
||||
// Checks if our jar files contains a messages.yml file for that language
|
||||
String file = LanguageFile.MESSAGES.getFilePath(id);
|
||||
return !streamConfigFile(file, null).getKeys(false).isEmpty();
|
||||
return !getConfigurationFromStream(file, null).getKeys(false).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,7 +199,7 @@ public class LocalizationService extends SlimefunLocalization {
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void copyToDefaultLanguage(String language, LanguageFile file) {
|
||||
FileConfiguration config = streamConfigFile(file.getFilePath(language), null);
|
||||
FileConfiguration config = getConfigurationFromStream(file.getFilePath(language), null);
|
||||
defaultLanguage.setFile(file, config);
|
||||
}
|
||||
|
||||
@ -210,7 +213,7 @@ public class LocalizationService extends SlimefunLocalization {
|
||||
|
||||
for (LanguageFile file : LanguageFile.values()) {
|
||||
FileConfiguration defaults = file == LanguageFile.MESSAGES ? getConfig().getConfiguration() : null;
|
||||
FileConfiguration config = streamConfigFile(file.getFilePath(language), defaults);
|
||||
FileConfiguration config = getConfigurationFromStream(file.getFilePath(language), defaults);
|
||||
language.setFile(file, config);
|
||||
}
|
||||
|
||||
@ -249,8 +252,7 @@ public class LocalizationService extends SlimefunLocalization {
|
||||
return Math.min(NumberUtils.reparseDouble(100.0 * (matches / (double) defaultKeys.size())), 100.0);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private FileConfiguration streamConfigFile(@Nonnull String file, @Nullable FileConfiguration defaults) {
|
||||
private @Nonnull FileConfiguration getConfigurationFromStream(@Nonnull String file, @Nullable FileConfiguration defaults) {
|
||||
InputStream inputStream = plugin.getClass().getResourceAsStream(file);
|
||||
|
||||
if (inputStream == null) {
|
||||
@ -258,15 +260,24 @@ public class LocalizationService extends SlimefunLocalization {
|
||||
}
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(reader);
|
||||
String content = reader.lines().collect(Collectors.joining("\n"));
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
/*
|
||||
* Fixes #3400 - Only attempt to load yaml files that contain data.
|
||||
* This is not a perfect fix but should be sufficient to circumvent this issue.
|
||||
*/
|
||||
if (PatternUtils.YAML_ENTRY.matcher(content).find()) {
|
||||
config.loadFromString(content);
|
||||
|
||||
if (defaults != null) {
|
||||
config.setDefaults(defaults);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
} catch (IOException e) {
|
||||
Slimefun.logger().log(Level.SEVERE, e, () -> "Failed to load language file into memory: \"" + file + "\"");
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
Slimefun.logger().log(Level.WARNING, e, () -> "Failed to load language file into memory: \"" + file + "\"");
|
||||
return new YamlConfiguration();
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,6 @@ public class GitHubService {
|
||||
|
||||
connectors = new HashSet<>();
|
||||
contributors = new ConcurrentHashMap<>();
|
||||
loadConnectors(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,6 +67,8 @@ public class GitHubService {
|
||||
* Our instance of {@link Slimefun}
|
||||
*/
|
||||
public void start(@Nonnull Slimefun plugin) {
|
||||
loadConnectors(false);
|
||||
|
||||
long period = TimeUnit.HOURS.toMillis(1);
|
||||
GitHubTask task = new GitHubTask(this);
|
||||
|
||||
|
@ -64,7 +64,14 @@ public abstract class SlimefunLocalization implements Keyed {
|
||||
defaultConfig.save();
|
||||
}
|
||||
|
||||
public @Nonnull String getPrefix() {
|
||||
/**
|
||||
* This returns the chat prefix for our messages.
|
||||
* Every message (unless explicitly omitted) will have this
|
||||
* prefix prepended.
|
||||
*
|
||||
* @return The chat prefix
|
||||
*/
|
||||
public @Nonnull String getChatPrefix() {
|
||||
return getMessage("prefix");
|
||||
}
|
||||
|
||||
@ -339,7 +346,7 @@ public abstract class SlimefunLocalization implements Keyed {
|
||||
Validate.notNull(recipient, "Recipient cannot be null!");
|
||||
Validate.notNull(key, "Message key cannot be null!");
|
||||
|
||||
String prefix = addPrefix ? getPrefix() : "";
|
||||
String prefix = addPrefix ? getChatPrefix() : "";
|
||||
|
||||
if (recipient instanceof Player) {
|
||||
recipient.sendMessage(ChatColors.color(prefix + getMessage((Player) recipient, key)));
|
||||
@ -352,7 +359,7 @@ public abstract class SlimefunLocalization implements Keyed {
|
||||
Validate.notNull(player, "Player cannot be null!");
|
||||
Validate.notNull(key, "Message key cannot be null!");
|
||||
|
||||
String prefix = addPrefix ? getPrefix() : "";
|
||||
String prefix = addPrefix ? getChatPrefix() : "";
|
||||
String message = ChatColors.color(prefix + getMessage(player, key));
|
||||
|
||||
BaseComponent[] components = TextComponent.fromLegacyText(message);
|
||||
@ -374,7 +381,7 @@ public abstract class SlimefunLocalization implements Keyed {
|
||||
return;
|
||||
}
|
||||
|
||||
String prefix = addPrefix ? getPrefix() : "";
|
||||
String prefix = addPrefix ? getChatPrefix() : "";
|
||||
|
||||
if (recipient instanceof Player) {
|
||||
recipient.sendMessage(ChatColors.color(prefix + function.apply(getMessage((Player) recipient, key))));
|
||||
@ -384,7 +391,7 @@ public abstract class SlimefunLocalization implements Keyed {
|
||||
}
|
||||
|
||||
public void sendMessages(@Nonnull CommandSender recipient, @Nonnull String key) {
|
||||
String prefix = getPrefix();
|
||||
String prefix = getChatPrefix();
|
||||
|
||||
if (recipient instanceof Player) {
|
||||
for (String translation : getMessages((Player) recipient, key)) {
|
||||
@ -401,7 +408,7 @@ public abstract class SlimefunLocalization implements Keyed {
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public void sendMessages(CommandSender recipient, String key, boolean addPrefix, UnaryOperator<String> function) {
|
||||
String prefix = addPrefix ? getPrefix() : "";
|
||||
String prefix = addPrefix ? getChatPrefix() : "";
|
||||
|
||||
if (recipient instanceof Player) {
|
||||
for (String translation : getMessages((Player) recipient, key)) {
|
||||
|
@ -20,6 +20,8 @@ public final class PatternUtils {
|
||||
|
||||
public static final Pattern SLASH_SEPARATOR = Pattern.compile(" / ");
|
||||
|
||||
public static final Pattern YAML_ENTRY = Pattern.compile("[a-z0-9_-]+:.*");
|
||||
|
||||
public static final Pattern MINECRAFT_NAMESPACEDKEY = Pattern.compile("minecraft:[a-z0-9/._-]+");
|
||||
|
||||
public static final Pattern MINECRAFT_TAG = Pattern.compile("#minecraft:[a-z_]+");
|
||||
|
Loading…
Reference in New Issue
Block a user