mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
be4a4df832
@ -29,10 +29,13 @@
|
||||
## Release Candidate 26 (TBD)
|
||||
|
||||
#### Additions
|
||||
* Diamonds can now be ground into Carbon using a Grind Stone
|
||||
* Deepslate ores can now be doubled using an Ore Crusher
|
||||
|
||||
#### Changes
|
||||
|
||||
#### Fixes
|
||||
* Fixed #2966
|
||||
|
||||
## Release Candidate 25 (20 Jun 2021)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#25
|
||||
|
2
pom.xml
2
pom.xml
@ -355,7 +355,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.seeseemelk</groupId>
|
||||
<artifactId>MockBukkit-v1.16</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>1.3.2</version>
|
||||
<scope>test</scope>
|
||||
|
||||
<exclusions>
|
||||
|
@ -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.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.OutputChest;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
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
|
||||
}
|
||||
|
||||
public List<ItemStack[]> getRecipes() {
|
||||
public @Nonnull List<ItemStack[]> getRecipes() {
|
||||
return recipes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDisplayRecipes() {
|
||||
public @Nonnull List<ItemStack> getDisplayRecipes() {
|
||||
return displayRecipes;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public MultiBlock getMultiBlock() {
|
||||
public @Nonnull MultiBlock getMultiBlock() {
|
||||
return multiblock;
|
||||
}
|
||||
|
||||
@ -112,8 +112,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
protected MultiBlockInteractionHandler getInteractionHandler() {
|
||||
protected @Nonnull MultiBlockInteractionHandler getInteractionHandler() {
|
||||
return (p, mb, b) -> {
|
||||
if (mb.equals(getMultiBlock())) {
|
||||
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}
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@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);
|
||||
|
||||
/*
|
||||
@ -167,8 +165,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static Material[] convertItemStacksToMaterial(@Nonnull ItemStack[] items) {
|
||||
private static @Nonnull Material[] convertItemStacksToMaterial(@Nonnull ItemStack[] items) {
|
||||
List<Material> materials = new ArrayList<>();
|
||||
|
||||
for (ItemStack item : items) {
|
||||
|
@ -7,6 +7,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
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}
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract T getItemHandler();
|
||||
public abstract @Nonnull T getItemHandler();
|
||||
|
||||
}
|
||||
|
@ -47,14 +47,13 @@ abstract class AbstractCraftingTable extends MultiBlockMachine {
|
||||
super(category, item, recipe, trigger);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
protected Inventory createVirtualInventory(@Nonnull Inventory inv) {
|
||||
protected @Nonnull Inventory createVirtualInventory(@Nonnull Inventory inv) {
|
||||
Inventory fakeInv = Bukkit.createInventory(null, 9, "Fake Inventory");
|
||||
|
||||
for (int j = 0; j < inv.getContents().length; j++) {
|
||||
ItemStack stack = inv.getContents()[j];
|
||||
|
||||
/**
|
||||
/*
|
||||
* Fixes #2103 - Properly simulating the consumption
|
||||
* (which may leave behind empty buckets or glass bottles)
|
||||
*/
|
||||
@ -115,8 +114,7 @@ abstract class AbstractCraftingTable extends MultiBlockMachine {
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private Optional<String> retrieveID(@Nullable ItemStack backpack, int size) {
|
||||
private @Nonnull Optional<String> retrieveID(@Nullable ItemStack backpack, int size) {
|
||||
if (backpack != null) {
|
||||
for (String line : backpack.getItemMeta().getLore()) {
|
||||
if (line.startsWith(ChatColors.color("&7ID: ")) && line.contains("#")) {
|
||||
|
@ -91,6 +91,9 @@ public class GrindStone extends MultiBlockMachine {
|
||||
|
||||
recipes.add(SlimefunItems.ENDER_LUMP_3);
|
||||
recipes.add(new SlimefunItemStack(SlimefunItems.ENDER_LUMP_2, 4));
|
||||
|
||||
recipes.add(new ItemStack(Material.DIAMOND));
|
||||
recipes.add(new SlimefunItemStack(SlimefunItems.CARBON, 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import io.papermc.lib.PaperLib;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
@ -107,8 +108,18 @@ public class OreCrusher extends MultiBlockMachine {
|
||||
public void 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)) {
|
||||
displayRecipes.add(new ItemStack(Material.NETHER_GOLD_ORE));
|
||||
displayRecipes.add(doubleOres.getGoldNuggets());
|
||||
@ -117,6 +128,7 @@ public class OreCrusher extends MultiBlockMachine {
|
||||
displayRecipes.add(doubleOres.getGoldNuggets());
|
||||
}
|
||||
|
||||
// Raw metal ores (1.17+)
|
||||
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
|
||||
displayRecipes.add(new ItemStack(Material.RAW_IRON));
|
||||
displayRecipes.add(SlimefunItems.IRON_DUST);
|
||||
@ -127,6 +139,19 @@ public class OreCrusher extends MultiBlockMachine {
|
||||
displayRecipes.add(new ItemStack(Material.RAW_GOLD));
|
||||
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
|
||||
@ -180,7 +205,7 @@ public class OreCrusher extends MultiBlockMachine {
|
||||
private final ItemStack quartz = new ItemStack(Material.QUARTZ, 1);
|
||||
private final ItemStack goldNuggets = new ItemStack(Material.GOLD_NUGGET, 4);
|
||||
|
||||
public DoubleOreSetting(@Nonnull OreCrusher oreCrusher) {
|
||||
DoubleOreSetting(@Nonnull OreCrusher oreCrusher) {
|
||||
super(oreCrusher, "double-ores", true);
|
||||
}
|
||||
|
||||
@ -195,12 +220,12 @@ public class OreCrusher extends MultiBlockMachine {
|
||||
|
||||
SlimefunItem ironDust = SlimefunItem.getByID("IRON_DUST");
|
||||
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");
|
||||
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());
|
||||
}
|
||||
|
||||
public ItemStack getCoal() {
|
||||
public @Nonnull ItemStack getCoal() {
|
||||
return coal;
|
||||
}
|
||||
|
||||
public ItemStack getLapisLazuli() {
|
||||
public @Nonnull ItemStack getLapisLazuli() {
|
||||
return lapis;
|
||||
}
|
||||
|
||||
public ItemStack getRedstone() {
|
||||
public @Nonnull ItemStack getRedstone() {
|
||||
return redstone;
|
||||
}
|
||||
|
||||
public ItemStack getDiamond() {
|
||||
public @Nonnull ItemStack getDiamond() {
|
||||
return diamond;
|
||||
}
|
||||
|
||||
public ItemStack getEmerald() {
|
||||
public @Nonnull ItemStack getEmerald() {
|
||||
return emerald;
|
||||
}
|
||||
|
||||
public ItemStack getNetherQuartz() {
|
||||
public @Nonnull ItemStack getNetherQuartz() {
|
||||
return quartz;
|
||||
}
|
||||
|
||||
public ItemStack getGoldNuggets() {
|
||||
public @Nonnull ItemStack getGoldNuggets() {
|
||||
return goldNuggets;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,10 @@ import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
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.utils.SlimefunUtils;
|
||||
import io.papermc.lib.PaperLib;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
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 {
|
||||
|
||||
private final boolean legacyMode;
|
||||
private final ItemStack[] dusts;
|
||||
// @formatter:off
|
||||
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) {
|
||||
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");
|
||||
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
|
||||
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
|
||||
// add these two recipes manually
|
||||
/*
|
||||
* 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
|
||||
* add these two recipes manually
|
||||
*/
|
||||
recipes.add(SlimefunItems.SIFTED_ORE);
|
||||
recipes.add(SlimefunItems.IRON_DUST);
|
||||
|
||||
@ -68,14 +102,15 @@ public class OreWasher extends MultiBlockMachine {
|
||||
Inventory outputInv = null;
|
||||
|
||||
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.
|
||||
// However, due to the way the method findValidOutputInv() functions, 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
|
||||
// however, signals that it's
|
||||
// not supposed to be given to the player.
|
||||
/*
|
||||
* 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.
|
||||
* However, due to the way the method findValidOutputInv() functions,
|
||||
* 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 however, signals that it's not supposed
|
||||
* to be given to the player.
|
||||
*/
|
||||
ItemStack dummyAdding = SlimefunItems.DEBUG_FISH;
|
||||
outputInv = findOutputInventory(dummyAdding, dispBlock, inv);
|
||||
} 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) {
|
||||
ItemStack removing = input.clone();
|
||||
removing.setAmount(amount);
|
||||
@ -129,7 +165,7 @@ public class OreWasher extends MultiBlockMachine {
|
||||
*
|
||||
* @return A randomly picked dust item
|
||||
*/
|
||||
public ItemStack getRandomDust() {
|
||||
public @Nonnull ItemStack getRandomDust() {
|
||||
int index = ThreadLocalRandom.current().nextInt(dusts.length);
|
||||
return dusts[index].clone();
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
@ -16,6 +17,7 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
@ -26,6 +28,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class PressureChamber extends MultiBlockMachine {
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
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);
|
||||
}
|
||||
@ -67,7 +70,7 @@ public class PressureChamber extends MultiBlockMachine {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
|
||||
}
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void craft(Player p, Block b, ItemStack output, Inventory outputInv, Dispenser dispenser) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int j = i;
|
||||
|
@ -15,7 +15,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see IndustrialMiner
|
||||
* @see ActiveMiner
|
||||
* @see MiningTask
|
||||
*
|
||||
*/
|
||||
public class AdvancedIndustrialMiner extends IndustrialMiner {
|
||||
|
@ -7,6 +7,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
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.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -41,17 +43,17 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see AdvancedIndustrialMiner
|
||||
* @see ActiveMiner
|
||||
* @see MiningTask
|
||||
*
|
||||
*/
|
||||
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<>();
|
||||
|
||||
private final int range;
|
||||
private final boolean silkTouch;
|
||||
private final ItemSetting<Boolean> canMineAncientDebris = new ItemSetting<>(this, "can-mine-ancient-debris", false);
|
||||
private final boolean silkTouch;
|
||||
private final int range;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
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
|
||||
*/
|
||||
public ItemStack getOutcome(Material ore) {
|
||||
public @Nonnull ItemStack getOutcome(@Nonnull Material ore) {
|
||||
if (hasSilkTouch()) {
|
||||
return new ItemStack(ore);
|
||||
}
|
||||
@ -149,8 +151,10 @@ public class IndustrialMiner extends MultiBlockMachine {
|
||||
* @param item
|
||||
* 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.notNull(item, "The fuel item cannot be null");
|
||||
|
||||
fuelTypes.add(new MachineFuel(ores / 2, item));
|
||||
}
|
||||
|
||||
@ -190,11 +194,11 @@ public class IndustrialMiner extends MultiBlockMachine {
|
||||
Block start = b.getRelative(-mod, -1, -mod);
|
||||
Block end = b.getRelative(mod, -1, mod);
|
||||
|
||||
ActiveMiner instance = new ActiveMiner(this, p.getUniqueId(), chest, pistons, start, end);
|
||||
instance.start(b);
|
||||
MiningTask task = new MiningTask(this, p.getUniqueId(), chest, pistons, start, end);
|
||||
task.start(b);
|
||||
}
|
||||
|
||||
private Block[] findPistons(Block chest) {
|
||||
private @Nonnull Block[] findPistons(@Nonnull Block chest) {
|
||||
Block northern = chest.getRelative(BlockFace.NORTH);
|
||||
|
||||
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}
|
||||
*/
|
||||
public boolean canMine(Material type) {
|
||||
public boolean canMine(@Nonnull Material type) {
|
||||
if (SlimefunTag.INDUSTRIAL_MINER_ORES.isTagged(type)) {
|
||||
return true;
|
||||
} else if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,9 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.mine
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
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.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.papermc.lib.PaperLib;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
|
||||
|
||||
/**
|
||||
@ -37,15 +41,11 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
|
||||
* @see AdvancedIndustrialMiner
|
||||
*
|
||||
*/
|
||||
class ActiveMiner implements Runnable {
|
||||
class MiningTask implements Runnable {
|
||||
|
||||
private final IndustrialMiner miner;
|
||||
private final UUID owner;
|
||||
|
||||
private int fuel = 0;
|
||||
private int ores = 0;
|
||||
private boolean running = false;
|
||||
|
||||
private final Block chest;
|
||||
private final Block[] pistons;
|
||||
|
||||
@ -53,10 +53,15 @@ class ActiveMiner implements Runnable {
|
||||
private final BlockPosition end;
|
||||
private final int height;
|
||||
|
||||
private boolean running = false;
|
||||
private int fuel = 0;
|
||||
private int ores = 0;
|
||||
|
||||
private int x;
|
||||
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.owner = owner;
|
||||
|
||||
@ -77,7 +82,7 @@ class ActiveMiner implements Runnable {
|
||||
* @param b
|
||||
* 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);
|
||||
running = true;
|
||||
|
||||
@ -87,7 +92,7 @@ class ActiveMiner implements Runnable {
|
||||
/**
|
||||
* This method stops the {@link IndustrialMiner}.
|
||||
*/
|
||||
public void stop() {
|
||||
void stop() {
|
||||
running = false;
|
||||
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.
|
||||
* The error message is a path to the location in Slimefun's localization files.
|
||||
*
|
||||
* @param error
|
||||
* The error message to send
|
||||
* @param reason
|
||||
* The reason why we stop
|
||||
*/
|
||||
public void stop(String error) {
|
||||
void stop(@Nonnull MinerStoppingReason reason) {
|
||||
Player p = Bukkit.getPlayer(owner);
|
||||
|
||||
if (p != null) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, error);
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, reason.getErrorMessage());
|
||||
}
|
||||
|
||||
stop();
|
||||
@ -117,12 +122,14 @@ class ActiveMiner implements Runnable {
|
||||
|
||||
if (fuel <= 0) {
|
||||
// This Miner has not enough fuel.
|
||||
stop("machines.INDUSTRIAL_MINER.no-fuel");
|
||||
stop(MinerStoppingReason.NO_FUEL);
|
||||
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();
|
||||
|
||||
queue.thenRun(4, () -> setPistonState(pistons[0], true));
|
||||
@ -177,7 +184,7 @@ class ActiveMiner implements Runnable {
|
||||
Block b = start.getWorld().getBlockAt(x, y, z);
|
||||
|
||||
if (!SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(owner), b, ProtectableAction.BREAK_BLOCK)) {
|
||||
stop("machines.INDUSTRIAL_MINER.no-permission");
|
||||
stop(MinerStoppingReason.NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -240,7 +247,7 @@ class ActiveMiner implements Runnable {
|
||||
*
|
||||
* @return Whether the operation was successful
|
||||
*/
|
||||
private boolean push(ItemStack item) {
|
||||
private boolean push(@Nonnull ItemStack item) {
|
||||
if (fuel < 1) {
|
||||
// Restock fuel
|
||||
fuel = consumeFuel();
|
||||
@ -258,18 +265,18 @@ class ActiveMiner implements Runnable {
|
||||
inv.addItem(item);
|
||||
return true;
|
||||
} else {
|
||||
stop("machines.INDUSTRIAL_MINER.chest-full");
|
||||
stop(MinerStoppingReason.CHEST_FULL);
|
||||
}
|
||||
} else {
|
||||
// I won't question how this happened...
|
||||
stop("machines.INDUSTRIAL_MINER.destroyed");
|
||||
stop(MinerStoppingReason.STRUCTURE_DESTROYED);
|
||||
}
|
||||
} else {
|
||||
// The chest has been destroyed
|
||||
stop("machines.INDUSTRIAL_MINER.destroyed");
|
||||
stop(MinerStoppingReason.STRUCTURE_DESTROYED);
|
||||
}
|
||||
} else {
|
||||
stop("machines.INDUSTRIAL_MINER.no-fuel");
|
||||
stop(MinerStoppingReason.NO_FUEL);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -293,7 +300,7 @@ class ActiveMiner implements Runnable {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int consumeFuel(Inventory inv) {
|
||||
private int consumeFuel(@Nonnull Inventory inv) {
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
for (MachineFuel fuelType : miner.fuelTypes) {
|
||||
ItemStack item = inv.getContents()[i];
|
||||
@ -313,7 +320,7 @@ class ActiveMiner implements Runnable {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void setPistonState(Block block, boolean extended) {
|
||||
private void setPistonState(@Nonnull Block block, boolean extended) {
|
||||
if (!running) {
|
||||
return;
|
||||
}
|
||||
@ -338,15 +345,15 @@ class ActiveMiner implements Runnable {
|
||||
setExtended(block, piston, extended);
|
||||
} else {
|
||||
// The pistons must be facing upwards
|
||||
stop("machines.INDUSTRIAL_MINER.piston-facing");
|
||||
stop(MinerStoppingReason.PISTON_WRONG_DIRECTION);
|
||||
}
|
||||
} else {
|
||||
// The pistons must be facing upwards
|
||||
stop("machines.INDUSTRIAL_MINER.piston-space");
|
||||
stop(MinerStoppingReason.PISTON_NO_SPACE);
|
||||
}
|
||||
} else {
|
||||
// The piston has been destroyed
|
||||
stop("machines.INDUSTRIAL_MINER.destroyed");
|
||||
stop(MinerStoppingReason.STRUCTURE_DESTROYED);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
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);
|
||||
block.setBlockData(piston, false);
|
||||
|
@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.seasonal;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
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.implementation.items.SimpleSlimefunItem;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
@ -39,7 +41,7 @@ public class ChristmasPresent extends SimpleSlimefunItem<ItemUseHandler> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
public @Nonnull ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
e.cancel();
|
||||
|
||||
|
@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.seasonal;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
@ -39,7 +40,7 @@ public class EasterEgg extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
public @Nonnull ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
e.cancel();
|
||||
|
||||
|
@ -104,23 +104,20 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
|
||||
*
|
||||
* @return a random {@link ItemStack} obtained by this {@link GoldPan}
|
||||
*/
|
||||
@Nonnull
|
||||
public ItemStack getRandomOutput() {
|
||||
public @Nonnull ItemStack getRandomOutput() {
|
||||
ItemStack item = randomizer.getRandom();
|
||||
|
||||
// Fixes #2804
|
||||
return item != null ? item : new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getLabelLocalPath() {
|
||||
public @Nonnull String getLabelLocalPath() {
|
||||
return "guide.tooltips.recipes.gold-pan";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
public @Nonnull ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
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}
|
||||
*/
|
||||
@Nonnull
|
||||
public EntityInteractHandler onEntityInteract() {
|
||||
public @Nonnull EntityInteractHandler onEntityInteract() {
|
||||
return (e, item, offHand) -> {
|
||||
if (!(e.getRightClicked() instanceof ItemFrame)) {
|
||||
e.setCancelled(true);
|
||||
@ -160,9 +156,8 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
|
||||
};
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<ItemStack> getDisplayRecipes() {
|
||||
public @Nonnull List<ItemStack> getDisplayRecipes() {
|
||||
List<ItemStack> recipes = new LinkedList<>();
|
||||
|
||||
for (GoldPanDrop drop : drops) {
|
||||
|
@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
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.items.SimpleSlimefunItem;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.GrapplingHookListener;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
@ -51,7 +53,7 @@ public class GrapplingHook extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
public @Nonnull ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
Player p = e.getPlayer();
|
||||
UUID uuid = p.getUniqueId();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
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.items.SimpleSlimefunItem;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -22,7 +24,7 @@ public class HerculesPickaxe extends SimpleSlimefunItem<ToolUseHandler> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolUseHandler getItemHandler() {
|
||||
public @Nonnull ToolUseHandler getItemHandler() {
|
||||
return (e, tool, fortune, drops) -> {
|
||||
if (SlimefunTag.ORES.isTagged(e.getBlock().getType())) {
|
||||
if (e.getBlock().getType() == Material.IRON_ORE) {
|
||||
|
@ -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.items.SimpleSlimefunItem;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -39,7 +40,7 @@ public class PickaxeOfTheSeeker extends SimpleSlimefunItem<ItemUseHandler> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
public @Nonnull ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
Player p = e.getPlayer();
|
||||
Block closest = findClosestOre(p);
|
||||
@ -69,8 +70,7 @@ public class PickaxeOfTheSeeker extends SimpleSlimefunItem<ItemUseHandler> imple
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Block findClosestOre(@Nonnull Player p) {
|
||||
private @Nullable Block findClosestOre(@Nonnull Player p) {
|
||||
Block start = p.getLocation().getBlock();
|
||||
Block closest = null;
|
||||
double lastDistance = Double.MAX_VALUE;
|
||||
|
@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
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.items.SimpleSlimefunItem;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -43,7 +45,7 @@ public class PickaxeOfVeinMining extends SimpleSlimefunItem<ToolUseHandler> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolUseHandler getItemHandler() {
|
||||
public @Nonnull ToolUseHandler getItemHandler() {
|
||||
return (e, tool, fortune, drops) -> {
|
||||
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()));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
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.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -29,7 +31,7 @@ public class PortableCrafter extends SimpleSlimefunItem<ItemUseHandler> implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
public @Nonnull ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
e.cancel();
|
||||
|
||||
|
@ -1,20 +1,32 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
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 {
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
@ -23,7 +35,7 @@ public class PortableDustbin extends SimpleSlimefunItem<ItemUseHandler> implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
public @Nonnull ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
e.cancel();
|
||||
|
||||
|
@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
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.items.SimpleSlimefunItem;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
@ -34,7 +35,7 @@ public class SmeltersPickaxe extends SimpleSlimefunItem<ToolUseHandler> implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolUseHandler getItemHandler() {
|
||||
public @Nonnull ToolUseHandler getItemHandler() {
|
||||
return (e, tool, fortune, drops) -> {
|
||||
Block b = e.getBlock();
|
||||
|
||||
|
@ -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.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -45,7 +46,7 @@ public class TapeMeasure extends SimpleSlimefunItem<ItemUseHandler> implements N
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
public @Nonnull ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
e.cancel();
|
||||
|
||||
@ -90,9 +91,8 @@ public class TapeMeasure extends SimpleSlimefunItem<ItemUseHandler> implements N
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ParametersAreNonnullByDefault
|
||||
public Optional<Location> getAnchor(Player p, ItemStack item) {
|
||||
public @Nonnull Optional<Location> getAnchor(Player p, ItemStack item) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
String data = meta.getPersistentDataContainer().get(key, PersistentDataType.STRING);
|
||||
@ -119,7 +119,7 @@ public class TapeMeasure extends SimpleSlimefunItem<ItemUseHandler> implements N
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
if (anchor.isPresent()) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -106,7 +106,7 @@ public class DebugFishListener implements Listener {
|
||||
}
|
||||
} else {
|
||||
// Read applicable Slimefun tags
|
||||
Set<SlimefunTag> tags = new HashSet<>();
|
||||
Set<SlimefunTag> tags = EnumSet.noneOf(SlimefunTag.class);
|
||||
|
||||
for (SlimefunTag tag : SlimefunTag.values()) {
|
||||
if (tag.isTagged(b.getType())) {
|
||||
|
@ -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.Teleporter;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.TeleporterPylon;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
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}).
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
* @author Walshy
|
||||
* @author Sfiguz7
|
||||
* @author SoSeDiK
|
||||
*
|
||||
*/
|
||||
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) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
@ -48,6 +55,11 @@ public class TeleporterListener implements Listener {
|
||||
SlimefunItem item = BlockStorage.check(b);
|
||||
Player p = e.getPlayer();
|
||||
|
||||
// Fixes #2966 - Check if Players can use these
|
||||
if (item == null || !item.canUse(p, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item instanceof ElevatorPlate) {
|
||||
// Pressure plate was an elevator
|
||||
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))) {
|
||||
Block block = b.getRelative(BlockFace.DOWN);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class TestItemStackWrapper {
|
||||
|
||||
Assertions.assertEquals(item.getType(), wrapper.getType());
|
||||
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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user