Fix /npc text pages, add via version backcompat

This commit is contained in:
fullwall 2022-12-17 11:22:14 +08:00
parent f90b1f747b
commit 249074c7bc
4 changed files with 47 additions and 10 deletions

View File

@ -223,7 +223,7 @@ public class Text extends Trait implements Runnable, Listener {
}
boolean sendPage(CommandSender player, int page) {
Paginator paginator = new Paginator().header("Current Texts").enablePageSwitcher();
Paginator paginator = new Paginator().header("Current Texts").enablePageSwitcher("/npc text page $page");
for (int i = 0; i < text.size(); i++) {
paginator.addLine(text.get(i) + " <green>(<click:suggest_command:edit " + i
+ " ><yellow>edit</click>) (<hover:show_text:Remove this text><click:run_command:/npc text remove "

View File

@ -351,7 +351,7 @@ citizens.editors.text.range-set=[[Range]] set to [[{0}]].
citizens.editors.text.delay-set=[[Delay]] set to [[{0}]] seconds.
citizens.editors.text.realistic-looking-set=[[Realistic looking]] set to [[{0}]].
citizens.editors.text.speech-bubbles-set=[[Speech bubbles]] set to [[{0}]].
citizens.editors.text.start-prompt=<click:suggest_command:add ><yellow>Add text</click> | <click:suggest_command:item ><hover:show_text:"Set the talk item in hand pattern (set to <yellow>default</yellow> to clear)"><yellow>item</hover></click> | <click:suggest_command:range ><hover:show_text:Set the talking range in blocks><yellow>range</hover></click> | <click:suggest_command:delay ><hover:show_text:Set the talking delay in seconds><yellow>delay</hover></click><br><click:run_command:/npc text close><hover:show_text:Toggle sending messages when players get close>{0}talk close</hover></click> | <click:run_command:/npc text random><hover:show_text:Toggle random talking>{1}random</hover></click> | <click:run_command:/npc text speech bubbles><hover:show_text:Toggle showing text as holograms instead of chat messages>{2}speech bubbles</hover></click> | <click:run_command:/npc text realistic looking><hover:show_text:Toggle requiring line of sight before speaking>{3}realistic</hover></click>
citizens.editors.text.start-prompt=<click:suggest_command:add ><yellow>Add text</click> | <click:suggest_command:item ><hover:show_text:"Set the talk item in hand pattern (set to <yellow>default</yellow> to clear)"><yellow>item</hover></click> | <click:suggest_command:range ><hover:show_text:Set the talking range in blocks><yellow>range</hover></click> | <click:suggest_command:delay ><hover:show_text:Set the talking delay in seconds><yellow>delay</yellow></hover></click><br><click:run_command:/npc text close><hover:show_text:Toggle sending messages when players get close>{0}talk close</hover></click> | <click:run_command:/npc text random><hover:show_text:Toggle random talking>{1}random</hover></click> | <click:run_command:/npc text speech bubbles><hover:show_text:Toggle showing text as holograms instead of chat messages>{2}speech bubbles</hover></click> | <click:run_command:/npc text realistic looking><hover:show_text:Toggle requiring line of sight before speaking>{3}realistic</hover></click>
citizens.editors.text.talk-item-set=[[Talk item pattern]] set to [[{0}]].
citizens.editors.text.text-list-header=Current text:
citizens.editors.waypoints.wander.editing-regions-stop=Exited the region editor.

View File

@ -6,6 +6,7 @@
<artifactId>citizens-parent</artifactId>
<version>2.0.30-SNAPSHOT</version>
</parent>
<artifactId>citizens-v1_19_R2</artifactId>
<properties>
@ -13,6 +14,13 @@
<craftbukkit.version>1.19.3-R0.1-SNAPSHOT</craftbukkit.version>
</properties>
<repositories>
<repository>
<id>viaversion-repo</id>
<url>https://repo.viaversion.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
@ -27,12 +35,17 @@
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.viaversion</groupId>
<artifactId>viaversion-api</artifactId>
<version>4.5.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean package install</defaultGoal>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -43,7 +56,6 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
@ -55,7 +67,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
@ -89,13 +100,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>

View File

@ -5,6 +5,9 @@ import java.lang.invoke.MethodHandle;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.viaversion.viaversion.api.Via;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.nms.v1_19_R2.entity.EntityHumanNPC;
import net.citizensnpcs.util.NMS;
@ -22,6 +25,15 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
public PlayerlistTracker(ChunkMap map, Entity entity, int i, int j, boolean flag) {
map.super(entity, i, j, flag);
this.tracker = entity;
if (VIA_ENABLED == null) {
try {
Via.getAPI();
VIA_ENABLED = true;
} catch (Throwable t) {
VIA_ENABLED = false;
}
}
}
public PlayerlistTracker(ChunkMap map, TrackedEntity entry) {
@ -41,6 +53,21 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0));
}
}, 1);
if (VIA_ENABLED == false || !Setting.DISABLE_TABLIST.asBoolean())
return;
@SuppressWarnings("unchecked")
int version = Via.getAPI().getPlayerVersion(entityplayer.getBukkitEntity());
if (version >= 761 /* 1.19.3 */)
return;
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
}
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asInt());
}
@Override
@ -92,4 +119,5 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
private static final MethodHandle TRACKER = NMS.getFirstGetter(TrackedEntity.class, Entity.class);
private static final MethodHandle TRACKER_ENTRY = NMS.getFirstGetter(TrackedEntity.class, ServerEntity.class);
private static final MethodHandle TRACKING_DISTANCE = NMS.getFirstGetter(TrackedEntity.class, int.class);
private static Boolean VIA_ENABLED = null;
}