Seperate SubServers.Host from the GalaxiEngine (Step 2)

This commit is contained in:
ME1312 2018-09-08 18:06:21 -04:00
parent bc5acab41d
commit a687a2d1cb
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
102 changed files with 504 additions and 5511 deletions

277
.gitignore vendored
View File

@ -16,18 +16,6 @@
*.ipr
*.iws
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# IntelliJ
/out/
@ -55,268 +43,5 @@ crashlytics-build.properties
/Javadoc/
/SubServers.Test/
/build.ant
/build.log
.DS_STORE
.alias
# Visual Studio 2015 cache/options directory
.vs/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
**/Properties/launchSettings.json
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs

View File

@ -1,11 +1,23 @@
# SubServers Library Patcher: Combines BungeeCord and SubServers.Bungee/SubServers.Sync into one jar file
# Usage: "bash SubServers.Bungee.Patcher.sh <BungeeCord.jar> <SubServers.jar>"
# SubServers Library Patcher
#
# Can be used to combine the following into one jar file:
# -> BungeeCord and SubServers.Bungee
# -> BungeeCord and SubServers.Sync
# -> GalaxiEngine and SubServers.Host
#
# Usage: "bash SubServers.Bungee.Patcher.sh <Platform.jar> <SubServers.jar>"
#
#!/usr/bin/env bash
if [ -z "$1" ]
then
echo "SubServers Library Patcher: Combines BungeeCord and SubServers.Bungee/SubServers.Sync into one jar file"
echo "Usage: bash $0 <BungeeCord.jar> <SubServers.jar>"
echo "SubServers Library Patcher"
echo ""
echo "Can be used to combine the following into one jar file:"
echo " -> BungeeCord and SubServers.Bungee"
echo " -> BungeeCord and SubServers.Sync"
echo " -> GalaxiEngine and SubServers.Host"
echo ""
echo "Usage: bash $0 <Platform.jar> <SubServers.jar>"
exit 1
fi
if [ ! -f "$1" ]

View File

@ -10,14 +10,6 @@
<packaging>jar</packaging>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>md_5-repo</id>
<url>http://repo.md-5.net/content/repositories/snapshots/</url>
</repository>
<repository>
<id>me1312-repo</id>
<url>https://src.me1312.net/maven</url>

View File

