From aa3a2f276709f54b43796d0a94bad7a6cd087d55 Mon Sep 17 00:00:00 2001 From: SydMontague Date: Sun, 5 Apr 2020 15:58:43 +1000 Subject: [PATCH] #645: Allow statistics to be accessed for offline players --- nms-patches/PlayerList.patch | 37 +++- .../craftbukkit/CraftOfflinePlayer.java | 200 ++++++++++++++++++ .../bukkit/craftbukkit/CraftStatistic.java | 109 ++++++++++ .../craftbukkit/entity/CraftPlayer.java | 71 ++----- 4 files changed, 353 insertions(+), 64 deletions(-) diff --git a/nms-patches/PlayerList.patch b/nms-patches/PlayerList.patch index 82134c8d50..6885e63d6b 100644 --- a/nms-patches/PlayerList.patch +++ b/nms-patches/PlayerList.patch @@ -379,13 +379,13 @@ + if (this.players.size() >= this.maxPlayers && !this.f(gameprofile)) { + event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full"); + } - } ++ } + + cserver.getPluginManager().callEvent(event); + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { + loginlistener.disconnect(event.getKickMessage()); + return null; -+ } + } + return entity; } @@ -466,13 +466,13 @@ + entityplayer1.setRespawnPosition(null, true, false); + entityplayer1.playerConnection.sendPacket(new PacketPlayOutGameStateChange(0, 0.0F)); + } - } ++ } + + if (location == null) { + cworld = (CraftWorld) this.server.server.getWorlds().get(0); + blockposition = entityplayer1.getSpawnPoint(cworld.getHandle()); + location = new Location(cworld, (double) ((float) blockposition.getX() + 0.5F), (double) ((float) blockposition.getY() + 0.1F), (double) ((float) blockposition.getZ() + 0.5F)); -+ } + } + + Player respawnPlayer = cserver.getPlayer(entityplayer1); + PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn); @@ -658,7 +658,7 @@ } public int getPlayerCount() { -@@ -710,26 +993,39 @@ +@@ -710,33 +993,52 @@ } public void shutdown() { @@ -695,15 +695,30 @@ } - public ServerStatisticManager getStatisticManager(EntityHuman entityhuman) { -+ public ServerStatisticManager getStatisticManager(EntityPlayer entityhuman) { - UUID uuid = entityhuman.getUniqueID(); +- UUID uuid = entityhuman.getUniqueID(); - ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) this.o.get(uuid); -+ ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) entityhuman.getStatisticManager(); ++ // CraftBukkit start ++ public ServerStatisticManager getStatisticManager(EntityPlayer entityhuman) { ++ ServerStatisticManager serverstatisticmanager = entityhuman.getStatisticManager(); ++ return serverstatisticmanager == null ? getStatisticManager(entityhuman.getUniqueID(), entityhuman.getDisplayName().getString()) : serverstatisticmanager; ++ } ++ ++ public ServerStatisticManager getStatisticManager(UUID uuid, String displayName) { ++ EntityPlayer entityHuman = this.a(uuid); ++ ServerStatisticManager serverstatisticmanager = entityHuman == null ? null : (ServerStatisticManager) entityHuman.getStatisticManager(); + // CraftBukkit end if (serverstatisticmanager == null) { File file = new File(this.server.getWorldServer(DimensionManager.OVERWORLD).getDataManager().getDirectory(), "stats"); -@@ -744,7 +1040,7 @@ + File file1 = new File(file, uuid + ".json"); + + if (!file1.exists()) { +- File file2 = new File(file, entityhuman.getDisplayName().getString() + ".json"); ++ File file2 = new File(file, displayName + ".json"); // CraftBukkit + + if (file2.exists() && file2.isFile()) { + file2.renameTo(file1); +@@ -744,7 +1046,7 @@ } serverstatisticmanager = new ServerStatisticManager(this.server, file1); @@ -712,7 +727,7 @@ } return serverstatisticmanager; -@@ -752,14 +1048,14 @@ +@@ -752,14 +1054,14 @@ public AdvancementDataPlayer f(EntityPlayer entityplayer) { UUID uuid = entityplayer.getUniqueID(); @@ -729,7 +744,7 @@ } advancementdataplayer.a(entityplayer); -@@ -795,13 +1091,20 @@ +@@ -795,13 +1097,20 @@ } public void reload() { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java index 6a448c02ec..58e10381c8 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -8,15 +8,19 @@ import java.util.Map; import java.util.UUID; import net.minecraft.server.DimensionManager; import net.minecraft.server.NBTTagCompound; +import net.minecraft.server.ServerStatisticManager; import net.minecraft.server.WhiteListEntry; import net.minecraft.server.WorldNBTStorage; import org.bukkit.BanList; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.Server; +import org.bukkit.Statistic; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; @@ -271,4 +275,200 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa public void removeMetadata(String metadataKey, Plugin plugin) { server.getPlayerMetadata().removeMetadata(this, metadataKey, plugin); } + + private ServerStatisticManager getStatisticManager() { + return server.getHandle().getStatisticManager(getUniqueId(), getName()); + } + + @Override + public void incrementStatistic(Statistic statistic) { + if (isOnline()) { + getPlayer().incrementStatistic(statistic); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.incrementStatistic(manager, statistic); + manager.a(); + } + } + + @Override + public void decrementStatistic(Statistic statistic) { + if (isOnline()) { + getPlayer().decrementStatistic(statistic); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.decrementStatistic(manager, statistic); + manager.a(); + } + } + + @Override + public int getStatistic(Statistic statistic) { + if (isOnline()) { + return getPlayer().getStatistic(statistic); + } else { + return CraftStatistic.getStatistic(getStatisticManager(), statistic); + } + } + + @Override + public void incrementStatistic(Statistic statistic, int amount) { + if (isOnline()) { + getPlayer().incrementStatistic(statistic, amount); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.incrementStatistic(manager, statistic, amount); + manager.a(); + } + } + + @Override + public void decrementStatistic(Statistic statistic, int amount) { + if (isOnline()) { + getPlayer().decrementStatistic(statistic, amount); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.decrementStatistic(manager, statistic, amount); + manager.a(); + } + } + + @Override + public void setStatistic(Statistic statistic, int newValue) { + if (isOnline()) { + getPlayer().setStatistic(statistic, newValue); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.setStatistic(manager, statistic, newValue); + manager.a(); + } + } + + @Override + public void incrementStatistic(Statistic statistic, Material material) { + if (isOnline()) { + getPlayer().incrementStatistic(statistic, material); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.incrementStatistic(manager, statistic, material); + manager.a(); + } + } + + @Override + public void decrementStatistic(Statistic statistic, Material material) { + if (isOnline()) { + getPlayer().decrementStatistic(statistic, material); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.decrementStatistic(manager, statistic, material); + manager.a(); + } + } + + @Override + public int getStatistic(Statistic statistic, Material material) { + if (isOnline()) { + return getPlayer().getStatistic(statistic, material); + } else { + return CraftStatistic.getStatistic(getStatisticManager(), statistic, material); + } + } + + @Override + public void incrementStatistic(Statistic statistic, Material material, int amount) { + if (isOnline()) { + getPlayer().incrementStatistic(statistic, material, amount); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.incrementStatistic(manager, statistic, material, amount); + manager.a(); + } + } + + @Override + public void decrementStatistic(Statistic statistic, Material material, int amount) { + if (isOnline()) { + getPlayer().decrementStatistic(statistic, material, amount); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.decrementStatistic(manager, statistic, material, amount); + manager.a(); + } + } + + @Override + public void setStatistic(Statistic statistic, Material material, int newValue) { + if (isOnline()) { + getPlayer().setStatistic(statistic, material, newValue); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.setStatistic(manager, statistic, material, newValue); + manager.a(); + } + } + + @Override + public void incrementStatistic(Statistic statistic, EntityType entityType) { + if (isOnline()) { + getPlayer().incrementStatistic(statistic, entityType); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.incrementStatistic(manager, statistic, entityType); + manager.a(); + } + } + + @Override + public void decrementStatistic(Statistic statistic, EntityType entityType) { + if (isOnline()) { + getPlayer().decrementStatistic(statistic, entityType); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.decrementStatistic(manager, statistic, entityType); + manager.a(); + } + } + + @Override + public int getStatistic(Statistic statistic, EntityType entityType) { + if (isOnline()) { + return getPlayer().getStatistic(statistic, entityType); + } else { + return CraftStatistic.getStatistic(getStatisticManager(), statistic, entityType); + } + } + + @Override + public void incrementStatistic(Statistic statistic, EntityType entityType, int amount) { + if (isOnline()) { + getPlayer().incrementStatistic(statistic, entityType, amount); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.incrementStatistic(manager, statistic, entityType, amount); + manager.a(); + } + } + + @Override + public void decrementStatistic(Statistic statistic, EntityType entityType, int amount) { + if (isOnline()) { + getPlayer().decrementStatistic(statistic, entityType, amount); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.decrementStatistic(manager, statistic, entityType, amount); + manager.a(); + } + } + + @Override + public void setStatistic(Statistic statistic, EntityType entityType, int newValue) { + if (isOnline()) { + getPlayer().setStatistic(statistic, entityType, newValue); + } else { + ServerStatisticManager manager = getStatisticManager(); + CraftStatistic.setStatistic(manager, statistic, entityType, newValue); + manager.a(); + } + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java b/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java index 50524e286c..29d298319b 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java @@ -8,9 +8,12 @@ import net.minecraft.server.EntityTypes; import net.minecraft.server.IRegistry; import net.minecraft.server.Item; import net.minecraft.server.MinecraftKey; +import net.minecraft.server.ServerStatisticManager; import net.minecraft.server.StatisticList; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.Statistic; +import org.bukkit.Statistic.Type; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.EntityType; @@ -188,4 +191,110 @@ public enum CraftStatistic { } return null; } + + public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic) { + incrementStatistic(manager, statistic, 1); + } + + public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic) { + decrementStatistic(manager, statistic, 1); + } + + public static int getStatistic(ServerStatisticManager manager, Statistic statistic) { + Validate.notNull(statistic, "Statistic cannot be null"); + Validate.isTrue(statistic.getType() == Type.UNTYPED, "Must supply additional paramater for this statistic"); + return manager.getStatisticValue(CraftStatistic.getNMSStatistic(statistic)); + } + + public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, int amount) { + Validate.isTrue(amount > 0, "Amount must be greater than 0"); + setStatistic(manager, statistic, getStatistic(manager, statistic) + amount); + } + + public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, int amount) { + Validate.isTrue(amount > 0, "Amount must be greater than 0"); + setStatistic(manager, statistic, getStatistic(manager, statistic) - amount); + } + + public static void setStatistic(ServerStatisticManager manager, Statistic statistic, int newValue) { + Validate.notNull(statistic, "Statistic cannot be null"); + Validate.isTrue(statistic.getType() == Type.UNTYPED, "Must supply additional paramater for this statistic"); + Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); + net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getNMSStatistic(statistic); + manager.setStatistic(null, nmsStatistic, newValue);; + } + + public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material) { + incrementStatistic(manager, statistic, material, 1); + } + + public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material) { + decrementStatistic(manager, statistic, material, 1); + } + + public static int getStatistic(ServerStatisticManager manager, Statistic statistic, Material material) { + Validate.notNull(statistic, "Statistic cannot be null"); + Validate.notNull(material, "Material cannot be null"); + Validate.isTrue(statistic.getType() == Type.BLOCK || statistic.getType() == Type.ITEM, "This statistic does not take a Material parameter"); + net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material); + Validate.notNull(nmsStatistic, "The supplied Material does not have a corresponding statistic"); + return manager.getStatisticValue(nmsStatistic); + } + + public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int amount) { + Validate.isTrue(amount > 0, "Amount must be greater than 0"); + setStatistic(manager, statistic, material, getStatistic(manager, statistic, material) + amount); + } + + public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int amount) { + Validate.isTrue(amount > 0, "Amount must be greater than 0"); + setStatistic(manager, statistic, material, getStatistic(manager, statistic, material) - amount); + } + + public static void setStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int newValue) { + Validate.notNull(statistic, "Statistic cannot be null"); + Validate.notNull(material, "Material cannot be null"); + Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); + Validate.isTrue(statistic.getType() == Type.BLOCK || statistic.getType() == Type.ITEM, "This statistic does not take a Material parameter"); + net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material); + Validate.notNull(nmsStatistic, "The supplied Material does not have a corresponding statistic"); + manager.setStatistic(null, nmsStatistic, newValue); + } + + public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType) { + incrementStatistic(manager, statistic, entityType, 1); + } + + public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType) { + decrementStatistic(manager, statistic, entityType, 1); + } + + public static int getStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType) { + Validate.notNull(statistic, "Statistic cannot be null"); + Validate.notNull(entityType, "EntityType cannot be null"); + Validate.isTrue(statistic.getType() == Type.ENTITY, "This statistic does not take an EntityType parameter"); + net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType); + Validate.notNull(nmsStatistic, "The supplied EntityType does not have a corresponding statistic"); + return manager.getStatisticValue(nmsStatistic); + } + + public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int amount) { + Validate.isTrue(amount > 0, "Amount must be greater than 0"); + setStatistic(manager, statistic, entityType, getStatistic(manager, statistic, entityType) + amount); + } + + public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int amount) { + Validate.isTrue(amount > 0, "Amount must be greater than 0"); + setStatistic(manager, statistic, entityType, getStatistic(manager, statistic, entityType) - amount); + } + + public static void setStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int newValue) { + Validate.notNull(statistic, "Statistic cannot be null"); + Validate.notNull(entityType, "EntityType cannot be null"); + Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); + Validate.isTrue(statistic.getType() == Type.ENTITY, "This statistic does not take an EntityType parameter"); + net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType); + Validate.notNull(nmsStatistic, "The supplied EntityType does not have a corresponding statistic"); + manager.setStatistic(null, nmsStatistic, newValue); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 4109e6b0b5..405c8ba10b 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -80,7 +80,6 @@ import org.bukkit.OfflinePlayer; import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.Statistic; -import org.bukkit.Statistic.Type; import org.bukkit.WeatherType; import org.bukkit.block.data.BlockData; import org.bukkit.configuration.serialization.DelegateDeserialization; @@ -720,126 +719,92 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public void incrementStatistic(Statistic statistic) { - incrementStatistic(statistic, 1); + CraftStatistic.incrementStatistic(getHandle().getStatisticManager(), statistic); } @Override public void decrementStatistic(Statistic statistic) { - decrementStatistic(statistic, 1); + CraftStatistic.decrementStatistic(getHandle().getStatisticManager(), statistic); } @Override public int getStatistic(Statistic statistic) { - Validate.notNull(statistic, "Statistic cannot be null"); - Validate.isTrue(statistic.getType() == Type.UNTYPED, "Must supply additional paramater for this statistic"); - return getHandle().getStatisticManager().getStatisticValue(CraftStatistic.getNMSStatistic(statistic)); + return CraftStatistic.getStatistic(getHandle().getStatisticManager(), statistic); } @Override public void incrementStatistic(Statistic statistic, int amount) { - Validate.isTrue(amount > 0, "Amount must be greater than 0"); - setStatistic(statistic, getStatistic(statistic) + amount); + CraftStatistic.incrementStatistic(getHandle().getStatisticManager(), statistic, amount); } @Override public void decrementStatistic(Statistic statistic, int amount) { - Validate.isTrue(amount > 0, "Amount must be greater than 0"); - setStatistic(statistic, getStatistic(statistic) - amount); + CraftStatistic.decrementStatistic(getHandle().getStatisticManager(), statistic, amount); } @Override public void setStatistic(Statistic statistic, int newValue) { - Validate.notNull(statistic, "Statistic cannot be null"); - Validate.isTrue(statistic.getType() == Type.UNTYPED, "Must supply additional paramater for this statistic"); - Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); - net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getNMSStatistic(statistic); - getHandle().getStatisticManager().setStatistic(getHandle(), nmsStatistic, newValue); + CraftStatistic.setStatistic(getHandle().getStatisticManager(), statistic, newValue); } @Override public void incrementStatistic(Statistic statistic, Material material) { - incrementStatistic(statistic, material, 1); + CraftStatistic.incrementStatistic(getHandle().getStatisticManager(), statistic, material); } @Override public void decrementStatistic(Statistic statistic, Material material) { - decrementStatistic(statistic, material, 1); + CraftStatistic.decrementStatistic(getHandle().getStatisticManager(), statistic, material); } @Override public int getStatistic(Statistic statistic, Material material) { - Validate.notNull(statistic, "Statistic cannot be null"); - Validate.notNull(material, "Material cannot be null"); - Validate.isTrue(statistic.getType() == Type.BLOCK || statistic.getType() == Type.ITEM, "This statistic does not take a Material parameter"); - net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material); - Validate.notNull(nmsStatistic, "The supplied Material does not have a corresponding statistic"); - return getHandle().getStatisticManager().getStatisticValue(nmsStatistic); + return CraftStatistic.getStatistic(getHandle().getStatisticManager(), statistic, material); } @Override public void incrementStatistic(Statistic statistic, Material material, int amount) { - Validate.isTrue(amount > 0, "Amount must be greater than 0"); - setStatistic(statistic, material, getStatistic(statistic, material) + amount); + CraftStatistic.incrementStatistic(getHandle().getStatisticManager(), statistic, material, amount); } @Override public void decrementStatistic(Statistic statistic, Material material, int amount) { - Validate.isTrue(amount > 0, "Amount must be greater than 0"); - setStatistic(statistic, material, getStatistic(statistic, material) - amount); + CraftStatistic.decrementStatistic(getHandle().getStatisticManager(), statistic, material, amount); } @Override public void setStatistic(Statistic statistic, Material material, int newValue) { - Validate.notNull(statistic, "Statistic cannot be null"); - Validate.notNull(material, "Material cannot be null"); - Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); - Validate.isTrue(statistic.getType() == Type.BLOCK || statistic.getType() == Type.ITEM, "This statistic does not take a Material parameter"); - net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material); - Validate.notNull(nmsStatistic, "The supplied Material does not have a corresponding statistic"); - getHandle().getStatisticManager().setStatistic(getHandle(), nmsStatistic, newValue); + CraftStatistic.setStatistic(getHandle().getStatisticManager(), statistic, material, newValue); } @Override public void incrementStatistic(Statistic statistic, EntityType entityType) { - incrementStatistic(statistic, entityType, 1); + CraftStatistic.incrementStatistic(getHandle().getStatisticManager(), statistic, entityType); } @Override public void decrementStatistic(Statistic statistic, EntityType entityType) { - decrementStatistic(statistic, entityType, 1); + CraftStatistic.decrementStatistic(getHandle().getStatisticManager(), statistic, entityType); } @Override public int getStatistic(Statistic statistic, EntityType entityType) { - Validate.notNull(statistic, "Statistic cannot be null"); - Validate.notNull(entityType, "EntityType cannot be null"); - Validate.isTrue(statistic.getType() == Type.ENTITY, "This statistic does not take an EntityType parameter"); - net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType); - Validate.notNull(nmsStatistic, "The supplied EntityType does not have a corresponding statistic"); - return getHandle().getStatisticManager().getStatisticValue(nmsStatistic); + return CraftStatistic.getStatistic(getHandle().getStatisticManager(), statistic, entityType); } @Override public void incrementStatistic(Statistic statistic, EntityType entityType, int amount) { - Validate.isTrue(amount > 0, "Amount must be greater than 0"); - setStatistic(statistic, entityType, getStatistic(statistic, entityType) + amount); + CraftStatistic.incrementStatistic(getHandle().getStatisticManager(), statistic, entityType, amount); } @Override public void decrementStatistic(Statistic statistic, EntityType entityType, int amount) { - Validate.isTrue(amount > 0, "Amount must be greater than 0"); - setStatistic(statistic, entityType, getStatistic(statistic, entityType) - amount); + CraftStatistic.decrementStatistic(getHandle().getStatisticManager(), statistic, entityType, amount); } @Override public void setStatistic(Statistic statistic, EntityType entityType, int newValue) { - Validate.notNull(statistic, "Statistic cannot be null"); - Validate.notNull(entityType, "EntityType cannot be null"); - Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); - Validate.isTrue(statistic.getType() == Type.ENTITY, "This statistic does not take an EntityType parameter"); - net.minecraft.server.Statistic nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType); - Validate.notNull(nmsStatistic, "The supplied EntityType does not have a corresponding statistic"); - getHandle().getStatisticManager().setStatistic(getHandle(), nmsStatistic, newValue); + CraftStatistic.setStatistic(getHandle().getStatisticManager(), statistic, entityType, newValue); } @Override