1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Moved Nether goo to the appropriate package (+ more annotations)

This commit is contained in:
TheBusyBiscuit 2020-09-02 14:47:32 +02:00
parent 426b4caae0
commit f4869991ca
12 changed files with 62 additions and 21 deletions

View File

@ -1,5 +1,7 @@
package io.github.thebusybiscuit.slimefun4.api.geo;
import javax.annotation.Nonnull;
import org.bukkit.Chunk;
import org.bukkit.Keyed;
import org.bukkit.World;
@ -43,7 +45,7 @@ public interface GEOResource extends Keyed {
*
* @return The default supply found in a {@link Chunk} with the given {@link Biome}
*/
int getDefaultSupply(Environment environment, Biome biome);
int getDefaultSupply(@Nonnull Environment environment, @Nonnull Biome biome);
/**
* Returns how much the value may deviate from the default supply (positive only).
@ -57,6 +59,7 @@ public interface GEOResource extends Keyed {
*
* @return The name of this Resource
*/
@Nonnull
String getName();
/**
@ -65,6 +68,7 @@ public interface GEOResource extends Keyed {
*
* @return The {@link ItemStack} version of this Resource.
*/
@Nonnull
ItemStack getItem();
/**
@ -90,7 +94,8 @@ public interface GEOResource extends Keyed {
* The {@link Player} to localize the name for.
* @return The localized name for this {@link GEOResource}
*/
default String getName(Player p) {
@Nonnull
default String getName(@Nonnull Player p) {
String name = SlimefunPlugin.getLocalization().getResourceString(p, "resources." + getKey().getNamespace() + "." + getKey().getKey());
return name == null ? getName() : name;
}

View File

@ -5,6 +5,9 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.Tag;
@ -44,6 +47,7 @@ public class MultiBlock {
}
}
@Nonnull
public static Set<Tag<Material>> getSupportedTags() {
return SUPPORTED_TAGS;
}
@ -53,7 +57,7 @@ public class MultiBlock {
private final BlockFace trigger;
private final boolean isSymmetric;
public MultiBlock(SlimefunItem item, Material[] build, BlockFace trigger) {
public MultiBlock(@Nonnull SlimefunItem item, Material[] build, @Nonnull BlockFace trigger) {
Validate.notNull(item, "A MultiBlock requires a SlimefunItem!");
if (build == null || build.length != 9) {
@ -70,18 +74,21 @@ public class MultiBlock {
this.isSymmetric = isSymmetric(build);
}
@Nonnull
public SlimefunItem getSlimefunItem() {
return item;
}
private static boolean isSymmetric(Material[] blocks) {
private static boolean isSymmetric(@Nonnull Material[] blocks) {
return blocks[0] == blocks[2] && blocks[3] == blocks[5] && blocks[6] == blocks[8];
}
@Nonnull
public Material[] getStructure() {
return blocks;
}
@Nonnull
public BlockFace getTriggerBlock() {
return trigger;
}
@ -112,7 +119,7 @@ public class MultiBlock {
return Objects.hash(item.getID(), blocks, trigger, isSymmetric);
}
private boolean compareBlocks(Material a, Material b) {
private boolean compareBlocks(Material a, @Nullable Material b) {
if (b != null) {
for (Tag<Material> tag : SUPPORTED_TAGS) {

View File

@ -5,6 +5,7 @@ import java.util.Arrays;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
@ -77,6 +78,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
return displayRecipes;
}
@Nonnull
public MultiBlock getMultiBlock() {
return multiblock;
}
@ -121,7 +123,9 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
return true;
}
else return false;
else {
return false;
}
};
}
@ -158,7 +162,8 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
}
}
protected Inventory findOutputChest(Block b, ItemStack output) {
@Nullable
protected Inventory findOutputChest(@Nonnull Block b, @Nonnull ItemStack output) {
for (BlockFace face : outputFaces) {
Block potentialOutput = b.getRelative(face);
@ -183,6 +188,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
return null;
}
@Nonnull
private static Material[] convertItemStacksToMaterial(ItemStack[] items) {
List<Material> materials = new ArrayList<>();

View File

@ -61,7 +61,7 @@ public class CustomTextureService {
config.setDefaultValue("_UI_NEXT_INACTIVE", 0);
for (SlimefunItem item : items) {
if (item != null && item.getID() != null) {
if (item != null) {
config.setDefaultValue(item.getID(), 0);
if (config.getInt(item.getID()) != 0) {

View File

@ -49,7 +49,7 @@ public class LocalizationService extends SlimefunLocalization implements Persist
private final NamespacedKey languageKey;
private final Language defaultLanguage;
public LocalizationService(SlimefunPlugin plugin, String prefix, String serverDefaultLanguage) {
public LocalizationService(@Nonnull SlimefunPlugin plugin, @Nullable String prefix, @Nullable String serverDefaultLanguage) {
super(plugin);
this.plugin = plugin;
@ -102,17 +102,20 @@ public class LocalizationService extends SlimefunLocalization implements Persist
}
@Override
@Nonnull
public NamespacedKey getKey() {
return languageKey;
}
@Override
@Nullable
public Language getLanguage(@Nonnull String id) {
Validate.notNull(id, "The language id cannot be null");
return languages.get(id);
}
@Override
@Nonnull
public Collection<Language> getLanguages() {
return languages.values();
}

View File

@ -204,7 +204,7 @@ public class PerWorldSettingsService {
Config config = getConfig(world);
for (SlimefunItem item : SlimefunPlugin.getRegistry().getEnabledSlimefunItems()) {
if (item != null && item.getID() != null) {
if (item != null) {
String addon = item.getAddon().getName().toLowerCase(Locale.ROOT);
config.setValue(addon + '.' + item.getID(), !items.contains(item.getID()));
}
@ -245,7 +245,7 @@ public class PerWorldSettingsService {
private void loadItemsFromWorldConfig(String worldName, Config config, Set<String> items) {
for (SlimefunItem item : SlimefunPlugin.getRegistry().getEnabledSlimefunItems()) {
if (item != null && item.getID() != null) {
if (item != null) {
String addon = item.getAddon().getName().toLowerCase(Locale.ROOT);
config.setDefaultValue(addon + ".enabled", true);
config.setDefaultValue(addon + '.' + item.getID(), true);

View File

@ -40,7 +40,7 @@ public class PermissionsService {
public void register(@Nonnull Iterable<SlimefunItem> items, boolean save) {
for (SlimefunItem item : items) {
if (item != null && item.getID() != null) {
if (item != null) {
String path = item.getID() + ".permission";
config.setDefaultValue(path, "none");

View File

@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.guide;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -39,18 +41,18 @@ class RecipeChoiceTask implements Runnable {
* @param inv
* The {@link Inventory} to start this task for
*/
public void start(Inventory inv) {
public void start(@Nonnull Inventory inv) {
Validate.notNull(inv, "Inventory must not be null");
inventory = inv;
id = Bukkit.getScheduler().runTaskTimerAsynchronously(SlimefunPlugin.instance(), this, 0, UPDATE_INTERVAL).getTaskId();
}
public void add(int slot, MaterialChoice choice) {
public void add(int slot, @Nonnull MaterialChoice choice) {
Validate.notNull(choice, "Cannot add a null RecipeChoice");
iterators.put(slot, new LoopIterator<>(choice.getChoices()));
}
public void add(int slot, Tag<Material> tag) {
public void add(int slot, @Nonnull Tag<Material> tag) {
Validate.notNull(tag, "Cannot add a null Tag");
iterators.put(slot, new LoopIterator<>(tag.getValues()));
}

View File

@ -1,4 +1,4 @@
package io.github.thebusybiscuit.slimefun4.implementation.resources;
package io.github.thebusybiscuit.slimefun4.implementation.items.misc;
import org.bukkit.entity.Piglin;
import org.bukkit.inventory.ItemStack;

View File

@ -1,5 +1,8 @@
package io.github.thebusybiscuit.slimefun4.implementation.resources;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.apache.commons.lang.Validate;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
@ -15,6 +18,7 @@ abstract class SlimefunResource implements GEOResource {
private final int maxDeviation;
private final boolean geoMiner;
@ParametersAreNonnullByDefault
SlimefunResource(String key, String defaultName, ItemStack item, int maxDeviation, boolean geoMiner) {
Validate.notNull(key, "NamespacedKey cannot be null!");
Validate.notNull(defaultName, "The default name cannot be null!");
@ -28,16 +32,19 @@ abstract class SlimefunResource implements GEOResource {
}
@Override
@Nonnull
public NamespacedKey getKey() {
return key;
}
@Override
@Nonnull
public String getName() {
return defaultName;
}
@Override
@Nonnull
public ItemStack getItem() {
return item.clone();
}

View File

@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
@ -147,6 +149,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuit
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.CoolantCell;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.OrganicFertilizer;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.OrganicFood;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.StrangeNetherGoo;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.SyntheticEmerald;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.ArmorForge;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.AutomatedPanningMachine;
@ -185,7 +188,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.IcyBow;
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe;
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SwordOfBeheading;
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
import io.github.thebusybiscuit.slimefun4.implementation.resources.StrangeNetherGoo;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
@ -226,7 +228,7 @@ public final class SlimefunItemSetup {
private SlimefunItemSetup() {}
public static void setup(SlimefunPlugin plugin) {
public static void setup(@Nonnull SlimefunPlugin plugin) {
if (registeredItems) {
throw new UnsupportedOperationException("Slimefun Items can only be registered once!");
}

View File

@ -8,6 +8,9 @@ import java.util.Locale;
import java.util.Optional;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Color;
@ -146,7 +149,7 @@ public class SlimefunItemStack extends CustomItem {
setItemId(id);
}
private void setItemId(String id) {
private void setItemId(@Nonnull String id) {
Validate.notNull(id, "The Item id must never be null!");
Validate.isTrue(id.equals(id.toUpperCase(Locale.ROOT)), "Slimefun Item Ids must be uppercase! (e.g. 'MY_ITEM_ID')");
@ -169,7 +172,8 @@ public class SlimefunItemStack extends CustomItem {
*
* @return The {@link SlimefunItem} id for this {@link SlimefunItemStack}
*/
public String getItemId() {
@Nonnull
public final String getItemId() {
return id;
}
@ -179,6 +183,7 @@ public class SlimefunItemStack extends CustomItem {
*
* @return The {@link SlimefunItem} for this {@link SlimefunItemStack}, null if not found.
*/
@Nullable
public SlimefunItem getItem() {
return SlimefunItem.getByID(id);
}
@ -267,7 +272,11 @@ public class SlimefunItemStack extends CustomItem {
return SkullItem.fromBase64(getTexture(id, texture));
}
private static String getTexture(String id, String texture) {
@Nonnull
private static String getTexture(@Nonnull String id, @Nonnull String texture) {
Validate.notNull(id, "The id cannot be null");
Validate.notNull(texture, "The texture cannot be null");
if (texture.startsWith("ey")) {
return texture;
}