Advertisement
Panakotta00

Main.java

Oct 16th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.27 KB | None | 0 0
  1. package de.Panakotta00.Varo;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Map.Entry;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.Location;
  10. import org.bukkit.Material;
  11. import org.bukkit.OfflinePlayer;
  12. import org.bukkit.World;
  13. import org.bukkit.command.Command;
  14. import org.bukkit.command.CommandSender;
  15. import org.bukkit.configuration.file.FileConfiguration;
  16. import org.bukkit.craftbukkit.v1_8_R2.CraftOfflinePlayer;
  17. import org.bukkit.enchantments.Enchantment;
  18. import org.bukkit.entity.Player;
  19. import org.bukkit.event.Listener;
  20. import org.bukkit.plugin.Plugin;
  21. import org.bukkit.plugin.java.JavaPlugin;
  22.  
  23. import de.Panakotta00.Varo.Event.Events;
  24.  
  25. public class Main extends JavaPlugin {
  26.    
  27.     public static Boolean Tom = false;
  28.     public static FileConfiguration cfg;
  29.     public static ArrayList<Material> notAllowed = new ArrayList<Material>();
  30.     public static ArrayList<Enchantment> notAllowedE = new ArrayList<Enchantment>();
  31.     public static ArrayList<Player> peacePlayers = new ArrayList<Player>();
  32.     public static ArrayList<Player> banned = new ArrayList<Player>();
  33.     public static ArrayList<Player> wait_players = new ArrayList<Player>();
  34.     public static HashMap<Integer, Player> players = new HashMap<Integer, Player>();
  35.     public static HashMap<Integer, OfflinePlayer> offlineplayers = new HashMap<Integer, OfflinePlayer>();
  36.     public static HashMap<String, CraftOfflinePlayer[]> teams = new HashMap<String, CraftOfflinePlayer[]>();
  37.     public static HashMap<Integer, ArrayList<Integer>> lastLoc = new HashMap<Integer, ArrayList<Integer>>();
  38.     int loop2 = 0;
  39.    
  40.     ArenaManager arenaManager;
  41.    
  42.     @SuppressWarnings("unchecked")
  43.     public void onEnable() {
  44.         notAllowed.add(Material.GOLDEN_APPLE);
  45.         notAllowed.add(Material.SADDLE);
  46.         notAllowed.add(Material.POTION);
  47.         notAllowed.add(Material.FISHING_ROD);
  48.        
  49.         notAllowedE.add(Enchantment.FIRE_ASPECT);
  50.         notAllowedE.add(Enchantment.ARROW_FIRE);
  51.         notAllowedE.add(Enchantment.ARROW_INFINITE);
  52.        
  53.         loadConfig();
  54.         getServer().getPluginManager().registerEvents((Listener)new Events(), (Plugin)this);
  55.         if (cfg.get("Players") != null) {
  56.             int loop = 1;
  57.             while (true) {
  58.                 if (cfg.get("Players." + loop) != null) {
  59.                     offlineplayers.put(loop, (CraftOfflinePlayer) cfg.get("Players." + loop));
  60.                     loop++;
  61.                 } else {
  62.                     break;
  63.                 }
  64.             }
  65.         } if (cfg.contains("lastLoc")) {
  66.             int loop = 1;
  67.             while (true) {
  68.                 if (cfg.get("lastLoc." + loop) != null) {
  69.                     lastLoc.put(loop, (ArrayList<Integer>) cfg.get("lastLoc." + loop));
  70.                     loop++;
  71.                 } else {
  72.                     break;
  73.                 }
  74.             }
  75.         } if (cfg.getInt("Day") == 4) {
  76.             ArrayList<Integer> locs = (ArrayList<Integer>) cfg.getList("Portal");
  77.             Location loc = new Location((World) cfg.get("World"), Double.valueOf(locs.get(0)), Double.valueOf(locs.get(1)), Double.valueOf(locs.get(2)));
  78.            
  79.             getServer().getWorld(cfg.get("World").toString()).getBlockAt(loc).setType(Material.REDSTONE_BLOCK);
  80.         } if (cfg.getInt("Day") >= 8) {
  81.             cfg.set("Day", 1);
  82.         } if (cfg.getInt("Day") >= 1 && cfg.getInt("Day") <= 4) {
  83.             Tom = true;
  84.         //} if (cfg.contains("Teams")) {
  85.         //  int loop = 1;
  86.         //  while (true) {
  87.         //      if (cfg.get("Teams." + loop) != null) {
  88.         //          teams.put(cfg.getString("Teams." + cfg.getloop), (CraftOfflinePlayer[]) cfg.get("Teams." + loop));
  89.         //          loop++;
  90.         //      } else {
  91.         //          break;
  92.         //      }
  93.         //  }
  94.         }
  95.         System.out.println("[Varo] Varo-Plugin wurde gestartet!");
  96.         arenaManager = new ArenaManager(this);
  97.     }
  98.    
  99.     public void onDisable() {
  100.         if (offlineplayers.size() > 0) {
  101.             int loop = 1;
  102.             while (true) {
  103.                 if (offlineplayers.size() >= loop) {
  104.                     cfg.set("Players." + loop, offlineplayers.get(loop));
  105.                     loop++;
  106.                 } else {
  107.                     break;
  108.                 }
  109.             }
  110.         }
  111.         //for(Entry<Integer, Player> entry : players.entrySet()) {
  112.         //  cfg.set("Players." + entry.getKey(), entry.getValue());
  113.         //}
  114.         if (lastLoc.size() > 0) {
  115.             int loop = 1;
  116.             while (true) {
  117.                 if (lastLoc.size() >= loop) {
  118.                     cfg.set("lastLoc." + loop, lastLoc.get(loop));
  119.                     loop++;
  120.                 } else {
  121.                     break;
  122.                 }
  123.             }
  124.         }
  125.         if (cfg.contains("Day")) {
  126.             cfg.set("Day", cfg.getInt("Day") + 1);
  127.         }
  128.         saveConfig();
  129.         loadConfig();
  130.         System.out.println("[Varo] Varo-Plugin wurde gestopt!");
  131.     }
  132.    
  133.     public void loadConfig() {
  134.         getConfig().addDefault("Null", null);
  135.         cfg = this.getConfig();
  136.         cfg.options().copyDefaults(true);
  137.         saveConfig();
  138.     }
  139.    
  140.     @SuppressWarnings({ "deprecation", "static-access" })
  141.     public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
  142.         Player p = (Player)sender;
  143.         if (cmd.getName().equalsIgnoreCase("varo")) {
  144.             if (args.length >= 1) {
  145.                 if (args[0].equalsIgnoreCase("start") && p.hasPermission("Varo.start")) {
  146.                     cfg.set("Day", 1);
  147.                     int loop = 1;
  148.                     while (loop <= players.size()) {
  149.                         players.get(loop).sendMessage(ChatColor.GREEN + "The Countdown beginns!");
  150.                         players.get(loop).sendMessage(ChatColor.GREEN +"Still "+ ChatColor.RED +"60"+ ChatColor.GREEN +" seconds!");
  151.                        
  152.                         loop++;
  153.                     }
  154.                     loop2 = 60;
  155.                     getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
  156.                         @Override
  157.                         public void run() {
  158.                             if (loop2 == 30) {
  159.                                 int countdown = 1;
  160.                                 while (countdown <= players.size()) {
  161.                                     players.get(countdown).sendMessage(ChatColor.GREEN +"Still "+ ChatColor.RED +"30"+ ChatColor.GREEN +" seconds!");
  162.                                     countdown++;
  163.                                 }
  164.                             } else if (loop2 == 15) {
  165.                                 int countdown = 1;
  166.                                 while (countdown <= players.size()) {
  167.                                     players.get(countdown).sendMessage(ChatColor.GREEN +"Still "+ ChatColor.RED +"15"+ ChatColor.GREEN +" seconds!");
  168.                                     countdown++;
  169.                                 }
  170.                             } else if (loop2 <= 10 && loop2 > 0) {
  171.                                 int countdown = 1;
  172.                                 while (countdown <= players.size()) {
  173.                                     players.get(countdown).sendMessage(ChatColor.GREEN +"Still "+ ChatColor.GOLD + loop2 + ChatColor.GREEN +" seconds!");
  174.                                     countdown++;
  175.                                 }
  176.                             } else if (loop2 == 0) {
  177.                                 int countdown = 1;
  178.                                 while (countdown <= players.size()) {
  179.                                     players.get(countdown).sendMessage(ChatColor.RED +"Run!"+ ChatColor.GREEN +" Run "+ ChatColor.UNDERLINE +"faster"+ ChatColor.UNDERLINE +" as you can!");
  180.                                     players.get(countdown).sendMessage(ChatColor.GREEN +"Varo beginns!");
  181.                                     wait_players.remove(players.get(countdown));
  182.                                     peace(players.get(countdown));
  183.                                     countdown++;
  184.                                 }
  185.                             }
  186.                            
  187.                             loop2--;
  188.                         }
  189.                     }, 0, 20L);
  190.                 } else if (args[0].equalsIgnoreCase("addplayer") && p.hasPermission("Varo.addplayer")) {
  191.                     if (args.length == 4) {
  192.                         arenaManager.addPlayer(p, args[1], args[2], Integer.valueOf(args[3]));
  193.                     } else {
  194.                         p.sendMessage(ChatColor.GREEN +"Syntax: /varo addplayer <playername> <team> <nummer>");
  195.                     }
  196.                 } else if (args[0].equalsIgnoreCase("setspawn") && p.hasPermission("Varo.setspawn")) {
  197.                     if (args.length == 2) {
  198.                         arenaManager.setSpawn(p, Integer.valueOf(args[1].toString().intern()));
  199.                     } else {
  200.                         p.sendMessage(ChatColor.GREEN +"Syntax: /varo setspawn <spawnnumber>");
  201.                     }
  202.                 } else if (args[0].equalsIgnoreCase("setworld")  && p.hasPermission("Varo.setworld")) {
  203.                     arenaManager.setWorld(p);
  204.                 } else if (args[0].equalsIgnoreCase("setportal")  && p.hasPermission("Varo.setportal")) {
  205.                     arenaManager.setPortal(p);
  206.                 }
  207.             } else {
  208.                 p.sendMessage(ChatColor.GREEN +"Syntax: /varo <subcommand>");
  209.             }
  210.         }
  211.        
  212.         return true;
  213.     }
  214.    
  215.     @SuppressWarnings("deprecation")
  216.     public void peace(Player p) {
  217.         peacePlayers.add(p);
  218.         p.sendMessage(ChatColor.GREEN +"Peace-Time has beginn!");
  219.         getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
  220.             @Override
  221.             public void run() {
  222.                 peacePlayers.remove(p);
  223.                 p.sendMessage(ChatColor.GREEN +"Peace-Time "+ ChatColor.RED +"ends"+ ChatColor.GREEN +"!");
  224.                 dayloop(p);
  225.             }
  226.         }, 20L * 10);
  227.     }
  228.    
  229.     @SuppressWarnings("deprecation")
  230.     public void dayloop(Player p) {
  231.         if (p.getName() != "yGravity") {
  232.             getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
  233.                 @SuppressWarnings("static-access")
  234.                 @Override
  235.                 public void run() {
  236.                     arenaManager.saveLoc(p, p.getLocation());
  237.                     banned.add(p);
  238.                     p.kickPlayer("Your 20 minutes are done!");
  239.                 }
  240.             }, 20L * 60 * 20);
  241.         } else if (Tom = false) {
  242.             getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
  243.                 @SuppressWarnings("static-access")
  244.                 @Override
  245.                 public void run() {
  246.                     arenaManager.saveLoc(p, p.getLocation());
  247.                     banned.add(p);
  248.                     p.kickPlayer("Your 20 minutes are done!");
  249.                 }
  250.             }, 20L * 60 * 20);
  251.         } else if (Tom = true) {
  252.             getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
  253.                 @SuppressWarnings("static-access")
  254.                 @Override
  255.                 public void run() {
  256.                     arenaManager.saveLoc(p, p.getLocation());
  257.                     banned.add(p);
  258.                     p.kickPlayer("Your 40 minutes are done!");
  259.                 }
  260.             }, 20L * 60 * 40);
  261.         }
  262.     }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement