Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 18th, 2012  |  syntax: None  |  size: 6.46 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package me.krazyswagga.tod;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import java.util.Map.Entry;
  7. import java.util.logging.Logger;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.ChatColor;
  11. import org.bukkit.Location;
  12. import org.bukkit.World;
  13. import org.bukkit.command.Command;
  14. import org.bukkit.command.CommandSender;
  15. import org.bukkit.configuration.Configuration;
  16. import org.bukkit.configuration.file.FileConfiguration;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.plugin.java.JavaPlugin;
  19.  
  20. public class TOD extends JavaPlugin{
  21.         Logger Log = Logger.getLogger("Minecraft");
  22.         final ArrayList<String> redt = new ArrayList<String>();
  23.         final ArrayList<String> bluet = new ArrayList<String>();
  24.         final Map<String, Object> config1 = new HashMap<String, Object>();
  25.         boolean gameStarted;
  26.         public void onEnable(){
  27.                 Log.info("[TOD] Has been enabled");
  28.                 getServer().getPluginManager().registerEvents(new PListener(this), this);
  29.         }
  30.         public void onDisable(){
  31.                 Log.info("[TOD] Has been disabled");
  32.         }
  33.  
  34.         public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
  35.                 final Player player = (Player) sender;
  36.                 final String ps = sender.getName();
  37.                 if(cmd.getName().equalsIgnoreCase("tjoin")){
  38.                         if(redt.contains(ps) || bluet.contains(ps)){
  39.                                 sender.sendMessage("You are already in a team");
  40.                         }else if (redt.size() > bluet.size()){
  41.                                 bluet.add(ps);
  42.                                 player.setDisplayName(ChatColor.BLUE + ps + ChatColor.WHITE);
  43.                                 sender.sendMessage("You have joined the blue team");
  44.                         }else if (redt.size() < bluet.size()){
  45.                                 redt.add(ps);
  46.                                 player.setDisplayName(ChatColor.RED + ps + ChatColor.WHITE);
  47.                                 sender.sendMessage("You have joined the red team");
  48.                         } else if (redt.size() == bluet.size()){
  49.                                 redt.add(ps);
  50.                                 player.setDisplayName(ChatColor.RED + ps + ChatColor.WHITE );
  51.                                 sender.sendMessage("You have joined the red team");
  52.                         } else if (!redt.contains(player.getName()) || !bluet.contains(player.getName())){
  53.                                 sender.sendMessage("Something must be wrong with joining.... Try again later or report this ASAP");
  54.                         }
  55.                 } else if(cmd.getName().equalsIgnoreCase("setblue")){
  56.                         this.setBlueSpawn((Player) sender);
  57.                         if(getConfig().get("blue.spawn") == null){
  58.                                 sender.sendMessage("Something is wrong with setting spawns...");
  59.  
  60.                         }       if(getConfig().get("blue.spawn") != null){
  61.                                 sender.sendMessage("blue spawn is set!");
  62.                         }
  63.  
  64.  
  65.                 }       else if(cmd.getName().equalsIgnoreCase("setred")){
  66.  
  67.                         this.setRedSpawn((Player) sender);
  68.                         if(getConfig().get("red.spawn") == null){
  69.                                 sender.sendMessage("Something is wrong with setting spawns...");
  70.  
  71.                         }       if(getConfig().get("red.spawn") != null){
  72.                                 sender.sendMessage("red spawn is set!");
  73.  
  74.                         }
  75.                 }  else if (cmd.getName().equalsIgnoreCase("tleave")){
  76.                         if(redt.contains(ps)){
  77.                                 redt.remove(ps);
  78.                                 player.setDisplayName(ChatColor.WHITE + ps);
  79.                         }else if (bluet.contains(ps)){
  80.                                 bluet.remove(ps);
  81.                                 player.setDisplayName(ChatColor.WHITE + ps);
  82.                                
  83.                         }
  84.                         sender.sendMessage("You have left TOD");
  85.                 }       if(bluet.size() == 1 || redt.size() == 1){
  86.                         this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  87.                                 public void run() {
  88.                                         Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GREEN + "TOD" + ChatColor.RED + "]" + ChatColor.WHITE + " Game will start in 10 seconds!");
  89.                                         gameStarted = true;
  90.                                 }
  91.                         }, 20L);
  92.                 } else {
  93.                         gameStarted = false;
  94.                        
  95.                 }if(bluet.size() == 1 || redt.size() == 1){
  96.                         this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  97.                                 public void run() {
  98.                                         for(Player pl : Bukkit.getServer().getOnlinePlayers()){
  99.                                                 Configuration config = getConfig();
  100.                                                 World w = getServer().getWorld("world");
  101.                                                 if(bluet.contains(pl.getName())){
  102.                                                         pl.teleport(new Location((w), config.getDouble("blue.spawn.x"), config.getDouble("blue.spawn.y"), config.getDouble("blue.spawn.z"), (float)config.getDouble("blue.spawn.pitch"), (float)config.getDouble("blue.spawn.yaw")));
  103.                                                         pl.sendMessage(ChatColor.BLUE + "You are now in the game! Good luck");
  104.                                                 } else if (redt.contains(pl.getName())){
  105.                                                         pl.teleport(new Location((w), config.getDouble("red.spawn.x"), config.getDouble("red.spawn.y"), config.getDouble("red.spawn.z"), (float)config.getDouble("red.spawn.pitch"), (float)config.getDouble("red.spawn.yaw")));
  106.                                                         pl.sendMessage(ChatColor.RED + "You are now in the game! Good luck");
  107.                                                 }
  108.                                                 gameStarted = true;
  109.                                         }
  110.                                 }
  111.                         }, 220L);
  112.                 } else {
  113.                         gameStarted = false;
  114.                 }
  115.  
  116.                 return false;
  117.         }
  118.  
  119.  
  120.         public void setRedSpawn(Player p){
  121.                 FileConfiguration config = this.getConfig();
  122.                 config1.put("red.spawn.x", p.getLocation().getX());
  123.                 config1.put("red.spawn.z", p.getLocation().getZ());
  124.                 config1.put("red.spawn.y", p.getLocation().getY());
  125.                 config1.put("red.spawn.pitch", p.getLocation().getPitch());
  126.                 config1.put("red.spawn.yaw", p.getLocation().getYaw());
  127.  
  128.  
  129.  
  130.                 for (final Entry<String, Object> e : config1.entrySet()){
  131.                         if (!config.contains(e.getKey()))
  132.                                 config.set(e.getKey(), e.getValue());
  133.                 }
  134.                 this.saveConfig();
  135.         }
  136.  
  137.  
  138.         public void setBlueSpawn(Player p){
  139.                 FileConfiguration config = this.getConfig();
  140.                 config1.put("blue.spawn.x", p.getLocation().getX());
  141.                 config1.put("blue.spawn.z", p.getLocation().getZ());
  142.                 config1.put("blue.spawn.y", p.getLocation().getY());
  143.                 config1.put("blue.spawn.pitch", p.getLocation().getPitch());
  144.                 config1.put("blue.spawn.yaw", p.getLocation().getYaw());
  145.                 for (final Entry<String, Object> e : config1.entrySet()){
  146.                         if (!config.contains(e.getKey()))
  147.                                 config.set(e.getKey(), e.getValue());
  148.                 }
  149.                 this.saveConfig();
  150.         }
  151.        
  152.  
  153. }
  154.  
  155.  
  156. //gameOn = true;
  157. //if(gameOn == true){
  158. //Player p = Bukkit.getPlayer("name");
  159. //Configuration config = getConfig();
  160. //World w = getServer().getWorld("name");
  161. //      if(bluet.contains(p.getName())){
  162. //      p.teleport(new Location((w), config.getDouble("blue.spawn.x"), config.getDouble("blue.spawn.y"), config.getDouble("blue.spawn.z"), (float)config.getDouble("blue.spawn.pitch"), (float)config.getDouble("blue.spawn.yaw")));
  163. //              p.sendMessage(ChatColor.BLUE + "You are now in the game! Good luck");
  164. //      } else if (redt.contains(p.getName())){
  165. //      p.teleport(new Location((w), config.getDouble("red.spawn.x"), config.getDouble("red.spawn.y"), config.getDouble("red.spawn.z"), (float)config.getDouble("red.spawn.pitch"), (float)config.getDouble("red.spawn.yaw")));
  166. //      p.sendMessage(ChatColor.RED + "You are now in the game! Good luck");
  167. //}