mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-09-14 11:16:46 +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;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface MetadataKeys {
|
||||
|
||||
|
||||
@ -7,5 +12,14 @@ public interface MetadataKeys {
|
||||
|
||||
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.PreventKicking;
|
||||
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.action.ActionManager;
|
||||
import io.github.hello09x.fakeplayer.core.manager.naming.SequenceName;
|
||||
@ -114,7 +115,7 @@ public class FakePlayer {
|
||||
*/
|
||||
public CompletableFuture<Void> spawnAsync(@NotNull SpawnOption option) {
|
||||
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
|
||||
.runTaskAsynchronously(Main.getInstance(), () -> {
|
||||
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.fakeplayer.core.Main;
|
||||
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.repository.UsedIdRepository;
|
||||
import io.github.hello09x.fakeplayer.core.util.InternalAddressGenerator;
|
||||
@ -75,18 +75,20 @@ public class FakeplayerListener implements Listener {
|
||||
public void preventKicking(@NotNull PlayerKickEvent event) {
|
||||
var player = event.getPlayer();
|
||||
|
||||
if (manager.isNotFake(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (config.getPreventKicking()) {
|
||||
case ON_SPAWNING -> {
|
||||
if (player.getMetadata(FakePlayerStatus.METADATA_KEY)
|
||||
.stream()
|
||||
.anyMatch(metadata -> metadata.value() == FakePlayerStatus.SPAWNING)
|
||||
) {
|
||||
var spawnAt = MetadataKeys.getSpawnedAt(player);
|
||||
if (spawnAt != null && Bukkit.getCurrentTick() - spawnAt < 20) {
|
||||
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 -> {
|
||||
if (!ComponentUtils.toString(event.reason()).startsWith("[fakeplayer]")) {
|
||||
|
Loading…
Reference in New Issue
Block a user