From cc3d8f84c76195a546329490f70ba0136d0d616c Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 15 Jan 2021 22:06:03 +0800 Subject: [PATCH] Fix double sending of command messages with LINEAR execution --- .../net/citizensnpcs/trait/CommandTrait.java | 12 ++++ .../nms/v1_16_R3/util/PlayerBodyControl.java | 62 +++++++++++++++++++ .../v1_16_R3/util/PlayerControllerLook.java | 24 ++++--- 3 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerBodyControl.java diff --git a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java index 2ffca451d..3e807f54b 100644 --- a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java @@ -3,8 +3,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.EnumSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -50,6 +52,7 @@ public class CommandTrait extends Trait { private final Map cooldowns = Maps.newHashMap(); @Persist private double cost = -1; + private final Map> executionErrors = Maps.newHashMap(); @Persist private ExecutionMode executionMode = ExecutionMode.LINEAR; @Persist @@ -165,6 +168,9 @@ public int compare(NPCCommand o1, NPCCommand o2) { }); max = commandList.size() > 0 ? commandList.get(commandList.size() - 1).id : -1; } + if (executionMode == ExecutionMode.LINEAR) { + executionErrors.put(player.getUniqueId().toString(), EnumSet.noneOf(CommandTraitMessages.class)); + } for (NPCCommand command : commandList) { if (executionMode == ExecutionMode.SEQUENTIAL) { PlayerNPCCommand info = cooldowns.get(player.getUniqueId().toString()); @@ -244,6 +250,12 @@ public void removeCommandById(int id) { } private void sendErrorMessage(Player player, CommandTraitMessages msg, Object... objects) { + Set sent = executionErrors.get(player.getUniqueId().toString()); + if (sent != null) { + if (sent.contains(msg)) + return; + sent.add(msg); + } String messageRaw = msg.setting.asString(); if (messageRaw != null && messageRaw.trim().length() > 0) { Messaging.send(player, Translator.format(messageRaw, objects)); diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerBodyControl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerBodyControl.java new file mode 100644 index 000000000..a467cf193 --- /dev/null +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerBodyControl.java @@ -0,0 +1,62 @@ +package net.citizensnpcs.nms.v1_16_R3.util; + +import net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC; +import net.minecraft.server.v1_16_R3.EntityInsentient; +import net.minecraft.server.v1_16_R3.MathHelper; + +public class PlayerBodyControl { + private final EntityHumanNPC a; + private int b; + private float c; + + public PlayerBodyControl(EntityHumanNPC var0) { + this.a = var0; + } + + public void a() { + if (f()) { + this.a.aA = this.a.yaw; + c(); + this.c = this.a.aC; + this.b = 0; + return; + } + if (e()) + if (Math.abs(this.a.aC - this.c) > 15.0F) { + System.out.println("BIG DX"); + this.b = 0; + this.c = this.a.aC; + b(); + } else { + this.b++; + if (this.b > 10) + d(); + } + } + + private void b() { + this.a.aA = MathHelper.b(this.a.aA, this.a.aC, 10); + this.a.yaw = this.a.aA; + } + + private void c() { + this.a.aC = MathHelper.b(this.a.aC, this.a.aA, 10); + } + + private void d() { + int var0 = this.b - 10; + float var1 = MathHelper.a(var0 / 10.0F, 0.0F, 1.0F); + float var2 = 40 * (1.0F - var1); + this.a.aA = MathHelper.b(this.a.aA, this.a.aC, var2); + } + + private boolean e() { + return (this.a.getPassengers().isEmpty() || !(this.a.getPassengers().get(0) instanceof EntityInsentient)); + } + + private boolean f() { + double var0 = this.a.locX() - this.a.lastX; + double var2 = this.a.locZ() - this.a.lastZ; + return (var0 * var0 + var2 * var2 > 2.500000277905201E-7D); + } +} \ No newline at end of file diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerControllerLook.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerControllerLook.java index 6c5398afa..5f6739e2f 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerControllerLook.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerControllerLook.java @@ -10,6 +10,7 @@ public class PlayerControllerLook { private final EntityHumanNPC a; protected float b; protected float c; + private final PlayerBodyControl control; protected boolean d; protected double e; protected double f; @@ -17,6 +18,7 @@ public class PlayerControllerLook { public PlayerControllerLook(EntityHumanNPC entityinsentient) { this.a = entityinsentient; + this.control = new PlayerBodyControl(this.a); } public void a() { @@ -35,7 +37,7 @@ public void a() { while (this.a.aC < -180F) { this.a.aC += 360F; } - double d = this.a.aC - 45; + double d = this.a.aC - 40; while (d >= 180F) { d -= 360F; } @@ -45,15 +47,17 @@ public void a() { if (d > this.a.yaw) { this.a.yaw = (float) d; } - d = this.a.aC + 45; - while (d >= 180F) { - d -= 360F; - } - while (d < -180F) { - d += 360F; - } - if (d < this.a.yaw) { - this.a.yaw = (float) d; + if (d != this.a.yaw) { + d = this.a.aC + 40; + while (d >= 180F) { + d -= 360F; + } + while (d < -180F) { + d += 360F; + } + if (d < this.a.yaw) { + this.a.yaw = (float) d; + } } // this.a.yaw = this.a(this.a.aC, this.h(), this.b); } else {