001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.server.packets.play.out; 019 020import io.netty.buffer.ByteBuf; 021import net.tridentsdk.server.netty.Codec; 022import net.tridentsdk.server.netty.packet.OutPacket; 023 024public class PacketPlayOutStatistics extends OutPacket { 025 026 public static final OutPacket DEFAULT_STATISTIC = new PacketPlayOutStatistics().set("entries", null); 027 protected StatisticEntry[] entries; 028 029 @Override 030 public int id() { 031 return 0x07; 032 } 033 034 public StatisticEntry[] entries() { 035 return this.entries; 036 } 037 038 @Override 039 public void encode(ByteBuf buf) { 040 if (this.entries == null) { 041 Codec.writeVarInt32(buf, 0); 042 return; 043 } 044 045 Codec.writeVarInt32(buf, this.entries.length); 046 047 for (StatisticEntry entry : this.entries) { 048 entry.write(buf); 049 } 050 } 051 052 public static class StatisticEntry { 053 protected String string; 054 protected int value; 055 056 public String string() { 057 return this.string; 058 } 059 060 public void setString(String string) { 061 this.string = string; 062 } 063 064 public int value() { 065 return this.value; 066 } 067 068 public void setValue(int value) { 069 this.value = value; 070 } 071 072 public void write(ByteBuf buf) { 073 Codec.writeString(buf, this.string); 074 Codec.writeVarInt32(buf, this.value); 075 } 076 } 077}