Skip to content

Commit

Permalink
Merge pull request #1 from CraftDream/main
Browse files Browse the repository at this point in the history
1
  • Loading branch information
YuanYuanOwO committed Jul 13, 2024
2 parents 16b9ce9 + c13d346 commit 86ede40
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

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: Build with Maven
run: mvn package

- name: Archive Artifacts
uses: actions/upload-artifact@v3
with:
name: target
path: target
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -44,9 +45,11 @@ public void onDisable() {

@EventHandler(ignoreCancelled = true)
public void onShopkeeperOpening(ShopkeeperOpenUIEvent event) {
System.out.println("[DEBUG] TEST1");
if (!DefaultUITypes.TRADING().equals(event.getUIType())) {
return;
}
System.out.println("[DEBUG] TEST2");
Shopkeeper shopkeeper = event.getShopkeeper();
Player player = event.getPlayer();

Expand All @@ -63,9 +66,11 @@ public void onShopkeeperOpening(ShopkeeperOpenUIEvent event) {
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onVillagerUI(PlayerInteractEntityEvent event){
System.out.println("[DEBUG] TEST3");
if(!(event.getRightClicked() instanceof Villager villager)){
return;
}
System.out.println("[DEBUG] TEST4");
Set<ItemStack> shopItems = new LinkedHashSet<>(); // 等待检查列表
for (MerchantRecipe recipe : villager.getRecipes()) {
shopItems.add(recipe.getResult());
Expand All @@ -78,14 +83,17 @@ public void onVillagerUI(PlayerInteractEntityEvent event){
}

private void updateShopItems(Set<ItemStack> adaptList, Player player, String name) {

System.out.println("[DEBUG] TEST5");
boolean anyUpdate = false;
int i = 0;
for (ItemStack storageContent : player.getInventory().getStorageContents()) {
if (storageContent == null) continue;
for (ItemStack shopItem : adaptList) {
System.out.println("[DEBUG] TEST6");
if (isStandardSimilar(storageContent, shopItem)) { // 标准检查下相同的话
System.out.println("[DEBUG] TEST7");
if (!storageContent.isSimilar(shopItem)) { // 但非标准检查并不相同
System.out.println("[DEBUG] TEST8");
// 同步玩家背包中的物品的 NBT 数据和商店的保持同步
anyUpdate = true;
storageContent.setItemMeta(shopItem.getItemMeta());
Expand Down Expand Up @@ -115,11 +123,35 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}

private boolean isStandardSimilar(ItemStack stack1, ItemStack stack2) {
stack1 = stack1.clone();
stack2 = stack2.clone();
stack1.setAmount(1);
stack2.setAmount(1);
return standardItemStack(stack1).isSimilar(standardItemStack(stack2));
ItemMeta meta1 = stack1.getItemMeta();
ItemMeta meta2 = stack2.getItemMeta();
if (meta1.hasDisplayName() != meta2.hasDisplayName()) {
return false;
}
if (meta1.hasLore() != meta2.hasLore()) {
return false;
}
if (meta1.hasDisplayName() && meta2.hasDisplayName()) {
if (!meta1.getDisplayName().equals(meta2.getDisplayName())) {
return false;
}
System.out.println("[DEBUG] TEST9 " + meta1.getDisplayName() + " AND " + meta2.getDisplayName());
}
List<String> lore1 = meta1.getLore();
List<String> lore2 = meta2.getLore();
if (lore1 != null && lore2 != null) {
lore1.replaceAll(ChatColor::stripColor);
lore2.replaceAll(ChatColor::stripColor);
System.out.println("[DEBUG] TEST10 " + lore1 + " AND " + lore2);
if (!lore1.equals(lore2)) {
return false;
}
System.out.println("[DEBUG] TEST11");
}
if (!meta1.getItemFlags().equals(meta2.getItemFlags())) {
return false;
}
return true;
}

private ItemStack standardItemStack(ItemStack original) {
Expand Down

0 comments on commit 86ede40

Please sign in to comment.