Skip to content

Commit

Permalink
Merge branch '0.2.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tanyaofei committed Nov 11, 2023
2 parents 59c2469 + a61ff3e commit a776efb
Show file tree
Hide file tree
Showing 152 changed files with 7,884 additions and 3,065 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ fabric.properties
.idea/
/folia/
/purpur/
/server
328 changes: 233 additions & 95 deletions README.md

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions fakeplayer-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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>1.0.0</version>
</parent>

<artifactId>fakeplayer-api</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.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.github.hello09x</groupId>
<artifactId>bedrock</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.hello09x.fakeplayer.util;
package io.github.hello09x.fakeplayer.api;

import org.checkerframework.checker.units.qual.N;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -25,6 +26,24 @@ public class Reflections {
return null;
}


public static @N Field getFistFieldByTypeIncludeParent(
@NotNull Class<?> clazz,
@NotNull Class<?> fieldType
) {
for (var field : clazz.getDeclaredFields()) {
if (field.getType() == fieldType) {
field.setAccessible(true);
return field;
}
}
var superclass = clazz.getSuperclass();
if (superclass == null || superclass == Object.class) {
return null;
}
return getFistFieldByTypeIncludeParent(superclass, fieldType);
}

public static @Nullable Field getFirstFieldByAssignFromType(
@NotNull Class<?> clazz,
@NotNull Class<?> fieldType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.hello09x.fakeplayer.manager.action;
package io.github.hello09x.fakeplayer.api.action;

import lombok.EqualsAndHashCode;

Expand All @@ -8,12 +8,12 @@ public class ActionSetting implements Cloneable {
/**
* 总次数
*/
public final int limit;
public final int maximum;

/**
* 剩余次数
*/
public int times;
public int remains;

/**
* 间隔
Expand All @@ -25,13 +25,13 @@ public class ActionSetting implements Cloneable {
*/
public int wait;

public ActionSetting(int times, int interval) {
this(times, interval, 0);
public ActionSetting(int maximum, int interval) {
this(maximum, interval, 0);
}

public ActionSetting(int times, int interval, int wait) {
this.limit = times;
this.times = times;
public ActionSetting(int maximum, int interval, int wait) {
this.maximum = maximum;
this.remains = maximum;
this.interval = interval;
this.wait = wait;
}
Expand All @@ -54,10 +54,10 @@ public static ActionSetting continuous() {

@Override
public ActionSetting clone() {
return new ActionSetting(
this.times,
this.interval,
this.wait
);
try {
return (ActionSetting) super.clone();
} catch (CloneNotSupportedException e) {
throw new Error(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.github.hello09x.fakeplayer.api.action;

import lombok.AllArgsConstructor;
import net.kyori.adventure.translation.Translatable;
import org.jetbrains.annotations.NotNull;

@AllArgsConstructor
public enum ActionType implements Translatable {

/**
* 攻击实体
*/
ATTACK("fakeplayer.action.attack"),

/**
* 挖掘
*/
MINE("fakeplayer.action.mine"),

/**
* 右键
*/
USE("fakeplayer.action.use"),

/**
* 跳跃
*/
JUMP("fakeplayer.action.jump"),

/**
* 看向附近实体
*/
LOOK_AT_NEAREST_ENTITY("fakeplayer.action.look-at-entity"),

/**
* 丢弃手上 1 个物品
*/
DROP_ITEM("fakeplayer.action.drop-item"),

/**
* 丢弃手上整组物品
*/
DROP_STACK("fakeplayer.action.drop-stack"),

/**
* 丢弃背包
*/
DROP_INVENTORY("fakeplayer.action.drop-inventory");

final String translationKey;


@Override
public @NotNull String translationKey() {
return this.translationKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.github.hello09x.fakeplayer.api.action;

import io.github.hello09x.fakeplayer.api.action.impl.*;
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 org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public abstract class BaseActionTicker implements ActionTicker {

protected Action action;

@NotNull
protected ActionSetting setting;

public BaseActionTicker(@NotNull Player player, @NotNull ActionType action, @NotNull ActionSetting setting) {
var bridge = Objects.requireNonNull(NMSBridge.getInstance());
this.setting = setting;
this.action = switch (action) {
case JUMP -> new JumpAction(bridge.player(player));
case LOOK_AT_NEAREST_ENTITY -> new LookAtEntityAction(bridge.player(player));
case DROP_ITEM -> new DropItemAction(bridge.player(player));
case DROP_STACK -> new DropStackAction(bridge.player(player));
case DROP_INVENTORY -> new DropInventoryAction(bridge.player(player));
default -> null;
};
}


@Override
public void tick() {
if (setting.wait > 0) {
setting.wait--;
inactiveTick();
return;
}

if (setting.remains == 0) {
inactiveTick();
return;
}

var valid = action.tick();
if (valid) {
if (setting.remains > 0) {
setting.remains--;
}
setting.wait = setting.interval;
}
}

@Override
public void inactiveTick() {
action.inactiveTick();
}

@Override
public void stop() {
action.stop();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.hello09x.fakeplayer.api.action.impl;

import io.github.hello09x.fakeplayer.api.spi.Action;
import io.github.hello09x.fakeplayer.api.spi.NMSServerPlayer;
import org.jetbrains.annotations.NotNull;

public class DropInventoryAction implements Action {


@NotNull
private final NMSServerPlayer player;

public DropInventoryAction(@NotNull NMSServerPlayer player) {
this.player = player;
}

@Override
public boolean tick() {
var inventory = player.getPlayer().getInventory();
for (int i = inventory.getSize(); i >= 0; i--) {
player.drop(i, false, true);
}
player.resetLastActionTime();
return true;
}

@Override
public void inactiveTick() {

}

@Override
public void stop() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.hello09x.fakeplayer.api.action.impl;

import io.github.hello09x.fakeplayer.api.spi.Action;
import io.github.hello09x.fakeplayer.api.spi.NMSServerPlayer;
import org.jetbrains.annotations.NotNull;

public class DropItemAction implements Action {

@NotNull
private final NMSServerPlayer player;

public DropItemAction(@NotNull NMSServerPlayer player) {
this.player = player;
}

@Override
public boolean tick() {
player.drop(false);
player.resetLastActionTime();
return true;
}

@Override
public void inactiveTick() {

}

@Override
public void stop() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.hello09x.fakeplayer.api.action.impl;

import io.github.hello09x.fakeplayer.api.spi.Action;
import io.github.hello09x.fakeplayer.api.spi.NMSServerPlayer;
import org.jetbrains.annotations.NotNull;

public class DropStackAction implements Action {

@NotNull
private final NMSServerPlayer player;

public DropStackAction(@NotNull NMSServerPlayer player) {
this.player = player;
}


@Override
public boolean tick() {
player.drop(true);
player.resetLastActionTime();
return true;
}

@Override
public void inactiveTick() {

}

@Override
public void stop() {

}

}
Loading

0 comments on commit a776efb

Please sign in to comment.