mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-30 06:33:56 +01:00
Fix player invisibility (note: they will appear on the tab list for now)
This commit is contained in:
parent
b5dfbcade9
commit
35dccc8243
@ -29,10 +29,13 @@ import net.citizensnpcs.trait.Controllable;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.minecraft.server.v1_8_R1.EnumPlayerInfoAction;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutPlayerInfo;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -49,6 +52,7 @@ import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
@ -272,6 +276,16 @@ public class EventListen implements Listener {
|
||||
Bukkit.getPluginManager().callEvent(rightClickEvent);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
for (NPC npc : getAllNPCs()) {
|
||||
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
||||
NMS.sendToOnline(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, ((CraftPlayer) npc
|
||||
.getEntity()).getHandle()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Editor.leave(event.getPlayer());
|
||||
|
@ -299,9 +299,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
break;
|
||||
}
|
||||
}
|
||||
NMS.sendToOnline(getListPacket(getBukkitEntity(), true));
|
||||
// NMS.sendToOnline(getListPacket(getBukkitEntity(), true));
|
||||
if (otherOnline != null) {
|
||||
NMS.sendToOnline(getListPacket(otherOnline, false));
|
||||
// NMS.sendToOnline(getListPacket(otherOnline, false));
|
||||
}
|
||||
NMS.sendPacketsNearby(getBukkitEntity(), current, packets);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -83,8 +84,8 @@ public class HumanController extends AbstractEntityController {
|
||||
npc.data().get("removefromplayerlist", removeFromPlayerList));
|
||||
}
|
||||
}, 1);
|
||||
NMS.sendToOnline(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle));
|
||||
handle.getBukkitEntity().setSleepingIgnored(true);
|
||||
NMS.sendToOnline(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle));
|
||||
return handle.getBukkitEntity();
|
||||
}
|
||||
|
||||
@ -93,6 +94,13 @@ public class HumanController extends AbstractEntityController {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
NMS.sendToOnline(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER,
|
||||
((CraftPlayer) getBukkitEntity()).getHandle()));
|
||||
super.remove();
|
||||
}
|
||||
|
||||
private void updateSkin(final NPC npc, final WorldServer nmsWorld, GameProfile profile) {
|
||||
String skinUUID = npc.data().get(NPC.PLAYER_SKIN_UUID_METADATA);
|
||||
if (skinUUID == null) {
|
||||
|
@ -118,8 +118,9 @@ public class PigZombieController extends MobEntityController {
|
||||
return;
|
||||
}
|
||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||
super.g(x, y, z);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Vector vector = new Vector(x, y, z);
|
||||
|
@ -212,17 +212,18 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private double updateHorizontalSpeed(net.minecraft.server.v1_8_R1.Entity handle, double speed, float speedMod) {
|
||||
private double updateHorizontalSpeed(net.minecraft.server.v1_8_R1.Entity handle,
|
||||
net.minecraft.server.v1_8_R1.Entity passenger, double speed, float speedMod) {
|
||||
double oldSpeed = Math.sqrt(handle.motX * handle.motX + handle.motZ * handle.motZ);
|
||||
double horizontal = ((EntityLiving) handle.passenger).aY;
|
||||
double horizontal = ((EntityLiving) passenger).aY;
|
||||
if (horizontal > 0.0D) {
|
||||
double dXcos = -Math.sin(handle.passenger.yaw * Math.PI / 180.0F);
|
||||
double dXsin = Math.cos(handle.passenger.yaw * Math.PI / 180.0F);
|
||||
double dXcos = -Math.sin(passenger.yaw * Math.PI / 180.0F);
|
||||
double dXsin = Math.cos(passenger.yaw * Math.PI / 180.0F);
|
||||
handle.motX += dXcos * speed * 0.5;
|
||||
handle.motZ += dXsin * speed * 0.5;
|
||||
}
|
||||
handle.motX += handle.passenger.motX * speedMod;
|
||||
handle.motZ += handle.passenger.motZ * speedMod;
|
||||
handle.motX += passenger.motX * speedMod;
|
||||
handle.motZ += passenger.motZ * speedMod;
|
||||
|
||||
double newSpeed = Math.sqrt(handle.motX * handle.motX + handle.motZ * handle.motZ);
|
||||
if (newSpeed > 0.35D) {
|
||||
@ -259,12 +260,13 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
|
||||
@Override
|
||||
public void run(Player rider) {
|
||||
net.minecraft.server.v1_8_R1.Entity handle = getHandle();
|
||||
net.minecraft.server.v1_8_R1.Entity passenger = ((CraftPlayer) rider).getHandle();
|
||||
boolean onGround = handle.onGround;
|
||||
float speedMod = npc.getNavigator().getDefaultParameters()
|
||||
.modifiedSpeed((onGround ? GROUND_SPEED : AIR_SPEED));
|
||||
this.speed = updateHorizontalSpeed(handle, speed, speedMod);
|
||||
speed = updateHorizontalSpeed(handle, passenger, speed, speedMod);
|
||||
|
||||
boolean shouldJump = NMS.shouldJump(handle.passenger);
|
||||
boolean shouldJump = NMS.shouldJump(passenger);
|
||||
if (shouldJump) {
|
||||
if (handle.onGround && jumpTicks == 0) {
|
||||
getHandle().motY = JUMP_VELOCITY;
|
||||
@ -353,8 +355,10 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
|
||||
return;
|
||||
}
|
||||
net.minecraft.server.v1_8_R1.Entity handle = getHandle();
|
||||
this.speed = updateHorizontalSpeed(handle, this.speed, 1F);
|
||||
boolean shouldJump = NMS.shouldJump(handle.passenger);
|
||||
net.minecraft.server.v1_8_R1.Entity passenger = ((CraftPlayer) rider).getHandle();
|
||||
|
||||
speed = updateHorizontalSpeed(handle, passenger, speed, 1F);
|
||||
boolean shouldJump = NMS.shouldJump(passenger);
|
||||
if (shouldJump) {
|
||||
handle.motY = 0.3F;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user