Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Save New Duplicate & Edit Just Text Twitter
- >
- package de.bitcraft.pathfinding;
- import com.google.common.reflect.Reflection;
- import com.mojang.authlib.GameProfile;
- import com.mojang.authlib.properties.Property;
- import net.minecraft.server.v1_8_R3.*;
- import org.bukkit.Bukkit;
- import org.bukkit.Chunk;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
- import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
- import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
- import org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Player;
- import java.util.*;
- /**
- * Created by Robin on 25.11.2017.
- */
- public class NPC extends Reflections {
- MinecraftServer minecraftServer;
- WorldServer worldServer;
- EntityPlayer entityPlayer;
- GameProfile gameProfile;
- public NPC(String name, Location location) {
- minecraftServer = ((CraftServer) Bukkit.getServer()).getServer();
- worldServer = ((CraftWorld) location.getWorld()).getHandle();
- gameProfile = new GameProfile(UUID.randomUUID(), name);
- entityPlayer = new EntityPlayer(minecraftServer, worldServer, gameProfile, new PlayerInteractManager(worldServer));
- Player player = entityPlayer.getBukkitEntity().getPlayer();
- player.setPlayerListName("");
- entityPlayer.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
- }
- public void changeSkin(String value, String signature) {
- gameProfile.getProperties().put("textures", new Property("textures", value, signature));
- }
- public void move(Location loc) {
- entityPlayer.move(loc.getX(), loc.getY(), loc.getZ());
- /* PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook(this.getEntityID(),
- (byte)(int)Math.floor((loc.getX()-this.getLocation().getX())*32.0D),
- (byte)(int)Math.floor((loc.getY()-this.getLocation().getY())*32.0D),
- (byte)(int)Math.floor((loc.getZ()-this.getLocation().getZ())*32.0D),
- (byte)loc.getYaw(), (byte)loc.getPitch(), false);
- for(Player player : Bukkit.getOnlinePlayers()) {
- sendPacket(packet, player);
- }*/
- }
- public Player getPlayer() {
- return entityPlayer.getBukkitEntity().getPlayer();
- }
- public void spawn(Player player) {
- PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawn();
- setValue(packetPlayOutNamedEntitySpawn, "a", entityPlayer.getBukkitEntity().getEntityId());
- setValue(packetPlayOutNamedEntitySpawn, "b", gameProfile.getId());
- setValue(packetPlayOutNamedEntitySpawn, "c", getFixLocation(getLocation().getX()));
- setValue(packetPlayOutNamedEntitySpawn, "d", getFixLocation(getLocation().getY()));
- setValue(packetPlayOutNamedEntitySpawn, "e", getFixLocation(getLocation().getZ()));
- setValue(packetPlayOutNamedEntitySpawn, "f", getFixRotation(getLocation().getYaw()));
- setValue(packetPlayOutNamedEntitySpawn, "g", getFixRotation(getLocation().getPitch()));
- setValue(packetPlayOutNamedEntitySpawn, "h", 0);
- DataWatcher dataWatcher = new DataWatcher(entityPlayer);
- dataWatcher.a(10, (byte)127);
- dataWatcher.a(6, (float) 20);
- setValue(packetPlayOutNamedEntitySpawn, "i", dataWatcher);
- addToTablist(player);
- sendPacket(packetPlayOutNamedEntitySpawn, player);
- headRotation(getFixRotation(getLocation().getYaw()), getFixRotation(getLocation().getPitch()), player);
- }
- public void despawn(Player player) {
- PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[] {entityPlayer.getBukkitEntity().getEntityId()});
- removeToTabList(player);
- sendPacket(packetPlayOutEntityDestroy, player);
- }
- public void addToTablist(Player player) {
- PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
- PacketPlayOutPlayerInfo.PlayerInfoData playerInfoData = packetPlayOutPlayerInfo.new PlayerInfoData(gameProfile, 1, WorldSettings.EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameProfile.getName())[0]);
- List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List <PacketPlayOutPlayerInfo.PlayerInfoData>) getValue(packetPlayOutPlayerInfo, "b");
- players.add(playerInfoData);
- setValue(packetPlayOutPlayerInfo, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
- setValue(packetPlayOutPlayerInfo, "b", players);
- sendPacket(packetPlayOutPlayerInfo, player);
- }
- public void removeToTabList(Player player) {
- PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
- PacketPlayOutPlayerInfo.PlayerInfoData playerInfoData = packetPlayOutPlayerInfo.new PlayerInfoData(gameProfile, 1, WorldSettings.EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameProfile.getName())[0]);
- List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List <PacketPlayOutPlayerInfo.PlayerInfoData>) getValue(packetPlayOutPlayerInfo, "b");
- players.add(playerInfoData);
- setValue(packetPlayOutPlayerInfo, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
- setValue(packetPlayOutPlayerInfo, "b", players);
- sendPacket(packetPlayOutPlayerInfo, player);
- }
- public void teleport(Location location, Player player){
- PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport();
- setValue(packet, "a", entityPlayer.getBukkitEntity().getEntityId());
- setValue(packet, "b", getFixLocation(location.getX()));
- setValue(packet, "c", getFixLocation(location.getY()));
- setValue(packet, "d", getFixLocation(location.getZ()));
- setValue(packet, "e", getFixRotation(location.getYaw()));
- setValue(packet, "f", getFixRotation(location.getPitch()));
- setValue(packet, "g", !this.getLocation().getBlock().isEmpty());
- sendPacket(packet, player);
- headRotation(location.getYaw(), location.getPitch(), player);
- }
- private Entity getEntityByUniqueId(UUID uuid) {
- for(World world : Bukkit.getWorlds()) {
- for(Chunk chunk : world.getLoadedChunks()) {
- for(Entity entity : chunk.getEntities()) {
- if(entity.getUniqueId().equals(uuid)) {
- return entity;
- }
- }
- }
- }
- return null;
- }
- public void headRotation(float yaw,float pitch, Player player){
- PacketPlayOutEntity.PacketPlayOutEntityLook packet = new PacketPlayOutEntity.PacketPlayOutEntityLook(entityPlayer.getBukkitEntity().getEntityId(), getFixRotation(yaw),getFixRotation(pitch) , true);
- PacketPlayOutEntityHeadRotation packetHead = new PacketPlayOutEntityHeadRotation();
- setValue(packetHead, "a", entityPlayer.getBukkitEntity().getEntityId());
- setValue(packetHead, "b", getFixRotation(yaw));
- sendPacket(packet, player);
- sendPacket(packetHead, player);
- }
- public void setLocation(Location location) {
- }
- public int getFixLocation(double pos){
- return (int)MathHelper.floor(pos * 32.0D);
- }
- public byte getFixRotation(float yawpitch){
- return (byte) ((int) (yawpitch * 256.0F / 360.0F));
- }
- public int getEntityID() {
- return entityPlayer.getBukkitEntity().getEntityId();
- }
- public Location getLocation() {
- return getPlayer().getLocation();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement