Skip to content

Commit d4fba01

Browse files
committed
Fix packet usage in spacenpc
1 parent 35ea12d commit d4fba01

5 files changed

Lines changed: 33 additions & 18 deletions

File tree

spaceNPC/src/main/java/me/tofaa/entitylib/npc/NPC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void spawn(@NotNull Location location) {
178178
}
179179
entity.setLocation(location);
180180

181-
if (entityType == com.github.retrooper.packetevents.protocol.entity.type.EntityTypes.PLAYER) {
181+
if (entityType == EntityTypes.PLAYER) {
182182
entity.getEntityMeta().setCustomNameVisible(false);
183183
registerScoreboardTeam();
184184
} else if (options.hasDisplayName()) {

spaceNPC/src/main/java/me/tofaa/entitylib/npc/NPCListenerManager.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ public static void register(org.bukkit.plugin.java.JavaPlugin plugin) {
4545
public void onPacketReceive(PacketReceiveEvent event) {
4646
UUID playerId = event.getUser().getUUID();
4747

48-
if (event.getPacketType() == PacketType.Play.Client.USE_ITEM) {
49-
WrapperPlayClientUseItem useItemPacket = new WrapperPlayClientUseItem(event);
50-
playersHoldingShift.add(playerId);
51-
handleInteraction(event, playerId, false, true);
52-
return;
53-
}
48+
// if (event.getPacketType() == PacketType.Play.Client.USE_ITEM) {
49+
// WrapperPlayClientUseItem useItemPacket = new WrapperPlayClientUseItem(event);
50+
// playersHoldingShift.add(playerId);
51+
// useItemPacket.get
52+
// handleInteraction(event, playerId, false, true);
53+
// return;
54+
// }
5455

5556
if (event.getPacketType() == PacketType.Play.Client.INTERACT_ENTITY) {
5657
WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);
@@ -64,9 +65,9 @@ public void onPacketReceive(PacketReceiveEvent event) {
6465
boolean isShift = playersHoldingShift.contains(playerId);
6566

6667
if (isLeftClick) {
67-
handleInteraction(event, playerId, isLeftClick, isShift);
68+
handleInteraction(event, playerId, isLeftClick, isShift, npc);
6869
} else {
69-
handleInteraction(event, playerId, isLeftClick, isShift);
70+
handleInteraction(event, playerId, isLeftClick, isShift, npc);
7071
}
7172
}
7273
}
@@ -90,12 +91,17 @@ public void onPacketReceive(PacketReceiveEvent event) {
9091
});
9192
}
9293

93-
private static void handleInteraction(PacketReceiveEvent event, UUID playerId, boolean isLeftClick, boolean isShift) {
94-
WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);
95-
int entityId = packet.getEntityId();
96-
97-
NPC npc = NPCRegistry.getByEntityId(entityId);
98-
if (npc == null) return;
94+
private static void handleInteraction(
95+
PacketReceiveEvent event,
96+
UUID playerId,
97+
boolean isLeftClick,
98+
boolean isShift,
99+
NPC npc
100+
) {
101+
// WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);
102+
// int entityId = packet.getEntityId();
103+
// NPC npc = NPCRegistry.getByEntityId(npcId);
104+
// if (npc == null) return;
99105

100106
InteractionType interactionType = getInteractionType(isLeftClick, isShift);
101107

spaceNPC/src/main/java/me/tofaa/entitylib/npc/command/NPCCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,8 @@ public List<String> tabComplete(
17801780
"right_click",
17811781
"left_click",
17821782
"shift_right_click",
1783-
"shift_left_click"
1783+
"shift_left_click",
1784+
"any"
17841785
);
17851786
return types
17861787
.stream()

spaceNPC/src/main/java/me/tofaa/entitylib/npc/interactions/InteractionHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ public static void handleInteraction(NPC npc, Player player, InteractionType int
1919
}
2020

2121
NPCOptions options = npc.getOptions();
22+
23+
List<InteractionAction> anyActions = options.getInteractions(InteractionType.ANY);
24+
executeActions(anyActions, player, npc);
25+
2226
List<InteractionAction> actions = options.getInteractions(interactionType);
23-
27+
executeActions(actions, player, npc);
28+
}
29+
30+
private static void executeActions(List<InteractionAction> actions, Player player, NPC npc) {
2431
if (actions == null || actions.isEmpty()) {
2532
return;
2633
}

spaceNPC/src/main/java/me/tofaa/entitylib/npc/interactions/InteractionType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public enum InteractionType {
44
RIGHT_CLICK("right_click", "rightclick"),
55
LEFT_CLICK("left_click", "leftclick"),
66
SHIFT_RIGHT_CLICK("shift_right_click", "shiftrightclick", "shift_right", "shiftright"),
7-
SHIFT_LEFT_CLICK("shift_left_click", "shiftleftclick", "shift_left", "shiftleft");
7+
SHIFT_LEFT_CLICK("shift_left_click", "shiftleftclick", "shift_left", "shiftleft"),
8+
ANY("any", "all");
89

910
private final String[] aliases;
1011

0 commit comments

Comments
 (0)