mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-09-14 19:26:51 +08:00
fix when prevent-kicking is ALWAYS can not kick a normal real player
This commit is contained in:
parent
84dc446225
commit
0b029daa5c
@ -1,5 +1,10 @@
|
|||||||
package io.github.hello09x.fakeplayer.core.constant;
|
package io.github.hello09x.fakeplayer.core.constant;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public interface MetadataKeys {
|
public interface MetadataKeys {
|
||||||
|
|
||||||
|
|
||||||
@ -7,5 +12,14 @@ public interface MetadataKeys {
|
|||||||
|
|
||||||
String REPLENISH = "fakeplayer:replenish";
|
String REPLENISH = "fakeplayer:replenish";
|
||||||
|
|
||||||
|
String SPAWNED_AT = "fakeplayer:spawned_at";
|
||||||
|
|
||||||
|
static @Nullable Integer getSpawnedAt(@NotNull Player player) {
|
||||||
|
var value = Iterables.getFirst(player.getMetadata(SPAWNED_AT), null);
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return value.asInt();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import io.github.hello09x.fakeplayer.core.Main;
|
|||||||
import io.github.hello09x.fakeplayer.core.config.Config;
|
import io.github.hello09x.fakeplayer.core.config.Config;
|
||||||
import io.github.hello09x.fakeplayer.core.config.PreventKicking;
|
import io.github.hello09x.fakeplayer.core.config.PreventKicking;
|
||||||
import io.github.hello09x.fakeplayer.core.constant.FakePlayerStatus;
|
import io.github.hello09x.fakeplayer.core.constant.FakePlayerStatus;
|
||||||
|
import io.github.hello09x.fakeplayer.core.constant.MetadataKeys;
|
||||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||||
import io.github.hello09x.fakeplayer.core.manager.action.ActionManager;
|
import io.github.hello09x.fakeplayer.core.manager.action.ActionManager;
|
||||||
import io.github.hello09x.fakeplayer.core.manager.naming.SequenceName;
|
import io.github.hello09x.fakeplayer.core.manager.naming.SequenceName;
|
||||||
@ -114,7 +115,7 @@ public class FakePlayer {
|
|||||||
*/
|
*/
|
||||||
public CompletableFuture<Void> spawnAsync(@NotNull SpawnOption option) {
|
public CompletableFuture<Void> spawnAsync(@NotNull SpawnOption option) {
|
||||||
var address = ipGen.next();
|
var address = ipGen.next();
|
||||||
this.player.setMetadata(FakePlayerStatus.METADATA_KEY, new FixedMetadataValue(Main.getInstance(), FakePlayerStatus.SPAWNING));
|
this.player.setMetadata(MetadataKeys.SPAWNED_AT, new FixedMetadataValue(Main.getInstance(), Bukkit.getCurrentTick()));
|
||||||
return SchedulerUtils
|
return SchedulerUtils
|
||||||
.runTaskAsynchronously(Main.getInstance(), () -> {
|
.runTaskAsynchronously(Main.getInstance(), () -> {
|
||||||
var event = this.callPreLoginEvent(address);
|
var event = this.callPreLoginEvent(address);
|
||||||
|
@ -6,7 +6,7 @@ import com.google.inject.Singleton;
|
|||||||
import io.github.hello09x.devtools.core.utils.ComponentUtils;
|
import io.github.hello09x.devtools.core.utils.ComponentUtils;
|
||||||
import io.github.hello09x.fakeplayer.core.Main;
|
import io.github.hello09x.fakeplayer.core.Main;
|
||||||
import io.github.hello09x.fakeplayer.core.config.Config;
|
import io.github.hello09x.fakeplayer.core.config.Config;
|
||||||
import io.github.hello09x.fakeplayer.core.constant.FakePlayerStatus;
|
import io.github.hello09x.fakeplayer.core.constant.MetadataKeys;
|
||||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||||
import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository;
|
import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository;
|
||||||
import io.github.hello09x.fakeplayer.core.util.InternalAddressGenerator;
|
import io.github.hello09x.fakeplayer.core.util.InternalAddressGenerator;
|
||||||
@ -75,18 +75,20 @@ public class FakeplayerListener implements Listener {
|
|||||||
public void preventKicking(@NotNull PlayerKickEvent event) {
|
public void preventKicking(@NotNull PlayerKickEvent event) {
|
||||||
var player = event.getPlayer();
|
var player = event.getPlayer();
|
||||||
|
|
||||||
|
if (manager.isNotFake(event.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (config.getPreventKicking()) {
|
switch (config.getPreventKicking()) {
|
||||||
case ON_SPAWNING -> {
|
case ON_SPAWNING -> {
|
||||||
if (player.getMetadata(FakePlayerStatus.METADATA_KEY)
|
var spawnAt = MetadataKeys.getSpawnedAt(player);
|
||||||
.stream()
|
if (spawnAt != null && Bukkit.getCurrentTick() - spawnAt < 20) {
|
||||||
.anyMatch(metadata -> metadata.value() == FakePlayerStatus.SPAWNING)
|
|
||||||
) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
log.warning(String.format(
|
|
||||||
"Canceled kicking fake player '%s' on spawning due to your configuration",
|
|
||||||
player.getName()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
log.warning(String.format(
|
||||||
|
"Canceled kicking fake player '%s' on spawning due to your configuration",
|
||||||
|
player.getName()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
case ALWAYS -> {
|
case ALWAYS -> {
|
||||||
if (!ComponentUtils.toString(event.reason()).startsWith("[fakeplayer]")) {
|
if (!ComponentUtils.toString(event.reason()).startsWith("[fakeplayer]")) {
|
||||||
|
2
pom.xml
2
pom.xml
@ -24,7 +24,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<revision>0.3.6-rc.3</revision>
|
<revision>0.3.6</revision>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
Loading…
Reference in New Issue
Block a user