1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Some code cleanup, documentation and paper optimizations

This commit is contained in:
TheBusyBiscuit 2020-10-28 00:44:35 +01:00
parent acecbff990
commit b3befbda49
14 changed files with 238 additions and 53 deletions

View File

@ -29,6 +29,12 @@
#### Changes
* Removed 1.13 support
* Cooling Units can no longer be placed down
* Heating Coils can no longer be placed down
* Electric Motors can no longer be placed down
* Cargo Motors can no longer be placed down
* Magnets can no longer be placed down
* Electromagnets can no longer be placed down
#### Fixes
* Fixed #2448

View File

@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.core.services;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -11,6 +14,9 @@ import org.bukkit.block.TileState;
import org.bukkit.persistence.PersistentDataHolder;
import org.bukkit.plugin.Plugin;
import io.papermc.lib.PaperLib;
import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
/**
* The {@link BlockDataService} is similar to the {@link CustomItemDataService},
* it is responsible for storing NBT data inside a {@link TileState}.
@ -24,7 +30,17 @@ public class BlockDataService implements PersistentDataService, Keyed {
private final NamespacedKey namespacedKey;
public BlockDataService(Plugin plugin, String key) {
/**
* This creates a new {@link BlockDataService} for the given {@link Plugin}.
* The {@link Plugin} and key will together form a {@link NamespacedKey} used to store
* data on a {@link TileState}.
*
* @param plugin
* The {@link Plugin} responsible for this service
* @param key
* The key under which to store data
*/
public BlockDataService(@Nonnull Plugin plugin, @Nonnull String key) {
namespacedKey = new NamespacedKey(plugin, key);
}
@ -41,12 +57,16 @@ public class BlockDataService implements PersistentDataService, Keyed {
* @param value
* The value to store
*/
public void setBlockData(Block b, String value) {
BlockState state = b.getState();
public void setBlockData(@Nonnull Block b, @Nonnull String value) {
BlockStateSnapshotResult result = PaperLib.getBlockState(b, false);
BlockState state = result.getState();
if (state instanceof TileState) {
setString((TileState) state, namespacedKey, value);
state.update();
if (result.isSnapshot()) {
state.update();
}
}
}
@ -57,8 +77,8 @@ public class BlockDataService implements PersistentDataService, Keyed {
* The {@link Block} to retrieve data from
* @return The stored value
*/
public Optional<String> getBlockData(Block b) {
BlockState state = b.getState();
public Optional<String> getBlockData(@Nonnull Block b) {
BlockState state = PaperLib.getBlockState(b, false).getState();
if (state instanceof TileState) {
return getString((TileState) state, namespacedKey);
@ -77,9 +97,10 @@ public class BlockDataService implements PersistentDataService, Keyed {
*
* @param type
* The {@link Material} to check for
*
* @return Whether the given {@link Material} is considered a Tile Entity
*/
public boolean isTileEntity(Material type) {
public boolean isTileEntity(@Nullable Material type) {
if (type == null || type.isAir()) {
// Cannot store data on air
return false;
@ -104,8 +125,10 @@ public class BlockDataService implements PersistentDataService, Keyed {
case BARREL:
case SPAWNER:
case BEACON:
// All of the above Materials are Tile Entities
return true;
default:
// Otherwise we assume they're not Tile Entities
return false;
}
}

View File

@ -2,6 +2,10 @@ package io.github.thebusybiscuit.slimefun4.core.services;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -35,7 +39,7 @@ public class CustomItemDataService implements PersistentDataService, Keyed {
* @param key
* The key under which to store data
*/
public CustomItemDataService(Plugin plugin, String key) {
public CustomItemDataService(@Nonnull Plugin plugin, @Nonnull String key) {
// Null-Validation is performed in the NamespacedKey constructor
namespacedKey = new NamespacedKey(plugin, key);
}
@ -45,13 +49,37 @@ public class CustomItemDataService implements PersistentDataService, Keyed {
return namespacedKey;
}
public void setItemData(ItemStack item, String id) {
/**
* This method stores the given id on the provided {@link ItemStack} via
* persistent data.
*
* @param item
* The {@link ItemStack} to store data on
* @param id
* The id to store on the {@link ItemStack}
*/
public void setItemData(@Nonnull ItemStack item, @Nonnull String id) {
Validate.notNull(item, "The Item cannot be null!");
Validate.notNull(id, "Cannot store null on an Item!");
ItemMeta im = item.getItemMeta();
setItemData(im, id);
item.setItemMeta(im);
}
public void setItemData(ItemMeta im, String id) {
/**
* This method stores the given id on the provided {@link ItemMeta} via
* persistent data.
*
* @param im
* The {@link ItemMeta} to store data on
* @param id
* The id to store on the {@link ItemMeta}
*/
public void setItemData(@Nonnull ItemMeta im, @Nonnull String id) {
Validate.notNull(im, "The ItemMeta cannot be null!");
Validate.notNull(id, "Cannot store null on an ItemMeta!");
setString(im, namespacedKey, id);
}
@ -65,7 +93,8 @@ public class CustomItemDataService implements PersistentDataService, Keyed {
*
* @return An {@link Optional} describing the result
*/
public Optional<String> getItemData(ItemStack item) {
@Nonnull
public Optional<String> getItemData(@Nullable ItemStack item) {
if (item == null || item.getType() == Material.AIR || !item.hasItemMeta()) {
return Optional.empty();
}
@ -82,7 +111,10 @@ public class CustomItemDataService implements PersistentDataService, Keyed {
*
* @return An {@link Optional} describing the result
*/
public Optional<String> getItemData(ItemMeta meta) {
@Nonnull
public Optional<String> getItemData(@Nonnull ItemMeta meta) {
Validate.notNull(meta, "Cannot read data from null!");
return getString(meta, namespacedKey);
}

View File

@ -28,6 +28,12 @@ public class CustomTextureService {
private String version = null;
private boolean modified = false;
/**
* This creates a new {@link CustomTextureService} for the provided {@link Config}
*
* @param config
* The {@link Config} to read custom model data from
*/
public CustomTextureService(@Nonnull Config config) {
this.config = config;
config.getConfiguration().options().header("This file is used to assign items from Slimefun or any of its addons\n" + "the 'CustomModelData' NBT tag. This can be used in conjunction with a custom resource pack\n" + "to give items custom textures.\n0 means there is no data assigned to that item.\n\n" + "There is no official Slimefun resource pack at the moment.");
@ -84,22 +90,60 @@ public class CustomTextureService {
return version;
}
/**
* This returns true if any custom model data was configured.
* If every item id has no configured custom model data, it will return false.
*
* @return Whether any custom model data was configured
*/
public boolean isActive() {
return modified;
}
/**
* This returns the configured custom model data for a given id.
*
* @param id
* The id to get the data for
*
* @return The configured custom model data
*/
public int getModelData(@Nonnull String id) {
Validate.notNull(id, "Cannot get the ModelData for 'null'");
return config.getInt(id);
}
/**
* This method sets the custom model data for this {@link ItemStack}
* to the value configured for the provided item id.
*
* @param im
* The {@link ItemStack} to set the custom model data for
* @param id
* The id for which to get the configured model data
*/
public void setTexture(@Nonnull ItemStack item, @Nonnull String id) {
Validate.notNull(item, "The Item cannot be null!");
Validate.notNull(id, "Cannot store null on an Item!");
ItemMeta im = item.getItemMeta();
setTexture(im, id);
item.setItemMeta(im);
}
/**
* This method sets the custom model data for this {@link ItemMeta}
* to the value configured for the provided item id.
*
* @param im
* The {@link ItemMeta} to set the custom model data for
* @param id
* The id for which to get the configured model data
*/
public void setTexture(@Nonnull ItemMeta im, @Nonnull String id) {
Validate.notNull(im, "The ItemMeta cannot be null!");
Validate.notNull(id, "Cannot store null on an ItemMeta!");
int data = getModelData(id);
im.setCustomModelData(data == 0 ? null : data);
}

View File

@ -34,9 +34,26 @@ import kong.unirest.UnirestException;
*/
public class MetricsService {
/**
* The URL pointing towards the GitHub API.
*/
private static final String API_URL = "https://api.github.com/";
/**
* The Name of our repository
*/
private static final String REPO_NAME = "MetricsModule";
/**
* The URL pointing towards the /releases/ endpoint of our
* Metrics repository
*/
private static final String RELEASES_URL = API_URL + "repos/Slimefun/" + REPO_NAME + "/releases/latest";
/**
* The URL pointing towards the download location for a
* GitHub release of our Metrics repository
*/
private static final String DOWNLOAD_URL = "https://github.com/Slimefun/" + REPO_NAME + "/releases/download";
private final SlimefunPlugin plugin;
@ -48,9 +65,22 @@ public class MetricsService {
private boolean hasDownloadedUpdate = false;
static {
Unirest.config().concurrency(2, 1).setDefaultHeader("User-Agent", "MetricsModule Auto-Updater").setDefaultHeader("Accept", "application/vnd.github.v3+json").enableCookieManagement(false).cookieSpec("ignoreCookies");
// @formatter:off (We want this to stay this nicely aligned :D )
Unirest.config()
.concurrency(2, 1)
.setDefaultHeader("User-Agent", "MetricsModule Auto-Updater")
.setDefaultHeader("Accept", "application/vnd.github.v3+json")
.enableCookieManagement(false)
.cookieSpec("ignoreCookies");
// @formatter:on
}
/**
* This constructs a new instance of our {@link MetricsService}.
*
* @param plugin
* Our {@link SlimefunPlugin} instance
*/
public MetricsService(@Nonnull SlimefunPlugin plugin) {
this.plugin = plugin;
this.parentFolder = new File(plugin.getDataFolder(), "cache" + File.separatorChar + "modules");

View File

@ -82,7 +82,7 @@ class ContributionsConnector extends GitHubConnector {
}
@Override
public String getURLSuffix() {
public String getEndpoint() {
return "/contributors?per_page=100&page=" + page;
}

View File

@ -35,7 +35,7 @@ class GitHubActivityConnector extends GitHubConnector {
}
@Override
public String getURLSuffix() {
public String getEndpoint() {
return "";
}

View File

@ -6,13 +6,14 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import kong.unirest.GetRequest;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
@ -31,22 +32,43 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
abstract class GitHubConnector {
private static final String API_URL = "https://api.github.com/";
private static final String HEADER = "Slimefun4 (https://github.com/Slimefun)";
protected File file;
protected String repository;
protected final GitHubService github;
private final String repository;
private final String url;
private File file;
@ParametersAreNonnullByDefault
public GitHubConnector(GitHubService github, String repository) {
/**
* This creates a new {@link GitHubConnector} for the given repository.
*
* @param github
* Our instance of {@link GitHubService}
* @param repository
* The repository we want to connect to
*/
GitHubConnector(@Nonnull GitHubService github, @Nonnull String repository) {
this.github = github;
this.repository = repository;
this.url = API_URL + "repos/" + repository + getEndpoint();
}
/**
* This returns the name of our cache {@link File}.
*
* @return The cache {@link File} name
*/
@Nonnull
public abstract String getFileName();
/**
* This is our {@link URL} endpoint.
* It is the suffix of the {@link URL} we want to connect to.
*
* @return Our endpoint
*/
@Nonnull
public abstract String getURLSuffix();
public abstract String getEndpoint();
/**
* This method is called when the connection finished successfully.
@ -63,7 +85,12 @@ abstract class GitHubConnector {
// Don't do anything by default
}
public void pullFile() {
/**
* This method will connect to GitHub and store the received data inside a local
* cache {@link File}.
* Make sure to call this method asynchronously!
*/
void download() {
file = new File("plugins/Slimefun/cache/github/" + getFileName() + ".json");
if (github.isLoggingEnabled()) {
@ -71,16 +98,15 @@ abstract class GitHubConnector {
}
try {
HttpResponse<JsonNode> resp = Unirest.get(API_URL + "repos/" + repository + getURLSuffix())
.header("User-Agent", "Slimefun4 (https://github.com/Slimefun)")
.asJson();
GetRequest request = Unirest.get(url).header("User-Agent", HEADER);
HttpResponse<JsonNode> response = request.asJson();
if (resp.isSuccess()) {
onSuccess(resp.getBody());
writeCacheFile(resp.getBody());
if (response.isSuccess()) {
onSuccess(response.getBody());
writeCacheFile(response.getBody());
} else {
if (github.isLoggingEnabled()) {
Slimefun.getLogger().log(Level.WARNING, "Failed to fetch {0}: {1} - {2}", new Object[] { repository + getURLSuffix(), resp.getStatus(), resp.getBody() });
Slimefun.getLogger().log(Level.WARNING, "Failed to fetch {0}: {1} - {2}", new Object[] { repository + getEndpoint(), response.getStatus(), response.getBody() });
}
// It has the cached file, let's just read that then

View File

@ -50,7 +50,7 @@ class GitHubIssuesConnector extends GitHubConnector {
}
@Override
public String getURLSuffix() {
public String getEndpoint() {
return "/issues?per_page=100";
}

View File

@ -57,7 +57,8 @@ public class GitHubService {
}
public void start(@Nonnull SlimefunPlugin plugin) {
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new GitHubTask(this), 80L, 60 * 60 * 20L);
GitHubTask task = new GitHubTask(this);
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, task, 80L, 60 * 60 * 20L);
}
/**

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.services.github;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -38,10 +39,14 @@ class GitHubTask implements Runnable {
@Override
public void run() {
gitHubService.getConnectors().forEach(GitHubConnector::pullFile);
gitHubService.getConnectors().forEach(GitHubConnector::download);
grabTextures();
}
/**
* This method will pull the skin textures for every {@link Contributor} and store
* the {@link UUID} and received skin inside a local cache {@link File}.
*/
private void grabTextures() {
// Store all queried usernames to prevent 429 responses for pinging the
// same URL twice in one run.

View File

@ -40,7 +40,7 @@ public class SlimefunBootsListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onDamage(EntityDamageEvent e) {
if (e.getEntity() instanceof Player && e.getCause() == DamageCause.FALL) {
onFallDamage(e);
onFallDamage(e);
}
}

View File

@ -206,7 +206,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
*
*/
public final class SlimefunItemSetup {
private static boolean registeredItems = false;
private SlimefunItemSetup() {}
@ -218,7 +218,8 @@ public final class SlimefunItemSetup {
registeredItems = true;
DefaultCategories categories = new DefaultCategories();
// @formatter:off (We will need to refactor this one day)
new SlimefunItem(categories.weapons, SlimefunItems.GRANDMAS_WALKING_STICK, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {null, new ItemStack(Material.OAK_LOG), null, null, new ItemStack(Material.OAK_LOG), null, null, new ItemStack(Material.OAK_LOG), null})
.register(plugin);
@ -1092,7 +1093,7 @@ public final class SlimefunItemSetup {
new RestoredBackpack(categories.usefulItems).register(plugin);
new SlimefunItem(categories.technicalComponents, SlimefunItems.MAGNET, RecipeType.SMELTERY,
new UnplaceableBlock(categories.technicalComponents, SlimefunItems.MAGNET, RecipeType.SMELTERY,
new ItemStack[] {SlimefunItems.NICKEL_INGOT, SlimefunItems.ALUMINUM_DUST, SlimefunItems.IRON_DUST, SlimefunItems.COBALT_INGOT, null, null, null, null, null})
.register(plugin);
@ -1303,15 +1304,15 @@ public final class SlimefunItemSetup {
new ItemStack[] {SlimefunItems.CARBONADO, SlimefunItems.BASIC_CIRCUIT_BOARD, SlimefunItems.CARBONADO, SlimefunItems.HEATING_COIL, SlimefunItems.REINFORCED_FURNACE, SlimefunItems.HEATING_COIL, SlimefunItems.CARBONADO, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.CARBONADO})
.register(plugin);
new SlimefunItem(categories.technicalComponents, SlimefunItems.ELECTRO_MAGNET, RecipeType.ENHANCED_CRAFTING_TABLE,
new UnplaceableBlock(categories.technicalComponents, SlimefunItems.ELECTRO_MAGNET, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.NICKEL_INGOT, SlimefunItems.MAGNET, SlimefunItems.COBALT_INGOT, null, SlimefunItems.BATTERY, null, null, null, null})
.register(plugin);
new SlimefunItem(categories.technicalComponents, SlimefunItems.ELECTRIC_MOTOR, RecipeType.ENHANCED_CRAFTING_TABLE,
new UnplaceableBlock(categories.technicalComponents, SlimefunItems.ELECTRIC_MOTOR, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, null, SlimefunItems.ELECTRO_MAGNET, null, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE})
.register(plugin);
new SlimefunItem(categories.technicalComponents, SlimefunItems.HEATING_COIL, RecipeType.ENHANCED_CRAFTING_TABLE,
new UnplaceableBlock(categories.technicalComponents, SlimefunItems.HEATING_COIL, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE})
.register(plugin);
@ -1455,7 +1456,7 @@ public final class SlimefunItemSetup {
new SlimefunItemStack(SlimefunItems.HARDENED_GLASS, 16))
.register(plugin);
new SlimefunItem(categories.technicalComponents, SlimefunItems.COOLING_UNIT, RecipeType.ENHANCED_CRAFTING_TABLE,
new UnplaceableBlock(categories.technicalComponents, SlimefunItems.COOLING_UNIT, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {new ItemStack(Material.ICE), new ItemStack(Material.ICE), new ItemStack(Material.ICE), SlimefunItems.ALUMINUM_INGOT, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.ALUMINUM_INGOT, new ItemStack(Material.ICE), new ItemStack(Material.ICE), new ItemStack(Material.ICE)})
.register(plugin);
@ -2867,7 +2868,7 @@ public final class SlimefunItemSetup {
}.register(plugin);
new SlimefunItem(categories.cargo, SlimefunItems.CARGO_MOTOR, RecipeType.ENHANCED_CRAFTING_TABLE,
new UnplaceableBlock(categories.cargo, SlimefunItems.CARGO_MOTOR, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.HARDENED_GLASS, SlimefunItems.ELECTRO_MAGNET, SlimefunItems.HARDENED_GLASS, SlimefunItems.SILVER_INGOT, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.SILVER_INGOT, SlimefunItems.HARDENED_GLASS, SlimefunItems.ELECTRO_MAGNET, SlimefunItems.HARDENED_GLASS},
new SlimefunItemStack(SlimefunItems.CARGO_MOTOR, 4))
.register(plugin);
@ -3048,6 +3049,8 @@ public final class SlimefunItemSetup {
new ElytraCap(categories.magicalArmor, SlimefunItems.ELYTRA_CAP, RecipeType.ARMOR_FORGE,
new ItemStack[]{new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.LEATHER_HELMET), new ItemStack(Material.SLIME_BALL)})
.register(plugin);
// @formatter:on
}
private static void registerArmorSet(Category category, ItemStack baseComponent, ItemStack[] items, String idSyntax, boolean vanilla, PotionEffect[][] effects, SlimefunAddon addon) {

View File

@ -4,6 +4,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
@ -24,11 +27,13 @@ public final class ColoredMaterials {
* constructor to be private.
*/
private ColoredMaterials() {}
// @formatter:off (We want this to stay formatted like this)
/**
* This {@link List} contains all wool colors ordered by their appearance ingame.
*/
public static final List<Material> WOOL = Collections.unmodifiableList(Arrays.asList(
public static final List<Material> WOOL = asList(new Material[] {
Material.WHITE_WOOL,
Material.ORANGE_WOOL,
Material.MAGENTA_WOOL,
@ -45,12 +50,12 @@ public final class ColoredMaterials {
Material.GREEN_WOOL,
Material.RED_WOOL,
Material.BLACK_WOOL
));
});
/**
* This {@link List} contains all stained glass colors ordered by their appearance ingame.
*/
public static final List<Material> STAINED_GLASS = Collections.unmodifiableList(Arrays.asList(
public static final List<Material> STAINED_GLASS = asList(new Material[] {
Material.WHITE_STAINED_GLASS,
Material.ORANGE_STAINED_GLASS,
Material.MAGENTA_STAINED_GLASS,
@ -67,12 +72,12 @@ public final class ColoredMaterials {
Material.GREEN_STAINED_GLASS,
Material.RED_STAINED_GLASS,
Material.BLACK_STAINED_GLASS
));
});
/**
* This {@link List} contains all stained glass pane colors ordered by their appearance ingame.
*/
public static final List<Material> STAINED_GLASS_PANE = Collections.unmodifiableList(Arrays.asList(
public static final List<Material> STAINED_GLASS_PANE = asList(new Material[] {
Material.WHITE_STAINED_GLASS_PANE,
Material.ORANGE_STAINED_GLASS_PANE,
Material.MAGENTA_STAINED_GLASS_PANE,
@ -89,12 +94,12 @@ public final class ColoredMaterials {
Material.GREEN_STAINED_GLASS_PANE,
Material.RED_STAINED_GLASS_PANE,
Material.BLACK_STAINED_GLASS_PANE
));
});
/**
* This {@link List} contains all terracotta colors ordered by their appearance ingame.
*/
public static final List<Material> TERRACOTTA = Collections.unmodifiableList(Arrays.asList(
public static final List<Material> TERRACOTTA = asList(new Material[] {
Material.WHITE_TERRACOTTA,
Material.ORANGE_TERRACOTTA,
Material.MAGENTA_TERRACOTTA,
@ -111,12 +116,12 @@ public final class ColoredMaterials {
Material.GREEN_TERRACOTTA,
Material.RED_TERRACOTTA,
Material.BLACK_TERRACOTTA
));
});
/**
* This {@link List} contains all glazed terracotta colors ordered by their appearance ingame.
*/
public static final List<Material> GLAZED_TERRACOTTA = Collections.unmodifiableList(Arrays.asList(
public static final List<Material> GLAZED_TERRACOTTA = asList(new Material[] {
Material.WHITE_GLAZED_TERRACOTTA,
Material.ORANGE_GLAZED_TERRACOTTA,
Material.MAGENTA_GLAZED_TERRACOTTA,
@ -133,12 +138,12 @@ public final class ColoredMaterials {
Material.GREEN_GLAZED_TERRACOTTA,
Material.RED_GLAZED_TERRACOTTA,
Material.BLACK_GLAZED_TERRACOTTA
));
});
/**
* This {@link List} contains all concrete colors ordered by their appearance ingame.
*/
public static final List<Material> CONCRETE = Collections.unmodifiableList(Arrays.asList(
public static final List<Material> CONCRETE = asList(new Material[] {
Material.WHITE_CONCRETE,
Material.ORANGE_CONCRETE,
Material.MAGENTA_CONCRETE,
@ -155,6 +160,16 @@ public final class ColoredMaterials {
Material.GREEN_CONCRETE,
Material.RED_CONCRETE,
Material.BLACK_CONCRETE
));
});
// @formatter:on
@Nonnull
private static List<Material> asList(@Nonnull Material[] materials) {
Validate.noNullElements(materials, "The List cannot contain any null elements");
Validate.isTrue(materials.length == 16, "Expected 16, received: " + materials.length + ". Did you miss a color?");
return Collections.unmodifiableList(Arrays.asList(materials));
}
}