Guest User

Untitled

a guest
Feb 21st, 2016
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.MattBlazeHD.OITCPlus;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.Sound;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.player.PlayerDropItemEvent;
  11. import org.bukkit.event.player.PlayerJoinEvent;
  12. import org.bukkit.event.player.PlayerQuitEvent;
  13. import org.bukkit.plugin.Plugin;
  14. import org.bukkit.scheduler.BukkitRunnable;
  15. public class Game implements Listener{
  16.  
  17. Plugin plugin = Main.getPlugin();
  18. @EventHandler
  19. public void onDrop(PlayerDropItemEvent e){
  20. e.getItemDrop();
  21. e.setCancelled(true);
  22. }
  23.  
  24. private static int time = 60*2;
  25. int nplayer = Bukkit.getOnlinePlayers().size();
  26.  
  27. @EventHandler
  28. public void onLeft(PlayerQuitEvent e){
  29. nplayer--;
  30. }
  31.  
  32. @EventHandler
  33. public void onJoin(PlayerJoinEvent e) {
  34. nplayer++;
  35. if(nplayer >= 2){
  36. time = 60*2;
  37. Bukkit.broadcastMessage(ChatColor.AQUA + "2 minuti " + ChatColor.GREEN + "per iniziare la partita!");
  38. new BukkitRunnable() {
  39. @SuppressWarnings("deprecation")
  40. public int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(), this, 0L, 20L);
  41. @Override
  42. public void run() {
  43. if (time > 0) {
  44. time--;
  45. for(Player p: Bukkit.getOnlinePlayers()){
  46. p.setLevel(time);
  47. }
  48. switch(time){
  49. case 60:
  50. for(Player p : Bukkit.getOnlinePlayers()){
  51. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 3, 0);
  52. }
  53. Bukkit.broadcastMessage(ChatColor.AQUA + "1 minuto " + ChatColor.GREEN + "per iniziare la partita!");
  54. break;
  55. case 30:
  56. for(Player p : Bukkit.getOnlinePlayers()){
  57. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 3, 0);
  58. }
  59. Bukkit.broadcastMessage(ChatColor.AQUA + "30 secondi " + ChatColor.GREEN + "per iniziare la partita!");
  60. break;
  61. case 10:
  62. for(Player p : Bukkit.getOnlinePlayers()){
  63. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 3, 0);
  64. }
  65. Bukkit.broadcastMessage(ChatColor.AQUA + "10 secondi " + ChatColor.GREEN + "per iniziare la partita!");
  66. break;
  67. case 5:
  68. for(Player p : Bukkit.getOnlinePlayers()){
  69. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 3, 0);
  70. }
  71. Bukkit.broadcastMessage(ChatColor.AQUA + "5 secondi " + ChatColor.GREEN + "per iniziare la partita!");
  72. break;
  73. case 4:
  74. for(Player p : Bukkit.getOnlinePlayers()){
  75. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 3, 0);
  76. }
  77. Bukkit.broadcastMessage(ChatColor.AQUA + "4 secondi " + ChatColor.GREEN + "per iniziare la partita!");
  78. break;
  79. case 3:
  80. for(Player p : Bukkit.getOnlinePlayers()){
  81. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 3, 0);
  82. }
  83. Bukkit.broadcastMessage(ChatColor.AQUA + "3 secondi " + ChatColor.GREEN + "per iniziare la partita!");
  84. break;
  85. case 2:
  86. for(Player p : Bukkit.getOnlinePlayers()){
  87. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 3, 0);
  88. }
  89. Bukkit.broadcastMessage(ChatColor.AQUA + "2 secondi " + ChatColor.GREEN + "per iniziare la partita!");
  90. break;
  91. case 1:
  92. for(Player p : Bukkit.getOnlinePlayers()){
  93. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 3, 0);
  94. }
  95. Bukkit.broadcastMessage(ChatColor.AQUA + "1 secondo " + ChatColor.GREEN + "per iniziare la partita!");
  96. break;
  97. }
  98. if(time == 0){
  99. Bukkit.getScheduler().cancelTask(taskID);
  100. Bukkit.broadcastMessage(ChatColor.RED + "Che il gioco abbia inizio!");
  101. Player p = e.getPlayer();
  102. p.setLevel(0);
  103. if(p.getWorld().equals("lobby")){
  104. Bukkit.broadcastMessage("pelopelo");
  105. Location loc = new Location(plugin.getServer().getWorld("Mappa1"), plugin.getServer().getWorld("Mappa1").getSpawnLocation().getX(), plugin.getServer().getWorld("Mappa1").getSpawnLocation().getY(), plugin.getServer().getWorld("Mappa1").getSpawnLocation().getZ());
  106. p.teleport(loc);
  107. }
  108. }
  109. if(nplayer < 2){
  110. Bukkit.getScheduler().cancelTask(taskID);
  111. Bukkit.broadcastMessage(ChatColor.GREEN + "Non si disponde dei player necessari, countdown annullato!");
  112. time = 0;
  113. for(Player p : Bukkit.getOnlinePlayers()){
  114. p.setLevel(time);
  115. }
  116. }
  117. }
  118. }
  119. };
  120. }
  121. }
  122. }
RAW Paste Data