Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Jun 9, 2024
2 parents ea2c1d2 + b86c047 commit 226af9b
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

echo "[pre-commit check]"

Expand Down
20 changes: 13 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# 贡献代码指南
# 贡献指南

在向 Slimefun 汉化版提交代码前,你必须先阅读这个指南。
在对 Slimefun 汉化版进行代码前,必须先阅读此贡献指南。

# 设置环境

我们提供了一个自动化格式检查系统,请使用 `mvn install` 进行初始化。

本项目已经提供 `.editorconfig` 用于控制代码样式。如果你有自己的代码样式风格,请在对本仓库进行贡献前切换为当前仓库的风格配置。

# 提交信息规范

本项目强制使用 [约定式提交](https://www.conventionalcommits.org/zh-hans/v1.0.0/) 的提交信息规范。
本项目**强制使用** [约定式提交](https://www.conventionalcommits.org/zh-hans/v1.0.0/) 的提交信息规范。

> 简单来说, 你的提交信息需要包含以下内容:
>
Expand All @@ -18,6 +24,8 @@
如果是修复请在主提交消息上声明,不必重复声明。

我们支持的类型前缀正则如下:`(feat(ure)?|fix|docs|style|refactor|ci|chore|perf|build|test|revert|trans)`

另外的, 如果是与翻译相关的提交,类型应为 trans。

# 代码规范
Expand All @@ -26,12 +34,10 @@

请不要过度缩减代码长度, 空格少了 Slimefun 也不会因此跑得更快.

我们使用了 Spotless 作为代码格式化工具,你可以直接使用 `mvn spotless:check spotless:apply` 来自动格式化你的代码。

如果你希望你的代码被合并至官方, 请遵守 Slimefun 主仓库的 [提交规范](https://github.com/Slimefun/Slimefun4/blob/master/CONTRIBUTING.md)
我们使用了 Spotless 作为代码格式化工具,在提交前你**必须**使用 `mvn spotless:check spotless:apply` 来自动格式化你的代码,否则将会被格式检查器拦截 PR。

# 提交代码类型

你提交的代码可以是修复、新增内容和 API。

下游代码现在支持提交 API 相关代码,开发者们可以通过 jitpack/GitHub Package 依赖汉化版的 Slimefun。
下游代码现在支持提交 API 相关代码,开发者们可以通过 jitpack 依赖汉化版的 Slimefun。
26 changes: 1 addition & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,33 +309,9 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.2</version>
<version>42.7.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.19.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.19.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
<scope>provided</scope>
</dependency>

<!-- Third party plugin integrations / soft dependencies -->
<dependency>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/city/norain/slimefun4/SlimefunExtended.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package city.norain.slimefun4;

import city.norain.slimefun4.listener.SlimefunMigrateListener;
import city.norain.slimefun4.utils.HikariLogFilter;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import java.util.logging.Level;
import javax.annotation.Nonnull;
Expand All @@ -16,7 +15,6 @@ public final class SlimefunExtended {
private static void checkDebug() {
if ("true".equals(System.getProperty("slimefun.database.debug"))) {
databaseDebugMode = true;
HikariLogFilter.registerFilter(org.apache.logging.log4j.Level.DEBUG);
}
}

Expand Down
50 changes: 0 additions & 50 deletions src/main/java/city/norain/slimefun4/utils/HikariLogFilter.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.OptionalInt;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -246,7 +248,7 @@ private int generate(@Nonnull GEOResource resource, @Nonnull World world, int x,
* @param block
* The {@link Block} which the scan starts at
* @param page
* The page to display
* The zero-based page to display
*/
public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
if (Slimefun.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) {
Expand Down Expand Up @@ -282,12 +284,20 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
resources.sort(Comparator.comparing(a -> a.getName(p).toLowerCase(Locale.ROOT)));

int index = 10;
int pages = (resources.size() - 1) / 36 + 1;
int pages = (int) (Math.ceil((double) resources.size() / 36) + 1);

for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
GEOResource resource = resources.get(i);
Map<GEOResource, Integer> supplyMap = new HashMap<>();

// if resource is not generated, generate the first
resources.forEach(resource -> {
OptionalInt optional = getSupplies(resource, block.getWorld(), x, z);
int supplies = optional.orElseGet(() -> generate(resource, block.getWorld(), x, block.getY(), z));
supplyMap.put(resource, supplies);
});

for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
GEOResource resource = resources.get(i);
int supplies = supplyMap.get(resource);
String suffix = Slimefun.getLocalization()
.getResourceString(p, ChatUtils.checkPlurality("tooltips.unit", supplies));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,17 @@ public final int hashCode() {
return Slimefun.getRegistry().getSlimefunItemIds().get(id);
}

/**
* Retrieve a {@link Optional} {@link SlimefunItem} by its id.
*
* @param id
* The id of the {@link SlimefunItem}
* @return The {@link Optional} {@link SlimefunItem} associated with that id. Empty if non-existent
*/
public static @Nonnull Optional<SlimefunItem> getOptionalById(@Nonnull String id) {
return Optional.ofNullable(getById(id));
}

/**
* Retrieve a {@link SlimefunItem} from an {@link ItemStack}.
*
Expand All @@ -1258,6 +1269,17 @@ public final int hashCode() {
return null;
}

/**
* Retrieve a {@link Optional} {@link SlimefunItem} from an {@link ItemStack}.
*
* @param item
* The {@link ItemStack} to check
* @return The {@link Optional} {@link SlimefunItem} associated with this {@link ItemStack} if present, otherwise empty
*/
public static @Nonnull Optional<SlimefunItem> getOptionalByItem(@Nullable ItemStack item) {
return Optional.ofNullable(getByItem(item));
}

/**
* Should load the {@link SlimefunBlockData} by default.
* If return false, only the item with {@link BlockTicker} will be loaded with {@link ChunkLoadEvent}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,16 @@ public void onResult(SlimefunChunkData result) {
}

private void start(@Nonnull Block b, @Nonnull BlockMenu inv) {
boolean success = Slimefun.getRegistry().getGEOResources().values().isEmpty();
for (GEOResource resource : Slimefun.getRegistry().getGEOResources().values()) {
if (resource.isObtainableFromGEOMiner()) {
OptionalInt optional = Slimefun.getGPSNetwork()
.getResourceManager()
.getSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4);

if (!optional.isPresent()) {
updateHologram(b, "&4需要先进行地形扫描!");
return;
}
if (optional.isEmpty()) continue;

success = true;

int supplies = optional.getAsInt();
if (supplies > 0) {
Expand All @@ -370,6 +370,11 @@ private void start(@Nonnull Block b, @Nonnull BlockMenu inv) {
}
}

if (!success) {
updateHologram(b, "&4需要先进行地形扫描!");
return;
}

updateHologram(b, "&7开采完成");
}
}
Loading

0 comments on commit 226af9b

Please sign in to comment.