[Open Source] MillenaryAPI - Packet, disguise, MySQL and more! v1.3

Discussion in 'Resources' started by ArthurMaker, Jul 14, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ArthurMaker

    GITHUB LINK: https://github.com/ArthurMaker/MillenaryAPI/tree/master/src/Millenary

    WARNING: Some things ONLY WORKS for Bukkit 1.7.9! If you are using an older version, you have to remove the disguise player method from DisguiseFactory and some other features!

    Well, I used to own a server called MillenaryCraft but, thanks to the EULA, I decided to put it down for a while. But I built a nice API for it and I supposed that it was better to put it on the internet. It does not have all the stuff, because it is a public version of it and has such "old" codes.

    I'm going out of doing Bukkit plugins and starting to creating my very first game: Project CHILD (you can see more stuff of it soon at http://projectchildgame.blogspot.com ), so I won't support that much it anymore, but here we go, MillenaryAPI!

    When I created this API, I was searching for something with everything and a little more that I could use on a normal Bukkit server or even on a BungeeCord network! So you will find a class called BungeeCordManager, where you can ping other servers and grab information about them.

    It has too a thing called PacketFactory. I built it thanks to bigteddy98 and Comphenix , because I studied a lot their packet managers (PacketAPI and ProtocolLib) and did some interesting things. I used as well a little modified version of TinyProtocol (by Comphenix) to make a ProtocolManager. You can also make PacketListeners. I did some pretty cool wrappers for you guys, like PacketWrapperStatusOutServerInfo (you can do some pretty cool stuff with I did there).

    It has Lore Translator (ItemManager class) too, it also have Fanciful (JSONMessage class), by mkremins , which I modified a little to be compatible to my PacketFactory, a HologramFactory (HologramFactory class, of course), which supports multiple lines and you can save all your holograms to a .yml using JSON (you may can keep doing the whole class, like a load method and keeping in memory all the holograms...), etc.

    May you can use as well my DisguiseFactory (it has a little YAW problem with EnderDragon's disguise and I could not be possible to solve it...) to disguise players as other players, mobs or even blocks and ghosts(only who is a ghost can see other people disguised as a ghost)! You can also use my BossBarFactory, which has some pretty cool features, a Custom Trader and some other useful stuff.

    PACKET FACTORY
    You can do almost everything with my PacketFactory. And it is MEGA easy to use it. With the wrappers I did, modifying packets will be easier for everyone. You can send me a wrapper that YOU have done and I can add it to MillenaryAPI too, with credits.

    To create PacketListeners, is the same thing as creating a normal Bukkit Listener. Just implements "PacketListener" in a class instead of "Listener" and use "@PacketHandler" instead of "@EventHandler". You can also filter packets (if you not, the PacketHandler will support ALL the packets) and cancel them when you want!
    You register PacketListeners using the PacketFactory.

    Here we go with some cool examples:
    Show Spoiler
    Registering a PacketListener
    Code:java
    1. @Override
    2. public void onEnable(){
    3. MillenaryAPI.getPacketFactory().registerPacketListener(new MySexyPacketListener());
    4. }

    Show Spoiler
    Customize the ServerPing of your server!
    Code:java
    1. import java.util.Random;
    2. import java.util.UUID;
    3.  
    4. import net.minecraft.util.com.mojang.authlib.GameProfile;
    5. import MillenaryAPI.Events.PacketReceiveEvent;
    6. import MillenaryAPI.Factories.PacketFactory.PacketFactory.PacketHandler;
    7. import MillenaryAPI.Factories.PacketFactory.Wrappers.PacketWrapperStatusOutServerInfo;
    8.  
    9. public class MySexyPacketListener implements PacketListener {
    10.  
    11. private String[] motds = {"MOTD 1", "MOTD 2", "Free diamonds NOW, bro!"};
    12.  
    13. @PacketHandler (PacketType = PacketType.PacketStatusOutServerInfo)
    14. public void onPacketStatusOutServerInfoSend(PacketSendEvent event){
    15. PacketWrapperStatusOutServerInfo w = new PacketWrapperStatusOutServerInfo(event.getPacket());
    16. //A random MOTD using it will be pretty cool, hu? So let's do it!
    17. w.setMOTD(motds[new Random().nextInt(this.motds.length-1)]);
    18. //We also can also hide or even modify the quantity of players in our servers!
    19. w.setMinPlayers(9001); // omg, it is over nine thousand!
    20. w.setMaxPlayers(69); // why not? :9
    21. String[] msg = {"Hey, this is a modified", "playercount for your", "server! :D", "", "§cYou can also use §ecolors §btoo!"};
    22. GameProfile[] gp = new GameProfile[msg.length];
    23. for(int j = 0; j < msg.length; j++) gp[j] = new GameProfile(UUID.randomUUID(), msg[j]);
    24. w.setOnlinePlayers(gp);
    25. }
    26.  
    27. }

    Show Spoiler
    You can find it inside DisguiseFactory.class
    Code:java
    1. protected static void sendPacket(Packet packet, Player except, Collection<Player> players){
    2. for(Player p : players) if(!p.equals(except)) MillenaryAPI.getPacketFactory().sendPacket(packet, p);
    3. }


    Thanks a lot to bigteddy98 (love ya) and Comphenix !

    Reserved for some codes and awesome tutorials.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
    Goblom likes this.
  2. Code:
    @SuppressWarnings("deprecation")
    public void disguiseAsBlock(Player p, Material blocktype, int data){
    	Entity e = new EntityFallingBlock(((CraftPlayer)p).getHandle().world, 0D, 0D, 0D, net.minecraft.server.v1_7_R3.Block.e(blocktype.getId()), data);
    	e.locX = p.getLocation().getX();
    	e.locY = p.getLocation().getY();
    	e.locZ = p.getLocation().getZ();
    	e.d(((CraftPlayer)p).getHandle().getId());
    	sendPacket(new PacketPlayOutEntityDestroy(((CraftPlayer)p).getHandle().getId()), p, p.getWorld().getPlayers());
    	sendPacket(new PacketPlayOutSpawnEntity(e, 70), p, p.getWorld().getPlayers());
    }
    
    This helped me a lot, thank you. :)
     
    ArthurMaker likes this.
  3. Offline

    ArthurMaker

    Fixed some errors with DisguiseFactory (disguiseAsPlayer method).
    I hope it is working now! :)
     
  4. I'm not sure, but I think you have to subtract 128 form the yaw.
    Code:java
    1.  
    2. e.yaw = p.getEyeLocation().getYaw();
    3.  

    to
    Code:java
    1.  
    2. e.yaw = p.getEyeLocation().getYaw();
    3. if (disguisetype == ENDER_DRAGON) {
    4. e.yaw -= 128;
    5. }
    6.  


    I'll test it tomorrow.
     
  5. Offline

    Bammerbom

    ArthurMaker
    Epic! Can I include this in my Plugin or is this an external plugin that users have to download too?
     
  6. Offline

    ArthurMaker

    I've already done that, but it didn't work, unfortunately. But you can try it again! Let me know if it worked for ya :D


    You can include it in every plugin, because it is open source! Have fun :D
     
  7. Offline

    Onlineids

  8. Offline

    ArthurMaker


    Actually, I don't know how to do it ^^'
     
  9. Offline

    ResultStatic

    ArthurMaker why would you take your server down just because of the eula. i havent seen one server change anything and nothing has happened. unless small servers start getting sued im not changing anything
     
  10. Offline

    ArthurMaker

    Server have till 1th August to be adequate to the EULA. After this, Idk what to expect.
     
  11. Offline

    mazentheamazin

    ArthurMaker
    2 suggestions I can have right off a scratch of the surface:
    1. Proper namespacing
    2. Maven (Some tutorials on how to even set it up on github are quite easy to find) repo. and generally on the API
     
  12. Offline

    irfantogluk

    I'll look this at home. Thanks.
     
  13. Can you please give an example for MySQL?
     
    Goblom likes this.
  14. Offline

    Goblom

    KingFaris11 it looks like you still need to know basic SQL syntax for querying, the MySQL stuff inside the plugin is just a handy way of providing a way of opening a connection to a database as well as querying data on that connection.

    To use the MySQL you do this...

    Database db = new MakersQL(args);
     
    KingFaris11 likes this.
  15. Guess I'll stick with your API then. :)
     
  16. Offline

    Goblom

    KingFaris11 why don't you just learn SQL, it's not hard at all
     
  17. It's boring and I've tried many time but keep getting TONS of errors when I implement it into Java.
     
  18. Offline

    DevRosemberg

    Damn this is nice. Good Job!
     
    ArthurMaker likes this.
  19. Offline

    ArthurMaker


    There is no need for this at all, you can just use "MakerSQL db = new MakerSQL(args);". I did the Database.class for other people making their versions of my MakerSQL(there is no need for this, but whatever).


    There is an "example" inside MillenaryAPI.class.
    Code:java
    1. String ip = "192.168.0.1"; // Coloque aqui o IP do servidor MySQL // Insert here the IP that hosts a MySQL server //
    2. String port = "3306"; // Padrão: 3306 // Default: 3306 //
    3. String database = "random_database"; // Coloque aqui o nome do database que queira conectar-se // Insert the name of the database that you want to connect to //
    4. String user_name = "random_user"; // Coloque o nome do usuário do login desejado // Insert here the user that you want access the MySQL database //
    5. String user_password = "0123456789"; // Coloque a senha do usuário escolhido (precisa ser a senha do usuário que você colocou em "user_name"!) //
    6. // Insert the password of the user, that you chose before to use in "user_name" //
    7. mcdatabase = new MakerSQL(this, ip, port, user_name, user_password, database);


    You also can take a look at SQLTable.class! There is some methods that you can "learn" more about SQL (or just how to make querys and updates).

    I'll find time to write more about the API and how the SQL stuff works, so sorry, for now.
    Thank you! :)
     
    KingFaris11 likes this.
  20. Cool thanks, I'm a big noob at MySQL as Goblom would know. I rely on APIs to use MySQL heavily, which may be slightly bad, but I don't see a sudden change in the way MySQL is written.
     
  21. Offline

    ArthurMaker

    There is no big difference in the codes, just a few different features. Using my API to manage your MySQL will be easy, don't worry. I'll write a balance system with it just to be an example here. ;)
     
    KingFaris11 likes this.
  22. I finally fixed the EnderDragon bug.
    You have to listen to PacketPlayInPositionLook and modify the yaw value if the player is disguised as an EnderDragon.
    Here's how i've done it.
    Code:Java
    1.  
    2. public class AsyncIncommingPacketListener implements Listener {
    3.  
    4. @EventHandler
    5. public void onIncommingPacket(AsyncIncomingPacketEvent event) { // listen to the packet. This is a selfwritten event, so you can't copy & paste the code. Use PacketProtocol or something like that instead
    6. if (DisguiseManager.getDisguiseType(event.getPlayer()) == EntityType.ENDER_DRAGON) { // Check if the player is disguised as an enderdragon. I saved the player object in a WeakHashMap to ckeck it. You can do it the same way.
    7. if (event.getPacket() instanceof PacketPlayInPositionLook) { // check for the right packet
    8. PacketPlayInPositionLook packet = (PacketPlayInPositionLook) event.getPacket(); // cast the packet
    9. float yaw = ReflectionUtil.getField(packet, "yaw"); // get the yaw with reflection. You can write your own class for that or just google for one.
    10. ReflectionUtil.setPrivateField(packet, "yaw", yaw - 180F); // substract 180 form the yaw
    11. }
    12. }
    13. }
    14. }
    15.  


    Hope this helps someone.
    Maybe someone can rewrite the code so that it works with PacketProtocol.

    PS:
    Sorry for spelling misstakes. I'm German so English isn't my native language. :)
     
    ArthurMaker likes this.
  23. Offline

    ArthurMaker


    Thank you! I'll implement that :D
     
  24. Offline

    Onlineids

  25. Seems like that there are some bugs sometimes e.g. if the player doesn't move for a few seconds.
    I'll try to find the packet which causes this bug and
    post the fixed code as soon as possible.
     
  26. Offline

    ArthurMaker

    BtoBastian

    I noticed that it doesn't work well. I did it with PacketFactory, but I receive errors on console or the enderdragon starts to have a seizure lol

    Onlineids I'm trying to ;)
     
  27. ArthurMaker
    It works most oft the time but it seems like there is an other packet wich also updates the yaw value. I'll have to find it and modify it, too.
    I also noticed some gereral bugs of the disguise-method.
    If you change the world, relog or just be out of range you will see the original entity/player again (if you are in range again). So you also have to listen to some spawn packets and disguise the player/entity again.
    I've allready fixed most oft these bugs, but some are still there.
    I'll post my code when I fixed them all.
     
  28. Offline

    ArthurMaker

    BtoBastian I'm working on a solution for the EnderDragon's YAW problem. I think it is working, just let me test it out ;)
     
  29. Offline

    ArthurMaker


    I'll convert most things to PacketFactory today ;)
     
Thread Status:
Not open for further replies.

Share This Page