forked from Slimefun/Slimefun4
-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # jitpack.yml
- Loading branch information
Showing
17 changed files
with
225 additions
and
102 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
/.vscode/ | ||
/data-storage/ | ||
/javadocs/ | ||
/local-deps/ | ||
|
||
.classpath | ||
.factorypath | ||
|
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,12 @@ | ||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 | ||
http://maven.apache.org/xsd/settings-1.0.0.xsd"> | ||
<servers> | ||
<server> | ||
<id>dough-downstream</id> | ||
<username>StarWishsama</username> | ||
<password>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</password> | ||
</server> | ||
</servers> | ||
</settings> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
before_install: | ||
- sdk install java 17.0.1-open | ||
- sdk use java 17.0.1-open | ||
- sdk install java 17.0.5-zulu | ||
- sdk use java 17.0.5-zulu | ||
|
||
jdk: | ||
- openjdk17 | ||
install: | ||
- chmod 777 ./mvnw | ||
- ./mvnw -s .mvn/settings.xml install -DskipTests |
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
85 changes: 85 additions & 0 deletions
85
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,85 @@ | ||
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.lang.reflect.Method; | ||
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; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.inventory.InventoryEvent; | ||
import org.bukkit.inventory.Inventory; | ||
|
||
@UtilityClass | ||
public class VersionedEvent { | ||
private Constructor<BlockExplodeEvent> BLOCK_EXPLODE_EVENT_CONSTRUCTOR; | ||
|
||
private Method GET_TOP_INVENTORY; | ||
private Method GET_CLICKED_INVENTORY; | ||
|
||
public void init() { | ||
if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_21)) { | ||
try { | ||
BLOCK_EXPLODE_EVENT_CONSTRUCTOR = | ||
BlockExplodeEvent.class.getConstructor(Block.class, List.class, float.class); | ||
|
||
GET_TOP_INVENTORY = | ||
Class.forName("org.bukkit.inventory.InventoryView").getMethod("getTopInventory"); | ||
GET_TOP_INVENTORY.setAccessible(true); | ||
|
||
GET_CLICKED_INVENTORY = Class.forName("org.bukkit.event.inventory.InventoryClickEvent") | ||
.getMethod("getClickedInventory"); | ||
GET_CLICKED_INVENTORY.setAccessible(true); | ||
|
||
} catch (NoSuchMethodException | ClassNotFoundException 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 (BLOCK_EXPLODE_EVENT_CONSTRUCTOR == null) { | ||
throw new IllegalStateException("Unable to create BlockExplodeEvent: missing constructor"); | ||
} | ||
return BLOCK_EXPLODE_EVENT_CONSTRUCTOR.newInstance(block, affectedBlock, yield); | ||
} | ||
} | ||
|
||
/** | ||
* See https://www.spigotmc.org/threads/inventoryview-changed-to-interface-backwards-compatibility.651754/ | ||
*/ | ||
@SneakyThrows | ||
public Inventory getTopInventory(InventoryEvent event) { | ||
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { | ||
return event.getView().getTopInventory(); | ||
} else { | ||
if (GET_TOP_INVENTORY == null) { | ||
throw new IllegalStateException("Unable to get top inventory: missing method"); | ||
} | ||
|
||
return (Inventory) GET_TOP_INVENTORY.invoke(event.getView()); | ||
} | ||
} | ||
|
||
@SneakyThrows | ||
public Inventory getClickedInventory(InventoryClickEvent event) { | ||
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { | ||
return event.getClickedInventory(); | ||
} else { | ||
if (GET_CLICKED_INVENTORY == null) { | ||
throw new IllegalStateException("Unable to get clicked inventory: missing method"); | ||
} | ||
|
||
return (Inventory) GET_CLICKED_INVENTORY.invoke(event); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.