mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-09-14 11:16:46 +08:00
1. 支持 1.20.2
2. CommandAPI 改为插件依赖
This commit is contained in:
parent
4bd71d67a0
commit
bcb39f0066
@ -1,29 +0,0 @@
|
||||
package io.github.hello09x.fakeplayer.api.action;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public interface ActionTicker {
|
||||
|
||||
static @NotNull ActionTicker create(@NotNull Player player, @NotNull ActionType action, @NotNull ActionSetting setting) {
|
||||
var instance = ServiceLoader.load(
|
||||
ActionTicker.class,
|
||||
ActionTicker.class.getClassLoader()
|
||||
).findFirst().orElseThrow();
|
||||
instance.init(player, action, setting);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void tick();
|
||||
|
||||
void inactiveTick();
|
||||
|
||||
void stop();
|
||||
|
||||
void init(@NotNull Player player, @NotNull ActionType action, @NotNull ActionSetting setting);
|
||||
|
||||
boolean isDone();
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package io.github.hello09x.fakeplayer.api.nms;
|
||||
|
||||
public interface NMSEntity {
|
||||
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package io.github.hello09x.fakeplayer.api.nms;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public interface NMSFactory {
|
||||
|
||||
static @NotNull NMSFactory getInstance() {
|
||||
return ServiceLoader.load(NMSFactory.class, NMSFactory.class.getClassLoader()).findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
NMSEntity entity(@NotNull Entity entity);
|
||||
|
||||
NMSServer server(@NotNull Server server);
|
||||
|
||||
NMSServerLevel world(@NotNull World world);
|
||||
|
||||
NMSServerPlayer player(@NotNull Player player);
|
||||
|
||||
NMSNetwork network();
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package io.github.hello09x.fakeplayer.api.nms;
|
||||
|
||||
public interface NMSServerLevel {
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.api.action;
|
||||
package io.github.hello09x.fakeplayer.api.spi;
|
||||
|
||||
public interface Action {
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.github.hello09x.fakeplayer.api.spi;
|
||||
|
||||
public interface ActionTicker {
|
||||
|
||||
void tick();
|
||||
|
||||
void inactiveTick();
|
||||
|
||||
void stop();
|
||||
|
||||
boolean isDone();
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.api.spi;
|
||||
|
||||
public interface NMSEntity {
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.api.nms;
|
||||
package io.github.hello09x.fakeplayer.api.spi;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.api.nms;
|
||||
package io.github.hello09x.fakeplayer.api.spi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -0,0 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.api.spi;
|
||||
|
||||
public interface NMSServerLevel {
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.api.nms;
|
||||
package io.github.hello09x.fakeplayer.api.spi;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
@ -0,0 +1,40 @@
|
||||
package io.github.hello09x.fakeplayer.api.spi;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public interface VersionSupport {
|
||||
|
||||
static @Nullable VersionSupport getInstance() {
|
||||
return ServiceLoader
|
||||
.load(VersionSupport.class, VersionSupport.class.getClassLoader())
|
||||
.stream()
|
||||
.map(ServiceLoader.Provider::get)
|
||||
.filter(v -> v.isSupported())
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@NotNull NMSEntity entity(@NotNull Entity entity);
|
||||
|
||||
@NotNull NMSServer server(@NotNull Server server);
|
||||
|
||||
@NotNull NMSServerLevel world(@NotNull World world);
|
||||
|
||||
@NotNull NMSServerPlayer player(@NotNull Player player);
|
||||
|
||||
@NotNull NMSNetwork network();
|
||||
|
||||
boolean isSupported();
|
||||
|
||||
ActionTicker createAction(@NotNull Player player, @NotNull ActionType action, @NotNull ActionSetting setting);
|
||||
|
||||
}
|
@ -47,14 +47,11 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- shaded -->
|
||||
<!-- https://github.com/JorelAli/CommandAPI -->
|
||||
<dependency>
|
||||
<groupId>dev.jorel</groupId>
|
||||
<artifactId>commandapi-bukkit-shade</artifactId>
|
||||
<artifactId>commandapi-bukkit-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
@ -1,15 +1,15 @@
|
||||
package io.github.hello09x.fakeplayer;
|
||||
package io.github.hello09x.fakeplayer.core;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.CommandAPIBukkitConfig;
|
||||
import io.github.hello09x.fakeplayer.command.CommandRegistry;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.listener.PlayerListeners;
|
||||
import io.github.hello09x.fakeplayer.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.manager.WildFakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.repository.UsedIdRepository;
|
||||
import io.github.hello09x.fakeplayer.util.update.UpdateChecker;
|
||||
import io.github.hello09x.fakeplayer.api.spi.VersionSupport;
|
||||
import io.github.hello09x.fakeplayer.core.command.CommandRegistry;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.listener.PlayerListeners;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.core.manager.WildFakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository;
|
||||
import io.github.hello09x.fakeplayer.core.util.update.UpdateChecker;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -19,9 +19,15 @@ public final class Main extends JavaPlugin {
|
||||
@Getter
|
||||
private static Main instance;
|
||||
|
||||
@Getter
|
||||
private static VersionSupport versionSupport;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
CommandAPI.onLoad(new CommandAPIBukkitConfig(this).silentLogs(true));
|
||||
versionSupport = VersionSupport.getInstance();
|
||||
if (versionSupport == null) {
|
||||
throw new ExceptionInInitializerError("不支持当前 minecraft 版本: " + Bukkit.getMinecraftVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,8 +36,6 @@ public final class Main extends JavaPlugin {
|
||||
instance = this;
|
||||
|
||||
CommandRegistry.register();
|
||||
CommandAPI.onEnable();
|
||||
|
||||
{
|
||||
var messenger = getServer().getMessenger();
|
||||
messenger.registerIncomingPluginChannel(this, "BungeeCord", WildFakeplayerManager.instance);
|
||||
@ -78,7 +82,6 @@ public final class Main extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
CommandAPI.onDisable();
|
||||
FakeplayerManager.instance.removeAll("plugin disabled");
|
||||
UsedIdRepository.instance.saveAll();
|
||||
FakeplayerManager.instance.onDisable();
|
@ -1,10 +1,10 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
@ -6,10 +6,10 @@ import dev.jorel.commandapi.executors.CommandExecutor;
|
||||
import dev.jorel.commandapi.wrappers.Rotation;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSFactory;
|
||||
import io.github.hello09x.fakeplayer.command.support.Direction;
|
||||
import io.github.hello09x.fakeplayer.manager.action.ActionManager;
|
||||
import io.github.hello09x.fakeplayer.util.Mth;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.command.support.Direction;
|
||||
import io.github.hello09x.fakeplayer.core.manager.action.ActionManager;
|
||||
import io.github.hello09x.fakeplayer.core.util.Mth;
|
||||
import io.papermc.paper.entity.LookAnchor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Location;
|
||||
@ -143,7 +143,7 @@ public class ActionCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
private void look(@NotNull Player player, float yaw, float pitch) {
|
||||
var handle = NMSFactory.getInstance().player(player);
|
||||
var handle = Main.getVersionSupport().player(player);
|
||||
handle.setYRot(yaw % 360);
|
||||
handle.setXRot(Mth.clamp(pitch, -90, 90));
|
||||
}
|
||||
@ -151,7 +151,7 @@ public class ActionCommand extends AbstractCommand {
|
||||
public CommandExecutor move(float forward, float strafing) {
|
||||
return (sender, args) -> {
|
||||
var target = getTarget(sender, args);
|
||||
var handle = NMSFactory.getInstance().player(target);
|
||||
var handle = Main.getVersionSupport().player(target);
|
||||
float vel = target.isSneaking() ? 0.3F : 1.0F;
|
||||
if (forward != 0.0F) {
|
||||
handle.setZza(vel * forward);
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
@ -9,11 +9,11 @@ import dev.jorel.commandapi.executors.CommandExecutor;
|
||||
import io.github.hello09x.bedrock.command.Usage;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import io.github.hello09x.fakeplayer.command.support.Direction;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.repository.model.Config;
|
||||
import io.github.hello09x.fakeplayer.repository.model.Configs;
|
||||
import io.github.hello09x.fakeplayer.core.command.support.Direction;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.core.repository.model.Config;
|
||||
import io.github.hello09x.fakeplayer.core.repository.model.Configs;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.fakeplayer.repository.UserConfigRepository;
|
||||
import io.github.hello09x.fakeplayer.repository.model.Config;
|
||||
import io.github.hello09x.fakeplayer.core.repository.UserConfigRepository;
|
||||
import io.github.hello09x.fakeplayer.core.repository.model.Config;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import org.bukkit.entity.Player;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
public interface Permission {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.bedrock.io.Experiences;
|
||||
import io.github.hello09x.fakeplayer.util.Mth;
|
||||
import io.github.hello09x.fakeplayer.core.util.Mth;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -28,7 +29,7 @@ public class ProfileCommand extends AbstractCommand {
|
||||
sender.sendMessage(textOfChildren(
|
||||
text(target.getName(), WHITE),
|
||||
text(" 当前 ", GRAY),
|
||||
text(level, DARK_GREEN),
|
||||
Component.text(level, DARK_GREEN),
|
||||
text(" 级, 共 ", GRAY),
|
||||
text(total, DARK_GREEN),
|
||||
text(" 点经验值", GRAY)
|
||||
@ -60,7 +61,7 @@ public class ProfileCommand extends AbstractCommand {
|
||||
sender.sendMessage(textOfChildren(
|
||||
text(target.getName(), WHITE),
|
||||
text(" 当前生命值: ", GRAY),
|
||||
text(Mth.floor(health, 0.5), color),
|
||||
Component.text(Mth.floor(health, 0.5), color),
|
||||
text("/", color),
|
||||
text(max, color)
|
||||
));
|
@ -1,7 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSFactory;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
@ -25,7 +25,7 @@ public class RideCommand extends AbstractCommand {
|
||||
if (entities.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
NMSFactory.getInstance().player(target).startRiding(entities.get(0), true);
|
||||
Main.getVersionSupport().player(target).startRiding(entities.get(0), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,7 +38,7 @@ public class RideCommand extends AbstractCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
NMSFactory.getInstance().player(target).startRiding(entity, true);
|
||||
Main.getVersionSupport().player(target).startRiding(entity, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,7 +56,7 @@ public class RideCommand extends AbstractCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
NMSFactory.getInstance().player(target).startRiding(entity, true);
|
||||
Main.getVersionSupport().player(target).startRiding(entity, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,11 +73,11 @@ public class RideCommand extends AbstractCommand {
|
||||
throw CommandAPI.failWithString("你离假人太远了");
|
||||
}
|
||||
|
||||
NMSFactory.getInstance().player(target).startRiding(sender, true);
|
||||
Main.getVersionSupport().player(target).startRiding(sender, true);
|
||||
}
|
||||
|
||||
public void stopRiding(@NotNull CommandSender sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
NMSFactory.getInstance().player(getTarget(sender, args)).stopRiding();
|
||||
Main.getVersionSupport().player(getTarget(sender, args)).stopRiding();
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.bedrock.command.MessageException;
|
||||
import io.github.hello09x.bedrock.page.Page;
|
||||
import io.github.hello09x.fakeplayer.util.Mth;
|
||||
import io.github.hello09x.fakeplayer.core.util.Mth;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
@ -1,8 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.command;
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.fakeplayer.util.Teleportor;
|
||||
import io.github.hello09x.fakeplayer.core.util.Teleportor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.command.support;
|
||||
package io.github.hello09x.fakeplayer.core.command.support;
|
||||
|
||||
public enum Direction {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.config;
|
||||
package io.github.hello09x.fakeplayer.core.config;
|
||||
|
||||
|
||||
import io.github.hello09x.bedrock.config.Config;
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
@ -1,17 +1,16 @@
|
||||
package io.github.hello09x.fakeplayer.entity;
|
||||
package io.github.hello09x.fakeplayer.core.entity;
|
||||
|
||||
import io.github.hello09x.bedrock.task.Tasks;
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSFactory;
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSServerPlayer;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.manager.action.ActionManager;
|
||||
import io.github.hello09x.fakeplayer.manager.naming.SequenceName;
|
||||
import io.github.hello09x.fakeplayer.util.InternalAddressGenerator;
|
||||
import io.github.hello09x.fakeplayer.util.Teleportor;
|
||||
import io.github.hello09x.fakeplayer.util.Worlds;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSServerPlayer;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.manager.action.ActionManager;
|
||||
import io.github.hello09x.fakeplayer.core.manager.naming.SequenceName;
|
||||
import io.github.hello09x.fakeplayer.core.util.InternalAddressGenerator;
|
||||
import io.github.hello09x.fakeplayer.core.util.Teleportor;
|
||||
import io.github.hello09x.fakeplayer.core.util.Worlds;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -81,7 +80,7 @@ public class FakePlayer {
|
||||
this.creator = creator;
|
||||
this.creatorIp = creatorIp;
|
||||
this.sequenceName = sequenceName;
|
||||
this.handle = NMSFactory.getInstance().server(Bukkit.getServer()).newPlayer(uuid, name);
|
||||
this.handle = Main.getVersionSupport().server(Bukkit.getServer()).newPlayer(uuid, name);
|
||||
this.player = handle.getPlayer();
|
||||
this.ticker = new FakeplayerTicker(this, removeAt);
|
||||
|
||||
@ -133,7 +132,7 @@ public class FakePlayer {
|
||||
));
|
||||
}
|
||||
|
||||
var network = NMSFactory.getInstance().network();
|
||||
var network = Main.getVersionSupport().network();
|
||||
network.bindEmptyServerGamePacketListener(Bukkit.getServer(), this.player, address);
|
||||
network.bindEmptyLoginPacketListener(Bukkit.getServer(), this.player, address);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.entity;
|
||||
package io.github.hello09x.fakeplayer.core.entity;
|
||||
|
||||
import io.github.hello09x.fakeplayer.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.entity;
|
||||
package io.github.hello09x.fakeplayer.core.entity;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
@ -1,11 +1,11 @@
|
||||
package io.github.hello09x.fakeplayer.listener;
|
||||
package io.github.hello09x.fakeplayer.core.listener;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.repository.UsedIdRepository;
|
||||
import io.github.hello09x.fakeplayer.util.InternalAddressGenerator;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository;
|
||||
import io.github.hello09x.fakeplayer.core.util.InternalAddressGenerator;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.event.EventHandler;
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.manager;
|
||||
package io.github.hello09x.fakeplayer.core.manager;
|
||||
|
||||
import io.github.hello09x.fakeplayer.entity.FakePlayer;
|
||||
import io.github.hello09x.fakeplayer.core.entity.FakePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
@ -1,22 +1,22 @@
|
||||
package io.github.hello09x.fakeplayer.manager;
|
||||
package io.github.hello09x.fakeplayer.core.manager;
|
||||
|
||||
import io.github.hello09x.bedrock.command.MessageException;
|
||||
import io.github.hello09x.bedrock.task.Tasks;
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.entity.FakePlayer;
|
||||
import io.github.hello09x.fakeplayer.entity.SpawnOption;
|
||||
import io.github.hello09x.fakeplayer.manager.action.ActionManager;
|
||||
import io.github.hello09x.fakeplayer.manager.naming.NameManager;
|
||||
import io.github.hello09x.fakeplayer.manager.naming.SequenceName;
|
||||
import io.github.hello09x.fakeplayer.manager.naming.exception.IllegalCustomNameException;
|
||||
import io.github.hello09x.fakeplayer.repository.UsedIdRepository;
|
||||
import io.github.hello09x.fakeplayer.repository.UserConfigRepository;
|
||||
import io.github.hello09x.fakeplayer.repository.model.Configs;
|
||||
import io.github.hello09x.fakeplayer.util.AddressUtils;
|
||||
import io.github.hello09x.fakeplayer.util.Commands;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.entity.FakePlayer;
|
||||
import io.github.hello09x.fakeplayer.core.entity.SpawnOption;
|
||||
import io.github.hello09x.fakeplayer.core.manager.action.ActionManager;
|
||||
import io.github.hello09x.fakeplayer.core.manager.naming.NameManager;
|
||||
import io.github.hello09x.fakeplayer.core.manager.naming.SequenceName;
|
||||
import io.github.hello09x.fakeplayer.core.manager.naming.exception.IllegalCustomNameException;
|
||||
import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository;
|
||||
import io.github.hello09x.fakeplayer.core.repository.UserConfigRepository;
|
||||
import io.github.hello09x.fakeplayer.core.repository.model.Configs;
|
||||
import io.github.hello09x.fakeplayer.core.util.AddressUtils;
|
||||
import io.github.hello09x.fakeplayer.core.util.Commands;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
@ -1,8 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.manager;
|
||||
package io.github.hello09x.fakeplayer.core.manager;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
@ -1,9 +1,9 @@
|
||||
package io.github.hello09x.fakeplayer.manager.action;
|
||||
package io.github.hello09x.fakeplayer.core.manager.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionTicker;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import io.github.hello09x.fakeplayer.api.spi.ActionTicker;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -37,7 +37,7 @@ public class ActionManager {
|
||||
@NotNull ActionSetting setting
|
||||
) {
|
||||
var managers = this.managers.computeIfAbsent(player.getUniqueId(), key -> new HashMap<>());
|
||||
managers.computeIfAbsent(action, key -> ActionTicker.create(player, action, setting));
|
||||
managers.computeIfAbsent(action, key -> Main.getVersionSupport().createAction(player, action, setting));
|
||||
}
|
||||
|
||||
public void tick() {
|
@ -1,9 +1,9 @@
|
||||
package io.github.hello09x.fakeplayer.manager.naming;
|
||||
package io.github.hello09x.fakeplayer.core.manager.naming;
|
||||
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.manager.naming.exception.IllegalCustomNameException;
|
||||
import io.github.hello09x.fakeplayer.repository.UsedIdRepository;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.manager.naming.exception.IllegalCustomNameException;
|
||||
import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.bukkit.Bukkit;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.manager.naming;
|
||||
package io.github.hello09x.fakeplayer.core.manager.naming;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.manager.naming;
|
||||
package io.github.hello09x.fakeplayer.core.manager.naming;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.manager.naming.exception;
|
||||
package io.github.hello09x.fakeplayer.core.manager.naming.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.TextComponent;
|
@ -1,7 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.repository;
|
||||
package io.github.hello09x.fakeplayer.core.repository;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.github.hello09x.fakeplayer.repository;
|
||||
package io.github.hello09x.fakeplayer.core.repository;
|
||||
|
||||
import io.github.hello09x.bedrock.database.Repository;
|
||||
import io.github.hello09x.fakeplayer.Main;
|
||||
import io.github.hello09x.fakeplayer.repository.model.Config;
|
||||
import io.github.hello09x.fakeplayer.repository.model.UserConfig;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.repository.model.Config;
|
||||
import io.github.hello09x.fakeplayer.core.repository.model.UserConfig;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.repository.model;
|
||||
package io.github.hello09x.fakeplayer.core.repository.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.repository.model;
|
||||
package io.github.hello09x.fakeplayer.core.repository.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.repository.model;
|
||||
package io.github.hello09x.fakeplayer.core.repository.model;
|
||||
|
||||
|
||||
import io.github.hello09x.bedrock.database.Table;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.util;
|
||||
package io.github.hello09x.fakeplayer.core.util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.util;
|
||||
package io.github.hello09x.fakeplayer.core.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.util;
|
||||
package io.github.hello09x.fakeplayer.core.util;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.jetbrains.annotations.NotNull;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.util;
|
||||
package io.github.hello09x.fakeplayer.core.util;
|
||||
|
||||
public class Mth {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.util;
|
||||
package io.github.hello09x.fakeplayer.core.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.util;
|
||||
package io.github.hello09x.fakeplayer.core.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.util.update;
|
||||
package io.github.hello09x.fakeplayer.core.util.update;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.AllArgsConstructor;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.util.update;
|
||||
package io.github.hello09x.fakeplayer.core.util.update;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.jetbrains.annotations.NotNull;
|
@ -1,9 +1,11 @@
|
||||
name: fakeplayer
|
||||
version: '${project.version}'
|
||||
main: io.github.hello09x.fakeplayer.Main
|
||||
main: io.github.hello09x.fakeplayer.core.Main
|
||||
api-version: '1.20'
|
||||
author: hello09x
|
||||
website: 'https://github.com/tanyaofei/minecraft-fakeplayer'
|
||||
depend:
|
||||
- CommandAPI
|
||||
|
||||
permissions:
|
||||
fakeplayer.all:
|
||||
|
67
fakeplayer-dist/pom.xml
Normal file
67
fakeplayer-dist/pom.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>io.github.hello09x.fakeplayer</groupId>
|
||||
<artifactId>fakeplayer-parent</artifactId>
|
||||
<version>0.1.9</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>fakeplayer-dist</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.hello09x.fakeplayer</groupId>
|
||||
<artifactId>fakeplayer-v1_20_R1</artifactId>
|
||||
<version>0.1.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.hello09x.fakeplayer</groupId>
|
||||
<artifactId>fakeplayer-v1_20_R2</artifactId>
|
||||
<version>0.1.9</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>../target</directory>
|
||||
<finalName>fakeplayer-${version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,2 @@
|
||||
io.github.hello09x.fakeplayer.v1_20_R1.spi.VersionSupportImpl
|
||||
io.github.hello09x.fakeplayer.v1_20_R2.spi.VersionSupportImpl
|
@ -54,41 +54,7 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>../target</directory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>dev.jorel.commandapi</pattern>
|
||||
<shadedPattern>io.github.hello09x.fakeplayer.shaded.commandapi</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>specialsource-maven-plugin</artifactId>
|
||||
@ -128,13 +94,6 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@ -14,7 +14,7 @@ public class MineAction extends TraceAction {
|
||||
|
||||
private final Current current = new Current();
|
||||
|
||||
protected MineAction(ServerPlayer player) {
|
||||
public MineAction(ServerPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.papermc.paper.entity.LookAnchor;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.Bukkit;
|
@ -1,7 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.Action;
|
||||
import io.github.hello09x.fakeplayer.x.action.util.Tracer;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.v1_20_R1.action.util.Tracer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@ -12,7 +12,7 @@ public class UseAction extends TraceAction {
|
||||
|
||||
private final Current current = new Current();
|
||||
|
||||
protected UseAction(@NotNull ServerPlayer player) {
|
||||
public UseAction(@NotNull ServerPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.action.util;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.action.util;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ClipContext;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.network;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.network;
|
||||
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import net.minecraft.advancements.Advancement;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.network;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.network;
|
||||
|
||||
import io.netty.channel.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.network;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.network;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.PacketSendListener;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.network;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.network;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.MinecraftServer;
|
@ -1,4 +1,4 @@
|
||||
package io.github.hello09x.fakeplayer.x.network;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.network;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
@ -1,24 +1,41 @@
|
||||
package io.github.hello09x.fakeplayer.x.action;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.spi;
|
||||
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.Action;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import io.github.hello09x.fakeplayer.x.nms.NMSServerPlayerImpl;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.v1_20_R1.action.*;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionTicker implements io.github.hello09x.fakeplayer.api.action.ActionTicker {
|
||||
public class ActionTickerImpl implements io.github.hello09x.fakeplayer.api.spi.ActionTicker {
|
||||
|
||||
/**
|
||||
* 行为类型
|
||||
*/
|
||||
public Action action;
|
||||
private final Action action;
|
||||
|
||||
/**
|
||||
* 行为设置
|
||||
*/
|
||||
public ActionSetting setting;
|
||||
private final ActionSetting setting;
|
||||
|
||||
public ActionTickerImpl(@NotNull Player player, @NotNull ActionType action, @NotNull ActionSetting setting) {
|
||||
var handle = ((CraftPlayer) player).getHandle();
|
||||
this.action = switch (action) {
|
||||
case ATTACK -> new AttackAction(handle);
|
||||
case MINE -> new MineAction(handle);
|
||||
case USE -> new UseAction(handle);
|
||||
case JUMP -> new JumpAction(handle);
|
||||
case LOOK_AT_NEAREST_ENTITY -> new StareEntityAction(handle);
|
||||
case DROP_ITEM -> new DropItemAction(handle);
|
||||
case DROP_STACK -> new DropStackAction(handle);
|
||||
case DROP_INVENTORY -> new DropInventoryAction(handle);
|
||||
};
|
||||
this.setting = setting;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
@ -56,22 +73,4 @@ public class ActionTicker implements io.github.hello09x.fakeplayer.api.action.Ac
|
||||
action.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(@NotNull Player player, @NotNull ActionType action, @NotNull ActionSetting setting) {
|
||||
var handle = new NMSServerPlayerImpl(player).getHandle();
|
||||
this.action = switch (action) {
|
||||
case ATTACK -> new AttackAction(handle);
|
||||
case MINE -> new MineAction(handle);
|
||||
case USE -> new UseAction(handle);
|
||||
case JUMP -> new JumpAction(handle);
|
||||
case LOOK_AT_NEAREST_ENTITY -> new StareEntityAction(handle);
|
||||
case DROP_ITEM -> new DropItemAction(handle);
|
||||
case DROP_STACK -> new DropStackAction(handle);
|
||||
case DROP_INVENTORY -> new DropInventoryAction(handle);
|
||||
};
|
||||
|
||||
this.setting = setting;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.x.nms;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.spi;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSEntity;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSEntity;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity;
|
@ -1,9 +1,9 @@
|
||||
package io.github.hello09x.fakeplayer.x.nms;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.spi;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSNetwork;
|
||||
import io.github.hello09x.fakeplayer.x.network.EmptyConnection;
|
||||
import io.github.hello09x.fakeplayer.x.network.EmptyLoginPacketListener;
|
||||
import io.github.hello09x.fakeplayer.x.network.EmptyServerGamePacketListener;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSNetwork;
|
||||
import io.github.hello09x.fakeplayer.v1_20_R1.network.EmptyConnection;
|
||||
import io.github.hello09x.fakeplayer.v1_20_R1.network.EmptyLoginPacketListener;
|
||||
import io.github.hello09x.fakeplayer.v1_20_R1.network.EmptyServerGamePacketListener;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
@ -1,8 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.x.nms;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.spi;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSServer;
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSServerPlayer;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSServer;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSServerPlayer;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
@ -1,6 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.x.nms;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.spi;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSServerLevel;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSServerLevel;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.bukkit.Bukkit;
|
@ -1,9 +1,9 @@
|
||||
package io.github.hello09x.fakeplayer.x.nms;
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.spi;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import io.github.hello09x.fakeplayer.api.Reflections;
|
||||
import io.github.hello09x.fakeplayer.api.nms.NMSServerPlayer;
|
||||
import io.github.hello09x.fakeplayer.x.network.EmptyAdvancements;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSServerPlayer;
|
||||
import io.github.hello09x.fakeplayer.v1_20_R1.network.EmptyAdvancements;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
@ -0,0 +1,54 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R1.spi;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import io.github.hello09x.fakeplayer.api.spi.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class VersionSupportImpl implements VersionSupport {
|
||||
|
||||
private final static Set<String> SUPPORTS = Set.of("1.20", "1.20.1");
|
||||
|
||||
@Override
|
||||
public @NotNull NMSEntity entity(@NotNull Entity entity) {
|
||||
return new NMSEntityImpl(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull NMSServer server(@NotNull Server server) {
|
||||
return new NMSServerImpl(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull NMSServerLevel world(@NotNull World world) {
|
||||
return new NMSServerLevelImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull NMSServerPlayer player(@NotNull Player player) {
|
||||
return new NMSServerPlayerImpl(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull NMSNetwork network() {
|
||||
return new NMSNetworkImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return SUPPORTS.contains(Bukkit.getMinecraftVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionTicker createAction(@NotNull Player player, @NotNull ActionType action, @NotNull ActionSetting setting) {
|
||||
return new ActionTickerImpl(player, action, setting);
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package io.github.hello09x.fakeplayer.x.nms;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.nms.*;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NMSFactoryImpl implements NMSFactory {
|
||||
|
||||
@Override
|
||||
public NMSEntity entity(@NotNull Entity entity) {
|
||||
return new NMSEntityImpl(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSServer server(@NotNull Server server) {
|
||||
return new NMSServerImpl(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSServerLevel world(@NotNull World world) {
|
||||
return new NMSServerLevelImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSServerPlayer player(@NotNull Player player) {
|
||||
return new NMSServerPlayerImpl(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSNetwork network() {
|
||||
return new NMSNetworkImpl();
|
||||
}
|
||||
|
||||
}
|
@ -1 +0,0 @@
|
||||
io.github.hello09x.fakeplayer.x.action.ActionTicker
|
@ -1 +0,0 @@
|
||||
io.github.hello09x.fakeplayer.x.nms.NMSFactoryImpl
|
99
fakeplayer-v1_20_R2/pom.xml
Normal file
99
fakeplayer-v1_20_R2/pom.xml
Normal file
@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>io.github.hello09x.fakeplayer</groupId>
|
||||
<artifactId>fakeplayer-parent</artifactId>
|
||||
<version>0.1.9</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>fakeplayer-v1_20_R2</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<craftbukkit.version>1.20.2-R0.1-SNAPSHOT</craftbukkit.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.hello09x.fakeplayer</groupId>
|
||||
<artifactId>fakeplayer-core</artifactId>
|
||||
<version>0.1.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.hello09x.fakeplayer</groupId>
|
||||
<artifactId>fakeplayer-api</artifactId>
|
||||
<version>0.1.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>${craftbukkit.version}</version>
|
||||
<classifier>remapped-mojang</classifier>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>specialsource-maven-plugin</artifactId>
|
||||
<version>1.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>remap</goal>
|
||||
</goals>
|
||||
<id>remap-obf</id>
|
||||
<configuration>
|
||||
<srgIn>org.spigotmc:minecraft-server:${craftbukkit.version}:txt:maps-mojang</srgIn>
|
||||
<reverse>true</reverse>
|
||||
<remappedDependencies>
|
||||
org.spigotmc:spigot:${craftbukkit.version}:jar:remapped-mojang
|
||||
</remappedDependencies>
|
||||
<remappedArtifactAttached>true</remappedArtifactAttached>
|
||||
<remappedClassifierName>remapped-obf</remappedClassifierName>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>remap</goal>
|
||||
</goals>
|
||||
<id>remap-spigot</id>
|
||||
<configuration>
|
||||
<inputFile>
|
||||
${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
|
||||
</inputFile>
|
||||
<srgIn>org.spigotmc:minecraft-server:${craftbukkit.version}:csrg:maps-spigot</srgIn>
|
||||
<remappedDependencies>org.spigotmc:spigot:${craftbukkit.version}:jar:remapped-obf
|
||||
</remappedDependencies>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,49 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
|
||||
public class AttackAction extends TraceAction {
|
||||
|
||||
private final ServerPlayer player;
|
||||
|
||||
public AttackAction(ServerPlayer player) {
|
||||
super(player);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean tick() {
|
||||
var hit = this.getTarget();
|
||||
if (hit == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hit.getType() != HitResult.Type.ENTITY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var entityHit = (EntityHitResult) hit;
|
||||
player.attack(entityHit.getEntity());
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
player.resetAttackStrengthTicker();
|
||||
player.resetLastActionTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DropInventoryAction implements Action {
|
||||
|
||||
private final ServerPlayer player;
|
||||
|
||||
public DropInventoryAction(@NotNull ServerPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tick() {
|
||||
var inventory = player.getInventory();
|
||||
for (int i = inventory.getContainerSize(); i >= 0; i--) {
|
||||
player.drop(inventory.removeItem(i, inventory.getItem(i).getCount()), false, true);
|
||||
}
|
||||
player.resetLastActionTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DropItemAction implements Action {
|
||||
|
||||
private final ServerPlayer player;
|
||||
|
||||
public DropItemAction(@NotNull ServerPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean tick() {
|
||||
player.resetLastActionTime();
|
||||
player.drop(false);
|
||||
player.resetLastActionTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DropStackAction implements Action {
|
||||
|
||||
public final ServerPlayer player;
|
||||
|
||||
public DropStackAction(@NotNull ServerPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean tick() {
|
||||
player.resetLastActionTime();
|
||||
player.drop(true);
|
||||
player.resetLastActionTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JumpAction implements Action {
|
||||
|
||||
private final ServerPlayer player;
|
||||
|
||||
public JumpAction(@NotNull ServerPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tick() {
|
||||
if (player.onGround()) {
|
||||
player.jumpFromGround();
|
||||
} else {
|
||||
player.setJumping(true);
|
||||
}
|
||||
player.resetLastActionTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
player.setJumping(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minecraft.network.protocol.game.ServerboundPlayerActionPacket.Action.*;
|
||||
|
||||
public class MineAction extends TraceAction {
|
||||
|
||||
private final Current current = new Current();
|
||||
|
||||
public MineAction(ServerPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
public boolean tick() {
|
||||
var hit = this.getTarget();
|
||||
if (hit == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hit.getType() != HitResult.Type.BLOCK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (current.freeze > 0) {
|
||||
current.freeze--;
|
||||
return false;
|
||||
}
|
||||
|
||||
var blockHit = (BlockHitResult) hit;
|
||||
var pos = blockHit.getBlockPos();
|
||||
var side = blockHit.getDirection();
|
||||
|
||||
if (player.blockActionRestricted(player.level(), pos, player.gameMode.getGameModeForPlayer())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (current.pos != null && player.level().getBlockState(current.pos).isAir()) {
|
||||
current.pos = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
var state = player.level().getBlockState(pos);
|
||||
var broken = false;
|
||||
if (player.gameMode.getGameModeForPlayer().isCreative()) {
|
||||
player.gameMode.handleBlockBreakAction(
|
||||
pos,
|
||||
START_DESTROY_BLOCK,
|
||||
side,
|
||||
player.level().getMaxBuildHeight(),
|
||||
-1
|
||||
);
|
||||
current.freeze = 5;
|
||||
} else if (current.pos == null || !current.pos.equals(pos)) {
|
||||
if (current.pos != null) {
|
||||
player.gameMode.handleBlockBreakAction(
|
||||
current.pos,
|
||||
ABORT_DESTROY_BLOCK,
|
||||
side,
|
||||
player.level().getMaxBuildHeight(),
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
player.gameMode.handleBlockBreakAction(
|
||||
pos,
|
||||
START_DESTROY_BLOCK,
|
||||
side,
|
||||
player.level().getMaxBuildHeight(),
|
||||
-1
|
||||
);
|
||||
|
||||
if (!state.isAir() && current.progress == 0) {
|
||||
state.attack(player.level(), pos, player);
|
||||
}
|
||||
|
||||
if (!state.isAir() && state.getDestroyProgress(player, player.level(), pos) >= 1) {
|
||||
current.pos = null;
|
||||
broken = true;
|
||||
} else {
|
||||
current.pos = pos;
|
||||
current.progress = 0;
|
||||
}
|
||||
} else {
|
||||
current.progress += state.getDestroyProgress(player, player.level(), pos);
|
||||
if (current.progress >= 1) {
|
||||
player.gameMode.handleBlockBreakAction(
|
||||
pos,
|
||||
STOP_DESTROY_BLOCK,
|
||||
side,
|
||||
player.level().getMaxBuildHeight(),
|
||||
-1
|
||||
);
|
||||
current.pos = null;
|
||||
current.freeze = 5;
|
||||
broken = true;
|
||||
}
|
||||
player.level().destroyBlockProgress(-1, pos, (int) (current.progress * 10));
|
||||
}
|
||||
|
||||
player.resetLastActionTime();
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
return broken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
public void stop() {
|
||||
if (current.pos == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.level().destroyBlockProgress(-1, current.pos, -1);
|
||||
player.gameMode.handleBlockBreakAction(
|
||||
current.pos,
|
||||
ABORT_DESTROY_BLOCK,
|
||||
Direction.DOWN,
|
||||
player.level().getMaxBuildHeight(),
|
||||
-1
|
||||
);
|
||||
current.pos = null;
|
||||
current.freeze = 0;
|
||||
current.progress = 0;
|
||||
}
|
||||
|
||||
private static class Current {
|
||||
|
||||
/**
|
||||
* 当前左键的目标位置
|
||||
*/
|
||||
@Nullable
|
||||
public BlockPos pos;
|
||||
|
||||
/**
|
||||
* 破坏方块的进度
|
||||
*/
|
||||
public float progress;
|
||||
|
||||
/**
|
||||
* 冷却, 单位: tick
|
||||
*/
|
||||
public int freeze;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.papermc.paper.entity.LookAnchor;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Damageable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StareEntityAction implements Action {
|
||||
|
||||
private final ServerPlayer player;
|
||||
|
||||
public StareEntityAction(@NotNull ServerPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public boolean tick() {
|
||||
var bukkitPlayer = Bukkit.getPlayer(player.getUUID());
|
||||
if (bukkitPlayer == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var target = bukkitPlayer
|
||||
.getNearbyEntities(4.5, 4.5, 4.5)
|
||||
.stream()
|
||||
.filter(e -> e instanceof Damageable)
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
|
||||
if (target == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bukkitPlayer.lookAt(target, LookAnchor.EYES, LookAnchor.EYES);
|
||||
player.resetLastActionTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.v1_20_R2.action.util.Tracer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class TraceAction implements Action {
|
||||
|
||||
protected final ServerPlayer player;
|
||||
|
||||
protected TraceAction(@NotNull ServerPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
protected @Nullable HitResult getTarget() {
|
||||
double reach = player.gameMode.isCreative() ? 5 : 4.5f;
|
||||
return Tracer.rayTrace(player, 1, reach, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UseAction extends TraceAction {
|
||||
|
||||
private final Current current = new Current();
|
||||
|
||||
public UseAction(@NotNull ServerPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
public boolean tick() {
|
||||
if (current.freeze > 0) {
|
||||
current.freeze--;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.isUsingItem()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var hit = this.getTarget();
|
||||
if (hit == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var hand : InteractionHand.values()) {
|
||||
switch (hit.getType()) {
|
||||
case BLOCK -> {
|
||||
player.resetLastActionTime();
|
||||
var world = player.serverLevel();
|
||||
var blockHit = (BlockHitResult) hit;
|
||||
var pos = blockHit.getBlockPos();
|
||||
var side = blockHit.getDirection();
|
||||
if (pos.getY() < player.level().getMaxBuildHeight() - (side == Direction.UP ? 1 : 0) && world.mayInteract(player, pos)) {
|
||||
var result = player.gameMode.useItemOn(player, world, player.getItemInHand(hand), hand, blockHit);
|
||||
if (result.consumesAction()) {
|
||||
player.swing(hand);
|
||||
current.freeze = 3;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
case ENTITY -> {
|
||||
player.resetLastActionTime();
|
||||
var entityHit = (EntityHitResult) hit;
|
||||
var entity = entityHit.getEntity();
|
||||
boolean handWasEmpty = player.getItemInHand(hand).isEmpty();
|
||||
boolean itemFrameEmpty = (entity instanceof ItemFrame) && ((ItemFrame) entity).getItem().isEmpty();
|
||||
var pos = entityHit.getLocation().subtract(entity.getX(), entity.getY(), entity.getZ());
|
||||
if (entity.interactAt(player, pos, hand).consumesAction()) {
|
||||
current.freeze = 3;
|
||||
return true;
|
||||
}
|
||||
if (player.interactOn(entity, hand).consumesAction() && !(handWasEmpty && itemFrameEmpty)) {
|
||||
current.freeze = 3;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
var handItem = player.getItemInHand(hand);
|
||||
if (player.gameMode.useItem(player, player.level(), handItem, hand).consumesAction()) {
|
||||
player.resetLastActionTime();
|
||||
current.freeze = 3;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
this.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
current.freeze = 0;
|
||||
player.releaseUsingItem();
|
||||
}
|
||||
|
||||
private final static class Current {
|
||||
|
||||
/**
|
||||
* 冷却, 单位: tick
|
||||
*/
|
||||
public int freeze;
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.action.util;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.phys.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* copy from fabric carpet mod
|
||||
*/
|
||||
public class Tracer {
|
||||
|
||||
public static @Nullable HitResult rayTrace(
|
||||
@NotNull Entity source,
|
||||
float partialTicks,
|
||||
double reach,
|
||||
boolean fluids
|
||||
) {
|
||||
var blockHit = rayTraceBlocks(source, partialTicks, reach, fluids);
|
||||
double maxSqDist = reach * reach;
|
||||
if (blockHit != null) {
|
||||
maxSqDist = blockHit.getLocation().distanceToSqr(source.getEyePosition(partialTicks));
|
||||
}
|
||||
EntityHitResult entityHit = rayTraceEntities(source, partialTicks, reach, maxSqDist);
|
||||
return entityHit == null ? blockHit : entityHit;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static @Nullable BlockHitResult rayTraceBlocks(
|
||||
@NotNull Entity source,
|
||||
float partialTicks,
|
||||
double reach,
|
||||
boolean fluids
|
||||
) {
|
||||
var pos = source.getEyePosition(partialTicks);
|
||||
var rotation = source.getViewVector(partialTicks);
|
||||
var reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
|
||||
return source.level().clip(new ClipContext(pos, reachEnd, ClipContext.Block.OUTLINE, fluids ?
|
||||
ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, source));
|
||||
}
|
||||
|
||||
public static @Nullable EntityHitResult rayTraceEntities(
|
||||
@NotNull Entity source,
|
||||
float partialTicks,
|
||||
double reach,
|
||||
double maxSqDist
|
||||
) {
|
||||
var pos = source.getEyePosition(partialTicks);
|
||||
var reachVec = source.getViewVector(partialTicks).scale(reach);
|
||||
var box = source.getBoundingBox().expandTowards(reachVec).inflate(1);
|
||||
return rayTraceEntities(source,
|
||||
pos,
|
||||
pos.add(reachVec),
|
||||
box,
|
||||
e -> !e.isSpectator() && e.isPickable(),
|
||||
maxSqDist);
|
||||
}
|
||||
|
||||
public static @Nullable EntityHitResult rayTraceEntities(
|
||||
@NotNull Entity source,
|
||||
@NotNull Vec3 start,
|
||||
@NotNull Vec3 end,
|
||||
@NotNull AABB box,
|
||||
@NotNull Predicate<Entity> predicate,
|
||||
double maxSqDistance
|
||||
) {
|
||||
@SuppressWarnings("resource")
|
||||
var world = source.level();
|
||||
double targetDistance = maxSqDistance;
|
||||
Entity target = null;
|
||||
Vec3 targetHitPos = null;
|
||||
for (Entity current : world.getEntities(source, box, predicate)) {
|
||||
var currentBox = current.getBoundingBox().inflate(current.getPickRadius());
|
||||
var currentHit = currentBox.clip(start, end);
|
||||
if (currentBox.contains(start)) {
|
||||
if (targetDistance >= 0) {
|
||||
target = current;
|
||||
targetHitPos = currentHit.orElse(start);
|
||||
targetDistance = 0;
|
||||
}
|
||||
} else if (currentHit.isPresent()) {
|
||||
var currentHitPos = currentHit.get();
|
||||
var currentDistance = start.distanceToSqr(currentHitPos);
|
||||
if (currentDistance < targetDistance || targetDistance == 0) {
|
||||
if (current.getRootVehicle() == source.getRootVehicle()) {
|
||||
if (targetDistance == 0) {
|
||||
target = current;
|
||||
targetHitPos = currentHitPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
target = current;
|
||||
targetHitPos = currentHitPos;
|
||||
targetDistance = currentDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return target == null ? null : new EntityHitResult(target, targetHitPos);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.network;
|
||||
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.ServerAdvancementManager;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class EmptyAdvancements extends PlayerAdvancements {
|
||||
|
||||
public EmptyAdvancements(
|
||||
DataFixer datafixer,
|
||||
PlayerList playerlist,
|
||||
ServerAdvancementManager manager,
|
||||
Path path,
|
||||
ServerPlayer player
|
||||
) {
|
||||
super(datafixer, playerlist, manager, path, player);
|
||||
this.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean award(AdvancementHolder advancementholder, String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushDirty(ServerPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdvancementProgress getOrStartProgress(AdvancementHolder advancement) {
|
||||
return new AdvancementProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revoke(AdvancementHolder advancement, String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayer(ServerPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedTab(AdvancementHolder advancement) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListening() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.network;
|
||||
|
||||
import io.netty.channel.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class EmptyChannel extends AbstractChannel {
|
||||
private final ChannelConfig config = new DefaultChannelConfig(this);
|
||||
|
||||
private final static EventLoop EVENT_LOOP = new DefaultEventLoop();
|
||||
private final InetAddress address;
|
||||
|
||||
public EmptyChannel(@Nullable Channel parent, @NotNull InetAddress address) {
|
||||
super(parent);
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelConfig config() {
|
||||
config.setAutoRead(true);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBeginRead() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(SocketAddress arg0) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDisconnect() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWrite(ChannelOutboundBuffer arg0) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop arg0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress localAddress0() {
|
||||
return new InetSocketAddress(address, 25565);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMetadata metadata() {
|
||||
return new ChannelMetadata(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return new AbstractUnsafe() {
|
||||
@Override
|
||||
public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
|
||||
safeSetSuccess(promise);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress remoteAddress0() {
|
||||
return new InetSocketAddress(address, 25565);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventLoop eventLoop() {
|
||||
return EVENT_LOOP;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.network;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.PacketSendListener;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class EmptyConnection extends Connection {
|
||||
public EmptyConnection(@NotNull PacketFlow flag, @NotNull InetAddress address) {
|
||||
super(flag);
|
||||
this.channel = new EmptyChannel(null, address);
|
||||
this.address = this.channel.remoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Packet<?> packet, PacketSendListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Packet<?> packet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDisconnection() {
|
||||
super.handleDisconnection();
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.network;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
||||
|
||||
public class EmptyLoginPacketListener extends ServerLoginPacketListenerImpl {
|
||||
public EmptyLoginPacketListener(MinecraftServer server, Connection connection) {
|
||||
super(server, connection);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.network;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
|
||||
public class EmptyServerGamePacketListener extends ServerGamePacketListenerImpl {
|
||||
public EmptyServerGamePacketListener(MinecraftServer minecraftServer, Connection networkManager, ServerPlayer entityPlayer, CommonListenerCookie commonListenerCookie) {
|
||||
super(minecraftServer, networkManager, entityPlayer, commonListenerCookie);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Packet<?> packet) {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package io.github.hello09x.fakeplayer.v1_20_R2.spi;
|
||||
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionSetting;
|
||||
import io.github.hello09x.fakeplayer.api.action.ActionType;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.v1_20_R2.action.*;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionTickerImpl implements io.github.hello09x.fakeplayer.api.spi.ActionTicker {
|
||||
|
||||
/**
|
||||
* 行为类型
|
||||
*/
|
||||
private final Action action;
|
||||
|
||||
/**
|
||||
* 行为设置
|
||||
*/
|
||||
private final ActionSetting setting;
|
||||
|
||||
public ActionTickerImpl(@NotNull Player player, @NotNull ActionType action, @NotNull ActionSetting setting) {
|
||||
var handle = ((CraftPlayer) player).getHandle();
|
||||
this.action = switch (action) {
|
||||
case ATTACK -> new AttackAction(handle);
|
||||
case MINE -> new MineAction(handle);
|
||||
case USE -> new UseAction(handle);
|
||||
case JUMP -> new JumpAction(handle);
|
||||
case LOOK_AT_NEAREST_ENTITY -> new StareEntityAction(handle);
|
||||
case DROP_ITEM -> new DropItemAction(handle);
|
||||
case DROP_STACK -> new DropStackAction(handle);
|
||||
case DROP_INVENTORY -> new DropInventoryAction(handle);
|
||||
};
|
||||
this.setting = setting;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (setting.wait > 0) {
|
||||
setting.wait--;
|
||||
inactiveTick();
|
||||
return;
|
||||
}
|
||||
|
||||
if (setting.times == 0) {
|
||||
inactiveTick();
|
||||
return;
|
||||
}
|
||||
|
||||
var valid = action.tick();
|
||||
if (valid) {
|
||||
if (setting.times > 0) {
|
||||
setting.times--;
|
||||
}
|
||||
setting.wait = setting.interval;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return setting.times <= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
action.inactiveTick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
action.stop();
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user