What should i make it do??

Discussion in 'Spigot Plugin Development' started by MrChickenSteve, Jul 13, 2018.

  1. So. i've got a command in my plugin that i'm making called /color wich just changes the 'server color' and stores it in the config.
    but what should i make it do.
    like if color == yellow then (do what?)
     
  2. OHHHH! IDEA. is it possible to make it change the color of the sky?
     
  3. I think it is using a texture pack. Almost certain
     
  4. Praya

    Benefactor

    you can change the color of the sky using Flag BossBar
     
  5. Code (Java):
    if (colour == yellow && sender instanceof Player)
            ((Player)sender).setHealth(0);
     
    • Funny Funny x 1
  6. That's actually true, not sure if it changes the color for good but it's a cool thing, seems a bit nice.
     
  7. Really? I cant seen to find a way to change colour in the java docs. Only darken/fog.
     
  8. MiniDigger

    Supporter

  9. Praya

    Benefactor

    yeah that what I mean. not very changed but the sky color changed a bit lol
     
  10. I don't think he did. He literally says "you can change the color of the sky using Flag BossBar"

    Very confusing :( I already knew about setting the boss bars colour so i'm kinda disappointed. I wanted blood red skies :)
     
    #10 AgainstTheNight, Jul 13, 2018
    Last edited by a moderator: Jul 13, 2018
  11. You could do something with dimension packets, but they are really advanced.
     
  12. Benz56

    Junior Mod Supporter

    How about something simple like changing all chat messages to the color.
     
  13. I wouldn't say dealing with packets is really advance. Its actually pretty simple.
     
  14. Try to us edimensional packets and you'll understand, just try
     
  15. Using PacketPlayOutRespawn?

    It not that difficult. Here you go:
    Code (Java):
    class ReflectionHandler
    {
        private static final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];

        private static Class<?> packetPlayOutGameStateChangeClass = getNMSClass("PacketPlayOutGameStateChange");
        private static Class<?> playerConnectionClass = getNMSClass("PlayerConnection");
        private static Class<?> packetClass = getNMSClass("Packet");

        //A float of 3 gives you blood red skies
        static boolean changeGameState(Player player, float number)
        {
            try
            {
                Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player);
                playerConnectionClass.getMethod("sendPacket", packetClass).invoke(entityPlayer.getClass().getField("playerConnection").get(entityPlayer), packetPlayOutGameStateChangeClass.getConstructor(int.class, float.class).newInstance(7, number));
            }
            catch (Exception e)
            {
                e.printStackTrace();
                return false;
            }

            return true;
        }

        private static Class<?> getNMSClass(String name)
        {
            try
            {
                return Class.forName("net.minecraft.server." + version + "." + name);
            }
            catch (ClassNotFoundException e)
            {
                e.printStackTrace();
                return null;
            }
        }
    }
     
    #15 AgainstTheNight, Jul 13, 2018
    Last edited by a moderator: Jul 13, 2018
  16. MiniDigger

    Supporter

    Now imagine you used a proper API like protocol lib instead of this inefficient reflection mess
     
    • Optimistic Optimistic x 1
  17. Meh. I only write decent code when I get paid for it. :)
     
  18. MiniDigger

    Supporter

    I just don't like wasting time using reflection when protocol lib does provide a native java API for every packet, lol. I would be way too lazy to write more code when I can use protocol lib and write less code ;)
     
  19. I've heard of it, but I've never bothered to use it. I tend to avoid making stuff with java if i'm honest. So it feels a bit pointless looking into it. :)
     
  20. I can agree with that, I think it's more of a hassle tho to use API.
     
    • Like Like x 1

Share This Page