Skip to main content

Coming back to MinecraftAPI



A long time for stop developing minecraft plugins due to busy about university and side works. Coming back from a long learning journey, i decide to recode my personal minecraft api for upcoming new server. Found that the code now i can build it with more structural design pattern. Such as MinecraftAPI interface class for runtime reloadable content.

package me.oska.core.abs;

public interface MinecraftAPI
{
    void register();
    void unregister();
    void intialise();
    void teardown();
}

Also i have updated my reader utility code for reading jar class with functional interface make it more flexible.

package me.oska.core.util;

import me.oska.core.OskaCore;
import me.oska.core.lambda.VoidAction;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class ReaderUtil
{
    public static void readJAR(File folder, VoidAction<Class<?>> action)
    {
        for (File file : folder.listFiles())
        {
            if (file.isDirectory())
            {
                readJAR(file, action);
            }
            else if (file.isFile())
            {
                if (FilenameUtils.getExtension(file.getName()).equalsIgnoreCase("jar"))
                {
                    try
                    {
                        JarFile jarfile = new JarFile(file);
                        Enumeration<JarEntry> entry = jarfile.entries();
                        URL[] urls = { new URL("jar:file:" + file.getPath() + "!/") };
                        URLClassLoader cl = URLClassLoader.newInstance(urls, OskaCore.ins.getClass().getClassLoader());
                        while (entry.hasMoreElements())
                        {
                            JarEntry je = entry.nextElement();
                            if (je.isDirectory() || !je.getName().endsWith(".class"))
                            {
                                continue;
                            }
                            String classname = je.getName().substring(0, je.getName().length() - 6);
                            classname = classname.replace('/', '.');
                            Class clazz = Class.forName(classname, true, cl);

                            action.run(clazz);
                        }
                        cl.close();
                        jarfile.close();
                    }
                    catch (Exception ex)
                    {
                        OskaCore.ins.getLogger().severe("Fail when loading from '" + file.getName() + "'");
                        ex.printStackTrace();
                    }
                }
            }
        }
    }
}

Popular posts from this blog

Preparing some plugins for upcoming server

Since i still having a free server from mine friends who in Taiwan keep supporting me for server hosting. For long time busy, and he hope i would still operate and having a survival server so i coming to build up a survival server that not like before only enhance survival gameplay instead of new gameplay and make player doesn't even know how to play. Here come with some idea before i preparing: Custom Building Structure ( Make player easier for some basic works ) Custom PvP & PvE Mechanic ( Make item flexible with skill system and update-able, also work with entity ) Socialize Gamplay ( Guilds & Friends & Party & Mail System ) Daily Gameplay ( Questing, Events )  Any suggestion would be appreciated ( welcome to inbox me :] ) Some images about mine developments in these 2 days. Mine Structure API Skill API work with Items system & Status system And here is the video about the Custom Building Structure Part. As past exp...

Object & Container Object

Object / Class What is Object? Object can be people, can be animal, can be anything. Object only store his own data, attributes and property like house has price, size and animal has age and gender.  Object also store his own function or method like animal can eat(); and people can walk();. Try imagine an object is a people, what should it have and what should it don't have? Let's take this example. public class People { private: String name; int age; int hungry; public: void grow() { this->age += 1; } void eat() { hungry = false; } } People can eat, people will grow up so this is true but you try imagine a people can fly(); ? What other programmer see when want to use ur code? "WTF, WTF is this? Oh my godness." so just store whatever the object need, have is enough. When some attribute is too much and enable to split to another object,...