From 36ba2432fcb3ab863ecb894d8fd8c7f327d19064 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Sun, 22 Dec 2024 13:44:37 +0800 Subject: [PATCH 1/2] refactor(android): use cache when update kv --- .../slimefun4/implementation/items/androids/Instruction.java | 5 +++-- .../implementation/items/androids/ProgrammableAndroid.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java index 675f8a0a7b..df47caf0e1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java @@ -1,6 +1,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.androids; import city.norain.slimefun4.api.menu.UniversalMenu; +import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import java.util.HashMap; @@ -74,7 +75,7 @@ public enum Instruction { */ TURN_LEFT(AndroidType.NONE, HeadTexture.SCRIPT_LEFT, (android, b, inv, face) -> { int mod = -1; - android.rotate(b, face, mod); + android.rotate(b, StorageCacheUtils.getUniversalBlock(inv.getUuid()), face, mod); }), /** @@ -82,7 +83,7 @@ public enum Instruction { */ TURN_RIGHT(AndroidType.NONE, HeadTexture.SCRIPT_RIGHT, (android, b, inv, face) -> { int mod = 1; - android.rotate(b, face, mod); + android.rotate(b, StorageCacheUtils.getUniversalBlock(inv.getUuid()), face, mod); }), /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java index bc481dbf39..a4dc6e3147 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java @@ -861,7 +861,7 @@ private void executeInstruction( } } - protected void rotate(Block b, BlockFace current, int mod) { + protected void rotate(Block b, SlimefunUniversalBlockData uniData, BlockFace current, int mod) { int index = POSSIBLE_ROTATIONS.indexOf(current) + mod; if (index == POSSIBLE_ROTATIONS.size()) { @@ -878,7 +878,7 @@ protected void rotate(Block b, BlockFace current, int mod) { } })); - StorageCacheUtils.setData(b.getLocation(), "rotation", rotation.name()); + uniData.setData("rotation", rotation.name()); } protected void depositItems(UniversalMenu menu, Block facedBlock) { From 74e6bc1fd842d9f5f8b23484e158f45deb00d2d6 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Sun, 22 Dec 2024 14:18:38 +0800 Subject: [PATCH 2/2] fix(backpack): pick from Slimefun4#4275 --- .../listeners/BackpackListener.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java index 77bbd088ee..a3990523f7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java @@ -26,6 +26,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.inventory.ItemStack; /** @@ -89,6 +90,24 @@ public void onItemDrop(PlayerDropItemEvent e) { } } + @EventHandler + public void onPlayerSwap(PlayerSwapHandItemsEvent e) { + var player = e.getPlayer(); + if (!backpacks.containsKey(player.getUniqueId())) { + return; + } + + ItemStack item = player.getInventory().getItemInOffHand(); + if (item == null || item.getType().isAir()) { + return; + } + + SlimefunItem backpack = SlimefunItem.getByItem(item); + if (backpack instanceof SlimefunBackpack) { + e.setCancelled(true); + } + } + @EventHandler(ignoreCancelled = true) public void onClick(InventoryClickEvent e) { ItemStack item = backpacks.get(e.getWhoClicked().getUniqueId());