feat(hamster-name-case-fix): 禁止大小写冲突的玩家名称进入游戏
This commit is contained in:
8
hamster-name-case-fix/build.gradle
Normal file
8
hamster-name-case-fix/build.gradle
Normal file
@@ -0,0 +1,8 @@
|
||||
version '1.0.0-SNAPSHOT'
|
||||
setArchivesBaseName("HamsterNameCaseFix")
|
||||
|
||||
dependencies {
|
||||
//noinspection VulnerableLibrariesLocal
|
||||
compileOnly "net.md-5:bungeecord-api:${bungeecord_api_version}"
|
||||
compileOnly "cn.hamster3.mc.plugin.ball:common:${hamster_ball_version}"
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package cn.hamster3.mc.plugin.name.fix;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class NameFixPlugin extends Plugin implements Listener {
|
||||
private String kickMessage;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (getDataFolder().mkdir()) {
|
||||
getLogger().info("创建插件文件夹...");
|
||||
}
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
try {
|
||||
InputStream in = getResourceAsStream("config.yml");
|
||||
Files.copy(in, configFile.toPath());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
kickMessage = configuration.getString("kick-message");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(this, this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPreLogin(PreLoginEvent event) {
|
||||
String name = event.getConnection().getName();
|
||||
for (BallPlayerInfo info : BallAPI.getInstance().getAllPlayerInfo().values()) {
|
||||
if (!name.equalsIgnoreCase(info.getName())) {
|
||||
continue;
|
||||
}
|
||||
if (name.equals(info.getName())) {
|
||||
continue;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
event.setCancelReason(new TextComponent(kickMessage.replace("%player_name%", info.getName())));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
9
hamster-name-case-fix/src/main/resources/bungee.yml
Normal file
9
hamster-name-case-fix/src/main/resources/bungee.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
name: HamsterNameCaseFix
|
||||
main: cn.hamster3.mc.plugin.name.fix.NameFixPlugin
|
||||
version: ${version}
|
||||
|
||||
author: MiniDay
|
||||
description: 禁止大小写冲突的玩家名称进入游戏
|
||||
|
||||
depends:
|
||||
- HamsterBall
|
1
hamster-name-case-fix/src/main/resources/config.yml
Normal file
1
hamster-name-case-fix/src/main/resources/config.yml
Normal file
@@ -0,0 +1 @@
|
||||
kick-message: "§c请使用名称 %player_name% 登录!"
|
@@ -13,4 +13,5 @@ include 'hamster-join-message'
|
||||
include 'hamster-protect-explosion'
|
||||
include 'hamster-protect-piston-wool-carpet'
|
||||
include 'hamster-protect-farmland'
|
||||
include 'hamster-name-case-fix'
|
||||
|
||||
|
Reference in New Issue
Block a user