diff --git a/src/main/java/city/norain/slimefun4/EnvironmentChecker.java b/src/main/java/city/norain/slimefun4/EnvironmentChecker.java index f44cd80c7c..68c5a3c7b7 100644 --- a/src/main/java/city/norain/slimefun4/EnvironmentChecker.java +++ b/src/main/java/city/norain/slimefun4/EnvironmentChecker.java @@ -37,20 +37,35 @@ static boolean checkIncompatiblePlugins(@Nonnull Logger logger) { } static boolean checkHybridServer() { + + try { + Class.forName("cpw.mods.modlauncher.Launcher", false, ClassLoader.getSystemClassLoader()); + return true; + } catch (ClassNotFoundException ignored) {} + try { - Class.forName("cpw.mods.modlauncher.Launcher"); - Class.forName("net.minecraftforge.server.console.TerminalHandler"); + Class.forName("net.minecraftforge.server.console.TerminalHandler", false, ClassLoader.getSystemClassLoader()); + + return true; + } catch (ClassNotFoundException ignored) {} + try { + Class.forName("org.cardboardpowered.mixin.CardboardMixinPlugin", false, ClassLoader.getSystemClassLoader()); return true; - } catch (ClassNotFoundException ignored) { - if (Bukkit.getPluginCommand("mohist") != null) { - return true; - } + } catch (ClassNotFoundException ignored) {} - var serverVer = Bukkit.getVersion().toLowerCase(); + try { + Class.forName("net.fabricmc.loader.impl.FabricLoaderImpl", false, ClassLoader.getSystemClassLoader()); + return true; + } catch (ClassNotFoundException ignored) {} - return serverVer.contains("arclight") || serverVer.contains("mohist"); + if (Bukkit.getPluginCommand("mohist") != null) { + return true; } + + var serverVer = Bukkit.getVersion().toLowerCase(); + + return serverVer.contains("arclight") || serverVer.contains("mohist"); } static void scheduleSlimeGlueCheck(@Nonnull Slimefun sf) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index ebe51d218e..458d87a6ca 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -20,6 +20,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEnchantment; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; + import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -27,6 +28,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -58,7 +60,7 @@ */ public class BlockListener implements Listener { - private static final BlockFace[] CARDINAL_BLOCKFACES = new BlockFace[] { + private static final BlockFace[] CARDINAL_BLOCKFACES = new BlockFace[]{ BlockFace.WEST, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.DOWN, BlockFace.UP }; @@ -123,27 +125,9 @@ public void onBlockPlace(BlockPlaceEvent e) { e.setCancelled(true); } else { var block = e.getBlock(); - if (block.getBlockData() instanceof Rotatable rotatable - && !(rotatable.getRotation() == BlockFace.UP || rotatable.getRotation() == BlockFace.DOWN)) { - BlockFace rotation = null; - - if (sfItem instanceof NotCardinallyRotatable && sfItem instanceof NotDiagonallyRotatable) { - rotation = BlockFace.NORTH; - } else if (sfItem instanceof NotRotatable notRotatable) { - rotation = notRotatable.getRotation(); - } else if (sfItem instanceof NotCardinallyRotatable notRotatable) { - rotation = notRotatable.getRotation(Location.normalizeYaw( - e.getPlayer().getLocation().getYaw())); - } else if (sfItem instanceof NotDiagonallyRotatable notRotatable) { - rotation = notRotatable.getRotation(Location.normalizeYaw( - e.getPlayer().getLocation().getYaw())); - } - if (rotation != null) { - rotatable.setRotation(rotation); - block.setBlockData(rotatable); - } - } + optimizePlacement(sfItem, block, e.getPlayer().getLocation()); + var placeEvent = new SlimefunBlockPlaceEvent(e.getPlayer(), item, block, sfItem); Bukkit.getPluginManager().callEvent(placeEvent); @@ -156,16 +140,16 @@ public void onBlockPlace(BlockPlaceEvent e) { if (sfItem instanceof UniversalBlock) { var data = Slimefun.getDatabaseManager() - .getBlockDataController() - .createUniversalBlock(block.getLocation(), sfItem.getId()); + .getBlockDataController() + .createUniversalBlock(block.getLocation(), sfItem.getId()); if (Slimefun.getBlockDataService().isTileEntity(block.getType())) { Slimefun.getBlockDataService().updateUniversalDataUUID(block, data.getKey()); } } else { Slimefun.getDatabaseManager() - .getBlockDataController() - .createBlock(block.getLocation(), sfItem.getId()); + .getBlockDataController() + .createBlock(block.getLocation(), sfItem.getId()); } sfItem.callItemHandler(BlockPlaceHandler.class, handler -> handler.onPlayerPlace(e)); @@ -189,15 +173,15 @@ public void onBlockBreak(BlockBreakEvent e) { var heldItem = e.getPlayer().getInventory().getItemInMainHand(); var block = e.getBlock(); var blockData = StorageCacheUtils.hasBlock(block.getLocation()) - ? StorageCacheUtils.getBlock(block.getLocation()) - : StorageCacheUtils.getUniversalBlock(block); + ? StorageCacheUtils.getBlock(block.getLocation()) + : StorageCacheUtils.getUniversalBlock(block); var sfItem = blockData == null ? null : SlimefunItem.getById(blockData.getSfId()); // If there is a Slimefun Block here, call our BreakEvent and, if cancelled, cancel this event // and return if (blockData != null) { SlimefunBlockBreakEvent breakEvent = - new SlimefunBlockBreakEvent(e.getPlayer(), heldItem, e.getBlock(), sfItem); + new SlimefunBlockBreakEvent(e.getPlayer(), heldItem, e.getBlock(), sfItem); Bukkit.getPluginManager().callEvent(breakEvent); if (breakEvent.isCancelled()) { @@ -229,18 +213,18 @@ public void onBlockBreak(BlockBreakEvent e) { e.setDropItems(false); var type = block.getType(); StorageCacheUtils.executeAfterLoad( - blockData, - () -> { - callBlockHandler(e, heldItem, drops); - if (e.isCancelled()) { - block.setType(type); - blockData.setPendingRemove(false); - return; - } - e.setDropItems(true); - dropItems(e, heldItem, block, sfItem, drops); - }, - true); + blockData, + () -> { + callBlockHandler(e, heldItem, drops); + if (e.isCancelled()) { + block.setType(type); + blockData.setPendingRemove(false); + return; + } + e.setDropItems(true); + dropItems(e, heldItem, block, sfItem, drops); + }, + true); return; } @@ -287,7 +271,7 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List @ParametersAreNonnullByDefault private void dropItems( - BlockBreakEvent e, ItemStack item, Block block, @Nullable SlimefunItem sfBlock, List drops) { + BlockBreakEvent e, ItemStack item, Block block, @Nullable SlimefunItem sfBlock, List drops) { if (!drops.isEmpty()) { // TODO: properly support loading inventories within unit tests if (!Slimefun.instance().isUnitTest()) { @@ -305,7 +289,7 @@ private void dropItems( // Prevent null or air from being dropped if (drop != null && drop.getType() != Material.AIR) { if (e.getPlayer().getGameMode() != GameMode.CREATIVE - || Slimefun.getCfg().getBoolean("options.drop-block-creative")) { + || Slimefun.getCfg().getBoolean("options.drop-block-creative")) { block.getWorld().dropItemNaturally(block.getLocation(), drop); } } @@ -343,7 +327,7 @@ private void checkForSensitiveBlockAbove(Player player, Block block, ItemStack i var controller = Slimefun.getDatabaseManager().getBlockDataController(); if (blockData.isDataLoaded()) { sfItem.callItemHandler( - BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops)); + BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops)); controller.removeBlock(loc); dropItems(dummyEvent, item, block, sfItem, drops); } else { @@ -357,7 +341,7 @@ public boolean runOnMainThread() { @Override public void onResult(SlimefunBlockData result) { sfItem.callItemHandler( - BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops)); + BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops)); controller.removeBlock(loc); dropItems(dummyEvent, item, block, sfItem, drops); } @@ -372,10 +356,8 @@ public void onResult(SlimefunBlockData result) { * This method checks recursively for any sensitive blocks * that are no longer supported due to this block breaking * - * @param block - * The {@link Block} in question - * @param count - * The amount of times this has been recursively called + * @param block The {@link Block} in question + * @param count The amount of times this has been recursively called */ @ParametersAreNonnullByDefault private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropItems) { @@ -407,12 +389,9 @@ private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropI * This method checks if the {@link BlockData} would be * supported at the given {@link Block}. * - * @param blockData - * The {@link BlockData} to check - * @param block - * The {@link Block} the {@link BlockData} would be at - * @return - * Whether the {@link BlockData} would be supported at the given {@link Block} + * @param blockData The {@link BlockData} to check + * @param block The {@link Block} the {@link BlockData} would be at + * @return Whether the {@link BlockData} would be supported at the given {@link Block} */ @ParametersAreNonnullByDefault private boolean isSupported(BlockData blockData, Block block) { @@ -447,4 +426,29 @@ private int getBonusDropsWithFortune(@Nullable ItemStack item, @Nonnull Block b) return amount; } + + // 美化可旋转类 (如头颅) 物品放置 + private void optimizePlacement(SlimefunItem sfItem, Block block, Location l) { + if (block.getBlockData() instanceof Rotatable rotatable + && !(rotatable.getRotation() == BlockFace.UP || rotatable.getRotation() == BlockFace.DOWN)) { + BlockFace rotation = null; + + if (sfItem instanceof NotCardinallyRotatable && sfItem instanceof NotDiagonallyRotatable) { + rotation = BlockFace.NORTH; + } else if (sfItem instanceof NotRotatable notRotatable) { + rotation = notRotatable.getRotation(); + } else if (sfItem instanceof NotCardinallyRotatable notRotatable) { + rotation = notRotatable.getRotation(Location.normalizeYaw( + l.getYaw())); + } else if (sfItem instanceof NotDiagonallyRotatable notRotatable) { + rotation = notRotatable.getRotation(Location.normalizeYaw( + l.getYaw())); + } + + if (rotation != null) { + rotatable.setRotation(rotation); + block.setBlockData(rotatable); + } + } + } }