Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.52 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import net.milkbowl.vault.economy.Economy;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.Server;
  8. import org.bukkit.World;
  9. import org.bukkit.block.Block;
  10. import org.bukkit.block.Sign;
  11. import org.bukkit.command.Command;
  12. import org.bukkit.command.CommandExecutor;
  13. import org.bukkit.command.CommandSender;
  14. import org.bukkit.command.ConsoleCommandSender;
  15. import org.bukkit.configuration.file.FileConfiguration;
  16. import org.bukkit.entity.Player;
  17. import org.bukkit.event.EventHandler;
  18. import org.bukkit.event.EventPriority;
  19. import org.bukkit.event.Listener;
  20. import org.bukkit.event.block.Action;
  21. import org.bukkit.event.block.SignChangeEvent;
  22. import org.bukkit.event.entity.PlayerDeathEvent;
  23. import org.bukkit.event.player.PlayerInteractEvent;
  24. import org.bukkit.event.player.PlayerQuitEvent;
  25. import org.bukkit.plugin.PluginManager;
  26. import org.bukkit.plugin.RegisteredServiceProvider;
  27. import org.bukkit.plugin.ServicesManager;
  28. import org.bukkit.plugin.java.JavaPlugin;
  29. import org.bukkit.scheduler.BukkitScheduler;
  30.  
  31. public class Projeto
  32. extends JavaPlugin
  33. implements Listener, CommandExecutor
  34. {
  35. public List<Player> list = new ArrayList();
  36. public static Economy i = null;
  37. public boolean aberto = false;
  38. public boolean risco = false;
  39. public boolean pvp = false;
  40. public boolean premio_ativo = false;
  41.  
  42. private boolean setupEconomy()
  43. {
  44. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(Economy.class);
  45. if (economyProvider != null) {
  46. i = (Economy)economyProvider.getProvider();
  47. }
  48. return i != null;
  49. }
  50.  
  51. public void onEnable()
  52. {
  53. ConsoleCommandSender sender = Bukkit.getConsoleSender();
  54. getServer().getPluginManager().registerEvents(this, this);
  55. if (!setupEconomy())
  56. {
  57. sender.sendMessage("§f[§bEventos Automáticos§f] §cAdicione O Vault, e um sistema de econômia para que o Plugin funcione.");
  58. getServer().getPluginManager().disablePlugin(this);
  59. }
  60. File file = new File(getDataFolder(), "config.yml");
  61. if (!file.exists()) {
  62. try
  63. {
  64. saveResource("config_template.yml", false);
  65. File file2 = new File(getDataFolder(), "config_template.yml");
  66. file2.renameTo(new File(getDataFolder(), "config.yml"));
  67. }
  68. catch (Exception e)
  69. {
  70. e.printStackTrace();
  71. }
  72. }
  73. reloadConfig();
  74. sender.sendMessage("§f[§bEventos Automáticos§f] Plugin inicializado. (Autor=lMassari)");
  75. }
  76.  
  77. public void onDisable()
  78. {
  79. ConsoleCommandSender sender = Bukkit.getConsoleSender();
  80. sender.sendMessage("§f[§bEventos Automáticos§f] Plugin finalizado. (Autor=lMassari)");
  81. }
  82.  
  83. public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args)
  84. {
  85. Player p = sender == getServer().getConsoleSender() ? null : (Player)sender;
  86. if (cmd.getName().equalsIgnoreCase("evento"))
  87. {
  88. reloadConfig();
  89. if (args.length == 0)
  90. {
  91. if (p != null)
  92. {
  93. if (this.aberto)
  94. {
  95. if (this.list.contains(p))
  96. {
  97. sender.sendMessage("§6[WarEventos] §eVocê já está participando!");
  98. }
  99. else
  100. {
  101. sender.sendMessage("§6[WarEventos] §eVocê foi adicionado á lista de participantes!");
  102. this.list.add(p);
  103. World world = getServer().getWorld(getConfig().getString("Lobby.Mundo"));
  104. int posX = getConfig().getInt("Lobby.x");
  105. int posY = getConfig().getInt("Lobby.y");
  106. int posZ = getConfig().getInt("Lobby.z");
  107. p.teleport(new Location(world, posX, posY, posZ));
  108. }
  109. }
  110. else if (!this.aberto) {
  111. sender.sendMessage("§6[WarEventos] §eNenhum evento ocorrendo!");
  112. }
  113. }
  114. else if (this.aberto) {
  115. sender.sendMessage("§6[WarEventos] §eJá há um evento ocorrendo!");
  116. } else {
  117. sender.sendMessage("§6[WarEventos] §eCorreto: /evento abrir <nome> <on/off> <x> <y> <z> <world>");
  118. }
  119. }
  120. else if (args[0].equalsIgnoreCase("abrir")) {
  121. if (sender.hasPermission("evento.abrir"))
  122. {
  123. if (args.length < 8)
  124. {
  125. sender.sendMessage("§6[WarEventos] §eCorreto: /evento abrir <nome> <pvp: on/off> <risco: on/off> <x> <y> <z> <world>");
  126. }
  127. else
  128. {
  129. if (args[2].equalsIgnoreCase("on")) {
  130. this.pvp = true;
  131. } else if (args[2].equalsIgnoreCase("off")) {
  132. this.pvp = false;
  133. } else if (args[3].equalsIgnoreCase("on")) {
  134. this.risco = true;
  135. } else if (args[3].equalsIgnoreCase("off")) {
  136. this.risco = false;
  137. }
  138. String nome = args[1];
  139. int x = Integer.parseInt(args[4]);
  140. int y = Integer.parseInt(args[5]);
  141. int z = Integer.parseInt(args[6]);
  142. World w = getServer().getWorld(args[7]);
  143. try
  144. {
  145. this.aberto = true;
  146. IniciarEvento(x, y, z, w, nome, 5);
  147. }
  148. catch (Exception e)
  149. {
  150. sender.sendMessage("§6[WarEventos] §eCorreto: /evento abrir <nome> <on/off> <x> <y> <z> <world>");
  151. }
  152. }
  153. }
  154. else {
  155. sender.sendMessage("§6[WarEventos] §eSem permissão.");
  156. }
  157. }
  158. }
  159. return false;
  160. }
  161.  
  162. public void IniciarEvento(final int x, final int y, final int z, final World w, final String nome, final int d)
  163. {
  164. getServer().broadcastMessage("§d[Evento Automático] Evento " + nome + " valendo " + getConfig().getInt("Config.AutoAward") + " Coin's!");
  165. getServer().broadcastMessage("§d[Evento Automático] PvP: [" + (this.pvp ? "§4ON§d" : "§aOFF§d") + "] / Risco: [" + (this.risco ? "§4ON§d" : "§aOFF§d") + "]");
  166. getServer().broadcastMessage("§d[Evento Automático] Para participar use /evento!");
  167. getServer().getScheduler().runTaskLater(this, new Runnable()
  168. {
  169. public void run()
  170. {
  171. if (d > 0)
  172. {
  173. Projeto.this.IniciarEvento(x, y, z, w, nome, d - 1);
  174. }
  175. else
  176. {
  177. Projeto.this.aberto = false;
  178. Projeto.this.getServer().broadcastMessage("§d[Evento Automático] Evento " + nome + " começando!");
  179. Projeto.this.getServer().broadcastMessage("§d[Evento Automático] Todos participantes teleportados ao Evento!");
  180. Projeto.this.getServer().broadcastMessage("§d[Evento Automático] Boa sorte á todos :D");
  181. for (Player me : Projeto.this.list)
  182. {
  183. me.teleport(new Location(w, x, y, z));
  184. me.sendMessage(" ");
  185. me.sendMessage("§6[WarEventos] §eVocê foi teleportado até o evento " + nome + "!");
  186. }
  187. }
  188. }
  189. }, 200L);
  190. }
  191.  
  192. @EventHandler(priority=EventPriority.HIGHEST)
  193. private void onDc(PlayerQuitEvent e)
  194. {
  195. if (this.list.contains(e.getPlayer()))
  196. {
  197. reloadConfig();
  198. this.list.remove(e.getPlayer());
  199. e.getPlayer().sendMessage("§6[WarEventos] §eVocê foi desclassificado do evento!");
  200. World world = getServer().getWorld(getConfig().getString("Saida.Mundo"));
  201. int posX = getConfig().getInt("Saida.x");
  202. int posY = getConfig().getInt("Saida.y");
  203. int posZ = getConfig().getInt("Saida.z");
  204. e.getPlayer().teleport(new Location(world, posX, posY, posZ));
  205. }
  206. }
  207.  
  208. @EventHandler(priority=EventPriority.HIGHEST)
  209. private void onDeath(PlayerDeathEvent e)
  210. {
  211. if (this.list.contains(e.getEntity().getPlayer()))
  212. {
  213. reloadConfig();
  214. this.list.remove(e.getEntity().getPlayer());
  215. e.getEntity().getPlayer().sendMessage("§6[WarEventos] §eVocê foi desclassificado do evento!");
  216. World world = getServer().getWorld(getConfig().getString("Saida.Mundo"));
  217. int posX = getConfig().getInt("Saida.x");
  218. int posY = getConfig().getInt("Saida.y");
  219. int posZ = getConfig().getInt("Saida.z");
  220. e.getEntity().getPlayer().teleport(new Location(world, posX, posY, posZ));
  221. }
  222. }
  223.  
  224. @EventHandler(priority=EventPriority.HIGHEST)
  225. private void onSignInteract(PlayerInteractEvent e)
  226. {
  227. if (this.list.contains(e.getPlayer()))
  228. {
  229. reloadConfig();
  230. if (((e.getAction() == Action.LEFT_CLICK_BLOCK) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) &&
  231. ((e.getClickedBlock().getState() instanceof Sign)))
  232. {
  233. Sign placa = (Sign)e.getClickedBlock().getState();
  234. if (placa.getLine(0).equalsIgnoreCase("[EventoAuto]"))
  235. {
  236. for (Player me : this.list)
  237. {
  238. World world = getServer().getWorld(getConfig().getString("Saida.Mundo"));
  239. int posX = getConfig().getInt("Saida.x");
  240. int posY = getConfig().getInt("Saida.y");
  241. int posZ = getConfig().getInt("Saida.z");
  242. me.teleport(new Location(world, posX, posY, posZ));
  243. }
  244. getServer().broadcastMessage("§d[Evento Automático] Evento " + placa.getLine(1) + " encerrado!");
  245. getServer().broadcastMessage("§d[Evento Automático] O Vencedor foi o jogador " + e.getPlayer().getName() + "!");
  246. getServer().broadcastMessage("§d[Evento Automático] Prêmio pago, evento finalizado!");
  247. this.list.clear();
  248. double pay = getConfig().getDouble("Config.AutoAward");
  249. i.depositPlayer(e.getPlayer().getName(), pay);
  250. }
  251. }
  252. }
  253. }
  254.  
  255. @EventHandler(priority=EventPriority.HIGHEST)
  256. private void onCreateSign(SignChangeEvent e)
  257. {
  258. if (e.getLine(0).equalsIgnoreCase("[EventoAuto]")) {
  259. if (e.getPlayer().hasPermission("evento.sign"))
  260. {
  261. if (e.getLine(1).length() == 0)
  262. {
  263. e.setCancelled(true);
  264. e.getBlock().breakNaturally();
  265. e.getPlayer().sendMessage("§6[WarEventos] §eFaltou o nome do evento na linha 2!");
  266. }
  267. else
  268. {
  269. e.setLine(0, "[EventoAuto]");
  270. e.setLine(1, e.getLine(1));
  271. e.setLine(2, "-Prêmio-");
  272. e.setLine(3, "<T>Click Aqui<T>");
  273. }
  274. }
  275. else if (!e.getPlayer().hasPermission("evento.sign"))
  276. {
  277. e.setCancelled(true);
  278. e.getBlock().breakNaturally();
  279. e.getPlayer().sendMessage("§6[WarEventos] §eSem permissão.");
  280. }
  281. }
  282. }
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement