So I'm making my plugin auto add people to teams on join, and if the teams both have 2 or more people on them, then the event will happen. But for some reason it wont execute when the requirments are made idk what to do. JoinEvent class: Code (Text): package com.rechargepvp.bear53.events; import me.confuser.barapi.BarAPI; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitScheduler; import com.rechargepvp.bear53.Main; import com.rechargepvp.bear53.utils.GameManager; public class PlayerJoin implements Listener { Main plugin; public PlayerJoin(Main pl) { this.plugin = pl; } @EventHandler public void onJoin(PlayerJoinEvent e) { final Player p = e.getPlayer(); if (!Main.gameStarted) { Main.spectators.add(p.getName()); if ((Main.blue.size() >= 2) && (Main.red.size() >= 2)) { BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); scheduler.scheduleSyncRepeatingTask((Plugin) this, new Runnable() { int time = 30; @Override public void run() { if (time >= 1) { for (Player p : Bukkit.getOnlinePlayers()) { BarAPI.setMessage(p, ChatColor.DARK_AQUA + "Game starting in " + time, time); } time--; } else { for (Player p : Bukkit.getOnlinePlayers()) { BarAPI.setMessage("Timer is done. Starting Match!"); GameManager.startGame(); } } } }, 0L, 20L); } } else if (Main.gameStarted) { Main.spectators.add(p.getName()); } double x = plugin.getConfig().getDouble("specspawn.x"); double y = plugin.getConfig().getDouble("specspawn.y"); double z = plugin.getConfig().getDouble("specspawn.z"); float pitch = (float) plugin.getConfig().getDouble("specspawn.pitch"); float yaw = (float) plugin.getConfig().getDouble("specspawn.yaw"); String world = plugin.getConfig().getString("specspawn.world"); Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z, yaw, pitch); p.teleport(loc); } } GameManager Class: Code (Text): package com.rechargepvp.bear53.utils; import me.confuser.barapi.BarAPI; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitScheduler; import com.rechargepvp.bear53.API; import com.rechargepvp.bear53.Main; public class GameManager { static Main plugin; public GameManager(Main pl) { this.plugin = pl; } public static void startGame() { Main.gameStarted = true; for (Player p : Bukkit.getOnlinePlayers()) { Main.players.add(p.getName()); Main.points.put(p.getName(), 0); Main.kills.put(p.getName(), 0); Main.deaths.put(p.getName(), 0); Main.totalAlive++; Main.scoreboard(p); if (Main.red.contains(p.getName())) { double x = plugin.getConfig().getDouble("redspawn.x"); double y = plugin.getConfig().getDouble("redspawn.y"); double z = plugin.getConfig().getDouble("redspawn.z"); float pitch = (float) plugin.getConfig().getDouble( "redspawn.pitch"); float yaw = (float) plugin.getConfig() .getDouble("redspawn.yaw"); String world = plugin.getConfig().getString("redspawn.world"); Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z, yaw, pitch); p.teleport(loc); } else if (Main.blue.contains(p.getName())) { double x = plugin.getConfig().getDouble("bluespawn.x"); double y = plugin.getConfig().getDouble("bluespawn.y"); double z = plugin.getConfig().getDouble("bluespawn.z"); float pitch = (float) plugin.getConfig().getDouble( "bluespawn.pitch"); float yaw = (float) plugin.getConfig().getDouble( "bluespawn.yaw"); String world = plugin.getConfig().getString("bluespawn.world"); Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z, yaw, pitch); p.teleport(loc); } else if (Main.spectators.contains(p.getName())) { return; } Bukkit.broadcastMessage("§5################"); Bukkit.broadcastMessage("§5## §6The match has started! §5##"); Bukkit.broadcastMessage("§5################"); } } public static void endGame() { Main.gameEnded = true; Player winner = null; for (String s : Main.players) { winner = Bukkit.getPlayer(s); Bukkit.broadcastMessage("§5###############"); Bukkit.broadcastMessage("§5## §6The match has ended!§5##"); Bukkit.broadcastMessage("§5## §a" + s + "§6has won! §5##"); Bukkit.broadcastMessage("§5###############"); } if (winner != null) { API.firework(winner); } BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() { int time = 30; @Override public void run() { if (time >= 1) { for (Player p : Bukkit.getOnlinePlayers()) { BarAPI.setMessage(p, ChatColor.DARK_AQUA + "Game restarting in " + time, time); } time--; } else { for (Player p : Bukkit.getOnlinePlayers()) { BarAPI.setMessage("Timer is done. Restarting Match!"); double x = plugin.getConfig().getDouble("specspawn.x"); double y = plugin.getConfig().getDouble("specspawn.y"); double z = plugin.getConfig().getDouble("specspawn.z"); float pitch = (float) plugin.getConfig().getDouble( "specspawn.pitch"); float yaw = (float) plugin.getConfig().getDouble( "specspawn.yaw"); String world = plugin.getConfig().getString( "specspawn.world"); Location loc = new Location(Bukkit.getServer() .getWorld(world), x, y, z, yaw, pitch); p.teleport(loc); } } } }, 0L, 20L); } } If you see anything that would make this event work please post! Edit: I'm aware its not a "event" I'm just using that as a example
yes Code (Text): public void onEnable() { PluginManager pm = Bukkit.getPluginManager(); pm.registerEvents(new EntityDamage(), this); pm.registerEvents(new EntityDamageByEntity(), this); pm.registerEvents(new entityDeath(), this); pm.registerEvents(new PlayerDeath(), this); pm.registerEvents(new PlayerDropItem(), this); pm.registerEvents(new PlayerJoin(this), this); pm.registerEvents(new PlayerPickupItem(), this); pm.registerEvents(new PlayerQuit(), this); getCommand("Join").setExecutor(new CommandJoin(this)); getCommand("Setblue").setExecutor(new CommandSetBlue(this)); getCommand("Setred").setExecutor(new CommandSetRed(this)); getCommand("Setspec").setExecutor(new CommandSetSpec(this)); getCommand("Start").setExecutor(new CommandStart(this));
First of all you ever named in the code you add to a random team to player , so you never execute what you 're asking . Also by the following: Code (Text): if (!Main.gameStarted) { Main.spectators.add(p.getName()); And this: Code (Text): } else if (Main.gameStarted) { Main.spectators.add(p.getName()); } Final mind can say though is in play or not this , you will always be a spectator.