Update GalaxiEngine

This commit is contained in:
ME1312 2021-06-05 14:16:24 -04:00
parent c6a354fe84
commit 42a73c8372
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
14 changed files with 309 additions and 233 deletions

View File

@ -28,13 +28,13 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -28,14 +28,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -0,0 +1,138 @@
package net.ME1312.SubServers.Bungee.Library;
import net.ME1312.Galaxi.Library.Util;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.regex.Pattern;
/**
* File Scanner Base Class
*/
public abstract class FileScanner {
/**
* Scan a Directory
*
* @param dir Directory
* @param whitelist File Whitelist
*/
protected void scan(File dir, String... whitelist) throws IOException {
List<String> files;
try {
files = Util.reflect(Util.class.getDeclaredMethod("zipsearch", File.class, File.class), null, dir, dir);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalStateException("Cannot access zipsearch()", e);
}
if (files.size() <= 0 || whitelist.length <= 0)
return;
boolean csfs = false;
{
long stamp = Math.round(Math.random() * 100000);
File test1 = new File(dir, '.' + stamp + ".ss_fsc");
File test2 = new File(dir, '.' + stamp + ".SS_FSC");
test1.createNewFile();
if (test2.createNewFile()) {
csfs = true;
test2.delete();
}
test1.delete();
}
LinkedHashMap<Pattern, Boolean> rules = new LinkedHashMap<Pattern, Boolean>();
for (String entry : whitelist) {
boolean mode = !entry.startsWith("!");
if (!mode) entry = entry.substring(1);
String pattern;
if (!entry.startsWith("%")) {
if (entry.startsWith("./"))
entry = entry.substring(1);
StringBuilder rule = new StringBuilder();
if (entry.startsWith("**")) {
entry = entry.substring(2);
rule.append("^.*");
} else if (entry.startsWith("/")) {
rule.append("^");
}
boolean greedyEnding = false;
if (entry.endsWith("**")) {
entry = entry.substring(0, entry.length() - 2);
greedyEnding = true;
} else if (entry.endsWith("/")) {
greedyEnding = true;
}
StringBuilder literal = new StringBuilder();
for (PrimitiveIterator.OfInt i = entry.codePoints().iterator(); i.hasNext(); ) {
int c = i.next();
if ((c == '*' || c == '?' || c == '[') && literal.length() > 0) {
rule.append(Pattern.quote(literal.toString()));
literal = new StringBuilder();
}
switch (c) {
case '\\':
if (i.hasNext()) c = i.next();
literal.appendCodePoint(c);
case '[':
for (boolean escaped = false; i.hasNext() && (c != ']' || escaped); c = i.next()) {
if (c == '\\') escaped = !escaped;
else escaped = false;
literal.appendCodePoint(c);
}
if (c == ']' && literal.length() > 1) {
literal.appendCodePoint(c);
rule.append(literal.toString());
}
literal = new StringBuilder();
break;
case '*':
rule.append("[^/]+");
break;
case '?':
rule.append("[^/]");
break;
default:
literal.appendCodePoint(c);
break;
}
}
if (literal.length() > 0)
rule.append(Pattern.quote(literal.toString()));
if (greedyEnding)
rule.append(".*");
rule.append("$");
pattern = rule.toString();
} else {
pattern = entry.substring(1);
}
if (csfs) rules.put(Pattern.compile(pattern), mode);
else rules.put(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE), mode);
}
for (String file : files) {
boolean act = false;
for (Map.Entry<Pattern, Boolean> rule : rules.entrySet()) {
if (rule.getKey().matcher('/' + file.replace(File.separatorChar, '/')).find()) act = rule.getValue();
}
if (act) act(dir, file);
}
}
/**
* Perform an action on an included file
*
* @param dir Parent Directory
* @param name File Name
*/
protected abstract void act(File dir, String name) throws IOException;
}

View File

@ -10,7 +10,7 @@ import java.util.regex.Pattern;
/**
* File Replacement Scanner
*/
public class ReplacementScanner {
public class ReplacementScanner extends FileScanner {
private final Map<String, String> replacements = new LinkedHashMap<>();
public ReplacementScanner(Map<String, String> replacements) {
@ -44,114 +44,11 @@ public class ReplacementScanner {
* @param whitelist File Whitelist
*/
public void replace(File dir, String... whitelist) throws IOException {
List<String> files;
try {
files = Util.reflect(Util.class.getDeclaredMethod("zipsearch", File.class, File.class), null, dir, dir);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalStateException("Cannot access zipsearch()", e);
}
if (files.size() <= 0 || whitelist.length <= 0)
return;
super.scan(dir, whitelist);
}
boolean csfs = false;
{
long stamp = Math.round(Math.random() * 100000);
File test1 = new File(dir, '.' + stamp + ".ss_fsc");
File test2 = new File(dir, '.' + stamp + ".SS_FSC");
test1.createNewFile();
if (test2.createNewFile()) {
csfs = true;
test2.delete();
}
test1.delete();
}
LinkedHashMap<Pattern, Boolean> rules = new LinkedHashMap<Pattern, Boolean>();
for (String entry : whitelist) {
boolean mode = !entry.startsWith("!");
if (!mode) entry = entry.substring(1);
String pattern;
if (!entry.startsWith("%")) {
if (entry.startsWith("./"))
entry = entry.substring(1);
StringBuilder rule = new StringBuilder();
if (entry.startsWith("**")) {
entry = entry.substring(2);
rule.append("^.*");
} else if (entry.startsWith("/")) {
rule.append("^");
}
boolean greedyEnding = false;
if (entry.endsWith("**")) {
entry = entry.substring(0, entry.length() - 2);
greedyEnding = true;
} else if (entry.endsWith("/")) {
greedyEnding = true;
}
StringBuilder literal = new StringBuilder();
for (PrimitiveIterator.OfInt i = entry.codePoints().iterator(); i.hasNext(); ) {
int c = i.next();
if ((c == '*' || c == '?' || c == '[') && literal.length() > 0) {
rule.append(Pattern.quote(literal.toString()));
literal = new StringBuilder();
}
switch (c) {
case '\\':
if (i.hasNext()) c = i.next();
literal.appendCodePoint(c);
case '[':
for (boolean escaped = false; i.hasNext() && (c != ']' || escaped); c = i.next()) {
if (c == '\\') escaped = !escaped;
else escaped = false;
literal.appendCodePoint(c);
}
if (c == ']' && literal.length() > 1) {
literal.appendCodePoint(c);
rule.append(literal.toString());
}
literal = new StringBuilder();
break;
case '*':
rule.append("[^/]+");
break;
case '?':
rule.append("[^/]");
break;
default:
literal.appendCodePoint(c);
break;
}
}
if (literal.length() > 0)
rule.append(Pattern.quote(literal.toString()));
if (greedyEnding)
rule.append(".*");
rule.append("$");
pattern = rule.toString();
} else {
pattern = entry.substring(1);
}
if (csfs) rules.put(Pattern.compile(pattern), mode);
else rules.put(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE), mode);
}
for (String file : files) {
boolean act = false;
for (Map.Entry<Pattern, Boolean> rule : rules.entrySet()) {
if (rule.getKey().matcher('/' + file.replace(File.separatorChar, '/')).find()) act = rule.getValue();
}
if (act) replaceFile(new File(dir, file));
}
} private void replaceFile(File file) throws IOException {
protected void act(File dir, String name) throws IOException {
File file = new File(dir, name);
FileInputStream stream = new FileInputStream(file);
String string = Util.readAll(new InputStreamReader(stream));
stream.close();

View File

@ -115,8 +115,6 @@ public final class SubCommand extends Command implements TabExecutor {
if (reload == null || !reload.isAlive()) (reload = new Thread(() -> {
if (args.length > 1) {
switch (args[1].toLowerCase()) {
case "*":
case "all":
case "hard":
case "system":
case "subdata":
@ -127,6 +125,8 @@ public final class SubCommand extends Command implements TabExecutor {
Util.isException(() -> player.disconnect(plugin.getTranslation("restart")));
}
plugin.shutdown();
case "*":
case "all":
case "soft":
case "bungee":
case "bungeecord":

View File

@ -46,7 +46,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -55,7 +55,7 @@ public class ObjectPermission {
for (int p = 0; !permitted && p < permissions.length; ++p) {
String perm = permissions[p];
if (perm != null) {
// Check all proxies & individual proxies permission
// Check all objects & individual objects permission
permitted = object.hasPermission(perm.replace("%", "*"))
|| object.hasPermission(perm.replace("%", string.toLowerCase()));
}

View File

@ -18,7 +18,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -28,7 +28,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -31,14 +31,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUI</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

View File

@ -0,0 +1,142 @@
package net.ME1312.SubServers.Host.Library;
import net.ME1312.Galaxi.Library.Util;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.PrimitiveIterator;
import java.util.regex.Pattern;
/**
* File Scanner Base Class
*/
public abstract class FileScanner {
/**
* Scan a Directory
*
* @param dir Directory
* @param whitelist File Whitelist
*/
protected void scan(File dir, String... whitelist) throws IOException {
List<String> files;
try {
files = Util.reflect(Util.class.getDeclaredMethod("zipsearch", File.class, File.class), null, dir, dir);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalStateException("Cannot access zipsearch()", e);
}
if (files.size() <= 0 || whitelist.length <= 0)
return;
boolean csfs = false;
{
long stamp = Math.round(Math.random() * 100000);
File test1 = new File(dir, '.' + stamp + ".ss_fsc");
File test2 = new File(dir, '.' + stamp + ".SS_FSC");
test1.createNewFile();
if (test2.createNewFile()) {
csfs = true;
test2.delete();
}
test1.delete();
}
LinkedHashMap<Pattern, Boolean> rules = new LinkedHashMap<Pattern, Boolean>();
for (String entry : whitelist) {
boolean mode = !entry.startsWith("!");
if (!mode) entry = entry.substring(1);
String pattern;
if (!entry.startsWith("%")) {
if (entry.startsWith("./"))
entry = entry.substring(1);
StringBuilder rule = new StringBuilder();
if (entry.startsWith("**")) {
entry = entry.substring(2);
rule.append("^.*");
} else if (entry.startsWith("/")) {
rule.append("^");
}
boolean greedyEnding = false;
if (entry.endsWith("**")) {
entry = entry.substring(0, entry.length() - 2);
greedyEnding = true;
} else if (entry.endsWith("/")) {
greedyEnding = true;
}
StringBuilder literal = new StringBuilder();
for (PrimitiveIterator.OfInt i = entry.codePoints().iterator(); i.hasNext(); ) {
int c = i.next();
if ((c == '*' || c == '?' || c == '[') && literal.length() > 0) {
rule.append(Pattern.quote(literal.toString()));
literal = new StringBuilder();
}
switch (c) {
case '\\':
if (i.hasNext()) c = i.next();
literal.appendCodePoint(c);
case '[':
for (boolean escaped = false; i.hasNext() && (c != ']' || escaped); c = i.next()) {
if (c == '\\') escaped = !escaped;
else escaped = false;
literal.appendCodePoint(c);
}
if (c == ']' && literal.length() > 1) {
literal.appendCodePoint(c);
rule.append(literal.toString());
}
literal = new StringBuilder();
break;
case '*':
rule.append("[^/]+");
break;
case '?':
rule.append("[^/]");
break;
default:
literal.appendCodePoint(c);
break;
}
}
if (literal.length() > 0)
rule.append(Pattern.quote(literal.toString()));
if (greedyEnding)
rule.append(".*");
rule.append("$");
pattern = rule.toString();
} else {
pattern = entry.substring(1);
}
if (csfs) rules.put(Pattern.compile(pattern), mode);
else rules.put(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE), mode);
}
for (String file : files) {
boolean act = false;
for (Map.Entry<Pattern, Boolean> rule : rules.entrySet()) {
if (rule.getKey().matcher('/' + file.replace(File.separatorChar, '/')).find()) act = rule.getValue();
}
if (act) act(dir, file);
}
}
/**
* Perform an action on an included file
*
* @param dir Parent Directory
* @param name File Name
*/
protected abstract void act(File dir, String name) throws IOException;
}

View File

@ -3,14 +3,12 @@ package net.ME1312.SubServers.Host.Library;
import net.ME1312.Galaxi.Library.Util;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.regex.Pattern;
/**
* File Replacement Scanner
*/
public class ReplacementScanner {
public class ReplacementScanner extends FileScanner {
private final Map<String, String> replacements = new LinkedHashMap<>();
public ReplacementScanner(Map<String, String> replacements) {
@ -44,114 +42,11 @@ public class ReplacementScanner {
* @param whitelist File Whitelist
*/
public void replace(File dir, String... whitelist) throws IOException {
List<String> files;
try {
files = Util.reflect(Util.class.getDeclaredMethod("zipsearch", File.class, File.class), null, dir, dir);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalStateException("Cannot access zipsearch()", e);
}
if (files.size() <= 0 || whitelist.length <= 0)
return;
super.scan(dir, whitelist);
}
boolean csfs = false;
{
long stamp = Math.round(Math.random() * 100000);
File test1 = new File(dir, '.' + stamp + ".ss_fsc");
File test2 = new File(dir, '.' + stamp + ".SS_FSC");
test1.createNewFile();
if (test2.createNewFile()) {
csfs = true;
test2.delete();
}
test1.delete();
}
LinkedHashMap<Pattern, Boolean> rules = new LinkedHashMap<Pattern, Boolean>();
for (String entry : whitelist) {
boolean mode = !entry.startsWith("!");
if (!mode) entry = entry.substring(1);
String pattern;
if (!entry.startsWith("%")) {
if (entry.startsWith("./"))
entry = entry.substring(1);
StringBuilder rule = new StringBuilder();
if (entry.startsWith("**")) {
entry = entry.substring(2);
rule.append("^.*");
} else if (entry.startsWith("/")) {
rule.append("^");
}
boolean greedyEnding = false;
if (entry.endsWith("**")) {
entry = entry.substring(0, entry.length() - 2);
greedyEnding = true;
} else if (entry.endsWith("/")) {
greedyEnding = true;
}
StringBuilder literal = new StringBuilder();
for (PrimitiveIterator.OfInt i = entry.codePoints().iterator(); i.hasNext(); ) {
int c = i.next();
if ((c == '*' || c == '?' || c == '[') && literal.length() > 0) {
rule.append(Pattern.quote(literal.toString()));
literal = new StringBuilder();
}
switch (c) {
case '\\':
if (i.hasNext()) c = i.next();
literal.appendCodePoint(c);
case '[':
for (boolean escaped = false; i.hasNext() && (c != ']' || escaped); c = i.next()) {
if (c == '\\') escaped = !escaped;
else escaped = false;
literal.appendCodePoint(c);
}
if (c == ']' && literal.length() > 1) {
literal.appendCodePoint(c);
rule.append(literal.toString());
}
literal = new StringBuilder();
break;
case '*':
rule.append("[^/]+");
break;
case '?':
rule.append("[^/]");
break;
default:
literal.appendCodePoint(c);
break;
}
}
if (literal.length() > 0)
rule.append(Pattern.quote(literal.toString()));
if (greedyEnding)
rule.append(".*");
rule.append("$");
pattern = rule.toString();
} else {
pattern = entry.substring(1);
}
if (csfs) rules.put(Pattern.compile(pattern), mode);
else rules.put(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE), mode);
}
for (String file : files) {
boolean act = false;
for (Map.Entry<Pattern, Boolean> rule : rules.entrySet()) {
if (rule.getKey().matcher('/' + file.replace(File.separatorChar, '/')).find()) act = rule.getValue();
}
if (act) replaceFile(new File(dir, file));
}
} private void replaceFile(File file) throws IOException {
protected void act(File dir, String name) throws IOException {
File file = new File(dir, name);
FileInputStream stream = new FileInputStream(file);
String string = Util.readAll(new InputStreamReader(stream));
stream.close();

View File

@ -1,5 +1,6 @@
package net.ME1312.SubServers.Host;
import net.ME1312.Galaxi.Command.CommandProcessor.Status;
import net.ME1312.Galaxi.Engine.CommandParser;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.AsyncConsolidator;
@ -59,7 +60,10 @@ public class SubCommand {
args.removeFirst();
CommandParser console = GalaxiEngine.getInstance().getCommandProcessor();
console.runCommand(sender, console.escapeCommand(rargs[0], args.toArray(new String[0])));
String command = console.escapeCommand(rargs[0], args.toArray(new String[0]));
if (console.runCommand(sender, command) == Status.UNKNOWN) {
sender.sendMessage("Unknown Command: " + command);
}
} else {
sender.sendMessage("Usage: /" + label + " <Command> [Args...]");
}

View File

@ -28,14 +28,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>21w15b</version>
<version>21w23c</version>
<scope>provided</scope>
</dependency>
<dependency>