3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 23:00:08 +01:00

Implement Leash API. Adds BUKKIT-4459, BUKKIT-4583

Dieser Commit ist enthalten in:
T00thpick1 2013-07-31 17:35:16 -04:00 committet von Wesley Wolfe
Ursprung f7ca953ff1
Commit 54672a75f6
9 geänderte Dateien mit 156 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -264,6 +264,7 @@ public abstract class EntityCreature extends EntityInsentient {
if (this instanceof EntityTameableAnimal && ((EntityTameableAnimal) this).isSitting()) {
if (f > 10.0F) {
this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.EntityUnleashEvent(this.getBukkitEntity(), org.bukkit.event.entity.EntityUnleashEvent.UnleashReason.DISTANCE)); // CraftBukkit
this.a(true, true);
}

Datei anzeigen

@ -4,8 +4,11 @@ import java.util.Iterator;
import java.util.List;
import java.util.UUID;
//CraftBukkit start
// CraftBukkit start
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
// CraftBukkit end
public abstract class EntityInsentient extends EntityLiving {
@ -769,6 +772,12 @@ public abstract class EntityInsentient extends EntityLiving {
public final boolean c(EntityHuman entityhuman) {
if (this.bH() && this.bI() == entityhuman) {
// CraftBukkit start
if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman).isCancelled()) {
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet39AttachEntity(1, this, this.bI()));
return false;
}
// CraftBukkit end
this.a(true, !entityhuman.abilities.canInstantlyBuild);
return true;
} else {
@ -776,12 +785,24 @@ public abstract class EntityInsentient extends EntityLiving {
if (itemstack != null && itemstack.id == Item.LEASH.id && this.bG()) {
if (!(this instanceof EntityTameableAnimal) || !((EntityTameableAnimal) this).isTamed()) {
// CraftBukkit start
if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet39AttachEntity(1, this, this.bI()));
return false;
}
// CraftBukkit end
this.b(entityhuman, true);
--itemstack.count;
return true;
}
if (entityhuman.getName().equalsIgnoreCase(((EntityTameableAnimal) this).getOwnerName())) {
// CraftBukkit start
if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet39AttachEntity(1, this, this.bI()));
return false;
}
// CraftBukkit end
this.b(entityhuman, true);
--itemstack.count;
return true;
@ -803,6 +824,7 @@ public abstract class EntityInsentient extends EntityLiving {
if (this.bv) {
if (this.bw == null || this.bw.dead) {
this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.HOLDER_GONE)); // CraftBukkit
this.a(true, true);
}
}
@ -869,6 +891,7 @@ public abstract class EntityInsentient extends EntityLiving {
this.bw = entityleash;
} else {
this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
this.a(false, true);
}
}

Datei anzeigen

@ -3,6 +3,8 @@ package net.minecraft.server;
import java.util.Iterator;
import java.util.List;
import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
public class EntityLeash extends EntityHanging {
public EntityLeash(World world) {
@ -55,6 +57,12 @@ public class EntityLeash extends EntityHanging {
while (iterator.hasNext()) {
entityinsentient = (EntityInsentient) iterator.next();
if (entityinsentient.bH() && entityinsentient.bI() == entityhuman) {
// CraftBukkit start
if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, this, entityhuman).isCancelled()) {
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet39AttachEntity(1, entityinsentient, entityinsentient.bI()));
continue;
}
// CraftBukkit end
entityinsentient.b(this, true);
flag = true;
}
@ -63,8 +71,11 @@ public class EntityLeash extends EntityHanging {
}
if (!this.world.isStatic && !flag) {
this.die();
if (entityhuman.abilities.canInstantlyBuild) {
// CraftBukkit start - Move below
// this.die();
boolean die = true;
// CraftBukkit end
if (true || entityhuman.abilities.canInstantlyBuild) { // CraftBukkit - Process for non-creative as well
d0 = 7.0D;
list = this.world.a(EntityInsentient.class, AxisAlignedBB.a().a(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + d0, this.locZ + d0));
if (list != null) {
@ -73,11 +84,22 @@ public class EntityLeash extends EntityHanging {
while (iterator.hasNext()) {
entityinsentient = (EntityInsentient) iterator.next();
if (entityinsentient.bH() && entityinsentient.bI() == this) {
entityinsentient.a(true, false);
// CraftBukkit start
if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) {
die = false;
continue;
}
entityinsentient.a(true, !entityhuman.abilities.canInstantlyBuild); // false -> survival mode boolean
// CraftBukkit end
}
}
}
}
// CraftBukkit start
if (die) {
this.die();
}
// CraftBukkit end
}
return true;

Datei anzeigen

@ -3,6 +3,8 @@ package net.minecraft.server;
import java.util.Iterator;
import java.util.List;
import org.bukkit.event.hanging.HangingPlaceEvent; // CraftBukkit
public class ItemLeash extends Item {
public ItemLeash(int i) {
@ -40,8 +42,23 @@ public class ItemLeash extends Item {
if (entityinsentient.bH() && entityinsentient.bI() == entityhuman) {
if (entityleash == null) {
entityleash = EntityLeash.a(world, i, j, k);
// CraftBukkit start
HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, world.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF);
world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
entityleash.die();
return false;
}
// CraftBukkit end
}
// CraftBukkit start
if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman).isCancelled()) {
continue;
}
// CraftBukkit end
entityinsentient.b(entityleash, true);
flag = true;
}

Datei anzeigen

@ -4,7 +4,6 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;
@ -994,6 +993,9 @@ public class CraftWorld implements World {
entity = new EntityPainting(world, (int) x, (int) y, (int) z, dir);
} else if (ItemFrame.class.isAssignableFrom(clazz)) {
entity = new EntityItemFrame(world, (int) x, (int) y, (int) z, dir);
} else if (LeashHitch.class.isAssignableFrom(clazz)) {
entity = new EntityLeash(world, (int) x, (int) y, (int) z);
entity.p = true;
}
if (entity != null && !((EntityHanging) entity).survives()) {

Datei anzeigen

@ -147,6 +147,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
} else if (entity instanceof EntityHanging) {
if (entity instanceof EntityPainting) { return new CraftPainting(server, (EntityPainting) entity); }
else if (entity instanceof EntityItemFrame) { return new CraftItemFrame(server, (EntityItemFrame) entity); }
else if (entity instanceof EntityLeash) { return new CraftLeash(server, (EntityLeash) entity); }
else { return new CraftHanging(server, (EntityHanging) entity); }
}
else if (entity instanceof EntityTNTPrimed) { return new CraftTNTPrimed(server, (EntityTNTPrimed) entity); }

Datei anzeigen

@ -0,0 +1,27 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityLeash;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LeashHitch;
public class CraftLeash extends CraftHanging implements LeashHitch {
public CraftLeash(CraftServer server, EntityLeash entity) {
super(server, entity);
}
@Override
public EntityLeash getHandle() {
return (EntityLeash) entity;
}
@Override
public String toString() {
return "CraftLeash";
}
public EntityType getType() {
return EntityType.LEASH_HITCH;
}
}

Datei anzeigen

@ -14,18 +14,17 @@ import net.minecraft.server.EntityEnderPearl;
import net.minecraft.server.EntityInsentient;
import net.minecraft.server.EntityLargeFireball;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntitySmallFireball;
import net.minecraft.server.EntitySnowball;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EntityPotion;
import net.minecraft.server.EntitySmallFireball;
import net.minecraft.server.EntitySnowball;
import net.minecraft.server.EntityWither;
import net.minecraft.server.EntityWitherSkull;
import net.minecraft.server.GenericAttributes;
import net.minecraft.server.MobEffect;
import net.minecraft.server.MobEffectList;
import net.minecraft.server.Packet42RemoveMobEffect;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -35,11 +34,11 @@ import org.bukkit.craftbukkit.inventory.CraftEntityEquipment;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Egg;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
@ -407,6 +406,46 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return getHandle() instanceof EntityInsentient && ((EntityInsentient) getHandle()).getCustomNameVisible();
}
public boolean isLeashed() {
if (!(getHandle() instanceof EntityInsentient)) {
return false;
}
return ((EntityInsentient) getHandle()).bI() != null;
}
public Entity getLeashHolder() throws IllegalStateException {
if (!isLeashed()) {
throw new IllegalStateException("Entity not leashed");
}
return ((EntityInsentient) getHandle()).bI().getBukkitEntity();
}
private boolean unleash() {
if (!isLeashed()) {
return false;
}
((EntityInsentient) getHandle()).a(true, false);
return true;
}
public boolean setLeashHolder(Entity holder) {
if ((getHandle() instanceof EntityWither) || !(getHandle() instanceof EntityInsentient)) {
return false;
}
if (holder == null) {
return unleash();
}
if (holder.isDead()) {
return false;
}
unleash();
((EntityInsentient) getHandle()).b(((CraftEntity) holder).getHandle(), true);
return true;
}
@Deprecated
public int _INVALID_getLastDamage() {
return NumberConversions.ceil(getLastDamage());

Datei anzeigen

@ -30,8 +30,8 @@ import net.minecraft.server.World;
import net.minecraft.server.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@ -44,10 +44,8 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftDamageSource;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
@ -706,4 +704,16 @@ public class CraftEventFactory {
player.playerConnection.sendPacket(new Packet103SetSlot(player.activeContainer.windowId, slot.g, itemInHand));
}
}
public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(EntityInsentient entity, EntityHuman player) {
PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity());
entity.world.getServer().getPluginManager().callEvent(event);
return event;
}
public static PlayerLeashEntityEvent callPlayerLeashEntityEvent(EntityInsentient entity, Entity leashHolder, EntityHuman player) {
PlayerLeashEntityEvent event = new PlayerLeashEntityEvent(entity.getBukkitEntity(), leashHolder.getBukkitEntity(), (Player) player.getBukkitEntity());
entity.world.getServer().getPluginManager().callEvent(event);
return event;
}
}