- package me.krazyswagga.tod;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.Configuration;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class TOD extends JavaPlugin{
- Logger Log = Logger.getLogger("Minecraft");
- final ArrayList<String> redt = new ArrayList<String>();
- final ArrayList<String> bluet = new ArrayList<String>();
- final Map<String, Object> config1 = new HashMap<String, Object>();
- boolean gameStarted;
- public void onEnable(){
- Log.info("[TOD] Has been enabled");
- getServer().getPluginManager().registerEvents(new PListener(this), this);
- }
- public void onDisable(){
- Log.info("[TOD] Has been disabled");
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
- final Player player = (Player) sender;
- final String ps = sender.getName();
- if(cmd.getName().equalsIgnoreCase("tjoin")){
- if(redt.contains(ps) || bluet.contains(ps)){
- sender.sendMessage("You are already in a team");
- }else if (redt.size() > bluet.size()){
- bluet.add(ps);
- player.setDisplayName(ChatColor.BLUE + ps + ChatColor.WHITE);
- sender.sendMessage("You have joined the blue team");
- }else if (redt.size() < bluet.size()){
- redt.add(ps);
- player.setDisplayName(ChatColor.RED + ps + ChatColor.WHITE);
- sender.sendMessage("You have joined the red team");
- } else if (redt.size() == bluet.size()){
- redt.add(ps);
- player.setDisplayName(ChatColor.RED + ps + ChatColor.WHITE );
- sender.sendMessage("You have joined the red team");
- } else if (!redt.contains(player.getName()) || !bluet.contains(player.getName())){
- sender.sendMessage("Something must be wrong with joining.... Try again later or report this ASAP");
- }
- } else if(cmd.getName().equalsIgnoreCase("setblue")){
- this.setBlueSpawn((Player) sender);
- if(getConfig().get("blue.spawn") == null){
- sender.sendMessage("Something is wrong with setting spawns...");
- } if(getConfig().get("blue.spawn") != null){
- sender.sendMessage("blue spawn is set!");
- }
- } else if(cmd.getName().equalsIgnoreCase("setred")){
- this.setRedSpawn((Player) sender);
- if(getConfig().get("red.spawn") == null){
- sender.sendMessage("Something is wrong with setting spawns...");
- } if(getConfig().get("red.spawn") != null){
- sender.sendMessage("red spawn is set!");
- }
- } else if (cmd.getName().equalsIgnoreCase("tleave")){
- if(redt.contains(ps)){
- redt.remove(ps);
- player.setDisplayName(ChatColor.WHITE + ps);
- }else if (bluet.contains(ps)){
- bluet.remove(ps);
- player.setDisplayName(ChatColor.WHITE + ps);
- }
- sender.sendMessage("You have left TOD");
- } if(bluet.size() == 1 || redt.size() == 1){
- this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- public void run() {
- Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GREEN + "TOD" + ChatColor.RED + "]" + ChatColor.WHITE + " Game will start in 10 seconds!");
- gameStarted = true;
- }
- }, 20L);
- } else {
- gameStarted = false;
- }if(bluet.size() == 1 || redt.size() == 1){
- this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- public void run() {
- for(Player pl : Bukkit.getServer().getOnlinePlayers()){
- Configuration config = getConfig();
- World w = getServer().getWorld("world");
- if(bluet.contains(pl.getName())){
- 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")));
- pl.sendMessage(ChatColor.BLUE + "You are now in the game! Good luck");
- } else if (redt.contains(pl.getName())){
- 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")));
- pl.sendMessage(ChatColor.RED + "You are now in the game! Good luck");
- }
- gameStarted = true;
- }
- }
- }, 220L);
- } else {
- gameStarted = false;
- }
- return false;
- }
- public void setRedSpawn(Player p){
- FileConfiguration config = this.getConfig();
- config1.put("red.spawn.x", p.getLocation().getX());
- config1.put("red.spawn.z", p.getLocation().getZ());
- config1.put("red.spawn.y", p.getLocation().getY());
- config1.put("red.spawn.pitch", p.getLocation().getPitch());
- config1.put("red.spawn.yaw", p.getLocation().getYaw());
- for (final Entry<String, Object> e : config1.entrySet()){
- if (!config.contains(e.getKey()))
- config.set(e.getKey(), e.getValue());
- }
- this.saveConfig();
- }
- public void setBlueSpawn(Player p){
- FileConfiguration config = this.getConfig();
- config1.put("blue.spawn.x", p.getLocation().getX());
- config1.put("blue.spawn.z", p.getLocation().getZ());
- config1.put("blue.spawn.y", p.getLocation().getY());
- config1.put("blue.spawn.pitch", p.getLocation().getPitch());
- config1.put("blue.spawn.yaw", p.getLocation().getYaw());
- for (final Entry<String, Object> e : config1.entrySet()){
- if (!config.contains(e.getKey()))
- config.set(e.getKey(), e.getValue());
- }
- this.saveConfig();
- }
- }
- //gameOn = true;
- //if(gameOn == true){
- //Player p = Bukkit.getPlayer("name");
- //Configuration config = getConfig();
- //World w = getServer().getWorld("name");
- // if(bluet.contains(p.getName())){
- // 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")));
- // p.sendMessage(ChatColor.BLUE + "You are now in the game! Good luck");
- // } else if (redt.contains(p.getName())){
- // 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")));
- // p.sendMessage(ChatColor.RED + "You are now in the game! Good luck");
- //}