mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Some minor code improvements
This commit is contained in:
parent
d91d9c2856
commit
a7835197a5
@ -42,6 +42,7 @@
|
|||||||
#### Fixes
|
#### Fixes
|
||||||
* Fixed #2987
|
* Fixed #2987
|
||||||
* Fixed #2989
|
* Fixed #2989
|
||||||
|
* Fixed #2977
|
||||||
|
|
||||||
## Release Candidate 22 (18 Apr 2021)
|
## Release Candidate 22 (18 Apr 2021)
|
||||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#22
|
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#22
|
||||||
|
@ -5,7 +5,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -254,22 +253,6 @@ public class LocalizationService extends SlimefunLocalization {
|
|||||||
return Math.min(NumberUtils.reparseDouble(100.0 * (matches / (double) defaultKeys.size())), 100.0);
|
return Math.min(NumberUtils.reparseDouble(100.0 * (matches / (double) defaultKeys.size())), 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private Set<String> getTotalKeys(@Nonnull Language lang) {
|
|
||||||
return getKeys(lang.getFiles());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private Set<String> getKeys(@Nonnull FileConfiguration... files) {
|
|
||||||
Set<String> keys = new HashSet<>();
|
|
||||||
|
|
||||||
for (FileConfiguration cfg : files) {
|
|
||||||
keys.addAll(cfg.getKeys(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private FileConfiguration streamConfigFile(@Nonnull String file, @Nullable FileConfiguration defaults) {
|
private FileConfiguration streamConfigFile(@Nonnull String file, @Nullable FileConfiguration defaults) {
|
||||||
if (plugin.getClass().getResourceAsStream(file) == null) {
|
if (plugin.getClass().getResourceAsStream(file) == null) {
|
||||||
|
@ -34,12 +34,12 @@ class ContributionsConnector extends GitHubConnector {
|
|||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
ContributionsConnector(GitHubService github, String prefix, int page, String repository, String role) {
|
ContributionsConnector(GitHubService github, String prefix, int page, String repository, ContributorRole role) {
|
||||||
super(github, repository);
|
super(github, repository);
|
||||||
|
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.role = role;
|
this.role = role.getId();
|
||||||
|
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package io.github.thebusybiscuit.slimefun4.core.services.github;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This enum holds the different roles a {@link Contributor} can have.
|
||||||
|
* This is only used to store various {@link String} constants for these roles.
|
||||||
|
* The actual {@link ContributorRole} type itself is not used anywhere.
|
||||||
|
*
|
||||||
|
* @author TheBusyBiscuit
|
||||||
|
*
|
||||||
|
* @see Contributor
|
||||||
|
* @see GitHubService
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
enum ContributorRole {
|
||||||
|
|
||||||
|
DEVELOPER("developer"),
|
||||||
|
RESOURCEPACK_ARTIST("resourcepack"),
|
||||||
|
TRANSLATOR("translator"),
|
||||||
|
WIKI_EDITOR("wiki");
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
|
||||||
|
ContributorRole(@Nonnull String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -103,7 +103,7 @@ public class GitHubService {
|
|||||||
Validate.notNull(minecraftName, "Minecraft username must not be null.");
|
Validate.notNull(minecraftName, "Minecraft username must not be null.");
|
||||||
Validate.notNull(profileURL, "GitHub profile url must not be null.");
|
Validate.notNull(profileURL, "GitHub profile url must not be null.");
|
||||||
Validate.notNull(role, "Role should not be null.");
|
Validate.notNull(role, "Role should not be null.");
|
||||||
Validate.isTrue(commits >= 0, "Commit count cannot be negative.");;
|
Validate.isTrue(commits >= 0, "Commit count cannot be negative.");
|
||||||
|
|
||||||
String username = profileURL.substring(profileURL.lastIndexOf('/') + 1);
|
String username = profileURL.substring(profileURL.lastIndexOf('/') + 1);
|
||||||
|
|
||||||
@ -118,15 +118,15 @@ public class GitHubService {
|
|||||||
addDefaultContributors();
|
addDefaultContributors();
|
||||||
|
|
||||||
// TheBusyBiscuit/Slimefun4 (multiple times because there may me multiple pages)
|
// TheBusyBiscuit/Slimefun4 (multiple times because there may me multiple pages)
|
||||||
connectors.add(new ContributionsConnector(this, "code", 1, repository, "developer"));
|
connectors.add(new ContributionsConnector(this, "code", 1, repository, ContributorRole.DEVELOPER));
|
||||||
connectors.add(new ContributionsConnector(this, "code2", 2, repository, "developer"));
|
connectors.add(new ContributionsConnector(this, "code2", 2, repository, ContributorRole.DEVELOPER));
|
||||||
connectors.add(new ContributionsConnector(this, "code3", 3, repository, "developer"));
|
connectors.add(new ContributionsConnector(this, "code3", 3, repository, ContributorRole.DEVELOPER));
|
||||||
|
|
||||||
// TheBusyBiscuit/Slimefun4-Wiki
|
// TheBusyBiscuit/Slimefun4-Wiki
|
||||||
connectors.add(new ContributionsConnector(this, "wiki", 1, "Slimefun/Wiki", "wiki"));
|
connectors.add(new ContributionsConnector(this, "wiki", 1, "Slimefun/Wiki", ContributorRole.WIKI_EDITOR));
|
||||||
|
|
||||||
// TheBusyBiscuit/Slimefun4-Resourcepack
|
// TheBusyBiscuit/Slimefun4-Resourcepack
|
||||||
connectors.add(new ContributionsConnector(this, "resourcepack", 1, "Slimefun/Resourcepack", "resourcepack"));
|
connectors.add(new ContributionsConnector(this, "resourcepack", 1, "Slimefun/Resourcepack", ContributorRole.RESOURCEPACK_ARTIST));
|
||||||
|
|
||||||
// Issues and Pull Requests
|
// Issues and Pull Requests
|
||||||
connectors.add(new GitHubIssuesConnector(this, repository, (issues, pullRequests) -> {
|
connectors.add(new GitHubIssuesConnector(this, repository, (issues, pullRequests) -> {
|
||||||
|
@ -135,7 +135,7 @@ public final class Language {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public FileConfiguration[] getFiles() {
|
protected FileConfiguration[] getFiles() {
|
||||||
return Arrays.stream(LanguageFile.valuesCached).map(this::getFile).toArray(FileConfiguration[]::new);
|
return Arrays.stream(LanguageFile.valuesCached).map(this::getFile).toArray(FileConfiguration[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public enum LanguageFile {
|
|||||||
RESOURCES("resources.yml"),
|
RESOURCES("resources.yml"),
|
||||||
RESEARCHES("researches.yml");
|
RESEARCHES("researches.yml");
|
||||||
|
|
||||||
static final LanguageFile[] valuesCached = values();
|
protected static final LanguageFile[] valuesCached = values();
|
||||||
|
|
||||||
private final String fileName;
|
private final String fileName;
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@ package io.github.thebusybiscuit.slimefun4.core.services.localization;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -371,4 +373,20 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
|
|||||||
public void sendMessages(CommandSender recipient, String key, UnaryOperator<String> function) {
|
public void sendMessages(CommandSender recipient, String key, UnaryOperator<String> function) {
|
||||||
sendMessages(recipient, key, true, function);
|
sendMessages(recipient, key, true, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
protected Set<String> getTotalKeys(@Nonnull Language lang) {
|
||||||
|
return getKeys(lang.getFiles());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
protected Set<String> getKeys(@Nonnull FileConfiguration... files) {
|
||||||
|
Set<String> keys = new HashSet<>();
|
||||||
|
|
||||||
|
for (FileConfiguration cfg : files) {
|
||||||
|
keys.addAll(cfg.getKeys(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class AutoDisenchanter extends AbstractEnchantmentMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDisenchantable(@Nullable ItemStack item) {
|
private boolean isDisenchantable(@Nullable ItemStack item) {
|
||||||
if (item == null) {
|
if (item == null || item.getType().isAir()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (item.getType() != Material.BOOK) {
|
} else if (item.getType() != Material.BOOK) {
|
||||||
// ^ This stops endless checks of getByItem for books
|
// ^ This stops endless checks of getByItem for books
|
||||||
|
@ -30,6 +30,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
|||||||
* @author Poslovitch
|
* @author Poslovitch
|
||||||
* @author Mooy1
|
* @author Mooy1
|
||||||
* @author StarWishSama
|
* @author StarWishSama
|
||||||
|
* @author martinbrom
|
||||||
*
|
*
|
||||||
* @see AutoDisenchanter
|
* @see AutoDisenchanter
|
||||||
*
|
*
|
||||||
@ -121,7 +122,7 @@ public class AutoEnchanter extends AbstractEnchantmentMachine {
|
|||||||
|
|
||||||
private boolean isEnchantable(@Nullable ItemStack item) {
|
private boolean isEnchantable(@Nullable ItemStack item) {
|
||||||
// stops endless checks of getByItem for enchanted book stacks.
|
// stops endless checks of getByItem for enchanted book stacks.
|
||||||
if (item != null && item.getType() != Material.ENCHANTED_BOOK) {
|
if (item != null && !item.getType().isAir() && item.getType() != Material.ENCHANTED_BOOK) {
|
||||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||||
return sfItem == null || sfItem.isEnchantable();
|
return sfItem == null || sfItem.isEnchantable();
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,7 +43,7 @@ public enum InfiniteBlockGenerator implements Predicate<Block> {
|
|||||||
*/
|
*/
|
||||||
BASALT_GENERATOR("BASALT");
|
BASALT_GENERATOR("BASALT");
|
||||||
|
|
||||||
public static final InfiniteBlockGenerator[] values = values();
|
private static final InfiniteBlockGenerator[] valuesCached = values();
|
||||||
private static final BlockFace[] sameLevelFaces = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
|
private static final BlockFace[] sameLevelFaces = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
|
||||||
|
|
||||||
private final Material material;
|
private final Material material;
|
||||||
@ -164,7 +164,7 @@ public enum InfiniteBlockGenerator implements Predicate<Block> {
|
|||||||
public static InfiniteBlockGenerator findAt(@Nonnull Block b) {
|
public static InfiniteBlockGenerator findAt(@Nonnull Block b) {
|
||||||
Validate.notNull(b, "Cannot find a generator without a Location!");
|
Validate.notNull(b, "Cannot find a generator without a Location!");
|
||||||
|
|
||||||
for (InfiniteBlockGenerator generator : values) {
|
for (InfiniteBlockGenerator generator : valuesCached) {
|
||||||
if (generator.test(b)) {
|
if (generator.test(b)) {
|
||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user