mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 11:07:41 +00:00
Compare commits
2 Commits
v2.0.2+50e
...
v2.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b1ccd018d | ||
|
|
8f1fd3f1f4 |
@@ -11,7 +11,7 @@ val PLUGIN_NAME = "OriginBlacklist"
|
|||||||
val PLUGIN_IDEN = "originblacklist"
|
val PLUGIN_IDEN = "originblacklist"
|
||||||
val PLUGIN_DOMN = "xyz.webmc"
|
val PLUGIN_DOMN = "xyz.webmc"
|
||||||
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
||||||
val PLUGIN_VERS = "2.0.2"
|
val PLUGIN_VERS = "2.0.3"
|
||||||
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
||||||
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
||||||
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
||||||
|
|||||||
@@ -10,9 +10,13 @@ import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
|||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
import xyz.webmc.originblacklist.base.util.UpdateChecker;
|
import xyz.webmc.originblacklist.base.util.UpdateChecker;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -40,12 +44,11 @@ public final class OriginBlacklist {
|
|||||||
|
|
||||||
private final IOriginBlacklistPlugin plugin;
|
private final IOriginBlacklistPlugin plugin;
|
||||||
private final OriginBlacklistConfig config;
|
private final OriginBlacklistConfig config;
|
||||||
private boolean updateAvailable;
|
private String updateURL;
|
||||||
|
|
||||||
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.config = new OriginBlacklistConfig(plugin);
|
this.config = new OriginBlacklistConfig(plugin);
|
||||||
this.checkForUpdate();
|
|
||||||
plugin.scheduleRepeat(() -> {
|
plugin.scheduleRepeat(() -> {
|
||||||
this.checkForUpdate();
|
this.checkForUpdate();
|
||||||
}, 60, TimeUnit.MINUTES);
|
}, 60, TimeUnit.MINUTES);
|
||||||
@@ -240,7 +243,7 @@ public final class OriginBlacklist {
|
|||||||
player.getName().replaceAll("_", "\\_"),
|
player.getName().replaceAll("_", "\\_"),
|
||||||
player.getOrigin(),
|
player.getOrigin(),
|
||||||
player.getBrand(),
|
player.getBrand(),
|
||||||
player.getAddr(),
|
this.config.get("discord.send_ips").getAsBoolean() ? player.getAddr() : "*\\*CENSORED\\**",
|
||||||
player.getPVN(),
|
player.getPVN(),
|
||||||
userAgent,
|
userAgent,
|
||||||
player.isRewind() ? "YES" : "NO",
|
player.isRewind() ? "YES" : "NO",
|
||||||
@@ -282,13 +285,48 @@ public final class OriginBlacklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final void checkForUpdate() {
|
private final void checkForUpdate() {
|
||||||
CompletableFuture.runAsync(() -> {
|
if (this.config.get("update_checker.enabled").getAsBoolean()) {
|
||||||
this.updateAvailable = UpdateChecker.checkForUpdate(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
CompletableFuture.runAsync(() -> {
|
||||||
this.config.get("update_checker.allow_snapshots").getAsBoolean());
|
this.updateURL = UpdateChecker.checkForUpdate(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
||||||
if (this.updateAvailable) {
|
this.config.get("update_checker.allow_snapshots").getAsBoolean());
|
||||||
this.plugin.log(EnumLogLevel.INFO, "An update is available! Download it at https://github.com/" + PLUGIN_REPO + ".git");
|
if (isNonNull((this.updateURL))) {
|
||||||
}
|
if (!this.config.get("update_checker.auto_update").getAsBoolean()) {
|
||||||
});
|
this.plugin.log(EnumLogLevel.INFO, "An update is available! Download it at " + this.updateURL);
|
||||||
|
} else {
|
||||||
|
final Path jar = this.plugin.getPluginJarPath();
|
||||||
|
final Path bak = jar.resolveSibling(jar.getFileName().toString() + ".bak");
|
||||||
|
final Path tmp = jar.resolveSibling(jar.getFileName().toString() + ".tmp");
|
||||||
|
try {
|
||||||
|
Files.copy(jar, bak, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final URL url = new URL(this.updateURL);
|
||||||
|
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("GET");
|
||||||
|
conn.setConnectTimeout(15000);
|
||||||
|
conn.setReadTimeout(15000);
|
||||||
|
conn.connect();
|
||||||
|
try (final InputStream in = conn.getInputStream()) {
|
||||||
|
Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} finally {
|
||||||
|
conn.disconnect();
|
||||||
|
}
|
||||||
|
Files.move(tmp, jar, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
Files.delete(bak);
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
try {
|
||||||
|
Files.move(bak, jar, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (final Throwable _t) {
|
||||||
|
_t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String getComponentString(final Component comp) {
|
public static final String getComponentString(final Component comp) {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package xyz.webmc.originblacklist.base.command;
|
package xyz.webmc.originblacklist.base.command;
|
||||||
|
|
||||||
public interface CommandContext {
|
public interface CommandContext {
|
||||||
String getPlayerName();
|
public String getPlayerName();
|
||||||
void reply(final String message);
|
public void reply(final String message);
|
||||||
boolean hasPermission(final String permission);
|
public boolean hasPermission(final String permission);
|
||||||
String[] getArgs();
|
public String[] getArgs();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package xyz.webmc.originblacklist.base.command;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ICommand {
|
public interface ICommand {
|
||||||
static final String NO_PERMISSION = "<red>You don't have permission to use this command.</red>";
|
public static final String NO_PERMISSION = "<red>You don't have permission to use this command.</red>";
|
||||||
boolean execute(final CommandContext ctx);
|
public boolean execute(final CommandContext ctx);
|
||||||
List<String> suggest(final CommandContext ctx);
|
public List<String> suggest(final CommandContext ctx);
|
||||||
void usage(final CommandContext ctx);
|
public void usage(final CommandContext ctx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,11 +216,12 @@ public final class OriginBlacklistConfig {
|
|||||||
final Json5Object dobj = new Json5Object();
|
final Json5Object dobj = new Json5Object();
|
||||||
addJSONObj(dobj, "enabled", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(dobj, "enabled", Json5Primitive.fromBoolean(false), null);
|
||||||
addJSONObj(dobj, "webhook_urls", new Json5Array(), null);
|
addJSONObj(dobj, "webhook_urls", new Json5Array(), null);
|
||||||
|
addJSONObj(dobj, "send_ips", Json5Primitive.fromBoolean(true), null);
|
||||||
addJSONObj(obj, "discord", dobj, null);
|
addJSONObj(obj, "discord", dobj, null);
|
||||||
final Json5Object uobj = new Json5Object();
|
final Json5Object uobj = new Json5Object();
|
||||||
addJSONObj(uobj, "enabled", Json5Primitive.fromBoolean(true), null);
|
addJSONObj(uobj, "enabled", Json5Primitive.fromBoolean(true), null);
|
||||||
addJSONObj(uobj, "allow_snapshots", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(uobj, "allow_snapshots", Json5Primitive.fromBoolean(false), null);
|
||||||
addJSONObj(uobj, "auto_update", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(uobj, "auto_update", Json5Primitive.fromBoolean(true), null);
|
||||||
addJSONObj(obj, "update_checker", uobj, null);
|
addJSONObj(obj, "update_checker", uobj, null);
|
||||||
addJSONObj(obj, "bStats", Json5Primitive.fromBoolean(true), null);
|
addJSONObj(obj, "bStats", Json5Primitive.fromBoolean(true), null);
|
||||||
return obj;
|
return obj;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
|||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -12,6 +13,7 @@ import org.semver4j.Semver;
|
|||||||
public interface IOriginBlacklistPlugin {
|
public interface IOriginBlacklistPlugin {
|
||||||
public String getPluginId();
|
public String getPluginId();
|
||||||
public Semver getPluginVersion();
|
public Semver getPluginVersion();
|
||||||
|
public Path getPluginJarPath();
|
||||||
public void log(final EnumLogLevel level, final String txt);
|
public void log(final EnumLogLevel level, final String txt);
|
||||||
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
||||||
public void setMOTD(final Component txt, final OriginBlacklistMOTDEvent event);
|
public void setMOTD(final Component txt, final OriginBlacklistMOTDEvent event);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package xyz.webmc.originblacklist.base.util;
|
package xyz.webmc.originblacklist.base.util;
|
||||||
|
|
||||||
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@@ -15,15 +17,16 @@ import org.semver4j.Semver.VersionDiff;
|
|||||||
public class UpdateChecker {
|
public class UpdateChecker {
|
||||||
private static final Json5 json5 = Json5.builder(builder -> builder.build());
|
private static final Json5 json5 = Json5.builder(builder -> builder.build());
|
||||||
|
|
||||||
public static final boolean checkForUpdate(final String repo, final Semver currentVersion, final boolean allowPreRelease) {
|
public static final String checkForUpdate(final String repo, final Semver currentVersion, final boolean allowPreRelease) {
|
||||||
try {
|
try {
|
||||||
final URL url = new URL("https://api.github.com/repos/" + repo + "/releases");
|
URL url = new URL("https://api.github.com/repos/" + repo + "/releases");
|
||||||
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
conn.setRequestMethod("GET");
|
conn.setRequestMethod("GET");
|
||||||
conn.setConnectTimeout(5000);
|
conn.setConnectTimeout(5000);
|
||||||
conn.setReadTimeout(5000);
|
conn.setReadTimeout(5000);
|
||||||
conn.connect();
|
conn.connect();
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
|
String ret = null;
|
||||||
Json5Element element = json5.parse(reader);
|
Json5Element element = json5.parse(reader);
|
||||||
if (element instanceof Json5Array) {
|
if (element instanceof Json5Array) {
|
||||||
final Json5Array arr = element.getAsJson5Array();
|
final Json5Array arr = element.getAsJson5Array();
|
||||||
@@ -34,16 +37,38 @@ public class UpdateChecker {
|
|||||||
final String tag = obj.get("tag_name").getAsString();
|
final String tag = obj.get("tag_name").getAsString();
|
||||||
final Semver ver = new Semver(tag.substring(1));
|
final Semver ver = new Semver(tag.substring(1));
|
||||||
if (ver.isGreaterThan(currentVersion) && (allowPreRelease || currentVersion.diff(ver) != VersionDiff.BUILD)) {
|
if (ver.isGreaterThan(currentVersion) && (allowPreRelease || currentVersion.diff(ver) != VersionDiff.BUILD)) {
|
||||||
return true;
|
element = obj.get("assets");
|
||||||
|
if (element instanceof Json5Array) {
|
||||||
|
final Json5Array aArr = element.getAsJson5Array();
|
||||||
|
element = aArr.get(0);
|
||||||
|
if (element instanceof Json5Object) {
|
||||||
|
final Json5Object vObj = element.getAsJson5Object();
|
||||||
|
ret = vObj.get("url").getAsString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
return false;
|
if (OriginBlacklist.isNonNull(ret)) {
|
||||||
|
url = new URL(ret);
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("GET");
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
conn.setReadTimeout(5000);
|
||||||
|
conn.connect();
|
||||||
|
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
|
element = json5.parse(reader);
|
||||||
|
if (element instanceof Json5Object) {
|
||||||
|
final Json5Object obj = element.getAsJson5Object();
|
||||||
|
ret = obj.get("browser_download_url").getAsString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
} catch (final Throwable t) {
|
} catch (final Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import xyz.webmc.originblacklist.bukkit.command.OriginBlacklistCommandBukkit;
|
|||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -127,6 +129,11 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
return new Semver(this.getDescription().getVersion());
|
return new Semver(this.getDescription().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Path getPluginJarPath() {
|
||||||
|
return Paths.get(this.getFile().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
@@ -224,7 +231,7 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
||||||
long ms = unit.toMillis((long) period);
|
long ms = unit.toMillis((long) period);
|
||||||
long ticks = Math.max(1L, ms / 50L);
|
long ticks = Math.max(1L, ms / 50L);
|
||||||
Bukkit.getScheduler().runTaskTimer(this, task, ticks, ticks);
|
Bukkit.getScheduler().runTaskTimer(this, task, 0, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
|||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
import xyz.webmc.originblacklist.bungee.command.OriginBlacklistCommandBungee;
|
import xyz.webmc.originblacklist.bungee.command.OriginBlacklistCommandBungee;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -129,6 +131,11 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
return new Semver(this.getDescription().getVersion());
|
return new Semver(this.getDescription().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Path getPluginJarPath() {
|
||||||
|
return Paths.get(this.getFile().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
@@ -188,7 +195,7 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
||||||
this.proxy.getScheduler().schedule(this, task, period, period, unit);
|
this.proxy.getScheduler().schedule(this, task, 0, period, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
|||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
import xyz.webmc.originblacklist.velocity.command.OriginBlacklistCommandVelocity;
|
import xyz.webmc.originblacklist.velocity.command.OriginBlacklistCommandVelocity;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -147,6 +149,15 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
return new Semver(this.plugin.getDescription().getVersion().get());
|
return new Semver(this.plugin.getDescription().getVersion().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Path getPluginJarPath() {
|
||||||
|
try {
|
||||||
|
return Paths.get(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).toAbsolutePath();
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw new RuntimeException("Unable to determine plugin JAR path");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
|
|||||||
Reference in New Issue
Block a user