Dev/remove standalone #86
No files matched your search
@@ -1,31 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshot or app console output**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Whole command used to start the app**
|
||||
Please insert the whole command you used to start the app.
|
||||
Censoring ip address is recommended.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
+47
-4
@@ -1,18 +1,27 @@
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
id "io.github.goooler.shadow" version "8.1.7"
|
||||
}
|
||||
|
||||
group 'me.creepermaxcz.mc-bots'
|
||||
group 'com.shanebeestudios'
|
||||
version '1.2.9'
|
||||
|
||||
sourceCompatibility = 17
|
||||
targetCompatibility = 17
|
||||
compileJava {
|
||||
sourceCompatibility = '17'
|
||||
targetCompatibility = '17'
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven { url 'https://repo.opencollab.dev/maven-snapshots/' }
|
||||
maven { url 'https://repo.opencollab.dev/maven-releases/' }
|
||||
|
||||
// Paper
|
||||
maven { url 'https://repo.papermc.io/repository/maven-public/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -23,14 +32,48 @@ dependencies {
|
||||
implementation 'dnsjava:dnsjava:3.4.3'
|
||||
implementation 'org.slf4j:slf4j-nop:1.7.32'
|
||||
implementation 'org.jline:jline:3.25.0'
|
||||
|
||||
// Paper
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
|
||||
|
||||
// Command Api
|
||||
implementation("dev.jorel:commandapi-bukkit-shade:9.3.0")
|
||||
}
|
||||
|
||||
processResources {
|
||||
filter ReplaceTokens, tokens: ["version": project.version]
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'com.shanebeestudios.mcbots.standalone.Main', 'Manifest-Version': this.version
|
||||
attributes 'Main-Class': 'com.shanebeestudios.mcbots.standalone.Main', 'Manifest-Version': project.version
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
from {
|
||||
configurations.runtimeClasspath.filter { it.exists() }.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
dependsOn(jar)
|
||||
archiveClassifier = null
|
||||
relocate("dev.jorel.commandapi", "com.shanebeestudios.mcbots.api.commandapi")
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
|
||||
tasks.withType(JavaCompile).tap {
|
||||
configureEach {
|
||||
options.compilerArgs.add("-Xlint:unchecked")
|
||||
options.compilerArgs.add("-Xlint:deprecation")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run task to build jar to another spot
|
||||
tasks.register('server', Copy) {
|
||||
from shadowJar
|
||||
// Change this to wherever you want your jar to build
|
||||
into '/Users/ShaneBee/Desktop/Server/Skript/1-20-4/plugins'
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,5 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -55,7 +55,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -80,13 +80,11 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -133,22 +131,29 @@ location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
@@ -205,6 +214,12 @@ set -- \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
||||
Vendored
+9
-6
@@ -14,7 +14,7 @@
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@@ -25,7 +25,8 @@
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
rootProject.name = 'mc-bots'
|
||||
|
||||
+23
-3
@@ -3,13 +3,14 @@ package com.shanebeestudios.mcbots.api;
|
||||
import com.shanebeestudios.mcbots.api.timer.GravityTimer;
|
||||
import com.shanebeestudios.mcbots.api.generator.NickGenerator;
|
||||
import com.shanebeestudios.mcbots.bot.Bot;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class Loader {
|
||||
public abstract class BotManager {
|
||||
|
||||
// Fields
|
||||
private final Info info;
|
||||
@@ -18,7 +19,7 @@ public abstract class Loader {
|
||||
protected NickGenerator nickGenerator;
|
||||
protected final GravityTimer gravityTimer;
|
||||
|
||||
public Loader(Info info) {
|
||||
public BotManager(Info info) {
|
||||
this.info = info;
|
||||
this.inetAddr = createInetAddress();
|
||||
this.nickGenerator = new NickGenerator(info.getNickPath(), info.getNickPrefix(), info.isUseRealNicknames());
|
||||
@@ -51,6 +52,25 @@ public abstract class Loader {
|
||||
return this.nickGenerator;
|
||||
}
|
||||
|
||||
public abstract void removeBot(Bot bot);
|
||||
public void removeBot(Bot bot) {
|
||||
this.bots.remove(bot);
|
||||
}
|
||||
|
||||
public void disconnectBot(Bot bot) {
|
||||
bot.disconnect();
|
||||
this.bots.remove(bot);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Bot findBotByName(String text) {
|
||||
for (Bot bot : this.getBots()) {
|
||||
// Starts with and ignore case
|
||||
// https://stackoverflow.com/a/38947571/11787611
|
||||
if (bot.getNickname().regionMatches(true, 0, text, 0, text.length())) {
|
||||
return bot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,11 +5,11 @@ import java.util.ArrayList;
|
||||
public abstract class Info {
|
||||
|
||||
protected int autoRespawnDelay;
|
||||
protected boolean minimal;
|
||||
protected boolean minimal = false;
|
||||
protected boolean mostMinimal = false;
|
||||
protected boolean useRealNicknames;
|
||||
protected String nickPath;
|
||||
protected String nickPrefix;
|
||||
protected String nickPath = null;
|
||||
protected String nickPrefix = "";
|
||||
protected String address;
|
||||
protected int port;
|
||||
protected boolean hasGravity;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.shanebeestudios.mcbots.api.generator;
|
||||
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jline.utils.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -36,9 +37,14 @@ public class NickGenerator {
|
||||
if (nicksCount == 0) {
|
||||
Logger.error("No valid nicknames loaded");
|
||||
System.exit(1);
|
||||
} else {
|
||||
Logger.info("Loaded %s nicknames", this.linesSize);
|
||||
}
|
||||
} else {
|
||||
if (useRealNicknames && this.lines == null) loadLines();
|
||||
if (useRealNicknames && this.lines == null) {
|
||||
loadLines();
|
||||
Logger.info("Loaded %s nicknames", this.linesSize);
|
||||
}
|
||||
this.real = useRealNicknames;
|
||||
}
|
||||
this.nickLength = DEFAULT_NICK_LENGTH - prefix.length();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.shanebeestudios.mcbots.api.generator;
|
||||
|
||||
import com.github.steveice10.packetlib.ProxyInfo;
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.shanebeestudios.mcbots.api.timer;
|
||||
|
||||
import com.shanebeestudios.mcbots.bot.Bot;
|
||||
import com.shanebeestudios.mcbots.api.Loader;
|
||||
import com.shanebeestudios.mcbots.api.BotManager;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@@ -9,17 +9,17 @@ import java.util.TimerTask;
|
||||
public class GravityTimer {
|
||||
|
||||
private final Timer timer = new Timer();
|
||||
private final Loader loader;
|
||||
private final BotManager botManager;
|
||||
|
||||
public GravityTimer(Loader loader) {
|
||||
this.loader = loader;
|
||||
public GravityTimer(BotManager botManager) {
|
||||
this.botManager = botManager;
|
||||
}
|
||||
|
||||
public void startTimer() {
|
||||
this.timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
GravityTimer.this.loader.getBots().forEach(Bot::fallDown);
|
||||
GravityTimer.this.botManager.getBots().forEach(Bot::fallDown);
|
||||
}
|
||||
}, 1000L, 50L);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.diogonunes.jcolor.Attribute;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
@@ -21,6 +22,7 @@ import java.util.Map;
|
||||
|
||||
import static com.diogonunes.jcolor.Ansi.colorize;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Utils {
|
||||
|
||||
private static JsonObject lang;
|
||||
@@ -30,12 +32,11 @@ public class Utils {
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.append(parseColor(message, colored));
|
||||
for (Component child : message.children()) {
|
||||
if (child instanceof TextComponent) {
|
||||
text.append(getFullText((TextComponent) child, colored));
|
||||
} else if (child instanceof TranslatableComponent) {
|
||||
text.append(translate((TranslatableComponent) child));
|
||||
if (child instanceof TextComponent textComponent) {
|
||||
text.append(getFullText(textComponent, colored));
|
||||
} else if (child instanceof TranslatableComponent translatableComponent) {
|
||||
text.append(translate(translatableComponent));
|
||||
}
|
||||
|
||||
}
|
||||
return text.toString();
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.shanebeestudios.mcbots.api.util.logging;
|
||||
|
||||
public abstract class BaseLogger {
|
||||
|
||||
public abstract void log(String prefix, String message);
|
||||
|
||||
public abstract void error(String error);
|
||||
|
||||
public abstract void error(Exception e);
|
||||
|
||||
public abstract void info(String format, Object... objects);
|
||||
|
||||
public abstract void info(String... message);
|
||||
|
||||
public abstract void info();
|
||||
|
||||
public abstract void warn(String... warning);
|
||||
|
||||
public abstract void warn();
|
||||
|
||||
public abstract void chat(String... chat);
|
||||
|
||||
public abstract void critical(Exception e);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.shanebeestudios.mcbots.api.util.logging;
|
||||
|
||||
import com.shanebeestudios.mcbots.plugin.McBotPlugin;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Logger {
|
||||
|
||||
private static BaseLogger INSTANCE = new StandaloneLogger();
|
||||
|
||||
public static void setupBukkitLogging(McBotPlugin plugin) {
|
||||
INSTANCE = new PluginLogger(plugin);
|
||||
}
|
||||
|
||||
public static void error(String error) {
|
||||
INSTANCE.error(error);
|
||||
}
|
||||
|
||||
public static void error(Exception e) {
|
||||
INSTANCE.error(e);
|
||||
}
|
||||
|
||||
public static void info(String format, Object... objects) {
|
||||
INSTANCE.info(format, objects);
|
||||
}
|
||||
|
||||
public static void info(String... message) {
|
||||
INSTANCE.info(message);
|
||||
}
|
||||
|
||||
public static void info() {
|
||||
INSTANCE.info();
|
||||
}
|
||||
|
||||
public static void warn(String... warning) {
|
||||
INSTANCE.warn(warning);
|
||||
}
|
||||
|
||||
public static void warn() {
|
||||
INSTANCE.warn();
|
||||
}
|
||||
|
||||
public static void chat(String... chat) {
|
||||
INSTANCE.chat(chat);
|
||||
}
|
||||
|
||||
public static void critical(Exception e) {
|
||||
INSTANCE.critical(e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.shanebeestudios.mcbots.api.util.logging;
|
||||
|
||||
import com.shanebeestudios.mcbots.plugin.McBotPlugin;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PluginLogger extends BaseLogger {
|
||||
|
||||
private static final String PREFIX = "&7[&bMc&3Bot&7]";
|
||||
private static final String PREFIX_ERROR = "&7[&bMc&3Bot &cERROR&7]";
|
||||
private static final Pattern HEX_PATTERN = Pattern.compile("<#([A-Fa-f\\d]){6}>");
|
||||
|
||||
@SuppressWarnings("deprecation") // Paper deprecation
|
||||
public static String getColString(String string) {
|
||||
Matcher matcher = HEX_PATTERN.matcher(string);
|
||||
while (matcher.find()) {
|
||||
final ChatColor hexColor = ChatColor.of(matcher.group().substring(1, matcher.group().length() - 1));
|
||||
final String before = string.substring(0, matcher.start());
|
||||
final String after = string.substring(matcher.end());
|
||||
string = before + hexColor + after;
|
||||
matcher = HEX_PATTERN.matcher(string);
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
|
||||
private final Logger bukkitLogger;
|
||||
|
||||
public PluginLogger(McBotPlugin plugin) {
|
||||
this.bukkitLogger = plugin.getLogger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String prefix, String message) {
|
||||
String string = getColString(prefix + " " + message);
|
||||
Bukkit.getConsoleSender().sendMessage(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String error) {
|
||||
log(PREFIX_ERROR, "&c" + error);
|
||||
}
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
@Override
|
||||
public void error(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object... objects) {
|
||||
log(PREFIX, "&7" + String.format(format, objects));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String... message) {
|
||||
log(PREFIX, "&7" + String.join(" ", message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info() {
|
||||
log(PREFIX, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String... warning) {
|
||||
this.bukkitLogger.warning(String.join(" ", warning));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn() {
|
||||
this.bukkitLogger.warning("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chat(String... chat) {
|
||||
log("[CHAT]", String.join(" ", chat));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void critical(Exception e) {
|
||||
error(e);
|
||||
}
|
||||
|
||||
}
|
||||
+16
-11
@@ -1,48 +1,53 @@
|
||||
package com.shanebeestudios.mcbots.api.util;
|
||||
package com.shanebeestudios.mcbots.api.util.logging;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class Logger {
|
||||
public class StandaloneLogger extends BaseLogger {
|
||||
|
||||
private static final SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
public static void log(String prefix, String message) {
|
||||
public void log(String prefix, String message) {
|
||||
System.out.println("\r[" + formatter.format(new Date()) + " " + prefix + "] " + message);
|
||||
//System.out.print(StandaloneLoader.getInstance().getPrompt() + "> ");
|
||||
}
|
||||
|
||||
public static void error(String error) {
|
||||
public void error(String error) {
|
||||
log("ERROR", error);
|
||||
}
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public static void error(Exception e) {
|
||||
public void error(Exception e) {
|
||||
log("ERROR", "");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public static void info(String... message) {
|
||||
@Override
|
||||
public void info(String format, Object... objects) {
|
||||
log("INFO", String.format(format, objects));
|
||||
}
|
||||
|
||||
public void info(String... message) {
|
||||
log("INFO", String.join(" ", message));
|
||||
}
|
||||
|
||||
public static void info() {
|
||||
public void info() {
|
||||
log("INFO", "");
|
||||
}
|
||||
|
||||
public static void warn(String... warning) {
|
||||
public void warn(String... warning) {
|
||||
log("WARN", String.join(" ", warning));
|
||||
}
|
||||
|
||||
public static void warn() {
|
||||
public void warn() {
|
||||
log("WARN", "");
|
||||
}
|
||||
|
||||
public static void chat(String... chat) {
|
||||
public void chat(String... chat) {
|
||||
log("CHAT", String.join(" ", chat));
|
||||
}
|
||||
|
||||
public static void critical(Exception e) {
|
||||
public void critical(Exception e) {
|
||||
error(e);
|
||||
System.exit(1);
|
||||
}
|
||||
@@ -11,11 +11,10 @@ import com.github.steveice10.packetlib.ProxyInfo;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import com.shanebeestudios.mcbots.api.Loader;
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
import com.shanebeestudios.mcbots.api.BotManager;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
import com.shanebeestudios.mcbots.listener.ClientListener;
|
||||
import com.shanebeestudios.mcbots.listener.MessageListener;
|
||||
import com.shanebeestudios.mcbots.standalone.StandaloneLoader;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.time.Instant;
|
||||
@@ -25,7 +24,7 @@ import java.util.Collections;
|
||||
public class Bot {
|
||||
|
||||
private final MinecraftProtocol protocol;
|
||||
private final Loader loader;
|
||||
private final BotManager botManager;
|
||||
private final String nickname;
|
||||
private final Session client;
|
||||
private boolean hasMainListener;
|
||||
@@ -33,8 +32,8 @@ public class Bot {
|
||||
private boolean connected;
|
||||
private boolean manualDisconnecting = false;
|
||||
|
||||
public Bot(StandaloneLoader loader, String nickname, InetSocketAddress address, ProxyInfo proxy) {
|
||||
this.loader = loader;
|
||||
public Bot(BotManager botManager, String nickname, InetSocketAddress address, ProxyInfo proxy) {
|
||||
this.botManager = botManager;
|
||||
this.nickname = nickname;
|
||||
|
||||
Logger.info("Creating bot", nickname);
|
||||
@@ -42,8 +41,8 @@ public class Bot {
|
||||
this.client = new TcpClientSession(address.getHostString(), address.getPort(), this.protocol, proxy);
|
||||
}
|
||||
|
||||
public Bot(StandaloneLoader loader, AuthenticationService authService, InetSocketAddress address, ProxyInfo proxy) {
|
||||
this.loader = loader;
|
||||
public Bot(BotManager botManager, AuthenticationService authService, InetSocketAddress address, ProxyInfo proxy) {
|
||||
this.botManager = botManager;
|
||||
this.nickname = authService.getUsername();
|
||||
|
||||
Logger.info("Creating bot", nickname);
|
||||
@@ -60,15 +59,15 @@ public class Bot {
|
||||
*/
|
||||
public void connect() {
|
||||
new Thread(() -> {
|
||||
if (!this.loader.getInfoBase().isMinimal()) {
|
||||
if (!this.botManager.getInfoBase().isMinimal()) {
|
||||
this.client.addListener(new ClientListener(this));
|
||||
}
|
||||
this.client.connect();
|
||||
}).start();;
|
||||
}).start();
|
||||
}
|
||||
|
||||
public Loader getLoader() {
|
||||
return this.loader;
|
||||
public BotManager getBotManager() {
|
||||
return this.botManager;
|
||||
}
|
||||
|
||||
public Session getClient() {
|
||||
@@ -102,10 +101,7 @@ public class Bot {
|
||||
// Send command
|
||||
packet = new ServerboundChatCommandPacket(text.substring(1), timeStamp, 0L, Collections.emptyList(), 0, bitSet);
|
||||
} else {
|
||||
// Send chat message
|
||||
// From 1.19.1 or 1.19, the ServerboundChatPacket needs timestamp, salt and signed signature to generate packet.
|
||||
// tmpSignature will provide an empty byte array that can pretend it as signature.
|
||||
// salt is set 0 since this is offline server and nobody will check it.
|
||||
// Send chat
|
||||
packet = new ServerboundChatPacket(text, timeStamp, 0L, null, 0, bitSet);
|
||||
}
|
||||
this.client.send(packet);
|
||||
@@ -117,7 +113,7 @@ public class Bot {
|
||||
|
||||
public void registerMainListener() {
|
||||
this.hasMainListener = true;
|
||||
if (this.loader.getInfoBase().isMinimal()) return;
|
||||
if (this.botManager.getInfoBase().isMinimal()) return;
|
||||
this.client.addListener(new MessageListener(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.shanebeestudios.mcbots.bot;
|
||||
|
||||
import com.github.steveice10.mc.auth.service.AuthenticationService;
|
||||
import com.github.steveice10.packetlib.ProxyInfo;
|
||||
import com.shanebeestudios.mcbots.standalone.StandaloneLoader;
|
||||
import com.shanebeestudios.mcbots.standalone.StandaloneBotManager;
|
||||
import com.shanebeestudios.mcbots.standalone.StandaloneInfo;
|
||||
import com.shanebeestudios.mcbots.api.generator.NickGenerator;
|
||||
import com.shanebeestudios.mcbots.api.generator.ProxyGenerator;
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
@@ -14,7 +14,7 @@ import java.util.Random;
|
||||
|
||||
public class BotLoader {
|
||||
|
||||
private final StandaloneLoader standaloneLoader;
|
||||
private final StandaloneBotManager standaloneLoader;
|
||||
private final StandaloneInfo standaloneInfo;
|
||||
private final int delayMin;
|
||||
private final int delayMax;
|
||||
@@ -22,7 +22,7 @@ public class BotLoader {
|
||||
private int triedToConnect = 0;
|
||||
private int proxyIndex = 0;
|
||||
|
||||
public BotLoader(StandaloneLoader standaloneLoader) {
|
||||
public BotLoader(StandaloneBotManager standaloneLoader) {
|
||||
this.standaloneLoader = standaloneLoader;
|
||||
this.standaloneInfo = standaloneLoader.getMainInfo();
|
||||
this.delayMin = this.standaloneInfo.getDelayMin();
|
||||
|
||||
@@ -2,45 +2,61 @@ package com.shanebeestudios.mcbots.listener;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.UnexpectedEncryptionException;
|
||||
import com.github.steveice10.mc.protocol.data.game.ClientCommand;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.RespawnScreenValue;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatKillPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundGameEventPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.shanebeestudios.mcbots.api.Loader;
|
||||
import com.shanebeestudios.mcbots.api.BotManager;
|
||||
import com.shanebeestudios.mcbots.api.util.Utils;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
import com.shanebeestudios.mcbots.bot.Bot;
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class ClientListener extends SessionAdapter {
|
||||
|
||||
private final Bot bot;
|
||||
private final Session client;
|
||||
private final Loader loader;
|
||||
private final BotManager botManager;
|
||||
private final ArrayList<String> joinMessages;
|
||||
private final int autoRespawnDelay;
|
||||
private int autoRespawnDelay;
|
||||
|
||||
public ClientListener(Bot bot) {
|
||||
this.bot = bot;
|
||||
this.client = bot.getClient();
|
||||
this.loader = bot.getLoader();
|
||||
this.joinMessages = this.loader.getInfoBase().getJoinMessages();
|
||||
this.autoRespawnDelay = this.loader.getInfoBase().getAutoRespawnDelay();
|
||||
this.botManager = bot.getBotManager();
|
||||
this.joinMessages = this.botManager.getInfoBase().getJoinMessages();
|
||||
this.autoRespawnDelay = this.botManager.getInfoBase().getAutoRespawnDelay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
if (packet instanceof ClientboundGameEventPacket gameEventPacket) {
|
||||
if (gameEventPacket.getNotification() == GameEvent.ENABLE_RESPAWN_SCREEN) {
|
||||
RespawnScreenValue value = (RespawnScreenValue) gameEventPacket.getValue();
|
||||
if (value == RespawnScreenValue.IMMEDIATE_RESPAWN) {
|
||||
this.autoRespawnDelay = 0;
|
||||
} else {
|
||||
this.autoRespawnDelay = this.botManager.getInfoBase().getAutoRespawnDelay();
|
||||
}
|
||||
}
|
||||
} else if (packet instanceof ClientboundLoginPacket loginPacket) {
|
||||
if (!loginPacket.isEnableRespawnScreen()) {
|
||||
this.autoRespawnDelay = 0;
|
||||
}
|
||||
this.bot.setConnected(true);
|
||||
Logger.info(this.bot.getNickname() + " connected");
|
||||
|
||||
@@ -78,21 +94,16 @@ public class ClientListener extends SessionAdapter {
|
||||
|
||||
// Do not write disconnect reason if disconnected by command
|
||||
if (!this.bot.isManualDisconnecting()) {
|
||||
// Fix broken reason string by finding the content with regex
|
||||
Pattern pattern = Pattern.compile("content=\"(.*?)\"");
|
||||
Matcher matcher = pattern.matcher(String.valueOf(event.getReason()));
|
||||
|
||||
StringBuilder reason = new StringBuilder();
|
||||
while (matcher.find()) {
|
||||
reason.append(matcher.group(1));
|
||||
Component reason = event.getReason();
|
||||
if (reason != null) {
|
||||
String reasonText = Utils.getFullText((TextComponent) reason, true);
|
||||
Logger.info("Reason: " + reasonText);
|
||||
}
|
||||
|
||||
Logger.info(" -> " + reason);
|
||||
|
||||
if (event.getCause() != null) {
|
||||
event.getCause().printStackTrace();
|
||||
|
||||
if (event.getCause() instanceof UnexpectedEncryptionException) {
|
||||
Throwable cause = event.getCause();
|
||||
if (cause != null) {
|
||||
cause.printStackTrace();
|
||||
if (cause instanceof UnexpectedEncryptionException) {
|
||||
Logger.warn("Server is running in online (premium) mode. Please use the -o option to use online mode bot.");
|
||||
System.exit(1);
|
||||
}
|
||||
@@ -100,8 +111,7 @@ public class ClientListener extends SessionAdapter {
|
||||
Logger.info();
|
||||
}
|
||||
|
||||
this.loader.removeBot(this.bot);
|
||||
|
||||
this.botManager.removeBot(this.bot);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.github.steveice10.packetlib.event.session.PacketErrorEvent;
|
||||
import com.github.steveice10.packetlib.event.session.PacketSendingEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionListener;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
import com.shanebeestudios.mcbots.standalone.StandaloneInfo;
|
||||
import com.shanebeestudios.mcbots.bot.Bot;
|
||||
import com.shanebeestudios.mcbots.api.util.Utils;
|
||||
@@ -23,7 +23,7 @@ public class MessageListener implements SessionListener {
|
||||
private final boolean coloredChat;
|
||||
|
||||
public MessageListener(Bot bot) {
|
||||
this.coloredChat = !(bot.getLoader().getInfoBase() instanceof StandaloneInfo standaloneInfo) || standaloneInfo.isColoredChat();
|
||||
this.coloredChat = !(bot.getBotManager().getInfoBase() instanceof StandaloneInfo standaloneInfo) || standaloneInfo.isColoredChat();
|
||||
Logger.info("MessageListener registered for: " + bot.getNickname());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.shanebeestudios.mcbots.plugin;
|
||||
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
import com.shanebeestudios.mcbots.plugin.command.Command;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.CommandAPIBukkitConfig;
|
||||
import dev.jorel.commandapi.exceptions.UnsupportedVersionException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class McBotPlugin extends JavaPlugin {
|
||||
|
||||
private static McBotPlugin instance;
|
||||
private boolean commandApiCanLoad;
|
||||
private PluginInfo pluginInfo;
|
||||
private PluginBotManager pluginBotManager;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
try {
|
||||
CommandAPI.onLoad(new CommandAPIBukkitConfig(this).verboseOutput(false));
|
||||
this.commandApiCanLoad = true;
|
||||
} catch (UnsupportedVersionException ignore) {
|
||||
this.commandApiCanLoad = false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onEnable() {
|
||||
long start = System.currentTimeMillis();
|
||||
instance = this;
|
||||
Logger.setupBukkitLogging(this);
|
||||
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
if (!commandApiCanLoad) {
|
||||
Logger.error("CommandAPI could not be loaded"); // TODO better message
|
||||
pluginManager.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Bukkit.getOnlineMode()) {
|
||||
Logger.error("This plugin will only work in offline mode!");
|
||||
pluginManager.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
setupBotLogic();
|
||||
setupCommand();
|
||||
|
||||
long finish = System.currentTimeMillis() - start;
|
||||
String version = getDescription().getVersion();
|
||||
Logger.info("&aSuccessfully enabled v%s&7 in &b%s ms", version, finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
CommandAPI.onDisable();
|
||||
}
|
||||
|
||||
private void setupBotLogic() {
|
||||
this.pluginInfo = new PluginInfo();
|
||||
this.pluginBotManager = new PluginBotManager(this.pluginInfo);
|
||||
}
|
||||
|
||||
private void setupCommand() {
|
||||
new Command(this);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
|
||||
}
|
||||
|
||||
// Getters
|
||||
public static McBotPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public PluginInfo getPluginInfo() {
|
||||
return this.pluginInfo;
|
||||
}
|
||||
|
||||
public PluginBotManager getPluginBotManager() {
|
||||
return this.pluginBotManager;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.shanebeestudios.mcbots.plugin;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private final McBotPlugin plugin;
|
||||
private final BukkitScheduler scheduler = Bukkit.getScheduler();
|
||||
|
||||
private final Map<UUID,PlayerProfile> profileMap = new HashMap<>();
|
||||
|
||||
public PlayerListener(McBotPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onPreJoin(AsyncPlayerPreLoginEvent event) {
|
||||
String name = event.getName();
|
||||
|
||||
String uuidString = nameToUUID(name);
|
||||
if (uuidString != null) {
|
||||
UUID uuid = UUID.fromString(uuidString.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
|
||||
PlayerProfile profile = Bukkit.createProfile(uuid, name);
|
||||
profile.complete(true, true);
|
||||
this.profileMap.put(event.getUniqueId(), profile);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (this.profileMap.containsKey(uuid)) {
|
||||
player.setPlayerProfile(this.profileMap.get(uuid));
|
||||
this.profileMap.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String nameToUUID(String playerName) {
|
||||
try {
|
||||
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + playerName);
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject json = (JSONObject) parser.parse(new InputStreamReader(url.openStream()));
|
||||
return (String) json.get("id");
|
||||
} catch (ParseException | IOException ignore) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.shanebeestudios.mcbots.plugin;
|
||||
|
||||
import com.shanebeestudios.mcbots.api.BotManager;
|
||||
import com.shanebeestudios.mcbots.api.Info;
|
||||
import com.shanebeestudios.mcbots.bot.Bot;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PluginBotManager extends BotManager {
|
||||
|
||||
public PluginBotManager(Info info) {
|
||||
super(info);
|
||||
}
|
||||
|
||||
public void createBot(@Nullable String name) {
|
||||
if (name != null && name.length() > 16) {
|
||||
return;
|
||||
}
|
||||
|
||||
String botname = name != null ? name : getNickGenerator().nextNick();
|
||||
Bot bot = new Bot(this, botname, getInetAddr(), null);
|
||||
this.bots.add(bot);
|
||||
bot.connect();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.shanebeestudios.mcbots.plugin;
|
||||
|
||||
import com.shanebeestudios.mcbots.api.Info;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public class PluginInfo extends Info {
|
||||
|
||||
public PluginInfo() {
|
||||
super();
|
||||
this.autoRespawnDelay = 3000;
|
||||
this.useRealNicknames = true;
|
||||
this.address = getServerAddress();
|
||||
this.port = Bukkit.getPort();
|
||||
this.hasGravity = true;
|
||||
}
|
||||
|
||||
private String getServerAddress() {
|
||||
try {
|
||||
return Inet4Address.getLocalHost().getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.shanebeestudios.mcbots.plugin.command;
|
||||
|
||||
import com.shanebeestudios.mcbots.bot.Bot;
|
||||
import com.shanebeestudios.mcbots.plugin.McBotPlugin;
|
||||
import com.shanebeestudios.mcbots.plugin.PluginBotManager;
|
||||
import dev.jorel.commandapi.CommandTree;
|
||||
import dev.jorel.commandapi.arguments.EntitySelectorArgument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import dev.jorel.commandapi.arguments.IntegerArgument;
|
||||
import dev.jorel.commandapi.arguments.LiteralArgument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class Command {
|
||||
|
||||
private final McBotPlugin plugin;
|
||||
private final PluginBotManager botManager;
|
||||
private final BukkitScheduler scheduler;
|
||||
|
||||
public Command(McBotPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.botManager = plugin.getPluginBotManager();
|
||||
this.scheduler = Bukkit.getScheduler();
|
||||
registerCommand();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void registerCommand() {
|
||||
CommandTree command = new CommandTree("mcbot")
|
||||
// Create a bot
|
||||
.then(new LiteralArgument("create")
|
||||
.then(new LiteralArgument("named")
|
||||
.then(new StringArgument("name")
|
||||
.executes((sender, args) -> {
|
||||
String name = (String) args.get("name");
|
||||
this.botManager.createBot(name);
|
||||
})))
|
||||
.then(new LiteralArgument("random")
|
||||
.then(new IntegerArgument("amount")
|
||||
.setOptional(true)
|
||||
.then(new IntegerArgument("delay-ticks")
|
||||
.setOptional(true)
|
||||
.executes((sender, args) -> {
|
||||
int amount = (int) args.getOrDefault("amount", 1);
|
||||
long delay = (int) args.getOrDefault("delay-ticks", 20);
|
||||
for (int i = 0; i < amount; i++) {
|
||||
this.scheduler.runTaskLater(this.plugin, () -> {
|
||||
this.botManager.createBot(null);
|
||||
}, delay * i);
|
||||
}
|
||||
})))))
|
||||
|
||||
// Remove a bot
|
||||
.then(new LiteralArgument("remove")
|
||||
.then(new EntitySelectorArgument.ManyPlayers("players")
|
||||
.executes((sender, args) -> {
|
||||
Collection<Entity> players = (Collection<Entity>) args.get("players");
|
||||
assert players != null;
|
||||
players.forEach(player -> {
|
||||
Bot bot = this.botManager.findBotByName(player.getName());
|
||||
if (bot != null) {
|
||||
this.botManager.disconnectBot(bot);
|
||||
}
|
||||
});
|
||||
})))
|
||||
|
||||
// Make a bot send a chat message or command
|
||||
.then(new LiteralArgument("chat")
|
||||
.then(new EntitySelectorArgument.ManyPlayers("players")
|
||||
.then(new GreedyStringArgument("message")
|
||||
.executes((sender, args) -> {
|
||||
String message = (String) args.get("message");
|
||||
Collection<Entity> players = (Collection<Entity>) args.get("players");
|
||||
assert message != null;
|
||||
assert players != null;
|
||||
players.forEach(player -> {
|
||||
Bot bot = this.botManager.findBotByName(player.getName());
|
||||
if (bot != null) {
|
||||
bot.sendChat(message);
|
||||
}
|
||||
});
|
||||
}))));
|
||||
|
||||
command.register();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.shanebeestudios.mcbots.standalone;
|
||||
|
||||
import com.shanebeestudios.mcbots.bot.Bot;
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
import org.jline.reader.LineReader;
|
||||
import org.jline.reader.LineReaderBuilder;
|
||||
import org.jline.reader.UserInterruptException;
|
||||
@@ -15,9 +15,9 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class ConsoleReader {
|
||||
|
||||
private final StandaloneLoader standaloneLoader;
|
||||
private final StandaloneBotManager standaloneLoader;
|
||||
|
||||
public ConsoleReader(StandaloneLoader standaloneLoader) {
|
||||
public ConsoleReader(StandaloneBotManager standaloneLoader) {
|
||||
this.standaloneLoader = standaloneLoader;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Main {
|
||||
options.addOption("ar", "auto-respawn", true, "Set autorespawn delay (-1 to disable)");
|
||||
|
||||
StandaloneInfo standaloneInfo = new StandaloneInfo(options, args);
|
||||
new StandaloneLoader(standaloneInfo);
|
||||
new StandaloneBotManager(standaloneInfo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.github.steveice10.mc.auth.exception.request.RequestException;
|
||||
import com.github.steveice10.mc.auth.service.AuthenticationService;
|
||||
import com.github.steveice10.mc.auth.service.MsaAuthenticationService;
|
||||
import com.github.steveice10.mc.auth.util.HTTP;
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
|
||||
+6
-18
@@ -2,27 +2,25 @@ package com.shanebeestudios.mcbots.standalone;
|
||||
|
||||
import com.github.steveice10.mc.auth.service.AuthenticationService;
|
||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||
import com.shanebeestudios.mcbots.api.BotManager;
|
||||
import com.shanebeestudios.mcbots.api.ServerInfo;
|
||||
import com.shanebeestudios.mcbots.api.Loader;
|
||||
import com.shanebeestudios.mcbots.api.util.logging.Logger;
|
||||
import com.shanebeestudios.mcbots.bot.Bot;
|
||||
import com.shanebeestudios.mcbots.bot.BotLoader;
|
||||
import com.shanebeestudios.mcbots.api.util.Logger;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class StandaloneLoader extends Loader {
|
||||
public class StandaloneBotManager extends BotManager {
|
||||
|
||||
private final StandaloneInfo standaloneInfo;
|
||||
private final HashSet<Bot> controlledBots = new HashSet<>();
|
||||
|
||||
|
||||
private final AuthenticationService authenticationService;
|
||||
private final BotLoader botLoader;
|
||||
|
||||
private boolean isMainListenerMissing = true;
|
||||
|
||||
public StandaloneLoader(StandaloneInfo standaloneInfo) {
|
||||
public StandaloneBotManager(StandaloneInfo standaloneInfo) {
|
||||
super(standaloneInfo);
|
||||
this.standaloneInfo = standaloneInfo;
|
||||
|
||||
@@ -76,8 +74,9 @@ public class StandaloneLoader extends Loader {
|
||||
this.bots.get(0).registerMainListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBot(Bot bot) {
|
||||
this.bots.remove(bot);
|
||||
super.removeBot(bot);
|
||||
controlledBots.remove(bot);
|
||||
if (bot.hasMainListener()) {
|
||||
Logger.info("Bot with MainListener removed");
|
||||
@@ -109,17 +108,6 @@ public class StandaloneLoader extends Loader {
|
||||
}
|
||||
}
|
||||
|
||||
public Bot findBotByName(String text) {
|
||||
for (Bot bot : this.getBots()) {
|
||||
// Starts with and ignore case
|
||||
// https://stackoverflow.com/a/38947571/11787611
|
||||
if (bot.getNickname().regionMatches(true, 0, text, 0, text.length())) {
|
||||
return bot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public StandaloneInfo getMainInfo() {
|
||||
return this.standaloneInfo;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
main: com.shanebeestudios.mcbots.plugin.McBotPlugin
|
||||
name: "McBots"
|
||||
version: @version@
|
||||
api-version: 1.13
|
||||
loadbefore:
|
||||
- Skript
|
||||
Reference in new issue
Block a user