Filled SleepBuffs, Add a reason for sleeping

Discussion in 'Plugin Requests' started by Dark_Serpent, Aug 2, 2016.

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

    I Al Istannen

    @frej4189
    Wow. Radical. I like it xD

    Yea, sometimes starting from scratch is a lot nicer ;)
    Good luck! And feel free to take anything worth taking out of my plugin.
    The code is packaged in the jar file, just open it with 7-zip, Winrar or something.
     
  2. Offline

    frej4189

    @I Al Istannen
    I just decompiled it with JD-Gui, as I feel it's a lot easier to read out, but that's just a personal preference.

    Thanks for the permissions to use your code! Not sure if I'm gonna do so or not though.

    I hope the plugin will turn out as @Dark_Serpent wanted!
     
  3. Offline

    I Al Istannen

    @frej4189
    No problem ;)

    For decompiling:
    I can also recommend Procyon (The Luyten Gui is nice) or Fernflower (which IntelliJ uses afaik)
    I found that they often create nicer code than JD-Gui.

    Though there is the ByteCode viewer, which has all of the, built in and you can see the result of different decompilers at the same time, next to each other.

    Me too :p
    Again, good luck!
     
  4. Offline

    frej4189

    @I Al Istannen
    I'm using java 1.6, and thus much of your code is unusable.
    I'll try to solve the problems and make the code 1.6 compatible, I won't give up now!

    I'll probably be making my own java decompiler at some time to make sure the styling and formatting is exactly as I want, I'll probably be doing that when this plugin is done actually, so I'm not planning on installing others, jd gui was the first one that popped up when I searched, and I was too lazy to look any further, and that's probably the main reason why I am using it!
     
    Last edited: Aug 17, 2016
  5. Offline

    I Al Istannen

    @frej4189
    1. Why the hell do you use Java 6. Look at the Java version diagram here. You won't find a server running Java 6 with a sane owner.
    2. Java 8 is great. Like really great xD
    To your own decompiler:
    It is a whole lot of work to make that, doubt you will finish it :/ But who knows ;) As long as you enjoy it (or make money :p) all is well :)
     
  6. Offline

    frej4189

    @I Al Istannen
    I use java 6 because:

     
  7. Offline

    I Al Istannen

    @frej4189
    Have you looked at the link? The link is the up to date version of the measures from the biggest minecraft statistic network out there. 77% of the servers use java 8, the rest java 7.

    Throw the Java 6 JDK as far away as possible, and tell the non-existant server owners with Java 6 to crawl out of their cave xD
     
  8. Offline

    frej4189

    @I Al Istannen
    The problem is just that last time I used java 8, it couldn't load on barely any server.
    Will try now, and hopefully it will work.
     
  9. Offline

    I Al Istannen

    @frej4189
    If you really want to be save, use java 7. It has the Diamond operator and a few other nice things (new File api for example), but in my opinion Java 8 is worth it ;)
     
  10. Offline

    frej4189

    @I Al Istannen
    Will try :D
    I don't really care about the Diamond Operator though, if that was the only reason to upgrade, I wouldn't

    @I Al Istannen
    Optional does not seem to have the empty(); function declared, will I need java 8 for this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    I Al Istannen likes this.
  11. @frej4189
    Does the Optional class even exist in anything else than Java 8? If I'm not mistaken it was added in Java 8.
     
  12. Offline

    I Al Istannen

    @AlvinB
    Guava. Also has an optional class, though the structure and methods are different.


    @frej4189
    Yea, Java 8 :/
     
  13. Offline

    frej4189

  14. Offline

    I Al Istannen

  15. Offline

    frej4189

    @I Al Istannen
    Sounds great, and by the way, Class[] needs generic type arguments, should I just do SuppressWarnings("rawtypes") or?
     
  16. Offline

    I Al Istannen

    @frej4189
    Which line? Which file? In the source packaged within might be the real code used. I don't rember having rawtypes.
     
  17. Offline

    frej4189

    @I Al Istannen
    ReflectionUtil.java, the Class[] paramater for invokeMethod
     
  18. Offline

    I Al Istannen

    @frej4189
    Not quite sure what you mean. No errors for me. Maybe "Class<?>" will help? I would need to see the whole line.
     
  19. Offline

    frej4189

    @I Al Istannen
    The parameter called parameterClasses takes a Class array, this is the line:
    Code:
    public static Object invokeMethod(Object handle, String methodName, Class[] parameterClasses, Object... args)
     
  20. Offline

    I Al Istannen

    @frej4189
    That gives me no error. Does this help? If not, just suppress the warning. It is because it is a Class and no particular one
    Code:java
    1. public static Object invokeMethod(Object handle, String methodName, Class<?>[] parameterClasses, Object... args)
     
  21. Offline

    frej4189

    It's not an error, just a warning, so it's not that big of a deal, I'm pretty sure your solution will work, not sure though.
     
  22. Offline

    frej4189

    @I Al Istannen
    Is there any way of creating the PacketPlayOutBed using the functions you have or will I need to create a new function for that?
     
  23. Offline

    I Al Istannen

    @frej4189
    I don't know what version of the ReflectionUtil is in there, but you can use these methods:
    Code:
        private static final String SERVER_VERSION;
    
        static {
            String name = Bukkit.getServer().getClass().getName();
            name = name.substring(name.indexOf("craftbukkit.") + "craftbukkit.".length());
            name = name.substring(0, name.indexOf("."));
    
            SERVER_VERSION = name;
        }
    
        /**
         * Returns the NMS class.
         *
         * @param name The name of the class
         *
         * @return The NMS class or null if an error occurred
         */
        public static Class<?> getNMSClass(String name) {
            try {
                return Class.forName("net.minecraft.server." + SERVER_VERSION + "." + name);
            } catch (ClassNotFoundException e) {
                return null;
            }
        }
    
        /**
         * Returns the constructor
         *
         * @param clazz  The class
         * @param params The Constructor parameters
         *
         * @return The Constructor or an empty Optional if there is none with these parameters
         */
        public static Optional<Constructor<?>> getConstructor(Class<?> clazz, Class<?>... params) {
            try {
                return Optional.of(clazz.getConstructor(params));
            } catch (NoSuchMethodException e) {
                return Optional.empty();
            }
        }
    
        /**
         * Instantiates the class. Will print the errors it gets
         *
         * @param constructor The constructor
         * @param arguments   The initial arguments
         *
         * @return The resulting object, or null if an error occurred.
         */
        public static Object instantiate(Constructor<?> constructor, Object... arguments) {
            try {
                return constructor.newInstance(arguments);
            } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
                MystLinkingBooks.getInstance().getLogger()
                        .log(Level.WARNING, "Can't instantiate class " + constructor.getDeclaringClass(), e);
            }
            return null;
        }
    Get the class with getNMSClass("PacketPlayOutBed")
    Then get the Constructor using getConstructor and then use the instantiate method to create it.
     
  24. Offline

    frej4189

    @I Al Istannen
    Code:
    .log(Level.WARNING, "Can't instantiate class " + constructor.getDeclaringClass(), e);
    
    Level.WARNING is of type java.util.logging.Level right?

    And also, eclipse tells me that the return type of getConstructor should be changed to Optional<?>, but then the instantiate method doesn't work with the constructor of course, why could this be?
     
    Last edited: Aug 21, 2016
  25. Offline

    I Al Istannen

    @frej4189
    Yes. You can probably even delete that thouhg. It is just that: A Warning.
     
  26. Offline

    frej4189

  27. Offline

    I Al Istannen

  28. Offline

    frej4189

  29. Offline

    I Al Istannen

    @frej4189
    It returns a constructor. In this case wrapped in an optional.
     
  30. Offline

    frej4189

    @I Al Istannen
    I know, but eclipse won't let me do that, it just tells me that it can't convert from
    Code:
    Optional<Constructor>capture#3-of?>>
    to
    Code:
    Optional<Constructor<?>>
     
Thread Status:
Not open for further replies.

Share This Page