Skip to content

Commit

Permalink
feat: 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolLoong committed Mar 2, 2024
1 parent 40a65a3 commit 49f156a
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 39 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
83 changes: 60 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,83 @@

<groupId>me.petterim1.itemblacklist</groupId>
<artifactId>ItemBlacklist</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://www.jitpack.io</url>
</repository>
<repository>
<id>opencollab-repository-maven-releases</id>
<name>Opencollab Repository releases</name>
<url>https://repo.opencollab.dev/maven-releases</url>
</repository>
<repository>
<id>opencollab-repository-maven-snapshots</id>
<name>Opencollab Repository snapshots</name>
<url>https://repo.opencollab.dev/maven-snapshots</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.github.PowerNukkitX</groupId>
<artifactId>PowerNukkitX</artifactId>
<version>master-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${maven.compiler.encoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>*</include>
<include>plugin.yml</include>
</includes>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>nukkitx</id>
<url>https://repo.nukkitx.com/main/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>cn.nukkit</groupId>
<artifactId>nukkit</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/data.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# stop the server before editing this or use 'blacklist <add|remove|list> <id:meta>' to edit blacklisted items
# - "id:meta" (use '*' for all meta values)
blacklist:
- "666:0"
- "999:0"
- "888:*"
- "minecraft:double_cut_copper_slab:0"
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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/
Expand Down

0 comments on commit 49f156a

Please sign in to comment.