Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Oct 14, 2024
1 parent 5ebb528 commit 64ae67a
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/main/java/cc/baka9/catseedlogin/bukkit/CatSeedLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,35 @@ public class CatSeedLogin extends JavaPlugin implements Listener {
private LoginPlayerHelper timeoutManager;

@Override
public void onEnable(){
public void onEnable() {
instance = this;
morePaperLib = new MorePaperLib(this);
HandySchedulerUtil.init(this);
getServer().getPluginManager().registerEvents(this, this);
timeoutManager = new LoginPlayerHelper();
//Config

// Config
try {
Config.load();
Config.save();
} catch (Exception e) {
e.printStackTrace();
getServer().getLogger().warning("加载配置文件时出错,请检查你的配置文件。");
}

sql = Config.MySQL.Enable ? new MySQL(this) : new SQLite(this);
try {

sql.init();

Cache.refreshAll();
} catch (Exception e) {
getLogger().warning("§c加载数据库时出错");
e.printStackTrace();
}
//Listeners

// Listeners
getServer().getPluginManager().registerEvents(new Listeners(), this);

//ProtocolLibListeners
// ProtocolLibListeners
if (Config.Settings.Emptybackpack) {
try {
Class.forName("com.comphenix.protocol.ProtocolLib");
Expand All @@ -75,17 +76,24 @@ public void onEnable(){
}
}

// bc
// BungeeCord
if (Config.BungeeCord.Enable) {
Communication.socketServerStartAsync();
}

// Floodgate
if (Bukkit.getPluginManager().getPlugin("floodgate") != null && Config.Settings.BedrockLoginBypass){
if (Bukkit.getPluginManager().getPlugin("floodgate") != null && Config.Settings.BedrockLoginBypass) {
getLogger().info("检测到floodgate,基岩版兼容已装载");
}

//Commands
// Commands
registerCommands();

// Task
Task.runAll();
}

private void registerCommands() {
getServer().getPluginCommand("login").setExecutor(new CommandLogin());
getServer().getPluginCommand("login").setTabCompleter((commandSender, command, s, args)
-> args.length == 1 ? Collections.singletonList("密码") : new ArrayList<>(0));
Expand Down Expand Up @@ -114,6 +122,7 @@ public void onEnable(){
}
return Collections.emptyList();
});

PluginCommand resetpassword = getServer().getPluginCommand("resetpassword");
resetpassword.setExecutor(new CommandResetPassword());
resetpassword.setTabCompleter((commandSender, command, s, args) -> {
Expand All @@ -130,12 +139,9 @@ public void onEnable(){
}
return Collections.emptyList();
});

PluginCommand catseedlogin = getServer().getPluginCommand("catseedlogin");
catseedlogin.setExecutor(new CommandCatSeedLogin());

//Task
Task.runAll();

}

@EventHandler
Expand All @@ -153,17 +159,16 @@ public void run() {
}.runTaskTimer(this, 0L, 20L);
}


@Override
public void onDisable(){
public void onDisable() {
Task.cancelAll();
Bukkit.getOnlinePlayers().forEach(p -> {
if (!LoginPlayerHelper.isLogin(p.getName())) return;
if (!p.isDead() || Config.Settings.DeathStateQuitRecordLocation) {
Config.setOfflineLocation(p);
}

});

try {
sql.getConnection().close();
} catch (Exception e) {
Expand All @@ -174,9 +179,7 @@ public void onDisable(){
super.onDisable();
}

public void runTaskAsync(Runnable runnable){
public void runTaskAsync(Runnable runnable) {
CatScheduler.runTaskAsync(runnable);
}


}

0 comments on commit 64ae67a

Please sign in to comment.