mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-24 01:06:01 +01:00
Implement Leash API. Adds BUKKIT-4459, BUKKIT-4583
By: T00thpick1 <t00thpick1dirko@gmail.com>
This commit is contained in:
parent
cdb0ea7069
commit
4cd10145c5
5 changed files with 89 additions and 10 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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); }
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue