mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-09-14 11:16:46 +08:00
Supports more options for prevent kicking
This commit is contained in:
parent
0974ac5fd9
commit
d5c6bae86c
@ -32,7 +32,7 @@ public class FakeplayerConfig extends Config<FakeplayerConfig> {
|
|||||||
log = Main.getInstance().getLogger();
|
log = Main.getInstance().getLogger();
|
||||||
instance = new FakeplayerConfig(
|
instance = new FakeplayerConfig(
|
||||||
Main.getInstance(),
|
Main.getInstance(),
|
||||||
"14"
|
"15"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,11 +101,6 @@ public class FakeplayerConfig extends Config<FakeplayerConfig> {
|
|||||||
*/
|
*/
|
||||||
private Pattern namePattern;
|
private Pattern namePattern;
|
||||||
|
|
||||||
/**
|
|
||||||
* 登陆时防止被踢
|
|
||||||
*/
|
|
||||||
private boolean preventKickedOnSpawning;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测更新
|
* 检测更新
|
||||||
*/
|
*/
|
||||||
@ -127,6 +122,11 @@ public class FakeplayerConfig extends Config<FakeplayerConfig> {
|
|||||||
*/
|
*/
|
||||||
private boolean debug;
|
private boolean debug;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 防止踢出
|
||||||
|
*/
|
||||||
|
private PreventKicking preventKicking;
|
||||||
|
|
||||||
public FakeplayerConfig(@NotNull JavaPlugin plugin, @NotNull String version) {
|
public FakeplayerConfig(@NotNull JavaPlugin plugin, @NotNull String version) {
|
||||||
super(plugin, version);
|
super(plugin, version);
|
||||||
reload(false);
|
reload(false);
|
||||||
@ -152,7 +152,7 @@ public class FakeplayerConfig extends Config<FakeplayerConfig> {
|
|||||||
this.kickOnDead = file.getBoolean("kick-on-dead", true);
|
this.kickOnDead = file.getBoolean("kick-on-dead", true);
|
||||||
this.checkForUpdates = file.getBoolean("check-for-updates", true);
|
this.checkForUpdates = file.getBoolean("check-for-updates", true);
|
||||||
this.namePattern = getNamePattern(file);
|
this.namePattern = getNamePattern(file);
|
||||||
this.preventKickedOnSpawning = file.getBoolean("prevent-kicked-on-spawning", false);
|
this.preventKicking = this.getPreventKicking(file);
|
||||||
this.nameTemplate = getNameTemplate(file);
|
this.nameTemplate = getNameTemplate(file);
|
||||||
this.lifespan = getLifespan(file);
|
this.lifespan = getLifespan(file);
|
||||||
this.allowCommands = file.getStringList("allow-commands")
|
this.allowCommands = file.getStringList("allow-commands")
|
||||||
@ -190,4 +190,13 @@ public class FakeplayerConfig extends Config<FakeplayerConfig> {
|
|||||||
return tmpl;
|
return tmpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @NotNull PreventKicking getPreventKicking(@NotNull FileConfiguration file) {
|
||||||
|
if (file.getBoolean("prevent-kicked-on-spawning", false)) {
|
||||||
|
log.warning("prevent-kicked-on-spawning is deprecated, use prevent-kick instead");
|
||||||
|
return PreventKicking.ON_SPAWNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PreventKicking.valueOf(file.getString("prevent-kicking", PreventKicking.NEVER.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package io.github.hello09x.fakeplayer.core.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tanyaofei
|
||||||
|
* @since 2024/7/26
|
||||||
|
**/
|
||||||
|
public enum PreventKicking {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不进行任何处理
|
||||||
|
*/
|
||||||
|
NEVER,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时
|
||||||
|
*/
|
||||||
|
ON_SPAWNING,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 永远, 除了假人插件自身
|
||||||
|
*/
|
||||||
|
ALWAYS
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.google.common.base.Throwables;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import io.github.hello09x.bedrock.i18n.I18n;
|
import io.github.hello09x.bedrock.i18n.I18n;
|
||||||
|
import io.github.hello09x.bedrock.util.Components;
|
||||||
import io.github.hello09x.fakeplayer.core.Main;
|
import io.github.hello09x.fakeplayer.core.Main;
|
||||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||||
import io.github.hello09x.fakeplayer.core.constant.FakePlayerStatus;
|
import io.github.hello09x.fakeplayer.core.constant.FakePlayerStatus;
|
||||||
@ -73,22 +74,31 @@ public class FakeplayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void preventBeingKickedOnSpawning(@NotNull PlayerKickEvent event) {
|
public void preventKicking(@NotNull PlayerKickEvent event) {
|
||||||
var player = event.getPlayer();
|
var player = event.getPlayer();
|
||||||
|
|
||||||
if (!config.isPreventKickedOnSpawning()) {
|
switch (config.getPreventKicking()) {
|
||||||
return;
|
case ON_SPAWNING -> {
|
||||||
}
|
if (player.getMetadata(FakePlayerStatus.METADATA_KEY)
|
||||||
|
.stream()
|
||||||
if (player.getMetadata(FakePlayerStatus.METADATA_KEY)
|
.anyMatch(metadata -> metadata.value() == FakePlayerStatus.SPAWNING)
|
||||||
.stream()
|
) {
|
||||||
.anyMatch(metadata -> metadata.value() == FakePlayerStatus.SPAWNING)
|
event.setCancelled(true);
|
||||||
) {
|
log.warning(String.format(
|
||||||
event.setCancelled(true);
|
"Canceled kicking fake player '%s' on spawning due to your configuration",
|
||||||
log.warning(String.format(
|
player.getName()
|
||||||
"Fake player '%s' was attempting to be kicked during the spawning which will be canceled cause you are enabled 'prevent-kicked-on-spawning'",
|
));
|
||||||
player.getName())
|
}
|
||||||
);
|
}
|
||||||
|
case ALWAYS -> {
|
||||||
|
if (!Components.asString(event.reason()).startsWith("[fakeplayer]")) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
log.warning(String.format(
|
||||||
|
"Canceled kicking fake player '%s' due to your configuration",
|
||||||
|
player.getName()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# 配置文件版本, 不要修改这个值
|
# 配置文件版本, 不要修改这个值
|
||||||
# THE VERSION OF THIS CONFIG FILE, DO NOT MODIFY IT
|
# THE VERSION OF THIS CONFIG FILE, DO NOT MODIFY IT
|
||||||
version: 14
|
version: 15
|
||||||
|
|
||||||
# 多国语言配置
|
# 多国语言配置
|
||||||
# 可选项: zh, en
|
# 可选项: zh, en
|
||||||
@ -64,11 +64,17 @@ name-template: ''
|
|||||||
# 3. 如果你改了正则表达式, 请确保它以 `^` 开头并且以 `$` 结尾
|
# 3. 如果你改了正则表达式, 请确保它以 `^` 开头并且以 `$` 结尾
|
||||||
name-pattern: '^[a-zA-Z0-9_]+$'
|
name-pattern: '^[a-zA-Z0-9_]+$'
|
||||||
|
|
||||||
# 防止假人在登陆过程中由于其他插件的不兼容问题踢掉假人,
|
# 防止假人被其他插件踢掉, 这个选项用来兼容一些插件因为某些问题而踢掉假人
|
||||||
# 开启这个选项可能可以解决一些登陆插件的兼容问题, 但是插件本身应该还是会打印错误日志
|
# 可选项:
|
||||||
# Prevent fake players from being kicked during spawning. Enabling this option may resolve some compatibility issues with login plugins.
|
# NEVER: 不进行任何处理
|
||||||
# But, these plugins may still print some error logs.
|
# ON_SPAWNING: 创建时防止被踢出, 某些登陆插件会在加入时踢掉, 但不支持某些插件会在下 1 tick 时才踢的情况
|
||||||
prevent-kicked-on-spawning: false
|
# ALWAYS: 永远, 即除了本插件以外任何插件包括 /kick 命令都无法将假人踢掉
|
||||||
|
# Prevent some plugins kick our fake players, enabling this option may resolve some compatibility issues with login plugins.
|
||||||
|
# Options:
|
||||||
|
# NEVER: do not prevent kicking
|
||||||
|
# ON_SPAWNING: only prevent kicking when fake players is spawning, but some plugin will kick them on the next tick, in such causes you should use `ALWAYS`
|
||||||
|
# ALWAYS: always prevent kicking from other plugins and command `/kick`
|
||||||
|
prevent-kicking: NEVER
|
||||||
|
|
||||||
# 跟随下线
|
# 跟随下线
|
||||||
# 假人创建者下线时是否也跟着下线
|
# 假人创建者下线时是否也跟着下线
|
||||||
|
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.5</revision>
|
<revision>0.3.6-rc1</revision>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
Loading…
Reference in New Issue
Block a user