diff --git a/CHANGELOG.md b/CHANGELOG.md index 4202a6342..a34f86b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ * Added Planks to Sticks recipe to the Table Saw * Added "slimefun.gps.bypass" permission to open GPS devices anywhere * (API) Added custom tags for developers +* The range of the Seeker Pickaxe is now configurable #### Changes * Improved Auto-Updater (Multi-Threading and more) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java new file mode 100644 index 000000000..3f62e355c --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java @@ -0,0 +1,52 @@ +package io.github.thebusybiscuit.slimefun4.api.items.settings; + +import javax.annotation.ParametersAreNonnullByDefault; + +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; + +/** + * This variation of {@link ItemSetting} allows you to define an {@link Integer} range + * and enforces this range using the {@link #validateInput(Integer)} method. + * + * @author TheBusyBiscuit + * + * @see ItemSetting + * + */ +public class IntRangeSetting extends ItemSetting { + + private final int min; + private final int max; + + @ParametersAreNonnullByDefault + public IntRangeSetting(String key, int min, int defaultValue, int max) { + super(key, defaultValue); + + this.min = min; + this.max = max; + } + + @Override + public boolean validateInput(Integer input) { + return super.validateInput(input) && input >= min && input <= max; + } + + /** + * This returns the minimum value of this {@link IntRangeSetting}. + * + * @return The minimum value + */ + public int getMinimum() { + return min; + } + + /** + * This returns the maximum value of this {@link IntRangeSetting}. + * + * @return The maximum value + */ + public int getMaximum() { + return max; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/MaterialTagSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/MaterialTagSetting.java new file mode 100644 index 000000000..b229fa9b4 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/MaterialTagSetting.java @@ -0,0 +1,76 @@ +package io.github.thebusybiscuit.slimefun4.api.items.settings; + +import java.util.List; +import java.util.stream.Collectors; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.Material; +import org.bukkit.Tag; + +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; + +/** + * This variation of {@link ItemSetting} allows you to define a default {@link Tag}. + * The {@link Tag} will be translated into a {@link String} {@link List} which the user + * can then configure as they wish. + * + * It also validates all inputs to be a valid {@link Material}. + * + * @author TheBusyBiscuit + * + * @see ItemSetting + * + */ +public class MaterialTagSetting extends ItemSetting> { + + private final Tag defaultTag; + + @ParametersAreNonnullByDefault + public MaterialTagSetting(String key, Tag defaultTag) { + super(key, getAsStringList(defaultTag)); + + this.defaultTag = defaultTag; + } + + /** + * This {@link Tag} holds the default values for this {@link MaterialTagSetting}. + * + * @return The default {@link Tag} + */ + @Nonnull + public Tag getDefaultTag() { + return defaultTag; + } + + @Override + public boolean validateInput(List input) { + if (input != null) { + for (String value : input) { + Material material = Material.matchMaterial(value); + + // This value is not a valid material, the setting is not valid. + if (material == null) { + return false; + } + } + + return true; + } else { + return false; + } + } + + /** + * Internal method to turn a {@link Tag} into a {@link List} of {@link String Strings}. + * + * @param tag + * Our {@link Tag} + * @return The {@link String} {@link List} + */ + private static List getAsStringList(Tag tag) { + return tag.getValues().stream().map(Material::name).collect(Collectors.toList()); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/package-info.java new file mode 100644 index 000000000..2f6bea34c --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/package-info.java @@ -0,0 +1,4 @@ +/** + * This package contains various sub classes of {@link io.github.thebusybiscuit.slimefun4.api.items.ItemSetting}. + */ +package io.github.thebusybiscuit.slimefun4.api.items.settings; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java index effaf7aa9..2bf0fbbea 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java @@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.blocks; import java.util.List; import java.util.UUID; -import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.Effect; @@ -21,6 +20,7 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.api.events.BlockPlacerPlaceEvent; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.MaterialTagSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; @@ -47,7 +47,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; */ public class BlockPlacer extends SlimefunItem { - private final ItemSetting> blacklist = new ItemSetting<>("unplaceable-blocks", SlimefunTag.UNBREAKABLE_MATERIALS.stream().map(Material::name).collect(Collectors.toList())); + private final ItemSetting> blacklist = new MaterialTagSetting("unplaceable-blocks", SlimefunTag.UNBREAKABLE_MATERIALS); public BlockPlacer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); @@ -88,7 +88,8 @@ public class BlockPlacer extends SlimefunItem { if (!material.isBlock() || SlimefunTag.BLOCK_PLACER_IGNORED_MATERIALS.isTagged(material)) { // Some materials cannot be reliably placed, like beds, it would look - // kinda wonky, so we just ignore these altogether + // kinda wonky, so we just ignore these altogether. + // The event has already been cancelled too, so they won't drop. return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java index a0e935e5d..9cd6a1ba2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.food; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Lists.RecipeType; @@ -20,7 +21,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; */ public class MeatJerky extends SimpleSlimefunItem { - private final ItemSetting saturation = new ItemSetting<>("saturation-level", 6); + private final ItemSetting saturation = new IntRangeSetting("saturation-level", 0, 6, Integer.MAX_VALUE); public MeatJerky(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java index be4d3ed4f..38b97d90b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java @@ -7,6 +7,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Lists.RecipeType; @@ -24,7 +25,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; */ public class TelepositionScroll extends SimpleSlimefunItem { - private final ItemSetting radius = new ItemSetting<>("radius", 10); + private final ItemSetting radius = new IntRangeSetting("radius", 1, 10, Integer.MAX_VALUE); public TelepositionScroll(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java index 9e17b1619..29a819f04 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java @@ -12,6 +12,7 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.implementation.settings.TalismanEnchantment; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/BasicCircuitBoard.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/BasicCircuitBoard.java index ee6d4420a..0adf206d2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/BasicCircuitBoard.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/BasicCircuitBoard.java @@ -4,6 +4,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.core.attributes.RandomMobDrop; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; @@ -15,7 +16,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class BasicCircuitBoard extends SimpleSlimefunItem implements NotPlaceable, RandomMobDrop { private final ItemSetting dropSetting = new ItemSetting<>("drop-from-golems", true); - private final ItemSetting chance = new ItemSetting<>("golem-drop-chance", 75); + private final ItemSetting chance = new IntRangeSetting("golem-drop-chance", 0, 75, 100); public BasicCircuitBoard(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/StrangeNetherGoo.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/StrangeNetherGoo.java index eb6aa7716..2782308cb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/StrangeNetherGoo.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/StrangeNetherGoo.java @@ -4,6 +4,7 @@ import org.bukkit.entity.Piglin; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.PiglinBarterDrop; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.VillagerRune; import me.mrCookieSlime.Slimefun.Lists.RecipeType; @@ -23,7 +24,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; */ public class StrangeNetherGoo extends SlimefunItem implements PiglinBarterDrop { - private final ItemSetting chance = new ItemSetting<>("barter-chance", 7); + private final ItemSetting chance = new IntRangeSetting("barter-chance", 0, 7, 100); public StrangeNetherGoo(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java index e5a0c8d01..0d447e193 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java @@ -23,6 +23,7 @@ import org.bukkit.inventory.meta.ItemMeta; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.papermc.lib.PaperLib; @@ -33,7 +34,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class Smeltery extends AbstractSmeltery { private final BlockFace[] faces = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; - private final ItemSetting fireBreakingChance = new ItemSetting<>("fire-breaking-chance", 34); + private final ItemSetting fireBreakingChance = new IntRangeSetting("fire-breaking-chance", 0, 34, 100); public Smeltery(Category category, SlimefunItemStack item) { super(category, item, new ItemStack[] { null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.NETHER_BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.NETHER_BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, BlockFace.DOWN); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java index 283193fd6..9ea82ab86 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java @@ -34,6 +34,7 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; 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.settings.ClimbableSurface; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java index 8b521ecdd..a29be2471 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java @@ -16,6 +16,7 @@ import org.bukkit.util.Vector; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; @@ -38,7 +39,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class GrapplingHook extends SimpleSlimefunItem { private final ItemSetting consumeOnUse = new ItemSetting<>("consume-on-use", true); - private final ItemSetting despawnTicks = new ItemSetting<>("despawn-seconds", 60); + private final ItemSetting despawnTicks = new IntRangeSetting("despawn-seconds", 0, 60, Integer.MAX_VALUE); @ParametersAreNonnullByDefault public GrapplingHook(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfTheSeeker.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfTheSeeker.java index d3d1d33a1..7f88a3f5a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfTheSeeker.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfTheSeeker.java @@ -1,12 +1,17 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Event.Result; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; @@ -16,10 +21,21 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * The {@link PickaxeOfTheSeeker} will make you face the nearest ore upon right clicking. + * + * @author TheBusyBiscuit + * + */ public class PickaxeOfTheSeeker extends SimpleSlimefunItem implements DamageableItem { + private final ItemSetting maxRange = new IntRangeSetting("max-range", 1, 5, Integer.MAX_VALUE); + + @ParametersAreNonnullByDefault public PickaxeOfTheSeeker(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); + + addItemSetting(maxRange); } @Override @@ -43,23 +59,35 @@ public class PickaxeOfTheSeeker extends SimpleSlimefunItem imple float yaw = alpha2 > 90 ? (180 - alpha1) : alpha1; float pitch = (float) ((-Math.atan((closest.getY() - 0.5 - p.getLocation().getY()) / Math.sqrt(l * l + w * w))) * 180 / Math.PI); - p.teleport(new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), yaw, pitch)); + // We could teleport them asynchronously here... + // But we're only changing the pitch and yaw anyway. + Location loc = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), yaw, pitch); + p.teleport(loc); } damageItem(p, e.getItem()); }; } - private Block findClosestOre(Player p) { + @Nullable + private Block findClosestOre(@Nonnull Player p) { + Block start = p.getLocation().getBlock(); Block closest = null; + double lastDistance = Double.MAX_VALUE; + int range = maxRange.getValue(); - for (int x = -4; x <= 4; x++) { - for (int y = -4; y <= 4; y++) { - for (int z = -4; z <= 4; z++) { - Material type = p.getLocation().add(x, y, z).getBlock().getType(); + for (int x = -range; x <= range; x++) { + for (int y = -range; y <= range; y++) { + for (int z = -range; z <= range; z++) { + Block block = start.getRelative(x, y, z); - if (SlimefunTag.PICKAXE_OF_THE_SEEKER_BLOCKS.isTagged(type) && (closest == null || p.getLocation().distanceSquared(closest.getLocation()) > p.getLocation().distanceSquared(p.getLocation().add(x, y, z)))) { - closest = p.getLocation().getBlock().getRelative(x, y, z); + if (SlimefunTag.PICKAXE_OF_THE_SEEKER_BLOCKS.isTagged(block.getType())) { + double distance = block.getLocation().distanceSquared(start.getLocation()); + + if (closest == null || distance < lastDistance) { + closest = block; + lastDistance = distance; + } } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfVeinMining.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfVeinMining.java index 2543d6589..bad2ca71a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfVeinMining.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfVeinMining.java @@ -15,6 +15,7 @@ import io.github.thebusybiscuit.cscorelib2.blocks.Vein; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; @@ -33,15 +34,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; */ public class PickaxeOfVeinMining extends SimpleSlimefunItem { - private final ItemSetting maxBlocks = new ItemSetting("max-blocks", 16) { - - @Override - public boolean validateInput(Integer input) { - // We do not wanna allow any negative values here - return super.validateInput(input) && input.intValue() > 0; - } - - }; + private final ItemSetting maxBlocks = new IntRangeSetting("max-blocks", 1, 16, Integer.MAX_VALUE); @ParametersAreNonnullByDefault public PickaxeOfVeinMining(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/SmeltersPickaxe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/SmeltersPickaxe.java index 88934823e..cd3ea1999 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/SmeltersPickaxe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/SmeltersPickaxe.java @@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools; import java.util.Collection; import java.util.Optional; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Effect; import org.bukkit.Material; import org.bukkit.block.Block; @@ -18,8 +20,15 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * The {@link SmeltersPickaxe} automatically smelts any ore you mine. + * + * @author TheBusyBiscuit + * + */ public class SmeltersPickaxe extends SimpleSlimefunItem implements DamageableItem { + @ParametersAreNonnullByDefault public SmeltersPickaxe(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); } @@ -27,12 +36,14 @@ public class SmeltersPickaxe extends SimpleSlimefunItem implemen @Override public ToolUseHandler getItemHandler() { return (e, tool, fortune, drops) -> { - if (SlimefunTag.SMELTERS_PICKAXE_BLOCKS.isTagged(e.getBlock().getType()) && !BlockStorage.hasBlockInfo(e.getBlock())) { - Collection blockDrops = e.getBlock().getDrops(getItem()); + Block b = e.getBlock(); + + if (SlimefunTag.SMELTERS_PICKAXE_BLOCKS.isTagged(b.getType()) && !BlockStorage.hasBlockInfo(b)) { + Collection blockDrops = b.getDrops(getItem()); for (ItemStack drop : blockDrops) { if (drop != null && drop.getType() != Material.AIR) { - smelt(e.getBlock(), drop, fortune); + smelt(b, drop, fortune); drops.add(drop); } } @@ -42,6 +53,7 @@ public class SmeltersPickaxe extends SimpleSlimefunItem implemen }; } + @ParametersAreNonnullByDefault private void smelt(Block b, ItemStack drop, int fortune) { Optional furnaceOutput = SlimefunPlugin.getMinecraftRecipeService().getFurnaceOutput(drop); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index ac1b31420..e73b78ea3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.weapons; +import java.util.Collection; + import org.bukkit.Bukkit; import org.bukkit.Particle; import org.bukkit.Sound; @@ -11,12 +13,11 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import java.util.Collection; - /** * The {@link ExplosiveBow} is a {@link SlimefunBow} which creates a fake explosion when it hits * a {@link LivingEntity}. Any nearby {@link LivingEntity LivingEntities} get pushed away and @@ -30,14 +31,7 @@ import java.util.Collection; */ public class ExplosiveBow extends SlimefunBow { - private final ItemSetting range = new ItemSetting("explosion-range", 3) { - - @Override - public boolean validateInput(Integer input) { - return super.validateInput(input) && input > 0; - } - - }; + private final ItemSetting range = new IntRangeSetting("explosion-range", 1, 3, Integer.MAX_VALUE); public ExplosiveBow(Category category, SlimefunItemStack item, ItemStack[] recipe) { super(category, item, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java index 905e0ce24..9f2d14170 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java @@ -14,6 +14,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Lists.RecipeType; @@ -22,11 +23,11 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class SwordOfBeheading extends SimpleSlimefunItem { - private final ItemSetting chanceZombie = new ItemSetting<>("chance.ZOMBIE", 40); - private final ItemSetting chanceSkeleton = new ItemSetting<>("chance.SKELETON", 40); - private final ItemSetting chanceWitherSkeleton = new ItemSetting<>("chance.WITHER_SKELETON", 25); - private final ItemSetting chanceCreeper = new ItemSetting<>("chance.CREEPER", 40); - private final ItemSetting chancePlayer = new ItemSetting<>("chance.PLAYER", 70); + private final ItemSetting chanceZombie = new IntRangeSetting("chance.ZOMBIE", 0, 40, 100); + private final ItemSetting chanceSkeleton = new IntRangeSetting("chance.SKELETON", 0, 40, 100); + private final ItemSetting chanceWitherSkeleton = new IntRangeSetting("chance.WITHER_SKELETON", 0, 25, 100); + private final ItemSetting chanceCreeper = new IntRangeSetting("chance.CREEPER", 0, 40, 100); + private final ItemSetting chancePlayer = new IntRangeSetting("chance.PLAYER", 0, 70, 100); public SwordOfBeheading(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/VampireBlade.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/VampireBlade.java index 72d101fa6..f31bd37bd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/VampireBlade.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/VampireBlade.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.implementation.listeners.VampireBladeListener; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; @@ -25,7 +26,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class VampireBlade extends SlimefunItem { private static final double HEALING_AMOUNT = 4.0; - private final ItemSetting chance = new ItemSetting<>("chance", 45); + private final ItemSetting chance = new IntRangeSetting("chance", 0, 45, 100); public VampireBlade(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java index ef2ba35a5..531bf9206 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java @@ -45,7 +45,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.MagicianTalisman; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman; -import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.TalismanEnchantment; +import io.github.thebusybiscuit.slimefun4.implementation.settings.TalismanEnchantment; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; public class TalismanListener implements Listener { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbableSurface.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/ClimbableSurface.java similarity index 88% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbableSurface.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/ClimbableSurface.java index cf3ed08a4..a430001e3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbableSurface.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/ClimbableSurface.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.tools; +package io.github.thebusybiscuit.slimefun4.implementation.settings; import javax.annotation.Nonnull; @@ -6,6 +6,7 @@ import org.bukkit.Material; import io.github.thebusybiscuit.slimefun4.api.events.ClimbingPickLaunchEvent; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.implementation.items.tools.ClimbingPick; /** * This is an {@link ItemSetting} @@ -48,4 +49,4 @@ public class ClimbableSurface extends ItemSetting { return type; } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/TalismanEnchantment.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/TalismanEnchantment.java similarity index 79% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/TalismanEnchantment.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/TalismanEnchantment.java index 4e3041790..74681d9c6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/TalismanEnchantment.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/TalismanEnchantment.java @@ -1,8 +1,11 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans; +package io.github.thebusybiscuit.slimefun4.implementation.settings; + +import javax.annotation.Nonnull; import org.bukkit.enchantments.Enchantment; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.MagicianTalisman; import io.github.thebusybiscuit.slimefun4.implementation.listeners.TalismanListener; /** @@ -17,7 +20,7 @@ public class TalismanEnchantment extends ItemSetting { private final Enchantment enchantment; private final int level; - public TalismanEnchantment(Enchantment enchantment, int level) { + public TalismanEnchantment(@Nonnull Enchantment enchantment, int level) { super("allow-enchantments." + enchantment.getKey().getKey() + ".level." + level, true); this.enchantment = enchantment; @@ -29,6 +32,7 @@ public class TalismanEnchantment extends ItemSetting { * * @return The associated {@link Enchantment} */ + @Nonnull public Enchantment getEnchantment() { return enchantment; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/package-info.java new file mode 100644 index 000000000..1b0af3d46 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/package-info.java @@ -0,0 +1,6 @@ +/** + * This package holds implementations of {@link io.github.thebusybiscuit.slimefun4.api.items.ItemSetting} that are for + * very specific {@link me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem SlimefunItems} and generally not + * very useful out of their context. + */ +package io.github.thebusybiscuit.slimefun4.implementation.settings; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java index b63251da7..c5bf0556e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java @@ -36,6 +36,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.tools.SmeltersPic * and follow Minecraft's tags.json format. * * @author TheBusyBiscuit + * + * @see TagParser * */ public enum SlimefunTag implements Tag { @@ -214,6 +216,17 @@ public enum SlimefunTag implements Tag { }); } + /** + * This method reloads every single {@link SlimefunTag} from the resources directory. + * It is equivalent to running {@link #reload()} on every single {@link SlimefunTag} manually. + * + * Do keep in mind though that any misconfigured {@link SlimefunTag} will abort the entire + * method and throw a {@link TagMisconfigurationException}. So one faulty {@link SlimefunTag} + * will stop the reloading process. + * + * @throws TagMisconfigurationException + * This is thrown if one of the {@link SlimefunTag SlimefunTags} could not be parsed correctly + */ public static void reloadAll() throws TagMisconfigurationException { for (SlimefunTag tag : valuesCache) { tag.reload(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java index aee7dcbfc..766f4edb2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java @@ -35,6 +35,8 @@ import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; * The {@link TagParser} is responsible for parsing a JSON input into a {@link SlimefunTag}. * * @author TheBusyBiscuit + * + * @see SlimefunTag * */ public class TagParser implements Keyed {