1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45: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.List;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.Iterator;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -62,18 +59,17 @@ public class BlockListener implements Listener {
// While this can cause ghost blocks it also prevents them from replacing grass // While this can cause ghost blocks it also prevents them from replacing grass
// or saplings etc... // or saplings etc...
Block block = e.getBlock(); Block block = e.getBlock();
if (BlockStorage.hasBlockInfo(block)) { SlimefunItem sfItem = BlockStorage.check(block);
if (sfItem != null) {
if (e.getBlockReplacedState().getType().isAir()) { if (e.getBlockReplacedState().getType().isAir()) {
Iterator<ItemStack> item = BlockStorage.check(block).getDrops().iterator(); for (ItemStack item : sfItem.getDrops()) {
World world = block.getWorld(); if (item != null && !item.getType().isAir()) { block.getWorld().dropItemNaturally(block.getLocation(), item); }
Location loc = block.getLocation();
while (item.hasNext()) {
world.dropItem(loc, item.next());
} }
BlockStorage.clearBlockInfo(block); BlockStorage.clearBlockInfo(block);
return; } else {
e.setCancelled(true);
} }
e.setCancelled(true);
} }
} }