1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Make code better

This commit is contained in:
Patbox 2020-12-05 20:22:03 +01:00
parent f4633c528f
commit ff634c0f5c

View File

@ -4,16 +4,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.Iterator;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
@ -62,20 +59,19 @@ public class BlockListener implements Listener {
// While this can cause ghost blocks it also prevents them from replacing grass
// or saplings etc...
Block block = e.getBlock();
if (BlockStorage.hasBlockInfo(block)) {
SlimefunItem sfItem = BlockStorage.check(block);
if (sfItem != null) {
if (e.getBlockReplacedState().getType().isAir()) {
Iterator<ItemStack> item = BlockStorage.check(block).getDrops().iterator();
World world = block.getWorld();
Location loc = block.getLocation();
while (item.hasNext()) {
world.dropItem(loc, item.next());
for (ItemStack item : sfItem.getDrops()) {
if (item != null && !item.getType().isAir()) { block.getWorld().dropItemNaturally(block.getLocation(), item); }
}
BlockStorage.clearBlockInfo(block);
return;
}
} else {
e.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {