1
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:
TheBusyBiscuit 2021-04-25 20:13:51 +02:00
parent d91d9c2856
commit a7835197a5
11 changed files with 68 additions and 31 deletions

View File

@ -42,6 +42,7 @@
#### Fixes
* Fixed #2987
* Fixed #2989
* Fixed #2977
## Release Candidate 22 (18 Apr 2021)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#22

View File

@ -5,7 +5,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
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);
}
@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
private FileConfiguration streamConfigFile(@Nonnull String file, @Nullable FileConfiguration defaults) {
if (plugin.getClass().getResourceAsStream(file) == null) {

View File

@ -34,12 +34,12 @@ class ContributionsConnector extends GitHubConnector {
private boolean finished = false;
@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);
this.prefix = prefix;
this.page = page;
this.role = role;
this.role = role.getId();
loadConfiguration();
}

View File

@ -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;
}
}

View File

@ -103,7 +103,7 @@ public class GitHubService {
Validate.notNull(minecraftName, "Minecraft username must not be null.");
Validate.notNull(profileURL, "GitHub profile url must 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);
@ -118,15 +118,15 @@ public class GitHubService {
addDefaultContributors();
// TheBusyBiscuit/Slimefun4 (multiple times because there may me multiple pages)
connectors.add(new ContributionsConnector(this, "code", 1, repository, "developer"));
connectors.add(new ContributionsConnector(this, "code2", 2, repository, "developer"));
connectors.add(new ContributionsConnector(this, "code3", 3, repository, "developer"));
connectors.add(new ContributionsConnector(this, "code", 1, repository, ContributorRole.DEVELOPER));
connectors.add(new ContributionsConnector(this, "code2", 2, repository, ContributorRole.DEVELOPER));
connectors.add(new ContributionsConnector(this, "code3", 3, repository, ContributorRole.DEVELOPER));
// 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
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
connectors.add(new GitHubIssuesConnector(this, repository, (issues, pullRequests) -> {

View File

@ -135,7 +135,7 @@ public final class Language {
}
@Nonnull
public FileConfiguration[] getFiles() {
protected FileConfiguration[] getFiles() {
return Arrays.stream(LanguageFile.valuesCached).map(this::getFile).toArray(FileConfiguration[]::new);
}

View File

@ -21,7 +21,7 @@ public enum LanguageFile {
RESOURCES("resources.yml"),
RESEARCHES("researches.yml");
static final LanguageFile[] valuesCached = values();
protected static final LanguageFile[] valuesCached = values();
private final String fileName;

View File

@ -2,7 +2,9 @@ package io.github.thebusybiscuit.slimefun4.core.services.localization;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.UnaryOperator;
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) {
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;
}
}

View File

@ -140,7 +140,7 @@ public class AutoDisenchanter extends AbstractEnchantmentMachine {
}
private boolean isDisenchantable(@Nullable ItemStack item) {
if (item == null) {
if (item == null || item.getType().isAir()) {
return false;
} else if (item.getType() != Material.BOOK) {
// ^ This stops endless checks of getByItem for books

View File

@ -30,6 +30,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
* @author Poslovitch
* @author Mooy1
* @author StarWishSama
* @author martinbrom
*
* @see AutoDisenchanter
*
@ -121,7 +122,7 @@ public class AutoEnchanter extends AbstractEnchantmentMachine {
private boolean isEnchantable(@Nullable ItemStack item) {
// 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);
return sfItem == null || sfItem.isEnchantable();
} else {

View File

@ -43,7 +43,7 @@ public enum InfiniteBlockGenerator implements Predicate<Block> {
*/
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 final Material material;
@ -164,7 +164,7 @@ public enum InfiniteBlockGenerator implements Predicate<Block> {
public static InfiniteBlockGenerator findAt(@Nonnull Block b) {
Validate.notNull(b, "Cannot find a generator without a Location!");
for (InfiniteBlockGenerator generator : values) {
for (InfiniteBlockGenerator generator : valuesCached) {
if (generator.test(b)) {
return generator;
}