mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-07-13 21:02:27 +08:00
使用 Guice 组织类
This commit is contained in:
parent
3f6e85aa48
commit
0a9446c252
@ -12,16 +12,6 @@ import java.util.ServiceLoader;
|
||||
|
||||
public interface NMSBridge {
|
||||
|
||||
static @Nullable NMSBridge getInstance() {
|
||||
return ServiceLoader
|
||||
.load(NMSBridge.class, NMSBridge.class.getClassLoader())
|
||||
.stream()
|
||||
.map(ServiceLoader.Provider::get)
|
||||
.filter(NMSBridge::isSupported)
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@NotNull NMSEntity fromEntity(@NotNull Entity entity);
|
||||
|
||||
@NotNull NMSServer fromServer(@NotNull Server server);
|
||||
|
@ -57,6 +57,11 @@
|
||||
<groupId>com.github.jikoo.OpenInv</groupId>
|
||||
<artifactId>openinvapi</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -0,0 +1,57 @@
|
||||
package io.github.hello09x.fakeplayer.core;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSBridge;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.manager.invsee.DefaultInvseeImpl;
|
||||
import io.github.hello09x.fakeplayer.core.manager.invsee.Invsee;
|
||||
import io.github.hello09x.fakeplayer.core.manager.invsee.OpenInvInvseeImpl;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class FakeplayerGuiceModule extends AbstractModule {
|
||||
|
||||
private final Logger log = Main.getInstance().getLogger();
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.bind(FakeplayerConfig.class).toProvider(this::fakeplayerConfig);
|
||||
super.bind(Invsee.class).toProvider(this::invsee);
|
||||
super.bind(NMSBridge.class).toInstance(nmsBridge());
|
||||
}
|
||||
|
||||
private FakeplayerConfig fakeplayerConfig() {
|
||||
return new FakeplayerConfig(Main.getInstance(), "13");
|
||||
}
|
||||
|
||||
private Invsee invsee() {
|
||||
if (Bukkit.getPluginManager().getPlugin("OpenInv") != null) {
|
||||
try {
|
||||
return new OpenInvInvseeImpl();
|
||||
} catch(Throwable e) {
|
||||
log.warning(Throwables.getStackTraceAsString(e));
|
||||
}
|
||||
}
|
||||
|
||||
return new DefaultInvseeImpl();
|
||||
}
|
||||
|
||||
private NMSBridge nmsBridge() {
|
||||
var bridge = ServiceLoader
|
||||
.load(NMSBridge.class, NMSBridge.class.getClassLoader())
|
||||
.stream()
|
||||
.map(ServiceLoader.Provider::get)
|
||||
.filter(NMSBridge::isSupported)
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
|
||||
if (bridge == null) {
|
||||
throw new ExceptionInInitializerError("Unsupported Minecraft version: " + Bukkit.getMinecraftVersion());
|
||||
}
|
||||
return bridge;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.core;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import io.github.hello09x.bedrock.i18n.I18n;
|
||||
import io.github.hello09x.bedrock.i18n.I18nSupported;
|
||||
import io.github.hello09x.bedrock.util.RegistrablePlugin;
|
||||
@ -22,40 +25,50 @@ public final class Main extends RegistrablePlugin implements I18nSupported {
|
||||
@Getter
|
||||
private static Main instance;
|
||||
|
||||
@Getter
|
||||
private static NMSBridge bridge;
|
||||
|
||||
private I18n i18n;
|
||||
|
||||
private Injector injector;
|
||||
|
||||
@Inject
|
||||
FakeplayerConfig config;
|
||||
|
||||
@Inject
|
||||
WildFakeplayerManager wildFakeplayerManager;
|
||||
|
||||
@Inject
|
||||
PlayerListeners playerListeners;
|
||||
|
||||
@Inject
|
||||
FakeplayerListener fakeplayerListener;
|
||||
|
||||
@Inject
|
||||
ReplenishListener replenishListener;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
bridge = NMSBridge.getInstance();
|
||||
if (bridge == null) {
|
||||
throw new ExceptionInInitializerError("Unsupported Minecraft version: " + Bukkit.getMinecraftVersion());
|
||||
}
|
||||
instance = this;
|
||||
injector = Guice.createInjector(new FakeplayerGuiceModule());
|
||||
this.i18n = new I18n(this, "message/message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
|
||||
CommandRegistry.register();
|
||||
injector.injectMembers(this);
|
||||
injector.getInstance(CommandRegistry.class).register();
|
||||
{
|
||||
var messenger = getServer().getMessenger();
|
||||
messenger.registerIncomingPluginChannel(this, "BungeeCord", WildFakeplayerManager.instance);
|
||||
messenger.registerIncomingPluginChannel(this, "BungeeCord", wildFakeplayerManager);
|
||||
messenger.registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
}
|
||||
|
||||
{
|
||||
var manager = getServer().getPluginManager();
|
||||
manager.registerEvents(PlayerListeners.instance, this);
|
||||
manager.registerEvents(FakeplayerListener.instance, this);
|
||||
manager.registerEvents(ReplenishListener.instance, this);
|
||||
manager.registerEvents(playerListeners, this);
|
||||
manager.registerEvents(fakeplayerListener, this);
|
||||
manager.registerEvents(replenishListener, this);
|
||||
}
|
||||
|
||||
if (FakeplayerConfig.instance.isCheckForUpdates()) {
|
||||
if (config.isCheckForUpdates()) {
|
||||
checkForUpdatesAsync();
|
||||
}
|
||||
}
|
||||
@ -108,4 +121,8 @@ public final class Main extends RegistrablePlugin implements I18nSupported {
|
||||
return instance.i18n;
|
||||
}
|
||||
|
||||
public static @NotNull Injector getInjector() {
|
||||
return instance.injector;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import io.github.hello09x.bedrock.command.Usage;
|
||||
import io.github.hello09x.bedrock.i18n.I18n;
|
||||
@ -7,6 +9,7 @@ import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.command.impl.*;
|
||||
import io.github.hello09x.fakeplayer.core.constant.Direction;
|
||||
import io.github.hello09x.fakeplayer.core.manager.invsee.Invsee;
|
||||
import io.github.hello09x.fakeplayer.core.repository.model.Config;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -17,13 +20,63 @@ import static io.github.hello09x.bedrock.command.Commands.*;
|
||||
import static io.github.hello09x.fakeplayer.core.command.CommandSupports.*;
|
||||
|
||||
|
||||
@Singleton
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
public class CommandRegistry {
|
||||
|
||||
private final static I18n i18n = Main.getI18n();
|
||||
|
||||
@Inject
|
||||
private ActionCommand actionCommand;
|
||||
@Inject
|
||||
private CmdCommand cmdCommand;
|
||||
@Inject
|
||||
private ConfigCommand configCommand;
|
||||
@Inject
|
||||
private DistanceCommand distanceCommand;
|
||||
@Inject
|
||||
private ExpmeCommand expmeCommand;
|
||||
@Inject
|
||||
private HoldCommand holdCommand;
|
||||
@Inject
|
||||
private InvseeCommand invseeCommand;
|
||||
@Inject
|
||||
private KillCommand killCommand;
|
||||
@Inject
|
||||
private KillallCommand killallCommand;
|
||||
@Inject
|
||||
private ListCommand listCommand;
|
||||
@Inject
|
||||
private MoveCommand moveCommand;
|
||||
@Inject
|
||||
private ReloadCommand reloadCommand;
|
||||
@Inject
|
||||
private RespawnCommand respawnCommand;
|
||||
@Inject
|
||||
private RideCommand rideCommand;
|
||||
@Inject
|
||||
private RotationCommand rotationCommand;
|
||||
@Inject
|
||||
private SelectCommand selectCommand;
|
||||
@Inject
|
||||
private SetCommand setCommand;
|
||||
@Inject
|
||||
private SkinCommand skinCommand;
|
||||
@Inject
|
||||
private SleepCommand sleepCommand;
|
||||
@Inject
|
||||
private SneakCommand sneakCommand;
|
||||
@Inject
|
||||
private SpawnCommand spawnCommand;
|
||||
@Inject
|
||||
private StatusCommand statusCommand;
|
||||
@Inject
|
||||
private SwapCommand swapCommand;
|
||||
@Inject
|
||||
private TeleportCommand teleportCommand;
|
||||
|
||||
public static void register() {
|
||||
|
||||
public void register() {
|
||||
command("fakeplayer")
|
||||
.withAliases("fp")
|
||||
.withHelp(
|
||||
@ -78,11 +131,11 @@ public class CommandRegistry {
|
||||
.withPermission(Permission.select)
|
||||
.withRequirement(CommandSupports::needSelect)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executesPlayer(SelectCommand.instance::select),
|
||||
.executesPlayer(selectCommand::select),
|
||||
command("selection")
|
||||
.withPermission(Permission.select)
|
||||
.withRequirement(CommandSupports::needSelect)
|
||||
.executesPlayer(SelectCommand.instance::selection),
|
||||
.executesPlayer(selectCommand::selection),
|
||||
|
||||
command("spawn")
|
||||
.withPermission(Permission.spawn)
|
||||
@ -90,51 +143,51 @@ public class CommandRegistry {
|
||||
text("name").withPermission(Permission.spawnName),
|
||||
world("world").withPermission(Permission.spawnLocation),
|
||||
location("location").withPermission(Permission.spawnLocation))
|
||||
.executes(SpawnCommand.instance::spawn),
|
||||
.executes(spawnCommand::spawn),
|
||||
command("kill")
|
||||
.withPermission(Permission.kill)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(targets("names"))
|
||||
.executes(KillCommand.instance::kill),
|
||||
.executes(killCommand::kill),
|
||||
command("list")
|
||||
.withPermission(Permission.list)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(
|
||||
int32("page", 1),
|
||||
int32("size", 1))
|
||||
.executes(ListCommand.instance::list),
|
||||
.executes(listCommand::list),
|
||||
command("distance")
|
||||
.withPermission(Permission.distance)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executesPlayer(DistanceCommand.instance::distance),
|
||||
.executesPlayer(distanceCommand::distance),
|
||||
command("skin")
|
||||
.withPermission(Permission.skin)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withArguments(offlinePlayer("player"))
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(SkinCommand.instance::skin),
|
||||
.executes(skinCommand::skin),
|
||||
command("invsee")
|
||||
.withPermission(Permission.invsee)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executesPlayer(InvseeCommand.instance::invsee),
|
||||
.executesPlayer(invseeCommand::invsee),
|
||||
command("hold")
|
||||
.withPermission(Permission.hold)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withArguments(int32("slot", 1, 9))
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(HoldCommand.instance::hold),
|
||||
.executes(holdCommand::hold),
|
||||
command("status")
|
||||
.withPermission(Permission.status)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(StatusCommand.instance::status),
|
||||
.executes(statusCommand::status),
|
||||
command("respawn")
|
||||
.withRequirement(CommandSupports::hasDeadTarget)
|
||||
.withPermission(Permission.respawn)
|
||||
.withOptionalArguments(target("name", Entity::isDead))
|
||||
.executes(RespawnCommand.instance::respawn),
|
||||
.executes(respawnCommand::respawn),
|
||||
command("set")
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withPermission(Permission.set)
|
||||
@ -143,7 +196,7 @@ public class CommandRegistry {
|
||||
configValue("config", "value")
|
||||
)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(SetCommand.instance::set),
|
||||
.executes(setCommand::set),
|
||||
command("config")
|
||||
.withPermission(Permission.config)
|
||||
.withSubcommands(
|
||||
@ -151,102 +204,102 @@ public class CommandRegistry {
|
||||
.withArguments(
|
||||
config("config"),
|
||||
configValue("config", "value"))
|
||||
.executesPlayer(ConfigCommand.instance::setConfig),
|
||||
.executesPlayer(configCommand::setConfig),
|
||||
command("list")
|
||||
.executes(ConfigCommand.instance::listConfig)
|
||||
.executes(configCommand::listConfig)
|
||||
)
|
||||
.executes(ConfigCommand.instance::listConfig),
|
||||
.executes(configCommand::listConfig),
|
||||
|
||||
command("expme")
|
||||
.withPermission(Permission.expme)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executesPlayer(ExpmeCommand.instance::expme),
|
||||
.executesPlayer(expmeCommand::expme),
|
||||
|
||||
command("tp")
|
||||
.withPermission(Permission.tp)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executesPlayer(TeleportCommand.instance::tp),
|
||||
.executesPlayer(teleportCommand::tp),
|
||||
command("tphere")
|
||||
.withPermission(Permission.tphere)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executesPlayer(TeleportCommand.instance::tphere),
|
||||
.executesPlayer(teleportCommand::tphere),
|
||||
command("tps")
|
||||
.withPermission(Permission.tps)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executesPlayer(TeleportCommand.instance::tps),
|
||||
.executesPlayer(teleportCommand::tps),
|
||||
|
||||
command("attack")
|
||||
.withPermission(Permission.attack)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withSubcommands(newActionCommands(Action.ActionType.ATTACK))
|
||||
.executes(ActionCommand.instance.action(Action.ActionType.ATTACK, Action.ActionSetting.once())),
|
||||
.executes(actionCommand.action(Action.ActionType.ATTACK, Action.ActionSetting.once())),
|
||||
command("mine")
|
||||
.withPermission(Permission.mine)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withSubcommands(newActionCommands(Action.ActionType.MINE))
|
||||
.executes(ActionCommand.instance.action(Action.ActionType.MINE, Action.ActionSetting.once())),
|
||||
.executes(actionCommand.action(Action.ActionType.MINE, Action.ActionSetting.once())),
|
||||
command("use")
|
||||
.withPermission(Permission.use)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withSubcommands(newActionCommands(Action.ActionType.USE))
|
||||
.executes(ActionCommand.instance.action(Action.ActionType.USE, Action.ActionSetting.once())),
|
||||
.executes(actionCommand.action(Action.ActionType.USE, Action.ActionSetting.once())),
|
||||
command("jump")
|
||||
.withPermission(Permission.jump)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withSubcommands(newActionCommands(Action.ActionType.JUMP))
|
||||
.executes(ActionCommand.instance.action(Action.ActionType.JUMP, Action.ActionSetting.once())),
|
||||
.executes(actionCommand.action(Action.ActionType.JUMP, Action.ActionSetting.once())),
|
||||
command("drop")
|
||||
.withPermission(Permission.drop)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withSubcommands(newActionCommands(Action.ActionType.DROP_ITEM))
|
||||
.executes(ActionCommand.instance.action(Action.ActionType.DROP_ITEM, Action.ActionSetting.once())),
|
||||
.executes(actionCommand.action(Action.ActionType.DROP_ITEM, Action.ActionSetting.once())),
|
||||
command("dropstack")
|
||||
.withPermission(Permission.dropstack)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withSubcommands(newActionCommands(Action.ActionType.DROP_STACK))
|
||||
.executes(ActionCommand.instance.action(Action.ActionType.DROP_STACK, Action.ActionSetting.once())),
|
||||
.executes(actionCommand.action(Action.ActionType.DROP_STACK, Action.ActionSetting.once())),
|
||||
command("dropinv")
|
||||
.withPermission(Permission.dropinv)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withSubcommands(newActionCommands(Action.ActionType.DROP_INVENTORY))
|
||||
.executes(ActionCommand.instance.action(Action.ActionType.DROP_INVENTORY, Action.ActionSetting.once())),
|
||||
.executes(actionCommand.action(Action.ActionType.DROP_INVENTORY, Action.ActionSetting.once())),
|
||||
command("sneak")
|
||||
.withPermission(Permission.sneak)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(
|
||||
target("name"),
|
||||
literals("sneaking", List.of("true", "false")))
|
||||
.executes(SneakCommand.instance::sneak),
|
||||
.executes(sneakCommand::sneak),
|
||||
command("look")
|
||||
.withPermission(Permission.look)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withSubcommands(
|
||||
command("north")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.look(Direction.NORTH)),
|
||||
.executes(rotationCommand.look(Direction.NORTH)),
|
||||
command("south")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.look(Direction.SOUTH)),
|
||||
.executes(rotationCommand.look(Direction.SOUTH)),
|
||||
command("west")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.look(Direction.WEST)),
|
||||
.executes(rotationCommand.look(Direction.WEST)),
|
||||
command("east")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.look(Direction.EAST)),
|
||||
.executes(rotationCommand.look(Direction.EAST)),
|
||||
command("up")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.look(Direction.UP)),
|
||||
.executes(rotationCommand.look(Direction.UP)),
|
||||
command("down")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.look(Direction.DOWN)),
|
||||
.executes(rotationCommand.look(Direction.DOWN)),
|
||||
command("at")
|
||||
.withArguments(location("location"))
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance::lookAt),
|
||||
.executes(rotationCommand::lookAt),
|
||||
command("entity")
|
||||
.withOptionalArguments(target("name"))
|
||||
.withSubcommands(newActionCommands(Action.ActionType.LOOK_AT_NEAREST_ENTITY)),
|
||||
@ -268,17 +321,17 @@ public class CommandRegistry {
|
||||
.withSubcommands(
|
||||
command("left")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.turn(-90, 0)),
|
||||
.executes(rotationCommand.turn(-90, 0)),
|
||||
command("right")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.turn(90, 0)),
|
||||
.executes(rotationCommand.turn(90, 0)),
|
||||
command("back")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance.turn(180, 0)),
|
||||
.executes(rotationCommand.turn(180, 0)),
|
||||
command("to")
|
||||
.withArguments(rotation("rotation"))
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RotationCommand.instance::turnTo),
|
||||
.executes(rotationCommand::turnTo),
|
||||
helpCommand(
|
||||
"/fp turn",
|
||||
Usage.of("left", i18n.asString("fakeplayer.command.turn.left.description")),
|
||||
@ -293,16 +346,16 @@ public class CommandRegistry {
|
||||
.withSubcommands(
|
||||
command("forward")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(MoveCommand.instance.move(1, 0)),
|
||||
.executes(moveCommand.move(1, 0)),
|
||||
command("backward")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(MoveCommand.instance.move(-1, 0)),
|
||||
.executes(moveCommand.move(-1, 0)),
|
||||
command("left")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(MoveCommand.instance.move(0, 1)),
|
||||
.executes(moveCommand.move(0, 1)),
|
||||
command("right")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(MoveCommand.instance.move(0, -1)),
|
||||
.executes(moveCommand.move(0, -1)),
|
||||
helpCommand(
|
||||
"/fp move",
|
||||
Usage.of("forward", i18n.asString("fakeplayer.command.move.forward.description")),
|
||||
@ -311,7 +364,7 @@ public class CommandRegistry {
|
||||
Usage.of("right", i18n.asString("fakeplayer.command.move.right.description"))
|
||||
)
|
||||
)
|
||||
.executes(MoveCommand.instance.move(1, 0)),
|
||||
.executes(moveCommand.move(1, 0)),
|
||||
|
||||
command("ride")
|
||||
.withPermission(Permission.ride)
|
||||
@ -319,19 +372,19 @@ public class CommandRegistry {
|
||||
.withSubcommands(
|
||||
command("me")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executesPlayer(RideCommand.instance::rideMe),
|
||||
.executesPlayer(rideCommand::rideMe),
|
||||
command("target")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RideCommand.instance::rideTarget),
|
||||
.executes(rideCommand::rideTarget),
|
||||
command("anything")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RideCommand.instance::rideAnything),
|
||||
.executes(rideCommand::rideAnything),
|
||||
command("vehicle")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RideCommand.instance::rideVehicle),
|
||||
.executes(rideCommand::rideVehicle),
|
||||
command("stop")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(RideCommand.instance::stopRiding),
|
||||
.executes(rideCommand::stopRiding),
|
||||
helpCommand(
|
||||
"/fp ride",
|
||||
Usage.of("me", i18n.asString("fakeplayer.command.ride.me.description")),
|
||||
@ -345,17 +398,17 @@ public class CommandRegistry {
|
||||
.withPermission(Permission.swap)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(SwapCommand.instance::swap),
|
||||
.executes(swapCommand::swap),
|
||||
command("sleep")
|
||||
.withPermission(Permission.sleep)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name", p -> !p.isSleeping()))
|
||||
.executes(SleepCommand.instance::sleep),
|
||||
.executes(sleepCommand::sleep),
|
||||
command("wakeup")
|
||||
.withPermission(Permission.wakeup)
|
||||
.withRequirement(CommandSupports::hasTarget)
|
||||
.withOptionalArguments(target("name", LivingEntity::isSleeping))
|
||||
.executes(SleepCommand.instance::wakeup),
|
||||
.executes(sleepCommand::wakeup),
|
||||
|
||||
command("cmd")
|
||||
.withRequirement(CommandSupports::isCmdAvailable)
|
||||
@ -363,14 +416,14 @@ public class CommandRegistry {
|
||||
target("name"),
|
||||
cmd("command")
|
||||
)
|
||||
.executes(CmdCommand.instance::cmd),
|
||||
.executes(cmdCommand::cmd),
|
||||
|
||||
command("killall")
|
||||
.withPermission(CommandPermission.OP)
|
||||
.executes(KillallCommand.instance::killall),
|
||||
.executes(killallCommand::killall),
|
||||
command("reload")
|
||||
.withPermission(CommandPermission.OP)
|
||||
.executes(ReloadCommand.instance::reload)
|
||||
.executes(reloadCommand::reload)
|
||||
|
||||
).register();
|
||||
}
|
||||
|
@ -30,30 +30,32 @@ import static io.github.hello09x.bedrock.command.Commands.int32;
|
||||
|
||||
public abstract class CommandSupports {
|
||||
|
||||
private final static FakeplayerManager manager = FakeplayerManager.instance;
|
||||
private final static FakeplayerManager manager = Main.getInjector().getInstance(FakeplayerManager.class);
|
||||
|
||||
private final static FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
private final static FakeplayerConfig config = Main.getInjector().getInstance(FakeplayerConfig.class);
|
||||
|
||||
private final static I18n i18n = Main.getI18n();
|
||||
|
||||
private static final ActionCommand actionCommand = Main.getInjector().getInstance(ActionCommand.class);
|
||||
|
||||
public static @NotNull CommandAPICommand[] newActionCommands(@NotNull Action.ActionType action) {
|
||||
return new CommandAPICommand[]{
|
||||
command("once")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(ActionCommand.instance.action(action, Action.ActionSetting.once())),
|
||||
.executes(actionCommand.action(action, Action.ActionSetting.once())),
|
||||
command("continuous")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(ActionCommand.instance.action(action, Action.ActionSetting.continuous())),
|
||||
.executes(actionCommand.action(action, Action.ActionSetting.continuous())),
|
||||
command("stop")
|
||||
.withOptionalArguments(target("name"))
|
||||
.executes(ActionCommand.instance.action(action, Action.ActionSetting.stop())),
|
||||
.executes(actionCommand.action(action, Action.ActionSetting.stop())),
|
||||
command("interval")
|
||||
.withOptionalArguments(
|
||||
int32("interval", 1),
|
||||
target("name"))
|
||||
.executes((sender, args) -> {
|
||||
int interval = (int) args.getOptional("interval").orElse(1);
|
||||
ActionCommand.instance.action(sender, args, action, Action.ActionSetting.interval(interval));
|
||||
actionCommand.action(sender, args, action, Action.ActionSetting.interval(interval));
|
||||
})
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
@ -20,12 +21,20 @@ import java.util.logging.Logger;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
protected final static FakeplayerManager manager = FakeplayerManager.instance;
|
||||
protected final static FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
protected final static NMSBridge bridge = Main.getBridge();
|
||||
protected final static I18n i18n = Main.getI18n();
|
||||
protected final static Logger log = Main.getInstance().getLogger();
|
||||
|
||||
protected final I18n i18n = Main.getI18n();
|
||||
|
||||
@Inject
|
||||
protected NMSBridge bridge;
|
||||
|
||||
@Inject
|
||||
protected FakeplayerManager manager;
|
||||
|
||||
@Inject
|
||||
protected FakeplayerConfig config;
|
||||
|
||||
|
||||
protected @NotNull Player getTarget(@NotNull CommandSender sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
return this.getTarget(sender, args, null);
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import dev.jorel.commandapi.executors.CommandExecutor;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.core.manager.action.ActionManager;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -15,12 +15,15 @@ import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class ActionCommand extends AbstractCommand {
|
||||
|
||||
public final static ActionCommand instance = new ActionCommand();
|
||||
private final ActionManager actionManager;
|
||||
|
||||
private final ActionManager actionManager = ActionManager.instance;
|
||||
@Inject
|
||||
public ActionCommand(ActionManager actionManager) {
|
||||
this.actionManager = actionManager;
|
||||
}
|
||||
|
||||
public @NotNull CommandExecutor action(@NotNull Action.ActionType action, @NotNull Action.ActionSetting setting) {
|
||||
return (sender, args) -> action(sender, args, action, setting.clone());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
@ -14,11 +15,9 @@ import java.util.Objects;
|
||||
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class CmdCommand extends AbstractCommand {
|
||||
|
||||
public final static CmdCommand instance = new CmdCommand();
|
||||
|
||||
/**
|
||||
* 假人执行命令
|
||||
*/
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
@ -27,12 +29,15 @@ import static net.kyori.adventure.text.event.ClickEvent.runCommand;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
import static net.kyori.adventure.text.format.TextDecoration.UNDERLINED;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class ConfigCommand extends AbstractCommand {
|
||||
|
||||
public final static ConfigCommand instance = new ConfigCommand();
|
||||
private final UserConfigManager configManager;
|
||||
|
||||
private final UserConfigManager configManager = UserConfigManager.instance;
|
||||
@Inject
|
||||
public ConfigCommand(UserConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置配置
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.fakeplayer.core.util.Mth;
|
||||
@ -16,11 +17,9 @@ import static net.kyori.adventure.text.Component.*;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class DistanceCommand extends AbstractCommand {
|
||||
|
||||
public final static DistanceCommand instance = new DistanceCommand();
|
||||
|
||||
/**
|
||||
* 查看距离
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.bedrock.io.Experiences;
|
||||
@ -13,12 +14,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class ExpmeCommand extends AbstractCommand {
|
||||
|
||||
|
||||
public final static ExpmeCommand instance = new ExpmeCommand();
|
||||
|
||||
public void expme(@NotNull Player sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
var target = getTarget(sender, args);
|
||||
var exp = Experiences.getExp(target);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -8,11 +9,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Singleton
|
||||
public class HoldCommand extends AbstractCommand {
|
||||
|
||||
public final static HoldCommand instance = new HoldCommand();
|
||||
|
||||
public void hold(@NotNull CommandSender sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
var target = super.getTarget(sender, args);
|
||||
var slot = (int) Objects.requireNonNull(args.get("slot"));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
@ -10,10 +11,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class InvseeCommand extends AbstractCommand {
|
||||
|
||||
public final static InvseeCommand instance = new InvseeCommand();
|
||||
|
||||
/**
|
||||
* 查看背包
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import lombok.AccessLevel;
|
||||
@ -12,11 +13,9 @@ import java.util.StringJoiner;
|
||||
import static net.kyori.adventure.text.Component.*;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class KillCommand extends AbstractCommand {
|
||||
|
||||
public final static KillCommand instance = new KillCommand();
|
||||
|
||||
/**
|
||||
* 移除假人
|
||||
*/
|
||||
|
@ -1,16 +1,15 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class KillallCommand extends AbstractCommand {
|
||||
|
||||
public final static KillallCommand instance = new KillallCommand();
|
||||
|
||||
/**
|
||||
* 移除服务器所有假人
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.bedrock.page.Page;
|
||||
import io.github.hello09x.fakeplayer.core.command.Permission;
|
||||
@ -17,10 +18,9 @@ import static net.kyori.adventure.text.event.ClickEvent.runCommand;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
import static net.kyori.adventure.text.format.TextDecoration.BOLD;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class ListCommand extends AbstractCommand {
|
||||
|
||||
public final static ListCommand instance = new ListCommand();
|
||||
|
||||
private static String toLocationString(@NotNull Location location) {
|
||||
return location.getWorld().getName()
|
||||
|
@ -1,14 +1,13 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.executors.CommandExecutor;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class MoveCommand extends AbstractCommand {
|
||||
|
||||
public final static MoveCommand instance = new MoveCommand();
|
||||
|
||||
/**
|
||||
* 假人移动
|
||||
*/
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import lombok.AccessLevel;
|
||||
@ -9,12 +11,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class ReloadCommand extends AbstractCommand {
|
||||
|
||||
public final static ReloadCommand instance = new ReloadCommand();
|
||||
private final FakeplayerConfig config;
|
||||
|
||||
private final FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
@Inject
|
||||
public ReloadCommand(FakeplayerConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void reload(@NotNull CommandSender sender, @NotNull CommandArguments args) {
|
||||
config.reload(true);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import lombok.AccessLevel;
|
||||
@ -8,11 +9,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class RespawnCommand extends AbstractCommand {
|
||||
|
||||
public final static RespawnCommand instance = new RespawnCommand();
|
||||
|
||||
/**
|
||||
* 重生
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
@ -18,11 +19,9 @@ import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class RideCommand extends AbstractCommand {
|
||||
|
||||
public final static RideCommand instance = new RideCommand();
|
||||
|
||||
/**
|
||||
* 骑最近的实体
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import dev.jorel.commandapi.executors.CommandExecutor;
|
||||
@ -7,8 +8,6 @@ import dev.jorel.commandapi.wrappers.Rotation;
|
||||
import io.github.hello09x.fakeplayer.core.constant.Direction;
|
||||
import io.github.hello09x.fakeplayer.core.util.Mth;
|
||||
import io.papermc.paper.entity.LookAnchor;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,12 +15,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class RotationCommand extends AbstractCommand {
|
||||
|
||||
public final static RotationCommand instance = new RotationCommand();
|
||||
|
||||
/**
|
||||
* 看向给定坐标
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -9,10 +10,9 @@ import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
@Singleton
|
||||
public class SelectCommand extends AbstractCommand {
|
||||
|
||||
public final static SelectCommand instance = new SelectCommand();
|
||||
|
||||
public void select(@NotNull Player sender, @NotNull CommandArguments args) {
|
||||
var target = this.getTargetNullable(sender, args);
|
||||
manager.setSelection(sender, target);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
@ -15,11 +16,9 @@ import java.util.Objects;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class SetCommand extends AbstractCommand {
|
||||
|
||||
public final static SetCommand instance = new SetCommand();
|
||||
|
||||
public void set(@NotNull CommandSender sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
var target = super.getTarget(sender, args);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
@ -16,13 +17,12 @@ import java.util.Objects;
|
||||
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.RED;
|
||||
|
||||
@Singleton
|
||||
public class SkinCommand extends AbstractCommand {
|
||||
|
||||
public final static SkinCommand instance = new SkinCommand();
|
||||
|
||||
private final Map<CommandSender, MutableInt> spams = new HashMap<>();
|
||||
|
||||
private SkinCommand() {
|
||||
public SkinCommand() {
|
||||
Bukkit.getScheduler().runTaskTimer(Main.getInstance(), () -> {
|
||||
spams.entrySet().removeIf(counter -> counter.getValue().decrementAndGet() <= 0);
|
||||
}, 0, 1);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.bedrock.util.Blocks;
|
||||
@ -9,11 +10,9 @@ import org.bukkit.block.data.type.Bed;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class SleepCommand extends AbstractCommand {
|
||||
|
||||
public final static SleepCommand instance = new SleepCommand();
|
||||
|
||||
/**
|
||||
* 睡觉
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import lombok.AccessLevel;
|
||||
@ -7,11 +8,9 @@ import lombok.NoArgsConstructor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class SneakCommand extends AbstractCommand {
|
||||
|
||||
public final static SneakCommand instance = new SneakCommand();
|
||||
|
||||
/**
|
||||
* 设置潜行
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.bedrock.command.MessageException;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
@ -25,11 +26,9 @@ import java.util.Optional;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class SpawnCommand extends AbstractCommand {
|
||||
|
||||
public final static SpawnCommand instance = new SpawnCommand();
|
||||
|
||||
private final static DateTimeFormatter REMOVE_AT_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
|
||||
|
||||
private static String toLocationString(@NotNull Location location) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.bedrock.io.Experiences;
|
||||
@ -30,11 +31,9 @@ import static net.kyori.adventure.text.event.ClickEvent.runCommand;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
import static net.kyori.adventure.text.format.TextDecoration.UNDERLINED;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class StatusCommand extends AbstractCommand {
|
||||
|
||||
public final static StatusCommand instance = new StatusCommand();
|
||||
|
||||
private final static Component LINE_SPLITTER = text(StringUtils.repeat("-", 20), GRAY);
|
||||
|
||||
private static @NotNull NamedTextColor color(double current, double max) {
|
||||
|
@ -1,16 +1,15 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Singleton
|
||||
public class SwapCommand extends AbstractCommand {
|
||||
|
||||
public final static SwapCommand instance = new SwapCommand();
|
||||
|
||||
/**
|
||||
* 交换主副手物品
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.command.impl;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.github.hello09x.bedrock.util.Teleportor;
|
||||
@ -11,11 +12,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.RED;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class TeleportCommand extends AbstractCommand {
|
||||
|
||||
public final static TeleportCommand instance = new TeleportCommand();
|
||||
|
||||
/**
|
||||
* 传送到假人
|
||||
*/
|
||||
|
@ -36,7 +36,6 @@ public class FakeplayerConfig extends Config<FakeplayerConfig> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 每位玩家最多多少个假人
|
||||
*/
|
||||
|
@ -40,11 +40,11 @@ public class FakePlayer {
|
||||
|
||||
private final static InternalAddressGenerator ipGen = new InternalAddressGenerator();
|
||||
|
||||
private final static FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
private final static FakeplayerConfig config = Main.getInjector().getInstance(FakeplayerConfig.class);
|
||||
|
||||
private final static I18n i18n = Main.getI18n();
|
||||
|
||||
private final static NMSBridge bridge = Main.getBridge();
|
||||
private final static NMSBridge bridge = Main.getInjector().getInstance(NMSBridge.class);
|
||||
|
||||
@NotNull
|
||||
@Getter
|
||||
@ -158,13 +158,13 @@ public class FakePlayer {
|
||||
this.player.setCollidable(option.collidable());
|
||||
this.player.setCanPickupItems(option.pickupItems());
|
||||
if (option.lookAtEntity()) {
|
||||
ActionManager.instance.setAction(player, Action.ActionType.LOOK_AT_NEAREST_ENTITY, Action.ActionSetting.continuous());
|
||||
Main.getInjector().getInstance(ActionManager.class).setAction(player, Action.ActionType.LOOK_AT_NEAREST_ENTITY, Action.ActionSetting.continuous());
|
||||
}
|
||||
if (option.skin() && this.creator instanceof Player playerCreator) {
|
||||
Skins.copySkin(playerCreator, this.player);
|
||||
}
|
||||
if (option.replenish()) {
|
||||
FakeplayerManager.instance.setReplenish(player, true);
|
||||
Main.getInjector().getInstance(FakeplayerManager.class).setReplenish(player, true);
|
||||
}
|
||||
|
||||
this.network = bridge.createNetwork(address);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.entity;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSServerPlayer;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -8,8 +9,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FakeplayerTicker extends BukkitRunnable {
|
||||
|
||||
private final static FakeplayerManager manager = FakeplayerManager.instance;
|
||||
|
||||
public final static long NO_REMOVE_AT = -1;
|
||||
|
||||
@NotNull
|
||||
@ -43,7 +42,7 @@ public class FakeplayerTicker extends BukkitRunnable {
|
||||
}
|
||||
|
||||
if (this.removeAt != NO_REMOVE_AT && this.player.getTickCount() % 20 == 0 && System.currentTimeMillis() > removeAt) {
|
||||
manager.remove(player.getName(), "lifespan ends");
|
||||
Main.getInjector().getInstance(FakeplayerManager.class).remove(player.getName(), "lifespan ends");
|
||||
super.cancel();
|
||||
return;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.entity.action;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.ActionTicker;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSBridge;
|
||||
@ -8,11 +9,9 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class BaseActionTicker implements ActionTicker {
|
||||
|
||||
protected final static NMSBridge bridge = Objects.requireNonNull(NMSBridge.getInstance(), "Unsupported");
|
||||
protected final NMSBridge bridge;
|
||||
|
||||
/**
|
||||
* 这个类无法初始化的动作, 由子类完成
|
||||
@ -23,14 +22,15 @@ public abstract class BaseActionTicker implements ActionTicker {
|
||||
@NotNull
|
||||
protected Action.ActionSetting setting;
|
||||
|
||||
public BaseActionTicker(@NotNull Player player, @NotNull Action.ActionType action, @NotNull Action.ActionSetting setting) {
|
||||
public BaseActionTicker(NMSBridge nms, @NotNull Player player, @NotNull Action.ActionType action, @NotNull Action.ActionSetting setting) {
|
||||
this.bridge = nms;
|
||||
this.setting = setting;
|
||||
this.action = switch (action) {
|
||||
case JUMP -> new JumpAction(bridge.fromPlayer(player));
|
||||
case LOOK_AT_NEAREST_ENTITY -> new LookAtEntityAction(bridge.fromPlayer(player));
|
||||
case DROP_ITEM -> new DropItemAction(bridge.fromPlayer(player));
|
||||
case DROP_STACK -> new DropStackAction(bridge.fromPlayer(player));
|
||||
case DROP_INVENTORY -> new DropInventoryAction(bridge.fromPlayer(player));
|
||||
case JUMP -> new JumpAction(nms.fromPlayer(player));
|
||||
case LOOK_AT_NEAREST_ENTITY -> new LookAtEntityAction(nms.fromPlayer(player));
|
||||
case DROP_ITEM -> new DropItemAction(nms.fromPlayer(player));
|
||||
case DROP_STACK -> new DropStackAction(nms.fromPlayer(player));
|
||||
case DROP_INVENTORY -> new DropInventoryAction(nms.fromPlayer(player));
|
||||
default -> null; // 子类需要实现其他 Action
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.core.listener;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.bedrock.i18n.I18n;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
@ -25,16 +27,24 @@ import java.util.logging.Logger;
|
||||
import static net.kyori.adventure.text.Component.*;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
|
||||
@Singleton
|
||||
public class FakeplayerListener implements Listener {
|
||||
|
||||
public final static FakeplayerListener instance = new FakeplayerListener();
|
||||
private final static Logger log = Main.getInstance().getLogger();
|
||||
private final FakeplayerManager manager = FakeplayerManager.instance;
|
||||
private final FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
private final UsedIdRepository usedIdRepository = UsedIdRepository.instance;
|
||||
|
||||
private final FakeplayerManager manager;
|
||||
private final UsedIdRepository usedIdRepository;
|
||||
private final FakeplayerConfig config;
|
||||
|
||||
private final I18n i18n = Main.getI18n();
|
||||
|
||||
@Inject
|
||||
public FakeplayerListener(FakeplayerManager manager, UsedIdRepository usedIdRepository, FakeplayerConfig config) {
|
||||
this.manager = manager;
|
||||
this.usedIdRepository = usedIdRepository;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拒绝真实玩家使用假人用过的 ID 登陆
|
||||
*/
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -11,10 +13,15 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Singleton
|
||||
public class PlayerListeners implements Listener {
|
||||
|
||||
public final static PlayerListeners instance = new PlayerListeners();
|
||||
private final FakeplayerManager manager = FakeplayerManager.instance;
|
||||
private final FakeplayerManager manager;
|
||||
|
||||
@Inject
|
||||
public PlayerListeners(FakeplayerManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家蹲伏时取消假人骑乘
|
||||
|
@ -2,6 +2,8 @@ package io.github.hello09x.fakeplayer.core.listener;
|
||||
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.bedrock.util.Blocks;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.command.Permission;
|
||||
@ -28,12 +30,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class ReplenishListener implements Listener {
|
||||
|
||||
public final static ReplenishListener instance = new ReplenishListener();
|
||||
private final FakeplayerManager manager;
|
||||
|
||||
private final FakeplayerManager manager = FakeplayerManager.instance;
|
||||
private final FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
@Inject
|
||||
public ReplenishListener(FakeplayerManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗物品自动填装
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.manager;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.fakeplayer.core.entity.FakePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -8,10 +9,9 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Singleton
|
||||
public class FakeplayerList {
|
||||
|
||||
public final static FakeplayerList instance = new FakeplayerList();
|
||||
|
||||
private final Map<String, FakePlayer> playersByName = new HashMap<>();
|
||||
|
||||
private final Map<UUID, FakePlayer> playersByUUID = new HashMap<>();
|
||||
|
@ -1,9 +1,12 @@
|
||||
package io.github.hello09x.fakeplayer.core.manager;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.bedrock.command.MessageException;
|
||||
import io.github.hello09x.bedrock.i18n.I18n;
|
||||
import io.github.hello09x.bedrock.util.AddressUtils;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSBridge;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import io.github.hello09x.fakeplayer.core.constant.MetadataKeys;
|
||||
@ -43,27 +46,30 @@ import static net.kyori.adventure.text.Component.textOfChildren;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
import static net.kyori.adventure.text.format.TextDecoration.ITALIC;
|
||||
|
||||
@Singleton
|
||||
public class FakeplayerManager {
|
||||
|
||||
public final static FakeplayerManager instance = new FakeplayerManager();
|
||||
|
||||
private final static Logger log = Main.getInstance().getLogger();
|
||||
|
||||
private final FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
|
||||
private final UsedIdRepository usedIdRepository = UsedIdRepository.instance;
|
||||
|
||||
private final NameManager nameManager = NameManager.instance;
|
||||
|
||||
private final FakeplayerList playerList = FakeplayerList.instance;
|
||||
|
||||
private final UserConfigManager configManager = UserConfigManager.instance;
|
||||
|
||||
private final I18n i18n = Main.getI18n();
|
||||
private final Invsee invsee;
|
||||
|
||||
private final Invsee invsee = Invsee.getInstance();
|
||||
private final UsedIdRepository usedIdRepository;
|
||||
private final NameManager nameManager;
|
||||
private final FakeplayerList playerList;
|
||||
private final UserConfigManager configManager;
|
||||
private final NMSBridge nms;
|
||||
private final FakeplayerConfig config;
|
||||
|
||||
@Inject
|
||||
public FakeplayerManager(Invsee invsee, UsedIdRepository usedIdRepository, NameManager nameManager, FakeplayerList playerList, UserConfigManager configManager, NMSBridge nms, FakeplayerConfig config) {
|
||||
this.invsee = invsee;
|
||||
this.usedIdRepository = usedIdRepository;
|
||||
this.nameManager = nameManager;
|
||||
this.playerList = playerList;
|
||||
this.configManager = configManager;
|
||||
this.nms = nms;
|
||||
this.config = config;
|
||||
|
||||
private FakeplayerManager() {
|
||||
var timer = Executors.newSingleThreadScheduledExecutor();
|
||||
timer.scheduleWithFixedDelay(() -> {
|
||||
if (Bukkit.getServer().getTPS()[1] < config.getKaleTps()) {
|
||||
@ -273,7 +279,7 @@ public class FakeplayerManager {
|
||||
}
|
||||
this.nameManager.unregister(fakeplayer.getSequenceName());
|
||||
if (config.isDropInventoryOnQuiting()) {
|
||||
Main.getBridge().createAction(
|
||||
this.nms.createAction(
|
||||
fakeplayer.getPlayer(),
|
||||
Action.ActionType.DROP_INVENTORY,
|
||||
Action.ActionSetting.once()
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.manager;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.fakeplayer.core.repository.UserConfigRepository;
|
||||
import io.github.hello09x.fakeplayer.core.repository.model.Config;
|
||||
import lombok.AccessLevel;
|
||||
@ -12,12 +14,15 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Singleton
|
||||
public class UserConfigManager {
|
||||
|
||||
public final static UserConfigManager instance = new UserConfigManager();
|
||||
private final UserConfigRepository repository;
|
||||
|
||||
private final UserConfigRepository repository = UserConfigRepository.instance;
|
||||
@Inject
|
||||
public UserConfigManager(UserConfigRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置值
|
||||
|
@ -1,6 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.core.manager;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -13,9 +15,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class WildFakeplayerManager implements PluginMessageListener {
|
||||
|
||||
public final static WildFakeplayerManager instance = new WildFakeplayerManager();
|
||||
private final static Logger log = Main.getInstance().getLogger();
|
||||
private final static boolean IS_BUNGEECORD = Bukkit
|
||||
.getServer()
|
||||
@ -33,11 +35,14 @@ public class WildFakeplayerManager implements PluginMessageListener {
|
||||
private final static int CLEANUP_THRESHOLD = 2;
|
||||
private final static int CLEANUP_PERIOD = 6000;
|
||||
|
||||
private final FakeplayerManager manager = FakeplayerManager.instance;
|
||||
private final FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
private final FakeplayerManager manager;
|
||||
private final FakeplayerConfig config;
|
||||
private final Map<String, AtomicInteger> offline = new HashMap<>();
|
||||
|
||||
public WildFakeplayerManager() {
|
||||
@Inject
|
||||
public WildFakeplayerManager(FakeplayerManager manager, FakeplayerConfig config) {
|
||||
this.manager = manager;
|
||||
this.config = config;
|
||||
Bukkit.getScheduler().runTaskTimer(Main.getInstance(), this::cleanup, 0, CLEANUP_PERIOD);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.manager.action;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.ActionTicker;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSBridge;
|
||||
@ -12,15 +14,16 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Singleton
|
||||
public class ActionManager {
|
||||
|
||||
public final static ActionManager instance = new ActionManager();
|
||||
|
||||
private final Map<UUID, Map<Action.ActionType, ActionTicker>> managers = new HashMap<>();
|
||||
|
||||
private final NMSBridge bridge = Main.getBridge();
|
||||
private final NMSBridge bridge;
|
||||
|
||||
public ActionManager() {
|
||||
@Inject
|
||||
public ActionManager(NMSBridge bridge) {
|
||||
this.bridge = bridge;
|
||||
Bukkit.getScheduler().runTaskTimer(Main.getInstance(), this::tick, 0, 1);
|
||||
}
|
||||
|
||||
|
@ -1,38 +1,11 @@
|
||||
package io.github.hello09x.fakeplayer.core.manager.invsee;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public interface Invsee {
|
||||
|
||||
|
||||
static @NotNull Invsee getInstance() {
|
||||
return ImplHolder.instance;
|
||||
}
|
||||
|
||||
|
||||
void openInventory(@NotNull Player visitor, @NotNull Player visited);
|
||||
|
||||
class ImplHolder {
|
||||
|
||||
static Invsee instance;
|
||||
|
||||
static {
|
||||
if (Bukkit.getPluginManager().getPlugin("OpenInv") != null) {
|
||||
try {
|
||||
instance = new OpenInvInvseeImpl();
|
||||
} catch (Throwable e) {
|
||||
Main.getInstance().getLogger().warning(Throwables.getStackTraceAsString(e));
|
||||
}
|
||||
} else {
|
||||
instance = new DefaultInvseeImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.core.manager.naming;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.bedrock.i18n.I18n;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||
@ -25,22 +27,26 @@ import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.RED;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
@Singleton
|
||||
public class NameManager {
|
||||
|
||||
public final static NameManager instance = new NameManager();
|
||||
private final static Logger log = Main.getInstance().getLogger();
|
||||
private final static int MAX_LENGTH = 16; // mojang required
|
||||
private final static int MIN_LENGTH = 3; // mojang required
|
||||
private final static String FALLBACK_NAME = "_fp_";
|
||||
|
||||
private final UsedIdRepository usedIdRepository = UsedIdRepository.instance;
|
||||
private final FakeplayerConfig config = FakeplayerConfig.instance;
|
||||
private final UsedIdRepository usedIdRepository;
|
||||
private final FakeplayerConfig config;
|
||||
private final Map<String, NameSource> nameSources = new HashMap<>();
|
||||
private final I18n i18n = Main.getI18n();
|
||||
|
||||
private final String serverId;
|
||||
|
||||
public NameManager() {
|
||||
@Inject
|
||||
public NameManager(UsedIdRepository usedIdRepository, FakeplayerConfig config) {
|
||||
this.usedIdRepository = usedIdRepository;
|
||||
this.config = config;
|
||||
|
||||
var file = new File(Main.getInstance().getDataFolder(), "serverid");
|
||||
serverId = Optional.ofNullable(loadServerId(file)).orElseGet(() -> {
|
||||
var uuid = UUID.randomUUID().toString();
|
||||
|
@ -1,6 +1,8 @@
|
||||
package io.github.hello09x.fakeplayer.core.repository;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -14,14 +16,15 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Singleton
|
||||
public class UsedIdRepository {
|
||||
|
||||
|
||||
public final static UsedIdRepository instance = new UsedIdRepository();
|
||||
private final static Logger log = Main.getInstance().getLogger();
|
||||
|
||||
private final Set<UUID> UUIDS = new HashSet<>();
|
||||
|
||||
@Inject
|
||||
public UsedIdRepository() {
|
||||
this.load();
|
||||
Main.getInstance().registerOnDisable(this::saveAll);
|
||||
|
@ -1,10 +1,10 @@
|
||||
package io.github.hello09x.fakeplayer.core.repository;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.hello09x.bedrock.database.Repository;
|
||||
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;
|
||||
|
||||
@ -14,12 +14,11 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Singleton
|
||||
public class UserConfigRepository extends Repository<UserConfig> {
|
||||
|
||||
public final static UserConfigRepository instance = new UserConfigRepository(Main.getInstance());
|
||||
|
||||
public UserConfigRepository(Plugin plugin) {
|
||||
super(plugin);
|
||||
public UserConfigRepository() {
|
||||
super(Main.getInstance());
|
||||
}
|
||||
|
||||
public @Nullable String select(@NotNull UUID playerId, @NotNull Config<?> config) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.hello09x.fakeplayer.core.repository.model;
|
||||
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.command.Permission;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import net.kyori.adventure.translation.Translatable;
|
||||
@ -132,7 +133,7 @@ public record Config<T>(
|
||||
List.of("true", "false"),
|
||||
Permission.replenish,
|
||||
Boolean::valueOf,
|
||||
new Accessor<>(FakeplayerManager.instance::isReplenish, FakeplayerManager.instance::setReplenish)
|
||||
new Accessor<>(Main.getInjector().getInstance(FakeplayerManager.class)::isReplenish, Main.getInjector().getInstance(FakeplayerManager.class)::setReplenish)
|
||||
);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -22,7 +22,7 @@ import java.util.logging.Logger;
|
||||
|
||||
public class FakeServerGamePacketListenerImpl extends ServerGamePacketListenerImpl implements NMSServerGamePacketListener {
|
||||
|
||||
private final static FakeplayerManager manager = FakeplayerManager.instance;
|
||||
private final FakeplayerManager manager = Main.getInjector().getInstance(FakeplayerManager.class);
|
||||
private final static Logger log = Main.getInstance().getLogger();
|
||||
|
||||
public FakeServerGamePacketListenerImpl(
|
||||
|
@ -3,6 +3,7 @@ package io.github.hello09x.fakeplayer.v1_21_R1.spi;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.Action;
|
||||
import io.github.hello09x.fakeplayer.api.spi.ActionTicker;
|
||||
import io.github.hello09x.fakeplayer.api.spi.NMSBridge;
|
||||
import io.github.hello09x.fakeplayer.core.entity.action.BaseActionTicker;
|
||||
import io.github.hello09x.fakeplayer.v1_21_R1.action.AttackAction;
|
||||
import io.github.hello09x.fakeplayer.v1_21_R1.action.MineAction;
|
||||
@ -13,8 +14,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionTickerImpl extends BaseActionTicker implements ActionTicker {
|
||||
|
||||
public ActionTickerImpl(@NotNull Player player, @NotNull Action.ActionType action, @NotNull Action.ActionSetting setting) {
|
||||
super(player, action, setting);
|
||||
public ActionTickerImpl(@NotNull NMSBridge nms, @NotNull Player player, @NotNull Action.ActionType action, @NotNull Action.ActionSetting setting) {
|
||||
super(nms, player, action, setting);
|
||||
if (this.action == null) {
|
||||
this.action = switch (action) {
|
||||
case ATTACK -> new AttackAction(((CraftPlayer) player).getHandle());
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.hello09x.fakeplayer.v1_21_R1.spi;
|
||||
|
||||
import io.github.hello09x.fakeplayer.api.spi.*;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
@ -47,7 +48,7 @@ public class NMSBridgeImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public @NotNull ActionTicker createAction(@NotNull Player player, @NotNull Action.ActionType action, @NotNull Action.ActionSetting setting) {
|
||||
return new ActionTickerImpl(player, action, setting);
|
||||
return new ActionTickerImpl(Main.getInjector().getInstance(NMSBridge.class), player, action, setting);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user