001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.bukkit.entity;
020
021import org.bukkit.Location;
022import org.bukkit.World;
023import org.bukkit.entity.Entity;
024import org.bukkit.entity.EntityType;
025import org.checkerframework.checker.nullness.qual.NonNull;
026
027public abstract class EntityWrapper {
028
029    protected final float yaw;
030    protected final float pitch;
031    private final Entity entity;
032    private final EntityType type;
033    public double x;
034    public double y;
035    public double z;
036
037    EntityWrapper(final @NonNull Entity entity) {
038        this.entity = entity;
039        this.type = entity.getType();
040
041        final Location location = entity.getLocation();
042        this.x = location.getX();
043        this.y = location.getY();
044        this.z = location.getZ();
045        this.yaw = location.getYaw();
046        this.pitch = location.getPitch();
047    }
048
049    @SuppressWarnings("deprecation")
050    @Override
051    public String toString() {
052        return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z);
053    }
054
055    public abstract Entity spawn(World world, int xOffset, int zOffset);
056
057    public abstract void saveEntity();
058
059    public float getYaw() {
060        return this.yaw;
061    }
062
063    public float getPitch() {
064        return this.pitch;
065    }
066
067    public Entity getEntity() {
068        return this.entity;
069    }
070
071    public EntityType getType() {
072        return this.type;
073    }
074
075    public double getX() {
076        return this.x;
077    }
078
079    public double getY() {
080        return this.y;
081    }
082
083    public double getZ() {
084        return this.z;
085    }
086
087}