Прошу не бить палками) Есть два Java класса. FrogSW - основной, PlayerJoin - обработчик событий. Почему у меня не получается вызвать метод getGame в классе PlayerJoin?
код FrogSW.java
package wastaz123.frogmine;
import org.bukkit.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import wastaz123.frogmine.objects.Game;
import wastaz123.frogmine.data.DataHandler;
import java.util.HashSet;
import java.util.Set;
public final class FrogSW extends JavaPlugin {
private static FrogSW instance;
private Set<Game> games = new HashSet<>();
private int gamesLimit = 0;
@Override
public void onEnable() {
instance = this;
getConfig().options().copyDefaults(true);
getConfig().options().copyHeader(true);
Bukkit.getConsoleSender().sendMessage("[Frog SkyWars]" + ChatColor.GREEN +" is enabled!");
Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this);
if (getConfig().getBoolean("single-server-mode")) {
gamesLimit = 1;
} else {
gamesLimit = getConfig().getInt("max-games");
}
if (DataHandler.getInstance().getGameInfo().getConfigurationSection("games") != null) {
for (String gameName : DataHandler.getInstance().getGameInfo().getConfigurationSection("games").getKeys(false)) {
Game game = new Game(gameName);
this.registerGame(game);
}
} else {
getLogger().warning("No games has been created!");
}
}
@Override
public void onDisable() {
Bukkit.getConsoleSender().sendMessage("[Frog SkyWars]" + ChatColor.RED +" is disabled!");
instance = null;
}
public static Plugin getInstance() { return instance; }
public boolean registerGame(Game game) {
if (games.size() == gamesLimit && gamesLimit != -1) {
return false;
}
games.add(game);
return true;
}
public Game getGame(String gameName) {
for (Game game : games) {
if (game.getDisplayName().equalsIgnoreCase(gameName)) {
return game;
}
}
return null;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("sw")){
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command");
return true;
}
GUI.showMainMenu((Player) sender);
return true;
}
return true;
}
}
код PlayerJoin.java
package wastaz123.frogmine.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import wastaz123.frogmine.FrogSW;
import wastaz123.frogmine.objects.Game;
import wastaz123.frogmine.objects.GamePlayer;
public class PlayerJoin implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Game exampleGame = FrogSW.getInstance().getGame("example"); //<---- жалуется на getGame()
exampleGame.joinGame(new GamePlayer(player));
}
}