mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-18 15:20:37 +01:00
#1287: Fix scoreboards not updating in Player#setStatistic
By: Collin <collinjbarber@gmail.com>
This commit is contained in:
parent
044d4ce4d3
commit
e002bc102b
3 changed files with 80 additions and 58 deletions
|
@ -310,7 +310,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().incrementStatistic(statistic);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.incrementStatistic(manager, statistic);
|
||||
CraftStatistic.incrementStatistic(manager, statistic, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().decrementStatistic(statistic);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.decrementStatistic(manager, statistic);
|
||||
CraftStatistic.decrementStatistic(manager, statistic, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().incrementStatistic(statistic, amount);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.incrementStatistic(manager, statistic, amount);
|
||||
CraftStatistic.incrementStatistic(manager, statistic, amount, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().decrementStatistic(statistic, amount);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.decrementStatistic(manager, statistic, amount);
|
||||
CraftStatistic.decrementStatistic(manager, statistic, amount, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -363,7 +363,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().setStatistic(statistic, newValue);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.setStatistic(manager, statistic, newValue);
|
||||
CraftStatistic.setStatistic(manager, statistic, newValue, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().incrementStatistic(statistic, material);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.incrementStatistic(manager, statistic, material);
|
||||
CraftStatistic.incrementStatistic(manager, statistic, material, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().decrementStatistic(statistic, material);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.decrementStatistic(manager, statistic, material);
|
||||
CraftStatistic.decrementStatistic(manager, statistic, material, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().incrementStatistic(statistic, material, amount);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.incrementStatistic(manager, statistic, material, amount);
|
||||
CraftStatistic.incrementStatistic(manager, statistic, material, amount, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().decrementStatistic(statistic, material, amount);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.decrementStatistic(manager, statistic, material, amount);
|
||||
CraftStatistic.decrementStatistic(manager, statistic, material, amount, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().setStatistic(statistic, material, newValue);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.setStatistic(manager, statistic, material, newValue);
|
||||
CraftStatistic.setStatistic(manager, statistic, material, newValue, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().incrementStatistic(statistic, entityType);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.incrementStatistic(manager, statistic, entityType);
|
||||
CraftStatistic.incrementStatistic(manager, statistic, entityType, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().decrementStatistic(statistic, entityType);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.decrementStatistic(manager, statistic, entityType);
|
||||
CraftStatistic.decrementStatistic(manager, statistic, entityType, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().incrementStatistic(statistic, entityType, amount);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.incrementStatistic(manager, statistic, entityType, amount);
|
||||
CraftStatistic.incrementStatistic(manager, statistic, entityType, amount, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().decrementStatistic(statistic, entityType, amount);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.decrementStatistic(manager, statistic, entityType, amount);
|
||||
CraftStatistic.decrementStatistic(manager, statistic, entityType, amount, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
@ -491,7 +491,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
|||
getPlayer().setStatistic(statistic, entityType, newValue);
|
||||
} else {
|
||||
ServerStatisticManager manager = getStatisticManager();
|
||||
CraftStatistic.setStatistic(manager, statistic, entityType, newValue);
|
||||
CraftStatistic.setStatistic(manager, statistic, entityType, newValue, null);
|
||||
manager.save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableBiMap;
|
|||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import net.minecraft.stats.ServerStatisticManager;
|
||||
import net.minecraft.stats.StatisticList;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
|
@ -199,12 +200,12 @@ public enum CraftStatistic {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic) {
|
||||
incrementStatistic(manager, statistic, 1);
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityPlayer player) {
|
||||
incrementStatistic(manager, statistic, 1, player);
|
||||
}
|
||||
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic) {
|
||||
decrementStatistic(manager, statistic, 1);
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityPlayer player) {
|
||||
decrementStatistic(manager, statistic, 1, player);
|
||||
}
|
||||
|
||||
public static int getStatistic(ServerStatisticManager manager, Statistic statistic) {
|
||||
|
@ -213,30 +214,37 @@ public enum CraftStatistic {
|
|||
return manager.getValue(CraftStatistic.getNMSStatistic(statistic));
|
||||
}
|
||||
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, int amount) {
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, int amount, EntityPlayer player) {
|
||||
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
|
||||
setStatistic(manager, statistic, getStatistic(manager, statistic) + amount);
|
||||
setStatistic(manager, statistic, getStatistic(manager, statistic) + amount, player);
|
||||
}
|
||||
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, int amount) {
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, int amount, EntityPlayer player) {
|
||||
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
|
||||
setStatistic(manager, statistic, getStatistic(manager, statistic) - amount);
|
||||
setStatistic(manager, statistic, getStatistic(manager, statistic) - amount, player);
|
||||
}
|
||||
|
||||
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, int newValue) {
|
||||
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, int newValue, EntityPlayer player) {
|
||||
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
|
||||
Preconditions.checkArgument(statistic.getType() == Type.UNTYPED, "Must supply additional parameter for this statistic");
|
||||
Preconditions.checkArgument(newValue >= 0, "Value must be greater than or equal to 0");
|
||||
net.minecraft.stats.Statistic nmsStatistic = CraftStatistic.getNMSStatistic(statistic);
|
||||
manager.setValue(null, nmsStatistic, newValue);;
|
||||
manager.setValue(null, nmsStatistic, newValue);
|
||||
|
||||
// Update scoreboards
|
||||
if (player != null) {
|
||||
player.level().getCraftServer().getScoreboardManager().getScoreboardScores(nmsStatistic, player.getScoreboardName(), score -> {
|
||||
score.setScore(newValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material) {
|
||||
incrementStatistic(manager, statistic, material, 1);
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, EntityPlayer player) {
|
||||
incrementStatistic(manager, statistic, material, 1, player);
|
||||
}
|
||||
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material) {
|
||||
decrementStatistic(manager, statistic, material, 1);
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, EntityPlayer player) {
|
||||
decrementStatistic(manager, statistic, material, 1, player);
|
||||
}
|
||||
|
||||
public static int getStatistic(ServerStatisticManager manager, Statistic statistic, Material material) {
|
||||
|
@ -248,17 +256,17 @@ public enum CraftStatistic {
|
|||
return manager.getValue(nmsStatistic);
|
||||
}
|
||||
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int amount) {
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int amount, EntityPlayer player) {
|
||||
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
|
||||
setStatistic(manager, statistic, material, getStatistic(manager, statistic, material) + amount);
|
||||
setStatistic(manager, statistic, material, getStatistic(manager, statistic, material) + amount, player);
|
||||
}
|
||||
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int amount) {
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int amount, EntityPlayer player) {
|
||||
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
|
||||
setStatistic(manager, statistic, material, getStatistic(manager, statistic, material) - amount);
|
||||
setStatistic(manager, statistic, material, getStatistic(manager, statistic, material) - amount, player);
|
||||
}
|
||||
|
||||
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int newValue) {
|
||||
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int newValue, EntityPlayer player) {
|
||||
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
|
||||
Preconditions.checkArgument(material != null, "Material cannot be null");
|
||||
Preconditions.checkArgument(newValue >= 0, "Value must be greater than or equal to 0");
|
||||
|
@ -266,14 +274,21 @@ public enum CraftStatistic {
|
|||
net.minecraft.stats.Statistic nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material);
|
||||
Preconditions.checkArgument(nmsStatistic != null, "The supplied Material %s does not have a corresponding statistic", material);
|
||||
manager.setValue(null, nmsStatistic, newValue);
|
||||
|
||||
// Update scoreboards
|
||||
if (player != null) {
|
||||
player.level().getCraftServer().getScoreboardManager().getScoreboardScores(nmsStatistic, player.getScoreboardName(), score -> {
|
||||
score.setScore(newValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType) {
|
||||
incrementStatistic(manager, statistic, entityType, 1);
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, EntityPlayer player) {
|
||||
incrementStatistic(manager, statistic, entityType, 1, player);
|
||||
}
|
||||
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType) {
|
||||
decrementStatistic(manager, statistic, entityType, 1);
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, EntityPlayer player) {
|
||||
decrementStatistic(manager, statistic, entityType, 1, player);
|
||||
}
|
||||
|
||||
public static int getStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType) {
|
||||
|
@ -285,17 +300,17 @@ public enum CraftStatistic {
|
|||
return manager.getValue(nmsStatistic);
|
||||
}
|
||||
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int amount) {
|
||||
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int amount, EntityPlayer player) {
|
||||
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
|
||||
setStatistic(manager, statistic, entityType, getStatistic(manager, statistic, entityType) + amount);
|
||||
setStatistic(manager, statistic, entityType, getStatistic(manager, statistic, entityType) + amount, player);
|
||||
}
|
||||
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int amount) {
|
||||
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int amount, EntityPlayer player) {
|
||||
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
|
||||
setStatistic(manager, statistic, entityType, getStatistic(manager, statistic, entityType) - amount);
|
||||
setStatistic(manager, statistic, entityType, getStatistic(manager, statistic, entityType) - amount, player);
|
||||
}
|
||||
|
||||
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int newValue) {
|
||||
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int newValue, EntityPlayer player) {
|
||||
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
|
||||
Preconditions.checkArgument(entityType != null, "EntityType cannot be null");
|
||||
Preconditions.checkArgument(newValue >= 0, "Value must be greater than or equal to 0");
|
||||
|
@ -303,5 +318,12 @@ public enum CraftStatistic {
|
|||
net.minecraft.stats.Statistic nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType);
|
||||
Preconditions.checkArgument(nmsStatistic != null, "The supplied EntityType %s does not have a corresponding statistic", entityType);
|
||||
manager.setValue(null, nmsStatistic, newValue);
|
||||
|
||||
// Update scoreboards
|
||||
if (player != null) {
|
||||
player.level().getCraftServer().getScoreboardManager().getScoreboardScores(nmsStatistic, player.getScoreboardName(), score -> {
|
||||
score.setScore(newValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1054,12 +1054,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic) {
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic);
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic) {
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic);
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1069,27 +1069,27 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, int amount) {
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, amount);
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, amount, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, int amount) {
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, amount);
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, amount, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(Statistic statistic, int newValue) {
|
||||
CraftStatistic.setStatistic(getHandle().getStats(), statistic, newValue);
|
||||
CraftStatistic.setStatistic(getHandle().getStats(), statistic, newValue, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, Material material) {
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, material);
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, material, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, Material material) {
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, material);
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, material, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1099,27 +1099,27 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, Material material, int amount) {
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, material, amount);
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, material, amount, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, Material material, int amount) {
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, material, amount);
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, material, amount, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(Statistic statistic, Material material, int newValue) {
|
||||
CraftStatistic.setStatistic(getHandle().getStats(), statistic, material, newValue);
|
||||
CraftStatistic.setStatistic(getHandle().getStats(), statistic, material, newValue, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, EntityType entityType) {
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, entityType);
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, entityType, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, EntityType entityType) {
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, entityType);
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, entityType, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1129,17 +1129,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, EntityType entityType, int amount) {
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, entityType, amount);
|
||||
CraftStatistic.incrementStatistic(getHandle().getStats(), statistic, entityType, amount, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, EntityType entityType, int amount) {
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, entityType, amount);
|
||||
CraftStatistic.decrementStatistic(getHandle().getStats(), statistic, entityType, amount, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(Statistic statistic, EntityType entityType, int newValue) {
|
||||
CraftStatistic.setStatistic(getHandle().getStats(), statistic, entityType, newValue);
|
||||
CraftStatistic.setStatistic(getHandle().getStats(), statistic, entityType, newValue, getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue