239 lines
6.2 KiB
Java
239 lines
6.2 KiB
Java
package eu.univento.core.api.entity;
|
|
|
|
import net.minecraft.server.v1_8_R3.EntityLiving;
|
|
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.EntityEffect;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature;
|
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
/**
|
|
*
|
|
* @author GerVorbis
|
|
* @version 1.0
|
|
*/
|
|
public class EntityModifier
|
|
{
|
|
static org.bukkit.entity.Entity entity;
|
|
static CraftEntity craftentity;
|
|
static net.minecraft.server.v1_8_R3.Entity entityS;
|
|
static int scheduler;
|
|
static Plugin plugin;
|
|
static Player player = null;
|
|
static float Speed;
|
|
|
|
public EntityModifier(org.bukkit.entity.Entity entity, Plugin plugin)
|
|
{
|
|
EntityModifier.entity = entity;
|
|
craftentity = (CraftEntity)entity;
|
|
entityS = craftentity.getHandle();
|
|
EntityModifier.plugin = plugin;
|
|
}
|
|
|
|
public static Builder modify()
|
|
{
|
|
return new Builder();
|
|
}
|
|
|
|
public static final class Builder
|
|
{
|
|
public Builder setDisplayName(String display)
|
|
{
|
|
EntityModifier.entity.setCustomName(display);
|
|
EntityModifier.entity.setCustomNameVisible(true);
|
|
return this;
|
|
}
|
|
|
|
public Builder setDisplayNameVisible(Boolean visible)
|
|
{
|
|
EntityModifier.entity.setCustomNameVisible(visible.booleanValue());
|
|
return this;
|
|
}
|
|
|
|
public Builder playEffekt(EntityEffect entityeffect)
|
|
{
|
|
EntityModifier.entity.playEffect(entityeffect);
|
|
return this;
|
|
}
|
|
|
|
public Builder remove()
|
|
{
|
|
EntityModifier.entity.remove();
|
|
return this;
|
|
}
|
|
|
|
public Builder setPassenger(org.bukkit.entity.Entity passenger)
|
|
{
|
|
EntityModifier.entity.setPassenger(passenger);
|
|
return this;
|
|
}
|
|
|
|
public Builder setFireTicks(int ticks)
|
|
{
|
|
EntityModifier.entity.setFireTicks(ticks);
|
|
return this;
|
|
}
|
|
|
|
public Builder setLocation(Location location)
|
|
{
|
|
teleport(location);
|
|
return this;
|
|
}
|
|
|
|
public Builder setYawPitch(float yaw, float pitch)
|
|
{
|
|
Location loc = EntityModifier.entity.getLocation().clone();
|
|
teleport(
|
|
new Location(loc.getWorld(), loc.getX(), loc.getY(),
|
|
loc.getZ(), yaw, pitch));
|
|
return this;
|
|
}
|
|
|
|
public Builder teleport(Location location)
|
|
{
|
|
EntityModifier.entity.teleport(location);
|
|
return this;
|
|
}
|
|
|
|
public Builder die()
|
|
{
|
|
EntityModifier.entityS.die();
|
|
return this;
|
|
}
|
|
|
|
public Builder setInvisible(boolean invisible)
|
|
{
|
|
EntityModifier.entityS.setInvisible(invisible);
|
|
return this;
|
|
}
|
|
|
|
public Builder noClip(boolean noClip)
|
|
{
|
|
EntityModifier.entityS.noclip = noClip;
|
|
return this;
|
|
}
|
|
|
|
public Builder setInvulnerable(boolean invulnerable)
|
|
{
|
|
try
|
|
{
|
|
Field invulnerableField = net.minecraft.server.v1_8_R3.Entity.class
|
|
.getDeclaredField("invulnerable");
|
|
invulnerableField.setAccessible(true);
|
|
invulnerableField.setBoolean(EntityModifier.entityS, invulnerable);
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public Builder setNoAI(boolean noAI)
|
|
{
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
EntityModifier.entityS.c(tag);
|
|
tag.setBoolean("NoAI", noAI);
|
|
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
|
el.a(tag);
|
|
return this;
|
|
}
|
|
|
|
public Builder setSilent(boolean silent)
|
|
{
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
EntityModifier.entityS.c(tag);
|
|
tag.setBoolean("Silent", silent);
|
|
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
|
el.a(tag);
|
|
return this;
|
|
}
|
|
|
|
public Builder setCanPickUpLoot(boolean canpickuploot)
|
|
{
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
EntityModifier.entityS.c(tag);
|
|
tag.setBoolean("CanPickUpLoot", canpickuploot);
|
|
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
|
el.a(tag);
|
|
return this;
|
|
}
|
|
|
|
public Builder setHealth(float health)
|
|
{
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
EntityModifier.entityS.c(tag);
|
|
tag.setFloat("HealF", health);
|
|
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
|
el.a(tag);
|
|
return this;
|
|
}
|
|
|
|
public Builder setCanDespawn(boolean candespawn)
|
|
{
|
|
candespawn = !candespawn;
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
EntityModifier.entityS.c(tag);
|
|
tag.setBoolean("PersistenceRequired", candespawn);
|
|
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
|
el.a(tag);
|
|
return this;
|
|
}
|
|
|
|
public Builder walkToLocation(Location location, float speed)
|
|
{
|
|
((CraftCreature)EntityModifier.entity)
|
|
.getHandle()
|
|
.getNavigation()
|
|
.a(location.getX(), location.getY(), location.getZ(), speed);
|
|
return this;
|
|
}
|
|
|
|
public Builder followPlayer(Player target, float speed)
|
|
{
|
|
EntityModifier.player = target;
|
|
EntityModifier.Speed = speed;
|
|
EntityModifier.scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(EntityModifier.plugin,
|
|
new Runnable()
|
|
{
|
|
@SuppressWarnings("deprecation")
|
|
public void run() {
|
|
double distance = EntityModifier.entity.getLocation().distance(
|
|
EntityModifier.player.getLocation());
|
|
if (distance < 11.0D) {
|
|
float speed = EntityModifier.Speed;
|
|
if (distance < 3.0D) {
|
|
speed = 0.0F;
|
|
}
|
|
((CraftCreature)EntityModifier.entity)
|
|
.getHandle()
|
|
.getNavigation()
|
|
.a(EntityModifier.player.getLocation().getX(),
|
|
EntityModifier.player.getLocation().getY(),
|
|
EntityModifier.player.getLocation().getZ(),
|
|
speed);
|
|
}
|
|
else if (EntityModifier.player.isOnGround()) {
|
|
EntityModifier.entity.teleport(EntityModifier.player);
|
|
}
|
|
}
|
|
}
|
|
, 0L, 1L);
|
|
return this;
|
|
}
|
|
|
|
public Builder stopFollowingPlayer()
|
|
{
|
|
Bukkit.getScheduler().cancelTask(EntityModifier.scheduler);
|
|
return this;
|
|
}
|
|
|
|
public org.bukkit.entity.Entity build()
|
|
{
|
|
return EntityModifier.entity;
|
|
}
|
|
}
|
|
} |