forked from Slimefun/Slimefun4
-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14602eb
commit cb6bb12
Showing
5 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package city.norain.slimefun4.compatibillty; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; | ||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; | ||
import java.lang.reflect.Constructor; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import lombok.SneakyThrows; | ||
import lombok.experimental.UtilityClass; | ||
import org.bukkit.ExplosionResult; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.block.BlockExplodeEvent; | ||
|
||
@UtilityClass | ||
public class VersionedEvent { | ||
private Constructor<BlockExplodeEvent> blockExplodeConstructor; | ||
|
||
public void init() { | ||
if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_21)) { | ||
try { | ||
blockExplodeConstructor = BlockExplodeEvent.class.getConstructor(Block.class, List.class, float.class); | ||
} catch (NoSuchMethodException e) { | ||
Slimefun.logger().log(Level.WARNING, "无法初始化事件版本兼容模块, 部分功能可能无法正常使用", e); | ||
} | ||
} | ||
} | ||
|
||
@SneakyThrows | ||
public BlockExplodeEvent newBlockExplodeEvent(Block block, List<Block> affectedBlock, float yield) { | ||
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { | ||
return new BlockExplodeEvent(block, block.getState(), affectedBlock, yield, ExplosionResult.DESTROY); | ||
} else { | ||
if (blockExplodeConstructor == null) { | ||
throw new IllegalStateException("Unable to create BlockExplodeEvent: missing constructor"); | ||
} | ||
return blockExplodeConstructor.newInstance(block, affectedBlock, yield); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters