13
0
geforkt von Mirrors/Paper

Add Critical missing Bukkit API - setTarget/getTarget moved down to SentientNPC

This fixes a CRITICAL missing part of the Bukkit API due to mistakes on upstream
refusing to implement the Sentient NPC baseclass of all NPC's.

Until now, the Bukkit API has not provided a way for accessing and setting
a non creature entities target.

Although Flying, Slime, Ambient, and Water mobs all supported targets internally,
you were unable to get/set it.

Now with the SentientNPC API and these API's moved down, every sentient NPC has
access to target data.
Dieser Commit ist enthalten in:
Aikar 2018-07-01 22:07:35 -04:00
Ursprung 2d646ba400
Commit 14ccb8ebeb
2 geänderte Dateien mit 217 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -14,7 +14,7 @@ This interface lets you identify NPC entities capable of sentience, and able to
diff --git a/src/main/java/com/destroystokyo/paper/entity/SentientNPC.java b/src/main/java/com/destroystokyo/paper/entity/SentientNPC.java
new file mode 100644
index 00000000..231e8af1
index 00000000..7e393254
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/SentientNPC.java
@@ -0,0 +0,0 @@
@ -56,6 +56,24 @@ index 00000000..231e8af1
+ * This interface lets you identify NPC entities capable of sentience, and able to move about and react to the world.
+ */
+public interface SentientNPC extends LivingEntity {
+
+ /**
+ * Instructs this Creature to set the specified LivingEntity as its
+ * target.
+ * <p>
+ * Hostile creatures may attack their target, and friendly creatures may
+ * follow their target.
+ *
+ * @param target New LivingEntity to target, or null to clear the target
+ */
+ public void setTarget(LivingEntity target);
+
+ /**
+ * Gets the current target of this Creature
+ *
+ * @return Current target of this creature, or null if none exists
+ */
+ public LivingEntity getTarget();
+}
diff --git a/src/main/java/org/bukkit/entity/Ambient.java b/src/main/java/org/bukkit/entity/Ambient.java
index 779e3897..ef548fb4 100644
@ -82,7 +100,7 @@ index f74411c3..1f00923e 100644
* Gets a list of parts that belong to this complex entity
*
diff --git a/src/main/java/org/bukkit/entity/Creature.java b/src/main/java/org/bukkit/entity/Creature.java
index f223f55b..77cbefcb 100644
index f223f55b..bbfb248e 100644
--- a/src/main/java/org/bukkit/entity/Creature.java
+++ b/src/main/java/org/bukkit/entity/Creature.java
@@ -0,0 +0,0 @@ package org.bukkit.entity;
@ -94,6 +112,21 @@ index f223f55b..77cbefcb 100644
/**
* Instructs this Creature to set the specified LivingEntity as its
@@ -0,0 +0,0 @@ public interface Creature extends LivingEntity {
*
* @param target New LivingEntity to target, or null to clear the target
*/
- public void setTarget(LivingEntity target);
+ //public void setTarget(LivingEntity target); // Paper - moved to SentientNPC
/**
* Gets the current target of this Creature
*
* @return Current target of this creature, or null if none exists
*/
- public LivingEntity getTarget();
+ //public LivingEntity getTarget(); // Paper - moved to SentientNPC
}
diff --git a/src/main/java/org/bukkit/entity/Flying.java b/src/main/java/org/bukkit/entity/Flying.java
index 4f16a26c..207e9922 100644
--- a/src/main/java/org/bukkit/entity/Flying.java

Datei anzeigen

