Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
- import net.milkbowl.vault.economy.Economy;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Server;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.Sign;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.block.SignChangeEvent;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.ServicesManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitScheduler;
- public class Projeto
- extends JavaPlugin
- implements Listener, CommandExecutor
- {
- public List<Player> list = new ArrayList();
- public static Economy i = null;
- public boolean aberto = false;
- public boolean risco = false;
- public boolean pvp = false;
- public boolean premio_ativo = false;
- private boolean setupEconomy()
- {
- RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(Economy.class);
- if (economyProvider != null) {
- i = (Economy)economyProvider.getProvider();
- }
- return i != null;
- }
- public void onEnable()
- {
- ConsoleCommandSender sender = Bukkit.getConsoleSender();
- getServer().getPluginManager().registerEvents(this, this);
- if (!setupEconomy())
- {
- sender.sendMessage("§f[§bEventos Automáticos§f] §cAdicione O Vault, e um sistema de econômia para que o Plugin funcione.");
- getServer().getPluginManager().disablePlugin(this);
- }
- File file = new File(getDataFolder(), "config.yml");
- if (!file.exists()) {
- try
- {
- saveResource("config_template.yml", false);
- File file2 = new File(getDataFolder(), "config_template.yml");
- file2.renameTo(new File(getDataFolder(), "config.yml"));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- reloadConfig();
- sender.sendMessage("§f[§bEventos Automáticos§f] Plugin inicializado. (Autor=lMassari)");
- }
- public void onDisable()
- {
- ConsoleCommandSender sender = Bukkit.getConsoleSender();
- sender.sendMessage("§f[§bEventos Automáticos§f] Plugin finalizado. (Autor=lMassari)");
- }
- public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args)
- {
- Player p = sender == getServer().getConsoleSender() ? null : (Player)sender;
- if (cmd.getName().equalsIgnoreCase("evento"))
- {
- reloadConfig();
- if (args.length == 0)
- {
- if (p != null)
- {
- if (this.aberto)
- {
- if (this.list.contains(p))
- {
- sender.sendMessage("§6[WarEventos] §eVocê já está participando!");
- }
- else
- {
- sender.sendMessage("§6[WarEventos] §eVocê foi adicionado á lista de participantes!");
- this.list.add(p);
- World world = getServer().getWorld(getConfig().getString("Lobby.Mundo"));
- int posX = getConfig().getInt("Lobby.x");
- int posY = getConfig().getInt("Lobby.y");
- int posZ = getConfig().getInt("Lobby.z");
- p.teleport(new Location(world, posX, posY, posZ));
- }
- }
- else if (!this.aberto) {
- sender.sendMessage("§6[WarEventos] §eNenhum evento ocorrendo!");
- }
- }
- else if (this.aberto) {
- sender.sendMessage("§6[WarEventos] §eJá há um evento ocorrendo!");
- } else {
- sender.sendMessage("§6[WarEventos] §eCorreto: /evento abrir <nome> <on/off> <x> <y> <z> <world>");
- }
- }
- else if (args[0].equalsIgnoreCase("abrir")) {
- if (sender.hasPermission("evento.abrir"))
- {
- if (args.length < 8)
- {
- sender.sendMessage("§6[WarEventos] §eCorreto: /evento abrir <nome> <pvp: on/off> <risco: on/off> <x> <y> <z> <world>");
- }
- else
- {
- if (args[2].equalsIgnoreCase("on")) {
- this.pvp = true;
- } else if (args[2].equalsIgnoreCase("off")) {
- this.pvp = false;
- } else if (args[3].equalsIgnoreCase("on")) {
- this.risco = true;
- } else if (args[3].equalsIgnoreCase("off")) {
- this.risco = false;
- }
- String nome = args[1];
- int x = Integer.parseInt(args[4]);
- int y = Integer.parseInt(args[5]);
- int z = Integer.parseInt(args[6]);
- World w = getServer().getWorld(args[7]);
- try
- {
- this.aberto = true;
- IniciarEvento(x, y, z, w, nome, 5);
- }
- catch (Exception e)
- {
- sender.sendMessage("§6[WarEventos] §eCorreto: /evento abrir <nome> <on/off> <x> <y> <z> <world>");
- }
- }
- }
- else {
- sender.sendMessage("§6[WarEventos] §eSem permissão.");
- }
- }
- }
- return false;
- }
- public void IniciarEvento(final int x, final int y, final int z, final World w, final String nome, final int d)
- {
- getServer().broadcastMessage("§d[Evento Automático] Evento " + nome + " valendo " + getConfig().getInt("Config.AutoAward") + " Coin's!");
- getServer().broadcastMessage("§d[Evento Automático] PvP: [" + (this.pvp ? "§4ON§d" : "§aOFF§d") + "] / Risco: [" + (this.risco ? "§4ON§d" : "§aOFF§d") + "]");
- getServer().broadcastMessage("§d[Evento Automático] Para participar use /evento!");
- getServer().getScheduler().runTaskLater(this, new Runnable()
- {
- public void run()
- {
- if (d > 0)
- {
- Projeto.this.IniciarEvento(x, y, z, w, nome, d - 1);
- }
- else
- {
- Projeto.this.aberto = false;
- Projeto.this.getServer().broadcastMessage("§d[Evento Automático] Evento " + nome + " começando!");
- Projeto.this.getServer().broadcastMessage("§d[Evento Automático] Todos participantes teleportados ao Evento!");
- Projeto.this.getServer().broadcastMessage("§d[Evento Automático] Boa sorte á todos :D");
- for (Player me : Projeto.this.list)
- {
- me.teleport(new Location(w, x, y, z));
- me.sendMessage(" ");
- me.sendMessage("§6[WarEventos] §eVocê foi teleportado até o evento " + nome + "!");
- }
- }
- }
- }, 200L);
- }
- @EventHandler(priority=EventPriority.HIGHEST)
- private void onDc(PlayerQuitEvent e)
- {
- if (this.list.contains(e.getPlayer()))
- {
- reloadConfig();
- this.list.remove(e.getPlayer());
- e.getPlayer().sendMessage("§6[WarEventos] §eVocê foi desclassificado do evento!");
- World world = getServer().getWorld(getConfig().getString("Saida.Mundo"));
- int posX = getConfig().getInt("Saida.x");
- int posY = getConfig().getInt("Saida.y");
- int posZ = getConfig().getInt("Saida.z");
- e.getPlayer().teleport(new Location(world, posX, posY, posZ));
- }
- }
- @EventHandler(priority=EventPriority.HIGHEST)
- private void onDeath(PlayerDeathEvent e)
- {
- if (this.list.contains(e.getEntity().getPlayer()))
- {
- reloadConfig();
- this.list.remove(e.getEntity().getPlayer());
- e.getEntity().getPlayer().sendMessage("§6[WarEventos] §eVocê foi desclassificado do evento!");
- World world = getServer().getWorld(getConfig().getString("Saida.Mundo"));
- int posX = getConfig().getInt("Saida.x");
- int posY = getConfig().getInt("Saida.y");
- int posZ = getConfig().getInt("Saida.z");
- e.getEntity().getPlayer().teleport(new Location(world, posX, posY, posZ));
- }
- }
- @EventHandler(priority=EventPriority.HIGHEST)
- private void onSignInteract(PlayerInteractEvent e)
- {
- if (this.list.contains(e.getPlayer()))
- {
- reloadConfig();
- if (((e.getAction() == Action.LEFT_CLICK_BLOCK) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) &&
- ((e.getClickedBlock().getState() instanceof Sign)))
- {
- Sign placa = (Sign)e.getClickedBlock().getState();
- if (placa.getLine(0).equalsIgnoreCase("[EventoAuto]"))
- {
- for (Player me : this.list)
- {
- World world = getServer().getWorld(getConfig().getString("Saida.Mundo"));
- int posX = getConfig().getInt("Saida.x");
- int posY = getConfig().getInt("Saida.y");
- int posZ = getConfig().getInt("Saida.z");
- me.teleport(new Location(world, posX, posY, posZ));
- }
- getServer().broadcastMessage("§d[Evento Automático] Evento " + placa.getLine(1) + " encerrado!");
- getServer().broadcastMessage("§d[Evento Automático] O Vencedor foi o jogador " + e.getPlayer().getName() + "!");
- getServer().broadcastMessage("§d[Evento Automático] Prêmio pago, evento finalizado!");
- this.list.clear();
- double pay = getConfig().getDouble("Config.AutoAward");
- i.depositPlayer(e.getPlayer().getName(), pay);
- }
- }
- }
- }
- @EventHandler(priority=EventPriority.HIGHEST)
- private void onCreateSign(SignChangeEvent e)
- {
- if (e.getLine(0).equalsIgnoreCase("[EventoAuto]")) {
- if (e.getPlayer().hasPermission("evento.sign"))
- {
- if (e.getLine(1).length() == 0)
- {
- e.setCancelled(true);
- e.getBlock().breakNaturally();
- e.getPlayer().sendMessage("§6[WarEventos] §eFaltou o nome do evento na linha 2!");
- }
- else
- {
- e.setLine(0, "[EventoAuto]");
- e.setLine(1, e.getLine(1));
- e.setLine(2, "-Prêmio-");
- e.setLine(3, "<T>Click Aqui<T>");
- }
- }
- else if (!e.getPlayer().hasPermission("evento.sign"))
- {
- e.setCancelled(true);
- e.getBlock().breakNaturally();
- e.getPlayer().sendMessage("§6[WarEventos] §eSem permissão.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement