Solved [Error] Selecting random teams

Discussion in 'Plugin Development' started by Xyplo, May 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Xyplo

    So i've been developing this new minigame for a server, but it won't select the teams. I really don't know what is wrong and there are no erros in the cmd prompt or in game for anyone to see or notice. Everything (from what I can see) is set up correctly and works like a charm. But what doesn't work is the team selector.

    This is the GameHandler class and here is the startGame and initialiseTeams coding.
    Code:java
    1. /**
    2. * Start the game
    3. */
    4. public void startGame() {
    5. initialiseTeams();
    6.  
    7. for(Player p : instance.ph.getPlayers()) {
    8. if(!IMC.containsPlayer(p) && !MILITIA.containsPlayer(p)) {
    9. if(IMC.getSize() > MILITIA.getSize()) {
    10. MILITIA.addPlayer(p);
    11. } else {
    12. if(MILITIA.getSize() > IMC.getSize()) {
    13. IMC.addPlayer(p);
    14. }
    15. }
    16. }
    17. }
    18.  
    19. instance.setState(GameState.IN_GAME);
    20. }
    21.  
    22. /**
    23. * Adds players to the specified teams
    24. */
    25. private void initialiseTeams() {
    26.  
    27. for(Player p : instance.ph.getPlayers()) {
    28. if(IMC.containsPlayer(p)) {
    29. p.teleport(this.getSpawnIMC());
    30. p.sendMessage(ChatColor.BLUE + "You're on the IMC team.");
    31. if(!this.titanTimer.containsKey(p.getName()))
    32. this.titanTimer.put(p.getName(), this.defaultTitanTimer);
    33. }
    34. else if(MILITIA.containsPlayer(p)) {
    35. p.teleport(this.getSpawnMilitia());
    36. p.sendMessage(ChatColor.RED + "You're on the MILITIA team.");
    37. if(!this.titanTimer.containsKey(p.getName()))
    38. this.titanTimer.put(p.getName(), this.defaultTitanTimer);
    39. }
    40. else {
    41. p.sendMessage(ChatColor.RED + "An error occured whilst trying to teleport you to the spawn locations. You're not on a team.");
    42. }
    43. }
    44.  
    45. }

    It's not teleporting the players which means it cannot select teams... Can someone help?

    (The entire GameHandler class)
    Code:java
    1. package project.titan.java.handlers;
    2.  
    3. import java.util.Collections;
    4. import java.util.HashMap;
    5. import java.util.List;
    6. import java.util.Map.Entry;
    7. import java.util.logging.Level;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.Location;
    12. import org.bukkit.Material;
    13. import org.bukkit.World;
    14. import org.bukkit.entity.IronGolem;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.event.EventHandler;
    17. import org.bukkit.event.Listener;
    18. import org.bukkit.event.block.BlockBreakEvent;
    19. import org.bukkit.event.block.BlockPlaceEvent;
    20. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    21. import org.bukkit.event.entity.EntityDamageEvent;
    22. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    23. import org.bukkit.event.entity.PlayerDeathEvent;
    24. import org.bukkit.event.player.PlayerInteractEvent;
    25. import org.bukkit.event.player.PlayerRespawnEvent;
    26. import org.bukkit.inventory.ItemStack;
    27. import org.bukkit.scheduler.BukkitRunnable;
    28.  
    29. import project.titan.java.MainComponent;
    30. import project.titan.java.Titanfall;
    31. import project.titan.java.events.BeaconPlaceEvent;
    32. import project.titan.java.handlers.titans.Titan;
    33. import project.titan.java.handlers.titans.TitanManager;
    34. import project.titan.java.util.GameState;
    35. import project.titan.java.util.Messages;
    36. import project.titan.java.util.ServerState;
    37.  
    38. public class GameHandler extends BukkitRunnable implements Listener {
    39.  
    40. //Uninitialised variables
    41. private Titanfall instance;
    42. private boolean cancelled;
    43.  
    44. public TeamHandler IMC;
    45. public TeamHandler MILITIA;
    46.  
    47. private int maximumScore;
    48.  
    49. private int defaultCount;
    50. private int currentCount;
    51.  
    52. private int intermission;
    53.  
    54. private MapHandler currentMap;
    55.  
    56. private TitanManager titanManager;
    57. private int defaultTitanTimer;
    58. private HashMap<String, Integer> titanTimer;
    59.  
    60. private int maximumTitans;
    61.  
    62. private Material beaconMaterial;
    63.  
    64. /**
    65. * Create a GameHandler class to handle
    66. * @param instance
    67. */
    68. public GameHandler(Titanfall instance) {
    69. this.titanTimer = new HashMap<String, Integer>();
    70.  
    71. this.instance = instance;
    72. this.cancelled = false;
    73.  
    74. this.defaultCount = MainComponent.getInstance().getConfig().getInt("timer.game");
    75. this.currentCount = this.defaultCount;
    76.  
    77. this.maximumScore = MainComponent.getInstance().getConfig().getInt("maximum-score");
    78.  
    79. this.beaconMaterial = Material.BEACON;
    80.  
    81. startIntermission();
    82. }
    83.  
    84. /**
    85. * Initialises all the required variables in order for the plugin to function
    86. */
    87. private void loadPrerequisites() {
    88. this.intermission = MainComponent.getInstance().getConfig().getInt("timer.intermission");
    89. this.maximumTitans = MainComponent.getInstance().getConfig().getInt("maximum-titans");
    90. this.defaultTitanTimer = MainComponent.getInstance().getConfig().getInt("timer.titan-wait");
    91.  
    92. titanTimer.clear();
    93.  
    94. IMC = new TeamHandler("IMC", ChatColor.BLUE, false);
    95. MILITIA = new TeamHandler("Militia", ChatColor.RED, false);
    96.  
    97. titanManager = new TitanManager();
    98.  
    99. currentMap = getRandomMap();
    100. if(currentMap == null) {
    101. this.setCancelled(true);
    102. MainComponent.getInstance().setState(ServerState.EDIT_MODE);
    103. } else {
    104. MainComponent.getInstance().setState(ServerState.GAME_MODE);
    105. }
    106. }
    107.  
    108. /**
    109. * Get a random map from the List
    110. * @return a random map
    111. */
    112. public MapHandler getRandomMap() {
    113. if(instance.maps != null && !instance.maps.isEmpty()) {
    114. List<MapHandler> m = instance.maps;
    115. Collections.shuffle(m);
    116. return m.get(0);
    117. } else {
    118. return null;
    119. }
    120. }
    121.  
    122. /**
    123. * Start the intermission
    124. */
    125. public void startIntermission() {
    126. loadPrerequisites();
    127.  
    128. for(Player p : instance.ph.getPlayers()) {
    129. if(this.getLobbySpawnLocation() != null)
    130. p.teleport(this.getLobbySpawnLocation());
    131. }
    132.  
    133. instance.setState(GameState.INTERMISSION);
    134. }
    135.  
    136. /**
    137. * Start the game
    138. */
    139. public void startGame() {
    140. initialiseTeams();
    141.  
    142. for(Player p : instance.ph.getPlayers()) {
    143. if(!IMC.containsPlayer(p) && !MILITIA.containsPlayer(p)) {
    144. if(IMC.getSize() > MILITIA.getSize()) {
    145. MILITIA.addPlayer(p);
    146. } else {
    147. if(MILITIA.getSize() > IMC.getSize()) {
    148. IMC.addPlayer(p);
    149. }
    150. }
    151. }
    152. }
    153.  
    154. instance.setState(GameState.IN_GAME);
    155. }
    156.  
    157. /**
    158. * Ends the game, and resets everything to default.
    159. */
    160. public void endGame() {
    161. //Announce winner...
    162.  
    163. this.startIntermission();
    164. this.currentCount = defaultCount;
    165. }
    166.  
    167. /**
    168. * Adds players to the specified teams
    169. */
    170. private void initialiseTeams() {
    171. for(Player p : instance.ph.getPlayers()) {
    172. if(IMC.containsPlayer(p)) {
    173. p.teleport(this.getSpawnIMC());
    174. p.sendMessage(ChatColor.BLUE + "You're on the IMC team.");
    175. if(!this.titanTimer.containsKey(p.getName()))
    176. this.titanTimer.put(p.getName(), this.defaultTitanTimer);
    177. }
    178. else if(MILITIA.containsPlayer(p)) {
    179. p.teleport(this.getSpawnMilitia());
    180. p.sendMessage(ChatColor.RED + "You're on the MILITIA team.");
    181. if(!this.titanTimer.containsKey(p.getName()))
    182. this.titanTimer.put(p.getName(), this.defaultTitanTimer);
    183. }
    184. else {
    185. p.sendMessage(ChatColor.RED + "An error occured whilst trying to teleport you to the spawn locations. You're not on a team.");
    186. }
    187. }
    188.  
    189. }
    190.  
    191. /**
    192. * Get the main lobby spawn location
    193. * @return Location object
    194. */
    195. public Location getLobbySpawnLocation() {
    196. double x, y, z;
    197. float yaw, pitch;
    198. World world;
    199.  
    200. if(Bukkit.getServer().getWorld(MainComponent.getInstance().getConfig().getString("LOBBY.spawn.world")) != null) {
    201. x = MainComponent.getInstance().getConfig().getDouble("LOBBY.spawn.x");
    202. y = MainComponent.getInstance().getConfig().getDouble("LOBBY.spawn.y");
    203. z = MainComponent.getInstance().getConfig().getDouble("LOBBY.spawn.z");
    204. yaw = MainComponent.getInstance().getConfig().getInt("LOBBY.spawn.yaw");
    205. pitch = MainComponent.getInstance().getConfig().getInt("LOBBY.spawn.pitch");
    206. world = Bukkit.getServer().getWorld(MainComponent.getInstance().getConfig().getString("LOBBY.spawn.world"));
    207.  
    208. return new Location(world, x, y, z, yaw, pitch);
    209. } else {
    210. Bukkit.getServer().getLogger().log(Level.SEVERE, "A lobby world doesn't exist! Please create one!");
    211. return null;
    212. }
    213. }
    214.  
    215. /**
    216. * Get the spawn location for the IMC team
    217. */
    218. public Location getSpawnDefault() {
    219. double x, y, z;
    220. float yaw, pitch;
    221.  
    222. x = currentMap.getConfigurationFile().getConfig().getDouble("DEFAULT.spawn.x");
    223. y = currentMap.getConfigurationFile().getConfig().getDouble("DEFAULT.spawn.y");
    224. z = currentMap.getConfigurationFile().getConfig().getDouble("DEFAULT.spawn.z");
    225. yaw = currentMap.getConfigurationFile().getConfig().getInt("DEFAULT.spawn.yaw");
    226. pitch = currentMap.getConfigurationFile().getConfig().getInt("DEFAULT.spawn.pitch");
    227.  
    228. return new Location(currentMap.getWorld(), x, y, z, yaw, pitch);
    229. }
    230.  
    231. /**
    232. * Get the spawn location for the IMC team
    233. */
    234. public Location getSpawnIMC() {
    235. double x, y, z;
    236. float yaw, pitch;
    237.  
    238. x = currentMap.getConfigurationFile().getConfig().getDouble("IMC.spawn.x");
    239. y = currentMap.getConfigurationFile().getConfig().getDouble("IMC.spawn.y");
    240. z = currentMap.getConfigurationFile().getConfig().getDouble("IMC.spawn.z");
    241. yaw = currentMap.getConfigurationFile().getConfig().getInt("IMC.spawn.yaw");
    242. pitch = currentMap.getConfigurationFile().getConfig().getInt("IMC.spawn.pitch");
    243.  
    244. return new Location(currentMap.getWorld(), x, y, z, yaw, pitch);
    245. }
    246.  
    247. /**
    248. * Get the spawn location for the MILITIA team
    249. */
    250. public Location getSpawnMilitia() {
    251. double x, y, z;
    252. float yaw, pitch;
    253.  
    254. x = currentMap.getConfigurationFile().getConfig().getDouble("MILITIA.spawn.x");
    255. y = currentMap.getConfigurationFile().getConfig().getDouble("MILITIA.spawn.y");
    256. z = currentMap.getConfigurationFile().getConfig().getDouble("MILITIA.spawn.z");
    257. yaw = currentMap.getConfigurationFile().getConfig().getInt("MILITIA.spawn.yaw");
    258. pitch = currentMap.getConfigurationFile().getConfig().getInt("MILITIA.spawn.pitch");
    259.  
    260. return new Location(currentMap.getWorld(), x, y, z, yaw, pitch);
    261. }
    262.  
    263. /**
    264. * Set the cancelled boolean of the timer
    265. * @param cancelled as boolean object
    266. */
    267. public void setCancelled(boolean cancelled) {
    268. this.cancelled = cancelled;
    269. }
    270.  
    271. /**
    272. * Check to see if the timer is cancelled or not
    273. * @return boolean object
    274. */
    275. public boolean isCancelled() {
    276. return cancelled;
    277. }
    278.  
    279. //Temporary int array
    280. private int[] seconds = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 60, 120, 300, 600, 1200, 1800, 3600 };
    281.  
    282. /**
    283. * The runnable method is triggered every ( 1 second / 20 server ticks )
    284. */
    285. public void run() {
    286. //If the timer isn't cancelled.
    287. if(!this.isCancelled() && MainComponent.getInstance().getState() == ServerState.GAME_MODE) {
    288. if(this.instance.getState() == GameState.INTERMISSION) {
    289. if(this.intermission > -1) {
    290. for(int n : seconds) {
    291. if(intermission == n) {
    292. for(Player p : instance.ph.getPlayers()) {
    293. p.sendMessage(Messages.intermissionTimer.replace("%%TIME%%", Integer.toString(intermission)));
    294. }
    295. }
    296. }
    297. this.intermission--;
    298. } else {
    299. int minimumRequirement = MainComponent.getInstance().getConfig().getInt("minimum-requirement");
    300. if(instance.ph.getSize() < minimumRequirement) {
    301. for(Player p : instance.ph.getPlayers()) {
    302. p.sendMessage(Messages.notEnoughPlayers.replace("%%AMOUNT%%", Integer.toString(minimumRequirement)));
    303. p.sendMessage(ChatColor.YELLOW + "Restarting the intermission...");
    304. }
    305. this.intermission = MainComponent.getInstance().getConfig().getInt("timer.intermission");
    306. } else {
    307. this.startGame();
    308. this.currentCount = defaultCount;
    309. }
    310. }
    311. } else if(this.instance.getState() == GameState.IN_GAME) {
    312.  
    313. if(this.currentCount >= -1) {
    314. for(int n : seconds) {
    315. if(currentCount == n)
    316. for(Player p : instance.ph.getPlayers()) {
    317. p.sendMessage(Messages.gameTimer.replace("%%TIME%%", Integer.toString(currentCount)));
    318. }
    319. }
    320.  
    321. titanLoopHandler();
    322.  
    323. if(this.MILITIA.getScore() >= this.maximumScore && this.IMC.getScore() >= this.maximumScore) {
    324. endGame();
    325. for(Player p : instance.ph.getPlayers()) {
    326. p.sendMessage(Messages.draw);
    327. }
    328. } else if(this.MILITIA.getScore() >= this.maximumScore) {
    329. endGame();
    330. for(Player p : instance.ph.getPlayers()) {
    331. p.sendMessage(Messages.militiaWon);
    332. }
    333. } else if(this.IMC.getScore() >= this.maximumScore) {
    334. endGame();
    335. for(Player p : instance.ph.getPlayers()) {
    336. p.sendMessage(Messages.imcWon);
    337. }
    338. }
    339. this.currentCount--;
    340. } else {
    341. if(this.IMC.getScore() == MILITIA.getScore()) {
    342. for(Player p : instance.ph.getPlayers()) {
    343. p.sendMessage(Messages.draw);
    344. }
    345. }
    346. endGame();
    347. }
    348. }
    349. }
    350. }
    351.  
    352. //Events
    353.  
    354. /**
    355. * What happens when a Player respawns...
    356. * @param event PlayerRespawnEvent object
    357. */
    358. @EventHandler
    359. public void onRespawn(PlayerRespawnEvent event) {
    360. if(!this.isCancelled() && MainComponent.getInstance().getState() == ServerState.GAME_MODE) {
    361. if(IMC.containsPlayer(event.getPlayer())) {
    362. event.setRespawnLocation(this.getSpawnIMC());
    363. }
    364. else if(MILITIA.containsPlayer(event.getPlayer())) {
    365. event.setRespawnLocation(this.getSpawnMilitia());
    366. }
    367. else {
    368. event.getPlayer().sendMessage(ChatColor.RED + "An error occured whilst trying to teleport you to the spawn locations. You're not on a team.");
    369. }
    370. }
    371. }
    372.  
    373. /**
    374. * What happens once a player has died
    375. * @param event PlayerDeathEvent object
    376. */
    377. @EventHandler
    378. public void onDeath(PlayerDeathEvent event) {
    379. if(!this.isCancelled() && MainComponent.getInstance().getState() == ServerState.GAME_MODE) {
    380. if(event.getEntity() instanceof Player) {
    381. if(IMC.containsPlayer((Player) event.getEntity())) {
    382. MILITIA.addScore(1);
    383. }
    384. else if(MILITIA.containsPlayer((Player) event.getEntity())) {
    385. IMC.addScore(1);
    386. }
    387. }
    388. }
    389. }
    390.  
    391. /**
    392. * What happens once a player takes damage
    393. * @param event EntityDamageEvent object
    394. */
    395. @EventHandler
    396. public void onDamage(EntityDamageEvent event) {
    397. if(!this.isCancelled() && MainComponent.getInstance().getState() == ServerState.GAME_MODE) {
    398. if(event.getEntity() instanceof Player) {
    399. if(event.getCause() == DamageCause.FALL) {
    400. event.setCancelled(true);
    401. }
    402. }
    403. }
    404. }
    405.  
    406. /**
    407. * What happens when a player breaks a block
    408. * @param event BlockPlaceEvent object
    409. */
    410. @EventHandler
    411. public void onBreak(BlockBreakEvent event) {
    412. if(!this.isCancelled() && MainComponent.getInstance().getState() == ServerState.GAME_MODE) {
    413. this.setCancelled(true);
    414. }
    415. }
    416.  
    417. /**
    418. * What happens when a player interacts with a block.
    419. * @param event PlayerInteractEvent object
    420. */
    421. @EventHandler
    422. public void onInteract(PlayerInteractEvent event) {
    423. if(!this.isCancelled() && MainComponent.getInstance().getState() == ServerState.GAME_MODE) {
    424. this.setCancelled(true);
    425. }
    426. }
    427.  
    428.  
    429.  
    430.  
    431.  
    432.  
    433.  
    434.  
    435. //The code which handles Titans
    436.  
    437.  
    438.  
    439.  
    440.  
    441.  
    442.  
    443. /**
    444. * This is a loop which goes along with the default loop
    445. */
    446. private void titanLoopHandler() {
    447. //loop through each person and lower his timer...
    448. for(Entry<String, Integer> entry : this.titanTimer.entrySet()) {
    449. if(!(this.titanManager.getTitans().size() >= maximumTitans)) {
    450. if(entry.getValue() >= 0) {
    451. this.titanTimer.remove(entry);
    452.  
    453. int i = entry.getValue();
    454. this.titanTimer.put(entry.getKey(), i--);
    455. } else {
    456. if(Bukkit.getServer().getPlayer(entry.getKey()) != null) {
    457. boolean hasTitan = false;
    458. for(Titan t : this.titanManager.getTitans()) {
    459. if(t.getOwner().getName().equalsIgnoreCase(entry.getKey())) {
    460. hasTitan = true;
    461. }
    462. }
    463. if(!hasTitan) {
    464. giveBeacon(Bukkit.getServer().getPlayer(entry.getKey()));
    465. }
    466. } else {
    467.  
    468. }
    469. }
    470. }
    471. }
    472. }
    473.  
    474. /**
    475. * Give a player a beacon
    476. * @param player Player object
    477. */
    478. public void giveBeacon(Player player) {
    479. player.getInventory().addItem(new ItemStack(beaconMaterial, 1));
    480. }
    481.  
    482. /**
    483. * What happens when a player places a block
    484. * @param event BlockPlaceEvent object
    485. */
    486. @EventHandler
    487. public void onPlace(BlockPlaceEvent event) {
    488. if(!this.isCancelled() && MainComponent.getInstance().getState() == ServerState.GAME_MODE) {
    489. if(event.getBlock().getType() == beaconMaterial) {
    490. if(!(this.titanManager.getTitans().size() >= maximumTitans)) {
    491. event.getPlayer().getInventory().remove(beaconMaterial);
    492.  
    493. BeaconPlaceEvent ev = new BeaconPlaceEvent(event.getBlock().getLocation(), event.getPlayer());
    494. MainComponent.getInstance().getServer().getPluginManager().callEvent(ev);
    495. } else {
    496. event.getPlayer().sendMessage(ChatColor.RED + "You cannot place a beacon at this time.");
    497. event.getPlayer().sendMessage(ChatColor.RED + "Maximum number of titans are in play.");
    498. }
    499. }
    500. event.setCancelled(true);
    501. }
    502. }
    503.  
    504. /**
    505. * When a beacon is placed
    506. * @param event BeaconPlaceEvent object
    507. */
    508. @EventHandler
    509. public void onBeacon(BeaconPlaceEvent event) {
    510. ChatColor color = ChatColor.GREEN;
    511. if(this.IMC.containsPlayer(event.getPlayer())) {
    512. color = ChatColor.BLUE;
    513. } else if(this.MILITIA.containsPlayer(event.getPlayer())) {
    514. color = ChatColor.RED;
    515. }
    516. Titan titan = new Titan(event.getLocation().add(0, 50, 0), event.getPlayer(), color);
    517.  
    518. boolean hasTitan = false;
    519. for(Titan t : this.titanManager.getTitans()) {
    520. if(t.getOwner().getName().equalsIgnoreCase(event.getPlayer().getName())) {
    521. hasTitan = true;
    522. }
    523. }
    524. if(!hasTitan) {
    525. this.titanManager.addTitan(titan);
    526. } else {
    527. event.getPlayer().sendMessage(ChatColor.RED + "You already have a Titan");
    528. }
    529.  
    530. }
    531.  
    532. /**
    533. * When an entity takes damage
    534. * @param event EntityDamageEvent object
    535. */
    536. @EventHandler
    537. public void onEntityDamage(EntityDamageEvent event) {
    538. if(event.getEntity() instanceof IronGolem) {
    539. event.setCancelled(true);
    540. }
    541. }
    542.  
    543. /**
    544. * When an entity takes damage caused by another entity
    545. * @param event EntityDamageByEntityEvent object
    546. */
    547. @EventHandler
    548. public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    549. if(event.getEntity() instanceof IronGolem) {
    550. for(Titan t : this.titanManager.getTitans()) {
    551. if(t.getGolem() == event.getEntity()) {
    552. if(event.getDamager() instanceof Player) {
    553. if(event.getCause() == DamageCause.CONTACT) {
    554. if(((Player) event.getDamager()).getName().equalsIgnoreCase(t.getOwner().getName())) {
    555. //Set mounted!
    556. }
    557. }
    558. }
    559. }
    560. }
    561. event.setCancelled(true);
    562. }
    563. }
    564.  
    565. }
    566.  


    In case it's needed, here's my config.yml
    Code:
    minimum-requirement: 1
    maximum-score: 100
    maximum-titans: 3
    timer:
      game: 60
      intermission: 20
      titan-wait: 15
    lobby:
      spawn: {}
    LOBBY:
      spawn:
        x: -630.1068948934618
        y: 5.0
        z: -630.000623558105
        yaw: 132.06277
        pitch: 18.455997
        world: hub1
    
    And here's my maps.yml
    Code:
    maps:
    arena1:
    world: hub1

    Any help would be appreciated. -Thanks XD
     
  2. Offline

    Plugers11

    Maybe use randoms ?
     
  3. Offline

    Xyplo

    I'll give it a shot. :)

    Plugers11 Update: I didn't use Random to select teams. I got my code working but it selects teams but puts every player on the IMC team. Is it because it's trying to add every player to a team at the same time?
    Code:java
    1. public void startGame() {
    2.  
    3. for(Player p : Bukkit.getServer().getOnlinePlayers()) {
    4. if(!IMC.containsPlayer(p) && !MILITIA.containsPlayer(p)) {
    5. if(IMC.getSize() > MILITIA.getSize()) {
    6. MILITIA.addPlayer(p);
    7. } else {
    8. if(!(IMC.getSize() > MILITIA.getSize())) {
    9. IMC.addPlayer(p);
    10. }
    11. }
    12. }
    13. }
    14. instance.setState(GameState.IN_GAME);
    15. }
    16. private void initialiseTeams() {
    17.  
    18. for(Player p : Bukkit.getServer().getOnlinePlayers()) {
    19.  
    20. if(IMC.containsPlayer(p)) {
    21. p.teleport(this.getSpawnIMC());
    22. p.sendMessage(ChatColor.BLUE + "You're on the IMC team.");
    23. if(!this.titanTimer.containsKey(p.getName()))
    24. this.titanTimer.put(p.getName(), this.defaultTitanTimer);
    25. }
    26. else if(MILITIA.containsPlayer(p)) {
    27. p.teleport(this.getSpawnMilitia());
    28. p.sendMessage(ChatColor.RED + "You're on the MILITIA team.");
    29. if(!this.titanTimer.containsKey(p.getName()))
    30. this.titanTimer.put(p.getName(), this.defaultTitanTimer);
    31. }
    32. else {
    33. p.sendMessage(ChatColor.RED + "An error occured whilst trying to teleport you to the spawn locations. You're not on a team.");
    34. }
    35. }
    36.  
    37. }
    38.  
    39.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  4. Offline

    macboinc

    Case and switch.
     
  5. Offline

    Xyplo

    How do they work? (Just give me a basic type of code, it doesn't have to have anything to do with mine) Just to help me out a ltitle.
     
  6. Offline

    macboinc

    I don't know how to use them for random, but I can if you need a player to join the team with less players
     
  7. Offline

    Xyplo

    That'll be great to equal out teams, Spoon Feed me a little ?? XD

    le bump because no one's helping me out. :) Like a rebel

    Not at all.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  8. Offline

    CarPet

    Xyplo Instead of just posting countless threads on here and distracting from others why don't you look around and see if people have asked the same question before?
     
  9. Offline

    Xyplo

    Because this was created a while ago and it's event stated as 'solved'... XD
     
Thread Status:
Not open for further replies.

Share This Page