Search in sources :

Example 46 with Slimefun

use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.

the class TestBackpackCommand method testValidBackpack.

@Test
@DisplayName("Test /sf backpack giving a restored backpack")
void testValidBackpack() throws InterruptedException {
    Player player = server.addPlayer();
    player.setOp(true);
    PlayerProfile profile = TestUtilities.awaitProfile(player);
    PlayerBackpack backpack = profile.createBackpack(54);
    server.execute("slimefun", player, "backpack", player.getName(), String.valueOf(backpack.getId())).assertSucceeded();
    Assertions.assertTrue(hasBackpack(player, backpack.getId()));
}
Also used : Player(org.bukkit.entity.Player) PlayerBackpack(io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack) PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 47 with Slimefun

use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.

the class TagParser method parsePrimitiveValue.

@ParametersAreNonnullByDefault
private void parsePrimitiveValue(String value, Set<Material> materials, Set<Tag<Material>> tags, boolean throwException) throws TagMisconfigurationException {
    if (PatternUtils.MINECRAFT_NAMESPACEDKEY.matcher(value).matches()) {
        // Match the NamespacedKey against Materials
        Material material = Material.matchMaterial(value);
        if (material != null) {
            // If the Material could be matched, simply add it to our Set
            materials.add(material);
        } else if (throwException) {
            throw new TagMisconfigurationException(key, "Minecraft Material '" + value + "' seems to not exist!");
        }
    } else if (PatternUtils.MINECRAFT_TAG.matcher(value).matches()) {
        // Get the actual Key portion and match it to item and block tags.
        String keyValue = CommonPatterns.COLON.split(value)[1];
        NamespacedKey namespacedKey = NamespacedKey.minecraft(keyValue);
        Tag<Material> itemsTag = Bukkit.getTag(Tag.REGISTRY_ITEMS, namespacedKey, Material.class);
        Tag<Material> blocksTag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, namespacedKey, Material.class);
        if (itemsTag != null) {
            // We will prioritize the item tag
            tags.add(itemsTag);
        } else if (blocksTag != null) {
            // If no item tag exists, fall back to the block tag
            tags.add(blocksTag);
        } else if (throwException) {
            // If both fail, then the tag does not exist.
            throw new TagMisconfigurationException(key, "There is no '" + value + "' tag in Minecraft.");
        }
    } else if (PatternUtils.SLIMEFUN_TAG.matcher(value).matches()) {
        // Get a SlimefunTag enum value for the given key
        String keyValue = CommonPatterns.COLON.split(value)[1].toUpperCase(Locale.ROOT);
        SlimefunTag tag = SlimefunTag.getTag(keyValue);
        if (tag != null) {
            tags.add(tag);
        } else if (throwException) {
            throw new TagMisconfigurationException(key, "There is no '" + value + "' tag in Slimefun");
        }
    } else if (throwException) {
        // If no RegEx pattern matched, it's malformed.
        throw new TagMisconfigurationException(key, "Could not recognize value '" + value + "'");
    }
}
Also used : TagMisconfigurationException(io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException) NamespacedKey(org.bukkit.NamespacedKey) Material(org.bukkit.Material) Tag(org.bukkit.Tag) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 48 with Slimefun

use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.

the class MinerAndroid method dig.

@Override
@ParametersAreNonnullByDefault
protected void dig(Block b, BlockMenu menu, Block block) {
    Collection<ItemStack> drops = block.getDrops(effectivePickaxe);
    if (!SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) && !drops.isEmpty()) {
        OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")));
        if (Slimefun.getProtectionManager().hasPermission(owner, block.getLocation(), Interaction.BREAK_BLOCK)) {
            AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b));
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
            // We only want to break non-Slimefun blocks
            if (!BlockStorage.hasBlockInfo(block)) {
                breakBlock(menu, drops, block);
            }
        }
    }
}
Also used : AndroidMineEvent(io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 49 with Slimefun

use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.

the class MinerAndroid method moveAndDig.

@Override
@ParametersAreNonnullByDefault
protected void moveAndDig(Block b, BlockMenu menu, BlockFace face, Block block) {
    Collection<ItemStack> drops = block.getDrops(effectivePickaxe);
    if (!SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) && !drops.isEmpty()) {
        OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")));
        if (Slimefun.getProtectionManager().hasPermission(owner, block.getLocation(), Interaction.BREAK_BLOCK)) {
            AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b));
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
            // We only want to break non-Slimefun blocks
            if (!BlockStorage.hasBlockInfo(block)) {
                breakBlock(menu, drops, block);
                move(b, face, block);
            }
        } else {
            move(b, face, block);
        }
    } else {
        move(b, face, block);
    }
}
Also used : AndroidMineEvent(io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 50 with Slimefun

use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.

the class DebugFishListener method onRightClick.

@ParametersAreNonnullByDefault
private void onRightClick(Player p, Block b, BlockFace face) {
    if (p.isSneaking()) {
        // Fixes #2655 - Delaying the placement to prevent a new event from being fired
        Slimefun.runSync(() -> {
            Block block = b.getRelative(face);
            block.setType(Material.PLAYER_HEAD);
            PlayerHead.setSkin(block, HeadTexture.MISSING_TEXTURE.getAsSkin(), true);
            p.playSound(block.getLocation(), Sound.BLOCK_BAMBOO_PLACE, 1, 1);
        }, 2L);
    } else if (BlockStorage.hasBlockInfo(b)) {
        try {
            sendInfo(p, b);
        } catch (Exception x) {
            Slimefun.logger().log(Level.SEVERE, "An Exception occurred while using a Debug-Fish", x);
        }
    } else {
        // Read applicable Slimefun tags
        Set<SlimefunTag> tags = EnumSet.noneOf(SlimefunTag.class);
        for (SlimefunTag tag : SlimefunTag.values()) {
            if (tag.isTagged(b.getType())) {
                tags.add(tag);
            }
        }
        if (!tags.isEmpty()) {
            p.sendMessage(" ");
            p.sendMessage(ChatColors.color("&dSlimefun tags for: &e") + b.getType().name());
            for (SlimefunTag tag : tags) {
                p.sendMessage(ChatColors.color("&d* &e") + tag.name());
            }
            p.sendMessage(" ");
        }
    }
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) SlimefunTag(io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag) Block(org.bukkit.block.Block) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)17 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)16 ItemStack (org.bukkit.inventory.ItemStack)14 DisplayName (org.junit.jupiter.api.DisplayName)14 Test (org.junit.jupiter.api.Test)14 Player (org.bukkit.entity.Player)12 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)10 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)8 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)7 NamespacedKey (org.bukkit.NamespacedKey)7 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 BeforeAll (org.junit.jupiter.api.BeforeAll)4 TagMisconfigurationException (io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException)3 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)3 Block (org.bukkit.block.Block)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 PotionEffect (org.bukkit.potion.PotionEffect)3 AndroidMineEvent (io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent)2