Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	jitpack.yml
  • Loading branch information
StarWishsama committed Aug 4, 2024
2 parents d36ce9d + a19da27 commit 5d89728
Show file tree
Hide file tree
Showing 17 changed files with 225 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
architecture: x64
cache: maven
- name: Codestyle Check
run: mvn -B spotless:check --errors
run: mvn -s .mvn/settings.xml -B spotless:check --errors
- name: Build Slimefun
run: mvn -B package --errors
run: mvn -s .mvn/settings.xml -B package --errors
- uses: actions/upload-artifact@v2
name: Upload Beta artifact
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
architecture: x64
cache: maven
- name: Codestyle check
run: mvn -B spotless:check --errors
run: mvn -s .mvn/settings.xml -B spotless:check --errors
- name: Build Slimefun
run: mvn -B package --errors
run: mvn -s .mvn/settings.xml -B package --errors
- name: Mask Output
run: |
echo "::add-mask::$CF_API_TOKEN"
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/pr-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
restore-keys: ${{ runner.os }}-m2

- name: Codestyle Check
run: mvn -B spotless:check compile --errors
run: mvn -s .mvn/settings.xml -B spotless:check compile --errors

- name: Build with Maven
run: mvn package
run: mvn -s .mvn/settings.xml package --errors

# Setup for the preview build
- name: Environment Setup
Expand All @@ -56,9 +56,6 @@ jobs:
echo "JAR_VERSION=$JAR_VERSION" >> "$GITHUB_ENV"
sed -i "s/<version>5.0-SNAPSHOT<\/version>/<version>$JAR_VERSION<\/version>/g" pom.xml
- name: Build with Maven
run: mvn clean package

- name: Upload the artifact
uses: actions/upload-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/.vscode/
/data-storage/
/javadocs/
/local-deps/

.classpath
.factorypath
Expand Down
12 changes: 12 additions & 0 deletions .mvn/settings.xml
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>&#103;&#104;&#112;&#95;&#110;&#84;&#77;&#99;&#122;&#76;&#121;&#102;&#53;&#110;&#69;&#65;&#82;&#68;&#80;&#51;&#87;&#120;&#70;&#80;&#51;&#84;&#122;&#118;&#68;&#66;&#74;&#110;&#48;&#75;&#48;&#105;&#81;&#109;&#110;&#88;</password>
</server>
</servers>
</settings>
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ Slimefun 4 可以在[鬼斩构建站](https://builds.guizhanss.com)页面中**

**! 建议你使用最新的测试版,可以获得最新的内容更新和 Bug 修复!**

## :computer: 如何编译
要编译 Slimefun4,你必须先安装 [Git](https://git-scm.com/)
然后 `git clone https://github.com/SlimefunGuguProject/Slimefun4.git`
最后如果你是 Windows 系统: `.\mvnw.cmd -s .mvn/settings.xml package`
如果你是类 Unix 系统: `.\mvnw -s .mvn/settings.xml package`

## :framed_picture: 截图

那么,Slimefun 看起来是怎样的呢?<br>
Expand Down
9 changes: 5 additions & 4 deletions jitpack.yml
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
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

<maven.settings.file>${project.basedir}/.mvn/settings.xml</maven.settings.file>

<!-- Spigot properties -->
<spigot.version>1.20.6</spigot.version>
<spigot.version>1.21</spigot.version>
<spigot.javadocs>https://hub.spigotmc.org/javadocs/spigot/</spigot.javadocs>
</properties>

Expand All @@ -48,6 +50,14 @@
<!-- Repositories that host our dependencies -->
<!-- Well, any that aren't found on maven-central. -->
<repositories>
<!-- Public dough downstream repo -->
<repository>
<id>dough-downstream</id>
<url>https://maven.pkg.github.com/StarWishsama/dough</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<!-- Spigot-API -->
<id>spigot-repo</id>
Expand Down Expand Up @@ -275,9 +285,9 @@

<!-- Shaded packages -->
<dependency>
<groupId>com.github.starwishsama.dough</groupId>
<groupId>io.github.baked-libs</groupId>
<artifactId>dough-api</artifactId>
<version>d783252831</version>
<version>1.3.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/city/norain/slimefun4/SlimefunExtended.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package city.norain.slimefun4;

import city.norain.slimefun4.compatibillty.VersionedEvent;
import city.norain.slimefun4.listener.SlimefunMigrateListener;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import java.util.logging.Level;
Expand Down Expand Up @@ -47,14 +48,16 @@ public static boolean checkEnvironment(@Nonnull Slimefun sf) {
}
}

public static void register(@Nonnull Slimefun sf) {
public static void init(@Nonnull Slimefun sf) {
EnvironmentChecker.scheduleSlimeGlueCheck(sf);

checkDebug();

VaultIntegration.register(sf);

migrateListener.register(sf);

VersionedEvent.init();
}

public static void shutdown() {
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ProfileDataController extends ADataController {

var key = new RecordKey(DataScope.PLAYER_PROFILE);
key.addField(FieldKey.PLAYER_BACKPACK_NUM);
key.addField(FieldKey.PLAYER_NAME);
key.addCondition(FieldKey.PLAYER_UUID, uuid);

var result = getData(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ private void onPluginStart() {

// All Slimefun Listeners
logger.log(Level.INFO, "正在注册监听器...");

// Inject downstream extra staff
SlimefunExtended.init(this);

registerListeners();

// Initiating various Stuff and all items with a slight delay (0ms after the Server finished
Expand Down Expand Up @@ -706,9 +710,6 @@ private void registerListeners() {
new SmithingTableListener(this);
new JoinListener(this);

// Inject downstream extra staff
SlimefunExtended.register(this);

// Item-specific Listeners
new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem());
new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem());
Expand Down
Loading

0 comments on commit 5d89728

Please sign in to comment.