TinyProtocolAPI v4.5.1

small library.

  1. ZahuseK
    Tested Minecraft Versions:
    • 1.8
    • 1.9
    TinyProtocolAPI
    [​IMG]
    TabAPI
    [​IMG]
    BetterServerListPingEvent
    [​IMG]


    TabAPI, BarAPI, HoloAPI for MC1.7 ? without addons ? Open src ? Check my first fun with packets (PacketAPI-opensrc "TinyProtocolAPI-PROTOTYPE") - HERE !


    TabAPI:

    • void refresh(Class<? extends Plugin> plugin, Player player, Preference priority, SettingAPI<TabModify> modify);
    • void refresh(Class<? extends Plugin> plugin, Player player, SettingAPI<TabModify> modify);
    • void setDefaultPreference(Class<? extends Plugin> plugin, Preference priority);
    • void remove(Class<? extends Plugin> plugin, Player player);
    • boolean hasAPI(Player player);
    TabModify:
    • void setMessage(int x, int y, String message);
    • void set(int x, int y, String display, String texture);
    • void set(int x, int y, String display, int ping);
    • void set(int x, int y, String display, String texture, int ping);
    • void setSignal(int x, int y, int signal);
    • void setSignal(int ping);
    • void setTexture(int x, int y, String texture);
    • void setTexture(String texture);
    • void setHeader(List<String> header);
    • void setFooter(List<String> footer);
    • void set(List<String> head, List<String> foot);
    • String getMessage(int x, int y);
    • String getTexture(int x, int y);
    • int getSignal(int x, int y);
    • List<String> getHeader();
    • List<String> getFooter();
    TitleAPI:
    • void title(Player player, String title, int start, int stay, int end);
    • void subtitle(Player player, String subtitle, int start, int stay, int end);
    • void subtitle(Player player, String subtitle)
    • void broadcast(Player player, String title, String subtitle, int start, int stay, int end);
    • void hotbar(Player player, String msg);
    • void clear(Player player);
    CREATING and LISTENING PACKETS - EXAMPLE

    ¡ Example ! Warning - The code is only for example.
    Code (Text):

    package com.gmail.zahusek.test;

    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.stream.Collectors;
    import java.util.stream.IntStream;

    import javax.imageio.ImageIO;

    import org.apache.commons.lang.StringUtils;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;

    import ru.tehkode.permissions.bukkit.PermissionsEx;

    import com.gmail.zahusek.test.listener.BetterServerListPingEvent;
    import com.gmail.zahusek.tinyprotocolapi.TinyProtocolAPI;
    import com.gmail.zahusek.tinyprotocolapi.api.Preference;
    import com.gmail.zahusek.tinyprotocolapi.api.tab.TabAPI;
    import com.gmail.zahusek.tinyprotocolapi.api.title.TitleAPI;
    import com.gmail.zahusek.tinyprotocolapi.listener.PacketHandler;
    import com.gmail.zahusek.tinyprotocolapi.listener.PacketListener;
    import com.gmail.zahusek.tinyprotocolapi.listener.PacketPriority;
    import com.google.gson.JsonObject;

    public class TestTPAPI extends JavaPlugin implements Listener, PacketListener
    {
        @Override
        public void onEnable()
        {
            TinyProtocolAPI.registerPackets(this, this);
            TabAPI.setDefaultPreference(TestTPAPI.class, Preference.NORMAL);
            getServer().getPluginManager().registerEvents(this, this);
            new BukkitRunnable() {

                @Override
                public void run() {
                    for(Player player : getServer().getOnlinePlayers())
                    {
                        if(!TabAPI.hasAPI(player)) continue;
                      TabAPI.refresh(TestTPAPI.class, player, modify ->
                      {
                          modify.setMessage(2, 10, "§a" + getServer().getOnlinePlayers().size() + " §6/§c " + getServer().getMaxPlayers());
                          modify.setMessage(2, 12, "§d" + String.format("%tT", System.currentTimeMillis()));
                          modify.setMessage(2, 14, "§7" + String.format("%tF", System.currentTimeMillis()));

                      });
                    }
       
                }
            }.runTaskTimerAsynchronously(this, 0, 10);
        }

        @EventHandler(priority = EventPriority.MONITOR)
        void join (PlayerJoinEvent e)
        {
            Player player = e.getPlayer();
            TabAPI.refresh(TestTPAPI.class, player, modify ->
            {
                modify.setSignal(99999);
                modify.setMessage(3, 0, "§6§l§m           §6§lI#I");
                modify.setMessage(0, 0, "§6§lI#I§6§l§m                   ");

                for(int i = 1; i < 3; i++)
                {
                    modify.setMessage(i, 0, "§6§l§m                   ");
                    modify.setMessage(i, 19, "§6§l§m                   ");
                }

                for(int i = 1; i < 19; i++)
                {
                    modify.setMessage(0, i, "§6§lI#I");
                    modify.setMessage(3, i, "              §6§lI#I");
                }

                modify.setMessage(0, 19, "§6§lI#I§6§l§m                   ");
                modify.setMessage(3, 19, "§6§l§m           §6§lI#I");

                modify.setMessage(1, 2, "§a§oProfile: ");
                modify.setMessage(2, 2, "§2" + player.getDisplayName());

                modify.setMessage(1, 4, "§c§oIP: ");
                modify.setMessage(2, 4, "§4" + player.getAddress().getAddress().getHostAddress());

                modify.setMessage(1, 6, "§b§oFirst Played: ");
                modify.setMessage(2, 6, "§3" + String.format("%tF", player.getFirstPlayed()));

                modify.setMessage(1, 8, "§e§oOnline mode: ");
                modify.setMessage(2, 8, getServer().getOnlineMode() == true ? "§aYeep" : "§cNope");

                modify.setMessage(1, 10, "§9§oStatus o/m: ");
                //status

                modify.setMessage(1, 12, "§5§oTime: ");
                //time

                modify.setMessage(1, 14, "§8§oDate: ");
                //date

                modify.setMessage(1, 16, "§1§oGroup: ");
                modify.setMessage(2, 16, "§f" + PermissionsEx.getUser(player).getGroupNames()[0]);


            });
            TitleAPI.broadcast(player, "§aTinyProtocilAPI", "§24.0", 0, 20*5, 0);

            new BukkitRunnable()
            {

                @Override
                public void run() {
                  TitleAPI.title(player, "§6Descriprtion:", 0, 20*12, 0);
                  TitleAPI.subtitle(player, "§bOptimization");
                }
            }.runTaskLaterAsynchronously(this, 20*3);

            new BukkitRunnable()
            {

                @Override
                public void run() {
                    TitleAPI.subtitle(player, "§bNew Methods");
                }
            }.runTaskLaterAsynchronously(this, 20*6);
            new BukkitRunnable()
            {

                @Override
                public void run() {
                    TitleAPI.subtitle(player, "§bCorrections");
                }
            }.runTaskLaterAsynchronously(this, 20*9);
            new BukkitRunnable()
            {

                @Override
                public void run() {
                    TitleAPI.subtitle(player, "§cDelete addon \"§5BarAPI§c\"");
                }
            }.runTaskLaterAsynchronously(this, 20*12);
        }

        @PacketHandler(priority = PacketPriority.LOWEST)
        void status(BetterServerListPingEvent e) throws MalformedURLException, IOException
        {
            JsonObject deFault = e.getDefaultJson();
            deFault.addProperty(e.motd(), "§6▓TinyProtocolAPI▓" + "\n" + "§9§k###§eVersion §5§n4.1§6§9§k###");
            deFault.addProperty(e.icon(), e.faviconSerializer(
                    ImageIO.read(new URL("http://megaicons.net/static/img/icons_sizes/257/1552/64/fc-barcelona-icon.png"))));

            JsonObject sample = e.getSampleJson();
            sample.add(e.hoverList(), e.sampleList(IntStream.range(0, 20).mapToObj((i) -> {
                if (i == 10) return "§9TinyProtocolAPI §e- §dBetterServerListPingEvent";
                else return StringUtils.join(IntStream.range(0, 80).mapToObj((o) -> " ").toArray());
                }).collect(Collectors.toList())));

            JsonObject protocol = e.getProtocolJson();
            protocol.addProperty(e.protocolVersion(), -1);
            int online = sample.get(e.online()).getAsInt(), max = sample.get(e.maxOnline()).getAsInt();
            protocol.addProperty(e.protocolName(), "§eLeftMotD" + StringUtils.join(IntStream.range(0, 72).mapToObj((i) -> " ").toArray()) +
                    "§7" + online + "§8/§7" + max);

            e.saveJson();
        }

    }
     
    ¡ ServerListPingEvent !
    Code (Text):

    package com.gmail.zahusek.test.listener;

    import io.netty.buffer.ByteBuf;
    import io.netty.buffer.ByteBufOutputStream;

    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.util.Collection;

    import org.bukkit.entity.Player;

    import com.gmail.zahusek.tinyprotocolapi.asm.reflection.ClassAccess;
    import com.gmail.zahusek.tinyprotocolapi.listener.PacketEvent;
    import com.gmail.zahusek.tinyprotocolapi.listener.PacketHandlerList;
    import com.gmail.zahusek.tinyprotocolapi.listener.PacketID;
    import com.gmail.zahusek.tinyprotocolapi.listener.PacketType;
    import com.google.common.base.Charsets;
    import com.google.gson.Gson;
    import com.google.gson.JsonArray;
    import com.google.gson.JsonObject;
    import com.google.gson.JsonParser;

    import static java.util.UUID.randomUUID;
    import static javax.imageio.ImageIO.write;
    import static io.netty.buffer.Unpooled.buffer;
    import static io.netty.handler.codec.base64.Base64.encode;

    @PacketID(id = PacketType.PacketStatusOutServerInfo)
    public class BetterServerListPingEvent extends PacketEvent
    {

        public static final PacketHandlerList handler = new PacketHandlerList();

        private static final String DEFID = randomUUID().toString();
        private static final ClassAccess fa = new ClassAccess("{nms}.PacketStatusOutServerInfo");
        private static final Class<?> fb = fa.getCanonicalClass("{nms}.ServerPing");
        private static final Gson fc = fa.get(null, Gson.class, 0);

        private final JsonObject json;

        public BetterServerListPingEvent(Player player, Object handle) {
            super(player, handle);
            json = new JsonParser().parse(fc.toJson(handle)).getAsJsonObject().getAsJsonObject("b");
        }

        public JsonArray sampleList(Collection<String> list)
        {
            JsonArray array = new JsonArray();
            for(String player : list)
            {
                JsonObject data = new JsonObject();
                data.addProperty("name", player);
                data.addProperty("id", DEFID);
                array.add(data);
            }
            return array;
        }

        public JsonObject getDefaultJson () { return json; }
        public JsonObject getProtocolJson() { return  json.getAsJsonObject("version"); }
        public JsonObject getSampleJson() { return  json.getAsJsonObject("players"); }
        public void saveJson() { fa.set(getPacket(), 1, fc.fromJson(json, fb)); }

        public String faviconSerializer (BufferedImage image)
        {
            if(image.getWidth() != 64 || image.getHeight() != 64) return json.get("favicon").getAsString();
           ByteBuf buffer = buffer();
           try { write(image, "PNG", new ByteBufOutputStream(buffer)); }
           catch (IOException e) { return json.get("favicon").getAsString(); }
           return "data:image/png;base64," + encode(buffer).toString(Charsets.UTF_8);
        }

        public String motd()
        { return "description";}

        public String icon()
        { return "favicon";}

        public String hoverList()
        { return "sample";}

        public String online()
        { return "online";}

        public String maxOnline()
        { return "max";}

        public String protocolVersion()
        { return "protocol";}

        public String protocolName()
        { return "name";}
    }

     
    GITHUB
    zThana, ramewn4421, Voidev and 8 others like this.