@ -0,0 +1,182 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 1 Jul 2018 22:06:29 -0400
Subject: [PATCH] Add SentientNPC Interface to Entities
Used to determine ACTUAL Living NPC's. Spigot mistakenly inversed the conditions for LivingEntity, and
used LivingEntity for Insentient Entities, and named the actual EntityLiving class EntityInsentient.
This should of all been inversed on the implementation side. To make matters worse, Spigot never
exposed the differentiator that there are entities with AI that are not sentient/alive such as
Armor stands and Players are the only things that do not implement the REAL EntityLiving class (named Insentient internally)
This interface lets you identify NPC entities capable of sentience, and able to move about and react to the world.
diff --git a/src/main/java/com/destroystokyo/paper/entity/CraftSentientNPC.java b/src/main/java/com/destroystokyo/paper/entity/CraftSentientNPC.java
new file mode 100644
index 000000000..a60ba1349
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/CraftSentientNPC.java
@@ -0,0 +0,0 @@
+package com.destroystokyo.paper.entity;
+
+import net.minecraft.server.EntityInsentient;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.LivingEntity;
+
+public interface CraftSentientNPC <T extends EntityInsentient> extends SentientNPC {
+ T getHandle();
+
+ default public void setTarget(LivingEntity target) {
+ T entity = getHandle();
+ if (target == null) {
+ entity.setGoalTarget(null, null, false);
+ } else if (target instanceof CraftLivingEntity) {
+ entity.setGoalTarget(((CraftLivingEntity) target).getHandle(), null, false);
+ }
+ }
+
+ default public LivingEntity getTarget() {
+ if (getHandle().getGoalTarget() == null) return null;
+
+ return (CraftLivingEntity) getHandle().getGoalTarget().getBukkitEntity();
+ }
+
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java
index 086980e76..ccce080ab 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java
@@ -0,0 +0,0 @@
package org.bukkit.craftbukkit.entity;
+import com.destroystokyo.paper.entity.CraftSentientNPC;
import net.minecraft.server.EntityAmbient;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.EntityType;
-public class CraftAmbient extends CraftLivingEntity implements Ambient {
+public class CraftAmbient extends CraftLivingEntity implements Ambient, CraftSentientNPC { // Paper
public CraftAmbient(CraftServer server, EntityAmbient entity) {
super(server, entity);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexLivingEntity.java
index cc115cc36..3a4e6f0c7 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexLivingEntity.java
@@ -0,0 +0,0 @@
package org.bukkit.craftbukkit.entity;
+import com.destroystokyo.paper.entity.CraftSentientNPC;
+import net.minecraft.server.EntityInsentient;
import net.minecraft.server.EntityLiving;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.ComplexLivingEntity;
-public abstract class CraftComplexLivingEntity extends CraftLivingEntity implements ComplexLivingEntity {
+public abstract class CraftComplexLivingEntity extends CraftLivingEntity implements ComplexLivingEntity, CraftSentientNPC { // Paper
public CraftComplexLivingEntity(CraftServer server, EntityLiving entity) {
super(server, entity);
}
@Override
- public EntityLiving getHandle() {
- return (EntityLiving) entity;
+ public EntityInsentient getHandle() { // Paper
+ return (EntityInsentient) entity; // Paper
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java
index 09d42141f..30004e5e8 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java
@@ -0,0 +0,0 @@
package org.bukkit.craftbukkit.entity;
+import com.destroystokyo.paper.entity.CraftSentientNPC;
import net.minecraft.server.EntityCreature;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Creature;
import org.bukkit.entity.LivingEntity;
-public class CraftCreature extends CraftLivingEntity implements Creature {
+public class CraftCreature extends CraftLivingEntity implements Creature, CraftSentientNPC { // Paper
public CraftCreature(CraftServer server, EntityCreature entity) {
super(server, entity);
}
- public void setTarget(LivingEntity target) {
+ // Paper start - move down to SentientNPC
+ /*public void setTarget(LivingEntity target) {
EntityCreature entity = getHandle();
if (target == null) {
entity.setGoalTarget(null, null, false);
@@ -0,0 +0,0 @@ public class CraftCreature extends CraftLivingEntity implements Creature {
if (getHandle().getGoalTarget() == null) return null;
return (CraftLivingEntity) getHandle().getGoalTarget().getBukkitEntity();
- }
+ }*/
+ // Paper end
@Override
public EntityCreature getHandle() {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java
index f374c7b88..9e6f523bf 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java
@@ -0,0 +0,0 @@
package org.bukkit.craftbukkit.entity;
+import com.destroystokyo.paper.entity.CraftSentientNPC;
import net.minecraft.server.EntityFlying;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Flying;
-public class CraftFlying extends CraftLivingEntity implements Flying {
+public class CraftFlying extends CraftLivingEntity implements Flying, CraftSentientNPC { // Paper
public CraftFlying(CraftServer server, EntityFlying entity) {
super(server, entity);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
index 6bf30c834..3768b9573 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
@@ -0,0 +0,0 @@
package org.bukkit.craftbukkit.entity;
+import com.destroystokyo.paper.entity.CraftSentientNPC;
import net.minecraft.server.EntitySlime;
import org.bukkit.craftbukkit.CraftServer;
@@ -0,0 +0,0 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Slime;
-public class CraftSlime extends CraftLivingEntity implements Slime {
+public class CraftSlime extends CraftLivingEntity implements Slime, CraftSentientNPC { // Paper
public CraftSlime(CraftServer server, EntitySlime entity) {
super(server, entity);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftWaterMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftWaterMob.java
index ee21d7b6e..f67dff38f 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftWaterMob.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftWaterMob.java
@@ -0,0 +0,0 @@
package org.bukkit.craftbukkit.entity;
+import com.destroystokyo.paper.entity.CraftSentientNPC;
import net.minecraft.server.EntityWaterAnimal;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.WaterMob;
-public class CraftWaterMob extends CraftLivingEntity implements WaterMob {
+public class CraftWaterMob extends CraftLivingEntity implements WaterMob, CraftSentientNPC { // Paper
public CraftWaterMob(CraftServer server, EntityWaterAnimal entity) {
super(server, entity);
--