@ -525,7 +525,7 @@ public final class SubCommand extends CommandX {
" Help: /sub help",
" List: /sub list",
" Version: /sub version",
" Reload: /sub reload [all|configs|templates]",
" Reload: /sub reload [all|config|templates]",
" Info: /sub info [proxy|host|group|server] <Name>",
" Start Server: /sub start <SubServer>",
" Stop Server: /sub stop <SubServer>",

View File

@ -60,7 +60,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
public final SubAPI api = new SubAPI(this);
public SubDataServer subdata = null;
public SubServer sudo = null;
public static final Version version = Version.fromString("2.13b");
public static final Version version = Version.fromString("2.13.1a");
public Proxy redis = null;
public boolean canSudo = false;

View File

@ -1,6 +1,6 @@
name: 'SubServers-Client-Bukkit'
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
version: '2.13b'
version: '2.13.1a'
authors: [ME1312]
softdepend: [Vault, TitleManager]
website: 'https://github.com/ME1312/SubServers-2'

View File

@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
/**
* SubServers Client Plugin Class
*/
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.13b", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.13.1a", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
public final class SubPlugin {
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
public YAMLConfig config;

View File

@ -9,24 +9,19 @@
<version>-PLACEHOLDER</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>me1312-repo</id>
<url>https://src.me1312.net/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.jopt-simple</groupId>
<artifactId>jopt-simple</artifactId>
<version>5.0.4</version>
<scope>compile</scope>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>18w36d</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
@ -34,18 +29,6 @@
<version>0.8.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.20</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,3 +1,4 @@
Manifest-Version: 1.0
Main-Class: net.ME1312.SubServers.Host.ExHost
Class-Path: GalaxiEngine.jar
Main-Class: net.ME1312.SubServers.Host.Launch
Implementation-Title: SubServers.Host

View File

@ -1,124 +0,0 @@
package net.ME1312.SubServers.Host.API;
import net.ME1312.SubServers.Host.Library.Exception.IllegalStringValueException;
import net.ME1312.SubServers.Host.SubAPI;
/**
* Command Layout Class
*/
public abstract class Command {
private String desc = null;
private String[] exDesc = new String[0];
private String[] usage = new String[0];
private SubPluginInfo plugin;
/**
* Creates a new Command
*
* @param plugin Plugin
*/
public Command(SubPluginInfo plugin) {
this.plugin = plugin;
}
/**
* Run Command
*
* @param handle Command Name
* @param args Arguments
*/
public abstract void command(String handle, String[] args);
/**
* Gets the Plugin that registering this Command
*
* @return Plugin Info
*/
public SubPluginInfo plugin() {
return this.plugin;
}
/**
* Gets the Description of this Command
*
* @return Command Description
*/
public String description() {
return this.desc;
}
/**
* Set the Description of this Command
*
* @param value Value
* @return The Command
*/
public Command description(String value) {
if (value != null) {
if (value.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use empty string for description");
if (value.contains("\n")) throw new IllegalStringValueException("String contains illegal character(s)");
}
this.desc = value;
return this;
}
/**
* Get the Help Page for this Command
*
* @return Help Page
*/
public String[] help() {
if (exDesc.length == 0 && desc != null) {
return new String[]{desc};
} else {
return exDesc;
}
}
/**
* Set the Help Page for this Command
*
* @param lines Help Page Lines
* @return The Command
*/
public Command help(String... lines) {
for (String line : lines) {
if (line.contains("\n")) throw new IllegalStringValueException("String contains illegal character(s)");
}
this.exDesc = lines;
return this;
}
/**
* Get the Usage of this Command
*
* @return Command Usage
*/
public String[] usage() {
return this.usage;
}
/**
* Set the Usage of this Command
*
* @param args Argument Placeholders
* @return The Command
*/
public Command usage(String... args) {
for (String arg : args) {
if (arg.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use empty string for usage");
if (arg.contains(" ") || arg.contains("\n")) throw new IllegalStringValueException("String contains illegal character(s)");
}
this.usage = args;
return this;
}
/**
* Register this Command
*
* @param handles Aliases
*/
public void register(String... handles) {
SubAPI.getInstance().addCommand(this, handles);
}
}

View File

@ -1,44 +0,0 @@
package net.ME1312.SubServers.Host.API.Event;
import net.ME1312.SubServers.Host.Library.Event.Cancellable;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.ExHost;
/**
* Command Pre-Process Event Class
*/
public class CommandPreProcessEvent extends Event implements Cancellable {
private boolean cancelled = false;
private String command;
/**
* Command Pre-Process Event
*
* @param host SubServers.Host
* @param command Command
*/
public CommandPreProcessEvent(ExHost host, String command) {
if (Util.isNull(host, command)) throw new NullPointerException();
this.command = command;
}
/**
* Gets the full Command String
*
* @return Command
*/
public String getCommand() {
return this.command;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean value) {
this.cancelled = value;
}
}

View File

@ -1,41 +0,0 @@
package net.ME1312.SubServers.Host.API.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.ExHost;
/**
* SubServers.Host Disable Event Class
*/
public class SubDisableEvent extends Event {
private int exit;
/**
* SubServers.Host Disable Event
*
* @param host SubServers.Host
* @param exit Exit Code
*/
public SubDisableEvent(ExHost host, int exit) {
if (Util.isNull(host, exit)) throw new NullPointerException();
this.exit = exit;
}
/**
* Get the Exit Code
*
* @return Exit Code
*/
public int getExitCode() {
return exit;
}
/**
* Set the Exit Code
*
* @param value Value
*/
public void setExitCode(int value) {
this.exit = value;
}
}

View File

@ -1,20 +0,0 @@
package net.ME1312.SubServers.Host.API.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.ExHost;
/**
* SubServers.Host Enable Event Class
*/
public class SubEnableEvent extends Event {
/**
* SubServers.Host Enable Event
*
* @param host SubServers.Host
*/
public SubEnableEvent(ExHost host) {
if (Util.isNull(host)) throw new NullPointerException();
}
}

View File

@ -1,70 +0,0 @@
package net.ME1312.SubServers.Host.API;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* SubPlugin Class Annotation<br>
* Classes defined in <u>package.xml</u> and annotated with this will be loaded
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SubPlugin {
/**
* The Name of this Plugin
*
* @return Plugin Name
*/
String name();
/**
* The Version of this Plugin
*
* @return Plugin Version
*/
String version();
/**
* The Authors of this Plugin
*
* @return Authors List
*/
String[] authors();
/**
* The Description of this Plugin
*
* @return Plugin Description
*/
String description() default "";
/**
* The Authors' Website
*
* @return Authors' Website
*/
String website() default "";
/**
* Load Before Plugins List
*
* @return Load Before List
*/
String[] loadBefore() default {};
/**
* Dependencies List
*
* @return Dependencies List
*/
String[] dependencies() default {};
/**
* Soft Dependencies List
*
* @return Soft Dependencies List
*/
String[] softDependencies() default {};
}

View File

@ -1,235 +0,0 @@
package net.ME1312.SubServers.Host.API;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Config.YAMLValue;
import net.ME1312.SubServers.Host.Library.ExtraDataHandler;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.ExHost;
import java.io.File;
import java.net.URL;
import java.util.*;
/**
* SubPlugin Info Class
*
* @see SubPlugin
*/
public class SubPluginInfo implements ExtraDataHandler {
private ExHost host;
private Object plugin;
private String name;
private Version version;
private List<String> authors;
private String desc;
private URL website;
private List<String> loadBefore;
private List<String> depend;
private List<String> softDepend;
private Logger logger = null;
private boolean enabled = false;
private YAMLSection extra = new YAMLSection();
/**
* Create a SubPlugin Description
*
* @param host SubServers.Host
* @param plugin Plugin
* @param name Plugin Name
* @param version Plugin Version
* @param authors Authors List
* @param description Plugin Description
* @param website Authors' Website
* @param loadBefore Load Before Plugins List
* @param dependencies Dependencies List
* @param softDependencies Soft Dependencies List
*/
public SubPluginInfo(ExHost host, Object plugin, String name, Version version, List<String> authors, String description, URL website, List<String> loadBefore, List<String> dependencies, List<String> softDependencies) {
if (Util.isNull(host, plugin, name, version, authors)) throw new NullPointerException();
name = name.replaceAll("#|<|\\$|\\+|%|>|!|`|&|\\*|'|\\||\\{|\\?|\"|=|}|/|\\\\|\\s|@|\\.|\\n", "_");
if (name.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty name");
if (version.toString().length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty version");
if (authors.size() == 0) throw new ArrayIndexOutOfBoundsException("Cannot use an empty authors list");
if (description != null && description.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty description");
this.host = host;
this.plugin = plugin;
this.name = name;
this.version = version;
this.authors = authors;
this.desc = description;
this.website = website;
this.loadBefore = (loadBefore == null)?Collections.emptyList():loadBefore;
this.depend = (dependencies == null)?Collections.emptyList():dependencies;
this.softDepend = (softDependencies == null)?Collections.emptyList():softDependencies;
}
/**
* Get the Plugin's ClassLoader
*
* @return Plugin ClassLoader
*/
public ClassLoader getLoader() {
return plugin.getClass().getClassLoader();
}
/**
* Get Plugin Object
*
* @return Plugin Object
*/
public Object get() {
return plugin;
}
/**
* Get Plugin's Name
*
* @return Plugin Name
*/
public String getName() {
return this.name;
}
/**
* Get Plugin's Version
*
* @return Plugin Version
*/
public Version getVersion() {
return this.version;
}
/**
* Get Authors List
*
* @return Authors List
*/
public List<String> getAuthors() {
return this.authors;
}
/**
* Get Plugin Description
*
* @return Plugin Description
*/
public String getDescription() {
return this.desc;
}
/**
* Get Authors' Website
*
* @return Authors' Website
*/
public URL getWebsite() {
return this.website;
}
/**
* Gets the Load Before Plugins List
*
* @return Load Before Plugins List
*/
public List<String> getLoadBefore() {
return this.loadBefore;
}
/**
* Gets the Dependencies List
*
* @return Dependencies List
*/
public List<String> getDependancies() {
return this.depend;
}
/**
* Gets the Soft Dependencies List
*
* @return Soft Dependencies List
*/
public List<String> getSoftDependancies() {
return this.softDepend;
}
/**
* Sets the Plugin's Enabled Status
*
* @return Enabled Status
*/
public boolean isEnabled() {
return enabled;
}
/**
* Sets if the Plugin is Enabled
*
* @param value Value
*/
public void setEnabled(boolean value) {
enabled = value;
}
/**
* Replace this Plugin's Logger with a custom one
*
* @param value Value
*/
public void setLogger(Logger value) {
logger = value;
}
/**
* Gets the default Logger for this Plugin
*
* @return Logger
*/
public Logger getLogger() {
if (logger == null) logger = new Logger(name);
return logger;
}
/**
* Gets this Plugin's data folder
*
* @return Data Folder
*/
public File getDataFolder() {
File dir = new File(host.api.getRuntimeDirectory(), "Plugins" + File.separator + name);
if (!dir.exists()) dir.mkdirs();
return dir;
}
@Override
public void addExtra(String handle, Object value) {
if (Util.isNull(handle, value)) throw new NullPointerException();
extra.set(handle, value);
}
@Override
public boolean hasExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
return extra.getKeys().contains(handle);
}
@Override
public YAMLValue getExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
return extra.get(handle);
}
@Override
public YAMLSection getExtra() {
return extra.clone();
}
@Override
public void removeExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
extra.remove(handle);
}
}

View File

@ -1,84 +0,0 @@
package net.ME1312.SubServers.Host.API;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.SubAPI;
import java.util.UUID;
/**
* SubServers Task Builder Class
*/
public abstract class SubTask implements Runnable {
private long repeat = -1L;
private long delay = -1L;
private SubPluginInfo plugin;
/**
* Create a new Task
*
* @param plugin Plugin Creating
*/
public SubTask(SubPluginInfo plugin) {
this.plugin = plugin;
}
/**
* Get the Plugin that created this task
*
* @return Plugin Info
*/
public SubPluginInfo plugin() {
return this.plugin;
}
/**
* Set the Repeat Interval for this task
*
* @param value Value
* @return Task Builder
*/
public SubTask repeat(long value) {
if (Util.isNull(value)) throw new NullPointerException();
this.repeat = value;
return this;
}
/**
* Get the Repeat Interval for this task
*
* @return Repeat Interval
*/
public long repeat() {
return this.repeat;
}
/**
* Delay this task
*
* @param value Value
* @return Task Builder
*/
public SubTask delay(long value) {
if (Util.isNull(value)) throw new NullPointerException();
this.delay = value;
return this;
}
/**
* Get the Delay for this task
*
* @return Task Delay
*/
public long delay() {
return this.delay;
}
/**
* Schedule this task
*
* @return Task ID
*/
public UUID schedule() {
return SubAPI.getInstance().schedule(this);
}
}

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
/**
* Proxy Add Event

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;

View File

@ -1,8 +1,8 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import java.util.UUID;

View File

@ -1,10 +1,10 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Config.YAMLValue;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Config.YAMLValue;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Host.Network.SubDataClient;
/**

View File

@ -1,6 +1,6 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.Galaxi.Library.Event.Event;
/**
* SubData Network Disconnect Event

View File

@ -1,8 +1,8 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Host.ExHost;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
/**
* SubServers.Host Reload Event Class

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
/**
* Proxy Remove Event

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;

View File

@ -1,8 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.API.Event;
package net.ME1312.SubServers.Host.Event;
import net.ME1312.SubServers.Host.Library.Event.Event;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Util;
/**
* Server Shell Exit Event

View File

@ -1,65 +1,54 @@
package net.ME1312.SubServers.Host;
import jline.console.ConsoleReader;
import net.ME1312.SubServers.Host.API.Event.*;
import net.ME1312.SubServers.Host.API.SubPluginInfo;
import net.ME1312.SubServers.Host.API.SubPlugin;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.Galaxi.Library.Version.VersionType;
import net.ME1312.Galaxi.Plugin.Plugin;
import net.ME1312.Galaxi.Plugin.PluginInfo;
import net.ME1312.SubServers.Host.Event.SubReloadEvent;
import net.ME1312.SubServers.Host.Executable.SubCreator;
import net.ME1312.SubServers.Host.Executable.SubServer;
import net.ME1312.SubServers.Host.Library.*;
import net.ME1312.SubServers.Host.Library.Config.YAMLConfig;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Exception.IllegalPluginException;
import net.ME1312.SubServers.Host.Library.Log.FileLogger;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Library.Version.VersionType;
import net.ME1312.SubServers.Host.Network.Cipher;
import net.ME1312.SubServers.Host.Network.SubDataClient;
import org.fusesource.jansi.AnsiConsole;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.jar.Manifest;
/**
* SubServers.Host Main Class
*/
@Plugin(name = "SubServers.Host", version = "2.13.1a", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
public final class ExHost {
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
public HashMap<String, SubCreator.ServerTemplate> templates = new HashMap<String, SubCreator.ServerTemplate>();
public HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
public SubCreator creator;
public final UniversalFile dir = new UniversalFile(new File(System.getProperty("user.dir")));
public Logger log;
public PluginInfo info;
public GalaxiEngine engine;
public YAMLConfig config;
public YAMLSection host = null;
public SubDataClient subdata = null;
public final SubAPI api = new SubAPI(this);
public static final Version version = Version.fromString("2.13b");
private ConsoleReader jline;
private boolean running = false;
private boolean ready = false;
/**
* SubServers.Host Launch
@ -67,7 +56,7 @@ public final class ExHost {
* @param args Args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
static void main(String[] args) throws Exception {
if (System.getProperty("RM.subservers", "true").equalsIgnoreCase("true")) {
joptsimple.OptionParser parser = new joptsimple.OptionParser();
parser.allowsUnrecognizedOptions();
@ -76,18 +65,29 @@ public final class ExHost {
parser.accepts("noconsole");
joptsimple.OptionSet options = parser.parse(args);
if(options.has("version") || options.has("v")) {
boolean build = false;
Version galaxi = Version.fromString(GalaxiEngine.class.getAnnotation(Plugin.class).version());
Version subservers = Version.fromString(ExHost.class.getAnnotation(Plugin.class).version());
Version galaxibuild = null;
Version subserversbuild = null;
try {
Manifest manifest = new Manifest(GalaxiEngine.class.getResourceAsStream("/META-INF/GalaxiEngine.MF"));
if (manifest.getMainAttributes().getValue("Implementation-Version") != null && manifest.getMainAttributes().getValue("Implementation-Version").length() > 0)
galaxibuild = new Version(manifest.getMainAttributes().getValue("Implementation-Version"));
} catch (Exception e) {} try {
Field f = Version.class.getDeclaredField("type");
f.setAccessible(true);
build = f.get(version) != VersionType.SNAPSHOT && ExHost.class.getPackage().getSpecificationTitle() != null;
if (f.get(subservers) != VersionType.SNAPSHOT && ExHost.class.getPackage().getSpecificationTitle() != null)
subserversbuild = new Version(ExHost.class.getPackage().getSpecificationTitle());
f.setAccessible(false);
} catch (Exception e) {}
System.out.println("");
System.out.println(System.getProperty("os.name") + " " + System.getProperty("os.version") + ',');
System.out.println("Java " + System.getProperty("java.version") + ",");
System.out.println("SubServers.Host v" + version.toExtendedString() + ((build)?" (" + ExHost.class.getPackage().getSpecificationTitle() + ')':""));
System.out.println(GalaxiEngine.class.getAnnotation(Plugin.class).name() + " v" + galaxi.toExtendedString() + ((galaxibuild != null)?" (" + galaxibuild + ')':"")
+ ((GalaxiEngine.class.getProtectionDomain().getCodeSource().getLocation().equals(ExHost.class.getProtectionDomain().getCodeSource().getLocation()))?" [Patched]":"") + ',');
System.out.println(ExHost.class.getAnnotation(Plugin.class).name() + " v" + subservers.toExtendedString() + ((subserversbuild != null)?" (" + subserversbuild + ')':""));
System.out.println("");
} else {
new ExHost(options);
@ -100,51 +100,36 @@ public final class ExHost {
}
private ExHost(joptsimple.OptionSet options) {
try {
JarFile jarFile = new JarFile(new File(ExHost.class.getProtectionDomain().getCodeSource().getLocation().toURI()));
Enumeration<JarEntry> entries = jarFile.entries();
boolean isplugin = false;
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
api.knownClasses.add(entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.'));
}
}
} catch (Exception e) {
e.printStackTrace();
}
log = new Logger("SubServers");
try {
jline = new ConsoleReader(System.in, AnsiConsole.out());
Logger.setup(AnsiConsole.out(), AnsiConsole.err(), jline, dir);
log.info.println("Loading SubServers.Host v" + version.toString() + " Libraries");
dir.mkdirs();
new File(dir, "Plugins").mkdir();
if (!(new UniversalFile(dir, "config.yml").exists())) {
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(dir, "config.yml").getPath());
log.info.println("Created ~/config.yml");
} else if ((new Version((new YAMLConfig(new UniversalFile(dir, "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
Files.move(new UniversalFile(dir, "config.yml").toPath(), new UniversalFile(dir, "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(dir, "config.yml").getPath());
try {
info = PluginInfo.getPluginInfo(this);
info.setLogger(log);
engine = GalaxiEngine.init(info);
log.info.println("Loading SubServers.Host v" + info.getVersion().toString() + " Libraries");
if (!(new UniversalFile(engine.getRuntimeDirectory(), "config.yml").exists())) {
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(engine.getRuntimeDirectory(), "config.yml").getPath());
log.info.println("Created ~/config.yml");
} else if ((new Version((new YAMLConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
Files.move(new UniversalFile(engine.getRuntimeDirectory(), "config.yml").toPath(), new UniversalFile(engine.getRuntimeDirectory(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(engine.getRuntimeDirectory(), "config.yml").getPath());
log.info.println("Updated ~/config.yml");
}
config = new YAMLConfig(new UniversalFile(dir, "config.yml"));
config = new YAMLConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"));
if (!(new UniversalFile(dir, "Templates").exists())) {
new UniversalFile(dir, "Templates").mkdir();
if (!(new UniversalFile(engine.getRuntimeDirectory(), "Templates").exists())) {
new UniversalFile(engine.getRuntimeDirectory(), "Templates").mkdir();
log.info.println("Created ~/Templates/");
}
if (new UniversalFile(dir, "Recently Deleted").exists()) {
int f = new UniversalFile(dir, "Recently Deleted").listFiles().length;
for (File file : new UniversalFile(dir, "Recently Deleted").listFiles()) {
if (new UniversalFile(engine.getRuntimeDirectory(), "Recently Deleted").exists()) {
int f = new UniversalFile(engine.getRuntimeDirectory(), "Recently Deleted").listFiles().length;
for (File file : new UniversalFile(engine.getRuntimeDirectory(), "Recently Deleted").listFiles()) {
try {
if (file.isDirectory()) {
if (new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json").exists()) {
FileReader reader = new FileReader(new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json"));
if (new UniversalFile(engine.getRuntimeDirectory(), "Recently Deleted:" + file.getName() + ":info.json").exists()) {
FileReader reader = new FileReader(new UniversalFile(engine.getRuntimeDirectory(), "Recently Deleted:" + file.getName() + ":info.json"));
JSONObject json = new JSONObject(Util.readAll(reader));
reader.close();
if (json.keySet().contains("Timestamp")) {
@ -173,218 +158,11 @@ public final class ExHost {
}
}
if (f <= 0) {
Files.delete(new UniversalFile(dir, "Recently Deleted").toPath());
Files.delete(new UniversalFile(engine.getRuntimeDirectory(), "Recently Deleted").toPath());
}
}
/*
* Find Jars
*/
UniversalFile pldir = new UniversalFile(dir, "Plugins");
LinkedList<File> pljars = new LinkedList<File>();
if (pldir.exists() && pldir.isDirectory()) for (File file : pldir.listFiles()) {
if (file.getName().endsWith(".jar")) pljars.add(file);
}
if (pljars.size() > 0) {
long begin = Calendar.getInstance().getTime().getTime();
log.info.println("Loading SubAPI Plugins...");
/*
* Load Jars & Find Main Classes
* (Unordered)
*/
LinkedHashMap<PluginClassLoader, NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>> classes = new LinkedHashMap<PluginClassLoader, NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>>();
for (File file : pljars) {
try {
JarFile jar = new JarFile(file);
Enumeration<JarEntry> entries = jar.entries();
PluginClassLoader loader = new PluginClassLoader(this.getClass().getClassLoader(), file.toURI().toURL());
List<String> contents = new ArrayList<String>();
loader.setDefaultClass(ClassNotFoundException.class);
boolean isplugin = false;
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
String cname = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
contents.add(cname);
try {
Class<?> clazz = loader.loadClass(cname);
if (clazz.isAnnotationPresent(SubPlugin.class)) {
NamedContainer<LinkedList<String>, LinkedHashMap<String, String>> jarmap = (classes.keySet().contains(loader))?classes.get(loader):new NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>(new LinkedList<String>(), new LinkedHashMap<>());
for (String dependancy : clazz.getAnnotation(SubPlugin.class).dependencies()) jarmap.name().add(dependancy);
for (String dependancy : clazz.getAnnotation(SubPlugin.class).softDependencies()) jarmap.name().add(dependancy);
jarmap.get().put(clazz.getAnnotation(SubPlugin.class).name(), cname);
classes.put(loader, jarmap);
isplugin = true;
}
} catch (Throwable e) {
log.error.println(new IllegalPluginException(e, "Couldn't load class: " + cname));
}
}
}
loader.setDefaultClass(null);
if (!isplugin) {
new PluginClassLoader(this.getClass().getClassLoader(), file.toURI().toURL());
log.info.println("Loaded Library: " + file.getName());
}
api.knownClasses.addAll(contents);
jar.close();
} catch (Throwable e) {
log.error.println(new InvocationTargetException(e, "Problem searching plugin jar: " + file.getName()));
}
}
/*
* Load Main Classes & Plugin Descriptions
* (Ordered by Known Dependencies)
*/
int progress = 1;
HashMap<String, SubPluginInfo> plugins = new LinkedHashMap<String, SubPluginInfo>();
while (classes.size() > 0) {
LinkedHashMap<PluginClassLoader, LinkedList<String>> loaded = new LinkedHashMap<PluginClassLoader, LinkedList<String>>();
for (PluginClassLoader loader : classes.keySet()) {
LinkedList<String> loadedlist = new LinkedList<String>();
for (String name : classes.get(loader).get().keySet()) {
boolean load = true;
for (String depend : classes.get(loader).name()) {
if (!plugins.keySet().contains(depend.toLowerCase())) {
load = progress <= 0;
}
}
if (load) {
String main = classes.get(loader).get().get(name);
try {
Class<?> clazz = loader.loadClass(main);
if (!clazz.isAnnotationPresent(SubPlugin.class))
throw new ClassCastException("Cannot find plugin descriptor");
Object obj = clazz.getConstructor().newInstance();
try {
SubPluginInfo plugin = new SubPluginInfo(this, obj, clazz.getAnnotation(SubPlugin.class).name(), Version.fromString(clazz.getAnnotation(SubPlugin.class).version()),
Arrays.asList(clazz.getAnnotation(SubPlugin.class).authors()), (clazz.getAnnotation(SubPlugin.class).description().length() > 0)?clazz.getAnnotation(SubPlugin.class).description():null,
(clazz.getAnnotation(SubPlugin.class).website().length() > 0)?new URL(clazz.getAnnotation(SubPlugin.class).website()):null, Arrays.asList(clazz.getAnnotation(SubPlugin.class).loadBefore()),
Arrays.asList(clazz.getAnnotation(SubPlugin.class).dependencies()), Arrays.asList(clazz.getAnnotation(SubPlugin.class).softDependencies()));
if (plugins.keySet().contains(plugin.getName().toLowerCase()))
log.warn.println("Duplicate plugin: " + plugin.getName().toLowerCase());
plugin.addExtra("subservers.plugin.loadafter", new ArrayList<String>());
plugins.put(plugin.getName().toLowerCase(), plugin);
} catch (Throwable e) {
log.error.println(new IllegalPluginException(e, "Couldn't load plugin descriptor for main class: " + main));
}
} catch (ClassCastException e) {
log.error.println(new IllegalPluginException(e, "Main class isn't annotated as a SubPlugin: " + main));
} catch (InvocationTargetException e) {
log.error.println(new IllegalPluginException(e.getTargetException(), "Uncaught exception occurred while loading main class: " + main));
} catch (Throwable e) {
log.error.println(new IllegalPluginException(e, "Couldn't load main class: " + main));
}
loadedlist.add(name);
}
}
if (loadedlist.size() > 0) loaded.put(loader, loadedlist);
}
progress = 0;
for (PluginClassLoader loader : loaded.keySet()) {
NamedContainer<LinkedList<String>, LinkedHashMap<String, String>> jarmap = classes.get(loader);
progress++;
for (String main : loaded.get(loader)) jarmap.get().remove(main);
if (jarmap.get().size() > 0) {
classes.put(loader, jarmap);
} else {
classes.remove(loader);
}
}
}
/*
* Load Extra Plugin Settings
*/
for (SubPluginInfo plugin : plugins.values()) {
for (String loadbefore : plugin.getLoadBefore()) {
if (plugins.keySet().contains(loadbefore.toLowerCase())) {
List<String> loadafter = plugins.get(loadbefore.toLowerCase()).getExtra("subservers.plugin.loadafter").asRawStringList();
loadafter.add(plugin.getName().toLowerCase());
plugins.get(loadbefore.toLowerCase()).addExtra("subservers.plugin.loadafter", loadafter);
}
}
}
/*
* Register Plugins
* (Ordered by LoadBefore & Dependencies)
*/
int i = 0;
while (plugins.size() > 0) {
List<String> loaded = new ArrayList<String>();
for (SubPluginInfo plugin : plugins.values()) {
try {
boolean load = true;
for (String depend : plugin.getDependancies()) {
if (plugins.keySet().contains(depend.toLowerCase())) {
load = false;
} else if (!api.plugins.keySet().contains(depend.toLowerCase())) {
throw new IllegalPluginException(new IllegalStateException("Unknown dependency: " + depend), "Cannot meet requirements for plugin: " + plugin.getName() + " v" + plugin.getVersion().toString());
}
}
for (String softdepend : plugin.getSoftDependancies()) {
if (plugins.keySet().contains(softdepend.toLowerCase())) {
load = false;
}
}
for (String loadafter : plugin.getExtra("subservers.plugin.loadafter").asRawStringList()) {
if (plugins.keySet().contains(loadafter.toLowerCase())) {
load = false;
}
}
if (load) try {
plugin.removeExtra("subservers.plugin.loadafter");
plugin.setEnabled(true);
api.addListener(plugin, plugin.get());
api.plugins.put(plugin.getName().toLowerCase(), plugin);
api.plugins.put(plugin.getName().toLowerCase(), plugin);
loaded.add(plugin.getName().toLowerCase());
String a = "";
int ai = 0;
for (String author : plugin.getAuthors()) {
ai++;
if (ai > 1) {
if (plugin.getAuthors().size() > 2) a += ", ";
else if (plugin.getAuthors().size() == 2) a += ' ';
if (ai == plugin.getAuthors().size()) a += "and ";
}
a += author;
}
log.info.println("Loaded " + plugin.getName() + " v" + plugin.getVersion().toString() + " by " + a);
i++;
} catch (Throwable e) {
plugin.setEnabled(false);
throw new InvocationTargetException(e, "Problem loading plugin: " + plugin.getName());
}
} catch (InvocationTargetException e) {
log.error.println(e);
loaded.add(plugin.getName().toLowerCase());
}
}
progress = 0;
for (String name : loaded) {
progress++;
plugins.remove(name);
}
if (progress == 0 && plugins.size() != 0) {
log.error.println(new IllegalStateException("Couldn't load more plugins yet " + plugins.size() + " remain unloaded"));
break;
}
}
/*
* Enable Plugins
*/
api.executeEvent(new SubEnableEvent(this));
log.info.println(i + " Plugin"+((i == 1)?"":"s") + " loaded in " + new DecimalFormat("0.000").format((Calendar.getInstance().getTime().getTime() - begin) / 1000D) + "s");
}
engine.getPluginManager().loadPlugins(new UniversalFile(engine.getRuntimeDirectory(), "Plugins"));
running = true;
Cipher cipher = null;
@ -403,7 +181,7 @@ public final class ExHost {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (running) {
log.warn.println("Received request from system to shutdown");
forcequit(0);
engine.stop();
}
}));
creator = new SubCreator(this);
@ -411,34 +189,29 @@ public final class ExHost {
loadDefaults();
new Metrics(this);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
try {
YAMLSection tags = new YAMLSection(new JSONObject("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}'));
List<Version> versions = new LinkedList<Version>();
engine.setUpdateChecker(() -> {
try {
YAMLSection tags = new YAMLSection(new JSONObject("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}'));
List<Version> versions = new LinkedList<Version>();
Version updversion = version;
int updcount = 0;
for (YAMLSection tag : tags.getSectionList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
Collections.sort(versions);
for (Version version : versions) {
if (version.compareTo(updversion) > 0) {
updversion = version;
updcount++;
}
Version updversion = info.getVersion();
int updcount = 0;
for (YAMLSection tag : tags.getSectionList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
Collections.sort(versions);
for (Version version : versions) {
if (version.compareTo(updversion) > 0) {
updversion = version;
updcount++;
}
if (updcount > 0) log.info.println("SubServers.Host v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
} catch (Exception e) {}
}
}, 0, TimeUnit.DAYS.toMillis(2));
}
if (updcount > 0) log.info.println("SubServers.Host v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
} catch (Exception e) {}
});
if (!options.has("noconsole")) {
loop();
}
engine.start(this::stop);
} catch (Exception e) {
log.error.println(e);
forcequit(1);
stop();
}
}
@ -462,137 +235,16 @@ public final class ExHost {
InetAddress.getByName(config.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
SubAPI.getInstance().executeEvent(new SubReloadEvent(this));
}
private void loop() throws Exception {
String line;
ready = true;
while (ready && (line = jline.readLine(">")) != null) {
if (!ready || line.replaceAll("\\s", "").length() == 0) continue;
final CommandPreProcessEvent event;
api.executeEvent(event = new CommandPreProcessEvent(this, line));
if (!event.isCancelled()) {
LinkedList<String> args = new LinkedList<String>();
Matcher parser = Pattern.compile("(?:^|\\s+)(\"(?:\\\\\"|[^\"])+\"?|(?:\\\\\\s|[^\\s])+)").matcher(line);
while (parser.find()) {
String arg = parser.group(1);
if (arg.startsWith("\"")) arg = arg.substring(1, arg.length() - ((arg.endsWith("\""))?1:0));
arg = unescapeCommand(arg);
args.add(arg);
}
String cmd = args.get(0);
args.remove(0);
if (cmd.startsWith("/")) cmd = cmd.substring(1);
if (args.size() >= 1 &&
((cmd.equalsIgnoreCase("sub") && !api.commands.keySet().contains("sub")) ||
(cmd.equalsIgnoreCase("subserver") && !api.commands.keySet().contains("subserver")) ||
(cmd.equalsIgnoreCase("subservers") && !api.commands.keySet().contains("subservers")))) {
cmd = args.get(0);
args.remove(0);
}
if (api.commands.keySet().contains(cmd.toLowerCase())) {
try {
api.commands.get(cmd.toLowerCase()).command(cmd, args.toArray(new String[args.size()]));
} catch (Exception e) {
log.error.println(new InvocationTargetException(e, "Uncaught exception while running command"));
}
} else {
String s = cmd.replace("\\", "\\\\").replace("\n", "\\n").replace("\"", "\\\"").replace(" ", "\\ ");
for (String arg : args) {
s += ' ' + arg.replace("\\", "\\\\").replace("\n", "\\n").replace("\"", "\\\"").replace(" ", "\\ ");
}
log.message.println("Unknown Command - " + s);
}
jline.getOutput().write("\b \b");
}
}
}
/**
* Parse escapes in a command
*
* @param str String
* @return Unescaped String
*/
private String unescapeCommand(String str) {
StringBuilder sb = new StringBuilder(str.length());
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch == '\\') {
char nextChar = (i == str.length() - 1) ? '\\' : str
.charAt(i + 1);
// Octal escape?
if (nextChar >= '0' && nextChar <= '7') {
String code = "" + nextChar;
i++;
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
&& str.charAt(i + 1) <= '7') {
code += str.charAt(i + 1);
i++;
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
&& str.charAt(i + 1) <= '7') {
code += str.charAt(i + 1);
i++;
}
}
sb.append((char) Integer.parseInt(code, 8));
continue;
}
switch (nextChar) {
case '\\':
ch = '\\';
break;
case 'n':
ch = '\n';
break;
case '\"':
ch = '\"';
break;
case ' ':
ch = ' ';
break;
// Hex Unicode: u????
case 'u':
if (i >= str.length() - 5) {
ch = 'u';
break;
}
int code = Integer.parseInt(
"" + str.charAt(i + 2) + str.charAt(i + 3)
+ str.charAt(i + 4) + str.charAt(i + 5), 16);
sb.append(Character.toChars(code));
i += 5;
continue;
}
i++;
}
sb.append(ch);
}
return sb.toString();
engine.getPluginManager().executeEvent(new SubReloadEvent(this));
}
private void loadDefaults() {
SubCommand.load(this);
}
/**
* Stop SubServers.Host
*
* @param exit Exit Code
*/
public void stop(int exit) {
if (ready) {
private void stop() {
if (running) {
log.info.println("Shutting down...");
SubDisableEvent event = new SubDisableEvent(this, exit);
api.executeEvent(event);
forcequit(event.getExitCode());
}
} private void forcequit(int exit) {
if (ready) {
ready = false;
List<String> subservers = new ArrayList<String>();
subservers.addAll(servers.keySet());
@ -624,10 +276,7 @@ public final class ExHost {
}
if (subdata != null) Util.isException(() -> subdata.destroy(0));
if (new File(dir, "Templates").exists()) Util.deleteDirectory(new File(dir, "Templates"));
Util.isException(FileLogger::end);
System.exit(exit);
if (new File(engine.getRuntimeDirectory(), "Templates").exists()) Util.deleteDirectory(new File(engine.getRuntimeDirectory(), "Templates"));
}
}
}

View File

@ -1,6 +1,6 @@
package net.ME1312.SubServers.Host.Executable;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Util;
import java.io.File;
import java.io.Serializable;

View File

@ -1,14 +1,15 @@
package net.ME1312.SubServers.Host.Executable;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Container;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Container;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Library.Exception.InvalidServerException;
import net.ME1312.SubServers.Host.Library.Exception.InvalidTemplateException;
import net.ME1312.SubServers.Host.Library.Exception.SubCreatorException;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.Library.UniversalFile;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.API.SubCreator.ServerType;
import net.ME1312.SubServers.Host.Network.Packet.PacketExCreateServer;
import net.ME1312.SubServers.Host.Network.Packet.PacketOutExLogMessage;
@ -266,7 +267,7 @@ public class SubCreator {
String gitBash = host.host.getRawString("Git-Bash") + ((host.host.getRawString("Git-Bash").endsWith(File.separator)) ? "" : File.separator) + "bin" + File.separatorChar + "bash.exe";
File cache;
if (template.getBuildOptions().getBoolean("Use-Cache", true)) {
cache = new UniversalFile(host.dir, "Cache:Templates:" + template.getName());
cache = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Cache:Templates:" + template.getName());
cache.mkdirs();
} else {
cache = null;
@ -307,9 +308,9 @@ public class SubCreator {
if (cache != null) {
if (cache.isDirectory() && cache.listFiles().length == 0) cache.delete();
cache = new UniversalFile(host.dir, "Cache:Templates");
cache = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Cache:Templates");
if (cache.isDirectory() && cache.listFiles().length == 0) cache.delete();
cache = new UniversalFile(host.dir, "Cache");
cache = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Cache");
if (cache.isDirectory() && cache.listFiles().length == 0) cache.delete();
}
}

View File

@ -1,8 +1,8 @@
package net.ME1312.SubServers.Host.Executable;
import net.ME1312.SubServers.Host.Library.Container;
import net.ME1312.SubServers.Host.Library.Log.LogStream;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Container;
import net.ME1312.Galaxi.Library.Log.LogStream;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.TextColor;
import net.ME1312.SubServers.Host.Network.Packet.PacketOutExLogMessage;
import net.ME1312.SubServers.Host.SubAPI;

View File

@ -1,11 +1,10 @@
package net.ME1312.SubServers.Host.Executable;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Container;
import net.ME1312.Galaxi.Library.Container;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Library.Exception.InvalidServerException;
import net.ME1312.SubServers.Host.Library.UniversalFile;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.Packet.PacketExUpdateServer;
import net.ME1312.SubServers.Host.ExHost;

View File

@ -0,0 +1,31 @@
package net.ME1312.SubServers.Host;
/**
* SubServers/GalaxiEngine Launch Class
*/
public final class Launch {
/**
* Launch SubServers/GalaxiEngine
*
* @param args Launch Arguments
* @throws Exception
*/
public static void main(String[] args) throws Exception {
System.setProperty("apple.laf.useScreenMenuBar", "true");
boolean exists = false;
try {
exists = Class.forName("net.ME1312.Galaxi.Engine.GalaxiEngine") != null;
} catch (Throwable e) {}
if (!exists) {
System.out.println(">> GalaxiEngine.jar Doesn't Exist");
System.out.println(">> ");
System.out.println(">> Please download a build from:");
System.out.println(">> https://github.com/ME1312/GalaxiEngine/releases");
System.exit(1);
} else {
net.ME1312.SubServers.Host.ExHost.main(args);
}
}
}

View File

@ -1,13 +0,0 @@
package net.ME1312.SubServers.Host.Library;
/**
* Callback Class
*/
public interface Callback<T> {
/**
* Run the Callback
*
* @param obj Object
*/
void run(T obj);
}

View File

@ -1,111 +0,0 @@
package net.ME1312.SubServers.Host.Library.Config;
import net.ME1312.SubServers.Host.Library.Util;
import org.json.JSONObject;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.error.YAMLException;
import java.io.*;
import java.util.LinkedHashMap;
/**
* YAML Config Class
*/
@SuppressWarnings("unused")
public class YAMLConfig {
private File file;
private Yaml yaml;
private YAMLSection config;
/**
* Creates/Loads a YAML Formatted Config
*
* @param file
* @throws IOException
* @throws YAMLException
*/
@SuppressWarnings("unchecked")
public YAMLConfig(File file) throws IOException, YAMLException {
if (Util.isNull(file)) throw new NullPointerException();
this.file = file;
this.yaml = new Yaml(getDumperOptions());
if (file.exists()) {
InputStream stream = new FileInputStream(file);
this.config = new YAMLSection((LinkedHashMap<String, ?>) yaml.loadAs(stream, LinkedHashMap.class), null, null, yaml);
stream.close();
} else {
this.config = new YAMLSection(null, null, null, yaml);
}
}
/**
* Get Config Contents
*
* @return Config Contents
*/
public YAMLSection get() {
return config;
}
/**
* Set Config Contents
*
* @param value Value
*/
public void set(YAMLSection value) {
if (Util.isNull(value)) throw new NullPointerException();
config = value;
}
/**
* Reload Config Contents
*
* @throws IOException
*/
@SuppressWarnings("unchecked")
public void reload() throws IOException {
if (file.exists()) {
InputStream stream = new FileInputStream(file);
this.config = new YAMLSection((LinkedHashMap<String, ?>) yaml.loadAs(stream, LinkedHashMap.class), null, null, yaml);
stream.close();
} else {
this.config = new YAMLSection(null, null, null, yaml);
}
}
/**
* Save Config Contents
*
* @throws IOException
*/
public void save() throws IOException {
if (!file.exists()) file.createNewFile();
FileWriter writer = new FileWriter(file);
yaml.dump(config.map, writer);
writer.close();
}
@Override
public boolean equals(Object object) {
if (object instanceof YAMLConfig) {
return get().equals(((YAMLConfig) object).get());
} else {
return super.equals(object);
}
}
@Override
public String toString() {
return yaml.dump(config.map);
}
protected static DumperOptions getDumperOptions() {
DumperOptions options = new DumperOptions();
options.setAllowUnicode(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setIndent(4);
return options;
}
}

View File

@ -1,375 +0,0 @@
package net.ME1312.SubServers.Host.Library.Config;
import net.ME1312.SubServers.Host.Library.TextColor;
import net.ME1312.SubServers.Host.Library.Util;
import org.yaml.snakeyaml.Yaml;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* YAML Value Class
*/
@SuppressWarnings({"unchecked", "unused"})
public class YAMLValue {
protected Object obj;
protected String label;
protected YAMLSection up;
private Yaml yaml;
protected YAMLValue(Object obj, YAMLSection up, String label, Yaml yaml) {
this.obj = obj;
this.label = label;
this.yaml = yaml;
this.up = up;
}
/**
* Get the YAML Section this Object was defined in
*
* @return YAML Section
*/
public YAMLSection getDefiningSection() {
return up;
}
/**
* Get Object
*
* @return Object
*/
public Object asObject() {
return obj;
}
/**
* Get Object as List
*
* @return List
*/
public List<?> asObjectList() {
return (List<?>) obj;
}
/**
* Get Object as Boolean
*
* @return Boolean
*/
public Boolean asBoolean() {
return (Boolean) obj;
}
/**
* Get Object as List
*
* @return List
*/
public List<Boolean> asBooleanList() {
return (List<Boolean>) obj;
}
/**
* Get Object as YAML Section
*
* @return YAML Section
*/
public YAMLSection asSection() {
if (obj != null) return new YAMLSection((Map<String, ?>) obj, up, label, yaml);
else return null;
}
/**
* Get Object as YAML Section List
*
* @return YAML Section List
*/
public List<YAMLSection> asSectionList() {
if (obj != null) {
List<YAMLSection> values = new ArrayList<YAMLSection>();
for (Map<String, ?> value : (List<? extends Map<String, ?>>) obj) {
values.add(new YAMLSection(value, null, null, yaml));
}
return values;
} else return null;
}
/**
* Get Object as Double
*
* @return Double
*/
public Double asDouble() {
return ((Number) obj).doubleValue();
}
/**
* Get Object as Double List
*
* @return Double List
*/
public List<Double> asDoubleList() {
return (List<Double>) obj;
}
/**
* Get Object as Float
*
* @return Float
*/
public Float asFloat() {
return ((Number) obj).floatValue();
}
/**
* Get Object as Float List
*
* @return Float List
*/
public List<Float> asFloatList() {
return (List<Float>) obj;
}
/**
* Get Object as Integer
*
* @return Integer
*/
public Integer asInt() {
return ((Number) obj).intValue();
}
/**
* Get Object as Integer List
*
* @return Integer List
*/
public List<Integer> asIntList() {
return (List<Integer>) obj;
}
/**
* Get Object as Long
*
* @return Long
*/
public Long asLong() {
return ((Number) obj).longValue();
}
/**
* Get Object as Long List
*
* @return Long List
*/
public List<Long> asLongList() {
return (List<Long>) obj;
}
/**
* Get a Short by Handle
*
* @return Short
*/
public Short asShort() {
return ((Number) obj).shortValue();
}
/**
* Get a Short List by Handle
*
* @return Short List
*/
public List<Short> asShortList() {
return (List<Short>) obj;
}
/**
* Get Object as Unparsed String
*
* @return Unparsed String
*/
public String asRawString() {
if (obj != null) return obj.toString();
else return null;
}
/**
* Get Object as Unparsed String List
*
* @return Unparsed String List
*/
public List<String> asRawStringList() {
if (obj != null) {
List<String> values = new ArrayList<String>();
for (Object value : (List<?>) obj) {
values.add(value.toString());
}
return values;
} else return null;
}
/**
* Get Object as String
*
* @return String
*/
public String asString() {
if (obj != null) return Util.unescapeJavaString(asRawString());
else return null;
}
/**
* Get Object as String List
*
* @return String List
*/
public List<String> asStringList() {
if (obj != null) {
List<String> values = new ArrayList<String>();
for (String value : asRawStringList()) {
values.add(Util.unescapeJavaString(value));
}
return values;
} else return null;
}
/**
* Get Object as Colored String
*
* @param color Color Char to parse
* @return Colored String
*/
public String asColoredString(char color) {
if (Util.isNull(color)) throw new NullPointerException();
if (obj != null) return TextColor.parseColor(color, asString());
else return null;
}
/**
* Get Object as Colored String List
*
* @param color Color Char to parse
* @return Colored String List
*/
public List<String> asColoredStringList(char color) {
if (obj != null) {
if (Util.isNull(color)) throw new NullPointerException();
List<String> values = new ArrayList<String>();
for (String value : asStringList()) {
values.add(TextColor.parseColor(color, value));
}
return values;
} else return null;
}
/**
* Get Object as UUID
*
* @return UUID
*/
public UUID asUUID() {
if (obj != null) return UUID.fromString((String) obj);
else return null;
}
/**
* Get Object as UUID List
*
* @return UUID List
*/
public List<UUID> asUUIDList() {
if (obj != null) {
List<UUID> values = new ArrayList<UUID>();
for (String value : (List<String>) obj) {
values.add(UUID.fromString(value));
}
return values;
} else return null;
}
/**
* Check if object is Null
*
* @return Null Status
*/
public boolean isNull() {
return obj == null;
}
/**
* Check if object is a Boolean
*
* @return Boolean Status
*/
public boolean isBoolean() {
return (obj instanceof Boolean);
}
/**
* Check if object is a YAML Section
*
* @return YAML Section Status
*/
public boolean isSection() {
return (obj instanceof Map);
}
/**
* Check if object is a List
*
* @return List Status
*/
public boolean isList() {
return (obj instanceof List);
}
/**
* Check if object is a Number
*
* @return Number Status
*/
public boolean isNumber() {
return (obj instanceof Number);
}
/**
* Check if object is a String
*
* @return String Status
*/
public boolean isString() {
return (obj instanceof String);
}
/**
* Check if object is a UUID
*
* @return UUID Status
*/
public boolean isUUID() {
return (obj instanceof String && !Util.isException(() -> UUID.fromString((String) obj)));
}
@Override
public boolean equals(Object object) {
if (obj == null) {
return object == null;
} else {
if (object instanceof YAMLValue) {
return obj.equals(((YAMLValue) object).obj);
} else {
return obj.equals(object);
}
}
}
@Override
public String toString() {
if (obj != null) return obj.toString();
else return "null";
}
}

View File

@ -1,50 +0,0 @@
package net.ME1312.SubServers.Host.Library;
/**
* Container Class
*
* @param <V> Item
*/
public class Container<V> {
private V obj;
/**
* Creates a Container
*
* @param item Object to Store
*/
public Container(V item) {
obj = item;
}
/**
* Grabs the Object
*
* @return The Object
*/
public V get() {
return obj;
}
/**
* Overwrite the Object
*
* @param value Object to Store
*/
public void set(V value) {
obj = value;
}
@Override
public boolean equals(Object object) {
if (object instanceof Container) {
if (obj == null || ((Container) object).get() == null) {
return obj == ((Container) object).get();
} else {
return obj.equals(((Container) object).get());
}
} else {
return super.equals(object);
}
}
}

View File

@ -1,20 +0,0 @@
package net.ME1312.SubServers.Host.Library.Event;
/**
* Cancellable SubEvent Layout Class
*/
public interface Cancellable {
/**
* Gets if the Event has been Cancelled
*
* @return Cancelled Status
*/
boolean isCancelled();
/**
* Sets if the Event is Cancelled
*
* @param value
*/
void setCancelled(boolean value);
}

View File

@ -1,71 +0,0 @@
package net.ME1312.SubServers.Host.Library.Event;
import net.ME1312.SubServers.Host.API.SubPluginInfo;
import net.ME1312.SubServers.Host.SubAPI;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
/**
* SubEvent Layout Class
*/
public abstract class Event {
private SubPluginInfo plugin = null;
/**
* Gets SubAPI
*
* @return SubAPI
*/
public SubAPI getAPI() {
return SubAPI.getInstance();
}
/**
* Gets your Plugin's Info
*
* @return Plugin Info
*/
public SubPluginInfo getPlugin() {
return plugin;
}
/**
* Get the handlers for this event
*
* @return Handler Map
*/
@SuppressWarnings({"deprecation", "unchecked"})
public Map<SubPluginInfo, List<Method>> getHandlers() throws IllegalAccessException {
try {
Field f = SubAPI.class.getDeclaredField("listeners");
f.setAccessible(true);
TreeMap<Short, HashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>>> listeners = (TreeMap<Short, HashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>>>) f.get(getAPI());
HashMap<SubPluginInfo, List<Method>> map = new LinkedHashMap<SubPluginInfo, List<Method>>();
f.setAccessible(false);
for (Short order : listeners.keySet()) {
if (!listeners.get(order).keySet().contains(getClass())) continue;
for (SubPluginInfo plugin : listeners.get(order).get(getClass()).keySet()) {
for (Object listener : listeners.get(order).get(getClass()).get(plugin).keySet()) {
for (Method method : listeners.get(order).get(getClass()).get(plugin).get(listener)) {
List<Method> methods = (map.keySet().contains(plugin))?map.get(plugin):new LinkedList<Method>();
methods.add(method);
map.put(plugin, methods);
}
}
}
}
return map;
} catch (NoSuchFieldException e) {
getAPI().getInternals().log.error.println(new InvocationTargetException(e, "Couldn't get handler list for event: " + toString()));
return null;
}
}
@Override
public String toString() {
return getClass().getTypeName();
}
}

View File

@ -1,33 +0,0 @@
package net.ME1312.SubServers.Host.Library.Event;
import net.ME1312.SubServers.Host.API.SubPluginInfo;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* EventHandler Method Annotation<br>
* Methods annotated by this and registered in SubAPI will be run when the event is called
*
* @see net.ME1312.SubServers.Host.SubAPI#addListener(SubPluginInfo, Object...)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface EventHandler {
/**
* Defines when this event should run
*
* @see EventOrder
* @return Event Order
*/
short order() default EventOrder.NORMAL;
/**
* If this Event should be run even if it's been cancelled
*
* @return Override Status
*/
boolean override() default false;
}

View File

@ -1,16 +0,0 @@
package net.ME1312.SubServers.Host.Library.Event;
/**
* Event Order Defaults Class<br>
* Events will be run from Short.MIN_VALUE to Short.MAX_VALUE
*/
public final class EventOrder {
private EventOrder() {}
public static final short FIRST = Short.MIN_VALUE;
public static final short VERY_EARLY = (Short.MIN_VALUE / 3) * 2;
public static final short EARLY = Short.MIN_VALUE / 3;
public static final short NORMAL = 0;
public static final short LATE = Short.MAX_VALUE / 3;
public static final short VERY_LATE = (Short.MAX_VALUE / 3) * 2;
public static final short LAST = Short.MAX_VALUE;
}

View File

@ -1,10 +0,0 @@
package net.ME1312.SubServers.Host.Library.Event;
/**
* Simple Listener Layout Class
*/
public interface Listener {
/*
* Place Events Here
*/
}

View File

@ -1,15 +0,0 @@
package net.ME1312.SubServers.Host.Library.Exception;
import java.lang.reflect.InvocationTargetException;
/**
* Illegal Plugin Exception
*/
public class IllegalPluginException extends InvocationTargetException {
public IllegalPluginException(Throwable e) {
super(e);
}
public IllegalPluginException(Throwable e, String s) {
super(e, s);
}
}

View File

@ -1,11 +0,0 @@
package net.ME1312.SubServers.Host.Library.Exception;
/**
* Illegal String Value Exception
*/
public class IllegalStringValueException extends IllegalStateException {
public IllegalStringValueException() {}
public IllegalStringValueException(String s) {
super(s);
}
}

View File

@ -1,47 +0,0 @@
package net.ME1312.SubServers.Host.Library;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Config.YAMLValue;
/**
* Extra Data Handler Layout Class
*/
public interface ExtraDataHandler {
/**
* Add an extra value to this Object
*
* @param handle Handle
* @param value Value
*/
void addExtra(String handle, Object value);
/**
* Determine if an extra value exists
*
* @param handle Handle
* @return Value Status
*/
boolean hasExtra(String handle);
/**
* Get an extra value
*
* @param handle Handle
* @return Value
*/
YAMLValue getExtra(String handle);
/**
* Get the extra value section
*
* @return Extra Value Section
*/
YAMLSection getExtra();
/**
* Remove an extra value from this Object
*
* @param handle Handle
*/
void removeExtra(String handle);
}

View File

@ -1,59 +0,0 @@
package net.ME1312.SubServers.Host.Library.Log;
import jline.console.ConsoleReader;
import jline.console.CursorBuffer;
import net.ME1312.SubServers.Host.Library.Container;
import net.ME1312.SubServers.Host.Library.TextColor;
import java.io.IOException;
import java.io.PrintStream;
import java.util.LinkedList;
/**
* Console Log Stream Class
*/
public class ConsoleStream extends PrintStream {
private ConsoleReader jline;
private PrintStream original;
private LinkedList<Integer> buffer;
private CursorBuffer hidden;
public ConsoleStream(ConsoleReader jline, PrintStream original) {
super(original);
this.jline = jline;
this.buffer = new LinkedList<Integer>();
this.original = original;
}
@Override
public void write(int i) {
try {
if (((char) i) == '\n') {
LinkedList<Integer> buffer = this.buffer;
this.buffer = new LinkedList<Integer>();
hide();
for (Integer b : buffer) original.write(b);
original.print(TextColor.RESET.asAnsiCode());
original.write(i);
show();
} else {
buffer.add(i);
}
} catch (Exception e) {}
}
private void hide() {
hidden = jline.getCursorBuffer().copy();
try {
jline.getOutput().write("\u001b[1G\u001b[K");
jline.flush();
} catch (IOException e) {}
}
private void show() {
try {
jline.resetPromptLine(jline.getPrompt(), hidden.toString(), hidden.cursor);
jline.flush();
} catch (IOException e) {}
}
}

View File

@ -1,47 +0,0 @@
package net.ME1312.SubServers.Host.Library.Log;
import net.ME1312.SubServers.Host.Library.Container;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* Error Log Stream Class
*/
public class ErrorStream extends LogStream {
protected ErrorStream(String prefix, String name, Container<PrintStream> stream) {
super(prefix, name, stream);
}
/**
* Print an Exception
*
* @param err Exception
*/
public void print(Throwable err) {
sync();
writing++;
StringWriter sw = new StringWriter();
err.printStackTrace(new PrintWriter(sw));
String s = sw.toString();
for (char c : s.substring(0, s.length() - 1).toCharArray()) write(c);
writing--;
}
/**
* Print multiple Exceptions (separated by a new line)
*
* @param err Exceptions
*/
public void println(Throwable... err) {
sync();
writing++;
for (Throwable e : err) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
for (char c : sw.toString().toCharArray()) write(c);
}
writing--;
}
}

View File

@ -1,39 +0,0 @@
package net.ME1312.SubServers.Host.Library.Log;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* Log File Writer Class
*/
public final class FileLogger extends OutputStream {
private static FileWriter file = null;
private PrintStream origin;
protected FileLogger(PrintStream origin, File dir) throws IOException {
this.origin = origin;
if (file == null) {
new File(dir, "Logs").mkdirs();
file = new FileWriter(new File(dir, "Logs" + File.separator + "SubServers.Host #" + (new File(dir, "Logs").list().length + 1) + " (" + new SimpleDateFormat("MM-dd-yyyy").format(Calendar.getInstance().getTime()) + ").log"));
}
}
@Override
public void write(int b) throws IOException {
origin.write((char)b);
if (file != null) {
file.write((char) b);
file.flush();
}
}
public static void end() throws IOException {
if (file != null) file.close();
file = null;
}
}

View File

@ -1,191 +0,0 @@
package net.ME1312.SubServers.Host.Library.Log;
import net.ME1312.SubServers.Host.Library.Container;
import java.io.File;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* Log Stream Class
*/
public class LogStream {
private static LogStream last = null;
private String prefix;
private String name;
private Container<PrintStream> stream;
private boolean first = true;
private Thread threadwriting = null;
protected long writing = 0;
protected LogStream(String prefix, String name, Container<PrintStream> stream) {
this.prefix = prefix;
this.name = name;
this.stream = stream;
}
protected String prefix() {
return "[" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "] [" + prefix + File.separator + name + "] > ";
}
/**
* Print an Object
*
* @param obj Object
*/
public void print(Object obj) {
sync();
writing++;
if (obj == null) {
for (char c : "null".toCharArray()) write(c);
} else {
for (char c : obj.toString().toCharArray()) write(c);
}
writing--;
}
/**
* Print a String
*
* @param str String
*/
public void print(String str) {
sync();
writing++;
if (str == null) {
for (char c : "null".toCharArray()) write(c);
} else {
for (char c : str.toCharArray()) write(c);
}
writing--;
}
/**
* Print an Array of Characters
*
* @param str Character Array
*/
public void print(char[] str) {
sync();
writing++;
for (char c : str) write(c);
writing--;
}
/**
* Print a Character
*
* @param c Character
*/
public void print(char c) {
sync();
writing++;
write(c);
writing--;
}
/**
* Write to the PrintStream
*
* @param c Character
*/
protected void write(char c) {
threadwriting = Thread.currentThread();
if (last != this) {
if (last != null) {
stall();
if (!last.first) last.print('\n');
}
LogStream.last = this;
first = true;
}
if (first) stream.get().print(prefix());
stream.get().print(c);
first = c == '\n';
}
private void stall() {
try {
while (last != null && last != this && last.writing > 0) {
Thread.sleep(125);
}
} catch (Exception e) {}
}
protected void sync() {
try {
while (threadwriting != null && threadwriting != Thread.currentThread() && writing > 0) {
Thread.sleep(125);
}
} catch (Exception e) {}
}
/**
* Print multiple Objects (separated by a new line)
*
* @param obj Objects
*/
public void println(Object... obj) {
sync();
writing++;
for (Object OBJ : obj) {
if (OBJ == null) {
for (char c : "null".toCharArray()) write(c);
} else {
for (char c : OBJ.toString().toCharArray()) write(c);
}
write('\n');
}
writing--;
}
/**
* Print multiple Strings (separated by a new line)
*
* @param str Objects
*/
public void println(String... str) {
sync();
writing++;
for (String STR : str) {
if (STR == null) {
for (char c : "null".toCharArray()) write(c);
} else {
for (char c : STR.toCharArray()) write(c);
}
write('\n');
}
writing--;
}
/**
* Print multiple Arrays of Characters (separated by a new line)
*
* @param str Character Arrays
*/
public void println(char[]... str) {
sync();
writing++;
for (char[] STR : str) {
for (char c : STR) write(c);
write('\n');
}
writing--;
}
/**
* Print multiple Characters (separated by a new line)
*
* @param c Characters
*/
public void println(char... c) {
sync();
writing++;
for (char C : c) {
write(C);
write('\n');
}
writing--;
}
}

View File

@ -1,58 +0,0 @@
package net.ME1312.SubServers.Host.Library.Log;
import jline.console.ConsoleReader;
import net.ME1312.SubServers.Host.Library.Container;
import net.ME1312.SubServers.Host.Library.Util;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URLDecoder;
/**
* Logger Class
*/
public final class Logger {
private static final Container<PrintStream> pso = new Container<PrintStream>(null);
private static final Container<PrintStream> pse = new Container<PrintStream>(null);
/**
* Setup the SubServers Log System
*
* @param out System.out
* @param err System.err
* @param in jline.in
* @param dir Runtime Directory
* @throws IOException
*/
public static void setup(PrintStream out, PrintStream err, ConsoleReader in, File dir) throws IOException {
if (Util.isNull(out, err, dir)) throw new NullPointerException();
if (pso.get() == null || pse.get() == null) {
pso.set(new PrintStream(new FileLogger(new ConsoleStream(in, out), dir)));
pse.set(new PrintStream(new FileLogger(new ConsoleStream(in, err), dir)));
System.setOut(new PrintStream(new SystemLogger(false)));
System.setErr(new PrintStream(new SystemLogger(true)));
}
}
/**
* Gets a new Logger
*
* @param prefix Log Prefix
*/
public Logger(String prefix) {
if (Util.isNull(prefix)) throw new NullPointerException();
if (prefix.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty prefix");
message = new LogStream(prefix, "MESSAGE", pso);
info = new LogStream(prefix, "INFO", pso);
warn = new ErrorStream(prefix, "WARN", pso);
error = new ErrorStream(prefix, "ERROR", pse);
severe = new ErrorStream(prefix, "SEVERE", pse);
}
public final LogStream message;
public final LogStream info;
public final ErrorStream warn;
public final ErrorStream error;
public final ErrorStream severe;
}

View File

@ -1,54 +0,0 @@
package net.ME1312.SubServers.Host.Library.Log;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.SubAPI;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.List;
/**
* System.out and System.err Override Class
*/
public final class SystemLogger extends OutputStream {
private NamedContainer<String, Logger> last = new NamedContainer<String, Logger>("", null);
private boolean error;
protected SystemLogger(boolean level) throws IOException {
this.error = level;
}
@SuppressWarnings("unchecked")
private List<String> getKnownClasses() {
List<String> value = null;
try {
Field f = SubAPI.class.getDeclaredField("knownClasses");
f.setAccessible(true);
value = (List<String>) f.get(SubAPI.getInstance());
f.setAccessible(false);
} catch (Exception e) {}
return value;
}
@Override
public void write(int c) throws IOException {
int i = 0;
String origin = java.lang.System.class.getCanonicalName();
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
if (i > 1 && getKnownClasses().contains(element.getClassName())) {
origin = element.getClassName().replaceFirst("\\$.*", "");
break;
}
i++;
}
if (!last.name().equals(origin)) last = new NamedContainer<String, Logger>(origin, new Logger(origin));
if (error) {
last.get().error.print((char) c);
} else {
last.get().info.print((char) c);
}
}
}

View File

@ -1,9 +1,10 @@
package net.ME1312.SubServers.Host.Library;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.SubServers.Host.ExHost;
import net.ME1312.SubServers.Host.Library.Config.YAMLConfig;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
@ -51,7 +52,7 @@ public class Metrics {
*/
public Metrics(ExHost host) {
boolean enabled = true;
File configPath = new File(new File(host.dir, "plugins"), "bStats");
File configPath = new File(new File(GalaxiEngine.getInstance().getRuntimeDirectory(), "plugins"), "bStats");
configPath.mkdirs();
File configFile = new File(configPath, "config.yml");
try {
@ -77,8 +78,9 @@ public class Metrics {
// Load charts
charts.add(new SingleLineChart("servers", () -> 1));
charts.add(new SingleLineChart("hosted_servers", () -> host.servers.size()));
charts.add(new SingleLineChart("plugins", () -> host.api.getPlugins().size()));
charts.add(new SimplePie("pluginVersion", host.version::toString));
charts.add(new SingleLineChart("plugins", () -> host.engine.getPluginManager().getPlugins().size()));
charts.add(new SimplePie("engineVersion", () -> host.engine.getEngineInfo().getVersion().toString()));
charts.add(new SimplePie("pluginVersion", () -> host.info.getVersion().toString()));
charts.add(new DrilldownPie("os", () -> {
String id = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
String name = System.getProperty("os.name");

View File

@ -1,52 +0,0 @@
package net.ME1312.SubServers.Host.Library;
/**
* Named Container Class
* @param <T> Name
* @param <V> Item
*/
public class NamedContainer<T, V> extends Container<V> {
private T name;
/**
* Creates a TaggedContainer
*
* @param name Tag to Bind
* @param item Object to Store
*/
public NamedContainer(T name, V item) {
super(item);
this.name = name;
}
/**
* Gets the name of the Container
*
* @return Container name
*/
public T name() {
return name;
}
/**
* Renames the Container
*
* @param name New Container Name
*/
public void rename(T name) {
this.name = name;
}
@Override
public boolean equals(Object object) {
if (object instanceof NamedContainer) {
if (name == null || ((NamedContainer) object).name() == null) {
return name == ((NamedContainer) object).name() && super.equals(object);
} else {
return name.equals(((NamedContainer) object).name()) && super.equals(object);
}
} else {
return super.equals(object);
}
}
}

View File

@ -1,98 +0,0 @@
package net.ME1312.SubServers.Host.Library;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* Plugin ClassLoader Class
*/
public class PluginClassLoader extends URLClassLoader {
private static Set<PluginClassLoader> loaders = new CopyOnWriteArraySet<PluginClassLoader>();
private Class<?> defaultClass = null;
/**
* Load Classes from URLs
*
* @param urls URLs
*/
public PluginClassLoader(URL[] urls) {
super(urls);
loaders.add(this);
}
/**
* Load Classes from URLs with a parent loader
*
* @param parent Parent loader
* @param urls URLs
*/
public PluginClassLoader(ClassLoader parent, URL... urls) {
super(urls, parent);
loaders.add(this);
}
/**
* Set the Default Class to load when no class is found
*
* @param clazz Class
*/
public void setDefaultClass(Class<?> clazz) {
defaultClass = clazz;
}
/**
* Get the Default Class to load when no class is found
*
* @throws ClassNotFoundException when no Default Class is set
* @return Default Class
*/
public Class<?> getDefaultClass() throws ClassNotFoundException {
if (defaultClass == null) {
throw new ClassNotFoundException();
} else {
return defaultClass;
}
}
private Class<?> getDefaultClass(String name) throws ClassNotFoundException {
try {
return getDefaultClass();
} catch (ClassNotFoundException e) {
throw new ClassNotFoundException(name);
}
}
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
return this.loadClass(name, resolve, true);
}
private Class<?> loadClass(String name, boolean resolve, boolean check) throws ClassNotFoundException {
try {
return super.loadClass(name, resolve);
} catch (NoClassDefFoundError | ClassNotFoundException e) {
if (check) {
Iterator i = loaders.iterator();
while (true) {
PluginClassLoader loader;
do {
if (!i.hasNext()) {
return getDefaultClass(name);
}
loader = (PluginClassLoader) i.next();
} while (loader == this);
try {
return loader.loadClass(name, resolve, false);
} catch (NoClassDefFoundError | ClassNotFoundException ex) {}
}
} else {
throw new ClassNotFoundException(name);
}
}
}
}

View File

@ -1,70 +0,0 @@
package net.ME1312.SubServers.Host.Library;
import java.io.File;
/**
* Universal File Class
*/
public class UniversalFile extends File {
/**
* Creates a File Link. Path names are separated by ':'
*
* @param pathname Path name
*/
public UniversalFile(String pathname) {
super(pathname.replace(".:", System.getProperty("user.dir") + ":").replace(':', File.separatorChar));
}
/**
* Creates a File Link. Path names are separated by the divider
*
* @param pathname Path name
* @param divider Divider to use
*/
public UniversalFile(String pathname, char divider) {
super(pathname.replace("." + divider, System.getProperty("user.dir") + divider).replace(divider, File.separatorChar));
}
/**
* Creates a File Link.
*
* @see File
* @param file File
*/
public UniversalFile(File file) {
super(file.getPath());
}
/**
* Creates a File. Path names are separated by the ':'
*
* @see File
* @param parent Parent File
* @param child Path name
*/
public UniversalFile(File parent, String child) {
super(parent, child.replace(':', File.separatorChar));
}
/**
* Creates a File. Path names are separated by the divider
*
* @see File
* @param parent Parent File
* @param child Path name
* @param divider Divider to use
*/
public UniversalFile(File parent, String child, char divider) {
super(parent, child.replace(divider, File.separatorChar));
}
/**
* Gets the Universal File Path (separated by ':')
*
* @return
*/
public String getUniversalPath() {
return getPath().replace(File.separatorChar, ':');
}
}

View File

@ -1,398 +0,0 @@
package net.ME1312.SubServers.Host.Library;
import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
/**
* SubServers Utility Class
*/
public final class Util {
private Util(){}
public interface ExceptionReturnRunnable<R> {
R run() throws Throwable;
}
public interface ExceptionRunnable {
void run() throws Throwable;
}
public interface ReturnRunnable<R> {
R run();
}
/**
* Checks values to make sure they're not null
*
* @param values Values to check
* @return If any are null
*/
public static boolean isNull(Object... values) {
boolean ret = false;
for (Object value : values) {
if (value == null) ret = true;
}
return ret;
}
/**
* Get keys by value from map
*
* @param map Map to search
* @param value Value to search for
* @param <K> Key
* @param <V> Value
* @return Search results
*/
public static <K, V> List<K> getBackwards(Map<K, V> map, V value) {
List<K> values = new ArrayList<K>();
for (K key : map.keySet()) {
if (map.get(key).equals(value)) {
values.add(key);
}
}
return values;
}
/**
* Get an item from a map ignoring case
*
* @param map Map to search
* @param key Key to search with
* @param <V> Value
* @return Search Result
*/
public static <V> V getCaseInsensitively(Map<String, V> map, String key) {
HashMap<String, String> insensitivity = new HashMap<String, String>();
for (String item : map.keySet()) insensitivity.put(item.toLowerCase(), item);
if (insensitivity.keySet().contains(key.toLowerCase())) {
return map.get(insensitivity.get(key.toLowerCase()));
} else {
return null;
}
}
/**
* Gets a new Variable that doesn't match the existing Variables
*
* @param existing Existing Variables
* @param generator Variable Generator
* @param <V> Variable Type
* @return Variable
*/
public static <V> V getNew(Collection<? extends V> existing, ReturnRunnable<V> generator) {
V result = null;
while (result == null) {
V tmp = generator.run();
if (!existing.contains(tmp)) result = tmp;
}
return result;
}
/**
* Read Everything from Reader
*
* @param rd Reader
* @return Reader Contents
* @throws IOException
*/
public static String readAll(Reader rd) throws IOException {
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1) {
sb.append((char) cp);
}
return sb.toString();
}
/**
* Copy from the Class Loader
*
* @param loader ClassLoader
* @param resource Location From
* @param destination Location To
*/
public static void copyFromJar(ClassLoader loader, String resource, String destination) {
InputStream resStreamIn = loader.getResourceAsStream(resource);
File resDestFile = new File(destination);
try {
OutputStream resStreamOut = new FileOutputStream(resDestFile);
int readBytes;
byte[] buffer = new byte[4096];
while ((readBytes = resStreamIn.read(buffer)) > 0) {
resStreamOut.write(buffer, 0, readBytes);
}
resStreamOut.close();
resStreamIn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* Get a variable from a method which may throw an exception
*
* @param runnable Runnable
* @param def Default value when an exception is thrown
* @param <R> Variable Type
* @return Returns value or default depending on if an exception is thrown
*/
public static <R> R getDespiteException(ExceptionReturnRunnable<R> runnable, R def) {
try {
return runnable.run();
} catch (Throwable e) {
return def;
}
}
/**
* Determines if an Exception will occur
*
* @param runnable Runnable
* @return If an Exception occured
*/
public static boolean isException(ExceptionRunnable runnable) {
try {
runnable.run();
return false;
} catch (Throwable e) {
return true;
}
}
/**
* Delete Directory
*
* @param folder Location
*/
public static void deleteDirectory(File folder) {
File[] files = folder.listFiles();
if(files!=null) {
for(File f: files) {
if(f.isDirectory()) {
deleteDirectory(f);
} else {
f.delete();
}
}
}
folder.delete();
}
/**
* Copy a Directory
*
* @param from Source
* @param to Destination
*/
public static void copyDirectory(File from, File to) {
if (from.isDirectory()) {
if (!to.exists()) {
to.mkdirs();
}
String files[] = from.list();
for (String file : files) {
File srcFile = new File(from, file);
File destFile = new File(to, file);
copyDirectory(srcFile, destFile);
}
} else {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(from);
out = new FileOutputStream(to, false);
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();
out.close();
} catch (Exception e) {
try {
if (in != null) in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
if (out != null) out.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
}
}
private static List<String> zipsearch(File origin, File file) {
List<String> list = new LinkedList<String>();
if (file.isFile()) {
list.add(file.getAbsoluteFile().toString().substring(origin.getAbsoluteFile().toString().length()+1, file.getAbsoluteFile().toString().length()));
}
if (file.isDirectory()) for (File next : file.listFiles()) {
list.addAll(zipsearch(origin, next));
}
return list;
}
public static void zip(File file, OutputStream zip) {
byte[] buffer = new byte[1024];
try{
ZipOutputStream zos = new ZipOutputStream(zip);
for(String next : zipsearch(file, file)){
ZipEntry ze= new ZipEntry(next);
zos.putNextEntry(ze);
FileInputStream in = new FileInputStream(file.getAbsolutePath() + File.separator + next);
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
}
zos.closeEntry();
zos.close();
} catch(IOException ex){
ex.printStackTrace();
}
}
public static void unzip(InputStream zip, File dir) {
byte[] buffer = new byte[1024];
try{
ZipInputStream zis = new ZipInputStream(zip);
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
File newFile = new File(dir + File.separator + ze.getName());
if (newFile.exists()) {
if (newFile.isDirectory()) {
Util.deleteDirectory(newFile);
} else {
newFile.delete();
}
}
if (ze.isDirectory()) {
newFile.mkdirs();
continue;
} else if (!newFile.getParentFile().exists()) {
newFile.getParentFile().mkdirs();
}
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
}
zis.closeEntry();
zis.close();
} catch(IOException ex) {
ex.printStackTrace();
}
}
/**
* Get a Random Integer
*
* @param min Minimum Value
* @param max Maximum Value
* @return Random Integer
*/
public static int random(int min, int max) {
return new Random().nextInt((max - min) + 1) + min;
}
/**
* Parse escapes in a Java String
*
* @param str String
* @return Unescaped String
*/
public static String unescapeJavaString(String str) {
StringBuilder sb = new StringBuilder(str.length());
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch == '\\') {
char nextChar = (i == str.length() - 1) ? '\\' : str
.charAt(i + 1);
// Octal escape?
if (nextChar >= '0' && nextChar <= '7') {
String code = "" + nextChar;
i++;
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
&& str.charAt(i + 1) <= '7') {
code += str.charAt(i + 1);
i++;
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
&& str.charAt(i + 1) <= '7') {
code += str.charAt(i + 1);
i++;
}
}
sb.append((char) Integer.parseInt(code, 8));
continue;
}
switch (nextChar) {
case '\\':
ch = '\\';
break;
case 'b':
ch = '\b';
break;
case 'f':
ch = '\f';
break;
case 'n':
ch = '\n';
break;
case 'r':
ch = '\r';
break;
case 't':
ch = '\t';
break;
case '\"':
ch = '\"';
break;
case '\'':
ch = '\'';
break;
// Hex Unicode: u????
case 'u':
if (i >= str.length() - 5) {
ch = 'u';
break;
}
int code = Integer.parseInt(
"" + str.charAt(i + 2) + str.charAt(i + 3)
+ str.charAt(i + 4) + str.charAt(i + 5), 16);
sb.append(Character.toChars(code));
i += 5;
continue;
}
i++;
}
sb.append(ch);
}
return sb.toString();
}
}

View File

@ -1,411 +0,0 @@
package net.ME1312.SubServers.Host.Library.Version;
import net.ME1312.SubServers.Host.Library.Util;
import java.io.Serializable;
import java.util.Collections;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Version Class
*/
@SuppressWarnings("serial")
public class Version implements Serializable, Comparable<Version> {
private final Version parent;
private final VersionType type;
private final String string;
/**
* Creates a Version
*
* @param string Version String
*/
public Version(String string) {
this(VersionType.VERSION, string);
}
/**
* Creates a Version
*
* @param type Version Type
* @param string Version String
*/
public Version(VersionType type, String string) {
this(null, type, string);
}
/**
* Creates a Version (Appending the parent)
*
* @param parent Parent Version
* @param string Version String
*/
public Version(Version parent, String string) {
this(parent, VersionType.VERSION, string);
}
/**
* Creates a Version (Appending the parent)
*
* @param parent Parent Version
* @param type Version Type
* @param string Version String
*/
public Version(Version parent, VersionType type, String string) {
if (Util.isNull(string, type)) throw new NullPointerException();
this.parent = parent;
this.type = type;
this.string = string;
}
/**
* Creates a Version
*
* @param ints Version Numbers (Will be separated with dots)
*/
public Version(int... ints) {
this(VersionType.VERSION, ints);
}
/**
* Creates a Version
*
* @param type Version Type
* @param ints Version Numbers (Will be separated with dots)
*/
public Version(VersionType type, int... ints) {
this(null, type, ints);
}
/**
* Creates a Version (Appending the parent)
*
* @param parent Parent Version
* @param ints Version Numbers (Will be separated with dots)
*/
public Version(Version parent, int... ints) {
this(parent, VersionType.VERSION, ints);
}
/**
* Creates a Version (Appending the parent)
*
* @param parent Parent Version
* @param type Version Type
* @param ints Version Numbers (Will be separated with dots)
*/
public Version(Version parent, VersionType type, int... ints) {
if (Util.isNull(type)) throw new NullPointerException();
this.parent = parent;
this.type = type;
String string = Integer.toString(ints[0]);
int i = 0;
if (ints.length != 1) {
do {
i++;
string = string + "." + ints[i];
} while ((i + 1) != ints.length);
}
this.string = string;
}
/**
* Parse a Version from a string
*
* @param string String to parse
* @see #toFullString() <b>#toFullString()</b> returns a valid string
* @see #toFullString() <b>#toString()</b> returns a valid string
*/
public static Version fromString(String string) {
Matcher regex = Pattern.compile("(rv|p?[abrv]|[su])?([^/]+)", Pattern.CASE_INSENSITIVE).matcher(string);
Version current = null;
while (regex.find()) {
try {
VersionType type = VersionType.VERSION;
if (regex.group(1) != null) switch (regex.group(1).toLowerCase()) {
case "pa":
type = VersionType.PRE_ALPHA;
break;
case "a":
type = VersionType.ALPHA;
break;
case "pv":
type = VersionType.PREVIEW;
break;
case "pb":
type = VersionType.PRE_BETA;
break;
case "b":
type = VersionType.BETA;
break;
case "s":
type = VersionType.SNAPSHOT;
break;
case "pr":
type = VersionType.PRE_RELEASE;
break;
case "r":
type = VersionType.RELEASE;
break;
case "rv":
type = VersionType.REVISION;
break;
case "u":
type = VersionType.UPDATE;
break;
}
current = new Version(current, type, regex.group(2));
} catch (Throwable e) {}
}
if (current == null) throw new IllegalArgumentException("Could not find version in string: " + string);
return current;
}
/**
* The default toString() method<br>
* <br>
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
* <b style="font-family: consolas">1.0.0/pa7</b>
*
* @return Version as a String
*/
@Override
public String toString() {
return ((parent == null)?"":parent.toString()+'/'+type.shortname) + string;
}
/**
* The full toString() method<br>
* <br>
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
* <b style="font-family: consolas">r1.0.0/pa7</b>
*
* @return Version as a String
*/
public String toFullString() {
return ((parent == null)?"":parent.toFullString()+'/') + type.shortname + string;
}
/**
* The extended toString() method<br>
* <br>
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
* <b style="font-family: consolas">1.0.0 pre-alpha 7</b>
*
* @return Version as a String
*/
public String toExtendedString() {
return ((parent == null)?"":parent.toExtendedString()+' '+type.longname+' ') + string;
}
/**
* The full extended toString() method<br>
* <br>
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
* <b style="font-family: consolas">release 1.0.0 pre-alpha 7</b>
*
* @return Version as a String
*/
public String toFullExtendedString() {
return ((parent == null)?"":parent.toFullExtendedString()+' ') + type.longname + ' ' + string;
}
@Override
public boolean equals(Object object) {
if (object instanceof Version) {
return equals((Version) object);
} else {
return super.equals(object);
}
}
/**
* See if Versions are Equal
*
* @param version Version to Compare to
* @return
*/
public boolean equals(Version version) {
return compareTo(version) == 0;
}
/*
* Returns 1 if Greater than
* Returns 0 if Equal
* Returns -1 if Less than
*//**
*
* Compare Versions
*
* @param version Version to Compare to
*/
public int compareTo(Version version) {
return compare(this, version);
}
/**
* See if Versions are Equal
*
* @param ver1 Version to Compare
* @param ver2 Version to Compare
* @return
*/
public static boolean equals(Version ver1, Version ver2) {
return compare(ver1, ver2) == 0;
}
/*
* Returns 1 if Greater than
* Returns 0 if Equal
* Returns -1 if Less than
*//**
* Compare Versions
*
* @param ver1 Version to Compare
* @param ver2 Version to Compare
*/
public static int compare(Version ver1, Version ver2) {
if (ver1 == null && ver2 == null) {
// Both versions are null
return 0;
}
if (ver1 == null) {
// Version one is null
return -1;
}
if (ver2 == null) {
// Version two is null
return 1;
}
LinkedList<Version> stack1 = new LinkedList<Version>();
stack1.add(ver1);
while (ver1.parent != null) {
ver1 = ver1.parent;
stack1.add(ver1);
}
Collections.reverse(stack1);
LinkedList<Version> stack2 = new LinkedList<Version>();
stack2.add(ver2);
while (ver2.parent != null) {
ver2 = ver2.parent;
stack2.add(ver2);
}
Collections.reverse(stack2);
int id;
for (id = 0; id < stack1.size(); id++) {
if (id >= stack2.size()) {
// Version one still has children when version two does not...
if (stack1.get(id).type.stageid < 0) {
// ...making version two the official version
return -1;
} else {
// ...however the direct child of version one has a stageid higher than or equal to a release
return 1;
}
}
int result = stack1.get(id).compare(stack2.get(id));
if (result != 0) {
// Versions are not the same, return the result
return result;
}
}
if (id < stack2.size()) {
// Version one does not children when version two still does...
if (stack2.get(id).type.stageid < 0) {
// ...making version one the official version
return 1;
} else {
// ...however the direct child of version two has a stageid higher than or equal to a release
return -1;
}
}
return 0;
}
/*
* Compares versions ignoring parent/child relationships
*/
private int compare(Version version) {
if (this.type.stageid > version.type.stageid) {
// Version one has a type of a later stage than version two
return 1;
}
if (this.type.stageid < version.type.stageid) {
// Version one has a type of an earlier stage than version two
return -1;
}
VersionTokenizer tokenizer1 = new VersionTokenizer(string);
VersionTokenizer tokenizer2 = new VersionTokenizer(version.string);
int number1, number2;
String suffix1, suffix2;
while (tokenizer1.MoveNext()) {
if (!tokenizer2.MoveNext()) {
do {
number1 = tokenizer1.getNumber();
suffix1 = tokenizer1.getSuffix();
if (number1 != 0 || suffix1.length() != 0) {
// Version one is longer than number two, and non-zero
return 1;
}
}
while (tokenizer1.MoveNext());
// Version one is longer than version two, but zero
return 0;
}
number1 = tokenizer1.getNumber();
suffix1 = tokenizer1.getSuffix();
number2 = tokenizer2.getNumber();
suffix2 = tokenizer2.getSuffix();
if (number1 < number2) {
// Number one is less than number two
return -1;
}
if (number1 > number2) {
// Number one is greater than number two
return 1;
}
boolean empty1 = suffix1.length() == 0;
boolean empty2 = suffix2.length() == 0;
if (empty1 && empty2) continue; // No suffixes
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
// Lexical comparison of suffixes
int result = suffix1.compareTo(suffix2);
if (result != 0) return result;
}
if (tokenizer2.MoveNext()) {
do {
number2 = tokenizer2.getNumber();
suffix2 = tokenizer2.getSuffix();
if (number2 != 0 || suffix2.length() != 0) {
// Version one is longer than version two, and non-zero
return -1;
}
}
while (tokenizer2.MoveNext());
// Version two is longer than version one, but zero
return 0;
}
return 0;
}
}

View File

@ -1,64 +0,0 @@
package net.ME1312.SubServers.Host.Library.Version;
public final class VersionTokenizer {
private final String _versionString;
private final int _length;
private int _position;
private int _number;
private String _suffix;
private boolean _hasValue;
protected int getNumber() {
return _number;
}
protected String getSuffix() {
return _suffix;
}
protected boolean hasValue() {
return _hasValue;
}
protected VersionTokenizer(String versionString) {
if (versionString == null)
throw new IllegalArgumentException("versionString is null");
_versionString = versionString;
_length = versionString.length();
}
protected boolean MoveNext() {
_number = 0;
_suffix = "";
_hasValue = false;
// No more characters
if (_position >= _length)
return false;
_hasValue = true;
while (_position < _length) {
char c = _versionString.charAt(_position);
if (c < '0' || c > '9') break;
_number = _number * 10 + (c - '0');
_position++;
}
int suffixStart = _position;
while (_position < _length) {
char c = _versionString.charAt(_position);
if (c == '.') break;
_position++;
}
_suffix = _versionString.substring(suffixStart, _position);
if (_position < _length) _position++;
return true;
}
}

View File

@ -1,23 +0,0 @@
package net.ME1312.SubServers.Host.Library.Version;
public enum VersionType {
PRE_ALPHA(-6, "pa", "pre-alpha"),
ALPHA(-5, "a", "alpha"),
PREVIEW(-4, "pv", "preview"),
PRE_BETA(-4, "pb", "pre-beta"),
BETA(-3, "b", "beta"),
SNAPSHOT(-2, "s", "snapshot"),
PRE_RELEASE(-1, "pr", "pre-release"),
RELEASE(0, "r", "release"),
REVISION(0, "rv", "revision"),
VERSION(0, "v", "version"),
UPDATE(0, "u", "update"),
;
final short stageid;
final String shortname, longname;
VersionType(int stageid, String shortname, String longname) {
this.stageid = (short) stageid;
this.shortname = shortname;
this.longname = longname;
}
}

View File

@ -1,8 +1,8 @@
package net.ME1312.SubServers.Host.Network.API;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Config.YAMLValue;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Config.YAMLValue;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadHostInfo;
import net.ME1312.SubServers.Host.SubAPI;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.API;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Config.YAMLValue;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Config.YAMLValue;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadProxyInfo;
import net.ME1312.SubServers.Host.SubAPI;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.Network.API;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadServerInfo;
import net.ME1312.SubServers.Host.SubAPI;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.API;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.Packet.PacketCreateServer;
import net.ME1312.SubServers.Host.SubAPI;

View File

@ -1,10 +1,9 @@
package net.ME1312.SubServers.Host.Network.API;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Host.Network.Packet.PacketCommandServer;
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadHostInfo;
import net.ME1312.SubServers.Host.Network.Packet.PacketStartServer;
import net.ME1312.SubServers.Host.Network.Packet.PacketStopServer;
import net.ME1312.SubServers.Host.SubAPI;

View File

@ -1,6 +1,6 @@
package net.ME1312.SubServers.Host.Network;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import org.msgpack.value.Value;
/**

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Host.Network.Encryption;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Network.SubDataClient;
import org.json.JSONObject;
import org.msgpack.core.MessagePack;
import org.msgpack.core.MessagePacker;
@ -187,7 +188,7 @@ public final class AES implements net.ME1312.SubServers.Host.Network.Cipher {
public Value encrypt(String key, YAMLSection data) throws Exception {
ByteArrayOutputStream unencrypted = new ByteArrayOutputStream();
MessagePacker packer = MessagePack.newDefaultPacker(unencrypted);
packer.packValue(data.msgPack());
packer.packValue(SubDataClient.convert(data));
packer.close();
ByteArrayOutputStream encrypted = new ByteArrayOutputStream();
@ -283,7 +284,7 @@ public final class AES implements net.ME1312.SubServers.Host.Network.Cipher {
public YAMLSection decrypt(String key, Value data) throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
decrypt(key, new ByteArrayInputStream(data.asBinaryValue().asByteArray()), bytes);
return new YAMLSection(MessagePack.newDefaultUnpacker(bytes.toByteArray()).unpackValue().asMapValue());
return SubDataClient.convert(MessagePack.newDefaultUnpacker(bytes.toByteArray()).unpackValue().asMapValue());
}
/**

View File

@ -1,10 +1,10 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.Network.SubDataClient;

View File

@ -1,9 +1,8 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,10 +1,10 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.Network.SubDataClient;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,11 +1,11 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Executable.Executable;
import net.ME1312.SubServers.Host.Executable.SubServer;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.Network.SubDataClient;

View File

@ -1,11 +1,12 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Executable.SubCreator;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.UniversalFile;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.Network.SubDataClient;
@ -50,7 +51,7 @@ public class PacketExConfigureHost implements PacketIn, PacketOut {
Util.deleteDirectory(template.getDirectory());
}
host.templates.clear();
UniversalFile templates = new UniversalFile(host.dir, "Templates");
UniversalFile templates = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates");
Util.deleteDirectory(templates);
templates.mkdirs();
for (String name : data.getSection("templates").getKeys()) {

View File

@ -1,8 +1,8 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.ExHost;

View File

@ -1,11 +1,12 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Executable.SubServer;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.UniversalFile;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.Network.SubDataClient;
@ -75,7 +76,7 @@ public class PacketExDeleteServer implements PacketIn, PacketOut {
SubServer server = host.servers.get(data.getRawString("server").toLowerCase());
host.servers.remove(data.getRawString("server").toLowerCase());
new Thread(() -> {
UniversalFile to = new UniversalFile(host.dir, "Recently Deleted:" + server.getName().toLowerCase());
UniversalFile to = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Recently Deleted:" + server.getName().toLowerCase());
try {
File from = new File(host.host.getRawString("Directory"), server.getDirectory());
if (from.exists()) {

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.Network.SubDataClient;

View File

@ -1,8 +1,8 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Executable.SubServer;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.ExHost;

View File

@ -1,8 +1,8 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.ExHost;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import java.io.IOException;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.ExHost;

View File

@ -1,10 +1,11 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.API.Event.*;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Event.*;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.SubAPI;
@ -26,28 +27,28 @@ public class PacketInRunEvent implements PacketIn {
callback("SubAddHostEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubAddHostEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("host")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubAddHostEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("host")));
callback("SubAddHostEvent", this);
}
});
callback("SubAddProxyEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubAddProxyEvent(data.getRawString("proxy")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubAddProxyEvent(data.getRawString("proxy")));
callback("SubAddProxyEvent", this);
}
});
callback("SubAddServerEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubAddServerEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, (data.contains("host"))?data.getRawString("host"):null, data.getRawString("server")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubAddServerEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, (data.contains("host"))?data.getRawString("host"):null, data.getRawString("server")));
callback("SubAddServerEvent", this);
}
});
callback("SubCreateEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubCreateEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("host"), data.getRawString("name"),
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubCreateEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("host"), data.getRawString("name"),
data.getRawString("template"), new Version(data.getRawString("version")), data.getInt("port")));
callback("SubCreateEvent", this);
}
@ -55,56 +56,56 @@ public class PacketInRunEvent implements PacketIn {
callback("SubSendCommandEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubSendCommandEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("server"), data.getRawString("command")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubSendCommandEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("server"), data.getRawString("command")));
callback("SubSendCommandEvent", this);
}
});
callback("SubEditServerEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubEditServerEvent((data.contains("player")) ? UUID.fromString(data.getRawString("player")):null, data.getRawString("server"), new NamedContainer<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubEditServerEvent((data.contains("player")) ? UUID.fromString(data.getRawString("player")):null, data.getRawString("server"), new NamedContainer<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
callback("SubEditServerEvent", this);
}
});
callback("SubStartEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubStartEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("server")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubStartEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("server")));
callback("SubStartEvent", this);
}
});
callback("SubStopEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubStopEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("server"), data.getBoolean("force")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubStopEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("server"), data.getBoolean("force")));
callback("SubStopEvent", this);
}
});
callback("SubStoppedEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubStoppedEvent(data.getRawString("server")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubStoppedEvent(data.getRawString("server")));
callback("SubStoppedEvent", this);
}
});
callback("SubRemoveServerEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubRemoveServerEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, (data.contains("host"))?data.getRawString("host"):null, data.getRawString("server")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubRemoveServerEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, (data.contains("host"))?data.getRawString("host"):null, data.getRawString("server")));
callback("SubRemoveServerEvent", this);
}
});
callback("SubRemoveProxyEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubAddProxyEvent(data.getRawString("proxy")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubAddProxyEvent(data.getRawString("proxy")));
callback("SubRemoveProxyEvent", this);
}
});
callback("SubRemoveHostEvent", new Callback<YAMLSection>() {
@Override
public void run(YAMLSection data) {
SubAPI.getInstance().executeEvent(new SubRemoveHostEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("host")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubRemoveHostEvent((data.contains("player"))?UUID.fromString(data.getRawString("player")):null, data.getRawString("host")));
callback("SubRemoveHostEvent", this);
}
});

View File

@ -1,9 +1,10 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import net.ME1312.SubServers.Host.Network.SubDataClient;
@ -53,7 +54,7 @@ public class PacketLinkExHost implements PacketIn, PacketOut {
} catch (Exception e) {}
} else {
log.info.println("Could not link name with host: " + data.getRawString("m"));
host.stop(1);
GalaxiEngine.getInstance().stop();
}
}

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketOut;
import java.util.UUID;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketOut;
/**

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,9 +1,9 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.Network;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Version.Version;
/**
* PacketIn Layout Class

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Host.Network;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Version.Version;
/**
* PacketOut Layout Class

View File

@ -1,35 +1,33 @@
package net.ME1312.SubServers.Host.Network;
import net.ME1312.SubServers.Host.API.Event.SubNetworkConnectEvent;
import net.ME1312.SubServers.Host.API.Event.SubNetworkDisconnectEvent;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Event.SubNetworkConnectEvent;
import net.ME1312.SubServers.Host.Event.SubNetworkDisconnectEvent;
import net.ME1312.SubServers.Host.Library.Exception.IllegalPacketException;
import net.ME1312.SubServers.Host.Library.Log.Logger;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.Encryption.AES;
import net.ME1312.SubServers.Host.Network.Packet.*;
import net.ME1312.SubServers.Host.SubAPI;
import net.ME1312.SubServers.Host.ExHost;
import org.json.JSONException;
import org.json.JSONObject;
import org.msgpack.core.MessageInsufficientBufferException;
import org.msgpack.core.MessagePack;
import org.msgpack.core.MessagePacker;
import org.msgpack.core.MessageUnpacker;
import org.msgpack.value.MapValue;
import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;
import org.yaml.snakeyaml.error.YAMLException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -73,12 +71,12 @@ public final class SubDataClient {
}
@Override
public Value encrypt(String key, YAMLSection data) {
return data.msgPack();
return convert(data);
}
@Override
@SuppressWarnings("unchecked")
public YAMLSection decrypt(String key, Value data) {
return new YAMLSection(data.asMapValue());
return convert(data.asMapValue());
}
};
@ -97,7 +95,7 @@ public final class SubDataClient {
queue.remove(0);
}
socket.rename(true);
host.api.executeEvent(new SubNetworkConnectEvent(host.subdata));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubNetworkConnectEvent(host.subdata));
}
static {
@ -380,6 +378,109 @@ public final class SubDataClient {
forwardPacket(packet, "");
}
/**
* Convert a YAMLSection to a MessagePack Map
*
* @param config YAMLSection
* @return MessagePack Map
*/
public static MapValue convert(YAMLSection config) {
return (MapValue) msgPack(config.get());
}
@SuppressWarnings("unchecked")
private static Value msgPack(Object value) {
if (value == null) {
return ValueFactory.newNil();
} else if (value instanceof Value) {
return (Value) value;
} else if (value instanceof Map) {
ValueFactory.MapBuilder map = ValueFactory.newMapBuilder();
for (String key : ((Map<String, ?>) value).keySet()) {
Value v = msgPack(((Map<String, ?>) value).get(key));
if (v != null) map.put(ValueFactory.newString(key), v);
}
return map.build();
} else if (value instanceof Collection) {
LinkedList<Value> values = new LinkedList<Value>();
for (Object object : (Collection<?>) value) {
Value v = msgPack(object);
if (v != null) values.add(v);
}
return ValueFactory.newArray(values);
} else if (value instanceof Boolean) {
return ValueFactory.newBoolean((boolean) value);
} else if (value instanceof Number) {
if (((Number) value).doubleValue() == (double)(int) ((Number) value).doubleValue()) {
return ValueFactory.newInteger(((Number) value).longValue());
} else {
return ValueFactory.newFloat(((Number) value).doubleValue());
}
} else if (value instanceof String) {
return ValueFactory.newString((String) value);
} else {
return null;
}
}
/**
* Convert a MessagePack Map to a YAMLSection
*
* @param msgpack MessagePack Map
* @return YAMLSection
*/
@SuppressWarnings("unchecked")
public static YAMLSection convert(MapValue msgpack) {
YAMLSection section = new YAMLSection();
boolean warned = false;
Map<Value, Value> map = msgpack.map();
for (Value key : map.keySet()) {
if (key.isStringValue()) {
section.set(key.asStringValue().asString(), simplify(map.get(key)));
} else if (!warned) {
new IllegalStateException("MessagePack contains non-string key(s)").printStackTrace();
warned = true;
}
}
return section;
}
private static Object simplify(Value value) {
Object simple = value;
if (value.isNilValue()) {
simple = null;
} else if (value.isMapValue()) {
Map<Value, Value> map = value.asMapValue().map();
simple = convert(value.asMapValue());
} else if (value.isArrayValue()) {
simple = value.asArrayValue().list();
} else if (value.isBooleanValue()) {
simple = value.asBooleanValue().getBoolean();
} else if (value.isFloatValue()) {
if (value.asFloatValue().toDouble() == (double)(float) value.asFloatValue().toDouble()) {
simple = value.asFloatValue().toFloat();
} else {
simple = value.asFloatValue().toDouble();
}
} else if (value.isIntegerValue()) {
if (value.asIntegerValue().isInByteRange()) {
simple = value.asIntegerValue().asByte();
} else if (value.asIntegerValue().isInShortRange()) {
simple = value.asIntegerValue().asShort();
} else if (value.asIntegerValue().isInIntRange()) {
simple = value.asIntegerValue().asInt();
} else if (value.asIntegerValue().isInLongRange()) {
simple = value.asIntegerValue().asLong();
} else {
simple = value.asIntegerValue().asBigInteger();
}
} else if (value.isStringValue()) {
simple = value.asStringValue().asString();
}
return simple;
}
/**
* Encode PacketOut
*
@ -441,7 +542,7 @@ public final class SubDataClient {
final Socket socket = this.socket.get();
this.socket.set(null);
if (!socket.isClosed()) socket.close();
host.api.executeEvent(new SubNetworkDisconnectEvent());
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubNetworkDisconnectEvent());
log.info.println("The SubData Connection was closed");
if (reconnect > 0) {
log.info.println("Attempting to reconnect in " + reconnect + " seconds");

View File

@ -1,14 +1,9 @@
package net.ME1312.SubServers.Host;
import net.ME1312.SubServers.Host.API.Command;
import net.ME1312.SubServers.Host.API.SubPluginInfo;
import net.ME1312.SubServers.Host.API.SubTask;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Event.*;
import net.ME1312.SubServers.Host.Library.NamedContainer;
import net.ME1312.SubServers.Host.Library.UniversalFile;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.Galaxi.Library.Callback;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Plugin.PluginInfo;
import net.ME1312.SubServers.Host.Network.API.Host;
import net.ME1312.SubServers.Host.Network.API.Proxy;
import net.ME1312.SubServers.Host.Network.API.Server;
@ -16,21 +11,13 @@ import net.ME1312.SubServers.Host.Network.API.SubServer;
import net.ME1312.SubServers.Host.Network.Packet.*;
import net.ME1312.SubServers.Host.Network.SubDataClient;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* SubAPI Class
*/
public final class SubAPI {
final TreeMap<Short, HashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>>> listeners = new TreeMap<Short, HashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>>>();
final HashMap<UUID, Timer> schedule = new HashMap<UUID, Timer>();
final TreeMap<String, Command> commands = new TreeMap<String, Command>();
final HashMap<String, SubPluginInfo> plugins = new LinkedHashMap<String, SubPluginInfo>();
final List<String> knownClasses = new ArrayList<String>();
private final ExHost host;
private static SubAPI api;
@ -381,279 +368,6 @@ public final class SubAPI {
return host.subdata;
}
/**
* Get a map of the Plugins
*
* @return PluginInfo Map
*/
public Map<String, SubPluginInfo> getPlugins() {
return new LinkedHashMap<String, SubPluginInfo>(plugins);
}
/**
* Gets a Plugin
*
* @param plugin Plugin Name
* @return PluginInfo
*/
public SubPluginInfo getPlugin(String plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
return getPlugins().get(plugin.toLowerCase());
}
/**
* Registers a Command
*
* @param command Command
* @param handles Aliases
*/
public void addCommand(Command command, String... handles) {
for (String handle : handles) {
commands.put(handle.toLowerCase(), command);
}
}
/**
* Unregisters a Command
*
* @param handles Aliases
*/
public void removeCommand(String... handles) {
for (String handle : handles) {
commands.remove(handle.toLowerCase());
}
}
private UUID getFreeSID() {
UUID sid = null;
do {
UUID id = UUID.randomUUID();
if (!schedule.keySet().contains(id)) {
sid = id;
}
} while (sid == null);
return sid;
}
/**
* Schedule a task
*
* @param builder SubTaskBuilder
* @return Task ID
*/
public UUID schedule(SubTask builder) {
if (Util.isNull(builder)) throw new NullPointerException();
UUID sid = getFreeSID();
TimerTask task = new TimerTask() {
@Override
public void run() {
try {
builder.run();
} catch (Throwable e) {
host.log.error.println(new InvocationTargetException(e, "Unhandled exception while running SubTask " + sid.toString()));
}
if (builder.repeat() <= 0) schedule.remove(sid);
}
};
schedule.put(sid, new Timer("SubTask_" + sid.toString()));
if (builder.repeat() > 0) {
if (builder.delay() > 0) {
schedule.get(sid).scheduleAtFixedRate(task, builder.delay(), builder.repeat());
} else {
schedule.get(sid).scheduleAtFixedRate(task, new Date(), builder.repeat());
}
} else {
if (builder.delay() > 0) {
schedule.get(sid).schedule(task, builder.delay());
} else {
new Thread(task).start();
}
}
return sid;
}
/**
* Schedule a task
*
* @param plugin Plugin Scheduling
* @param run What to run
* @return Task ID
*/
public UUID schedule(SubPluginInfo plugin, Runnable run) {
return schedule(plugin, run, -1L);
}
/**
* Schedule a task
*
* @param plugin Plugin Scheduling
* @param run What to Run
* @param delay Task Delay
* @return Task ID
*/
public UUID schedule(SubPluginInfo plugin, Runnable run, long delay) {
return schedule(plugin, run, delay, -1L);
}
/**
* Schedule a task
*
* @param plugin Plugin Scheduling
* @param run What to Run
* @param delay Task Delay
* @param repeat Task Repeat Interval
* @return Task ID
*/
public UUID schedule(SubPluginInfo plugin, Runnable run, long delay, long repeat) {
return schedule(plugin, run, TimeUnit.MILLISECONDS, delay, repeat);
}
/**
* Schedule a task
*
* @param plugin Plugin Scheduling
* @param run What to Run
* @param unit TimeUnit to use
* @param delay Task Delay
* @param repeat Task Repeat Interval
* @return Task ID
*/
public UUID schedule(SubPluginInfo plugin, Runnable run, TimeUnit unit, long delay, long repeat) {
if (Util.isNull(plugin, run, unit, delay, repeat)) throw new NullPointerException();
return schedule(new SubTask(plugin) {
@Override
public void run() {
run.run();
}
}.delay(unit.toMillis(delay)).repeat(unit.toMillis(repeat)));
}
/**
* Cancel a task
*
* @param sid Task ID
*/
public void cancelTask(UUID sid) {
if (Util.isNull(sid)) throw new NullPointerException();
if (schedule.keySet().contains(sid)) {
schedule.get(sid).cancel();
schedule.remove(sid);
}
}
/**
* Register SubEvent Listeners
*
* @param plugin PluginInfo
* @param listeners Listeners
*/
@SuppressWarnings("unchecked")
public void addListener(SubPluginInfo plugin, Object... listeners) {
for (Object listener : listeners) {
if (Util.isNull(plugin, listener)) throw new NullPointerException();
for (Method method : Arrays.asList(listener.getClass().getMethods())) {
if (method.isAnnotationPresent(EventHandler.class)) {
if (method.getParameterTypes().length == 1) {
if (Event.class.isAssignableFrom(method.getParameterTypes()[0])) {
HashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>> events = (this.listeners.keySet().contains(method.getAnnotation(EventHandler.class).order()))?this.listeners.get(method.getAnnotation(EventHandler.class).order()):new LinkedHashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>>();
HashMap<SubPluginInfo, HashMap<Object, List<Method>>> plugins = (events.keySet().contains((Class<Event>) method.getParameterTypes()[0]))?events.get((Class<Event>) method.getParameterTypes()[0]):new LinkedHashMap<SubPluginInfo, HashMap<Object, List<Method>>>();
HashMap<Object, List<Method>> objects = (plugins.keySet().contains(plugin))?plugins.get(plugin):new LinkedHashMap<Object, List<Method>>();
List<Method> methods = (objects.keySet().contains(listener))?objects.get(listener):new LinkedList<Method>();
methods.add(method);
objects.put(listener, methods);
plugins.put(plugin, objects);
events.put((Class<Event>) method.getParameterTypes()[0], plugins);
this.listeners.put(method.getAnnotation(EventHandler.class).order(), events);
} else {
plugin.getLogger().error.println(
"Cannot register listener \"" + listener.getClass().getCanonicalName() + '.' + method.getName() + "(" + method.getParameterTypes()[0].getCanonicalName() + ")\":",
"\"" + method.getParameterTypes()[0].getCanonicalName() + "\" is not an Event");
}
} else {
LinkedList<String> args = new LinkedList<String>();
for (Class<?> clazz : method.getParameterTypes()) args.add(clazz.getCanonicalName());
plugin.getLogger().error.println(
"Cannot register listener \"" + listener.getClass().getCanonicalName() + '.' + method.getName() + "(" + args.toString().substring(1, args.toString().length() - 1) + ")\":",
((method.getParameterTypes().length > 0) ? "Too many" : "No") + " parameters for method to be executed");
}
}
}
}
}
/**
* Unregister SubEvent Listeners
*
* @param plugin PluginInfo
* @param listeners Listeners
*/
public void removeListener(SubPluginInfo plugin, Object... listeners) {
for (Object listener : listeners) {
if (Util.isNull(plugin, listener)) throw new NullPointerException();
TreeMap<Short, HashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>>> map = new TreeMap<Short, HashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>>>(this.listeners);
for (Short order : map.keySet()) {
for (Class<? extends Event> event : map.get(order).keySet()) {
if (map.get(order).get(event).keySet().contains(plugin) && map.get(order).get(event).get(plugin).keySet().contains(listener)) {
HashMap<Class<? extends Event>, HashMap<SubPluginInfo, HashMap<Object, List<Method>>>> events = this.listeners.get(order);
HashMap<SubPluginInfo, HashMap<Object, List<Method>>> plugins = this.listeners.get(order).get(event);
HashMap<Object, List<Method>> objects = this.listeners.get(order).get(event).get(plugin);
objects.remove(listener);
plugins.put(plugin, objects);
events.put(event, plugins);
this.listeners.put(order, events);
}
}
}
}
}
/**
* Run a SubEvent
*
* @param event SubEvent
*/
public void executeEvent(Event event) {
if (Util.isNull(event)) throw new NullPointerException();
for (Short order : listeners.keySet()) {
if (listeners.get(order).keySet().contains(event.getClass())) {
for (SubPluginInfo plugin : listeners.get(order).get(event.getClass()).keySet()) {
try {
Field pf = Event.class.getDeclaredField("plugin");
pf.setAccessible(true);
pf.set(event, plugin);
pf.setAccessible(false);
} catch (Exception e) {
this.host.log.error.println(e);
}
for (Object listener : listeners.get(order).get(event.getClass()).get(plugin).keySet()) {
for (Method method : listeners.get(order).get(event.getClass()).get(plugin).get(listener)) {
if (!(event instanceof Cancellable) || !((Cancellable) event).isCancelled() || method.getAnnotation(EventHandler.class).override()) {
try {
method.invoke(listener, event);
} catch (InvocationTargetException e) {
plugin.getLogger().error.println("Event listener \"" + listener.getClass().getCanonicalName() + '.' + method.getName() + "(" + event.getClass().getTypeName() + ")\" had an unhandled exception:");
plugin.getLogger().error.println(e.getTargetException());
} catch (IllegalAccessException e) {
plugin.getLogger().error.println("Cannot access method \"" + listener.getClass().getCanonicalName() + '.' + method.getName() + "(" + event.getClass().getTypeName() + ")\"");
plugin.getLogger().error.println(e);
}
}
}
}
}
}
}
try {
Field pf = Event.class.getDeclaredField("plugin");
pf.setAccessible(true);
pf.set(event, null);
pf.setAccessible(false);
} catch (Exception e) {
this.host.log.error.println(e);
}
}
/**
* Gets the current SubServers Lang Channels
*
@ -687,29 +401,11 @@ public final class SubAPI {
}
/**
* Gets the Runtime Directory
* Gets the SubServers App Info
*
* @return Directory
* @return SubServers App Info
*/
public UniversalFile getRuntimeDirectory() {
return host.dir;
}
/**
* Gets the SubServers Version
*
* @return SubServers Version
*/
public Version getAppVersion() {
return host.version;
}
/**
* Gets the SubServers Build Signature
*
* @return SubServers Build Signature (or null if unsigned)
*/
public Version getAppBuild() {
return (ExHost.class.getPackage().getSpecificationTitle() != null)?new Version(ExHost.class.getPackage().getSpecificationTitle()):null;
public PluginInfo getAppInfo() {
return host.info;
}
}

Some files were not shown because too many files have changed in this diff Show More