summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
blob: e6be1ca4bb9ef99e1e4c04aec9f884c04dc9bb95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package org.bukkit.craftbukkit.entity;

import net.minecraft.server.Entity;
import net.minecraft.server.WorldServer;
import org.bukkit.Location;
import org.bukkit.Vector;
import org.bukkit.World;
import org.bukkit.craftbukkit.CraftServer;

public abstract class CraftEntity implements org.bukkit.entity.Entity {
    protected final CraftServer server;
    private Entity entity;

    public CraftEntity(final CraftServer server, final Entity entity) {
        this.server = server;
        this.entity = entity;
    }

    public Location getLocation() {
        return new Location(getWorld(), entity.p, entity.q, entity.r, entity.v, entity.w);
    }

    public Vector getVelocity() {
        return new Vector(entity.s, entity.t, entity.u);
    }

    public void setVelocity(Vector vel) {
        entity.s = vel.getX();
        entity.t = vel.getY();
        entity.u = vel.getZ();
    }

    public World getWorld() {
        return ((WorldServer)entity.l).getWorld();
    }

    public void teleportTo(Location location) {
        entity.b(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    public void teleportTo(org.bukkit.entity.Entity destination) {
        teleportTo(destination.getLocation());
    }

    public int getEntityId() {
        return entity.g;
    }

    public Entity getHandle() {
        return entity;
    }

    public void setHandle(final Entity entity) {
        this.entity = entity;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CraftEntity other = (CraftEntity) obj;
        if (this.server != other.server && (this.server == null || !this.server.equals(other.server))) {
            return false;
        }
        if (this.entity != other.entity && (this.entity == null || !this.entity.equals(other.entity))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 89 * hash + (this.server != null ? this.server.hashCode() : 0);
        hash = 89 * hash + (this.entity != null ? this.entity.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "CraftEntity{" + "id=" + getEntityId() + '}';
    }
}