1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2020-08-04 00:58:43 +02:00
parent cafa66b1a8
commit 56b78eac61
3 changed files with 22 additions and 15 deletions

View File

@ -34,6 +34,7 @@
* Fixed #2176 * Fixed #2176
* Fixed #2103 * Fixed #2103
* Fixed #2184 * Fixed #2184
* Fixed #2183
## Release Candidate 15 (01 Aug 2020) ## Release Candidate 15 (01 Aug 2020)

View File

@ -1,6 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import org.bukkit.Material; import org.bukkit.Material;
@ -33,7 +33,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
public abstract class CropGrowthAccelerator extends SlimefunItem implements InventoryBlock, EnergyNetComponent { public abstract class CropGrowthAccelerator extends SlimefunItem implements InventoryBlock, EnergyNetComponent {
private final int[] border = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; private final int[] border = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
private final Set<Material> crops = new HashSet<>(); private final Set<Material> crops = EnumSet.noneOf(Material.class);
// We wanna strip the Slimefun Item id here // We wanna strip the Slimefun Item id here
private static final ItemStack organicFertilizer = new ItemStackWrapper(SlimefunItems.FERTILIZER); private static final ItemStack organicFertilizer = new ItemStackWrapper(SlimefunItems.FERTILIZER);

View File

@ -1,7 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners; package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
@ -35,7 +35,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
public class BlockListener implements Listener { public class BlockListener implements Listener {
// Materials that require a Block under it, e.g. Pressure Plates // Materials that require a Block under it, e.g. Pressure Plates
private final Set<Material> sensitiveMaterials = new HashSet<>(); private final Set<Material> sensitiveMaterials = EnumSet.noneOf(Material.class);
public BlockListener(SlimefunPlugin plugin) { public BlockListener(SlimefunPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
@ -82,11 +82,8 @@ public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockUnregister(BlockBreakEvent e) { public void onBlockUnregister(BlockBreakEvent e) {
if (hasSensitiveBlockAbove(e.getPlayer(), e.getBlock())) { checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock());
e.setCancelled(true);
return;
}
SlimefunItem sfItem = BlockStorage.check(e.getBlock()); SlimefunItem sfItem = BlockStorage.check(e.getBlock());
ItemStack item = e.getPlayer().getInventory().getItemInMainHand(); ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
int fortune = getBonusDropsWithFortune(item, e.getBlock()); int fortune = getBonusDropsWithFortune(item, e.getBlock());
@ -142,7 +139,17 @@ public class BlockListener implements Listener {
} }
} }
private boolean hasSensitiveBlockAbove(Player p, Block b) { /**
* This method checks for a sensitive {@link Block}.
* Sensitive {@link Block Blocks} are pressure plates or saplings, which should be broken
* when the block beneath is broken as well.
*
* @param p
* The {@link Player} who broke this {@link Block}
* @param b
* The {@link Block} that was broken
*/
private void checkForSensitiveBlockAbove(Player p, Block b) {
Block blockAbove = b.getRelative(BlockFace.UP); Block blockAbove = b.getRelative(BlockFace.UP);
if (sensitiveMaterials.contains(blockAbove.getType())) { if (sensitiveMaterials.contains(blockAbove.getType())) {
@ -156,14 +163,13 @@ public class BlockListener implements Listener {
blockAbove.getWorld().dropItemNaturally(blockAbove.getLocation(), BlockStorage.retrieve(blockAbove)); blockAbove.getWorld().dropItemNaturally(blockAbove.getLocation(), BlockStorage.retrieve(blockAbove));
blockAbove.setType(Material.AIR); blockAbove.setType(Material.AIR);
} }
else { }
return true; else {
} blockAbove.getWorld().dropItemNaturally(blockAbove.getLocation(), BlockStorage.retrieve(blockAbove));
blockAbove.setType(Material.AIR);
} }
} }
} }
return false;
} }
private int getBonusDropsWithFortune(ItemStack item, Block b) { private int getBonusDropsWithFortune(ItemStack item, Block b) {