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

Merge branch 'master' into master

This commit is contained in:
EpicPlayerA10 2021-06-26 10:12:56 +02:00 committed by GitHub
commit be4a4df832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 290 additions and 120 deletions

View File

@ -29,10 +29,13 @@
## Release Candidate 26 (TBD) ## Release Candidate 26 (TBD)
#### Additions #### Additions
* Diamonds can now be ground into Carbon using a Grind Stone
* Deepslate ores can now be doubled using an Ore Crusher
#### Changes #### Changes
#### Fixes #### Fixes
* Fixed #2966
## Release Candidate 25 (20 Jun 2021) ## Release Candidate 25 (20 Jun 2021)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#25 https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#25

View File

@ -355,7 +355,7 @@
<dependency> <dependency>
<groupId>com.github.seeseemelk</groupId> <groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.16</artifactId> <artifactId>MockBukkit-v1.16</artifactId>
<version>1.3.0</version> <version>1.3.2</version>
<scope>test</scope> <scope>test</scope>
<exclusions> <exclusions>

View File

@ -27,6 +27,7 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.OutputChest; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.OutputChest;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -67,17 +68,16 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
// Override this method to register some default recipes // Override this method to register some default recipes
} }
public List<ItemStack[]> getRecipes() { public @Nonnull List<ItemStack[]> getRecipes() {
return recipes; return recipes;
} }
@Override @Override
public List<ItemStack> getDisplayRecipes() { public @Nonnull List<ItemStack> getDisplayRecipes() {
return displayRecipes; return displayRecipes;
} }
@Nonnull public @Nonnull MultiBlock getMultiBlock() {
public MultiBlock getMultiBlock() {
return multiblock; return multiblock;
} }
@ -112,8 +112,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
} }
} }
@Nonnull protected @Nonnull MultiBlockInteractionHandler getInteractionHandler() {
protected MultiBlockInteractionHandler getInteractionHandler() {
return (p, mb, b) -> { return (p, mb, b) -> {
if (mb.equals(getMultiBlock())) { if (mb.equals(getMultiBlock())) {
if (canUse(p, true) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.INTERACT_BLOCK)) { if (canUse(p, true) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.INTERACT_BLOCK)) {
@ -144,15 +143,14 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
* *
* @return The target {@link Inventory} * @return The target {@link Inventory}
*/ */
@Nullable
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
protected Inventory findOutputInventory(ItemStack adding, Block dispBlock, Inventory dispInv) { protected @Nullable Inventory findOutputInventory(ItemStack adding, Block dispBlock, Inventory dispInv) {
return findOutputInventory(adding, dispBlock, dispInv, dispInv); return findOutputInventory(adding, dispBlock, dispInv, dispInv);
} }
@Nullable
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
protected Inventory findOutputInventory(ItemStack product, Block dispBlock, Inventory dispInv, Inventory placeCheckerInv) { protected @Nullable Inventory findOutputInventory(ItemStack product, Block dispBlock, Inventory dispInv, Inventory placeCheckerInv) {
Optional<Inventory> outputChest = OutputChest.findOutputChestFor(dispBlock, product); Optional<Inventory> outputChest = OutputChest.findOutputChestFor(dispBlock, product);
/* /*
@ -167,8 +165,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
} }
} }
@Nonnull private static @Nonnull Material[] convertItemStacksToMaterial(@Nonnull ItemStack[] items) {
private static Material[] convertItemStacksToMaterial(@Nonnull ItemStack[] items) {
List<Material> materials = new ArrayList<>(); List<Material> materials = new ArrayList<>();
for (ItemStack item : items) { for (ItemStack item : items) {

View File

@ -7,6 +7,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -51,7 +52,6 @@ public abstract class SimpleSlimefunItem<T extends ItemHandler> extends Slimefun
* *
* @return The {@link ItemHandler} that should be added to this {@link SlimefunItem} * @return The {@link ItemHandler} that should be added to this {@link SlimefunItem}
*/ */
@Nonnull public abstract @Nonnull T getItemHandler();
public abstract T getItemHandler();
} }

View File

@ -47,14 +47,13 @@ abstract class AbstractCraftingTable extends MultiBlockMachine {
super(category, item, recipe, trigger); super(category, item, recipe, trigger);
} }
@Nonnull protected @Nonnull Inventory createVirtualInventory(@Nonnull Inventory inv) {
protected Inventory createVirtualInventory(@Nonnull Inventory inv) {
Inventory fakeInv = Bukkit.createInventory(null, 9, "Fake Inventory"); Inventory fakeInv = Bukkit.createInventory(null, 9, "Fake Inventory");
for (int j = 0; j < inv.getContents().length; j++) { for (int j = 0; j < inv.getContents().length; j++) {
ItemStack stack = inv.getContents()[j]; ItemStack stack = inv.getContents()[j];
/** /*
* Fixes #2103 - Properly simulating the consumption * Fixes #2103 - Properly simulating the consumption
* (which may leave behind empty buckets or glass bottles) * (which may leave behind empty buckets or glass bottles)
*/ */
@ -115,8 +114,7 @@ abstract class AbstractCraftingTable extends MultiBlockMachine {
} }
} }
@Nonnull private @Nonnull Optional<String> retrieveID(@Nullable ItemStack backpack, int size) {
private Optional<String> retrieveID(@Nullable ItemStack backpack, int size) {
if (backpack != null) { if (backpack != null) {
for (String line : backpack.getItemMeta().getLore()) { for (String line : backpack.getItemMeta().getLore()) {
if (line.startsWith(ChatColors.color("&7ID: ")) && line.contains("#")) { if (line.startsWith(ChatColors.color("&7ID: ")) && line.contains("#")) {

View File

@ -91,6 +91,9 @@ public class GrindStone extends MultiBlockMachine {
recipes.add(SlimefunItems.ENDER_LUMP_3); recipes.add(SlimefunItems.ENDER_LUMP_3);
recipes.add(new SlimefunItemStack(SlimefunItems.ENDER_LUMP_2, 4)); recipes.add(new SlimefunItemStack(SlimefunItems.ENDER_LUMP_2, 4));
recipes.add(new ItemStack(Material.DIAMOND));
recipes.add(new SlimefunItemStack(SlimefunItems.CARBON, 4));
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -107,8 +108,18 @@ public class OreCrusher extends MultiBlockMachine {
public void postRegister() { public void postRegister() {
super.postRegister(); super.postRegister();
displayRecipes.addAll(Arrays.asList(new ItemStack(Material.COAL_ORE), doubleOres.getCoal(), new ItemStack(Material.LAPIS_ORE), doubleOres.getLapisLazuli(), new ItemStack(Material.REDSTONE_ORE), doubleOres.getRedstone(), new ItemStack(Material.DIAMOND_ORE), doubleOres.getDiamond(), new ItemStack(Material.EMERALD_ORE), doubleOres.getEmerald(), new ItemStack(Material.NETHER_QUARTZ_ORE), doubleOres.getNetherQuartz())); // @formatter:off
displayRecipes.addAll(Arrays.asList(
new ItemStack(Material.COAL_ORE), doubleOres.getCoal(),
new ItemStack(Material.LAPIS_ORE), doubleOres.getLapisLazuli(),
new ItemStack(Material.REDSTONE_ORE), doubleOres.getRedstone(),
new ItemStack(Material.DIAMOND_ORE), doubleOres.getDiamond(),
new ItemStack(Material.EMERALD_ORE), doubleOres.getEmerald(),
new ItemStack(Material.NETHER_QUARTZ_ORE), doubleOres.getNetherQuartz()
));
// @formatter:on
// Gold ore variants (1.16+)
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) { if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) {
displayRecipes.add(new ItemStack(Material.NETHER_GOLD_ORE)); displayRecipes.add(new ItemStack(Material.NETHER_GOLD_ORE));
displayRecipes.add(doubleOres.getGoldNuggets()); displayRecipes.add(doubleOres.getGoldNuggets());
@ -117,6 +128,7 @@ public class OreCrusher extends MultiBlockMachine {
displayRecipes.add(doubleOres.getGoldNuggets()); displayRecipes.add(doubleOres.getGoldNuggets());
} }
// Raw metal ores (1.17+)
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) { if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
displayRecipes.add(new ItemStack(Material.RAW_IRON)); displayRecipes.add(new ItemStack(Material.RAW_IRON));
displayRecipes.add(SlimefunItems.IRON_DUST); displayRecipes.add(SlimefunItems.IRON_DUST);
@ -127,6 +139,19 @@ public class OreCrusher extends MultiBlockMachine {
displayRecipes.add(new ItemStack(Material.RAW_GOLD)); displayRecipes.add(new ItemStack(Material.RAW_GOLD));
displayRecipes.add(SlimefunItems.GOLD_DUST); displayRecipes.add(SlimefunItems.GOLD_DUST);
} }
// Deepslate Ores (1.17+)
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
// @formatter:off
displayRecipes.addAll(Arrays.asList(
new ItemStack(Material.DEEPSLATE_COAL_ORE), doubleOres.getCoal(),
new ItemStack(Material.DEEPSLATE_LAPIS_ORE), doubleOres.getLapisLazuli(),
new ItemStack(Material.DEEPSLATE_REDSTONE_ORE), doubleOres.getRedstone(),
new ItemStack(Material.DEEPSLATE_DIAMOND_ORE), doubleOres.getDiamond(),
new ItemStack(Material.DEEPSLATE_EMERALD_ORE), doubleOres.getEmerald()
));
// @formatter:on
}
} }
@Override @Override
@ -180,7 +205,7 @@ public class OreCrusher extends MultiBlockMachine {
private final ItemStack quartz = new ItemStack(Material.QUARTZ, 1); private final ItemStack quartz = new ItemStack(Material.QUARTZ, 1);
private final ItemStack goldNuggets = new ItemStack(Material.GOLD_NUGGET, 4); private final ItemStack goldNuggets = new ItemStack(Material.GOLD_NUGGET, 4);
public DoubleOreSetting(@Nonnull OreCrusher oreCrusher) { DoubleOreSetting(@Nonnull OreCrusher oreCrusher) {
super(oreCrusher, "double-ores", true); super(oreCrusher, "double-ores", true);
} }
@ -195,12 +220,12 @@ public class OreCrusher extends MultiBlockMachine {
SlimefunItem ironDust = SlimefunItem.getByID("IRON_DUST"); SlimefunItem ironDust = SlimefunItem.getByID("IRON_DUST");
if (ironDust != null) { if (ironDust != null) {
ironDust.setRecipeOutput(new CustomItem(SlimefunItems.IRON_DUST, value ? 2 : 1)); ironDust.setRecipeOutput(new SlimefunItemStack(SlimefunItems.IRON_DUST, value ? 2 : 1));
} }
SlimefunItem goldDust = SlimefunItem.getByID("GOLD_DUST"); SlimefunItem goldDust = SlimefunItem.getByID("GOLD_DUST");
if (goldDust != null) { if (goldDust != null) {
goldDust.setRecipeOutput(new CustomItem(SlimefunItems.GOLD_DUST, value ? 2 : 1)); goldDust.setRecipeOutput(new SlimefunItemStack(SlimefunItems.GOLD_DUST, value ? 2 : 1));
} }
} }
@ -216,31 +241,31 @@ public class OreCrusher extends MultiBlockMachine {
apply(getValue()); apply(getValue());
} }
public ItemStack getCoal() { public @Nonnull ItemStack getCoal() {
return coal; return coal;
} }
public ItemStack getLapisLazuli() { public @Nonnull ItemStack getLapisLazuli() {
return lapis; return lapis;
} }
public ItemStack getRedstone() { public @Nonnull ItemStack getRedstone() {
return redstone; return redstone;
} }
public ItemStack getDiamond() { public @Nonnull ItemStack getDiamond() {
return diamond; return diamond;
} }
public ItemStack getEmerald() { public @Nonnull ItemStack getEmerald() {
return emerald; return emerald;
} }
public ItemStack getNetherQuartz() { public @Nonnull ItemStack getNetherQuartz() {
return quartz; return quartz;
} }
public ItemStack getGoldNuggets() { public @Nonnull ItemStack getGoldNuggets() {
return goldNuggets; return goldNuggets;
} }

View File

@ -4,6 +4,10 @@ import java.util.List;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -20,26 +24,56 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/**
* The {@link OreWasher} is a special {@link MultiBlockMachine} which allows you to
* turn Sifted Ore into ore dusts.
*
* @author TheBusyBiscuit
* @author Sfiguz7
*
*/
public class OreWasher extends MultiBlockMachine { public class OreWasher extends MultiBlockMachine {
private final boolean legacyMode; // @formatter:off
private final ItemStack[] dusts; private final ItemStack[] dusts = new ItemStack[] {
SlimefunItems.IRON_DUST,
SlimefunItems.GOLD_DUST,
SlimefunItems.COPPER_DUST,
SlimefunItems.TIN_DUST,
SlimefunItems.ZINC_DUST,
SlimefunItems.ALUMINUM_DUST,
SlimefunItems.MAGNESIUM_DUST,
SlimefunItems.LEAD_DUST,
SlimefunItems.SILVER_DUST
};
// @formatter:on
private final boolean legacyMode;
@ParametersAreNonnullByDefault
public OreWasher(Category category, SlimefunItemStack item) { public OreWasher(Category category, SlimefunItemStack item) {
super(category, item, new ItemStack[] { null, new ItemStack(Material.DISPENSER), null, null, new ItemStack(Material.OAK_FENCE), null, null, new ItemStack(Material.CAULDRON), null }, BlockFace.SELF); // @formatter:off
super(category, item, new ItemStack[] {
null, new ItemStack(Material.DISPENSER), null,
null, new ItemStack(Material.OAK_FENCE), null,
null, new ItemStack(Material.CAULDRON), null
}, BlockFace.SELF);
// @formatter:on
legacyMode = SlimefunPlugin.getCfg().getBoolean("options.legacy-ore-washer"); legacyMode = SlimefunPlugin.getCfg().getBoolean("options.legacy-ore-washer");
dusts = new ItemStack[] { SlimefunItems.IRON_DUST, SlimefunItems.GOLD_DUST, SlimefunItems.COPPER_DUST, SlimefunItems.TIN_DUST, SlimefunItems.ZINC_DUST, SlimefunItems.ALUMINUM_DUST, SlimefunItems.MAGNESIUM_DUST, SlimefunItems.LEAD_DUST, SlimefunItems.SILVER_DUST };
} }
@Override @Override
protected void registerDefaultRecipes(List<ItemStack> recipes) { protected void registerDefaultRecipes(List<ItemStack> recipes) {
// Iron and Gold are displayed as Ore Crusher recipes, as that is their primary /*
// way of obtaining them. But we also wanna display them here, so we just * Iron and Gold are displayed as Ore Crusher recipes, as that is their primary
// add these two recipes manually * way of obtaining them. But we also wanna display them here, so we just
* add these two recipes manually
*/
recipes.add(SlimefunItems.SIFTED_ORE); recipes.add(SlimefunItems.SIFTED_ORE);
recipes.add(SlimefunItems.IRON_DUST); recipes.add(SlimefunItems.IRON_DUST);
@ -68,14 +102,15 @@ public class OreWasher extends MultiBlockMachine {
Inventory outputInv = null; Inventory outputInv = null;
if (!legacyMode) { if (!legacyMode) {
// This is a fancy way of checking if there is empty space in the inv; by checking if an /*
// unobtainable item could fit in it. * This is a fancy way of checking if there is empty space in the inv
// However, due to the way the method findValidOutputInv() functions, the dummyAdding will * by checking if an unobtainable item could fit in it.
// never * However, due to the way the method findValidOutputInv() functions,
// actually be added to the real inventory, * the dummyAdding will never actually be added to the real inventory,
// so it really doesn't matter what item the ItemStack is made by. SlimefunItems.DEBUG_FISH * so it really doesn't matter what item the ItemStack is made by.
// however, signals that it's * SlimefunItems.DEBUG_FISH however, signals that it's not supposed
// not supposed to be given to the player. * to be given to the player.
*/
ItemStack dummyAdding = SlimefunItems.DEBUG_FISH; ItemStack dummyAdding = SlimefunItems.DEBUG_FISH;
outputInv = findOutputInventory(dummyAdding, dispBlock, inv); outputInv = findOutputInventory(dummyAdding, dispBlock, inv);
} else { } else {
@ -110,7 +145,8 @@ public class OreWasher extends MultiBlockMachine {
} }
} }
private void removeItem(Player p, Block b, Inventory inputInv, Inventory outputInv, ItemStack input, ItemStack output, int amount) { @ParametersAreNonnullByDefault
private void removeItem(Player p, Block b, Inventory inputInv, @Nullable Inventory outputInv, ItemStack input, ItemStack output, int amount) {
if (outputInv != null) { if (outputInv != null) {
ItemStack removing = input.clone(); ItemStack removing = input.clone();
removing.setAmount(amount); removing.setAmount(amount);
@ -129,7 +165,7 @@ public class OreWasher extends MultiBlockMachine {
* *
* @return A randomly picked dust item * @return A randomly picked dust item
*/ */
public ItemStack getRandomDust() { public @Nonnull ItemStack getRandomDust() {
int index = ThreadLocalRandom.current().nextInt(dusts.length); int index = ThreadLocalRandom.current().nextInt(dusts.length);
return dusts[index].clone(); return dusts[index].clone();
} }

View File

@ -3,7 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -16,6 +17,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
@ -26,6 +28,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class PressureChamber extends MultiBlockMachine { public class PressureChamber extends MultiBlockMachine {
@ParametersAreNonnullByDefault
public PressureChamber(Category category, SlimefunItemStack item) { public PressureChamber(Category category, SlimefunItemStack item) {
super(category, item, new ItemStack[] { new ItemStack(Material.SMOOTH_STONE_SLAB), new CustomItem(Material.DISPENSER, "Dispenser (Facing down)"), new ItemStack(Material.SMOOTH_STONE_SLAB), new ItemStack(Material.PISTON), new ItemStack(Material.GLASS), new ItemStack(Material.PISTON), new ItemStack(Material.PISTON), new ItemStack(Material.CAULDRON), new ItemStack(Material.PISTON) }, BlockFace.UP); super(category, item, new ItemStack[] { new ItemStack(Material.SMOOTH_STONE_SLAB), new CustomItem(Material.DISPENSER, "Dispenser (Facing down)"), new ItemStack(Material.SMOOTH_STONE_SLAB), new ItemStack(Material.PISTON), new ItemStack(Material.GLASS), new ItemStack(Material.PISTON), new ItemStack(Material.PISTON), new ItemStack(Material.CAULDRON), new ItemStack(Material.PISTON) }, BlockFace.UP);
} }
@ -67,7 +70,7 @@ public class PressureChamber extends MultiBlockMachine {
SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true); SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
} }
} }
@ParametersAreNonnullByDefault
private void craft(Player p, Block b, ItemStack output, Inventory outputInv, Dispenser dispenser) { private void craft(Player p, Block b, ItemStack output, Inventory outputInv, Dispenser dispenser) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
int j = i; int j = i;

View File

@ -15,7 +15,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
* @author TheBusyBiscuit * @author TheBusyBiscuit
* *
* @see IndustrialMiner * @see IndustrialMiner
* @see ActiveMiner * @see MiningTask
* *
*/ */
public class AdvancedIndustrialMiner extends IndustrialMiner { public class AdvancedIndustrialMiner extends IndustrialMiner {

View File

@ -7,6 +7,7 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
@ -27,6 +28,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@ -41,17 +43,17 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
* @author TheBusyBiscuit * @author TheBusyBiscuit
* *
* @see AdvancedIndustrialMiner * @see AdvancedIndustrialMiner
* @see ActiveMiner * @see MiningTask
* *
*/ */
public class IndustrialMiner extends MultiBlockMachine { public class IndustrialMiner extends MultiBlockMachine {
protected final Map<Location, ActiveMiner> activeMiners = new HashMap<>(); protected final Map<Location, MiningTask> activeMiners = new HashMap<>();
protected final List<MachineFuel> fuelTypes = new ArrayList<>(); protected final List<MachineFuel> fuelTypes = new ArrayList<>();
private final int range;
private final boolean silkTouch;
private final ItemSetting<Boolean> canMineAncientDebris = new ItemSetting<>(this, "can-mine-ancient-debris", false); private final ItemSetting<Boolean> canMineAncientDebris = new ItemSetting<>(this, "can-mine-ancient-debris", false);
private final boolean silkTouch;
private final int range;
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public IndustrialMiner(Category category, SlimefunItemStack item, Material baseMaterial, boolean silkTouch, int range) { public IndustrialMiner(Category category, SlimefunItemStack item, Material baseMaterial, boolean silkTouch, int range) {
@ -115,7 +117,7 @@ public class IndustrialMiner extends MultiBlockMachine {
* *
* @return The outcome when mining this ore * @return The outcome when mining this ore
*/ */
public ItemStack getOutcome(Material ore) { public @Nonnull ItemStack getOutcome(@Nonnull Material ore) {
if (hasSilkTouch()) { if (hasSilkTouch()) {
return new ItemStack(ore); return new ItemStack(ore);
} }
@ -149,8 +151,10 @@ public class IndustrialMiner extends MultiBlockMachine {
* @param item * @param item
* The item that shall be consumed * The item that shall be consumed
*/ */
public void addFuelType(int ores, ItemStack item) { public void addFuelType(int ores, @Nonnull ItemStack item) {
Validate.isTrue(ores > 1 && ores % 2 == 0, "The amount of ores must be at least 2 and a multiple of 2."); Validate.isTrue(ores > 1 && ores % 2 == 0, "The amount of ores must be at least 2 and a multiple of 2.");
Validate.notNull(item, "The fuel item cannot be null");
fuelTypes.add(new MachineFuel(ores / 2, item)); fuelTypes.add(new MachineFuel(ores / 2, item));
} }
@ -190,11 +194,11 @@ public class IndustrialMiner extends MultiBlockMachine {
Block start = b.getRelative(-mod, -1, -mod); Block start = b.getRelative(-mod, -1, -mod);
Block end = b.getRelative(mod, -1, mod); Block end = b.getRelative(mod, -1, mod);
ActiveMiner instance = new ActiveMiner(this, p.getUniqueId(), chest, pistons, start, end); MiningTask task = new MiningTask(this, p.getUniqueId(), chest, pistons, start, end);
instance.start(b); task.start(b);
} }
private Block[] findPistons(Block chest) { private @Nonnull Block[] findPistons(@Nonnull Block chest) {
Block northern = chest.getRelative(BlockFace.NORTH); Block northern = chest.getRelative(BlockFace.NORTH);
if (northern.getType() == Material.PISTON) { if (northern.getType() == Material.PISTON) {
@ -212,7 +216,7 @@ public class IndustrialMiner extends MultiBlockMachine {
* *
* @return Whether this {@link IndustrialMiner} is capable of mining this {@link Material} * @return Whether this {@link IndustrialMiner} is capable of mining this {@link Material}
*/ */
public boolean canMine(Material type) { public boolean canMine(@Nonnull Material type) {
if (SlimefunTag.INDUSTRIAL_MINER_ORES.isTagged(type)) { if (SlimefunTag.INDUSTRIAL_MINER_ORES.isTagged(type)) {
return true; return true;
} else if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) { } else if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) {

View File

@ -0,0 +1,63 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner;
import javax.annotation.Nonnull;
import org.bukkit.block.Chest;
import org.bukkit.block.data.type.Piston;
import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock;
/**
* This enum holds various different reasons as to why an {@link IndustrialMiner}
* may stop mining.
*
* @author TheBusyBiscuit
*
*/
enum MinerStoppingReason {
/**
* The {@link IndustrialMiner} has run out of fuel.
*/
NO_FUEL("machines.INDUSTRIAL_MINER.no-fuel"),
/**
* The {@link IndustrialMiner} has entered a region where
* the {@link Player} has no permission to build.
*/
NO_PERMISSION("machines.INDUSTRIAL_MINER.no-permission"),
/**
* The {@link Chest} of our {@link IndustrialMiner} is full.
*/
CHEST_FULL("machines.INDUSTRIAL_MINER.chest-full"),
/**
* The {@link MultiBlock} structure of the {@link IndustrialMiner}
* has been destroyed.
*/
STRUCTURE_DESTROYED("machines.INDUSTRIAL_MINER.destroyed"),
/**
* The {@link Piston}s inside the structure faces the wrong way.
*/
PISTON_WRONG_DIRECTION("machines.INDUSTRIAL_MINER.piston-facing"),
/**
* The {@link Piston}s have no space to move.
*/
PISTON_NO_SPACE("machines.INDUSTRIAL_MINER.piston-space");
private final String messageKey;
MinerStoppingReason(@Nonnull String messageKey) {
this.messageKey = messageKey;
}
@Nonnull
String getErrorMessage() {
return messageKey;
}
}

View File

@ -3,6 +3,9 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.mine
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Location; import org.bukkit.Location;
@ -26,6 +29,7 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.cscorelib2.scheduling.TaskQueue; import io.github.thebusybiscuit.cscorelib2.scheduling.TaskQueue;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
/** /**
@ -37,15 +41,11 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
* @see AdvancedIndustrialMiner * @see AdvancedIndustrialMiner
* *
*/ */
class ActiveMiner implements Runnable { class MiningTask implements Runnable {
private final IndustrialMiner miner; private final IndustrialMiner miner;
private final UUID owner; private final UUID owner;
private int fuel = 0;
private int ores = 0;
private boolean running = false;
private final Block chest; private final Block chest;
private final Block[] pistons; private final Block[] pistons;
@ -53,10 +53,15 @@ class ActiveMiner implements Runnable {
private final BlockPosition end; private final BlockPosition end;
private final int height; private final int height;
private boolean running = false;
private int fuel = 0;
private int ores = 0;
private int x; private int x;
private int z; private int z;
public ActiveMiner(IndustrialMiner miner, UUID owner, Block chest, Block[] pistons, Block start, Block end) { @ParametersAreNonnullByDefault
MiningTask(IndustrialMiner miner, UUID owner, Block chest, Block[] pistons, Block start, Block end) {
this.miner = miner; this.miner = miner;
this.owner = owner; this.owner = owner;
@ -77,7 +82,7 @@ class ActiveMiner implements Runnable {
* @param b * @param b
* The {@link Block} which marks the center of this {@link IndustrialMiner} * The {@link Block} which marks the center of this {@link IndustrialMiner}
*/ */
public void start(Block b) { void start(@Nonnull Block b) {
miner.activeMiners.put(b.getLocation(), this); miner.activeMiners.put(b.getLocation(), this);
running = true; running = true;
@ -87,7 +92,7 @@ class ActiveMiner implements Runnable {
/** /**
* This method stops the {@link IndustrialMiner}. * This method stops the {@link IndustrialMiner}.
*/ */
public void stop() { void stop() {
running = false; running = false;
miner.activeMiners.remove(chest.getRelative(BlockFace.DOWN).getLocation()); miner.activeMiners.remove(chest.getRelative(BlockFace.DOWN).getLocation());
} }
@ -96,14 +101,14 @@ class ActiveMiner implements Runnable {
* This method stops the {@link IndustrialMiner} with an error message. * This method stops the {@link IndustrialMiner} with an error message.
* The error message is a path to the location in Slimefun's localization files. * The error message is a path to the location in Slimefun's localization files.
* *
* @param error * @param reason
* The error message to send * The reason why we stop
*/ */
public void stop(String error) { void stop(@Nonnull MinerStoppingReason reason) {
Player p = Bukkit.getPlayer(owner); Player p = Bukkit.getPlayer(owner);
if (p != null) { if (p != null) {
SlimefunPlugin.getLocalization().sendMessage(p, error); SlimefunPlugin.getLocalization().sendMessage(p, reason.getErrorMessage());
} }
stop(); stop();
@ -117,12 +122,14 @@ class ActiveMiner implements Runnable {
if (fuel <= 0) { if (fuel <= 0) {
// This Miner has not enough fuel. // This Miner has not enough fuel.
stop("machines.INDUSTRIAL_MINER.no-fuel"); stop(MinerStoppingReason.NO_FUEL);
return; return;
} }
// This is our warm up animation /*
// The pistons will push after another in decreasing intervals * This is our warm up animation.
* The pistons will push after another in decreasing intervals
*/
TaskQueue queue = new TaskQueue(); TaskQueue queue = new TaskQueue();
queue.thenRun(4, () -> setPistonState(pistons[0], true)); queue.thenRun(4, () -> setPistonState(pistons[0], true));
@ -177,7 +184,7 @@ class ActiveMiner implements Runnable {
Block b = start.getWorld().getBlockAt(x, y, z); Block b = start.getWorld().getBlockAt(x, y, z);
if (!SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(owner), b, ProtectableAction.BREAK_BLOCK)) { if (!SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(owner), b, ProtectableAction.BREAK_BLOCK)) {
stop("machines.INDUSTRIAL_MINER.no-permission"); stop(MinerStoppingReason.NO_PERMISSION);
return; return;
} }
@ -240,7 +247,7 @@ class ActiveMiner implements Runnable {
* *
* @return Whether the operation was successful * @return Whether the operation was successful
*/ */
private boolean push(ItemStack item) { private boolean push(@Nonnull ItemStack item) {
if (fuel < 1) { if (fuel < 1) {
// Restock fuel // Restock fuel
fuel = consumeFuel(); fuel = consumeFuel();
@ -258,18 +265,18 @@ class ActiveMiner implements Runnable {
inv.addItem(item); inv.addItem(item);
return true; return true;
} else { } else {
stop("machines.INDUSTRIAL_MINER.chest-full"); stop(MinerStoppingReason.CHEST_FULL);
} }
} else { } else {
// I won't question how this happened... // I won't question how this happened...
stop("machines.INDUSTRIAL_MINER.destroyed"); stop(MinerStoppingReason.STRUCTURE_DESTROYED);
} }
} else { } else {
// The chest has been destroyed // The chest has been destroyed
stop("machines.INDUSTRIAL_MINER.destroyed"); stop(MinerStoppingReason.STRUCTURE_DESTROYED);
} }
} else { } else {
stop("machines.INDUSTRIAL_MINER.no-fuel"); stop(MinerStoppingReason.NO_FUEL);
} }
return false; return false;
@ -293,7 +300,7 @@ class ActiveMiner implements Runnable {
return 0; return 0;
} }
private int consumeFuel(Inventory inv) { private int consumeFuel(@Nonnull Inventory inv) {
for (int i = 0; i < inv.getSize(); i++) { for (int i = 0; i < inv.getSize(); i++) {
for (MachineFuel fuelType : miner.fuelTypes) { for (MachineFuel fuelType : miner.fuelTypes) {
ItemStack item = inv.getContents()[i]; ItemStack item = inv.getContents()[i];
@ -313,7 +320,7 @@ class ActiveMiner implements Runnable {
return 0; return 0;
} }
private void setPistonState(Block block, boolean extended) { private void setPistonState(@Nonnull Block block, boolean extended) {
if (!running) { if (!running) {
return; return;
} }
@ -338,15 +345,15 @@ class ActiveMiner implements Runnable {
setExtended(block, piston, extended); setExtended(block, piston, extended);
} else { } else {
// The pistons must be facing upwards // The pistons must be facing upwards
stop("machines.INDUSTRIAL_MINER.piston-facing"); stop(MinerStoppingReason.PISTON_WRONG_DIRECTION);
} }
} else { } else {
// The pistons must be facing upwards // The pistons must be facing upwards
stop("machines.INDUSTRIAL_MINER.piston-space"); stop(MinerStoppingReason.PISTON_NO_SPACE);
} }
} else { } else {
// The piston has been destroyed // The piston has been destroyed
stop("machines.INDUSTRIAL_MINER.destroyed"); stop(MinerStoppingReason.STRUCTURE_DESTROYED);
} }
} catch (Exception e) { } catch (Exception e) {
SlimefunPlugin.logger().log(Level.SEVERE, e, () -> "An Error occurred while moving a Piston for an Industrial Miner at " + new BlockPosition(block)); SlimefunPlugin.logger().log(Level.SEVERE, e, () -> "An Error occurred while moving a Piston for an Industrial Miner at " + new BlockPosition(block));
@ -354,7 +361,7 @@ class ActiveMiner implements Runnable {
} }
} }
private void setExtended(Block block, Piston piston, boolean extended) { private void setExtended(@Nonnull Block block, @Nonnull Piston piston, boolean extended) {
piston.setExtended(extended); piston.setExtended(extended);
block.setBlockData(piston, false); block.setBlockData(piston, false);

View File

@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.seasonal;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -13,6 +14,7 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils; import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -39,7 +41,7 @@ public class ChristmasPresent extends SimpleSlimefunItem<ItemUseHandler> impleme
} }
@Override @Override
public ItemUseHandler getItemHandler() { public @Nonnull ItemUseHandler getItemHandler() {
return e -> { return e -> {
e.cancel(); e.cancel();

View File

@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.seasonal;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -39,7 +40,7 @@ public class EasterEgg extends SimpleSlimefunItem<ItemUseHandler> {
} }
@Override @Override
public ItemUseHandler getItemHandler() { public @Nonnull ItemUseHandler getItemHandler() {
return e -> { return e -> {
e.cancel(); e.cancel();

View File

@ -104,23 +104,20 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
* *
* @return a random {@link ItemStack} obtained by this {@link GoldPan} * @return a random {@link ItemStack} obtained by this {@link GoldPan}
*/ */
@Nonnull public @Nonnull ItemStack getRandomOutput() {
public ItemStack getRandomOutput() {
ItemStack item = randomizer.getRandom(); ItemStack item = randomizer.getRandom();
// Fixes #2804 // Fixes #2804
return item != null ? item : new ItemStack(Material.AIR); return item != null ? item : new ItemStack(Material.AIR);
} }
@Nonnull
@Override @Override
public String getLabelLocalPath() { public @Nonnull String getLabelLocalPath() {
return "guide.tooltips.recipes.gold-pan"; return "guide.tooltips.recipes.gold-pan";
} }
@Nonnull
@Override @Override
public ItemUseHandler getItemHandler() { public @Nonnull ItemUseHandler getItemHandler() {
return e -> { return e -> {
Optional<Block> block = e.getClickedBlock(); Optional<Block> block = e.getClickedBlock();
@ -151,8 +148,7 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
* *
* @return the {@link EntityInteractHandler} of this {@link SlimefunItem} * @return the {@link EntityInteractHandler} of this {@link SlimefunItem}
*/ */
@Nonnull public @Nonnull EntityInteractHandler onEntityInteract() {
public EntityInteractHandler onEntityInteract() {
return (e, item, offHand) -> { return (e, item, offHand) -> {
if (!(e.getRightClicked() instanceof ItemFrame)) { if (!(e.getRightClicked() instanceof ItemFrame)) {
e.setCancelled(true); e.setCancelled(true);
@ -160,9 +156,8 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
}; };
} }
@Nonnull
@Override @Override
public List<ItemStack> getDisplayRecipes() { public @Nonnull List<ItemStack> getDisplayRecipes() {
List<ItemStack> recipes = new LinkedList<>(); List<ItemStack> recipes = new LinkedList<>();
for (GoldPanDrop drop : drops) { for (GoldPanDrop drop : drops) {

View File

@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -22,6 +23,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.GrapplingHookListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.GrapplingHookListener;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -51,7 +53,7 @@ public class GrapplingHook extends SimpleSlimefunItem<ItemUseHandler> {
} }
@Override @Override
public ItemUseHandler getItemHandler() { public @Nonnull ItemUseHandler getItemHandler() {
return e -> { return e -> {
Player p = e.getPlayer(); Player p = e.getPlayer();
UUID uuid = p.getUniqueId(); UUID uuid = p.getUniqueId();

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools; package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,6 +11,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@ -22,7 +24,7 @@ public class HerculesPickaxe extends SimpleSlimefunItem<ToolUseHandler> {
} }
@Override @Override
public ToolUseHandler getItemHandler() { public @Nonnull ToolUseHandler getItemHandler() {
return (e, tool, fortune, drops) -> { return (e, tool, fortune, drops) -> {
if (SlimefunTag.ORES.isTagged(e.getBlock().getType())) { if (SlimefunTag.ORES.isTagged(e.getBlock().getType())) {
if (e.getBlock().getType() == Material.IRON_ORE) { if (e.getBlock().getType() == Material.IRON_ORE) {

View File

@ -17,6 +17,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@ -39,7 +40,7 @@ public class PickaxeOfTheSeeker extends SimpleSlimefunItem<ItemUseHandler> imple
} }
@Override @Override
public ItemUseHandler getItemHandler() { public @Nonnull ItemUseHandler getItemHandler() {
return e -> { return e -> {
Player p = e.getPlayer(); Player p = e.getPlayer();
Block closest = findClosestOre(p); Block closest = findClosestOre(p);
@ -69,8 +70,7 @@ public class PickaxeOfTheSeeker extends SimpleSlimefunItem<ItemUseHandler> imple
}; };
} }
@Nullable private @Nullable Block findClosestOre(@Nonnull Player p) {
private Block findClosestOre(@Nonnull Player p) {
Block start = p.getLocation().getBlock(); Block start = p.getLocation().getBlock();
Block closest = null; Block closest = null;
double lastDistance = Double.MAX_VALUE; double lastDistance = Double.MAX_VALUE;

View File

@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Effect; import org.bukkit.Effect;
@ -20,6 +21,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@ -43,7 +45,7 @@ public class PickaxeOfVeinMining extends SimpleSlimefunItem<ToolUseHandler> {
} }
@Override @Override
public ToolUseHandler getItemHandler() { public @Nonnull ToolUseHandler getItemHandler() {
return (e, tool, fortune, drops) -> { return (e, tool, fortune, drops) -> {
if (SlimefunTag.PICKAXE_OF_VEIN_MINING_BLOCKS.isTagged(e.getBlock().getType())) { if (SlimefunTag.PICKAXE_OF_VEIN_MINING_BLOCKS.isTagged(e.getBlock().getType())) {
List<Block> blocks = Vein.find(e.getBlock(), maxBlocks.getValue(), b -> SlimefunTag.PICKAXE_OF_VEIN_MINING_BLOCKS.isTagged(b.getType())); List<Block> blocks = Vein.find(e.getBlock(), maxBlocks.getValue(), b -> SlimefunTag.PICKAXE_OF_VEIN_MINING_BLOCKS.isTagged(b.getType()));

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools; package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -10,6 +11,7 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@ -29,7 +31,7 @@ public class PortableCrafter extends SimpleSlimefunItem<ItemUseHandler> implemen
} }
@Override @Override
public ItemUseHandler getItemHandler() { public @Nonnull ItemUseHandler getItemHandler() {
return e -> { return e -> {
e.cancel(); e.cancel();

View File

@ -1,20 +1,32 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools; package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/**
* The {@link PortableDustbin} is one of the oldest items in Slimefun.
* It simply opens an empty {@link Inventory} in which you can dump any
* unwanted {@link ItemStack}. When closing the {@link Inventory}, all items
* will be voided.
*
* @author TheBusyBiscuit
*
*/
public class PortableDustbin extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable { public class PortableDustbin extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable {
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
@ -23,7 +35,7 @@ public class PortableDustbin extends SimpleSlimefunItem<ItemUseHandler> implemen
} }
@Override @Override
public ItemUseHandler getItemHandler() { public @Nonnull ItemUseHandler getItemHandler() {
return e -> { return e -> {
e.cancel(); e.cancel();

View File

@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import java.util.Collection; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -15,6 +15,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
@ -34,7 +35,7 @@ public class SmeltersPickaxe extends SimpleSlimefunItem<ToolUseHandler> implemen
} }
@Override @Override
public ToolUseHandler getItemHandler() { public @Nonnull ToolUseHandler getItemHandler() {
return (e, tool, fortune, drops) -> { return (e, tool, fortune, drops) -> {
Block b = e.getBlock(); Block b = e.getBlock();

View File

@ -24,6 +24,7 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@ -45,7 +46,7 @@ public class TapeMeasure extends SimpleSlimefunItem<ItemUseHandler> implements N
} }
@Override @Override
public ItemUseHandler getItemHandler() { public @Nonnull ItemUseHandler getItemHandler() {
return e -> { return e -> {
e.cancel(); e.cancel();
@ -90,9 +91,8 @@ public class TapeMeasure extends SimpleSlimefunItem<ItemUseHandler> implements N
} }
} }
@Nonnull
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public Optional<Location> getAnchor(Player p, ItemStack item) { public @Nonnull Optional<Location> getAnchor(Player p, ItemStack item) {
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
String data = meta.getPersistentDataContainer().get(key, PersistentDataType.STRING); String data = meta.getPersistentDataContainer().get(key, PersistentDataType.STRING);
@ -119,7 +119,7 @@ public class TapeMeasure extends SimpleSlimefunItem<ItemUseHandler> implements N
} }
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public OptionalDouble getDistance(Player p, ItemStack item, Block block) { public @Nonnull OptionalDouble getDistance(Player p, ItemStack item, Block block) {
Optional<Location> anchor = getAnchor(p, item); Optional<Location> anchor = getAnchor(p, item);
if (anchor.isPresent()) { if (anchor.isPresent()) {

View File

@ -1,6 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners; package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
@ -106,7 +106,7 @@ public class DebugFishListener implements Listener {
} }
} else { } else {
// Read applicable Slimefun tags // Read applicable Slimefun tags
Set<SlimefunTag> tags = new HashSet<>(); Set<SlimefunTag> tags = EnumSet.noneOf(SlimefunTag.class);
for (SlimefunTag tag : SlimefunTag.values()) { for (SlimefunTag tag : SlimefunTag.values()) {
if (tag.isTagged(b.getType())) { if (tag.isTagged(b.getType())) {

View File

@ -19,6 +19,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.elevator.Elevator
import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.AbstractTeleporterPlate; import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.AbstractTeleporterPlate;
import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.Teleporter; import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.Teleporter;
import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.TeleporterPylon; import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.TeleporterPylon;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
@ -26,13 +27,19 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
* This {@link Listener} is responsible for the {@link Teleporter} (and {@link ElevatorPlate}). * This {@link Listener} is responsible for the {@link Teleporter} (and {@link ElevatorPlate}).
* *
* @author TheBusyBiscuit * @author TheBusyBiscuit
* @author Walshy
* @author Sfiguz7 * @author Sfiguz7
* @author SoSeDiK * @author SoSeDiK
* *
*/ */
public class TeleporterListener implements Listener { public class TeleporterListener implements Listener {
private final BlockFace[] faces = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST }; // @formatter:off
private final BlockFace[] faces = {
BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST,
BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST
};
// @formatter:on
public TeleporterListener(@Nonnull SlimefunPlugin plugin) { public TeleporterListener(@Nonnull SlimefunPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
@ -48,6 +55,11 @@ public class TeleporterListener implements Listener {
SlimefunItem item = BlockStorage.check(b); SlimefunItem item = BlockStorage.check(b);
Player p = e.getPlayer(); Player p = e.getPlayer();
// Fixes #2966 - Check if Players can use these
if (item == null || !item.canUse(p, true)) {
return;
}
if (item instanceof ElevatorPlate) { if (item instanceof ElevatorPlate) {
// Pressure plate was an elevator // Pressure plate was an elevator
ElevatorPlate elevator = SlimefunItems.ELEVATOR_PLATE.getItem(ElevatorPlate.class); ElevatorPlate elevator = SlimefunItems.ELEVATOR_PLATE.getItem(ElevatorPlate.class);
@ -59,7 +71,7 @@ public class TeleporterListener implements Listener {
if (teleporter instanceof Teleporter && checkForPylons(b.getRelative(BlockFace.DOWN))) { if (teleporter instanceof Teleporter && checkForPylons(b.getRelative(BlockFace.DOWN))) {
Block block = b.getRelative(BlockFace.DOWN); Block block = b.getRelative(BlockFace.DOWN);
UUID owner = UUID.fromString(BlockStorage.getLocationInfo(block.getLocation(), "owner")); UUID owner = UUID.fromString(BlockStorage.getLocationInfo(block.getLocation(), "owner"));
SlimefunPlugin.getGPSNetwork().getTeleportationManager().openTeleporterGUI(p, owner, block); SlimefunPlugin.getGPSNetwork().getTeleportationManager().openTeleporterGUI(p, owner, block, SlimefunPlugin.getGPSNetwork().getNetworkComplexity(owner));
} }
} }
} }

View File

@ -52,7 +52,7 @@ class TestItemStackWrapper {
Assertions.assertEquals(item.getType(), wrapper.getType()); Assertions.assertEquals(item.getType(), wrapper.getType());
Assertions.assertEquals(item.hasItemMeta(), wrapper.hasItemMeta()); Assertions.assertEquals(item.hasItemMeta(), wrapper.hasItemMeta());
Assertions.assertEquals(item.getItemMeta(), wrapper.getItemMeta()); // Assertions.assertEquals(item.getItemMeta(), wrapper.getItemMeta());
Assertions.assertTrue(SlimefunUtils.isItemSimilar(wrapper, item, true)); Assertions.assertTrue(SlimefunUtils.isItemSimilar(wrapper, item, true));
} }