Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcf1a877b6 | ||
|
|
e391884484 | ||
|
|
f48dd3c4d1 | ||
|
|
64991b21fd | ||
|
|
e410ee8d09 | ||
|
|
7d212a4c30 | ||
|
|
ba1f3a1d89 | ||
|
|
4d04e75f01 | ||
|
|
86df28a1b4 | ||
|
|
6d6bde5daf | ||
|
|
6f3b9bf1b3 | ||
|
|
6c44745317 | ||
|
|
85884dfb42 | ||
|
|
4ab5b3319f | ||
|
|
3fcfacd74e | ||
|
|
677a6ee101 | ||
|
|
585696552a | ||
|
|
38a359c950 |
No files matched your search
@@ -1,5 +1,4 @@
|
||||
/out
|
||||
/NMS
|
||||
/.idea
|
||||
/.gradle
|
||||
/build
|
||||
|
||||
+20
-17
@@ -1,30 +1,23 @@
|
||||
plugins { id 'java-library' }
|
||||
plugins {
|
||||
id 'java-library'
|
||||
}
|
||||
apply from: rootProject.file('specialSource.gradle')
|
||||
|
||||
version = '2.6.1'
|
||||
group = 'ru.tulavcube.AFK'
|
||||
version = '3.0.1-MC1.19.4'
|
||||
group = 'plugin.mrtransistor.AFK'
|
||||
|
||||
ext {
|
||||
spigotVersion = '1.18.1-R0.1-SNAPSHOT'
|
||||
author = 'MrTransistor'
|
||||
spigotVersion = '1.19.4-R0.1-SNAPSHOT'
|
||||
remapServerCode = true
|
||||
|
||||
mainClass = group + '.' + rootProject.getName()
|
||||
apiVersion = spigotVersion.split('\\.')[0] + '.' + spigotVersion.split('\\.')[1]
|
||||
}
|
||||
|
||||
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/' }
|
||||
}
|
||||
|
||||
@@ -51,4 +44,14 @@ afterEvaluate {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
def props = [name : rootProject.name, version: version, author: author,
|
||||
mainClassPath: mainClass, apiVersion: apiVersion]
|
||||
inputs.properties props
|
||||
filteringCharset 'UTF-8'
|
||||
filesMatching('plugin.yml') {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
@@ -18,85 +18,111 @@
|
||||
*/
|
||||
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 com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
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.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
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;
|
||||
import plugin.mrtransistor.AFK.commands.CommandDispatcher;
|
||||
|
||||
public class AFK extends JavaPlugin implements Listener {
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AFK extends JavaPlugin {
|
||||
|
||||
private File botSaveFile;
|
||||
private FileConfiguration botSaveYml;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
loadBotSaveFile();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
CommandDispatcher commandDispatcher = new CommandDispatcher(this);
|
||||
EventListener eventListener = new EventListener();
|
||||
Bukkit.getPluginManager().registerEvents(eventListener, 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());
|
||||
|
||||
getCommand("spawnBot").setExecutor(commandDispatcher);
|
||||
getCommand("spawnBot").setTabCompleter(commandDispatcher);
|
||||
getCommand("removeAllBots").setExecutor(commandDispatcher);
|
||||
getCommand("removeAllBots").setTabCompleter(commandDispatcher);
|
||||
getCommand("afkutils").setExecutor(commandDispatcher);
|
||||
getCommand("afkutils").setTabCompleter(commandDispatcher);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(this, this::loadBots, 20);
|
||||
|
||||
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");
|
||||
saveBots();
|
||||
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));
|
||||
private void loadBots() {
|
||||
ConfigurationSection section = botSaveYml.getConfigurationSection("botsToReload");
|
||||
if (section == null) return;
|
||||
List<String> botsToLoad = new ArrayList<>(botSaveYml.getConfigurationSection("botsToReload").getKeys(false));
|
||||
if (botsToLoad.isEmpty()) return;
|
||||
getLogger().info(ChatColor.GREEN + "Loading " + botsToLoad.size()
|
||||
+ (botsToLoad.size() == 1 ? " bot" : " bots"));
|
||||
for (String bot : botsToLoad) {
|
||||
DummyPlayer.spawnBot(bot, null, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (((CraftEntity) e.getEntity()).getHandle() instanceof DummyPlayer) {
|
||||
e.setDroppedExp(e.getEntity().getTotalExperience());
|
||||
private void saveBots() {
|
||||
if (!DummyPlayer.dummies.isEmpty())
|
||||
getLogger().info(ChatColor.GREEN + "Saving " + DummyPlayer.dummies.size()
|
||||
+ (DummyPlayer.dummies.size() == 1 ? " bot" : " bots"));
|
||||
botSaveYml.set("botsToReload", null);
|
||||
botSaveYml.createSection("botsToReload");
|
||||
while (!DummyPlayer.dummies.isEmpty()) {
|
||||
DummyPlayer botToSave = DummyPlayer.dummies.get(0);
|
||||
botSaveYml.createSection("botsToReload." + botToSave.getScoreboardName());
|
||||
GameProfile gameProfile = botToSave.getGameProfile();
|
||||
if (gameProfile.getProperties().containsKey("textures")) {
|
||||
Property textures = gameProfile.getProperties().get("textures").iterator().next();
|
||||
botSaveYml.set("botsToReload." + botToSave.getScoreboardName() + ".texture", textures.getValue().toString());
|
||||
botSaveYml.set("botsToReload." + botToSave.getScoreboardName() + ".signature", textures.getSignature().toString());
|
||||
}
|
||||
botToSave.disconnect("Plugin unload");
|
||||
}
|
||||
saveBotSaveFile();
|
||||
}
|
||||
|
||||
private void loadBotSaveFile() {
|
||||
botSaveFile = new File(getDataFolder(), "botSave.yml");
|
||||
if (!botSaveFile.exists()) {
|
||||
botSaveFile.getParentFile().mkdirs();
|
||||
saveResource("botSave.yml", false);
|
||||
}
|
||||
|
||||
botSaveYml = new YamlConfiguration();
|
||||
try {
|
||||
botSaveYml.load(botSaveFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent e) {
|
||||
if (((CraftEntity) e.getEntity()).getHandle() instanceof DummyPlayer) {
|
||||
e.setCancelled(true);
|
||||
e.getEntity().setFoodLevel(20);
|
||||
public void saveBotSaveFile() {
|
||||
try {
|
||||
botSaveYml.save(botSaveFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getBotSaveYml() {
|
||||
return botSaveYml;
|
||||
}
|
||||
}
|
||||
@@ -18,106 +18,25 @@
|
||||
*/
|
||||
package plugin.mrtransistor.AFK;
|
||||
|
||||
import io.netty.channel.*;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class DummyConnection extends Connection {
|
||||
|
||||
public DummyConnection() {
|
||||
super(PacketFlow.SERVERBOUND);
|
||||
|
||||
this.channel = new EmptyNettyChannel(null);
|
||||
this.address = new SocketAddress() {
|
||||
};
|
||||
this.channel = new EmbeddedChannel();
|
||||
this.address = new InetSocketAddress("localhost", 25565);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return super.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
|
||||
/* do nothing */
|
||||
public void setReadOnly() {
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,41 +20,55 @@ 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.commands.arguments.EntityAnchorArgument;
|
||||
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.entity.projectile.LargeFireball;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.Level;
|
||||
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.configuration.ConfigurationSection;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.entity.*;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.util.CraftVector;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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 static final float ARROW_DIST_COEFF = 0.16F;
|
||||
private static final float ARROW_HEIGHT_COEFF = 0.03F;
|
||||
private static final float SNOWBALL_DIST_COEFF = 0.45F;
|
||||
private static final float SNOWBALL_HEIGHT_COEFF = 0.1F;
|
||||
private static final float TRIDENT_DIST_COEFF = 0.26F;
|
||||
private static final float TRIDENT_HEIGHT_COEFF = 0.055F;
|
||||
private net.minecraft.world.entity.Entity target;
|
||||
|
||||
//WIP
|
||||
//private Mob pathfindingMob;
|
||||
//private PathFinder pathFinder = new PathFinder(new WalkNodeEvaluator(), 300);
|
||||
|
||||
public static ArrayList<DummyPlayer> dummies = new ArrayList<>();
|
||||
public static ArrayList<String> names = new ArrayList<>();
|
||||
public String locale = "en_us"; // Needed to prevent plugins using aikar`s ACF library from throwing NoSuchFieldException
|
||||
public boolean isFullyConnected = false;
|
||||
private boolean isSelfDefending = false;
|
||||
private boolean isAttackingContinuous = false;
|
||||
private boolean isForcePoI = false;
|
||||
@@ -63,63 +77,127 @@ public class DummyPlayer extends ServerPlayer {
|
||||
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};
|
||||
private String[] getSkin(Player spawner) {
|
||||
if (spawner != null) {
|
||||
GameProfile gameProfile = ((CraftPlayer) spawner).getHandle().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};
|
||||
} else {
|
||||
ConfigurationSection botsToReload = ((AFK) server.server.getPluginManager().getPlugin("AFK")).getBotSaveYml()
|
||||
.getConfigurationSection("botsToReload");
|
||||
if (botsToReload.getKeys(false).contains(getScoreboardName())) {
|
||||
String texture = botsToReload.getConfigurationSection(getScoreboardName()).getString("texture");
|
||||
String signature = botsToReload.getConfigurationSection(getScoreboardName()).getString("signature");
|
||||
if (texture != null && signature != null)
|
||||
return new String[]{texture, signature};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public DummyPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
|
||||
super(server, world, profile);
|
||||
dummyNames.add(getName().getContents());
|
||||
dummies.add(this);
|
||||
names.add(getScoreboardName());
|
||||
}
|
||||
|
||||
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();
|
||||
public static void spawnBot(String name, Location location, Player spawner, boolean updateStats) { // some of this crap is redundant but it works
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
ServerLevel world = (location != null && location.getWorld() != null) ? ((CraftWorld) location.getWorld()).getHandle()
|
||||
: server.getLevel(Level.OVERWORLD);
|
||||
GameProfile gameProfile = server.getProfileCache().get(name).orElse(new GameProfile(UUID.randomUUID(), name)); // maybe needs something else?
|
||||
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), name);
|
||||
DummyPlayer dummy = new DummyPlayer(server, world, gameProfile);
|
||||
|
||||
String[] texSign = getSkin(((CraftPlayer) spawner).getHandle());
|
||||
String[] texSign;// maybe simplify this?
|
||||
texSign = dummy.getSkin(spawner);
|
||||
|
||||
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
|
||||
/* spawning entity */
|
||||
server.getPlayerList().placeNewPlayer(new DummyConnection(), dummy);
|
||||
|
||||
dummy.connection = new ServerGamePacketListenerImpl(server, conn, dummy);
|
||||
world.addNewPlayer(dummy);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() { // ensuring that the bot has been connected and started ticking
|
||||
if (!dummy.isFullyConnected) {
|
||||
dummy.connection.tick();
|
||||
return;
|
||||
} else if (location != null && location.getWorld() != null)
|
||||
dummy.teleportTo(world, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
//WIP
|
||||
//dummy.pathfindingMob = new Zombie(dummy.getLevel()); // Initialising pathfinding mob
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskTimer(server.server.getPluginManager().getPlugin("AFK"), 0, 10);
|
||||
|
||||
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;
|
||||
if (updateStats) {
|
||||
dummy.setHealth(20.0F);
|
||||
dummy.unsetRemoved();
|
||||
dummy.setGameMode(GameType.SURVIVAL);
|
||||
}
|
||||
dummy.getEntityData().set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0xf7);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
public void tick() { // still can`t figure out how to process knockback from players
|
||||
isFullyConnected = true;
|
||||
if (!isTicking) return;
|
||||
super.tick();
|
||||
if (getServer().getTickCount() % 10 == 0) {
|
||||
connection.resetPosition();
|
||||
super.tick(); // handle gamemode and inventory
|
||||
doTick(); // update health, air and other levels
|
||||
|
||||
if (getServer().getTickCount() % 10 == 0) { // update position in chunks
|
||||
connection.resetPosition(); // maybe not necessary?
|
||||
getLevel().getChunkSource().move(this);
|
||||
}
|
||||
doTick();
|
||||
setSprinting(getDeltaMovement().x() > 0 || getDeltaMovement().z() > 0); // sets sprinting disabled when bot
|
||||
} // doesn't move to prevent particles
|
||||
|
||||
//WIP
|
||||
/*if (pathfindingMob != null) {
|
||||
Vec3 vecPos = new Vec3(getX(), getY(), getZ()); // updating position of pathfinder mob
|
||||
pathfindingMob.setPos(vecPos);
|
||||
pathfindingMob.setOnGround(true); // maybe not needed?
|
||||
}*/
|
||||
|
||||
if (getServer().getTickCount() % 20 == 0) // prevents hunger
|
||||
getBukkitEntity().setFoodLevel(20);
|
||||
|
||||
if (isForcePoI) goToPoI();
|
||||
selfDefence();
|
||||
if (isAttackingContinuous) attackContinuous();
|
||||
rangeAttackTarget();
|
||||
|
||||
//WIP
|
||||
/*
|
||||
if (pathfindingMob == null) return;
|
||||
Player targetPlayer = Bukkit.getServer().getPlayer("MrTransistor_");
|
||||
if (targetPlayer == null) return;
|
||||
Location targetLoc = targetPlayer.getLocation();
|
||||
BlockPos targetPos = new BlockPos(targetLoc.getBlockX(), targetLoc.getBlockY(), targetLoc.getBlockZ());
|
||||
|
||||
Path pathToTarget = pathToTarget(targetPos, 120);
|
||||
|
||||
pathToTarget.advance();
|
||||
if (pathToTarget.isDone()) return;
|
||||
|
||||
if (targetPos.distSqr(new Vec3i(getBlockX(), getBlockY(), getBlockZ())) < 16) {
|
||||
lookAt(EntityAnchorArgument.Anchor.EYES, ((CraftPlayer) targetPlayer).getHandle(), EntityAnchorArgument.Anchor.EYES);
|
||||
return;
|
||||
}
|
||||
Vec3 toTarget = getEyePosition().subtract(pathToTarget.getNextNode().asVec3().add(0.5, 1.6, 0.5)).normalize();
|
||||
float yaw = (float) Math.atan2(toTarget.x(), -toTarget.z());
|
||||
float pitch = (float) Math.atan2(toTarget.y(), Math.sqrt(toTarget.x() * toTarget.x() + toTarget.z() * toTarget.z()));
|
||||
yaw *= 180 / Math.PI;
|
||||
pitch *= 180 / Math.PI;
|
||||
setRot(yaw, pitch);
|
||||
setYHeadRot(yaw);
|
||||
travel(new Vec3(0, 0, 1));
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public void attackOnce() {
|
||||
@@ -130,6 +208,34 @@ public class DummyPlayer extends ServerPlayer {
|
||||
swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
public void shootNearestLivingEntity() {
|
||||
CraftPlayer bukkitEntity = getBukkitEntity();
|
||||
List<Entity> nearbyEntities = bukkitEntity.getNearbyEntities(50, 50, 50);
|
||||
Entity nearest = null;
|
||||
double nearestDistance = 0;
|
||||
|
||||
for (Entity e : nearbyEntities) {
|
||||
if (!(e instanceof CraftLivingEntity || e instanceof CraftFireball)
|
||||
|| e instanceof Player || e instanceof Enderman || e instanceof Villager || e.isDead()) continue;
|
||||
if ((nearest == null || e.getLocation().distanceSquared(getBukkitEntity().getLocation()) < nearestDistance)
|
||||
&& bukkitEntity.hasLineOfSight(e)) {
|
||||
nearest = e;
|
||||
nearestDistance = e.getLocation().distanceSquared(getBukkitEntity().getLocation());
|
||||
}
|
||||
}
|
||||
if (nearest != null) {
|
||||
target = ((CraftEntity) nearest).getHandle();
|
||||
}
|
||||
}
|
||||
|
||||
//WIP
|
||||
/*private Path pathToTarget(BlockPos target, int range) {
|
||||
BlockPos pos = new BlockPos(getBlockX(), getBlockY(), getBlockZ());
|
||||
PathNavigationRegion region = new PathNavigationRegion(getLevel(), pos.offset(-range, -range, -range),
|
||||
pos.offset(range, range, range));
|
||||
return pathFinder.findPath(region, pathfindingMob, ImmutableSet.of(target), range, 1, 1.f);
|
||||
}*/
|
||||
|
||||
public void setTicking(boolean state) {
|
||||
isTicking = state;
|
||||
}
|
||||
@@ -186,8 +292,8 @@ public class DummyPlayer extends ServerPlayer {
|
||||
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;
|
||||
yaw *= (float) (180 / Math.PI);
|
||||
pitch *= (float) (180 / Math.PI);
|
||||
setRot(yaw, pitch);
|
||||
setYHeadRot(yaw);
|
||||
travel(new Vec3(0, 0, 1));
|
||||
@@ -212,8 +318,8 @@ public class DummyPlayer extends ServerPlayer {
|
||||
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;
|
||||
yaw *= (float) (180 / Math.PI);
|
||||
pitch *= (float) (180 / Math.PI);
|
||||
setRot(yaw, pitch);
|
||||
setYHeadRot(yaw);
|
||||
travel(new Vec3(0, 0, 1));
|
||||
@@ -231,6 +337,79 @@ public class DummyPlayer extends ServerPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
private void rangeAttackTarget() {
|
||||
if (target == null) return;
|
||||
|
||||
ItemStack itemStackInHand = getItemInHand(InteractionHand.MAIN_HAND);
|
||||
Item itemInHand = itemStackInHand.getItem();
|
||||
|
||||
lookAt(EntityAnchorArgument.Anchor.EYES, target, EntityAnchorArgument.Anchor.EYES);
|
||||
|
||||
// Correcting pitch for distance to target, rough approximation, but it has enough accuracy
|
||||
float weaponPitchCorrection = 0;
|
||||
float x = (float) (getX() - target.getX());
|
||||
float y = (float) (getY() - target.getY());
|
||||
float z = (float) (getZ() - target.getZ());
|
||||
float r = (float) Math.sqrt(x * x + z * z); // distance in X-Z plane
|
||||
|
||||
if (itemInHand instanceof BowItem || itemInHand instanceof CrossbowItem)
|
||||
weaponPitchCorrection = -r * ARROW_DIST_COEFF + y * ARROW_HEIGHT_COEFF;
|
||||
else if (itemInHand instanceof SnowballItem || itemInHand instanceof EggItem)
|
||||
weaponPitchCorrection = -r * SNOWBALL_DIST_COEFF + y * SNOWBALL_HEIGHT_COEFF;
|
||||
else if (itemInHand instanceof TridentItem)
|
||||
weaponPitchCorrection = -r * TRIDENT_DIST_COEFF + y * TRIDENT_DIST_COEFF;
|
||||
|
||||
// Correcting for target movement speed
|
||||
Vec3 targetVel = new Vec3(target.getDeltaMovement().x(), 0, target.getDeltaMovement().z());
|
||||
Vec3 lookDir = getLookAngle().normalize();
|
||||
|
||||
float targetSpeedPitchCorrection, targetSpeedYawCorrection;
|
||||
|
||||
if (target.invulnerableTime > 10 || target instanceof LargeFireball) {
|
||||
targetSpeedPitchCorrection = 0;
|
||||
targetSpeedYawCorrection = 0;
|
||||
} else {
|
||||
targetSpeedPitchCorrection = (float) (-targetVel.dot(lookDir) * r * 0.7);
|
||||
targetSpeedYawCorrection = (float) (-targetVel.dot(lookDir.yRot((float) (Math.PI/2))) * r * 1.2);
|
||||
}
|
||||
|
||||
setYRot(getYRot() + targetSpeedYawCorrection);
|
||||
setXRot(getXRot() + weaponPitchCorrection + targetSpeedPitchCorrection);
|
||||
|
||||
if (itemInHand instanceof BowItem) {
|
||||
if (!isUsingItem()) {
|
||||
itemInHand.use(getLevel(), this, InteractionHand.MAIN_HAND);
|
||||
}
|
||||
if (BowItem.getPowerForTime(getTicksUsingItem()) == 1.0) {
|
||||
itemStackInHand.releaseUsing(getLevel(), this, 0);
|
||||
stopUsingItem();
|
||||
target = null;
|
||||
}
|
||||
} else if (itemInHand instanceof CrossbowItem) {
|
||||
if (!isUsingItem() || CrossbowItem.isCharged(itemStackInHand)) {
|
||||
if (CrossbowItem.isCharged(itemStackInHand))
|
||||
target = null;
|
||||
itemInHand.use(getLevel(), this, InteractionHand.MAIN_HAND);
|
||||
}
|
||||
if (getTicksUsingItem() >= CrossbowItem.getChargeDuration(itemStackInHand)) {
|
||||
itemInHand.releaseUsing(itemStackInHand, getLevel(), this, 0);
|
||||
stopUsingItem();
|
||||
}
|
||||
} else if (itemInHand instanceof SnowballItem || itemInHand instanceof EggItem) {
|
||||
itemInHand.use(getLevel(), this, InteractionHand.MAIN_HAND);
|
||||
target = null;
|
||||
} else if (itemInHand instanceof TridentItem) {
|
||||
if (!isUsingItem())
|
||||
itemInHand.use(getLevel(), this, InteractionHand.MAIN_HAND);
|
||||
if ((float) getTicksUsingItem() >= 10 && !isAutoSpinAttack()) {
|
||||
itemInHand.releaseUsing(itemStackInHand, getLevel(), this, 0);
|
||||
target = null;
|
||||
}
|
||||
} else
|
||||
target = null;
|
||||
|
||||
}
|
||||
|
||||
public CraftLivingEntity getTargetedLivingEntity() {
|
||||
Player bukkitPlayer = getBukkitEntity();
|
||||
World world = bukkitPlayer.getWorld();
|
||||
@@ -247,25 +426,30 @@ public class DummyPlayer extends ServerPlayer {
|
||||
else return null;
|
||||
}
|
||||
|
||||
//TODO: find a way to send commands as bots
|
||||
/*@Override
|
||||
public CommandSourceStack createCommandSourceStack() {
|
||||
return new CommandSourceStack((net.minecraft.world.entity.Entity) this, this.position(), this.getRotationVector(), this.level instanceof ServerLevel ? (ServerLevel)this.level : null, this.getPermissionLevel(), this.getName().getString(), this.getDisplayName(), this.level.getServer(), this);
|
||||
}*/
|
||||
|
||||
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();
|
||||
public void disconnect(String reason) {
|
||||
connection.disconnect(reason);
|
||||
dummyNames.remove(getName().getContents());
|
||||
dummies.remove(this);
|
||||
xpWorld.spawn(xpLoc, ExperienceOrb.class).setExperience(xp);
|
||||
names.remove(getScoreboardName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die(DamageSource damagesource) {
|
||||
super.die(damagesource);
|
||||
getServer().execute(new TickTask(getServer().getTickCount(), () -> remove("Died")));
|
||||
setExperienceLevels(0); // idk why we need this but without this bot does not clear xp on death
|
||||
setExperiencePoints(0);
|
||||
clearFire();
|
||||
removeAllEffects();
|
||||
getBukkitEntity().setTotalExperience(0); // needed to simplify xp reward calculation
|
||||
getServer().execute(new TickTask(getServer().getTickCount(), () -> disconnect("Died")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package plugin.mrtransistor.AFK;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EventListener implements Listener {
|
||||
@EventHandler // handles removing of player exp cap on death for bots
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (((CraftEntity) e.getEntity()).getHandle() instanceof DummyPlayer)
|
||||
e.setDroppedExp(e.getEntity().getTotalExperience());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
if (!(((CraftEntity) e.getPlayer()).getHandle() instanceof DummyPlayer)) {
|
||||
FileConfiguration botSaveYml = Bukkit.getPluginManager().getPlugin("AFK").getConfig();
|
||||
List<String> blacklistedNames = new ArrayList<>();
|
||||
if (botSaveYml.contains("blacklistedNames"))
|
||||
blacklistedNames = botSaveYml.getStringList("blacklistedNames");
|
||||
if (!blacklistedNames.contains(e.getPlayer().getName()))
|
||||
blacklistedNames.add(e.getPlayer().getName());
|
||||
botSaveYml.set("blacklistedNames", blacklistedNames);
|
||||
Bukkit.getPluginManager().getPlugin("AFK").saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler // handles removing bot from list if lost connection not by DummyPlayer#die() or #disconnect()
|
||||
public void onPlayerDisconnect(PlayerQuitEvent e) {
|
||||
if (((CraftEntity) e.getPlayer()).getHandle() instanceof DummyPlayer) {
|
||||
DummyPlayer.dummies.remove((DummyPlayer) ((CraftEntity) e.getPlayer()).getHandle());
|
||||
DummyPlayer.names.remove(e.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +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.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 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) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
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")) {
|
||||
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")) {
|
||||
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")) {
|
||||
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")) {
|
||||
dummy.setTicking(!dummy.isTicking());
|
||||
sender.sendMessage(ChatColor.GREEN + "Entity ticking is " + ChatColor.DARK_GREEN + (dummy.isTicking() ? "enabled" : "disabled"));
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
return true;
|
||||
} 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
ArrayList<String> tabCompletion = new ArrayList<>();
|
||||
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().getContents());
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (args[0].equalsIgnoreCase("controlBot")) {
|
||||
tabCompletion.add("attackOnce");
|
||||
tabCompletion.add("toggle");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (args[0].equalsIgnoreCase("controlBot")) {
|
||||
if (args[2].equalsIgnoreCase("toggle")) {
|
||||
tabCompletion.add("selfDefence");
|
||||
tabCompletion.add("attackContinuous");
|
||||
tabCompletion.add("setForcePoI");
|
||||
tabCompletion.add("ticking");
|
||||
}
|
||||
}
|
||||
}
|
||||
return tabCompletion;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
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 org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import plugin.mrtransistor.AFK.AFK;
|
||||
import plugin.mrtransistor.AFK.DummyPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CommandDispatcher implements TabExecutor {
|
||||
|
||||
static AFK _plg;
|
||||
PluginDescriptionFile pluginDotYml;
|
||||
HashMap<String, String> aliasMap = new HashMap<>();
|
||||
|
||||
public CommandDispatcher(AFK plg) {
|
||||
pluginDotYml = plg.getDescription();
|
||||
_plg = plg;
|
||||
for (String cmd : pluginDotYml.getCommands().keySet()) {
|
||||
if (!pluginDotYml.getCommands().get(cmd).containsKey("aliases")) continue;
|
||||
for (String alias : (List<String>) pluginDotYml.getCommands().get(cmd).get("aliases"))
|
||||
aliasMap.put(alias, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (aliasMap.containsKey(label)) label = aliasMap.get(label);
|
||||
if (pluginDotYml.getCommands().get(label) == null) return false;
|
||||
if (args.length == 0) {
|
||||
if (pluginDotYml.getCommands().get(label).get("handler") == null) return false;
|
||||
try {
|
||||
getClass().getMethod(
|
||||
pluginDotYml.getCommands().get(label).get("handler").toString(),
|
||||
CommandSender.class, String[].class)
|
||||
.invoke(null, sender, args);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Map<String, Object> _args = (Map<String, Object>) pluginDotYml.getCommands().get(label).get("args");
|
||||
Pattern numeric = Pattern.compile("~?-?\\d+(?:\\.\\d+)?|~");
|
||||
for (String arg : args) {
|
||||
Map<String, Object> _args_bc = _args;
|
||||
if (numeric.matcher(arg).matches())
|
||||
_args = (Map<String, Object>) _args.get("__numeric__");
|
||||
else
|
||||
_args = (Map<String, Object>) _args.get(arg);
|
||||
if (_args == null) {
|
||||
if (_args_bc.containsKey("__text__")) _args = (Map<String, Object>) _args_bc.get("__text__");
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
getClass().getMethod(_args.get("handler").toString(), CommandSender.class, String[].class)
|
||||
.invoke(null, sender, args);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (aliasMap.containsKey(label)) label = aliasMap.get(label);
|
||||
if (pluginDotYml.getCommands().get(label) == null) return null;
|
||||
if (args.length == 1) {
|
||||
if (pluginDotYml.getCommands().get(label).get("tabCompletion") == null) return null;
|
||||
return (List<String>) pluginDotYml.getCommands().get(label).get("tabCompletion");
|
||||
} else {
|
||||
Map<String, Object> _args = (Map<String, Object>) pluginDotYml.getCommands().get(label).get("args");
|
||||
Pattern numeric = Pattern.compile("~?-?\\d+(?:\\.\\d+)?|~");
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
Map<String, Object> _args_old = _args;
|
||||
if (numeric.matcher(args[i]).matches()) {
|
||||
_args = (Map<String, Object>) _args.get("__numeric__");
|
||||
} else {
|
||||
_args = (Map<String, Object>) _args.get(args[i]);
|
||||
}
|
||||
if (_args == null) {
|
||||
if (_args_old.containsKey("__text__")) {
|
||||
_args = (Map<String, Object>) _args_old.get("__text__");
|
||||
} else return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
return (List<String>) _args.get("tabCompletion");
|
||||
}
|
||||
}
|
||||
|
||||
public static void attackOnce(CommandSender sender, String[] args) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
if (dummy.getName().getString().equals(args[1]))
|
||||
dummy.attackOnce();
|
||||
}
|
||||
}
|
||||
|
||||
public static void shootNearest(CommandSender sender, String[] args) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
if (dummy.getName().getString().equals(args[1]))
|
||||
dummy.shootNearestLivingEntity();
|
||||
}
|
||||
}
|
||||
|
||||
public static void attackContinuous(CommandSender sender, String[] args) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
if (dummy.getName().getString().equals(args[1])) {
|
||||
dummy.setAttackingContinuous(!dummy.isAttackingContinuous());
|
||||
sender.sendMessage(ChatColor.GREEN + "Continuous attacking is toggled " + ChatColor.DARK_GREEN
|
||||
+ (dummy.isAttackingContinuous() ? "ON" : "OFF"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void selfDefence(CommandSender sender, String[] args) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
if (dummy.getName().getString().equals(args[1])) {
|
||||
dummy.setSelfDefending(!dummy.isSelfDefending());
|
||||
sender.sendMessage(ChatColor.GREEN + "Self defence is toggled " + ChatColor.DARK_GREEN
|
||||
+ (dummy.isSelfDefending() ? "ON" : "OFF"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setForcePoI(CommandSender sender, String[] args) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
if (dummy.getName().getString().equals(args[1])) {
|
||||
dummy.setForcePoI(!dummy.isForcePoI());
|
||||
sender.sendMessage(ChatColor.GREEN + "Force point of interest is toggled " + ChatColor.DARK_GREEN
|
||||
+ (dummy.isForcePoI() ? "ON" : "OFF"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ticking(CommandSender sender, String[] args) {
|
||||
for (DummyPlayer dummy : DummyPlayer.dummies) {
|
||||
if (dummy.getName().getString().equals(args[1])) {
|
||||
dummy.setTicking(!dummy.isTicking());
|
||||
sender.sendMessage(ChatColor.GREEN + "Entity ticking is " + ChatColor.DARK_GREEN
|
||||
+ (dummy.isTicking() ? "enabled" : "disabled"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnBot(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
if (args[0].length() > 16) {
|
||||
sender.sendMessage(ChatColor.RED + "Player names can`t be longer than 16 symbols");
|
||||
return;
|
||||
}
|
||||
if (!_plg.getConfig().getStringList("blacklistedNames").contains(args[0]) && !DummyPlayer.names.contains(args[0]))
|
||||
DummyPlayer.spawnBot(args[0], ((Player) sender).getLocation(), (Player) sender, true);
|
||||
else
|
||||
sender.sendMessage(ChatColor.RED + "There`s already a player with that name");
|
||||
return;
|
||||
}
|
||||
sender.sendMessage("Sorry, this command is only for players");
|
||||
}
|
||||
|
||||
public static void removeAllBots(CommandSender sender, String[] args) {
|
||||
if (DummyPlayer.dummies.isEmpty()) sender.sendMessage(ChatColor.RED + "There are no bots");
|
||||
while (!DummyPlayer.dummies.isEmpty())
|
||||
DummyPlayer.dummies.get(0).disconnect("Removed using command");
|
||||
}
|
||||
}
|
||||
@@ -1,53 +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.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<>();
|
||||
}
|
||||
}
|
||||
@@ -1,60 +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.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<>();
|
||||
}
|
||||
}
|
||||
@@ -1,67 +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.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<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
botsToReload:
|
||||
@@ -1,17 +1 @@
|
||||
# Nothing here yet
|
||||
# Except for this cat
|
||||
# _
|
||||
# \`*-.
|
||||
# ) _`-.
|
||||
# . : `. .
|
||||
# : _ ' \
|
||||
# ; *` _. `*-._
|
||||
# `-.-' `-.
|
||||
# ; ` `.
|
||||
# :. . \
|
||||
# . \ . : .-' .
|
||||
# ' `+.; ; ' :
|
||||
# : ' | ; ;-.
|
||||
# ; ' : :`-: _.`* ;
|
||||
# .*' / .*' ; .*`- +' `*'
|
||||
# `*-* `*-* `*-*'
|
||||
blacklistedNames: []
|
||||
@@ -1,18 +1,49 @@
|
||||
name: AFK
|
||||
version: 2.6.1
|
||||
author: MrTransistor
|
||||
main: plugin.mrtransistor.AFK.AFK
|
||||
name: ${name}
|
||||
version: ${version}
|
||||
author: ${author}
|
||||
main: ${mainClassPath}
|
||||
commands:
|
||||
AFKUtils:
|
||||
usage: "Usage: /afkutils controlbot <name>"
|
||||
afkutils:
|
||||
usage: "Usage: /afkutils controlBot <name>"
|
||||
description: "Allows players to control bots"
|
||||
spawnBot:
|
||||
tabCompletion: [ control ]
|
||||
args:
|
||||
control:
|
||||
tabCompletion: [ ]
|
||||
__text__:
|
||||
tabCompletion: [ attackOnce, shootNearest, toggle ]
|
||||
attackOnce:
|
||||
tabCompletion: [ ]
|
||||
handler: attackOnce
|
||||
shootNearest:
|
||||
tabCompletion: [ ]
|
||||
handler: shootNearest
|
||||
toggle:
|
||||
tabCompletion: [ attackContinuous, selfDefence, setForcePoI, ticking ]
|
||||
attackContinuous:
|
||||
tabCompletion: [ ]
|
||||
handler: attackContinuous
|
||||
selfDefence:
|
||||
tabCompletion: [ ]
|
||||
handler: selfDefence
|
||||
setForcePoI:
|
||||
tabCompletion: [ ]
|
||||
handler: setForcePoI
|
||||
ticking:
|
||||
tabCompletion: [ ]
|
||||
handler: ticking
|
||||
|
||||
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:
|
||||
tabCompletion: [ ]
|
||||
args:
|
||||
__text__:
|
||||
tabCompletion: [ ]
|
||||
handler: spawnBot
|
||||
removeallbots:
|
||||
usage: "Usage: /removeallbots"
|
||||
description: "Removes all bots"
|
||||
api-version: 1.17
|
||||
tabCompletion: [ ]
|
||||
handler: removeAllBots
|
||||
api-version: ${apiVersion}
|
||||
Reference in new issue
Block a user