From c328c274d4c18ca677a36f606a3b0a4509da91a5 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 19 Jun 2020 15:02:35 +0200 Subject: [PATCH] Statistics --- .../minosoft/game/datatypes/Statistics.java | 96 +++++++++++++++++++ .../clientbound/play/PacketStatistics.java | 55 +++++++++++ ...roperty.java => PacketWindowProperty.java} | 2 +- .../serverbound/play/PacketClientStatus.java | 72 ++++++++++++++ .../protocol/protocol/PacketHandler.java | 6 +- .../minosoft/protocol/protocol/Protocol.java | 1 + 6 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/game/datatypes/Statistics.java create mode 100644 src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStatistics.java rename src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/{WindowProperty.java => PacketWindowProperty.java} (96%) create mode 100644 src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientStatus.java diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/Statistics.java b/src/main/java/de/bixilon/minosoft/game/datatypes/Statistics.java new file mode 100644 index 000000000..4ec502166 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/Statistics.java @@ -0,0 +1,96 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes; + +public enum Statistics { + ACHIEVEMENT_OPEN_INVENTORY(new Identifier("achievement.openInventory")), + ACHIEVEMENT_MINE_WOOD(new Identifier("achievement.mineWood")), + ACHIEVEMENT_BUILD_WORKBENCH(new Identifier("achievement.buildWorkBench")), + ACHIEVEMENT_BUILD_PICKAXE(new Identifier("achievement.buildPickaxe")), + ACHIEVEMENT_BUILD_FURNACE(new Identifier("achievement.buildFurnace")), + ACHIEVEMENT_ACQUIRE_IRON(new Identifier("achievement.acquireIron")), + ACHIEVEMENT_BUILD_HOE(new Identifier("achievement.buildHoe")), + ACHIEVEMENT_MAKE_BREAD(new Identifier("achievement.makeBread")), + ACHIEVEMENT_BAKE_CAKE(new Identifier("achievement.bakeCake")), + ACHIEVEMENT_BUILD_BETTER_PICKAXE(new Identifier("achievement.buildBetterPickaxe")), + ACHIEVEMENT_COOK_FISH(new Identifier("achievement.cookFish")), + ACHIEVEMENT_ON_A_RAIL(new Identifier("achievement.onARail")), + ACHIEVEMENT_BUILD_SWORD(new Identifier("achievement.buildSword")), + ACHIEVEMENT_KILL_ENEMY(new Identifier("achievement.killEnemy")), + ACHIEVEMENT_KILL_COW(new Identifier("achievement.killCow")), + ACHIEVEMENT_FLY_PIG(new Identifier("achievement.flyPig")), + ACHIEVEMENT_SNIPE_SKELETON(new Identifier("achievement.snipeSkeleton")), + ACHIEVEMENT_DIAMONDS(new Identifier("achievement.diamonds")), + ACHIEVEMENT_DIAMONDS_TO_YOU(new Identifier("achievement.diamondsToYou")), + ACHIEVEMENT_PORTAL(new Identifier("achievement.portal")), + ACHIEVEMENT_GHAST(new Identifier("achievement.ghast")), + ACHIEVEMENT_BLAZE_ROD(new Identifier("achievement.blazeRod")), + ACHIEVEMENT_POTION(new Identifier("achievement.potion")), + ACHIEVEMENT_THE_END(new Identifier("achievement.theEnd")), + ACHIEVEMENT_THE_END2(new Identifier("achievement.theEnd2")), + ACHIEVEMENT_ENCHANTMENTS(new Identifier("achievement.enchantments")), + ACHIEVEMENT_OVERKILL(new Identifier("achievement.overkill")), + ACHIEVEMENT_BOOKCASE(new Identifier("achievement.bookcase")), + ACHIEVEMENT_BREED_COW(new Identifier("achievement.breedCow")), + ACHIEVEMENT_SPAWN_WITHER(new Identifier("achievement.spawnWither")), + ACHIEVEMENT_KILL_WITHER(new Identifier("achievement.killWither")), + ACHIEVEMENT_FULL_BEACON(new Identifier("achievement.fullBeacon")), + ACHIEVEMENT_EXPLORE_ALL_BIOMES(new Identifier("achievement.exploreAllBiomes")), + + STAT_LEAVE_GAME(new Identifier("stat.leaveGame")), + STAT_PLAY_ONE_MINUTE(new Identifier("stat.playOneMinute")), + STAT_WALK_ONE_CM(new Identifier("stat.walkOneCm")), + STAT_SWIM_ONE_CM(new Identifier("stat.swimOneCm")), + STAT_FALL_ONE_CM(new Identifier("stat.fallOneCm")), + STAT_CLIMB_ONE_CM(new Identifier("stat.climbOneCm")), + STAT_FLY_ONE_CM(new Identifier("stat.flyOneCm")), + STAT_DIVE_ONE_CM(new Identifier("stat.diveOneCm")), + STAT_MINECART__ONE__CM(new Identifier("stat.minecartOneCm")), + STAT_BOAT__ONE__CM(new Identifier("stat.boatOneCm")), + STAT_PIG__ONE__CM(new Identifier("stat.pigOneCm")), + STAT_HORSE__ONE__CM(new Identifier("stat.horseOneCm")), + STAT_JUMP(new Identifier("stat.jump")), + STAT_DROP(new Identifier("stat.drop")), + STAT_DAMAGE_DEALT(new Identifier("stat.damageDealt")), + STAT_DAMAGE_TAKEN(new Identifier("stat.damageTaken")), + STAT_DEATHS(new Identifier("stat.deaths")), + STAT_MOB_KILLS(new Identifier("stat.mobKills")), + STAT_ANIMALS_BRED(new Identifier("stat.animalsBred")), + STAT_PLAYER_KILLS(new Identifier("stat.playerKills")), + STAT_FISH_CAUGHT(new Identifier("stat.fishCaught")), + STAT_JUN_KFISHED(new Identifier("stat.junkFished")), + STAT_TREASURE_FISHED(new Identifier("stat.treasureFished")), + + ; + + final Identifier identifier; + + Statistics(Identifier identifier) { + this.identifier = identifier; + } + + public static Statistics byIdentifier(Identifier identifier) { + for (Statistics s : values()) { + if (s.getIdentifier().equals(identifier)) { + return s; + } + } + return null; + } + + public Identifier getIdentifier() { + return identifier; + } + +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStatistics.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStatistics.java new file mode 100644 index 000000000..f4aa6bedf --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStatistics.java @@ -0,0 +1,55 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.game.datatypes.Identifier; +import de.bixilon.minosoft.game.datatypes.Statistics; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +import java.util.HashMap; + +public class PacketStatistics implements ClientboundPacket { + HashMap statistics = new HashMap<>(); + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + int length = buffer.readVarInt(); + for (int i = 0; i < length; i++) { + statistics.put(Statistics.byIdentifier(new Identifier(buffer.readString())), buffer.readVarInt()); + } + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Received player statistics (count=%d)", statistics.size())); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public HashMap getStatistics() { + return statistics; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/WindowProperty.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowProperty.java similarity index 96% rename from src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/WindowProperty.java rename to src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowProperty.java index 76d200a89..aba93d973 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/WindowProperty.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowProperty.java @@ -19,7 +19,7 @@ import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; import de.bixilon.minosoft.protocol.protocol.PacketHandler; import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; -public class WindowProperty implements ClientboundPacket { +public class PacketWindowProperty implements ClientboundPacket { byte windowId; short property; short value; diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientStatus.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientStatus.java new file mode 100644 index 000000000..5ec6fce88 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientStatus.java @@ -0,0 +1,72 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.serverbound.play; + +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ServerboundPacket; +import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.Packets; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketClientStatus implements ServerboundPacket { + + private final ClientStatus status; + + public PacketClientStatus(ClientStatus status) { + this.status = status; + log(); + } + + + @Override + public OutPacketBuffer write(ProtocolVersion v) { + OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_STATUS)); + switch (v) { + case VERSION_1_7_10: + buffer.writeByte((byte) status.getId()); + break; + } + return buffer; + } + + @Override + public void log() { + Log.protocol(String.format("Sending client status packet (status=%s)", status.name())); + } + + public enum ClientStatus { + PERFORM_RESPAWN(0), + REQUEST_STATISTICS(1), + OPEN_INVENTORY_ACHIEVEMENT(2); + + final int id; + + ClientStatus(int id) { + this.id = id; + } + + public static ClientStatus byId(int id) { + for (ClientStatus s : values()) { + if (s.getId() == id) { + return s; + } + } + return null; + } + + public int getId() { + return id; + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java index 0bec7e2e1..589f0a1eb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -328,11 +328,15 @@ public class PacketHandler { //ToDo } - public void handle(WindowProperty pkg) { + public void handle(PacketWindowProperty pkg) { //ToDo } public void handle(PacketConfirmTransactionReceiving pkg) { //ToDo } + + public void handle(PacketStatistics pkg) { + //ToDo + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java index b0f48e612..8d999f2c7 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java @@ -93,6 +93,7 @@ public interface Protocol { packetClassMapping.put(Packets.Clientbound.PLAY_SET_SLOT, PacketSetSlot.class); packetClassMapping.put(Packets.Clientbound.PLAY_WINDOW_CONFIRMATION, PacketConfirmTransactionReceiving.class); packetClassMapping.put(Packets.Clientbound.PLAY_PLAYER_ABILITIES, PacketPlayerAbilitiesReceiving.class); + packetClassMapping.put(Packets.Clientbound.PLAY_STATISTICS, PacketStatistics.class); } int getProtocolVersion();