mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #1993
This commit is contained in:
parent
4855f0da86
commit
c84dd02b39
@ -62,6 +62,7 @@
|
||||
* Fixed #1992
|
||||
* Possibly fixed #1951
|
||||
* Fixed tab completion for /sf give showing players instead of amounts
|
||||
* Fixed #1993
|
||||
|
||||
## Release Candidate 12 (27 May 2020)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#12
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.blocks;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
@ -8,13 +9,16 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Nameable;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
@ -47,11 +51,12 @@ public class BlockPlacer extends SimpleSlimefunItem<BlockDispenseHandler> {
|
||||
e.setCancelled(true);
|
||||
|
||||
if ((facedBlock.getType() == null || facedBlock.getType() == Material.AIR) && e.getItem().getType().isBlock() && !isBlacklisted(e.getItem().getType())) {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(e.getItem());
|
||||
SlimefunItem item = SlimefunItem.getByItem(e.getItem());
|
||||
|
||||
if (sfItem != null) {
|
||||
if (!SlimefunPlugin.getRegistry().getBlockHandlers().containsKey(sfItem.getID())) {
|
||||
placeSlimefunBlock(sfItem, e.getItem(), facedBlock, dispenser);
|
||||
if (item != null) {
|
||||
// Check if this Item can even be placed down
|
||||
if (!(item instanceof NotPlaceable) && !SlimefunPlugin.getRegistry().getBlockHandlers().containsKey(item.getID())) {
|
||||
placeSlimefunBlock(item, e.getItem(), facedBlock, dispenser);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -75,10 +80,20 @@ public class BlockPlacer extends SimpleSlimefunItem<BlockDispenseHandler> {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void placeSlimefunBlock(SlimefunItem sfItem, ItemStack item, Block facedBlock, Dispenser dispenser) {
|
||||
facedBlock.setType(item.getType());
|
||||
BlockStorage.store(facedBlock, sfItem.getID());
|
||||
facedBlock.getWorld().playEffect(facedBlock.getLocation(), Effect.STEP_SOUND, item.getType());
|
||||
private void placeSlimefunBlock(SlimefunItem sfItem, ItemStack item, Block block, Dispenser dispenser) {
|
||||
block.setType(item.getType());
|
||||
BlockStorage.store(block, sfItem.getID());
|
||||
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, item.getType());
|
||||
|
||||
if (item.getType() == Material.SPAWNER && sfItem instanceof RepairedSpawner) {
|
||||
Optional<EntityType> entity = ((RepairedSpawner) sfItem).getEntityType(item);
|
||||
|
||||
if (entity.isPresent()) {
|
||||
CreatureSpawner spawner = (CreatureSpawner) block.getState();
|
||||
spawner.setSpawnedType(entity.get());
|
||||
spawner.update(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (dispenser.getInventory().containsAtLeast(item, 2)) {
|
||||
dispenser.getInventory().removeItem(new CustomItem(item, 1));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
@ -25,18 +26,12 @@ public class RepairedSpawner extends SimpleSlimefunItem<BlockPlaceHandler> {
|
||||
public BlockPlaceHandler getItemHandler() {
|
||||
return (e, item) -> {
|
||||
// We need to explicitly ignore the lore here
|
||||
if (SlimefunUtils.isItemSimilar(item, SlimefunItems.REPAIRED_SPAWNER, false)) {
|
||||
EntityType type = null;
|
||||
if (SlimefunUtils.isItemSimilar(item, SlimefunItems.REPAIRED_SPAWNER, false, false)) {
|
||||
Optional<EntityType> entity = getEntityType(item);
|
||||
|
||||
for (String line : item.getItemMeta().getLore()) {
|
||||
if (ChatColor.stripColor(line).startsWith("Type: ") && !line.contains("<Type>")) {
|
||||
type = EntityType.valueOf(ChatColor.stripColor(line).replace("Type: ", "").replace(' ', '_').toUpperCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
if (entity.isPresent()) {
|
||||
CreatureSpawner spawner = (CreatureSpawner) e.getBlock().getState();
|
||||
spawner.setSpawnedType(type);
|
||||
spawner.setSpawnedType(entity.get());
|
||||
spawner.update(true, false);
|
||||
}
|
||||
|
||||
@ -48,4 +43,22 @@ public class RepairedSpawner extends SimpleSlimefunItem<BlockPlaceHandler> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This method tries to obtain an {@link EntityType} from a given {@link ItemStack}.
|
||||
* The provided {@link ItemStack} must be a {@link RepairedSpawner} item.
|
||||
*
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public Optional<EntityType> getEntityType(ItemStack item) {
|
||||
for (String line : item.getItemMeta().getLore()) {
|
||||
if (ChatColor.stripColor(line).startsWith("Type: ") && !line.contains("<Type>")) {
|
||||
EntityType type = EntityType.valueOf(ChatColor.stripColor(line).replace("Type: ", "").replace(' ', '_').toUpperCase(Locale.ROOT));
|
||||
return Optional.of(type);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user