Skip to content

Commit

Permalink
Use new duration option
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 14, 2023
1 parent eb63c91 commit 513a6c7
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 54 deletions.
1 change: 1 addition & 0 deletions main/pom.xml
Expand Up @@ -190,6 +190,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down
24 changes: 12 additions & 12 deletions main/src/main/java/net/citizensnpcs/ProtocolLibListener.java
Expand Up @@ -111,33 +111,33 @@ public void onPacketSending(PacketEvent event) {
return;
boolean changed = false;
for (int i = 0; i < list.size(); i++) {
PlayerInfoData info = list.get(i);
if (info == null)
PlayerInfoData npcInfo = list.get(i);
if (npcInfo == null)
continue;
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(info.getProfile().getUUID());
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(npcInfo.getProfile().getUUID());
if (npc == null || !npc.isSpawned())
continue;
MirrorTrait trait = npc.getTraitNullable(MirrorTrait.class);
if (trait == null || !trait.isMirroring(event.getPlayer())) {
continue;
}
GameProfile profile = NMS.getProfile(event.getPlayer());
GameProfile playerProfile = NMS.getProfile(event.getPlayer());
if (trait.mirrorName()) {
list.set(i,
new PlayerInfoData(
WrappedGameProfile.fromPlayer(event.getPlayer()).withId(
info.getProfile().getId()),
info.getLatency(), info.getGameMode(),
WrappedGameProfile.fromPlayer(event.getPlayer())
.withId(npcInfo.getProfile().getId()),
npcInfo.getLatency(), npcInfo.getGameMode(),
WrappedChatComponent.fromText(event.getPlayer().getDisplayName())));
continue;
}
Collection<Property> textures = profile.getProperties().get("textures");
Collection<Property> textures = playerProfile.getProperties().get("textures");
if (textures == null || textures.size() == 0)
continue;
info.getProfile().getProperties().clear();
for (String key : profile.getProperties().keySet()) {
info.getProfile().getProperties().putAll(key,
Iterables.transform(profile.getProperties().get(key),
npcInfo.getProfile().getProperties().clear();
for (String key : playerProfile.getProperties().keySet()) {
npcInfo.getProfile().getProperties().putAll(key,
Iterables.transform(playerProfile.getProperties().get(key),
skin -> new WrappedSignedProperty(skin.getName(), skin.getValue(),
skin.getSignature())));
}
Expand Down
4 changes: 2 additions & 2 deletions main/src/main/java/net/citizensnpcs/Settings.java
Expand Up @@ -314,7 +314,7 @@ public List<String> asList() {

public int asSeconds() {
if (duration == null) {
duration = SpigotUtil.parseDuration(asString());
duration = SpigotUtil.parseDuration(asString(), null);
}
return Util.convert(TimeUnit.SECONDS, duration);
}
Expand All @@ -325,7 +325,7 @@ public String asString() {

public int asTicks() {
if (duration == null) {
duration = SpigotUtil.parseDuration(asString());
duration = SpigotUtil.parseDuration(asString(), null);
}
return Util.toTicks(duration);
}
Expand Down
Expand Up @@ -2996,7 +2996,7 @@ public void target(CommandContext args, Player sender, NPC npc) {
flags = "t",
permission = "citizens.npc.targetable")
public void targetable(CommandContext args, CommandSender sender, NPC npc) {
boolean targetable = !npc.data().get(NPC.Metadata.TARGETABLE, npc.isProtected());
boolean targetable = !npc.data().get(NPC.Metadata.TARGETABLE, !npc.isProtected());
if (args.hasFlag('t')) {
npc.data().set(NPC.Metadata.TARGETABLE, targetable);
} else {
Expand Down
9 changes: 3 additions & 6 deletions main/src/main/java/net/citizensnpcs/npc/skin/Skin.java
Expand Up @@ -139,12 +139,9 @@ public void applyAndRespawn(SkinnableEntity entity) {
if (!npc.isSpawned())
return;

Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
});
}

Expand Down
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/util/StringHelper.java
Expand Up @@ -10,6 +10,6 @@ public static String wrap(Object string, String colour) {
}

public static String wrapHeader(Object string) {
return "<yellow>=====[ </yellow>" + string.toString() + "<yellow> ]=====";
return "<yellow>=====[</yellow> " + string.toString() + "<yellow> ]=====";
}
}
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/util/Util.java
Expand Up @@ -339,7 +339,7 @@ public static Set<EntityType> optionalEntitySet(String... types) {
}

public static int parseTicks(String raw) {
Duration duration = SpigotUtil.parseDuration(raw);
Duration duration = SpigotUtil.parseDuration(raw, null);
return duration == null ? -1 : toTicks(duration);
}

Expand Down
1 change: 1 addition & 0 deletions v1_10_R1/pom.xml
Expand Up @@ -38,6 +38,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions v1_11_R1/pom.xml
Expand Up @@ -38,6 +38,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions v1_12_R1/pom.xml
Expand Up @@ -38,6 +38,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions v1_13_R2/pom.xml
Expand Up @@ -38,6 +38,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions v1_14_R1/pom.xml
Expand Up @@ -38,6 +38,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions v1_15_R1/pom.xml
Expand Up @@ -36,6 +36,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions v1_16_R3/pom.xml
Expand Up @@ -36,6 +36,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down
Expand Up @@ -51,16 +51,13 @@ protected Entity createEntity(final Location at, final NPC npc) {
if (skin != null) {
skin.apply(handle);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get(NPC.Metadata.REMOVE_FROM_PLAYERLIST,
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get(NPC.Metadata.REMOVE_FROM_PLAYERLIST,
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
}, 20);
handle.getBukkitEntity().setSleepingIgnored(true);
return handle.getBukkitEntity();
Expand Down
Expand Up @@ -62,9 +62,9 @@ public void updateLastPlayer(ServerPlayer lastUpdatedPlayer) {
final ServerPlayer entityplayer = lastUpdatedPlayer;
boolean sendTabRemove = NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
if (!sendTabRemove || !Setting.DISABLE_TABLIST.asBoolean()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0));
}, 1);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
() -> NMSImpl.sendPacket(entityplayer.getBukkitEntity(), new ClientboundAnimatePacket(tracker, 0)),
1);
return;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
Expand Down
Expand Up @@ -1183,39 +1183,39 @@ public void onPlayerInfoAdd(Player player, Object raw) {
List<ClientboundPlayerInfoUpdatePacket.Entry> list = Lists.newArrayList(packet.entries());
boolean changed = false;
for (int i = 0; i < list.size(); i++) {
ClientboundPlayerInfoUpdatePacket.Entry info = list.get(i);
if (info == null)
ClientboundPlayerInfoUpdatePacket.Entry npcInfo = list.get(i);
if (npcInfo == null)
continue;
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(info.profileId());
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(npcInfo.profileId());
if (npc == null || !npc.isSpawned())
continue;
if (Setting.DISABLE_TABLIST.asBoolean() != info.listed()) {
if (Setting.DISABLE_TABLIST.asBoolean() != npcInfo.listed()) {
list.set(i,
new ClientboundPlayerInfoUpdatePacket.Entry(info.profileId(), info.profile(),
!Setting.DISABLE_TABLIST.asBoolean(), info.latency(), info.gameMode(),
!Setting.DISABLE_TABLIST.asBoolean() ? info.displayName() : Component.empty(),
info.chatSession()));
new ClientboundPlayerInfoUpdatePacket.Entry(npcInfo.profileId(), npcInfo.profile(),
!Setting.DISABLE_TABLIST.asBoolean(), npcInfo.latency(), npcInfo.gameMode(),
!Setting.DISABLE_TABLIST.asBoolean() ? npcInfo.displayName() : Component.empty(),
npcInfo.chatSession()));
changed = true;
}
MirrorTrait trait = npc.getTraitNullable(MirrorTrait.class);
if (trait == null || !trait.isMirroring(player)) {
continue;
}
GameProfile profile = NMS.getProfile(player);
GameProfile playerProfile = NMS.getProfile(player);
if (trait.mirrorName()) {
list.set(i,
new ClientboundPlayerInfoUpdatePacket.Entry(info.profileId(), profile,
!Setting.DISABLE_TABLIST.asBoolean(), info.latency(), info.gameMode(),
Component.literal(profile.getName()), info.chatSession()));
new ClientboundPlayerInfoUpdatePacket.Entry(npcInfo.profileId(), playerProfile,
!Setting.DISABLE_TABLIST.asBoolean(), npcInfo.latency(), npcInfo.gameMode(),
Component.literal(playerProfile.getName()), npcInfo.chatSession()));
changed = true;
continue;
}
Collection<Property> textures = profile.getProperties().get("textures");
Collection<Property> textures = playerProfile.getProperties().get("textures");
if (textures == null || textures.size() == 0)
continue;
info.profile().getProperties().clear();
for (String key : profile.getProperties().keySet()) {
info.profile().getProperties().putAll(key, profile.getProperties().get(key));
npcInfo.profile().getProperties().clear();
for (String key : playerProfile.getProperties().keySet()) {
npcInfo.profile().getProperties().putAll(key, playerProfile.getProperties().get(key));
}
changed = true;
}
Expand Down Expand Up @@ -1260,8 +1260,8 @@ public CraftInventoryView getBukkitView() {
container.getBukkitView().setItem(0, anvil.getItem(0));
container.getBukkitView().setItem(1, anvil.getItem(1));
container.checkReachable = false;
handle.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(),
MutableComponent.create(new LiteralContents(title))));
handle.connection.send(
new ClientboundOpenScreenPacket(container.containerId, container.getType(), container.getTitle()));
handle.containerMenu = container;
handle.initMenu(container);
return container.getBukkitView();
Expand Down
1 change: 1 addition & 0 deletions v1_8_R3/pom.xml
Expand Up @@ -38,6 +38,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
Expand Down

0 comments on commit 513a6c7

Please sign in to comment.