mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Lots of refactoring
This commit is contained in:
parent
aab665ffea
commit
83e8010e29
@ -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)
|
||||
|
@ -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<Integer> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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<List<String>> {
|
||||
|
||||
private final Tag<Material> defaultTag;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public MaterialTagSetting(String key, Tag<Material> 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<Material> getDefaultTag() {
|
||||
return defaultTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateInput(List<String> 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<String> getAsStringList(Tag<Material> tag) {
|
||||
return tag.getValues().stream().map(Material::name).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
@ -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<List<String>> blacklist = new ItemSetting<>("unplaceable-blocks", SlimefunTag.UNBREAKABLE_MATERIALS.stream().map(Material::name).collect(Collectors.toList()));
|
||||
private final ItemSetting<List<String>> 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;
|
||||
}
|
||||
|
||||
|
@ -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<ItemConsumptionHandler> {
|
||||
|
||||
private final ItemSetting<Integer> saturation = new ItemSetting<>("saturation-level", 6);
|
||||
private final ItemSetting<Integer> 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);
|
||||
|
@ -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<ItemUseHandler> {
|
||||
|
||||
private final ItemSetting<Integer> radius = new ItemSetting<>("radius", 10);
|
||||
private final ItemSetting<Integer> radius = new IntRangeSetting("radius", 1, 10, Integer.MAX_VALUE);
|
||||
|
||||
public TelepositionScroll(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<ItemUseHandler> implements NotPlaceable, RandomMobDrop {
|
||||
|
||||
private final ItemSetting<Boolean> dropSetting = new ItemSetting<>("drop-from-golems", true);
|
||||
private final ItemSetting<Integer> chance = new ItemSetting<>("golem-drop-chance", 75);
|
||||
private final ItemSetting<Integer> chance = new IntRangeSetting("golem-drop-chance", 0, 75, 100);
|
||||
|
||||
public BasicCircuitBoard(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
|
@ -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<Integer> chance = new ItemSetting<>("barter-chance", 7);
|
||||
private final ItemSetting<Integer> chance = new IntRangeSetting("barter-chance", 0, 7, 100);
|
||||
|
||||
public StrangeNetherGoo(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
|
@ -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<Integer> fireBreakingChance = new ItemSetting<>("fire-breaking-chance", 34);
|
||||
private final ItemSetting<Integer> 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);
|
||||
|
@ -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;
|
||||
|
@ -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<ItemUseHandler> {
|
||||
|
||||
private final ItemSetting<Boolean> consumeOnUse = new ItemSetting<>("consume-on-use", true);
|
||||
private final ItemSetting<Integer> despawnTicks = new ItemSetting<>("despawn-seconds", 60);
|
||||
private final ItemSetting<Integer> despawnTicks = new IntRangeSetting("despawn-seconds", 0, 60, Integer.MAX_VALUE);
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public GrapplingHook(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
|
@ -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<ItemUseHandler> implements DamageableItem {
|
||||
|
||||
private final ItemSetting<Integer> 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<ItemUseHandler> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<ToolUseHandler> {
|
||||
|
||||
private final ItemSetting<Integer> maxBlocks = new ItemSetting<Integer>("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<Integer> maxBlocks = new IntRangeSetting("max-blocks", 1, 16, Integer.MAX_VALUE);
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public PickaxeOfVeinMining(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
|
@ -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<ToolUseHandler> 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<ToolUseHandler> implemen
|
||||
@Override
|
||||
public ToolUseHandler getItemHandler() {
|
||||
return (e, tool, fortune, drops) -> {
|
||||
if (SlimefunTag.SMELTERS_PICKAXE_BLOCKS.isTagged(e.getBlock().getType()) && !BlockStorage.hasBlockInfo(e.getBlock())) {
|
||||
Collection<ItemStack> blockDrops = e.getBlock().getDrops(getItem());
|
||||
Block b = e.getBlock();
|
||||
|
||||
if (SlimefunTag.SMELTERS_PICKAXE_BLOCKS.isTagged(b.getType()) && !BlockStorage.hasBlockInfo(b)) {
|
||||
Collection<ItemStack> 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<ToolUseHandler> implemen
|
||||
};
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void smelt(Block b, ItemStack drop, int fortune) {
|
||||
Optional<ItemStack> furnaceOutput = SlimefunPlugin.getMinecraftRecipeService().getFurnaceOutput(drop);
|
||||
|
||||
|
@ -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<Integer> range = new ItemSetting<Integer>("explosion-range", 3) {
|
||||
|
||||
@Override
|
||||
public boolean validateInput(Integer input) {
|
||||
return super.validateInput(input) && input > 0;
|
||||
}
|
||||
|
||||
};
|
||||
private final ItemSetting<Integer> range = new IntRangeSetting("explosion-range", 1, 3, Integer.MAX_VALUE);
|
||||
|
||||
public ExplosiveBow(Category category, SlimefunItemStack item, ItemStack[] recipe) {
|
||||
super(category, item, recipe);
|
||||
|
@ -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<EntityKillHandler> {
|
||||
|
||||
private final ItemSetting<Integer> chanceZombie = new ItemSetting<>("chance.ZOMBIE", 40);
|
||||
private final ItemSetting<Integer> chanceSkeleton = new ItemSetting<>("chance.SKELETON", 40);
|
||||
private final ItemSetting<Integer> chanceWitherSkeleton = new ItemSetting<>("chance.WITHER_SKELETON", 25);
|
||||
private final ItemSetting<Integer> chanceCreeper = new ItemSetting<>("chance.CREEPER", 40);
|
||||
private final ItemSetting<Integer> chancePlayer = new ItemSetting<>("chance.PLAYER", 70);
|
||||
private final ItemSetting<Integer> chanceZombie = new IntRangeSetting("chance.ZOMBIE", 0, 40, 100);
|
||||
private final ItemSetting<Integer> chanceSkeleton = new IntRangeSetting("chance.SKELETON", 0, 40, 100);
|
||||
private final ItemSetting<Integer> chanceWitherSkeleton = new IntRangeSetting("chance.WITHER_SKELETON", 0, 25, 100);
|
||||
private final ItemSetting<Integer> chanceCreeper = new IntRangeSetting("chance.CREEPER", 0, 40, 100);
|
||||
private final ItemSetting<Integer> chancePlayer = new IntRangeSetting("chance.PLAYER", 0, 70, 100);
|
||||
|
||||
public SwordOfBeheading(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
|
@ -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<Integer> chance = new ItemSetting<>("chance", 45);
|
||||
private final ItemSetting<Integer> chance = new IntRangeSetting("chance", 0, 45, 100);
|
||||
|
||||
public VampireBlade(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
|
@ -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 {
|
||||
|
@ -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}
|
@ -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<Boolean> {
|
||||
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<Boolean> {
|
||||
*
|
||||
* @return The associated {@link Enchantment}
|
||||
*/
|
||||
@Nonnull
|
||||
public Enchantment getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
@ -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;
|
@ -37,6 +37,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.tools.SmeltersPic
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see TagParser
|
||||
*
|
||||
*/
|
||||
public enum SlimefunTag implements Tag<Material> {
|
||||
|
||||
@ -214,6 +216,17 @@ public enum SlimefunTag implements Tag<Material> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
@ -36,6 +36,8 @@ import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see SlimefunTag
|
||||
*
|
||||
*/
|
||||
public class TagParser implements Keyed {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user