Add guided waypoint msg

This commit is contained in:
fullwall 2023-04-03 22:40:04 +08:00
parent a82e39fbbc
commit d6ffa085a0
20 changed files with 182 additions and 72 deletions

View File

@ -146,10 +146,10 @@ public class SkinTrait extends Trait {
} }
/** /**
* Sets the skin data directly, respawning the NPC if spawned * Sets the skin data directly, respawning the NPC if spawned.
* *
* @param skinName * @param skinName
* Skin name, for caching purposes * Skin name or cache key
* @param signature * @param signature
* {@link #getSignature()} * {@link #getSignature()}
* @param data * @param data

View File

@ -238,7 +238,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
}; };
} }
private final class LinearWaypointEditor extends WaypointEditor { private class LinearWaypointEditor extends WaypointEditor {
Conversation conversation; Conversation conversation;
boolean editing = true; boolean editing = true;
EntityMarkers<Waypoint> markers; EntityMarkers<Waypoint> markers;
@ -324,12 +324,9 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
String message = event.getMessage(); String message = event.getMessage();
if (message.equalsIgnoreCase("triggers")) { if (message.equalsIgnoreCase("triggers")) {
event.setCancelled(true); event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
@Override conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
public void run() { conversation.addConversationAbandonedListener(e -> conversation = null);
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
conversation.addConversationAbandonedListener(e -> conversation = null);
}
}); });
} else if (message.equalsIgnoreCase("clear")) { } else if (message.equalsIgnoreCase("clear")) {
event.setCancelled(true); event.setCancelled(true);

View File

@ -1,13 +1,90 @@
package net.citizensnpcs.util; package net.citizensnpcs.util;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
public interface EntityPacketTracker extends Runnable { public interface EntityPacketTracker extends Runnable {
public void link(Player player); public void link(Player player);
public void unlink(Player player); public void unlink(Player player);
public void unlinkAll(Consumer<Player> callback); public void unlinkAll(Consumer<Player> callback);
public static class PacketAggregator {
private final Set<PlayerConnection> connections = Sets.newHashSet();
private List<Object> packets;
public void add(UUID uuid, Consumer<Object> conn) {
connections.add(new PlayerConnection(uuid, conn));
}
public void removeConnection(UUID uuid) {
connections.remove(new PlayerConnection(uuid, null));
}
public void send(Object packet) {
if (packets != null) {
packets.add(packet);
return;
}
for (PlayerConnection conn : connections) {
conn.conn.accept(packet);
}
}
public void startBundling() {
packets = Lists.newArrayList();
}
public void stopBundlingAndSend() {
Iterable<Object> packets = NMS.createBundlePacket(this.packets);
this.packets = null;
for (Object packet : packets) {
for (PlayerConnection conn : connections) {
conn.conn.accept(packet);
}
}
}
private static class PlayerConnection {
Consumer<Object> conn;
UUID uuid;
public PlayerConnection(UUID uuid, Consumer<Object> conn) {
this.uuid = uuid;
this.conn = conn;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
PlayerConnection other = (PlayerConnection) obj;
if (uuid == null) {
if (other.uuid != null) {
return false;
}
} else if (!uuid.equals(other.uuid)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return 31 + ((uuid == null) ? 0 : uuid.hashCode());
}
}
}
} }

View File

@ -142,6 +142,7 @@ public class Messages {
public static final String GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE = "citizens.editors.waypoints.guided.added-guide"; public static final String GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE = "citizens.editors.waypoints.guided.added-guide";
public static final String GUIDED_WAYPOINT_EDITOR_ALREADY_TAKEN = "citizens.editors.waypoints.guided.already-taken"; public static final String GUIDED_WAYPOINT_EDITOR_ALREADY_TAKEN = "citizens.editors.waypoints.guided.already-taken";
public static final String GUIDED_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.guided.begin"; public static final String GUIDED_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.guided.begin";
public static final String GUIDED_WAYPOINT_EDITOR_DISTANCE_SET = "citizens.editors.waypoints.guided.distance-set";
public static final String GUIDED_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.guided.end"; public static final String GUIDED_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.guided.end";
public static final String HEADONLY_SET = "citizens.commands.npc.lookclose.headonly-set"; public static final String HEADONLY_SET = "citizens.commands.npc.lookclose.headonly-set";
public static final String HEADONLY_UNSET = "citizens.commands.npc.lookclose.headonly-unset"; public static final String HEADONLY_UNSET = "citizens.commands.npc.lookclose.headonly-unset";

View File

@ -55,6 +55,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
import net.citizensnpcs.npc.skin.SkinnableEntity; import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose; import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState; import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
public class NMS { public class NMS {
private NMS() { private NMS() {
@ -118,8 +119,16 @@ public class NMS {
* an Exception like it should. * an Exception like it should.
*/ */
public static Iterable<Object> createBundlePacket(List<Object> packets) {
return BRIDGE.createBundlePacket(packets);
}
public static EntityPacketTracker createPacketTracker(Entity entity) { public static EntityPacketTracker createPacketTracker(Entity entity) {
return BRIDGE.createPacketTracker(entity); return createPacketTracker(entity, new PacketAggregator());
}
public static EntityPacketTracker createPacketTracker(Entity entity, PacketAggregator agg) {
return BRIDGE.createPacketTracker(entity, agg);
} }
public static GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable { public static GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable {

View File

@ -41,6 +41,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
import net.citizensnpcs.npc.skin.SkinnableEntity; import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose; import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState; import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
public interface NMSBridge { public interface NMSBridge {
default void activate(Entity entity) { default void activate(Entity entity) {
@ -54,10 +55,12 @@ public interface NMSBridge {
public void cancelMoveDestination(Entity entity); public void cancelMoveDestination(Entity entity);
default public EntityPacketTracker createPacketTracker(Entity entity) { public default Iterable<Object> createBundlePacket(List<Object> packets) {
throw new UnsupportedOperationException(); return packets;
} }
public EntityPacketTracker createPacketTracker(Entity entity, PacketAggregator agg);
public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable; public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable;
public BlockBreaker getBlockBreaker(Entity entity, Block targetBlock, BlockBreakerConfiguration config); public BlockBreaker getBlockBreaker(Entity entity, Block targetBlock, BlockBreakerConfiguration config);
@ -80,9 +83,9 @@ public interface NMSBridge {
public float getHorizontalMovement(Entity entity); public float getHorizontalMovement(Entity entity);
public CompoundTag getNBT(ItemStack item); public CompoundTag getNBT(ItemStack item);;
public NPC getNPC(Entity entity);; public NPC getNPC(Entity entity);
public List<Entity> getPassengers(Entity entity); public List<Entity> getPassengers(Entity entity);
@ -145,9 +148,9 @@ public interface NMSBridge {
public void removeFromServerPlayerList(Player player); public void removeFromServerPlayerList(Player player);
public void removeFromWorld(org.bukkit.entity.Entity entity); public void removeFromWorld(org.bukkit.entity.Entity entity);;
public void removeHookIfNecessary(NPCRegistry npcRegistry, FishHook entity);; public void removeHookIfNecessary(NPCRegistry npcRegistry, FishHook entity);
public void replaceTrackerEntry(Entity entity); public void replaceTrackerEntry(Entity entity);
@ -170,7 +173,7 @@ public interface NMSBridge {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void setBodyYaw(Entity entity, float yaw); public void setBodyYaw(Entity entity, float yaw);;
public void setBoundingBox(Entity entity, BoundingBox box);; public void setBoundingBox(Entity entity, BoundingBox box);;
@ -178,11 +181,11 @@ public interface NMSBridge {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
}; };
public void setCustomName(Entity entity, Object component, String string);; public void setCustomName(Entity entity, Object component, String string);
public void setDestination(Entity entity, double x, double y, double z, float speed); public void setDestination(Entity entity, double x, double y, double z, float speed);;
public void setDimensions(Entity entity, EntityDim desired);; public void setDimensions(Entity entity, EntityDim desired);
public void setEndermanAngry(Enderman enderman, boolean angry); public void setEndermanAngry(Enderman enderman, boolean angry);

View File

@ -407,6 +407,7 @@ citizens.editors.waypoints.guided.begin=Entered the guided waypoint editor! The
citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint which the NPC will follow on the way to their destination. citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint which the NPC will follow on the way to their destination.
citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint which the NPC will randomly pathfind between. citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint which the NPC will randomly pathfind between.
citizens.editors.waypoints.guided.already-taken=There is already a waypoint here. citizens.editors.waypoints.guided.already-taken=There is already a waypoint here.
citizens.editors.waypoints.guided.distance-set=Distance between guides set to [[{0}]].
citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]] total). citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]] total).
citizens.editors.waypoints.linear.begin=<green>=== [[Linear Waypoint Editor]] ===<br> [[Left click]] to add a waypoint, [[right click]] to remove it.<br> Right click while sneaking to select and remove points.<br> Type [[markers]] to hide waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints,<br> [[cycle]] to cycle waypoints instead of looping. citizens.editors.waypoints.linear.begin=<green>=== [[Linear Waypoint Editor]] ===<br> [[Left click]] to add a waypoint, [[right click]] to remove it.<br> Right click while sneaking to select and remove points.<br> Type [[markers]] to hide waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints,<br> [[cycle]] to cycle waypoints instead of looping.
citizens.editors.waypoints.linear.selected-waypoint=Selected waypoint at {0}. Sneak + right click again to remove this waypoint. citizens.editors.waypoints.linear.selected-waypoint=Selected waypoint at {0}. Sneak + right click again to remove this waypoint.

View File

@ -180,6 +180,7 @@ import net.citizensnpcs.trait.versioned.ShulkerTrait;
import net.citizensnpcs.trait.versioned.SnowmanTrait; import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -318,7 +319,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
// TODO: configuration / use minecraft defaults for this // TODO: configuration / use minecraft defaults for this
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80; int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;

View File

@ -197,6 +197,7 @@ import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.trait.versioned.SpellcasterTrait; import net.citizensnpcs.trait.versioned.SpellcasterTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -339,7 +340,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
// TODO: configuration / use minecraft defaults for this // TODO: configuration / use minecraft defaults for this
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80; int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;

View File

@ -200,6 +200,7 @@ import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.trait.versioned.SpellcasterTrait; import net.citizensnpcs.trait.versioned.SpellcasterTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -344,7 +345,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
// TODO: configuration / use minecraft defaults for this // TODO: configuration / use minecraft defaults for this
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80; int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;

View File

@ -213,6 +213,7 @@ import net.citizensnpcs.trait.versioned.SpellcasterTrait;
import net.citizensnpcs.trait.versioned.TropicalFishTrait; import net.citizensnpcs.trait.versioned.TropicalFishTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -364,7 +365,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
// TODO: configuration / use minecraft defaults for this // TODO: configuration / use minecraft defaults for this
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80; int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;

View File

@ -223,6 +223,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
import net.citizensnpcs.trait.versioned.VillagerTrait; import net.citizensnpcs.trait.versioned.VillagerTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -403,15 +404,12 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
Set<EntityPlayer> linked = Sets.newIdentityHashSet(); Set<EntityPlayer> linked = Sets.newIdentityHashSet();
EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle, EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle,
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), packet -> { handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), agg::send,
for (EntityPlayer link : linked) { linked);
link.playerConnection.sendPacket(packet);
}
}, linked);
return new EntityPacketTracker() { return new EntityPacketTracker() {
@Override @Override
public void link(Player player) { public void link(Player player) {
@ -419,6 +417,7 @@ public class NMSImpl implements NMSBridge {
handle.dead = false; handle.dead = false;
tracker.b(p); tracker.b(p);
linked.add(p); linked.add(p);
agg.add(p.getUniqueID(), packet -> p.playerConnection.sendPacket((Packet<?>) packet));
handle.dead = true; handle.dead = true;
} }
@ -432,6 +431,7 @@ public class NMSImpl implements NMSBridge {
EntityPlayer p = (EntityPlayer) getHandle(player); EntityPlayer p = (EntityPlayer) getHandle(player);
tracker.a(p); tracker.a(p);
linked.remove(p); linked.remove(p);
agg.removeConnection(p.getUniqueID());
} }
@Override @Override

View File

@ -225,6 +225,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
import net.citizensnpcs.trait.versioned.VillagerTrait; import net.citizensnpcs.trait.versioned.VillagerTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -418,15 +419,12 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
Set<EntityPlayer> linked = Sets.newIdentityHashSet(); Set<EntityPlayer> linked = Sets.newIdentityHashSet();
EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle, EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle,
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), packet -> { handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), agg::send,
for (EntityPlayer link : linked) { linked);
link.playerConnection.sendPacket(packet);
}
}, linked);
return new EntityPacketTracker() { return new EntityPacketTracker() {
@Override @Override
public void link(Player player) { public void link(Player player) {
@ -434,6 +432,7 @@ public class NMSImpl implements NMSBridge {
handle.dead = false; handle.dead = false;
tracker.b(p); tracker.b(p);
linked.add(p); linked.add(p);
agg.add(p.getUniqueID(), packet -> p.playerConnection.sendPacket((Packet<?>) packet));
handle.dead = true; handle.dead = true;
} }
@ -447,6 +446,7 @@ public class NMSImpl implements NMSBridge {
EntityPlayer p = (EntityPlayer) getHandle(player); EntityPlayer p = (EntityPlayer) getHandle(player);
tracker.a(p); tracker.a(p);
linked.remove(p); linked.remove(p);
agg.removeConnection(p.getUniqueID());
} }
@Override @Override

View File

@ -233,6 +233,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
import net.citizensnpcs.trait.versioned.VillagerTrait; import net.citizensnpcs.trait.versioned.VillagerTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -432,15 +433,12 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
Set<EntityPlayer> linked = Sets.newIdentityHashSet(); Set<EntityPlayer> linked = Sets.newIdentityHashSet();
EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle, EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle,
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), packet -> { handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), agg::send,
for (EntityPlayer link : linked) { linked);
link.playerConnection.sendPacket(packet);
}
}, linked);
return new EntityPacketTracker() { return new EntityPacketTracker() {
@Override @Override
public void link(Player player) { public void link(Player player) {
@ -448,6 +446,7 @@ public class NMSImpl implements NMSBridge {
handle.dead = false; handle.dead = false;
tracker.b(p); tracker.b(p);
linked.add(p); linked.add(p);
agg.add(p.getUniqueID(), packet -> p.playerConnection.sendPacket((Packet<?>) packet));
handle.dead = true; handle.dead = true;
} }
@ -461,6 +460,7 @@ public class NMSImpl implements NMSBridge {
EntityPlayer p = (EntityPlayer) getHandle(player); EntityPlayer p = (EntityPlayer) getHandle(player);
tracker.a(p); tracker.a(p);
linked.remove(p); linked.remove(p);
agg.removeConnection(p.getUniqueID());
} }
@Override @Override

View File

@ -236,6 +236,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
import net.citizensnpcs.trait.versioned.VillagerTrait; import net.citizensnpcs.trait.versioned.VillagerTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -446,15 +447,11 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet(); Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet();
ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(), ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(),
handle.getType().trackDeltas(), packet -> { handle.getType().trackDeltas(), agg::send, linked);
for (ServerPlayerConnection link : linked) {
link.send(packet);
}
}, linked);
return new EntityPacketTracker() { return new EntityPacketTracker() {
@Override @Override
public void link(Player player) { public void link(Player player) {
@ -462,6 +459,7 @@ public class NMSImpl implements NMSBridge {
handle.unsetRemoved(); handle.unsetRemoved();
tracker.addPairing(p); tracker.addPairing(p);
linked.add(p.connection); linked.add(p.connection);
agg.add(p.getUUID(), packet -> p.connection.send((Packet<?>) packet));
} }
@Override @Override
@ -474,6 +472,7 @@ public class NMSImpl implements NMSBridge {
ServerPlayer p = (ServerPlayer) getHandle(player); ServerPlayer p = (ServerPlayer) getHandle(player);
tracker.removePairing(p); tracker.removePairing(p);
linked.remove(p.connection); linked.remove(p.connection);
agg.removeConnection(p.getUUID());
} }
@Override @Override

View File

@ -237,6 +237,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
import net.citizensnpcs.trait.versioned.VillagerTrait; import net.citizensnpcs.trait.versioned.VillagerTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -452,15 +453,11 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet(); Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet();
ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(), ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(),
handle.getType().trackDeltas(), packet -> { handle.getType().trackDeltas(), agg::send, linked);
for (ServerPlayerConnection link : linked) {
link.send(packet);
}
}, linked);
return new EntityPacketTracker() { return new EntityPacketTracker() {
@Override @Override
public void link(Player player) { public void link(Player player) {
@ -468,6 +465,7 @@ public class NMSImpl implements NMSBridge {
handle.unsetRemoved(); handle.unsetRemoved();
tracker.addPairing(p); tracker.addPairing(p);
linked.add(p.connection); linked.add(p.connection);
agg.add(p.getUUID(), packet -> p.connection.send((Packet<?>) packet));
} }
@Override @Override
@ -480,6 +478,7 @@ public class NMSImpl implements NMSBridge {
ServerPlayer p = (ServerPlayer) getHandle(player); ServerPlayer p = (ServerPlayer) getHandle(player);
tracker.removePairing(p); tracker.removePairing(p);
linked.remove(p.connection); linked.remove(p.connection);
agg.removeConnection(p.getUUID());
} }
@Override @Override

View File

@ -3,7 +3,9 @@ package net.citizensnpcs.nms.v1_19_R3.entity.nonliving;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R3.CraftServer; import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_19_R3.entity.CraftFishHook;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
@ -38,6 +40,21 @@ public class FishingHookController extends MobEntityController {
super(EntityFishingHookNPC.class); super(EntityFishingHookNPC.class);
} }
@Override
protected org.bukkit.entity.Entity createEntity(Location at, NPC npc) {
ServerLevel level = ((CraftWorld) at.getWorld()).getHandle();
ServerPlayer sp = new ServerPlayer(level.getServer(), level,
new GameProfile(UUID.randomUUID(), "dummyfishhook")) {
};
sp.setPos(at.getX(), at.getY(), at.getZ());
sp.setYRot(at.getYaw());
sp.setXRot(at.getPitch());
sp.setHealth(20F);
sp.getInventory().items.set(sp.getInventory().selected, new ItemStack(Items.FISHING_ROD, 1));
final EntityFishingHookNPC handle = new EntityFishingHookNPC(EntityType.FISHING_BOBBER, level, npc, sp);
return handle.getBukkitEntity();
}
@Override @Override
public FishHook getBukkitEntity() { public FishHook getBukkitEntity() {
return (FishHook) super.getBukkitEntity(); return (FishHook) super.getBukkitEntity();
@ -47,13 +64,11 @@ public class FishingHookController extends MobEntityController {
private final CitizensNPC npc; private final CitizensNPC npc;
public EntityFishingHookNPC(EntityType<? extends FishingHook> types, Level level) { public EntityFishingHookNPC(EntityType<? extends FishingHook> types, Level level) {
this(types, level, null); this(types, level, null, null);
} }
public EntityFishingHookNPC(EntityType<? extends FishingHook> types, Level level, NPC npc) { public EntityFishingHookNPC(EntityType<? extends FishingHook> types, Level level, NPC npc, ServerPlayer sp) {
super(new ServerPlayer(((ServerLevel) level).getServer(), (ServerLevel) level, super(sp, level, 0, 0);
new GameProfile(UUID.randomUUID(), "dummyfishhook")) {
}, level, 0, 0);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
} }
@ -122,10 +137,7 @@ public class FishingHookController extends MobEntityController {
@Override @Override
public void tick() { public void tick() {
if (npc != null) { if (npc != null) {
((ServerPlayer) getPlayerOwner()).setHealth(20F);
getPlayerOwner().unsetRemoved(); getPlayerOwner().unsetRemoved();
((ServerPlayer) getPlayerOwner()).getInventory().items.set(
((ServerPlayer) getPlayerOwner()).getInventory().selected, new ItemStack(Items.FISHING_ROD, 1));
NMSImpl.setLife(this, 0); NMSImpl.setLife(this, 0);
npc.update(); npc.update();
} else { } else {

View File

@ -55,6 +55,7 @@ import org.bukkit.util.Vector;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -257,6 +258,7 @@ import net.citizensnpcs.trait.versioned.VillagerTrait;
import net.citizensnpcs.trait.versioned.WardenTrait; import net.citizensnpcs.trait.versioned.WardenTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -270,6 +272,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
@ -476,15 +479,17 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { @SuppressWarnings("rawtypes")
public Iterable<Object> createBundlePacket(List source) {
return source.isEmpty() ? ImmutableList.of() : ImmutableList.of(new ClientboundBundlePacket(source));
}
@Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet(); Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet();
ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(), ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(),
handle.getType().trackDeltas(), packet -> { handle.getType().trackDeltas(), agg::send, linked);
for (ServerPlayerConnection link : linked) {
link.send(packet);
}
}, linked);
return new EntityPacketTracker() { return new EntityPacketTracker() {
@Override @Override
public void link(Player player) { public void link(Player player) {
@ -492,6 +497,7 @@ public class NMSImpl implements NMSBridge {
handle.unsetRemoved(); handle.unsetRemoved();
tracker.addPairing(p); tracker.addPairing(p);
linked.add(p.connection); linked.add(p.connection);
agg.add(p.getUUID(), packet -> p.connection.send((Packet<?>) packet));
} }
@Override @Override
@ -504,6 +510,7 @@ public class NMSImpl implements NMSBridge {
ServerPlayer p = (ServerPlayer) getHandle(player); ServerPlayer p = (ServerPlayer) getHandle(player);
tracker.removePairing(p); tracker.removePairing(p);
linked.remove(p.connection); linked.remove(p.connection);
agg.removeConnection(p.getUUID());
} }
@Override @Override
@ -728,7 +735,7 @@ public class NMSImpl implements NMSBridge {
@Override @Override
public MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final Location dest, public MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) { final NavigatorParameters params) {
return getTargetNavigator(entity, params, (input) -> { return getTargetNavigator(entity, params, input -> {
return input.moveTo(dest.getX(), dest.getY(), dest.getZ(), params.speed()); return input.moveTo(dest.getX(), dest.getY(), dest.getZ(), params.speed());
}); });
} }

View File

@ -164,6 +164,7 @@ import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.RotationTrait;
import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker; import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge; import net.citizensnpcs.util.NMSBridge;
@ -299,7 +300,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);
// TODO: configuration / use minecraft defaults for this // TODO: configuration / use minecraft defaults for this
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80; int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;