SPIGOT-1571: Add Entity Glide Events.

This commit is contained in:
0x277F 2016-03-12 20:57:32 +11:00 committed by md_5
parent d0e326a071
commit 1386bd3ddf
5 changed files with 110 additions and 53 deletions

View File

@ -1,12 +1,13 @@
--- a/net/minecraft/server/EntityHuman.java
+++ b/net/minecraft/server/EntityHuman.java
@@ -9,6 +9,18 @@
@@ -9,6 +9,19 @@
import java.util.List;
import java.util.UUID;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.entity.CraftItem;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.player.PlayerBedEnterEvent;
@ -19,7 +20,7 @@
public abstract class EntityHuman extends EntityLiving {
private static final DataWatcherObject<Float> a = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.c);
@@ -19,7 +31,7 @@
@@ -19,7 +32,7 @@
private InventoryEnderChest enderChest = new InventoryEnderChest();
public Container defaultContainer;
public Container activeContainer;
@ -28,7 +29,7 @@
protected int bv;
public float bw;
public float bx;
@@ -52,6 +64,17 @@
@@ -52,6 +65,17 @@
private final ItemCooldown bU = this.l();
public EntityFishingHook hookedFish;
@ -46,7 +47,7 @@
protected ItemCooldown l() {
return new ItemCooldown();
}
@@ -301,7 +324,8 @@
@@ -301,7 +325,8 @@
if (this.world.getDifficulty() == EnumDifficulty.PEACEFUL && this.world.getGameRules().getBoolean("naturalRegeneration")) {
if (this.getHealth() < this.getMaxHealth() && this.ticksLived % 20 == 0) {
@ -56,7 +57,7 @@
}
if (this.foodData.c() && this.ticksLived % 10 == 0) {
@@ -325,7 +349,7 @@
@@ -325,7 +350,7 @@
this.l((float) attributeinstance.getValue());
float f = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
@ -65,7 +66,7 @@
if (f > 0.1F) {
f = 0.1F;
@@ -416,28 +440,35 @@
@@ -416,28 +441,35 @@
public void b(Entity entity, int i) {
if (entity != this) {
this.addScore(i);
@ -108,7 +109,7 @@
private Collection<ScoreboardObjective> d(Entity entity) {
String s = entity instanceof EntityHuman ? entity.getName() : entity.getUniqueID().toString();
ScoreboardTeam scoreboardteam = this.getScoreboard().getPlayerTeam(this.getName());
@@ -471,6 +502,7 @@
@@ -471,6 +503,7 @@
}
public EntityItem a(boolean flag) {
@ -116,7 +117,7 @@
return this.a(this.inventory.splitStack(this.inventory.itemInHandIndex, flag && this.inventory.getItemInHand() != null ? this.inventory.getItemInHand().count : 1), false, true);
}
@@ -513,6 +545,30 @@
@@ -513,6 +546,30 @@
entityitem.motZ += Math.sin((double) f1) * (double) f;
}
@ -147,7 +148,7 @@
ItemStack itemstack1 = this.a(entityitem);
if (flag1) {
@@ -612,6 +668,13 @@
@@ -612,6 +669,13 @@
this.a(true, true, false);
}
@ -161,7 +162,7 @@
if (nbttagcompound.hasKeyOfType("SpawnX", 99) && nbttagcompound.hasKeyOfType("SpawnY", 99) && nbttagcompound.hasKeyOfType("SpawnZ", 99)) {
this.e = new BlockPosition(nbttagcompound.getInt("SpawnX"), nbttagcompound.getInt("SpawnY"), nbttagcompound.getInt("SpawnZ"));
this.f = nbttagcompound.getBoolean("SpawnForced");
@@ -649,6 +712,12 @@
@@ -649,6 +713,12 @@
this.foodData.b(nbttagcompound);
this.abilities.a(nbttagcompound);
nbttagcompound.set("EnderItems", this.enderChest.h());
@ -174,7 +175,7 @@
}
public boolean damageEntity(DamageSource damagesource, float f) {
@@ -667,7 +736,7 @@
@@ -667,7 +737,7 @@
if (damagesource.r()) {
if (this.world.getDifficulty() == EnumDifficulty.PEACEFUL) {
@ -183,7 +184,7 @@
}
if (this.world.getDifficulty() == EnumDifficulty.EASY) {
@@ -679,7 +748,7 @@
@@ -679,7 +749,7 @@
}
}
@ -192,7 +193,7 @@
return false;
} else {
Entity entity = damagesource.getEntity();
@@ -695,10 +764,29 @@
@@ -695,10 +765,29 @@
}
public boolean a(EntityHuman entityhuman) {
@ -225,7 +226,7 @@
}
protected void damageArmor(float f) {
@@ -742,7 +830,12 @@
@@ -742,7 +831,12 @@
return (float) i / (float) this.inventory.armor.length;
}
@ -239,7 +240,7 @@
if (!this.isInvulnerable(damagesource)) {
f = this.applyArmorModifier(damagesource, f);
f = this.applyMagicModifier(damagesource, f);
@@ -762,6 +855,7 @@
@@ -762,6 +856,7 @@
}
}
@ -247,7 +248,7 @@
}
public void openSign(TileEntitySign tileentitysign) {}
@@ -884,8 +978,15 @@
@@ -884,8 +979,15 @@
if (entity instanceof EntityLiving) {
f3 = ((EntityLiving) entity).getHealth();
if (j > 0 && !entity.isBurning()) {
@ -265,7 +266,7 @@
}
}
@@ -925,11 +1026,28 @@
@@ -925,11 +1027,28 @@
}
if (entity instanceof EntityPlayer && entity.velocityChanged) {
@ -294,7 +295,7 @@
}
if (flag2) {
@@ -991,7 +1109,8 @@
@@ -991,7 +1110,8 @@
if (itemstack3 != null && object instanceof EntityLiving) {
itemstack3.a((EntityLiving) object, this);
@ -304,7 +305,7 @@
this.a(EnumHand.MAIN_HAND, (ItemStack) null);
}
}
@@ -1001,7 +1120,14 @@
@@ -1001,7 +1121,14 @@
this.a(StatisticList.y, Math.round(f5 * 10.0F));
if (j > 0) {
@ -320,7 +321,7 @@
}
if (this.world instanceof WorldServer && f5 > 2.0F) {
@@ -1090,6 +1216,20 @@
@@ -1090,6 +1217,20 @@
this.stopRiding();
}
@ -341,7 +342,7 @@
this.setSize(0.2F, 0.2F);
if (this.world.isLoaded(blockposition)) {
EnumDirection enumdirection = (EnumDirection) this.world.getType(blockposition).get(BlockFacingHorizontal.FACING);
@@ -1172,6 +1312,23 @@
@@ -1172,6 +1313,23 @@
this.world.everyoneSleeping();
}
@ -365,7 +366,7 @@
this.sleepTicks = flag ? 0 : 100;
if (flag2) {
this.setRespawnPosition(this.bedPosition, false);
@@ -1222,9 +1379,11 @@
@@ -1222,9 +1380,11 @@
if (blockposition != null) {
this.e = blockposition;
this.f = flag;
@ -377,3 +378,11 @@
}
}
@@ -1266,6 +1426,7 @@
this.motY = d3 * 0.6D;
this.aQ = f2;
this.fallDistance = 0.0F;
+ if (!CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
this.setFlag(7, false);
} else {
super.g(f, f1);

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/server/EntityLiving.java
+++ b/net/minecraft/server/EntityLiving.java
@@ -9,6 +9,20 @@
@@ -9,6 +9,21 @@
import java.util.Random;
import java.util.UUID;
@ -11,6 +11,7 @@
+import org.bukkit.craftbukkit.attribute.CraftAttributeMap;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
@ -21,7 +22,7 @@
public abstract class EntityLiving extends Entity {
private static final UUID a = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
@@ -80,6 +94,13 @@
@@ -80,6 +95,13 @@
protected int bn;
protected int bo;
private BlockPosition bC;
@ -35,7 +36,7 @@
public void Q() {
this.damageEntity(DamageSource.OUT_OF_WORLD, Float.MAX_VALUE);
@@ -88,7 +109,8 @@
@@ -88,7 +110,8 @@
public EntityLiving(World world) {
super(world);
this.initAttributes();
@ -45,7 +46,7 @@
this.i = true;
this.aL = (float) ((Math.random() + 1.0D) * 0.009999999776482582D);
this.setPosition(this.locX, this.locY, this.locZ);
@@ -125,7 +147,13 @@
@@ -125,7 +148,13 @@
double d1 = Math.min((double) (0.2F + f / 15.0F), 2.5D);
int i = (int) (150.0D * d1);
@ -60,7 +61,7 @@
}
}
@@ -183,7 +211,11 @@
@@ -183,7 +212,11 @@
this.stopRiding();
}
} else {
@ -73,7 +74,7 @@
}
if (!this.world.isClientSide) {
@@ -240,6 +272,18 @@
@@ -240,6 +273,18 @@
this.world.methodProfiler.b();
}
@ -92,7 +93,7 @@
protected void b(BlockPosition blockposition) {
int i = EnchantmentManager.a(Enchantments.j, this);
@@ -255,19 +299,19 @@
@@ -255,19 +300,19 @@
protected void bC() {
++this.deathTicks;
@ -121,7 +122,7 @@
this.die();
@@ -421,6 +465,17 @@
@@ -421,6 +466,17 @@
}
}
@ -139,7 +140,7 @@
if (nbttagcompound.hasKeyOfType("Health", 99)) {
this.setHealth(nbttagcompound.getFloat("Health"));
}
@@ -436,9 +491,15 @@
@@ -436,9 +492,15 @@
}
@ -155,7 +156,7 @@
while (iterator.hasNext()) {
MobEffectList mobeffectlist = (MobEffectList) iterator.next();
MobEffect mobeffect = (MobEffect) this.effects.get(mobeffectlist);
@@ -452,6 +513,16 @@
@@ -452,6 +514,16 @@
this.a(mobeffect, false);
}
}
@ -172,7 +173,7 @@
if (this.updateEffects) {
if (!this.world.isClientSide) {
@@ -548,6 +619,12 @@
@@ -548,6 +620,12 @@
}
public void addEffect(MobEffect mobeffect) {
@ -185,7 +186,7 @@
if (this.d(mobeffect)) {
MobEffect mobeffect1 = (MobEffect) this.effects.get(mobeffect.getMobEffect());
@@ -579,6 +656,12 @@
@@ -579,6 +657,12 @@
}
public MobEffect c(MobEffectList mobeffectlist) {
@ -198,7 +199,7 @@
return (MobEffect) this.effects.remove(mobeffectlist);
}
@@ -618,20 +701,52 @@
@@ -618,20 +702,52 @@
}
@ -252,7 +253,7 @@
this.datawatcher.set(EntityLiving.HEALTH, Float.valueOf(MathHelper.a(f, 0.0F, this.getMaxHealth())));
}
@@ -647,7 +762,8 @@
@@ -647,7 +763,8 @@
} else if (damagesource.o() && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
return false;
} else {
@ -262,7 +263,7 @@
this.getEquipment(EnumItemSlot.HEAD).damage((int) (f * 4.0F + this.random.nextFloat() * f * 2.0F), this);
f *= 0.75F;
}
@@ -673,19 +789,38 @@
@@ -673,19 +790,38 @@
if ((float) this.noDamageTicks > (float) this.maxNoDamageTicks / 2.0F) {
if (f <= this.lastDamage) {
@ -303,7 +304,7 @@
this.az = 0.0F;
Entity entity = damagesource.getEntity();
@@ -825,6 +960,12 @@
@@ -825,6 +961,12 @@
boolean flag = this.lastDamageByPlayerTime > 0;
this.a(flag, i, damagesource);
@ -316,7 +317,7 @@
}
}
@@ -912,8 +1053,13 @@
@@ -912,8 +1054,13 @@
int i = MathHelper.f((f - 3.0F - f2) * f1);
if (i > 0) {
@ -331,7 +332,7 @@
int j = MathHelper.floor(this.locX);
int k = MathHelper.floor(this.locY - 0.20000000298023224D);
int l = MathHelper.floor(this.locZ);
@@ -940,20 +1086,20 @@
@@ -940,20 +1087,20 @@
protected float applyArmorModifier(DamageSource damagesource, float f) {
if (!damagesource.ignoresArmor()) {
@ -355,7 +356,7 @@
i = (this.getEffect(MobEffects.RESISTANCE).getAmplifier() + 1) * 5;
int j = 25 - i;
float f1 = f * (float) j;
@@ -974,22 +1120,122 @@
@@ -974,22 +1121,122 @@
}
}
@ -485,7 +486,7 @@
}
public CombatTracker getCombatTracker() {
@@ -1055,6 +1301,7 @@
@@ -1055,6 +1302,7 @@
public AttributeMapBase getAttributeMap() {
if (this.bp == null) {
this.bp = new AttributeMapServer();
@ -493,7 +494,23 @@
}
return this.bp;
@@ -1702,6 +1949,13 @@
@@ -1329,6 +1577,7 @@
}
if (this.onGround && !this.world.isClientSide) {
+ if (getFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
this.setFlag(7, false);
}
} else {
@@ -1689,6 +1938,7 @@
}
if (!this.world.isClientSide) {
+ if (!CraftEventFactory.callToggleGlideEvent(this, flag).isCancelled()) // CraftBukkit
this.setFlag(7, flag);
}
@@ -1702,6 +1952,13 @@
if (!list.isEmpty()) {
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity) list.get(i);
@ -507,7 +524,7 @@
this.C(entity);
}
@@ -1918,7 +2172,22 @@
@@ -1918,7 +2175,22 @@
protected void v() {
if (this.bm != null && this.cs()) {
this.a(this.bm, 16);

View File

@ -422,23 +422,24 @@
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
this.s();
}
@@ -741,7 +916,16 @@
@@ -741,8 +916,17 @@
public void triggerHealthUpdate() {
this.lastHealthSent = -1.0E8F;
+ this.lastSentExp = -1; // CraftBukkit - Added to reset
+ }
+
}
+ // CraftBukkit start - Support multi-line messages
+ public void sendMessage(IChatBaseComponent[] ichatbasecomponent) {
+ for (IChatBaseComponent component : ichatbasecomponent) {
+ this.sendMessage(component);
+ }
}
+ }
+ // CraftBukkit end
+
public void b(IChatBaseComponent ichatbasecomponent) {
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent));
}
@@ -802,6 +986,8 @@
}
@ -486,10 +487,24 @@
}
public void a(EnumHand enumhand) {
@@ -962,4 +1156,127 @@
this.setFlag(7, true);
this.setFlag(7, false);
@@ -955,11 +1149,139 @@
}
public void M() {
+ if (!CraftEventFactory.callToggleGlideEvent(this, true).isCancelled()) // CraftBukkit
this.setFlag(7, true);
}
public void N() {
- this.setFlag(7, true);
- this.setFlag(7, false);
+ // CraftBukkit start
+ if (!CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) {
+ this.setFlag(7, true);
+ this.setFlag(7, false);
+ }
+ // CraftBukkit end
+ }
+
+ // CraftBukkit start - Add per-player time and weather.
+ public long timeOffset = 0;
@ -611,6 +626,6 @@
+ @Override
+ public CraftPlayer getBukkitEntity() {
+ return (CraftPlayer) super.getBukkitEntity();
+ }
}
+ // CraftBukkit end
}

View File

@ -474,6 +474,16 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return true;
}
@Override
public boolean isGliding() {
return getHandle().getFlag(7);
}
@Override
public void setGliding(boolean gliding) {
getHandle().setFlag(7, gliding);
}
@Deprecated
public int _INVALID_getLastDamage() {
return NumberConversions.ceil(getLastDamage());

View File

@ -984,4 +984,10 @@ public class CraftEventFactory {
event.getInventory().setItem(2, event.getResult());
return event;
}
public static EntityToggleGlideEvent callToggleGlideEvent(EntityLiving entity, boolean gliding) {
EntityToggleGlideEvent event = new EntityToggleGlideEvent((LivingEntity) entity.getBukkitEntity(), gliding);
entity.world.getServer().getPluginManager().callEvent(event);
return event;
}
}