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()));
}
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 + "'");
}
}
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);
}
}
}
}
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);
}
}
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(" ");
}
}
}
Aggregations