Skip to content

Instantly share code, notes, and snippets.

@crocstar47
Created August 16, 2016 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crocstar47/ebbd9d13482f1029b6320a63859d6083 to your computer and use it in GitHub Desktop.
Save crocstar47/ebbd9d13482f1029b6320a63859d6083 to your computer and use it in GitHub Desktop.
CRC Title Libary | Title | Header/Footer | Actionbar by crocstar47

CRC Title Libary for Bukkit/Spigot Version: 1.0.0 Author: crocstar47 Minecraft-Version: 1.10

Description: You have the Permission to use this Libary on your Plugins but you don't have the Permission to remove or modify the Information Comment!

package me.crocstar47.Packets.PacketLibs;
import java.lang.reflect.Field;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerListHeaderFooter;
import net.minecraft.server.v1_10_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_10_R1.PlayerConnection;
import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer;
public class CRC_Title_Lib {
/**
* Name: CRC Title Libary
* Version: 1.0.0
* Author: crocstar47
* MC-Version: 1.10
*
* You have the Permission to use this Libary on your Plugins but
* you don't have the Permission to remove or modify this Comment!
*/
/* Text Title */
String Titletext;
String Subtitletext;
int Fadeintime;
int Visibletime;
int Fadeouttime;
/* Header and Footer Text */
String Headertext;
String Footertext;
/* Actionbar Text */
String Actionbartext;
/* Title without Time */
public void MSZ_Title_Lib_Title(Player player, String Titletext, String Subtitletext)
{
this.Titletext = Titletext;
this.Subtitletext = Subtitletext;
//Getting Player Connection for packet
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
//Preparing Title Text
IChatBaseComponent Title = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + Titletext + "\"}");
IChatBaseComponent Subtitle = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + Subtitletext + "\"}");
//Preparing new Packet
PacketPlayOutTitle Title_Packet = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, Title);
PacketPlayOutTitle Title_Packet2 = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, Subtitle);
//Sending the Packet to the Player
connection.sendPacket(Title_Packet);
connection.sendPacket(Title_Packet2);
}
/* Title with Time */
public void MSZ_Title_Lib_Title(Player player, String Titletext, String Subtitletext, int Fadeintime, int Visibletime, int Fadeouttime)
{
this.Titletext = Titletext;
this.Subtitletext = Subtitletext;
this.Fadeintime = Fadeintime;
this.Visibletime = Visibletime;
this.Fadeouttime = Fadeouttime;
//Getting Player Connection for packet
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
//Preparing Title Text
IChatBaseComponent Title = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + Titletext + "\"}");
IChatBaseComponent Subtitle = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + Subtitletext + "\"}");
//Preparing new Packet
PacketPlayOutTitle Title_Packet = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, Title, Fadeintime, Visibletime, Fadeouttime);
PacketPlayOutTitle Title_Packet2 = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, Title);
PacketPlayOutTitle Title_Packet3 = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, Subtitle);
//Sending the Packet to the Player
connection.sendPacket(Title_Packet);
connection.sendPacket(Title_Packet2);
connection.sendPacket(Title_Packet3);
}
/* Header and Footer */
public void MSZ_Title_Lib_Header_And_Footer(Player player, String Headertext, String Footertext)
{
this.Headertext = Headertext;
this.Footertext = Footertext;
//Getting Player Connection for packet
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
//Preparing new Packet
PacketPlayOutPlayerListHeaderFooter Header_And_Footer_Packet = new PacketPlayOutPlayerListHeaderFooter();
//Preparing Text for Header and Footer
IChatBaseComponent Header = ChatSerializer.a("{\"text\":\"" + Headertext + "\"}");
IChatBaseComponent Footer = ChatSerializer.a("{\"text\":\"" + Footertext + "\"}");
//Using Reflections to edit the Values
try
{
//Make the 2 Fields Accessible for us because its private and we need them!
Field field = Header_And_Footer_Packet.getClass().getDeclaredField("a");
field.setAccessible(true);
field.set(Header_And_Footer_Packet, Header);
Field field2 = Header_And_Footer_Packet.getClass().getDeclaredField("b");
field2.setAccessible(true);
field2.set(Header_And_Footer_Packet, Footer);
} catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex)
{
ex.printStackTrace();
}
//Sending the Packet to the Player
connection.sendPacket(Header_And_Footer_Packet);
}
/* Actionbar */
public void MSZ_Title_Lib_Actionbar(Player player, String Actionbartext)
{
this.Actionbartext = Actionbartext;
//Getting Player Connection for packet
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
//Preparing Text for Actionbar
IChatBaseComponent Actionbar = ChatSerializer.a("{\"text\":\"" + Actionbartext + "\"}");
//Preparing new Packet
PacketPlayOutChat Chat_Packet = new PacketPlayOutChat(Actionbar, (byte) 2);
//Sending the Packet to the Player
connection.sendPacket(Chat_Packet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment