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 Aug 29, 2024
2 parents 538e41a + 6e611c1 commit dc72b4b
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 36 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/pr-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,11 @@ jobs:
java-version: ${{ vars.JAVA_CI_VERSION }}
java-package: jdk
architecture: x64

- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
cache: 'maven'

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

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

# Setup for the preview build
- name: Environment Setup
id: env-setup
Expand All @@ -54,7 +45,10 @@ jobs:
echo "SHORT_COMMIT_HASH=$SHORT_COMMIT_HASH" >> "$GITHUB_ENV"
echo "SHORT_COMMIT_HASH=$SHORT_COMMIT_HASH" >> "$GITHUB_OUTPUT"
echo "JAR_VERSION=$JAR_VERSION" >> "$GITHUB_ENV"
sed -i "s/<version>5.0-SNAPSHOT<\/version>/<version>$JAR_VERSION<\/version>/g" pom.xml
sed -i "s/<version>UNOFFICIAL<\/version>/<version>$JAR_VERSION<\/version>/g" pom.xml
- name: Build with Maven
run: mvn -s .mvn/settings.xml package --errors

- name: Upload the artifact
uses: actions/upload-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.1
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperVersion=3.3.2
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Slimefun 4 可以在[鬼斩构建站](https://builds.guizhanss.com)页面中**
## :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`
最后如果你是 Windows 系统: `.\mvnw.cmd package`
如果你是类 Unix 系统: `.\mvnw package`

## :framed_picture: 截图

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<configuration>
<installHooks>
<pre-commit>.git-hooks/pre-commit</pre-commit>
Expand Down Expand Up @@ -369,7 +369,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.5</version>
<version>2.11.6</version>
<scope>provided</scope>

<exclusions>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/city/norain/slimefun4/SlimefunExtended.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import city.norain.slimefun4.compatibillty.VersionedEvent;
import city.norain.slimefun4.listener.SlimefunMigrateListener;
import io.github.bakedlibs.dough.versions.MinecraftVersion;
import io.github.bakedlibs.dough.versions.UnknownServerVersionException;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import java.util.logging.Level;
import javax.annotation.Nonnull;
Expand All @@ -13,13 +15,23 @@ public final class SlimefunExtended {
@Getter
private static boolean databaseDebugMode = false;

@Getter
private static MinecraftVersion minecraftVersion;

private static void checkDebug() {
if ("true".equals(System.getProperty("slimefun.database.debug"))) {
databaseDebugMode = true;
}
}

public static boolean checkEnvironment(@Nonnull Slimefun sf) {
try {
minecraftVersion = MinecraftVersion.of(sf.getServer());
} catch (UnknownServerVersionException e) {
sf.getLogger().log(Level.WARNING, "无法识别你正在使用的服务端版本 :(");
return false;
}

if (EnvironmentChecker.checkHybridServer()) {
sf.getLogger().log(Level.WARNING, "#######################################################");
sf.getLogger().log(Level.WARNING, "");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xzavier0722.mc.plugin.slimefun4.storage.util;

import city.norain.slimefun4.SlimefunExtended;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
Expand Down Expand Up @@ -39,7 +40,11 @@ public static boolean isSameLoc(Location l1, Location l2) {

public static Chunk toChunk(World w, String cKey) {
var loc = cKey.split(";")[1].split(":");
return w.getChunkAt(Integer.parseInt(loc[0]), Integer.parseInt(loc[1]), false);
if (SlimefunExtended.getMinecraftVersion().isAtLeast(1, 19, 4)) {
return w.getChunkAt(Integer.parseInt(loc[0]), Integer.parseInt(loc[1]), false);
} else {
return w.getChunkAt(Integer.parseInt(loc[0]), Integer.parseInt(loc[1]));
}
}

public static boolean isSameWorld(World w1, World w2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ public List<ItemGroup> getAllItemGroups() {
*/
public @Nonnull List<SlimefunItem> getDisabledSlimefunItems() {
List<SlimefunItem> allItems = new ArrayList<>(getAllSlimefunItems());
List<SlimefunItem> enabledItems = getEnabledSlimefunItems();
allItems.removeAll(enabledItems);
return allItems;
return new ArrayList<>(
allItems.stream().filter(SlimefunItem::isDisabled).toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.CraftingTableListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.GrindstoneListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.SmithingTableListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.VanillaCrafterListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.BeeListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.EntityInteractionListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.FireworksListener;
Expand Down Expand Up @@ -708,6 +709,7 @@ private void registerListeners() {
new BeeWingsListener(this, (BeeWings) SlimefunItems.BEE_WINGS.getItem());
new PiglinListener(this);
new SmithingTableListener(this);
new VanillaCrafterListener(this);
new JoinListener(this);

// Item-specific Listeners
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,8 @@ private SlimefunItems() {}
public static final SlimefunItemStack LAVA_CRYSTAL =
new SlimefunItemStack("LAVA_CRYSTAL", HeadTexture.LAVA_CRYSTAL, "&4岩浆水晶");
public static final SlimefunItemStack SALT = new SlimefunItemStack("SALT", Material.SUGAR, "&r盐");
public static final SlimefunItemStack CHEESE = new SlimefunItemStack("CHEESE", HeadTexture.CHEESE, "&r黄油");
public static final SlimefunItemStack BUTTER = new SlimefunItemStack("BUTTER", HeadTexture.BUTTER, "&r奶酪");
public static final SlimefunItemStack CHEESE = new SlimefunItemStack("CHEESE", HeadTexture.CHEESE, "&r奶酪");
public static final SlimefunItemStack BUTTER = new SlimefunItemStack("BUTTER", HeadTexture.BUTTER, "&r黄油");
public static final SlimefunItemStack DUCT_TAPE =
new SlimefunItemStack("DUCT_TAPE", HeadTexture.DUCT_TAPE, "&8强力胶布", "", "&r可以用这个在自动铁砧里", "&r修复物品");
public static final SlimefunItemStack HEAVY_CREAM =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ private void openBackpack(Player p, ItemStack item, PlayerProfile profile, int s
Slimefun.getLocalization().sendMessage(p, "backpack.not-original-item", true);
return;
}
if (item.getAmount() > 1) {
Slimefun.getLocalization().sendMessage(p, "backpack.no-stack", true);
return;
}
PlayerBackpack.bindItem(
item,
Slimefun.getDatabaseManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ public void onBlockBreak(BlockBreakEvent e) {
var heldItem = e.getPlayer().getInventory().getItemInMainHand();
var block = e.getBlock();
var blockData = StorageCacheUtils.getBlock(block.getLocation());
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) {
var sfItem = SlimefunItem.getById(blockData.getSfId());
SlimefunBlockBreakEvent breakEvent =
new SlimefunBlockBreakEvent(e.getPlayer(), heldItem, e.getBlock(), sfItem);
Bukkit.getPluginManager().callEvent(breakEvent);
Expand All @@ -204,7 +204,7 @@ public void onBlockBreak(BlockBreakEvent e) {
checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock(), heldItem);

if (blockData == null || blockData.isPendingRemove()) {
dropItems(e, drops);
dropItems(e, heldItem, block, sfItem, drops);
return;
}

Expand All @@ -223,7 +223,7 @@ public void onBlockBreak(BlockBreakEvent e) {
return;
}
e.setDropItems(true);
dropItems(e, drops);
dropItems(e, heldItem, block, sfItem, drops);
},
true);
return;
Expand All @@ -233,7 +233,7 @@ public void onBlockBreak(BlockBreakEvent e) {
if (e.isCancelled()) {
blockData.setPendingRemove(false);
}
dropItems(e, drops);
dropItems(e, heldItem, block, sfItem, drops);

// Checks for vanilla sensitive blocks everywhere
// checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems());
Expand Down Expand Up @@ -271,27 +271,32 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List<ItemStack>
}

@ParametersAreNonnullByDefault
private void dropItems(BlockBreakEvent e, List<ItemStack> drops) {
private void dropItems(
BlockBreakEvent e, ItemStack item, Block block, @Nullable SlimefunItem sfBlock, List<ItemStack> drops) {
if (!drops.isEmpty()) {
// TODO: properly support loading inventories within unit tests
if (!Slimefun.instance().isUnitTest()) {
// Notify plugins like CoreProtect
Slimefun.getProtectionManager().logAction(e.getPlayer(), e.getBlock(), Interaction.BREAK_BLOCK);
Slimefun.getProtectionManager().logAction(e.getPlayer(), block, Interaction.BREAK_BLOCK);
}

// Fixes #2560
if (e.isDropItems()) {
// Disable normal block drops
e.setDropItems(false);

// Fixes #4051
if (sfBlock == null) {
block.breakNaturally(item);
}

// The list only contains other drops, not those from the block itself, so we still need to handle those
for (ItemStack drop : drops) {
// 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")) {
e.getBlock()
.getWorld()
.dropItemNaturally(e.getBlock().getLocation(), drop);
block.getWorld().dropItemNaturally(block.getLocation(), drop);
}
}
}
Expand Down Expand Up @@ -330,7 +335,7 @@ private void checkForSensitiveBlockAbove(Player player, Block block, ItemStack i
sfItem.callItemHandler(
BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops));
controller.removeBlock(loc);
dropItems(dummyEvent, drops);
dropItems(dummyEvent, item, block, sfItem, drops);
} else {
blockData.setPendingRemove(true);
controller.loadBlockDataAsync(blockData, new IAsyncReadCallback<>() {
Expand All @@ -344,7 +349,7 @@ public void onResult(SlimefunBlockData result) {
sfItem.callItemHandler(
BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops));
controller.removeBlock(loc);
dropItems(dummyEvent, drops);
dropItems(dummyEvent, item, block, sfItem, drops);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ default boolean isUnallowed(@Nullable ItemStack item) {
default boolean isUnallowed(@Nullable SlimefunItem item) {
return item != null && !(item instanceof VanillaItem) && !item.isDisabled();
}

default boolean isCraftingUnallowed(@Nullable ItemStack item) {
if (item == null) {
return false;
}

SlimefunItem sfItem = SlimefunItem.getByItem(item);
return isCraftingUnallowed(sfItem);
}

default boolean isCraftingUnallowed(@Nullable SlimefunItem item) {
return item != null && !item.isUseableInWorkbench();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting;

import city.norain.slimefun4.SlimefunExtended;
import city.norain.slimefun4.compatibillty.VersionedEvent;
import io.github.bakedlibs.dough.versions.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import javax.annotation.Nonnull;
import org.bukkit.block.Crafter;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;

public class VanillaCrafterListener implements SlimefunCraftingListener {
public VanillaCrafterListener(@Nonnull Slimefun plugin) {
if (SlimefunExtended.getMinecraftVersion().isAtLeast(MinecraftVersion.parse("1.20.3")))
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@EventHandler(ignoreCancelled = true)
public void onCrafter(InventoryClickEvent e) {
Inventory clickedInventory = e.getClickedInventory();
Inventory topInventory = VersionedEvent.getTopInventory(e);

if (clickedInventory != null
&& topInventory.getType() == InventoryType.CRAFTER
&& topInventory.getHolder() instanceof Crafter
&& e.getWhoClicked() instanceof Player player) {

if (e.getAction() == InventoryAction.HOTBAR_SWAP) {
e.setCancelled(true);
return;
}

if (clickedInventory.getType() == InventoryType.CRAFTER) {
e.setCancelled(isCraftingUnallowed(SlimefunItem.getByItem(e.getCursor())));
} else {
e.setCancelled(isCraftingUnallowed(SlimefunItem.getByItem(e.getCurrentItem())));
}

if (e.getResult() == Event.Result.DENY) {
Slimefun.getLocalization().sendMessage((Player) e.getWhoClicked(), "crafter.not-working", true);
}
}
}

@EventHandler
public void hopperOnCrafter(InventoryMoveItemEvent e) {
if (e.getDestination().getType() == InventoryType.CRAFTER && isCraftingUnallowed(e.getItem())) {
e.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.utils;

import city.norain.slimefun4.SlimefunExtended;
import io.github.bakedlibs.dough.common.CommonPatterns;
import io.github.bakedlibs.dough.items.ItemMetaSnapshot;
import io.github.bakedlibs.dough.skins.PlayerHead;
Expand Down Expand Up @@ -501,8 +502,20 @@ private static boolean equalsItemMeta(
}
}

if (itemMeta instanceof PotionMeta && sfitemMeta instanceof PotionMeta) {
return ((PotionMeta) itemMeta).getBasePotionType().equals(((PotionMeta) sfitemMeta).getBasePotionType());
if (itemMeta instanceof PotionMeta potionMeta && sfitemMeta instanceof PotionMeta sfPotionMeta) {
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_20_5)) {
if (!potionMeta.hasBasePotionType() && !sfPotionMeta.hasBasePotionType()) {
return true;
}

return potionMeta.hasBasePotionType()
&& sfPotionMeta.hasBasePotionType()
&& potionMeta.getBasePotionType().equals(sfPotionMeta.getBasePotionType());
} else if (SlimefunExtended.getMinecraftVersion().isAtLeast(1, 20, 2)) {
return potionMeta.getBasePotionType().equals(sfPotionMeta.getBasePotionType());
} else {
return potionMeta.getBasePotionData().equals(sfPotionMeta.getBasePotionData());
}
}

Debug.log(TestCase.CARGO_INPUT_TESTING, " All meta checked.");
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/languages/en/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ workbench:
cauldron:
no-discoloring: '&4You cannot discolor Slimefun Armor'

crafter:
not-working: '&4You cannot use a Slimefun item in crafter!'

gps:
deathpoint: '&4Deathpoint &7%date%'
status-online: 'ONLINE'
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/languages/zh-CN/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ workbench:
not-enhanced: '&4你不能在普通的工作台上使用 Slimefun 物品'
cauldron:
no-discoloring: '&4你不能用炼药锅洗去 Slimefun 物品的颜色'
crafter:
not-working: '&4你不能在合成机上用 Slimefun 物品合成'
gps:
deathpoint: '&4死亡点 &7%date%'
status-online: '在线'
Expand Down

0 comments on commit dc72b4b

Please sign in to comment.