use of org.bukkit.craftbukkit.v1_16_R2.CraftServer in project Nokaut by smaks6.
the class CreateNPC method spawnNPC.
private EntityPlayer spawnNPC() {
Location location = znokautowany.getLocation();
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorld(znokautowany.getWorld().getName())).getHandle();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ChatColor.RED + "*Nokaut*");
gameProfile.getProperties().putAll(((CraftPlayer) znokautowany).getHandle().getProfile().getProperties());
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
npc.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
npc.setPose(EntityPose.SWIMMING);
PlayerConnection connection = ((CraftPlayer) see).getHandle().playerConnection;
npc.setPose(EntityPose.SWIMMING);
DataWatcher watcher = npc.getDataWatcher();
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), watcher, false));
connection.sendPacket(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.yaw * 256 / 360)));
CraftPlayer craftPlayer = npc.getBukkitEntity();
craftPlayer.setCollidable(false);
return npc;
}
use of org.bukkit.craftbukkit.v1_16_R2.CraftServer in project Nokaut by smaks6.
the class CreateNPC method spawnNPC.
private EntityPlayer spawnNPC() {
Location location = znokautowany.getLocation();
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorld(znokautowany.getWorld().getName())).getHandle();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ChatColor.RED + "*Nokaut*");
gameProfile.getProperties().putAll(((CraftPlayer) znokautowany).getHandle().getProfile().getProperties());
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
npc.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
npc.setPose(EntityPose.SWIMMING);
PlayerConnection connection = ((CraftPlayer) see).getHandle().playerConnection;
npc.setPose(EntityPose.SWIMMING);
DataWatcher watcher = npc.getDataWatcher();
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), watcher, false));
connection.sendPacket(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.yaw * 256 / 360)));
CraftPlayer craftPlayer = npc.getBukkitEntity();
craftPlayer.setCollidable(false);
return npc;
}
use of org.bukkit.craftbukkit.v1_16_R2.CraftServer in project Nokaut by smaks6.
the class CreateNPC method spawnNPC.
private EntityPlayer spawnNPC() {
Location location = znokautowany.getLocation();
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorld(znokautowany.getWorld().getName())).getHandle();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ChatColor.RED + "*Nokaut*");
gameProfile.getProperties().putAll(((CraftPlayer) znokautowany).getHandle().getProfile().getProperties());
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
npc.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
// npc.setPose(EntityPose.SWIMMING);
PlayerConnection connection = ((CraftPlayer) see).getHandle().playerConnection;
// npc.setPose(EntityPose.SWIMMING);
DataWatcher watcher = npc.getDataWatcher();
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), watcher, false));
connection.sendPacket(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.yaw * 256 / 360)));
CraftPlayer craftPlayer = npc.getBukkitEntity();
craftPlayer.setCollidable(false);
return npc;
}
use of org.bukkit.craftbukkit.v1_16_R2.CraftServer in project Magma by magmafoundation.
the class CraftEventFactory method canBuild.
// helper methods
private static boolean canBuild(CraftWorld world, Player player, int x, int z) {
WorldServer worldServer = world.getHandle();
int spawnSize = Bukkit.getServer().getSpawnRadius();
if (world.getHandle().dimension != 0) {
return true;
}
if (spawnSize <= 0) {
return true;
}
if (((CraftServer) Bukkit.getServer()).getHandle().getOppedPlayers().isEmpty()) {
return true;
}
if (player.isOp()) {
return true;
}
BlockPos chunkcoordinates = worldServer.getSpawnPoint();
int distanceFromSpawn = Math.max(Math.abs(x - chunkcoordinates.getX()), Math.abs(z - chunkcoordinates.getZ()));
return distanceFromSpawn > spawnSize;
}
use of org.bukkit.craftbukkit.v1_16_R2.CraftServer in project Magma by magmafoundation.
the class CraftEventFactory method callPlayerInteractEvent.
public static PlayerInteractEvent callPlayerInteractEvent(EntityPlayer who, Action action, BlockPos position, EnumFacing direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = null;
if (position != null) {
blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
} else {
switch(action) {
case LEFT_CLICK_BLOCK:
action = Action.LEFT_CLICK_AIR;
break;
case RIGHT_CLICK_BLOCK:
action = Action.RIGHT_CLICK_AIR;
break;
}
}
BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
itemInHand = null;
}
PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
if (cancelledBlock) {
event.setUseInteractedBlock(Event.Result.DENY);
}
craftServer.getPluginManager().callEvent(event);
return event;
}
Aggregations