Catch protocollib errors again, change /npc list to use uuid rather than id

This commit is contained in:
fullwall 2023-07-09 18:57:30 +08:00
parent ea00df6c7e
commit a9fea94c61
4 changed files with 45 additions and 27 deletions

View File

@ -169,7 +169,24 @@ public class ProtocolLibListener implements Listener {
ListenerOptions.ASYNC) {
@Override
public void onPacketSending(PacketEvent event) {
RotationTrait trait = rotationTraits.get(event.getPacket().getIntegers().readSafely(0));
Integer eid = null;
try {
eid = event.getPacket().getIntegers().readSafely(0);
if (eid == null)
return;
} catch (FieldAccessException | IllegalArgumentException ex) {
if (!LOGGED_ERROR) {
Messaging.severe(
"Error retrieving entity from ID: ProtocolLib error? Suppressing further exceptions unless debugging.");
ex.printStackTrace();
LOGGED_ERROR = true;
} else if (Messaging.isDebugging()) {
ex.printStackTrace();
}
return;
}
RotationTrait trait = rotationTraits.get(eid);
if (trait == null)
return;

View File

@ -109,7 +109,7 @@ public class Settings {
"The default MOVEMENT distance in blocks where the NPC will move to before considering a path finished<br>Note: this is different from the PATHFINDING distance which is specified by path-distance-margin",
"npc.pathfinding.default-distance-margin", 1),
DEFAULT_LOOK_CLOSE("Enable look close by default", "npc.default.look-close.enabled", false),
DEFAULT_LOOK_CLOSE_RANGE("Default look close range in blocks", "npc.default.look-close.range", 5),
DEFAULT_LOOK_CLOSE_RANGE("Default look close range in blocks", "npc.default.look-close.range", 10),
DEFAULT_NPC_HOLOGRAM_LINE_HEIGHT("Default distance between hologram lines", "npc.hologram.default-line-height",
0.4D),
DEFAULT_NPC_LIMIT(

View File

@ -12,6 +12,7 @@ import org.bukkit.conversations.NumericPrompt;
import org.bukkit.conversations.Prompt;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.command.CommandContext;
@ -99,31 +100,31 @@ public class NPCCommandSelector extends NumericPrompt {
return;
} catch (IllegalArgumentException e) {
}
try {
int id = Integer.parseInt(raw);
Integer id = Ints.tryParse(raw);
if (id != null) {
callback.run(npcRegistry.getById(id));
return;
} catch (NumberFormatException ex) {
String name = args.getString(1);
List<NPC> possible = Lists.newArrayList();
double range = -1;
if (args.hasValueFlag("range")) {
range = Math.abs(args.getFlagDouble("range"));
}
for (NPC test : npcRegistry) {
if (test.getName().equalsIgnoreCase(name)) {
if (range > 0 && test.isSpawned() && !Util.locationWithinRange(args.getSenderLocation(),
test.getEntity().getLocation(), range))
continue;
possible.add(test);
}
}
if (possible.size() == 1) {
callback.run(possible.get(0));
} else if (possible.size() > 1) {
NPCCommandSelector.start(callback, (Conversable) sender, possible);
return;
}
String name = args.getString(1);
List<NPC> possible = Lists.newArrayList();
double range = -1;
if (args.hasValueFlag("range")) {
range = Math.abs(args.getFlagDouble("range"));
}
for (NPC test : npcRegistry) {
if (test.getName().equalsIgnoreCase(name)) {
if (range > 0 && test.isSpawned()
&& !Util.locationWithinRange(args.getSenderLocation(), test.getEntity().getLocation(), range))
continue;
possible.add(test);
}
}
if (possible.size() == 1) {
callback.run(possible.get(0));
} else if (possible.size() > 1) {
NPCCommandSelector.start(callback, (Conversable) sender, possible);
}
}
}

View File

@ -1476,10 +1476,10 @@ public class NPCCommands {
Paginator paginator = new Paginator().header("NPCs").console(sender instanceof ConsoleCommandSender)
.enablePageSwitcher('/' + args.getRawCommand() + " --page $page");
for (int i = 0; i < npcs.size(); i++) {
int id = npcs.get(i).getId();
String line = StringHelper.wrap(id) + " " + npcs.get(i).getName() + " (<click:run_command:/npc tp --id "
String id = npc.getUniqueId().toString();
String line = StringHelper.wrap(id) + " " + npcs.get(i).getName() + " (<click:run_command:/npc tp --uuid "
+ id
+ "><hover:show_text:Teleport to this NPC>[[tp]]</hover></click>) (<click:run_command:/npc tph --id "
+ "><hover:show_text:Teleport to this NPC>[[tp]]</hover></click>) (<click:run_command:/npc tph --uuid "
+ id
+ "><hover:show_text:Teleport NPC to me>[[summon]]</hover></click>) (<click:run_command:/npc remove "
+ id + "><hover:show_text:Remove this NPC><red>-</red></hover></click>)";