mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-19 13:55:00 +00:00
830daab8f4
Reflection issue when initializing the daemon; trying to call a constructor with one argument using two arguments. Removed an unused constructor.
75 lines
1.9 KiB
Java
75 lines
1.9 KiB
Java
package me.totalfreedom.totalfreedommod.httpd;
|
|
|
|
import java.lang.reflect.Constructor;
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
import me.totalfreedom.totalfreedommod.httpd.module.HTTPDModule;
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
import org.bukkit.Bukkit;
|
|
|
|
public abstract class ModuleExecutable
|
|
{
|
|
private final boolean async;
|
|
|
|
public ModuleExecutable(boolean async)
|
|
{
|
|
this.async = async;
|
|
}
|
|
|
|
public static ModuleExecutable forClass(Class<? extends HTTPDModule> clazz, boolean async)
|
|
{
|
|
final Constructor<? extends HTTPDModule> cons;
|
|
try
|
|
{
|
|
cons = clazz.getConstructor(NanoHTTPD.HTTPSession.class);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new IllegalArgumentException("Improperly defined module!");
|
|
}
|
|
|
|
return new ModuleExecutable(async)
|
|
{
|
|
@Override
|
|
public NanoHTTPD.Response getResponse(NanoHTTPD.HTTPSession session)
|
|
{
|
|
try
|
|
{
|
|
return cons.newInstance(session).getResponse();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
return null;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
public NanoHTTPD.Response execute(final NanoHTTPD.HTTPSession session)
|
|
{
|
|
try
|
|
{
|
|
if (async)
|
|
{
|
|
return getResponse(session);
|
|
}
|
|
|
|
// Sync to server thread
|
|
return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.getPlugin(), () -> getResponse(session)).get();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public abstract NanoHTTPD.Response getResponse(NanoHTTPD.HTTPSession session);
|
|
|
|
public boolean isAsync()
|
|
{
|
|
return async;
|
|
}
|
|
}
|