Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79e1ab20f3 | ||
|
|
187efe22bd |
No files matched your search
@@ -1,3 +1,6 @@
|
||||
/out
|
||||
/NMS
|
||||
/.idea
|
||||
/.gradle
|
||||
/build
|
||||
/AFK.iml
|
||||
@@ -0,0 +1,54 @@
|
||||
plugins { id 'java-library' }
|
||||
apply from: rootProject.file('specialSource.gradle')
|
||||
|
||||
version = '2.6.1'
|
||||
group = 'ru.tulavcube.AFK'
|
||||
|
||||
ext {
|
||||
spigotVersion = '1.18.1-R0.1-SNAPSHOT'
|
||||
remapServerCode = true
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
|
||||
|
||||
// As of Gradle 5.1, you can limit this to only those
|
||||
// dependencies you expect from it
|
||||
content {
|
||||
includeGroup 'org.bukkit'
|
||||
includeGroup 'org.spigotmc'
|
||||
}
|
||||
}
|
||||
|
||||
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
|
||||
maven { url = 'https://oss.sonatype.org/content/repositories/central' }
|
||||
maven { url = 'https://libraries.minecraft.net/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
afterEvaluate {
|
||||
if (remapServerCode) {
|
||||
implementation "org.spigotmc:spigot:${spigotVersion}:remapped-mojang"
|
||||
} else {
|
||||
implementation "org.spigotmc:spigot:${spigotVersion}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
if (remapServerCode) {
|
||||
jar {
|
||||
doLast {
|
||||
def outputFiles = outputs.files.files
|
||||
for (inputFile in outputFiles) {
|
||||
File intermediateFile = new File(temporaryDir, inputFile.name.replace('.jar', '-obf.jar'))
|
||||
File outputFile = inputFile
|
||||
remapMojangToSpigot(inputFile, intermediateFile, outputFile, spigotVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,185 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$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"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MSYS* | MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
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.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+89
@@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="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
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,2 @@
|
||||
rootProject.name = 'AFK'
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
configurations.create('specialSource')
|
||||
|
||||
dependencies {
|
||||
specialSource 'net.md-5:SpecialSource:1.11.0:shaded'
|
||||
}
|
||||
}
|
||||
|
||||
// Spigot server code remapping: https://www.spigotmc.org/threads/spigot-bungeecord-1-17-1-17-1.510208/
|
||||
// These dependencies and mappings are installed into the local Maven repository when BuildTools builds the Spigot dependencies.
|
||||
def m2Repo = new File(repositories.mavenLocal().url.path)
|
||||
def remappedMojang = new File(m2Repo, 'org/spigotmc/spigot/{spigotVersion}/spigot-{spigotVersion}-remapped-mojang.jar').path
|
||||
def remappedObf = new File(m2Repo, 'org/spigotmc/spigot/{spigotVersion}/spigot-{spigotVersion}-remapped-obf.jar').path
|
||||
def mojangMappings = new File(m2Repo, 'org/spigotmc/minecraft-server/{spigotVersion}/minecraft-server-{spigotVersion}-maps-mojang.txt').path
|
||||
def spigotMappings = new File(m2Repo, 'org/spigotmc/minecraft-server/{spigotVersion}/minecraft-server-{spigotVersion}-maps-spigot.csrg').path
|
||||
|
||||
def specialSource = buildscript.configurations.specialSource.resolvedConfiguration.getFirstLevelModuleDependencies {
|
||||
it.group == 'net.md-5' && it.name == 'SpecialSource'
|
||||
}.first().moduleArtifacts.first().file.path
|
||||
|
||||
// Converts from Mojang's mappings to Minecraft's obfuscated mappings.
|
||||
ext.remapMojangToObfuscated = { inputFile, outputFile, spigotVersion ->
|
||||
println '> remapMojangToObfuscated'
|
||||
println ' Input: ' + inputFile.path
|
||||
println ' Output: ' + outputFile.path
|
||||
println ' Spigot version: ' + spigotVersion
|
||||
def classpathSeparator = System.properties['path.separator']
|
||||
exec {
|
||||
commandLine 'java',
|
||||
'-cp', "${specialSource}${classpathSeparator}${remappedMojang}".replace('{spigotVersion}', spigotVersion),
|
||||
'net.md_5.specialsource.SpecialSource',
|
||||
'--live',
|
||||
'-i', inputFile.path,
|
||||
'-o', outputFile.path,
|
||||
'-m', mojangMappings.replace('{spigotVersion}', spigotVersion),
|
||||
'--reverse'
|
||||
}
|
||||
}
|
||||
|
||||
// Converts from Minecraft's obfuscated mappings to Spigot's mappings.
|
||||
ext.remapObfuscatedToSpigot = { inputFile, outputFile, spigotVersion ->
|
||||
println '> remapObfuscatedToSpigot'
|
||||
println ' Input: ' + inputFile.path
|
||||
println ' Output: ' + outputFile.path
|
||||
println ' Spigot version: ' + spigotVersion
|
||||
def classpathSeparator = System.properties['path.separator']
|
||||
exec {
|
||||
commandLine 'java',
|
||||
'-cp', "${specialSource}${classpathSeparator}${remappedObf}".replace('{spigotVersion}', spigotVersion),
|
||||
'net.md_5.specialsource.SpecialSource',
|
||||
'--live',
|
||||
'-i', inputFile.path,
|
||||
'-o', outputFile.path,
|
||||
'-m', spigotMappings.replace('{spigotVersion}', spigotVersion)
|
||||
}
|
||||
}
|
||||
|
||||
// Converts from Mojang's mappings to Spigot's mappings.
|
||||
ext.remapMojangToSpigot = { inputFile, intermediateFile, outputFile, spigotVersion ->
|
||||
println '> remapMojangToSpigot'
|
||||
println ' Input: ' + inputFile.path
|
||||
println ' Intermediate: ' + intermediateFile.path
|
||||
println ' Output: ' + outputFile.path
|
||||
println ' Spigot version: ' + spigotVersion
|
||||
remapMojangToObfuscated(inputFile, intermediateFile, spigotVersion)
|
||||
remapObfuscatedToSpigot(intermediateFile, outputFile, spigotVersion)
|
||||
}
|
||||
+102
-119
@@ -1,119 +1,102 @@
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK;
|
||||
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.network.PlayerConnection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import plugin.mrtransistor.AFK.commands.AFKUtils;
|
||||
import plugin.mrtransistor.AFK.commands.RemoveAllBots;
|
||||
import plugin.mrtransistor.AFK.commands.RemoveBot;
|
||||
import plugin.mrtransistor.AFK.commands.SpawnBot;
|
||||
|
||||
public class AFK extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
|
||||
getCommand("spawnBot").setExecutor(new SpawnBot());
|
||||
getCommand("spawnBot").setTabCompleter(new SpawnBot());
|
||||
getCommand("removeBot").setExecutor(new RemoveBot());
|
||||
getCommand("removeBot").setTabCompleter(new RemoveBot());
|
||||
getCommand("removeAllBots").setExecutor(new RemoveAllBots());
|
||||
getCommand("removeAllBots").setTabCompleter(new RemoveAllBots());
|
||||
getCommand("afkutils").setExecutor(new AFKUtils());
|
||||
getCommand("afkutils").setTabCompleter(new AFKUtils());
|
||||
|
||||
// Attack test
|
||||
/*new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
LivingEntity target = dummy.getTargetedLivingEntity();
|
||||
if (target != null) {
|
||||
dummy.swingHand(EnumHand.MAIN_HAND, true);
|
||||
dummy.attack(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(this, 0, 15);*/
|
||||
|
||||
getLogger().info("AFK plugin started!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
int botsRemoved = 0;
|
||||
int numBots = DummyPlayer.dummies.size();
|
||||
for (int i = 0; i < numBots; i++) {
|
||||
DummyPlayer dummy = DummyPlayer.dummies.get(0);
|
||||
getLogger().info("Bot '" + ChatColor.DARK_GREEN + dummy.getName() + ChatColor.RESET + "' with UUID:["
|
||||
+ ChatColor.GOLD + dummy.getUniqueIDString() + ChatColor.RESET + "] was removed");
|
||||
dummy.remove("Plugin stopped");
|
||||
botsRemoved++;
|
||||
}
|
||||
if (botsRemoved == 0) getLogger().info(ChatColor.GREEN + "No bots were removed");
|
||||
else if (botsRemoved == 1)
|
||||
getLogger().info(ChatColor.GREEN + "1 bot was removed");
|
||||
else getLogger().info(ChatColor.GREEN + Integer.toString(botsRemoved) + " bots were removed");
|
||||
getLogger().info("AFK plugin stopped!");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
PlayerConnection plc = ((CraftPlayer) e.getPlayer()).getHandle().b;
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
plc.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a,
|
||||
dummy));
|
||||
plc.sendPacket(new PacketPlayOutNamedEntitySpawn(dummy));
|
||||
plc.sendPacket(new PacketPlayOutEntityMetadata(dummy.getId(),
|
||||
dummy.getDataWatcher(), true));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e){
|
||||
if(((CraftEntity)e.getEntity()).getHandle() instanceof DummyPlayer){
|
||||
e.setDroppedExp(e.getEntity().getTotalExperience());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent e){
|
||||
if(((CraftEntity)e.getEntity()).getHandle() instanceof DummyPlayer){
|
||||
e.setCancelled(true);
|
||||
e.getEntity().setFoodLevel(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK;
|
||||
|
||||
import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import plugin.mrtransistor.AFK.commands.AFKUtils;
|
||||
import plugin.mrtransistor.AFK.commands.RemoveAllBots;
|
||||
import plugin.mrtransistor.AFK.commands.RemoveBot;
|
||||
import plugin.mrtransistor.AFK.commands.SpawnBot;
|
||||
|
||||
public class AFK extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
|
||||
getCommand("spawnBot").setExecutor(new SpawnBot());
|
||||
getCommand("spawnBot").setTabCompleter(new SpawnBot());
|
||||
getCommand("removeBot").setExecutor(new RemoveBot());
|
||||
getCommand("removeBot").setTabCompleter(new RemoveBot());
|
||||
getCommand("removeAllBots").setExecutor(new RemoveAllBots());
|
||||
getCommand("removeAllBots").setTabCompleter(new RemoveAllBots());
|
||||
getCommand("afkutils").setExecutor(new AFKUtils());
|
||||
getCommand("afkutils").setTabCompleter(new AFKUtils());
|
||||
|
||||
getLogger().info("AFK plugin started!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
int botsRemoved = 0;
|
||||
int numBots = DummyPlayer.dummies.size();
|
||||
for (int i = 0; i < numBots; i++) {
|
||||
DummyPlayer dummy = DummyPlayer.dummies.get(0);
|
||||
getLogger().info("Bot '" + ChatColor.DARK_GREEN + dummy.getName().getContents() + ChatColor.RESET + "' with UUID:["
|
||||
+ ChatColor.GOLD + dummy.getStringUUID() + ChatColor.RESET + "] was removed");
|
||||
dummy.remove("Plugin stopped");
|
||||
botsRemoved++;
|
||||
}
|
||||
if (botsRemoved == 0) getLogger().info(ChatColor.GREEN + "No bots were removed");
|
||||
else if (botsRemoved == 1)
|
||||
getLogger().info(ChatColor.GREEN + "1 bot was removed");
|
||||
else getLogger().info(ChatColor.GREEN + Integer.toString(botsRemoved) + " bots were removed");
|
||||
getLogger().info("AFK plugin stopped!");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
ServerGamePacketListenerImpl plc = ((CraftPlayer) e.getPlayer()).getHandle().connection;
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
plc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, dummy));
|
||||
plc.send(new ClientboundAddPlayerPacket(dummy));
|
||||
plc.send(new ClientboundSetEntityDataPacket(dummy.getId(), dummy.getEntityData(), true));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (((CraftEntity) e.getEntity()).getHandle() instanceof DummyPlayer) {
|
||||
e.setDroppedExp(e.getEntity().getTotalExperience());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent e) {
|
||||
if (((CraftEntity) e.getEntity()).getHandle() instanceof DummyPlayer) {
|
||||
e.setCancelled(true);
|
||||
e.getEntity().setFoodLevel(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
-122
@@ -1,123 +1,123 @@
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK;
|
||||
|
||||
import io.netty.channel.*;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.protocol.EnumProtocolDirection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class DummyNetworkManager extends NetworkManager {
|
||||
|
||||
public DummyNetworkManager() {
|
||||
super(EnumProtocolDirection.b);
|
||||
|
||||
this.k = new EmptyNettyChannel(null);
|
||||
this.l = new SocketAddress() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return super.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDisconnection() {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public static class EmptyNettyChannel extends AbstractChannel {
|
||||
private final ChannelConfig config = new DefaultChannelConfig(this);
|
||||
|
||||
public EmptyNettyChannel(Channel parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelConfig config() {
|
||||
config.setAutoRead(true);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBeginRead() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(SocketAddress address) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDisconnect() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWrite(ChannelOutboundBuffer buffer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop loop) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress localAddress0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMetadata metadata() {
|
||||
return new ChannelMetadata(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress remoteAddress0() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK;
|
||||
|
||||
import io.netty.channel.*;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class DummyConnection extends Connection {
|
||||
|
||||
public DummyConnection() {
|
||||
super(PacketFlow.SERVERBOUND);
|
||||
|
||||
this.channel = new EmptyNettyChannel(null);
|
||||
this.address = new SocketAddress() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return super.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDisconnection() {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public static class EmptyNettyChannel extends AbstractChannel {
|
||||
private final ChannelConfig config = new DefaultChannelConfig(this);
|
||||
|
||||
public EmptyNettyChannel(Channel parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelConfig config() {
|
||||
config.setAutoRead(true);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBeginRead() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(SocketAddress address) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDisconnect() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWrite(ChannelOutboundBuffer buffer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop loop) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress localAddress0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMetadata metadata() {
|
||||
return new ChannelMetadata(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress remoteAddress0() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.TickTask;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DummyPlayer extends ServerPlayer {
|
||||
public static ArrayList<DummyPlayer> dummies = new ArrayList<>();
|
||||
public static ArrayList<String> dummyNames = new ArrayList<>();
|
||||
|
||||
private boolean isSelfDefending = false;
|
||||
private boolean isAttackingContinuous = false;
|
||||
private boolean isForcePoI = false;
|
||||
private boolean aware = false;
|
||||
private boolean isTicking = true;
|
||||
private Location PoI_loc;
|
||||
private final float[] PoI_yawpitch = new float[2];
|
||||
|
||||
private static String[] getSkin(ServerPlayer player) {
|
||||
GameProfile gameProfile = player.getGameProfile();
|
||||
//### ДОБАВИТЬ ПРОВЕРКУ ОТСУТСТВИЯ СКИНА
|
||||
if (!gameProfile.getProperties().containsKey("textures")) return null;
|
||||
Property property = gameProfile.getProperties().get("textures").iterator().next();
|
||||
String texture = property.getValue();
|
||||
String signature = property.getSignature();
|
||||
return new String[]{texture, signature};
|
||||
}
|
||||
|
||||
public DummyPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
|
||||
super(server, world, profile);
|
||||
dummyNames.add(getName().getContents());
|
||||
dummies.add(this);
|
||||
}
|
||||
|
||||
public static DummyPlayer spawnBot(String name, Location location, org.bukkit.entity.Player spawner) {
|
||||
MinecraftServer server = ((CraftServer) (Bukkit.getServer())).getServer();
|
||||
ServerLevel world = ((CraftWorld) location.getWorld()).getHandle();
|
||||
Connection conn = new DummyConnection();
|
||||
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), name);
|
||||
DummyPlayer dummy = new DummyPlayer(server, world, gameProfile);
|
||||
|
||||
String[] texSign = getSkin(((CraftPlayer) spawner).getHandle());
|
||||
|
||||
if (texSign != null)
|
||||
gameProfile.getProperties().put("textures", new Property("textures", texSign[0], texSign[1]));
|
||||
|
||||
dummy.getEntityData().set(new EntityDataAccessor<>(17, EntityDataSerializers.BYTE), (byte) 0x7f); // show all model layers
|
||||
|
||||
dummy.connection = new ServerGamePacketListenerImpl(server, conn, dummy);
|
||||
world.addNewPlayer(dummy);
|
||||
|
||||
dummy.forceSetPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
dummy.setYHeadRot(location.getYaw());
|
||||
world.getChunkSource().move(dummy);
|
||||
|
||||
server.getPlayerList().broadcastAll(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, dummy));
|
||||
server.getPlayerList().broadcastAll(new ClientboundAddPlayerPacket(dummy));
|
||||
server.getPlayerList().broadcastAll(new ClientboundSetEntityDataPacket(dummy.getId(), dummy.getEntityData(), true));
|
||||
return dummy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!isTicking) return;
|
||||
super.tick();
|
||||
if (getServer().getTickCount() % 10 == 0) {
|
||||
connection.resetPosition();
|
||||
getLevel().getChunkSource().move(this);
|
||||
}
|
||||
doTick();
|
||||
|
||||
if (isForcePoI) goToPoI();
|
||||
selfDefence();
|
||||
if (isAttackingContinuous) attackContinuous();
|
||||
}
|
||||
|
||||
public void attackOnce() {
|
||||
CraftLivingEntity target = getTargetedLivingEntity();
|
||||
if (getAttackStrengthScale(0.5f) == 1 && target != null) {
|
||||
attack(target);
|
||||
}
|
||||
swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
public void setTicking(boolean state) {
|
||||
isTicking = state;
|
||||
}
|
||||
|
||||
public boolean isTicking() {
|
||||
return isTicking;
|
||||
}
|
||||
|
||||
public void setAttackingContinuous(boolean state) {
|
||||
isAttackingContinuous = state;
|
||||
}
|
||||
|
||||
public boolean isAttackingContinuous() {
|
||||
return isAttackingContinuous;
|
||||
}
|
||||
|
||||
public void setSelfDefending(boolean state) {
|
||||
isSelfDefending = state;
|
||||
}
|
||||
|
||||
public boolean isSelfDefending() {
|
||||
return isSelfDefending;
|
||||
}
|
||||
|
||||
public void setForcePoI(boolean state) {
|
||||
isForcePoI = state;
|
||||
if (isForcePoI) {
|
||||
PoI_loc = getBukkitEntity().getEyeLocation();
|
||||
PoI_yawpitch[0] = PoI_loc.getYaw();
|
||||
PoI_yawpitch[1] = PoI_loc.getPitch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isForcePoI() {
|
||||
return isForcePoI;
|
||||
}
|
||||
|
||||
private void attackContinuous() {
|
||||
if (!aware) {
|
||||
CraftLivingEntity target = getTargetedLivingEntity();
|
||||
if (getAttackStrengthScale(0.5f) == 1 && target != null) {
|
||||
attack(target);
|
||||
swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void selfDefence() {
|
||||
LivingEntity damager = getLastHurtByMob();
|
||||
|
||||
if (damager == null || !isSelfDefending) {
|
||||
if (aware) {
|
||||
Vector toTarget = getBukkitEntity().getEyeLocation().toVector().subtract(PoI_loc.toVector()).normalize();
|
||||
float yaw = (float) Math.atan2(toTarget.getX(), -toTarget.getZ());
|
||||
float pitch = (float) Math.atan2(toTarget.getY(), Math.sqrt(toTarget.getX() * toTarget.getX() + toTarget.getZ() * toTarget.getZ()));
|
||||
yaw *= 180 / Math.PI;
|
||||
pitch *= 180 / Math.PI;
|
||||
setRot(yaw, pitch);
|
||||
setYHeadRot(yaw);
|
||||
travel(new Vec3(0, 0, 1));
|
||||
if (PoI_loc.distance(getBukkitEntity().getEyeLocation()) < 0.1) {
|
||||
getBukkitEntity().setVelocity(new Vector(0, 0, 0));
|
||||
setRot(PoI_yawpitch[0], PoI_yawpitch[1]);
|
||||
setYHeadRot(PoI_yawpitch[0]);
|
||||
aware = false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!aware) {
|
||||
if (!isForcePoI) {
|
||||
PoI_loc = getBukkitEntity().getEyeLocation();
|
||||
PoI_yawpitch[0] = PoI_loc.getYaw();
|
||||
PoI_yawpitch[1] = PoI_loc.getPitch();
|
||||
}
|
||||
aware = true;
|
||||
}
|
||||
|
||||
Vector toTarget = getBukkitEntity().getEyeLocation().toVector().subtract(((CraftLivingEntity) damager.getBukkitEntity()).getEyeLocation().toVector()).normalize();
|
||||
float yaw = (float) Math.atan2(toTarget.getX(), -toTarget.getZ());
|
||||
float pitch = (float) Math.atan2(toTarget.getY(), Math.sqrt(toTarget.getX() * toTarget.getX() + toTarget.getZ() * toTarget.getZ()));
|
||||
yaw *= 180 / Math.PI;
|
||||
pitch *= 180 / Math.PI;
|
||||
setRot(yaw, pitch);
|
||||
setYHeadRot(yaw);
|
||||
travel(new Vec3(0, 0, 1));
|
||||
|
||||
CraftLivingEntity target = getTargetedLivingEntity();
|
||||
if (getAttackStrengthScale(0.5f) == 1 && target != null && target.getUniqueId().equals(damager.getUUID())) {
|
||||
attack(target);
|
||||
swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
}
|
||||
|
||||
private void goToPoI() {
|
||||
if (PoI_loc.distance(getBukkitEntity().getEyeLocation()) > 0.1) {
|
||||
aware = true;
|
||||
}
|
||||
}
|
||||
|
||||
public CraftLivingEntity getTargetedLivingEntity() {
|
||||
Player bukkitPlayer = getBukkitEntity();
|
||||
World world = bukkitPlayer.getWorld();
|
||||
Location eyePos = bukkitPlayer.getEyeLocation();
|
||||
Vector eyeDirection = bukkitPlayer.getEyeLocation().getDirection();
|
||||
Predicate<Entity> filter = entity -> !entity.equals(bukkitPlayer) && entity instanceof CraftLivingEntity;
|
||||
double reach = getBukkitEntity().getGameMode() == GameMode.CREATIVE ? 4.5 : 3;
|
||||
|
||||
RayTraceResult trace = world.rayTrace(eyePos, eyeDirection, reach, FluidCollisionMode.NEVER, true, 0, filter);
|
||||
if (trace == null) return null;
|
||||
Entity hitEntity = trace.getHitEntity();
|
||||
if (hitEntity instanceof CraftLivingEntity)
|
||||
return (CraftLivingEntity) hitEntity;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public void attack(Entity entity) {
|
||||
attack(((CraftEntity) entity).getHandle());
|
||||
}
|
||||
|
||||
public void remove(String reason) {
|
||||
dropEquipment();
|
||||
CraftPlayer bEntity = getBukkitEntity();
|
||||
World xpWorld = bEntity.getWorld();
|
||||
Location xpLoc = bEntity.getLocation();
|
||||
int xp = bEntity.getTotalExperience();
|
||||
connection.disconnect(reason);
|
||||
dummyNames.remove(getName().getContents());
|
||||
dummies.remove(this);
|
||||
xpWorld.spawn(xpLoc, ExperienceOrb.class).setExperience(xp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die(DamageSource damagesource) {
|
||||
super.die(damagesource);
|
||||
getServer().execute(new TickTask(getServer().getTickCount(), () -> remove("Died")));
|
||||
}
|
||||
}
|
||||
+19
-26
@@ -30,45 +30,38 @@ import java.util.List;
|
||||
public class AFKUtils implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if(args.length >= 1 && args[0].equalsIgnoreCase("controlBot")){
|
||||
if(args.length >= 2) {
|
||||
if (args.length >= 1 && args[0].equalsIgnoreCase("controlBot")) {
|
||||
if (args.length >= 2) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
if (dummy.getName().equals(args[1])) {
|
||||
if(args.length >= 3) {
|
||||
if (dummy.getName().getContents().equals(args[1])) {
|
||||
if (args.length >= 3) {
|
||||
if (args[2].equalsIgnoreCase("attackOnce")) {
|
||||
dummy.attackOnce();
|
||||
}
|
||||
else if(args[2].equalsIgnoreCase("toggle")) {
|
||||
if(args.length >= 4){
|
||||
if(args[3].equalsIgnoreCase("selfDefence")){
|
||||
} else if (args[2].equalsIgnoreCase("toggle")) {
|
||||
if (args.length >= 4) {
|
||||
if (args[3].equalsIgnoreCase("selfDefence")) {
|
||||
dummy.setSelfDefending(!dummy.isSelfDefending());
|
||||
sender.sendMessage(ChatColor.GREEN + "Self defence is toggled " + ChatColor.DARK_GREEN + (dummy.isSelfDefending() ? "ON" : "OFF"));
|
||||
}
|
||||
else if(args[3].equalsIgnoreCase("attackContinuous")){
|
||||
} else if (args[3].equalsIgnoreCase("attackContinuous")) {
|
||||
dummy.setAttackingContinuous(!dummy.isAttackingContinuous());
|
||||
sender.sendMessage(ChatColor.GREEN + "Continuous attacking is toggled " + ChatColor.DARK_GREEN + (dummy.isAttackingContinuous() ? "ON" : "OFF"));
|
||||
}
|
||||
else if(args[3].equalsIgnoreCase("setForcePoI")){
|
||||
} else if (args[3].equalsIgnoreCase("setForcePoI")) {
|
||||
dummy.setForcePoI(!dummy.isForcePoI());
|
||||
sender.sendMessage(ChatColor.GREEN + "Force point of interest is toggled " + ChatColor.DARK_GREEN + (dummy.isForcePoI() ? "ON" : "OFF"));
|
||||
}
|
||||
else if(args[3].equalsIgnoreCase("ticking")){
|
||||
} else if (args[3].equalsIgnoreCase("ticking")) {
|
||||
dummy.setTicking(!dummy.isTicking());
|
||||
sender.sendMessage(ChatColor.GREEN + "Entity ticking is " + ChatColor.DARK_GREEN + (dummy.isTicking() ? "enabled" : "disabled"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
} else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
} else return false;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + "There is no bot with name '" + ChatColor.DARK_GREEN + args[1] + ChatColor.RED + "'");
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
} else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -76,24 +69,24 @@ public class AFKUtils implements TabExecutor {
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
ArrayList<String> tabCompletion = new ArrayList<>();
|
||||
switch(args.length){
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
tabCompletion.add("controlBot");
|
||||
break;
|
||||
case 2:
|
||||
if(args[0].equalsIgnoreCase("controlBot")){
|
||||
for(DummyPlayer dummy : DummyPlayer.dummies) tabCompletion.add(dummy.getName());
|
||||
if (args[0].equalsIgnoreCase("controlBot")) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) tabCompletion.add(dummy.getName().getContents());
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(args[0].equalsIgnoreCase("controlBot")){
|
||||
if (args[0].equalsIgnoreCase("controlBot")) {
|
||||
tabCompletion.add("attackOnce");
|
||||
tabCompletion.add("toggle");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(args[0].equalsIgnoreCase("controlBot")){
|
||||
if(args[2].equalsIgnoreCase("toggle")){
|
||||
if (args[0].equalsIgnoreCase("controlBot")) {
|
||||
if (args[2].equalsIgnoreCase("toggle")) {
|
||||
tabCompletion.add("selfDefence");
|
||||
tabCompletion.add("attackContinuous");
|
||||
tabCompletion.add("setForcePoI");
|
||||
+53
-53
@@ -1,53 +1,53 @@
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import plugin.mrtransistor.AFK.DummyPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoveAllBots implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
int botsRemoved = 0;
|
||||
int numBots = DummyPlayer.dummies.size();
|
||||
for (int i = 0; i < numBots; i++) {
|
||||
DummyPlayer dummy = DummyPlayer.dummies.get(0);
|
||||
sender.sendMessage("Bot '" + ChatColor.DARK_GREEN + dummy.getName() + ChatColor.RESET + "' with UUID:["
|
||||
+ ChatColor.GOLD + dummy.getUniqueIDString() + ChatColor.RESET + "] was removed");
|
||||
dummy.remove("Removed using command");
|
||||
botsRemoved++;
|
||||
}
|
||||
if (botsRemoved == 0) sender.sendMessage(ChatColor.RED + "There are no bots");
|
||||
else if (botsRemoved == 1)
|
||||
sender.sendMessage(ChatColor.GREEN + "1 bot was removed");
|
||||
else sender.sendMessage(ChatColor.GREEN + Integer.toString(botsRemoved) + " bots were removed");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import plugin.mrtransistor.AFK.DummyPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoveAllBots implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
int botsRemoved = 0;
|
||||
int numBots = DummyPlayer.dummies.size();
|
||||
for (int i = 0; i < numBots; i++) {
|
||||
DummyPlayer dummy = DummyPlayer.dummies.get(0);
|
||||
sender.sendMessage("Bot '" + ChatColor.DARK_GREEN + dummy.getName().getContents() + ChatColor.RESET + "' with UUID:["
|
||||
+ ChatColor.GOLD + dummy.getStringUUID() + ChatColor.RESET + "] was removed");
|
||||
dummy.remove("Removed using command");
|
||||
botsRemoved++;
|
||||
}
|
||||
if (botsRemoved == 0) sender.sendMessage(ChatColor.RED + "There are no bots");
|
||||
else if (botsRemoved == 1)
|
||||
sender.sendMessage(ChatColor.GREEN + "1 bot was removed");
|
||||
else sender.sendMessage(ChatColor.GREEN + Integer.toString(botsRemoved) + " bots were removed");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
+60
-61
@@ -1,61 +1,60 @@
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
import plugin.mrtransistor.AFK.DummyPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoveBot implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1) return false;
|
||||
int botsRemoved = 0;
|
||||
int numBots = DummyPlayer.dummies.size();
|
||||
int iter = 0;
|
||||
for (int i = 0; i < numBots; i++) {
|
||||
DummyPlayer dummy = DummyPlayer.dummies.get(iter);
|
||||
if (dummy.getName().equals(args[0])) {
|
||||
sender.sendMessage("Bot '" + ChatColor.DARK_GREEN + args[0] + ChatColor.RESET + "' with UUID:["
|
||||
+ ChatColor.GOLD + dummy.getUniqueIDString() + ChatColor.RESET + "] was removed");
|
||||
dummy.remove("Removed using command");
|
||||
botsRemoved++;
|
||||
} else iter++;
|
||||
}
|
||||
|
||||
if (botsRemoved == 0) sender.sendMessage(ChatColor.RED + "There are no bots with specified name");
|
||||
else if (botsRemoved == 1)
|
||||
sender.sendMessage(ChatColor.GREEN + "1 bot was removed");
|
||||
else sender.sendMessage(ChatColor.GREEN + Integer.toString(botsRemoved) + " bots were removed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import plugin.mrtransistor.AFK.DummyPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoveBot implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1) return false;
|
||||
int botsRemoved = 0;
|
||||
int numBots = DummyPlayer.dummies.size();
|
||||
int iter = 0;
|
||||
for (int i = 0; i < numBots; i++) {
|
||||
DummyPlayer dummy = DummyPlayer.dummies.get(iter);
|
||||
if (dummy.getName().getContents().equals(args[0])) {
|
||||
sender.sendMessage("Bot '" + ChatColor.DARK_GREEN + args[0] + ChatColor.RESET + "' with UUID:["
|
||||
+ ChatColor.GOLD + dummy.getStringUUID() + ChatColor.RESET + "] was removed");
|
||||
dummy.remove("Removed using command");
|
||||
botsRemoved++;
|
||||
} else iter++;
|
||||
}
|
||||
|
||||
if (botsRemoved == 0) sender.sendMessage(ChatColor.RED + "There is no bot with specified name");
|
||||
else if (botsRemoved == 1)
|
||||
sender.sendMessage(ChatColor.GREEN + "1 bot was removed");
|
||||
else sender.sendMessage(ChatColor.GREEN + Integer.toString(botsRemoved) + " bots were removed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
+67
-68
@@ -1,68 +1,67 @@
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import plugin.mrtransistor.AFK.DummyPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnBot implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1) return false;
|
||||
if (sender instanceof Player) {
|
||||
if (args[0].length() > 16) {
|
||||
sender.sendMessage(ChatColor.RED + "Player names can`t be longer than 16 symbols");
|
||||
return true;
|
||||
}
|
||||
if (!DummyPlayer.dummyNames.contains(args[0])) {
|
||||
DummyPlayer dummy = DummyPlayer.spawnBot(args[0], ((Player) sender).getLocation(), (Player) sender);
|
||||
|
||||
String json = "[{\"text\":\"Bot '\", \"color\":\"white\"}," +
|
||||
"{\"text\":\"" + dummy.getName() + "\", \"color\":\"dark_green\"}," +
|
||||
"{\"text\":\"' with UUID:[\", \"color\":\"white\"}," +
|
||||
"{\"text\":\"" + dummy.getUniqueIDString() + "\", \"color\":\"gold\"," +
|
||||
" \"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"" + dummy.getUniqueIDString() + "\"}," +
|
||||
" \"hoverEvent\":{\"action\":\"show_text\", \"value\":\"Click to copy to clipboard\"}}," +
|
||||
"{\"text\":\"] spawned\", \"color\":\"white\"}]";
|
||||
|
||||
Bukkit.dispatchCommand(sender, "tellraw " + sender.getName() + " " + json);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Bot with name '" + ChatColor.DARK_GREEN + args[0] + ChatColor.RED + "' already exists");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage("Sorry, this command is only for players");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import plugin.mrtransistor.AFK.DummyPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnBot implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1) return false;
|
||||
if (sender instanceof Player) {
|
||||
if (args[0].length() > 16) {
|
||||
sender.sendMessage(ChatColor.RED + "Player names can`t be longer than 16 symbols");
|
||||
return true;
|
||||
}
|
||||
if (!DummyPlayer.dummyNames.contains(args[0])) {
|
||||
DummyPlayer dummy = DummyPlayer.spawnBot(args[0], ((Player) sender).getLocation(), (Player) sender);
|
||||
|
||||
String json = "[{\"text\":\"Bot '\", \"color\":\"white\"}," +
|
||||
"{\"text\":\"" + dummy.getName().getContents() + "\", \"color\":\"dark_green\"}," +
|
||||
"{\"text\":\"' with UUID:[\", \"color\":\"white\"}," +
|
||||
"{\"text\":\"" + dummy.getStringUUID() + "\", \"color\":\"gold\"," +
|
||||
" \"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"" + dummy.getStringUUID() + "\"}," +
|
||||
" \"hoverEvent\":{\"action\":\"show_text\", \"value\":\"Click to copy to clipboard\"}}," +
|
||||
"{\"text\":\"] spawned\", \"color\":\"white\"}]";
|
||||
|
||||
Bukkit.dispatchCommand(sender, "tellraw " + sender.getName() + " " + json);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Bot with name '" + ChatColor.DARK_GREEN + args[0] + ChatColor.RED + "' already exists");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage("Sorry, this command is only for players");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
# Nothing here yet
|
||||
# Except for this cat
|
||||
# _
|
||||
# \`*-.
|
||||
# ) _`-.
|
||||
# . : `. .
|
||||
# : _ ' \
|
||||
# ; *` _. `*-._
|
||||
# `-.-' `-.
|
||||
# ; ` `.
|
||||
# :. . \
|
||||
# . \ . : .-' .
|
||||
# ' `+.; ; ' :
|
||||
# : ' | ; ;-.
|
||||
# ; ' : :`-: _.`* ;
|
||||
# .*' / .*' ; .*`- +' `*'
|
||||
# Nothing here yet
|
||||
# Except for this cat
|
||||
# _
|
||||
# \`*-.
|
||||
# ) _`-.
|
||||
# . : `. .
|
||||
# : _ ' \
|
||||
# ; *` _. `*-._
|
||||
# `-.-' `-.
|
||||
# ; ` `.
|
||||
# :. . \
|
||||
# . \ . : .-' .
|
||||
# ' `+.; ; ' :
|
||||
# : ' | ; ;-.
|
||||
# ; ' : :`-: _.`* ;
|
||||
# .*' / .*' ; .*`- +' `*'
|
||||
# `*-* `*-* `*-*'
|
||||
@@ -1,18 +1,18 @@
|
||||
name: AFK
|
||||
version: 2.5
|
||||
author: MrTransistor
|
||||
main: plugin.mrtransistor.AFK.AFK
|
||||
commands:
|
||||
AFKUtils:
|
||||
usage: "Usage: /afkutils controlbot <name>"
|
||||
description: "Allows players to control bots"
|
||||
spawnBot:
|
||||
usage: "Usage: /spawnbot <name>"
|
||||
description: "Spawns an EntityPlayer, that can be controlled from within the plugin and acts as a player, allowing loading mobs and random ticking"
|
||||
removeBot:
|
||||
usage: "Usage: /removebot <name>"
|
||||
description: "Removes all bots with specified name"
|
||||
removeAllBots:
|
||||
usage: "Usage: /removeallbots"
|
||||
description: "Removes all bots"
|
||||
name: AFK
|
||||
version: 2.6.1
|
||||
author: MrTransistor
|
||||
main: plugin.mrtransistor.AFK.AFK
|
||||
commands:
|
||||
AFKUtils:
|
||||
usage: "Usage: /afkutils controlbot <name>"
|
||||
description: "Allows players to control bots"
|
||||
spawnBot:
|
||||
usage: "Usage: /spawnbot <name>"
|
||||
description: "Spawns an NPC, that can be controlled from within the plugin, which acts as a player, allowing loading mobs and random ticking"
|
||||
removeBot:
|
||||
usage: "Usage: /removebot <name>"
|
||||
description: "Removes all bots with specified name"
|
||||
removeAllBots:
|
||||
usage: "Usage: /removeallbots"
|
||||
description: "Removes all bots"
|
||||
api-version: 1.17
|
||||
@@ -1,267 +0,0 @@
|
||||
/*
|
||||
* Plugin that adds server-side bots
|
||||
*
|
||||
* Copyright (C) 2021 MrTransistor
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package plugin.mrtransistor.AFK;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.network.syncher.DataWatcherObject;
|
||||
import net.minecraft.network.syncher.DataWatcherRegistry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.TickTask;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.server.network.PlayerConnection;
|
||||
import net.minecraft.world.EnumHand;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EntityLiving;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DummyPlayer extends EntityPlayer {
|
||||
public static ArrayList<DummyPlayer> dummies = new ArrayList<>();
|
||||
public static ArrayList<String> dummyNames = new ArrayList<>();
|
||||
|
||||
private boolean isSelfDefending = false;
|
||||
private boolean isAttackingContinuous = false;
|
||||
private boolean isForcePoI = false;
|
||||
private boolean aware = false;
|
||||
private boolean isTicking = true;
|
||||
private Location PoI_loc;
|
||||
private final float[] PoI_yawpitch = new float[2];
|
||||
|
||||
private static String[] getSkin(EntityPlayer entityPlayer) {
|
||||
GameProfile gameProfile = entityPlayer.getProfile();
|
||||
Property property = gameProfile.getProperties().get("textures").iterator().next();
|
||||
String texture = property.getValue();
|
||||
String signature = property.getSignature();
|
||||
return new String[]{texture, signature};
|
||||
}
|
||||
|
||||
public DummyPlayer(MinecraftServer server, WorldServer world, GameProfile profile) {
|
||||
super(server, world, profile);
|
||||
dummyNames.add(getName());
|
||||
dummies.add(this);
|
||||
}
|
||||
|
||||
public static DummyPlayer spawnBot(String name, Location location, Player spawner) {
|
||||
MinecraftServer server = ((CraftServer) (Bukkit.getServer())).getServer();
|
||||
WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
|
||||
NetworkManager networkManager = new DummyNetworkManager();
|
||||
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), name);
|
||||
DummyPlayer dummy = new DummyPlayer(server, worldServer, gameProfile);
|
||||
|
||||
String[] texSign = getSkin(((CraftPlayer) spawner).getHandle());
|
||||
gameProfile.getProperties().put("textures", new Property("textures", texSign[0], texSign[1]));
|
||||
|
||||
dummy.getDataWatcher().set(new DataWatcherObject<>(17, DataWatcherRegistry.a), (byte) 0x7f); // show all model layers
|
||||
|
||||
dummy.b = new PlayerConnection(server, networkManager, dummy);
|
||||
worldServer.addPlayerJoin(dummy);
|
||||
|
||||
dummy.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
dummy.setHeadRotation(location.getYaw());
|
||||
dummy.setYawPitch(location.getYaw(), location.getPitch());
|
||||
worldServer.getChunkProvider().movePlayer(dummy);
|
||||
|
||||
|
||||
server.getPlayerList().sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, dummy));
|
||||
server.getPlayerList().sendAll(new PacketPlayOutNamedEntitySpawn(dummy));
|
||||
server.getPlayerList().sendAll(new PacketPlayOutEntityMetadata(dummy.getId(), dummy.getDataWatcher(), true));
|
||||
return dummy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if(!isTicking) return;
|
||||
if(isForcePoI) goToPoI();
|
||||
selfDefence();
|
||||
if(isAttackingContinuous) attackContinuous();
|
||||
|
||||
//getBukkitEntity().getServer().getLogger().info("");
|
||||
|
||||
if (getMinecraftServer().ai() % 10 == 0) {
|
||||
b.syncPosition();
|
||||
getWorldServer().getChunkProvider().movePlayer(this);
|
||||
}
|
||||
super.tick();
|
||||
playerTick();
|
||||
}
|
||||
|
||||
public void attackOnce() {
|
||||
LivingEntity target = getTargetedLivingEntity();
|
||||
if (getAttackCooldown(0.5f) == 1 && target != null) {
|
||||
attack(target);
|
||||
}
|
||||
swingHand(EnumHand.a);
|
||||
}
|
||||
|
||||
public void setTicking(boolean state){
|
||||
isTicking = state;
|
||||
}
|
||||
|
||||
public boolean isTicking(){
|
||||
return isTicking;
|
||||
}
|
||||
|
||||
public void setAttackingContinuous(boolean state){
|
||||
isAttackingContinuous = state;
|
||||
}
|
||||
|
||||
public boolean isAttackingContinuous(){
|
||||
return isAttackingContinuous;
|
||||
}
|
||||
|
||||
public void setSelfDefending(boolean state){
|
||||
isSelfDefending = state;
|
||||
}
|
||||
|
||||
public boolean isSelfDefending(){
|
||||
return isSelfDefending;
|
||||
}
|
||||
|
||||
public void setForcePoI(boolean state){
|
||||
isForcePoI = state;
|
||||
if(isForcePoI) {
|
||||
PoI_loc = getBukkitEntity().getEyeLocation();
|
||||
PoI_yawpitch[0] = PoI_loc.getYaw();
|
||||
PoI_yawpitch[1] = PoI_loc.getPitch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isForcePoI(){
|
||||
return isForcePoI;
|
||||
}
|
||||
|
||||
private void attackContinuous(){
|
||||
if(!aware) {
|
||||
LivingEntity target = getTargetedLivingEntity();
|
||||
if (getAttackCooldown(0.5f) == 1 && target != null) {
|
||||
attack(target);
|
||||
swingHand(EnumHand.a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void selfDefence() {
|
||||
EntityLiving damager = getLastDamager();
|
||||
|
||||
if (damager == null || !isSelfDefending){
|
||||
if(aware){
|
||||
Vector toTarget = getBukkitEntity().getEyeLocation().toVector().subtract(PoI_loc.toVector()).normalize();
|
||||
float yaw = (float) Math.atan2(toTarget.getX(), -toTarget.getZ());
|
||||
float pitch = (float) Math.atan2(toTarget.getY(), Math.sqrt(toTarget.getX() * toTarget.getX() + toTarget.getZ() * toTarget.getZ()));
|
||||
yaw *= 180 / Math.PI;
|
||||
pitch *= 180 / Math.PI;
|
||||
setYawPitch(yaw, pitch);
|
||||
setHeadRotation(yaw);
|
||||
g(new Vec3D(0, 0, 1));
|
||||
if(PoI_loc.distance(getBukkitEntity().getEyeLocation()) < 0.1){
|
||||
getBukkitEntity().setVelocity(new Vector(0, 0, 0));
|
||||
setYawPitch(PoI_yawpitch[0], PoI_yawpitch[1]);
|
||||
setHeadRotation(PoI_yawpitch[0]);
|
||||
aware = false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(!aware){
|
||||
if(!isForcePoI) {
|
||||
PoI_loc = getBukkitEntity().getEyeLocation();
|
||||
PoI_yawpitch[0] = PoI_loc.getYaw();
|
||||
PoI_yawpitch[1] = PoI_loc.getPitch();
|
||||
}
|
||||
aware = true;
|
||||
}
|
||||
|
||||
Vector toTarget = getBukkitEntity().getEyeLocation().toVector().subtract(((LivingEntity) damager.getBukkitEntity()).getEyeLocation().toVector()).normalize();
|
||||
float yaw = (float) Math.atan2(toTarget.getX(), -toTarget.getZ());
|
||||
float pitch = (float) Math.atan2(toTarget.getY(), Math.sqrt(toTarget.getX() * toTarget.getX() + toTarget.getZ() * toTarget.getZ()));
|
||||
yaw *= 180 / Math.PI;
|
||||
pitch *= 180 / Math.PI;
|
||||
setYawPitch(yaw, pitch);
|
||||
setHeadRotation(yaw);
|
||||
g(new Vec3D(0, 0, 1));
|
||||
|
||||
LivingEntity target = getTargetedLivingEntity();
|
||||
if (getAttackCooldown(0.5f) == 1 && target != null && target.getUniqueId().equals(damager.getUniqueID())) {
|
||||
attack(target);
|
||||
swingHand(EnumHand.a);
|
||||
}
|
||||
}
|
||||
|
||||
private void goToPoI(){
|
||||
if(PoI_loc.distance(getBukkitEntity().getEyeLocation()) > 0.1){
|
||||
aware = true;
|
||||
}
|
||||
}
|
||||
|
||||
public LivingEntity getTargetedLivingEntity() {
|
||||
Player bukkitPlayer = getBukkitEntity();
|
||||
World world = bukkitPlayer.getWorld();
|
||||
Location eyePos = bukkitPlayer.getEyeLocation();
|
||||
Vector eyeDirection = bukkitPlayer.getEyeLocation().getDirection();
|
||||
Predicate<org.bukkit.entity.Entity> filter = entity -> !entity.equals(bukkitPlayer) && entity instanceof LivingEntity;
|
||||
double reach = b.b.getBukkitEntity().getGameMode() == GameMode.CREATIVE ? 4.5 : 3;
|
||||
|
||||
RayTraceResult trace = world.rayTrace(eyePos, eyeDirection, reach, FluidCollisionMode.NEVER, true, 0, filter);
|
||||
if (trace == null) return null;
|
||||
Entity hitEntity = trace.getHitEntity();
|
||||
if (hitEntity instanceof LivingEntity)
|
||||
return (LivingEntity) hitEntity;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public void attack(Entity entity) {
|
||||
attack(((CraftEntity) entity).getHandle());
|
||||
}
|
||||
|
||||
public void remove(String reason) {
|
||||
dropInventory();
|
||||
b.disconnect(reason);
|
||||
dummyNames.remove(getName());
|
||||
dummies.remove(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die(DamageSource damagesource) {
|
||||
super.die(damagesource);
|
||||
getMinecraftServer().a(new TickTask(getMinecraftServer().ai(), () -> remove("Died")));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user