mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 12:15:53 +01:00
Add guided waypoint msg
This commit is contained in:
parent
a82e39fbbc
commit
d6ffa085a0
@ -46,7 +46,7 @@
|
||||
<repository>
|
||||
<id>viaversion-repo</id>
|
||||
<url>https://repo.viaversion.com</url>
|
||||
</repository>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -55,7 +55,7 @@
|
||||
<version>${craftbukkit.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
|
@ -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
|
||||
* Skin name, for caching purposes
|
||||
* Skin name or cache key
|
||||
* @param signature
|
||||
* {@link #getSignature()}
|
||||
* @param data
|
||||
|
@ -238,7 +238,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
};
|
||||
}
|
||||
|
||||
private final class LinearWaypointEditor extends WaypointEditor {
|
||||
private class LinearWaypointEditor extends WaypointEditor {
|
||||
Conversation conversation;
|
||||
boolean editing = true;
|
||||
EntityMarkers<Waypoint> markers;
|
||||
@ -324,12 +324,9 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
String message = event.getMessage();
|
||||
if (message.equalsIgnoreCase("triggers")) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
|
||||
conversation.addConversationAbandonedListener(e -> conversation = null);
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
|
||||
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
|
||||
conversation.addConversationAbandonedListener(e -> conversation = null);
|
||||
});
|
||||
} else if (message.equalsIgnoreCase("clear")) {
|
||||
event.setCancelled(true);
|
||||
|
@ -1,13 +1,90 @@
|
||||
package net.citizensnpcs.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public interface EntityPacketTracker extends Runnable {
|
||||
public void link(Player player);
|
||||
|
||||
public void unlink(Player player);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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_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_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 HEADONLY_SET = "citizens.commands.npc.lookclose.headonly-set";
|
||||
public static final String HEADONLY_UNSET = "citizens.commands.npc.lookclose.headonly-unset";
|
||||
|
@ -55,6 +55,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
|
||||
import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
|
||||
public class NMS {
|
||||
private NMS() {
|
||||
@ -118,8 +119,16 @@ public class NMS {
|
||||
* an Exception like it should.
|
||||
*/
|
||||
|
||||
public static Iterable<Object> createBundlePacket(List<Object> packets) {
|
||||
return BRIDGE.createBundlePacket(packets);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -41,6 +41,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
|
||||
import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
|
||||
public interface NMSBridge {
|
||||
default void activate(Entity entity) {
|
||||
@ -54,10 +55,12 @@ public interface NMSBridge {
|
||||
|
||||
public void cancelMoveDestination(Entity entity);
|
||||
|
||||
default public EntityPacketTracker createPacketTracker(Entity entity) {
|
||||
throw new UnsupportedOperationException();
|
||||
public default Iterable<Object> createBundlePacket(List<Object> packets) {
|
||||
return packets;
|
||||
}
|
||||
|
||||
public EntityPacketTracker createPacketTracker(Entity entity, PacketAggregator agg);
|
||||
|
||||
public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable;
|
||||
|
||||
public BlockBreaker getBlockBreaker(Entity entity, Block targetBlock, BlockBreakerConfiguration config);
|
||||
@ -80,9 +83,9 @@ public interface NMSBridge {
|
||||
|
||||
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);
|
||||
|
||||
@ -145,9 +148,9 @@ public interface NMSBridge {
|
||||
|
||||
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);
|
||||
|
||||
@ -170,7 +173,7 @@ public interface NMSBridge {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void setBodyYaw(Entity entity, float yaw);
|
||||
public void setBodyYaw(Entity entity, float yaw);;
|
||||
|
||||
public void setBoundingBox(Entity entity, BoundingBox box);;
|
||||
|
||||
@ -178,11 +181,11 @@ public interface NMSBridge {
|
||||
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);
|
||||
|
||||
|
@ -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-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.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.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.
|
||||
|
@ -180,6 +180,7 @@ import net.citizensnpcs.trait.versioned.ShulkerTrait;
|
||||
import net.citizensnpcs.trait.versioned.SnowmanTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -318,7 +319,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
// TODO: configuration / use minecraft defaults for this
|
||||
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;
|
||||
|
@ -197,6 +197,7 @@ import net.citizensnpcs.trait.versioned.SnowmanTrait;
|
||||
import net.citizensnpcs.trait.versioned.SpellcasterTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -339,7 +340,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
// TODO: configuration / use minecraft defaults for this
|
||||
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;
|
||||
|
@ -200,6 +200,7 @@ import net.citizensnpcs.trait.versioned.SnowmanTrait;
|
||||
import net.citizensnpcs.trait.versioned.SpellcasterTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -344,7 +345,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
// TODO: configuration / use minecraft defaults for this
|
||||
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;
|
||||
|
@ -213,6 +213,7 @@ import net.citizensnpcs.trait.versioned.SpellcasterTrait;
|
||||
import net.citizensnpcs.trait.versioned.TropicalFishTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -364,7 +365,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
// TODO: configuration / use minecraft defaults for this
|
||||
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;
|
||||
|
@ -223,6 +223,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
|
||||
import net.citizensnpcs.trait.versioned.VillagerTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -403,15 +404,12 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
Set<EntityPlayer> linked = Sets.newIdentityHashSet();
|
||||
EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle,
|
||||
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), packet -> {
|
||||
for (EntityPlayer link : linked) {
|
||||
link.playerConnection.sendPacket(packet);
|
||||
}
|
||||
}, linked);
|
||||
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), agg::send,
|
||||
linked);
|
||||
return new EntityPacketTracker() {
|
||||
@Override
|
||||
public void link(Player player) {
|
||||
@ -419,6 +417,7 @@ public class NMSImpl implements NMSBridge {
|
||||
handle.dead = false;
|
||||
tracker.b(p);
|
||||
linked.add(p);
|
||||
agg.add(p.getUniqueID(), packet -> p.playerConnection.sendPacket((Packet<?>) packet));
|
||||
handle.dead = true;
|
||||
}
|
||||
|
||||
@ -432,6 +431,7 @@ public class NMSImpl implements NMSBridge {
|
||||
EntityPlayer p = (EntityPlayer) getHandle(player);
|
||||
tracker.a(p);
|
||||
linked.remove(p);
|
||||
agg.removeConnection(p.getUniqueID());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -225,6 +225,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
|
||||
import net.citizensnpcs.trait.versioned.VillagerTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -418,15 +419,12 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
Set<EntityPlayer> linked = Sets.newIdentityHashSet();
|
||||
EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle,
|
||||
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), packet -> {
|
||||
for (EntityPlayer link : linked) {
|
||||
link.playerConnection.sendPacket(packet);
|
||||
}
|
||||
}, linked);
|
||||
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), agg::send,
|
||||
linked);
|
||||
return new EntityPacketTracker() {
|
||||
@Override
|
||||
public void link(Player player) {
|
||||
@ -434,6 +432,7 @@ public class NMSImpl implements NMSBridge {
|
||||
handle.dead = false;
|
||||
tracker.b(p);
|
||||
linked.add(p);
|
||||
agg.add(p.getUniqueID(), packet -> p.playerConnection.sendPacket((Packet<?>) packet));
|
||||
handle.dead = true;
|
||||
}
|
||||
|
||||
@ -447,6 +446,7 @@ public class NMSImpl implements NMSBridge {
|
||||
EntityPlayer p = (EntityPlayer) getHandle(player);
|
||||
tracker.a(p);
|
||||
linked.remove(p);
|
||||
agg.removeConnection(p.getUniqueID());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,6 +233,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
|
||||
import net.citizensnpcs.trait.versioned.VillagerTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -432,15 +433,12 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
Set<EntityPlayer> linked = Sets.newIdentityHashSet();
|
||||
EntityTrackerEntry tracker = new EntityTrackerEntry((WorldServer) handle.world, handle,
|
||||
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), packet -> {
|
||||
for (EntityPlayer link : linked) {
|
||||
link.playerConnection.sendPacket(packet);
|
||||
}
|
||||
}, linked);
|
||||
handle.getEntityType().getUpdateInterval(), handle.getEntityType().isDeltaTracking(), agg::send,
|
||||
linked);
|
||||
return new EntityPacketTracker() {
|
||||
@Override
|
||||
public void link(Player player) {
|
||||
@ -448,6 +446,7 @@ public class NMSImpl implements NMSBridge {
|
||||
handle.dead = false;
|
||||
tracker.b(p);
|
||||
linked.add(p);
|
||||
agg.add(p.getUniqueID(), packet -> p.playerConnection.sendPacket((Packet<?>) packet));
|
||||
handle.dead = true;
|
||||
}
|
||||
|
||||
@ -461,6 +460,7 @@ public class NMSImpl implements NMSBridge {
|
||||
EntityPlayer p = (EntityPlayer) getHandle(player);
|
||||
tracker.a(p);
|
||||
linked.remove(p);
|
||||
agg.removeConnection(p.getUniqueID());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -236,6 +236,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
|
||||
import net.citizensnpcs.trait.versioned.VillagerTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -446,15 +447,11 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet();
|
||||
ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(),
|
||||
handle.getType().trackDeltas(), packet -> {
|
||||
for (ServerPlayerConnection link : linked) {
|
||||
link.send(packet);
|
||||
}
|
||||
}, linked);
|
||||
handle.getType().trackDeltas(), agg::send, linked);
|
||||
return new EntityPacketTracker() {
|
||||
@Override
|
||||
public void link(Player player) {
|
||||
@ -462,6 +459,7 @@ public class NMSImpl implements NMSBridge {
|
||||
handle.unsetRemoved();
|
||||
tracker.addPairing(p);
|
||||
linked.add(p.connection);
|
||||
agg.add(p.getUUID(), packet -> p.connection.send((Packet<?>) packet));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -474,6 +472,7 @@ public class NMSImpl implements NMSBridge {
|
||||
ServerPlayer p = (ServerPlayer) getHandle(player);
|
||||
tracker.removePairing(p);
|
||||
linked.remove(p.connection);
|
||||
agg.removeConnection(p.getUUID());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -237,6 +237,7 @@ import net.citizensnpcs.trait.versioned.TropicalFishTrait;
|
||||
import net.citizensnpcs.trait.versioned.VillagerTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -452,15 +453,11 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet();
|
||||
ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(),
|
||||
handle.getType().trackDeltas(), packet -> {
|
||||
for (ServerPlayerConnection link : linked) {
|
||||
link.send(packet);
|
||||
}
|
||||
}, linked);
|
||||
handle.getType().trackDeltas(), agg::send, linked);
|
||||
return new EntityPacketTracker() {
|
||||
@Override
|
||||
public void link(Player player) {
|
||||
@ -468,6 +465,7 @@ public class NMSImpl implements NMSBridge {
|
||||
handle.unsetRemoved();
|
||||
tracker.addPairing(p);
|
||||
linked.add(p.connection);
|
||||
agg.add(p.getUUID(), packet -> p.connection.send((Packet<?>) packet));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -480,6 +478,7 @@ public class NMSImpl implements NMSBridge {
|
||||
ServerPlayer p = (ServerPlayer) getHandle(player);
|
||||
tracker.removePairing(p);
|
||||
linked.remove(p.connection);
|
||||
agg.removeConnection(p.getUUID());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,7 +3,9 @@ package net.citizensnpcs.nms.v1_19_R3.entity.nonliving;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
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.CraftFishHook;
|
||||
import org.bukkit.entity.FishHook;
|
||||
@ -38,6 +40,21 @@ public class FishingHookController extends MobEntityController {
|
||||
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
|
||||
public FishHook getBukkitEntity() {
|
||||
return (FishHook) super.getBukkitEntity();
|
||||
@ -47,13 +64,11 @@ public class FishingHookController extends MobEntityController {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
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) {
|
||||
super(new ServerPlayer(((ServerLevel) level).getServer(), (ServerLevel) level,
|
||||
new GameProfile(UUID.randomUUID(), "dummyfishhook")) {
|
||||
}, level, 0, 0);
|
||||
public EntityFishingHookNPC(EntityType<? extends FishingHook> types, Level level, NPC npc, ServerPlayer sp) {
|
||||
super(sp, level, 0, 0);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
@ -122,10 +137,7 @@ public class FishingHookController extends MobEntityController {
|
||||
@Override
|
||||
public void tick() {
|
||||
if (npc != null) {
|
||||
((ServerPlayer) getPlayerOwner()).setHealth(20F);
|
||||
getPlayerOwner().unsetRemoved();
|
||||
((ServerPlayer) getPlayerOwner()).getInventory().items.set(
|
||||
((ServerPlayer) getPlayerOwner()).getInventory().selected, new ItemStack(Items.FISHING_ROD, 1));
|
||||
NMSImpl.setLife(this, 0);
|
||||
npc.update();
|
||||
} else {
|
||||
|
@ -55,6 +55,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
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.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
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.contents.LiteralContents;
|
||||
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.ClientboundPlayerInfoRemovePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
|
||||
@ -476,15 +479,17 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@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);
|
||||
Set<ServerPlayerConnection> linked = Sets.newIdentityHashSet();
|
||||
ServerEntity tracker = new ServerEntity((ServerLevel) handle.level, handle, handle.getType().updateInterval(),
|
||||
handle.getType().trackDeltas(), packet -> {
|
||||
for (ServerPlayerConnection link : linked) {
|
||||
link.send(packet);
|
||||
}
|
||||
}, linked);
|
||||
handle.getType().trackDeltas(), agg::send, linked);
|
||||
return new EntityPacketTracker() {
|
||||
@Override
|
||||
public void link(Player player) {
|
||||
@ -492,6 +497,7 @@ public class NMSImpl implements NMSBridge {
|
||||
handle.unsetRemoved();
|
||||
tracker.addPairing(p);
|
||||
linked.add(p.connection);
|
||||
agg.add(p.getUUID(), packet -> p.connection.send((Packet<?>) packet));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -504,6 +510,7 @@ public class NMSImpl implements NMSBridge {
|
||||
ServerPlayer p = (ServerPlayer) getHandle(player);
|
||||
tracker.removePairing(p);
|
||||
linked.remove(p.connection);
|
||||
agg.removeConnection(p.getUUID());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -728,7 +735,7 @@ public class NMSImpl implements NMSBridge {
|
||||
@Override
|
||||
public MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final Location dest,
|
||||
final NavigatorParameters params) {
|
||||
return getTargetNavigator(entity, params, (input) -> {
|
||||
return getTargetNavigator(entity, params, input -> {
|
||||
return input.moveTo(dest.getX(), dest.getY(), dest.getZ(), params.speed());
|
||||
});
|
||||
}
|
||||
|
@ -164,6 +164,7 @@ import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.util.EmptyChannel;
|
||||
import net.citizensnpcs.util.EntityPacketTracker;
|
||||
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.NMSBridge;
|
||||
@ -299,7 +300,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity) {
|
||||
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
|
||||
Entity handle = getHandle(entity);
|
||||
// TODO: configuration / use minecraft defaults for this
|
||||
int visibleDistance = handle instanceof EntityPlayer ? 512 : 80;
|
||||
|
Loading…
Reference in New Issue
Block a user