mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
Fix bot (#705)
* refactor: refactor bot * fix: fix use * fix: fix use * fix: fix
This commit is contained in:
@@ -8,20 +8,20 @@ import org.bukkit.Bukkit;
|
||||
public interface UseItemAction extends TimerBotAction<UseItemAction> {
|
||||
|
||||
/**
|
||||
* Gets the equivalent right-click hold duration in ticks.
|
||||
* Default is -1, which means will not be released.
|
||||
* Gets the equivalent right-click hold duration timeout in ticks.
|
||||
* Default is -1, which means no timeout.
|
||||
*
|
||||
* @return the equivalent right-click hold duration
|
||||
* @return the equivalent right-click hold duration timeout
|
||||
*/
|
||||
int getUseTick();
|
||||
int getUseTickTimeout();
|
||||
|
||||
/**
|
||||
* Sets the equivalent right-click hold duration in ticks.
|
||||
* Sets the equivalent right-click hold duration timeout in ticks.
|
||||
*
|
||||
* @param useTick the equivalent right-click hold duration
|
||||
* @param timeout the equivalent right-click hold duration timeout
|
||||
* @return this action instance
|
||||
*/
|
||||
UseItemAction setUseTick(int useTick);
|
||||
UseItemAction setUseTickTimeout(int timeout);
|
||||
|
||||
static UseItemAction create() {
|
||||
return Bukkit.getBotManager().newAction(UseItemAction.class);
|
||||
|
||||
@@ -8,20 +8,20 @@ import org.bukkit.Bukkit;
|
||||
public interface UseItemAutoAction extends TimerBotAction<UseItemAutoAction> {
|
||||
|
||||
/**
|
||||
* Gets the equivalent right-click hold duration in ticks.
|
||||
* Default is -1, which means will not be released.
|
||||
* Gets the equivalent right-click hold duration timeout in ticks.
|
||||
* Default is -1, which means no timeout.
|
||||
*
|
||||
* @return the equivalent right-click hold duration
|
||||
* @return the equivalent right-click hold duration timeout
|
||||
*/
|
||||
int getUseTick();
|
||||
int getUseTickTimeout();
|
||||
|
||||
/**
|
||||
* Sets the equivalent right-click hold duration in ticks.
|
||||
* Sets the equivalent right-click hold duration timeout in ticks.
|
||||
*
|
||||
* @param useTick the equivalent right-click hold duration
|
||||
* @param timeout the equivalent right-click hold duration timeout
|
||||
* @return this action instance
|
||||
*/
|
||||
UseItemAutoAction setUseTick(int useTick);
|
||||
UseItemAutoAction setUseTickTimeout(int timeout);
|
||||
|
||||
static UseItemAutoAction create() {
|
||||
return Bukkit.getBotManager().newAction(UseItemAutoAction.class);
|
||||
|
||||
@@ -8,20 +8,20 @@ import org.bukkit.Bukkit;
|
||||
public interface UseItemOffhandAction extends TimerBotAction<UseItemOffhandAction> {
|
||||
|
||||
/**
|
||||
* Gets the equivalent right-click hold duration in ticks.
|
||||
* Default is -1, which means will not be released.
|
||||
* Gets the equivalent right-click hold duration timeout in ticks.
|
||||
* Default is -1, which means no timeout.
|
||||
*
|
||||
* @return the equivalent right-click hold duration
|
||||
* @return the equivalent right-click hold duration timeout
|
||||
*/
|
||||
int getUseTick();
|
||||
int getUseTickTimeout();
|
||||
|
||||
/**
|
||||
* Sets the equivalent right-click hold duration in ticks.
|
||||
* Sets the equivalent right-click hold duration timeout in ticks.
|
||||
*
|
||||
* @param useTick the equivalent right-click hold duration
|
||||
* @param timeout the equivalent right-click hold duration timeout
|
||||
* @return this action instance
|
||||
*/
|
||||
UseItemOffhandAction setUseTick(int useTick);
|
||||
UseItemOffhandAction setUseTickTimeout(int timeout);
|
||||
|
||||
static UseItemOffhandAction create() {
|
||||
return Bukkit.getBotManager().newAction(UseItemOffhandAction.class);
|
||||
|
||||
@@ -8,20 +8,20 @@ import org.bukkit.Bukkit;
|
||||
public interface UseItemOnAction extends TimerBotAction<UseItemOnAction> {
|
||||
|
||||
/**
|
||||
* Gets the equivalent right-click hold duration in ticks.
|
||||
* Default is -1, which means will not be released.
|
||||
* Gets the equivalent right-click hold duration timeout in ticks.
|
||||
* Default is -1, which means no timeout.
|
||||
*
|
||||
* @return the equivalent right-click hold duration
|
||||
* @return the equivalent right-click hold duration timeout
|
||||
*/
|
||||
int getUseTick();
|
||||
int getUseTickTimeout();
|
||||
|
||||
/**
|
||||
* Sets the equivalent right-click hold duration in ticks.
|
||||
* Sets the equivalent right-click hold duration timeout in ticks.
|
||||
*
|
||||
* @param useTick the equivalent right-click hold duration
|
||||
* @param timeout the equivalent right-click hold duration timeout
|
||||
* @return this action instance
|
||||
*/
|
||||
UseItemOnAction setUseTick(int useTick);
|
||||
UseItemOnAction setUseTickTimeout(int timeout);
|
||||
|
||||
static UseItemOnAction create() {
|
||||
return Bukkit.getBotManager().newAction(UseItemOnAction.class);
|
||||
|
||||
@@ -8,20 +8,20 @@ import org.bukkit.Bukkit;
|
||||
public interface UseItemOnOffhandAction extends TimerBotAction<UseItemOnOffhandAction> {
|
||||
|
||||
/**
|
||||
* Gets the equivalent right-click hold duration in ticks.
|
||||
* Default is -1, which means will not be released.
|
||||
* Gets the equivalent right-click hold duration timeout in ticks.
|
||||
* Default is -1, which means no timeout.
|
||||
*
|
||||
* @return the equivalent right-click hold duration
|
||||
* @return the equivalent right-click hold duration timeout
|
||||
*/
|
||||
int getUseTick();
|
||||
int getUseTickTimeout();
|
||||
|
||||
/**
|
||||
* Sets the equivalent right-click hold duration in ticks.
|
||||
* Sets the equivalent right-click hold duration timeout in ticks.
|
||||
*
|
||||
* @param useTick the equivalent right-click hold duration
|
||||
* @param timeout the equivalent right-click hold duration timeout
|
||||
* @return this action instance
|
||||
*/
|
||||
UseItemOnOffhandAction setUseTick(int useTick);
|
||||
UseItemOnOffhandAction setUseTickTimeout(int timeout);
|
||||
|
||||
static UseItemOnOffhandAction create() {
|
||||
return Bukkit.getBotManager().newAction(UseItemOnOffhandAction.class);
|
||||
|
||||
@@ -8,20 +8,20 @@ import org.bukkit.Bukkit;
|
||||
public interface UseItemToAction extends TimerBotAction<UseItemToAction> {
|
||||
|
||||
/**
|
||||
* Gets the equivalent right-click hold duration in ticks.
|
||||
* Default is -1, which means will not be released.
|
||||
* Gets the equivalent right-click hold duration timeout in ticks.
|
||||
* Default is -1, which means no timeout.
|
||||
*
|
||||
* @return the equivalent right-click hold duration
|
||||
* @return the equivalent right-click hold duration timeout
|
||||
*/
|
||||
int getUseTick();
|
||||
int getUseTickTimeout();
|
||||
|
||||
/**
|
||||
* Sets the equivalent right-click hold duration in ticks.
|
||||
* Sets the equivalent right-click hold duration timeout in ticks.
|
||||
*
|
||||
* @param useTick the equivalent right-click hold duration
|
||||
* @param timeout the equivalent right-click hold duration timeout
|
||||
* @return this action instance
|
||||
*/
|
||||
UseItemToAction setUseTick(int useTick);
|
||||
UseItemToAction setUseTickTimeout(int timeout);
|
||||
|
||||
static UseItemToAction create() {
|
||||
return Bukkit.getBotManager().newAction(UseItemToAction.class);
|
||||
|
||||
@@ -8,20 +8,20 @@ import org.bukkit.Bukkit;
|
||||
public interface UseItemToOffhandAction extends TimerBotAction<UseItemToOffhandAction> {
|
||||
|
||||
/**
|
||||
* Gets the equivalent right-click hold duration in ticks.
|
||||
* Default is -1, which means will not be released.
|
||||
* Gets the equivalent right-click hold duration timeout in ticks.
|
||||
* Default is -1, which means no timeout.
|
||||
*
|
||||
* @return the equivalent right-click hold duration
|
||||
* @return the equivalent right-click hold duration timeout
|
||||
*/
|
||||
int getUseTick();
|
||||
int getUseTickTimeout();
|
||||
|
||||
/**
|
||||
* Sets the equivalent right-click hold duration in ticks.
|
||||
* Sets the equivalent right-click hold duration timeout in ticks.
|
||||
*
|
||||
* @param useTick the equivalent right-click hold duration
|
||||
* @param timeout the equivalent right-click hold duration timeout
|
||||
* @return this action instance
|
||||
*/
|
||||
UseItemToOffhandAction setUseTick(int useTick);
|
||||
UseItemToOffhandAction setUseTickTimeout(int timeout);
|
||||
|
||||
static UseItemToOffhandAction create() {
|
||||
return Bukkit.getBotManager().newAction(UseItemToOffhandAction.class);
|
||||
|
||||
@@ -225,23 +225,11 @@ public abstract class ServerBotAction<E extends ServerBotAction<E>> {
|
||||
this.onFail = onFail;
|
||||
}
|
||||
|
||||
public Consumer<E> getOnFail() {
|
||||
return onFail;
|
||||
}
|
||||
|
||||
public void setOnSuccess(Consumer<E> onSuccess) {
|
||||
this.onSuccess = onSuccess;
|
||||
}
|
||||
|
||||
public Consumer<E> getOnSuccess() {
|
||||
return onSuccess;
|
||||
}
|
||||
|
||||
public void setOnStop(Consumer<E> onStop) {
|
||||
this.onStop = onStop;
|
||||
}
|
||||
|
||||
public Consumer<E> getOnStop() {
|
||||
return onStop;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,19 +15,19 @@ import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class ServerUseBotAction<T extends ServerUseBotAction<T>> extends ServerTimerBotAction<T> {
|
||||
private int useTick = -1;
|
||||
private int useTickTimeout = -1;
|
||||
private int alreadyUsedTick = 0;
|
||||
private int useItemRemainingTicks = 0;
|
||||
|
||||
public ServerUseBotAction(String name, Supplier<T> supplier) {
|
||||
super(name, CommandArgument.of(CommandArgumentType.INTEGER, CommandArgumentType.INTEGER, CommandArgumentType.INTEGER, CommandArgumentType.INTEGER), supplier);
|
||||
this.setSuggestion(3, Pair.of(List.of("-1"), "[UseTick]"));
|
||||
this.setSuggestion(3, Pair.of(List.of("-1"), "[UseTickTimeout]"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCommand(ServerPlayer player, @NotNull CommandArgumentResult result) {
|
||||
super.loadCommand(player, result);
|
||||
this.useTick = result.readInt(-1);
|
||||
this.useTickTimeout = result.readInt(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +73,7 @@ public abstract class ServerUseBotAction<T extends ServerUseBotAction<T>> extend
|
||||
}
|
||||
|
||||
private boolean isUseTickLimitExceeded() {
|
||||
int useTickLimit = useTick == -1 ? Integer.MAX_VALUE : useTick;
|
||||
int useTickLimit = useTickTimeout == -1 ? Integer.MAX_VALUE : useTickTimeout;
|
||||
return alreadyUsedTick > useTickLimit;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public abstract class ServerUseBotAction<T extends ServerUseBotAction<T>> extend
|
||||
@NotNull
|
||||
public CompoundTag save(@NotNull CompoundTag nbt) {
|
||||
super.save(nbt);
|
||||
nbt.putInt("useTick", this.useTick);
|
||||
nbt.putInt("useTick", this.useTickTimeout);
|
||||
nbt.putInt("alreadyUsedTick", this.alreadyUsedTick);
|
||||
return nbt;
|
||||
}
|
||||
@@ -105,18 +105,18 @@ public abstract class ServerUseBotAction<T extends ServerUseBotAction<T>> extend
|
||||
@Override
|
||||
public void load(@NotNull CompoundTag nbt) {
|
||||
super.load(nbt);
|
||||
this.useTick = nbt.getInt("useTick").orElseThrow();
|
||||
this.useTickTimeout = nbt.getInt("useTick").orElseThrow();
|
||||
this.alreadyUsedTick = nbt.getInt("alreadyUsedTick").orElseGet(
|
||||
() -> this.useTick - nbt.getInt("tickToRelease").orElseThrow()
|
||||
() -> this.useTickTimeout - nbt.getInt("tickToRelease").orElseThrow()
|
||||
);
|
||||
}
|
||||
|
||||
public int getUseTick() {
|
||||
return useTick;
|
||||
public int getUseTickTimeout() {
|
||||
return useTickTimeout;
|
||||
}
|
||||
|
||||
public void setUseTick(int useTick) {
|
||||
this.useTick = useTick;
|
||||
public void setUseTickTimeout(int useTickTimeout) {
|
||||
this.useTickTimeout = useTickTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ public class ServerUseItemAction extends ServerUseBotAction<ServerUseItemAction>
|
||||
}
|
||||
|
||||
public static @NotNull InteractionResult useItem(@NotNull ServerBot bot, InteractionHand hand) {
|
||||
bot.updateItemInHand(hand);
|
||||
InteractionResult result = bot.gameMode.useItem(bot, bot.level(), bot.getItemInHand(hand), hand);
|
||||
if (shouldSwing(result)) {
|
||||
bot.swing(hand);
|
||||
|
||||
@@ -30,6 +30,7 @@ public class ServerUseItemOnAction extends ServerUseBotAction<ServerUseItemOnAct
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
|
||||
bot.updateItemInHand(hand);
|
||||
InteractionResult interactionResult = bot.gameMode.useItemOn(bot, bot.level(), bot.getItemInHand(hand), hand, hitResult);
|
||||
if (shouldSwing(interactionResult)) {
|
||||
bot.swing(hand);
|
||||
|
||||
@@ -32,6 +32,7 @@ public class ServerUseItemToAction extends ServerUseBotAction<ServerUseItemToAct
|
||||
}
|
||||
|
||||
Vec3 vec3 = hitResult.getLocation().subtract(entity.getX(), entity.getY(), entity.getZ());
|
||||
bot.updateItemInHand(hand);
|
||||
InteractionResult interactionResult = entity.interactAt(bot, vec3, hand);
|
||||
if (!interactionResult.consumesAction()) {
|
||||
interactionResult = bot.interactOn(hitResult.getEntity(), hand);
|
||||
|
||||
@@ -16,13 +16,13 @@ public class CraftUseItemAction extends CraftTimerBotAction<UseItemAction, Serve
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseTick() {
|
||||
return serverAction.getUseTick();
|
||||
public int getUseTickTimeout() {
|
||||
return serverAction.getUseTickTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftUseItemAction setUseTick(int useTick) {
|
||||
serverAction.setUseTick(useTick);
|
||||
public CraftUseItemAction setUseTickTimeout(int timeout) {
|
||||
serverAction.setUseTickTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ public class CraftUseItemAutoAction extends CraftTimerBotAction<UseItemAutoActio
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseTick() {
|
||||
return serverAction.getUseTick();
|
||||
public int getUseTickTimeout() {
|
||||
return serverAction.getUseTickTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftUseItemAutoAction setUseTick(int useTick) {
|
||||
serverAction.setUseTick(useTick);
|
||||
public CraftUseItemAutoAction setUseTickTimeout(int timeout) {
|
||||
serverAction.setUseTickTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ public class CraftUseItemOffhandAction extends CraftTimerBotAction<UseItemOffhan
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseTick() {
|
||||
return serverAction.getUseTick();
|
||||
public int getUseTickTimeout() {
|
||||
return serverAction.getUseTickTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftUseItemOffhandAction setUseTick(int useTick) {
|
||||
serverAction.setUseTick(useTick);
|
||||
public CraftUseItemOffhandAction setUseTickTimeout(int timeout) {
|
||||
serverAction.setUseTickTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ public class CraftUseItemOnAction extends CraftTimerBotAction<UseItemOnAction, S
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseTick() {
|
||||
return serverAction.getUseTick();
|
||||
public int getUseTickTimeout() {
|
||||
return serverAction.getUseTickTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftUseItemOnAction setUseTick(int useTick) {
|
||||
serverAction.setUseTick(useTick);
|
||||
public CraftUseItemOnAction setUseTickTimeout(int timeout) {
|
||||
serverAction.setUseTickTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ public class CraftUseItemOnOffhandAction extends CraftTimerBotAction<UseItemOnOf
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseTick() {
|
||||
return serverAction.getUseTick();
|
||||
public int getUseTickTimeout() {
|
||||
return serverAction.getUseTickTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftUseItemOnOffhandAction setUseTick(int useTick) {
|
||||
serverAction.setUseTick(useTick);
|
||||
public CraftUseItemOnOffhandAction setUseTickTimeout(int timeout) {
|
||||
serverAction.setUseTickTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ public class CraftUseItemToAction extends CraftTimerBotAction<UseItemToAction, S
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseTick() {
|
||||
return serverAction.getUseTick();
|
||||
public int getUseTickTimeout() {
|
||||
return serverAction.getUseTickTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftUseItemToAction setUseTick(int useTick) {
|
||||
serverAction.setUseTick(useTick);
|
||||
public CraftUseItemToAction setUseTickTimeout(int timeout) {
|
||||
serverAction.setUseTickTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ public class CraftUseItemToOffhandAction extends CraftTimerBotAction<UseItemToOf
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseTick() {
|
||||
return serverAction.getUseTick();
|
||||
public int getUseTickTimeout() {
|
||||
return serverAction.getUseTickTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftUseItemToOffhandAction setUseTick(int useTick) {
|
||||
serverAction.setUseTick(useTick);
|
||||
public CraftUseItemToOffhandAction setUseTickTimeout(int timeout) {
|
||||
serverAction.setUseTickTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user