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 PacketPlayOutTitle extends OutPacket { 025 026 protected int action; 027 protected Object[] values; 028 029 @Override 030 public int id() { 031 return 0x45; 032 } 033 034 public int action() { 035 return this.action; 036 } 037 038 public Object[] values() { 039 return this.values; 040 } 041 042 @Override 043 public void encode(ByteBuf buf) { 044 Codec.writeVarInt32(buf, this.action); 045 046 for (Object o : this.values) { 047 switch (o.getClass().getSimpleName()) { 048 case "String": 049 Codec.writeString(buf, (String) o); 050 break; 051 052 case "Integer": 053 buf.writeInt((Integer) o); 054 break; 055 056 default: 057 // ignore bad developers 058 break; 059 } 060 } 061 } 062 063 public enum TitleAction { 064 TITLE(0), 065 SUBTITLE(1), 066 TIMES_AND_DISPLAY(2), 067 HIDE(3), 068 RESET(4); 069 070 private int id; 071 072 TitleAction(int id) { 073 this.id = id; 074 } 075 076 public int id() { 077 return id; 078 } 079 } 080}