From 9c24eb91b3536c4b3a90782d272bde625b8d45f5 Mon Sep 17 00:00:00 2001
From: LT_Name <572413378@qq.com>
Date: Thu, 26 Dec 2024 10:34:24 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BE=9D=E8=B5=96=E6=94=B9=E4=B8=BAnkmot?=
=?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=89=93=E5=BC=80=E5=AF=B9=E8=AF=9D?=
=?UTF-8?q?=E6=A1=86=E6=92=AD=E6=94=BE=E5=A3=B0=E9=9F=B3=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 10 +--
.../java/com/smallaswater/npc/OnListener.java | 3 +-
src/main/java/com/smallaswater/npc/RsNPC.java | 19 ++++-
.../smallaswater/npc/data/RsNpcConfig.java | 24 ++++--
.../smallaswater/npc/dialog/DialogPages.java | 37 +++++++--
.../smallaswater/npc/entitys/EntityRsNPC.java | 6 ++
.../npc/entitys/EntityRsNPCCustomEntity.java | 78 ++++++++++---------
.../npc/utils/GameCoreDownload.java | 2 +-
.../com/smallaswater/npc/utils/Utils.java | 8 ++
src/main/resources/Dialog/demo.yml | 3 +
.../Language/chs/DialogConfigDescription.yml | 7 +-
.../Language/eng/DialogConfigDescription.yml | 7 +-
src/main/resources/plugin.yml | 6 +-
13 files changed, 141 insertions(+), 69 deletions(-)
diff --git a/pom.xml b/pom.xml
index 33f51a5..b3fc116 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,9 +41,9 @@
UTF-8
UTF-8
UTF-8
- 1.8
- 1.8
- 1.6.11
+ 17
+ 17
+ 1.6.11-PM1E
@@ -87,8 +87,8 @@
cn.nukkit
- nukkit
- 1.0-SNAPSHOT
+ Nukkit
+ MOT-SNAPSHOT
provided
diff --git a/src/main/java/com/smallaswater/npc/OnListener.java b/src/main/java/com/smallaswater/npc/OnListener.java
index 9c99064..b870315 100644
--- a/src/main/java/com/smallaswater/npc/OnListener.java
+++ b/src/main/java/com/smallaswater/npc/OnListener.java
@@ -32,8 +32,7 @@ public OnListener(RsNPC rsNPC) {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityVehicleEnter(EntityVehicleEnterEvent event) {
- if (event.getEntity() instanceof EntityRsNPC ||
- event.getVehicle() instanceof EntityRsNPC) {
+ if (event.getEntity() instanceof EntityRsNPC) {
event.setCancelled(true);
}
}
diff --git a/src/main/java/com/smallaswater/npc/RsNPC.java b/src/main/java/com/smallaswater/npc/RsNPC.java
index 6ed46a9..ada29ca 100644
--- a/src/main/java/com/smallaswater/npc/RsNPC.java
+++ b/src/main/java/com/smallaswater/npc/RsNPC.java
@@ -118,7 +118,7 @@ public void onEnable() {
try {
if (Server.getInstance().getPluginManager().getPlugin("AutoUpData") != null) {
- if (AutoData.defaultUpDataByMaven(this, this.getFile(), "com.smallaswater", "RsNPC", null)) {
+ if (AutoData.defaultUpDataByMaven(this, this.getFile(), "com.smallaswater", "RsNPC", "")) {
return;
}
}
@@ -130,9 +130,9 @@ public void onEnable() {
//检查插件分支是否和核心匹配
NukkitTypeUtils.NukkitType nukkitType = NukkitTypeUtils.getNukkitType();
- if (nukkitType != NukkitTypeUtils.NukkitType.NUKKITX && nukkitType != NukkitTypeUtils.NukkitType.POWER_NUKKIT) {
+ if (nukkitType != NukkitTypeUtils.NukkitType.PM1E && nukkitType != NukkitTypeUtils.NukkitType.MOT) {
this.getLogger().error(this.getLanguage().translateString("plugin.load.pluginBranchError", nukkitType.getShowName(), this.getVersion()));
- this.getServer().getPluginManager().disablePlugin(this);
+ //this.getServer().getPluginManager().disablePlugin(this);
return;
}
@@ -347,7 +347,18 @@ private void loadSkins() {
skin.setTrusted(true);
- if (skin.isValid()) {
+ boolean skinIsValid = false;
+ try {
+ skinIsValid = (boolean) Skin.class.getMethod("isValid", boolean.class).invoke(skin, this.getServer().doNotLimitSkinGeometry);
+ } catch (Exception exception) {
+ try {
+ skinIsValid = (boolean) Skin.class.getMethod("isValid").invoke(skin);
+ } catch (Exception e) {
+ this.getLogger().error("Skin validation failed!", e);
+ }
+ }
+
+ if (skinIsValid) {
this.skins.put(skinName, skin);
this.getLogger().info(this.getLanguage().translateString("plugin.load.skin.loadSucceed", skinName));
} else {
diff --git a/src/main/java/com/smallaswater/npc/data/RsNpcConfig.java b/src/main/java/com/smallaswater/npc/data/RsNpcConfig.java
index 2badba3..1e2b3db 100644
--- a/src/main/java/com/smallaswater/npc/data/RsNpcConfig.java
+++ b/src/main/java/com/smallaswater/npc/data/RsNpcConfig.java
@@ -1,9 +1,10 @@
package com.smallaswater.npc.data;
import cn.lanink.gamecore.utils.ConfigUtils;
-import cn.lanink.gamecore.utils.CustomEntityUtils;
import cn.nukkit.Server;
import cn.nukkit.entity.Entity;
+import cn.nukkit.entity.custom.EntityDefinition;
+import cn.nukkit.entity.custom.EntityManager;
import cn.nukkit.entity.data.Skin;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
@@ -97,7 +98,7 @@ public class RsNpcConfig {
// 自定义实体
private boolean enableCustomEntity;
- private String customEntityIdentifier;
+ private EntityDefinition customEntityDefinition;
private int customEntitySkinId;
//自定义碰撞大小
@@ -269,10 +270,17 @@ public RsNpcConfig(@NonNull String name, @NonNull Config config) throws RsNpcCon
try {
this.enableCustomEntity = this.config.getBoolean("CustomEntity.enable", false);
- this.customEntityIdentifier = this.config.getString("CustomEntity.identifier", "RsNPC:Demo");
+ String identifier = this.config.getString("CustomEntity.identifier", "RsNPC:Demo");
this.customEntitySkinId = this.config.getInt("CustomEntity.skinId", 0);
- if (this.enableCustomEntity && CustomEntityUtils.getRuntimeId(this.customEntityIdentifier) == -1) {
- CustomEntityUtils.registerCustomEntity(this.customEntityIdentifier);
+ if (this.enableCustomEntity) {
+ this.customEntityDefinition = EntityManager.get().getDefinition(identifier);
+ if (this.customEntityDefinition == null) { //不存在时注册新的
+ this.customEntityDefinition = EntityDefinition.builder()
+ .identifier(identifier)
+ .spawnEgg(false)
+ .implementation(EntityRsNPCCustomEntity.class).build();
+ EntityManager.get().registerDefinition(this.customEntityDefinition);
+ }
}
}catch (Exception e) {
throw new RsNpcConfigLoadException("NPC配置 自定义实体配置加载失败!请检查配置文件!", e);
@@ -344,7 +352,7 @@ public void save() {
this.config.set("对话框.页面", this.dialogPagesName);
this.config.set("CustomEntity.enable", this.enableCustomEntity);
- this.config.set("CustomEntity.identifier", this.customEntityIdentifier);
+ this.config.set("CustomEntity.identifier", this.customEntityDefinition == null ? "RsNPC:Demo" : this.customEntityDefinition.getIdentifier());
this.config.set("CustomEntity.skinId", this.customEntitySkinId);
this.config.set("CustomCollisionSize.enable", this.enableCustomCollisionSize);
@@ -370,11 +378,11 @@ public void checkEntity() {
.putCompound("Skin", (new CompoundTag())
.putByteArray("Data", this.skin.getSkinData().data)
.putString("ModelId", this.skin.getSkinId()));
- if (this.enableCustomEntity && this.customEntityIdentifier != null) {
+ if (this.enableCustomEntity && this.customEntityDefinition != null) {
nbt.putInt("skinId", this.customEntitySkinId);
this.entityRsNpc = new EntityRsNPCCustomEntity(this.location.getChunk(), nbt, this);
EntityRsNPCCustomEntity entityRsNPC = (EntityRsNPCCustomEntity) this.entityRsNpc;
- entityRsNPC.setIdentifier(this.customEntityIdentifier);
+ entityRsNPC.setDefinition(this.customEntityDefinition);
}else {
this.entityRsNpc = new EntityRsNPC(this.location.getChunk(), nbt, this);
this.entityRsNpc.setSkin(this.getSkin());
diff --git a/src/main/java/com/smallaswater/npc/dialog/DialogPages.java b/src/main/java/com/smallaswater/npc/dialog/DialogPages.java
index 8b9c193..f7286b0 100644
--- a/src/main/java/com/smallaswater/npc/dialog/DialogPages.java
+++ b/src/main/java/com/smallaswater/npc/dialog/DialogPages.java
@@ -4,6 +4,7 @@
import cn.lanink.gamecore.utils.packet.ProtocolVersion;
import cn.nukkit.Player;
import cn.nukkit.Server;
+import cn.nukkit.network.protocol.PlaySoundPacket;
import cn.nukkit.network.protocol.ProtocolInfo;
import cn.nukkit.utils.Config;
import com.smallaswater.npc.RsNPC;
@@ -61,6 +62,7 @@ public static class DialogPage {
private final String key;
private final String title;
private final String content;
+ private final Sound sound;
private final ArrayList