- Сообщения
- 285
- Решения
- 1
Я хочу сделать несколько языков в плагине проблема что при перезагрузки конфига язык остается тем же что и был а если сервер перезагрузить он меняется
Код:
package me.sp3ctr0.ecolobby;
import me.sp3ctr0.ecolobby.commands.EcoLobbyCommand;
import me.sp3ctr0.ecolobby.configurations.Configurations;
import me.sp3ctr0.ecolobby.event.EcoEventHandler;
import me.sp3ctr0.ecolobby.utils.Chat;
import me.sp3ctr0.ecolobby.utils.Events;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Arrays;
import java.util.List;
public final class EcoLobby extends JavaPlugin {
private Configurations configurations = new Configurations(this, "config.yml", "lang/en.yml", "lang/ru.yml");
private final Chat chat = new Chat(configurations);
private final Events events = new Events(configurations);
public final List<String> ENABLE_MESSAGE = Arrays.asList
(
"§7=-=-=-=-§a§lEco§f§lLobby§7-=-=-=-=",
"",
" Version: §a" + this.getDescription().getVersion(),
" Author: §aSp3ctr0",
"",
"§7=-=-=-=-§a§lEco§f§lLobby§7-=-=-=-="
);
@Override
public void onEnable() {
ENABLE_MESSAGE.forEach(System.out::println);
configurations.loadConfigurations();
getServer().getPluginCommand("ecolobby").setExecutor(new EcoLobbyCommand(configurations, this));
getServer().getPluginManager().registerEvents(new EcoEventHandler(configurations), this);
Events.setRules();
}
@Override
public void onDisable() {
configurations = null;
}
public void reload() {
configurations.reloadConfigurations();
}
}
Код:
package me.sp3ctr0.ecolobby.commands;
import me.sp3ctr0.ecolobby.EcoLobby;
import me.sp3ctr0.ecolobby.configurations.Configurations;
import me.sp3ctr0.ecolobby.utils.Chat;
import me.sp3ctr0.ecolobby.utils.Events;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
public class EcoLobbyCommand implements CommandExecutor {
private final EcoLobby plugin;
private final FileConfiguration m;
private final FileConfiguration c;
public EcoLobbyCommand(Configurations configurations, EcoLobby plugin) {
this.plugin = plugin;
c = configurations.get("config.yml");
m = configurations.get("lang/"+ c.get("lang") +".yml");
}
private static final List<String> HELP = Arrays.asList
(
" &7&m=-=-=-=-&a&lEco&f&lLobby&7&m-=-=-=-=",
"",
" /ecolobby reload &8- &aReload plugin.",
" /ecolobby setspawn &8- &aSet spawn.",
" /ecolobby spawn &8- &aTeleport to spawn.",
"",
" &7&m=-=-=-=-&a&lEco&f&lLobby&7&m-=-=-=-="
);
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("ecolobby.reload")) {
Chat.sendMessagePrefix(sender, m.getString("no-permission", "You don't have permission!"));
return true;
}
Chat.sendMessagePrefix(sender, m.getString("plugin-reloaded", "Plugin successfully reloaded!"));
plugin.reload();
}
else if (args.length == 1 && args[0].equalsIgnoreCase("setspawn")) {
if (!(sender instanceof Player)) {
Chat.sendMessagePrefix(sender, m.getString("no-player", "This command is only available to players!"));
return true;
}
if (!sender.hasPermission("ecolobby.setspawn")) {
Chat.sendMessagePrefix(sender, m.getString("no-permission", "You don't have permission!"));
return true;
}
Player player = (Player) sender;
Events.getLocation(player);
Chat.sendMessagePrefix(sender, m.getString("successfully-setspawn", "Spawn has been successfully installed."));
}
else if ((args.length == 1 && args[0].equalsIgnoreCase("spawn"))) {
if (!(sender instanceof Player)) {
Chat.sendMessagePrefix(sender, m.getString("no-player", "This command is only available to players!"));
return true;
}
if (!sender.hasPermission("ecolobby.spawn")) {
Chat.sendMessagePrefix(sender, m.getString("no-permission", "You don't have permission!"));
return true;
}
Player player = (Player) sender;
Events.tpSpawn(player);
Chat.sendMessagePrefix(sender, m.getString("successfully-spawn", "You have been teleported to spawn."));
}
else {
if (!sender.hasPermission("ecolobby.help"))
{
Chat.sendMessagePrefix(sender, m.getString("no-permissions", "You don't have permission!"));
return true;
}
List<String> help = m.getStringList("help");
if (help.isEmpty()) {
HELP.forEach((x) -> Chat.sendMessage(sender, x));
return true;
}
help.forEach((x) -> Chat.sendMessage(sender, x));
}
return true;
}
}