mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 18:45:29 +01:00
Fix double sending of command messages with LINEAR execution
This commit is contained in:
parent
918fcb9ca7
commit
cc3d8f84c7
@ -3,8 +3,10 @@ package net.citizensnpcs.trait;
|
||||
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<String, PlayerNPCCommand> cooldowns = Maps.newHashMap();
|
||||
@Persist
|
||||
private double cost = -1;
|
||||
private final Map<String, Set<CommandTraitMessages>> executionErrors = Maps.newHashMap();
|
||||
@Persist
|
||||
private ExecutionMode executionMode = ExecutionMode.LINEAR;
|
||||
@Persist
|
||||
@ -165,6 +168,9 @@ public class CommandTrait extends Trait {
|
||||
});
|
||||
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 class CommandTrait extends Trait {
|
||||
}
|
||||
|
||||
private void sendErrorMessage(Player player, CommandTraitMessages msg, Object... objects) {
|
||||
Set<CommandTraitMessages> 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));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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 class PlayerControllerLook {
|
||||
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 class PlayerControllerLook {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user