Skip to content

Commit

Permalink
Fix double sending of command messages with LINEAR execution
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jan 15, 2021
1 parent 918fcb9 commit cc3d8f8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 10 deletions.
12 changes: 12 additions & 0 deletions main/src/main/java/net/citizensnpcs/trait/CommandTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -244,6 +250,12 @@ public void removeCommandById(int id) {
}

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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ 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;
protected double g;

public PlayerControllerLook(EntityHumanNPC entityinsentient) {
this.a = entityinsentient;
this.control = new PlayerBodyControl(this.a);
}

public void a() {
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down

0 comments on commit cc3d8f8

Please sign in to comment.