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

Flutter codebase sharing

# Clone For master branch come with example, you can clone and run `flutter doctor && flutter run` ``` git clone --single-branch --branch master https://github.com/Oskang09/Flutter-CB2019.git ``` For codebase branch just empty codebase, but setup done you can just start your development. ``` git clone --single-branch --branch codebase https://github.com/Oskang09/Flutter-CB2019.git ``` # Plugins * Dart as "Programming Language" * Flutter as "SDK" * Redux as "State Management" * Fluro as "Navigator Router" # pubspec.yaml ```yaml name: flutter_codebase description: A new Flutter project. version: 1.0.0+1 environment: sdk: ">=2.0.0-dev.68.0 (); Router router = Router(); routers.forEach( (route) { router.define( route.routePath, handler: Handler( handlerFunc: (context, params) => route.widget(params) ), transitionType: route.transitionType ...

Async / Await vs Promises

## Node.JS In node.js, asynchronous operation able to done by two ways. They are async/await codeblock or promises. What different between them? ### Promises In promises, some of them call it `callback hell` because of the syntax keep repeating callback like and until the end of the async operation. Here come with an example. ```js samplePromise: () => { var promise = new Promise((resolve, reject) => { try { // async codeblock resolve(result); } catch (e) { reject(e); } }); promise.then( (result) => { // result is returning and async operation run complete. }, (rejected) => { // rejected something wrong when running async operation } ).catch( (error) => { // unhandled error occurs when running async opeartion } ); } ``` With this example, you able see that promise code block is quite long when running an async operation, try to think what if more complex async operation required to run, like you need to get data fr...

Global Game Jam @ 2019 January 25 - 27 with Friends

A 3 day 2 night game development event, Global game jam and held at KDU Glenmarie. With a team of 3 people, we haven't done our game until the end but we learned much on the development. Such as modeling, coding, designing, editing using software like photoshop, magicavoxel, unity. Due to inexperienced we doesn't allocate work properly and lastly only done modeling & some mechanic part like health, damage, team check. But still many mechanic haven't done like taming, spawning and more. Sadly doesn't meet our expectation but really enjoy when developing in this event, KDU's student also very friendly to we. Thanks for the all participate for sharing in this event. Event & Game Information This global game jam event title is about "What is home means to you". So we have come with idea bring characters ( player ) back to home, or with defensive feature also dialog chat. Lastly we decide with Realtime-Strategy Defensive Game ( RTS Defensive ) abo...