diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..89dcb78 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,49 @@ +name: Build + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + permissions: write-all + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Cache local Maven repository + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Read Project Info + id: "info" + uses: YunaBraska/java-info-action@main + + # CONFIGS (Optional) + with: + deep: '-1' + work-dir: '.' + jv-fallback: 17 + pv-fallback: '1.0.0' + pe-fallback: 'utf-8' + custom-gradle-cmd: "clean build" + custom-maven-cmd: "clean package" + - name: Build with Maven + run: mvn clean -B package --file pom.xml + - name: Upload artifact + uses: actions/upload-artifact@v3 + if: success() + with: + name: ${{ steps.info.outputs.x_project_artifactId }} + path: target/${{ steps.info.outputs.x_project_artifactId }}-${{ steps.info.outputs.project_version }}.jar \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5c9671c..29b614c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,46 +6,83 @@ me.petterim1.itemblacklist ItemBlacklist - 1.2.0 + 1.3.0 + + UTF-8 + UTF-8 + UTF-8 + 17 + 17 + + + + + central + https://repo.maven.apache.org/maven2/ + + + jitpack.io + https://www.jitpack.io + + + opencollab-repository-maven-releases + Opencollab Repository releases + https://repo.opencollab.dev/maven-releases + + + opencollab-repository-maven-snapshots + Opencollab Repository snapshots + https://repo.opencollab.dev/maven-snapshots + + + + + + com.github.PowerNukkitX + PowerNukkitX + master-SNAPSHOT + provided + + ${basedir}/src/main/java org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.10.0 - 1.8 - 1.8 + ${maven.compiler.source} + ${maven.compiler.target} + ${maven.compiler.encoding} + + org.apache.maven.plugins + maven-shade-plugin + 3.5.1 + + + + + + package + + shade + + + + . true - ${basedir}/src/main/resources/ + ${basedir}/src/main/resources - * + plugin.yml - - - nukkitx - https://repo.nukkitx.com/main/ - - - - - cn.nukkit - nukkit - 1.0-SNAPSHOT - provided - - - - UTF-8 - diff --git a/src/main/java/me/petterim1/itemblacklist/BlockInventoryTransactions.java b/src/main/java/me/petterim1/itemblacklist/BlockInventoryTransactions.java index ff76604..77694cc 100644 --- a/src/main/java/me/petterim1/itemblacklist/BlockInventoryTransactions.java +++ b/src/main/java/me/petterim1/itemblacklist/BlockInventoryTransactions.java @@ -2,23 +2,44 @@ import cn.nukkit.event.EventHandler; import cn.nukkit.event.Listener; -import cn.nukkit.event.inventory.InventoryTransactionEvent; -import cn.nukkit.inventory.transaction.action.InventoryAction; -import cn.nukkit.item.Item; +import cn.nukkit.event.inventory.ItemStackRequestActionEvent; +import cn.nukkit.inventory.Inventory; +import cn.nukkit.inventory.request.NetworkMapping; +import cn.nukkit.network.protocol.types.itemstack.ContainerSlotType; +import cn.nukkit.network.protocol.types.itemstack.request.ItemStackRequestSlotData; +import cn.nukkit.network.protocol.types.itemstack.request.action.ItemStackRequestAction; +import cn.nukkit.network.protocol.types.itemstack.request.action.SwapAction; +import cn.nukkit.network.protocol.types.itemstack.request.action.TransferItemStackRequestAction; public class BlockInventoryTransactions implements Listener { @EventHandler - public void onInventoryTransaction(InventoryTransactionEvent e) { - for (InventoryAction action : e.getTransaction().getActionList()) { - Item source = action.getSourceItem(); - String s = source != null ? (source.getId() + ":" + source.getDamage()) : ""; - String s_ = source != null ? (source.getId() + ":*") : ""; - Item target = action.getTargetItem(); - String t = target != null ? (target.getId() + ":" + target.getDamage()) : ""; - String t_ = target != null ? (target.getId() + ":*") : ""; + public void onInventoryTransaction(ItemStackRequestActionEvent event) { + ItemStackRequestAction action = event.getAction(); + ItemStackRequestSlotData source = null; + ItemStackRequestSlotData destination = null; + if (action instanceof TransferItemStackRequestAction transferItemStackRequestAction) { + source = transferItemStackRequestAction.getSource(); + destination = transferItemStackRequestAction.getDestination(); + } else if (action instanceof SwapAction swapAction) { + source = swapAction.getSource(); + destination = swapAction.getDestination(); + } + if (source != null && destination != null) { + ContainerSlotType sourceSlotType = source.getContainer(); + ContainerSlotType destinationSlotType = destination.getContainer(); + Inventory sourceI = NetworkMapping.getInventory(event.getPlayer(), sourceSlotType); + Inventory destinationI = NetworkMapping.getInventory(event.getPlayer(), destinationSlotType); + int sourceSlot = sourceI.fromNetworkSlot(source.getSlot()); + int destinationSlot = destinationI.fromNetworkSlot(destination.getSlot()); + var sourItem = sourceI.getItem(sourceSlot); + var destItem = destinationI.getItem(destinationSlot); + String s = sourItem != null ? (sourItem.getId() + ":" + sourItem.getDamage()) : ""; + String s_ = sourItem != null ? (sourItem.getId() + ":*") : ""; + String t = destItem != null ? (destItem.getId() + ":" + destItem.getDamage()) : ""; + String t_ = destItem != null ? (destItem.getId() + ":*") : ""; if (Plugin.blacklist.contains(s) || Plugin.blacklist.contains(s_) || Plugin.blacklist.contains(t) || Plugin.blacklist.contains(t_)) { - e.setCancelled(true); + event.setCancelled(true); } } } diff --git a/src/main/resources/data.yml b/src/main/resources/data.yml index 28829e4..0dbf535 100644 --- a/src/main/resources/data.yml +++ b/src/main/resources/data.yml @@ -1,6 +1,4 @@ # stop the server before editing this or use 'blacklist ' to edit blacklisted items # - "id:meta" (use '*' for all meta values) blacklist: - - "666:0" - - "999:0" - - "888:*" + - "minecraft:double_cut_copper_slab:0" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3767f1c..c370bc7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: ItemBlacklist main: me.petterim1.itemblacklist.Plugin version: "${pom.version}" -api: ["1.0.0"] +api: [ "2.0.0" ] author: PetteriM1 description: "Advanced item blacklist plugin for Nukkit" website: https://cloudburstmc.org/resources/itemblacklist.533/