Recent Reviews

  1. KSDpolska
    KSDpolska
    1/5,
    Version: v4.5.1
    DOESn't WORK! THE CONSOLE GIVE ME A CRITICAL ERROR!
    It's HORRIBLE! !
  2. stevejone1997
    stevejone1997
    1/5,
    Version: v4.5.1
    The app didn't work for me as i expected. That is all what i have to say about it.
  3. Wruczek
    Wruczek
    5/5,
    Version: v4.5.1
    Excellent and useful API. Everything in one library, good replacement for BarAPI, TabAPI, HoloAPI and ProtocolLib.

    Gratulacje! :D
  4. TheIntelloBox
    TheIntelloBox
    1/5,
    Version: 3.8.1
    I'm using TinyProtocolAPI 3.6 and look at this :
    8,809.03% of the ticks of my server !!!!
    This is lagging extremely !
    1. ZahuseK
      Author's Response
      Mhmm .. TinyProtocolAPi uses "reflection", so the problem should be performance only if you send a large number of packets in a short period of time, e.g refresh all TabList in 5-10 ticks. I want dispense of reflection, but is it on test phase ;v. Thank you for sharp opinion, my friend ;x.
  5. benjozork
    benjozork
    5/5,
    Version: 3.8.1
    Wow! Useful library, can't wait to use it in my next plugin project! Thanks for the amazing lib! You are amazing!
    1. ZahuseK
      Author's Response
      Thanks you so much ^^.
  6. BartzzDev
    BartzzDev
    5/5,
    Version: 3.8
    Best plug that I ever seen!
    No protocol, no anything else..
    The best of the best <3

    ps: pozdo zahus mordo! :D
    1. ZahuseK
      Author's Response
      Thanks, again ^^.

      Bez p.s'a ;D
  7. ElDzi
    ElDzi
    5/5,
    Version: 3.7.9
    Awesome plugin ! I love that library ! Very nice!!
    Thats FUCK-UP! Very helpful ! <3 <3 <3

    I'll use this in my plugins <3!
    1. ZahuseK
      Author's Response
      Nie podlizuj się xd.

      Thanks ;D.
  8. Kamilkime
    Kamilkime
    5/5,
    Version: 3.7.8
    I LOVE THIS API :D :D :D :D :D
    IT SAVED MY ASS SOOOOO MANY TIMES xD
    My guild plugins still uses TabAPI from this plugin and it never generates lags!
    1. ZahuseK
      Author's Response
      Hah, Thanks U ^^.
  9. su1414
    su1414
    5/5,
    Version: 3.6.2
    Great!! I am using it, and it is EPIC. Good luck in the further development of the plugin.

    Tak wgle to siemka xD
    1. ZahuseK
      Author's Response
      Thanks you. I'll try not to disappoint ^^.

      Siemanko ;D