Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --------------------------------------------------------------------------------------------------------------+
- //
- // Name: Paintball
- //
- // Description: Paintball plugin for Bukkit (1.6.2 RC 0.2 )
- //
- // Initial author: momo5502 <[email protected]>
- //
- // Version: 1.0.0.0
- //
- // Credits: redsgreens <[email protected]> for the Snowball spawn and vector to location part
- // Ajaks (Aleksandar Jovanov) for helping and giving advices :D
- // dasg1972 (Yannis Huhle) mental help (beer and chilling ;) ).
- //
- // --------------------------------------------------------------------------------------------------------------+
- package us.blackpulse.momo.painball;
- import java.util.HashMap;
- import java.util.Map;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.Server;
- import org.bukkit.World;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Damageable;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Player;
- import org.bukkit.entity.Snowball;
- 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.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.entity.EntityDamageEvent;
- import org.bukkit.event.player.PlayerGameModeChangeEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scoreboard.DisplaySlot;
- import org.bukkit.scoreboard.Objective;
- import org.bukkit.scoreboard.Score;
- import org.bukkit.scoreboard.Scoreboard;
- import org.bukkit.scoreboard.ScoreboardManager;
- import org.bukkit.scoreboard.Team;
- import org.bukkit.util.Vector;
- public class main extends JavaPlugin implements Listener
- {
- // ------------------------------------------------------------------------------------------------------+
- // Global variables
- boolean paintballting = false;
- Map<Integer, Player> playerMap = new HashMap<Integer, Player>();
- Map<Integer, Player> axisMap = new HashMap<Integer, Player>();
- Map<Integer, Player> alliesMap = new HashMap<Integer, Player>();
- Map<Integer, ItemStack[]> invContentMap = new HashMap<Integer, ItemStack[]>();
- Map<Integer, ItemStack[]> invArmorMap = new HashMap<Integer, ItemStack[]>();
- Map<Integer, Location> locationMap = new HashMap<Integer, Location>();
- int gold_spawns = 0;
- int white_spawns = 0;
- Location[] spawnsAxis = new Location[15];
- Location[] spawnsAllies = new Location[15];
- ScoreboardManager manager;
- Scoreboard axisBoard;
- Scoreboard alliesBoard;
- Team axisTeam;
- Team alliesTeam;
- Objective axisObj;
- Objective alliesObj;
- OfflinePlayer axisSelf;
- OfflinePlayer axisEnemy;
- OfflinePlayer alliesSelf;
- OfflinePlayer alliesEnemy;
- int maxScore = 50;
- int maxPlayers = 8; // Per team, so in total 2 * maxPlayers
- FileConfiguration config = null;
- // ------------------------------------------------------------------------------------------------------+
- // Events
- @Override
- public void onEnable()
- {
- setupFromConfig();
- setupScoreBoard();
- getServer().getPluginManager().registerEvents(this, this);
- }
- @Override
- public void onDisable()
- {
- saveConfig();
- // saveCustomConfig();
- }
- @EventHandler(priority = EventPriority.HIGHEST)
- public void onPlayerInteractBlock(PlayerInteractEvent event)
- {
- if (!paintballting || !isPaintBallPlayer(event.getPlayer()))
- return;
- Action action = event.getAction();
- if (action != Action.LEFT_CLICK_AIR
- && action != Action.LEFT_CLICK_BLOCK)
- return;
- Player player = event.getPlayer();
- // int id = 280; // Stick id
- int playerweapon = getWeapon(isAxis(player)).getId();
- if (player.getItemInHand().getTypeId() == playerweapon)
- {
- throwProjectile(player);
- }
- }
- @EventHandler(priority = EventPriority.HIGH)
- public void onGamemodeChange(PlayerGameModeChangeEvent event)
- {
- Player player = event.getPlayer();
- if (isPaintBallPlayer(player))
- {
- if (event.getNewGameMode() == GameMode.CREATIVE
- || event.getNewGameMode() == GameMode.ADVENTURE)
- {
- player.sendMessage(ChatColor.DARK_RED
- + "Please don't cheat and stay in survival!");
- event.setCancelled(true);
- player.setGameMode(GameMode.SURVIVAL);
- }
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label,
- String[] args)
- {
- if (cmd.getName().equalsIgnoreCase("paintball")
- || cmd.getName().equalsIgnoreCase("pb"))
- {
- if (!(sender instanceof Player))
- {
- sender.sendMessage(ChatColor.RED
- + "Only players can use this command!");
- return true;
- }
- if (args.length < 1)
- return false;
- return subCommand((Player) sender, args);
- }
- return true;
- }
- @EventHandler
- public void onEntityDamage(final EntityDamageEvent event)
- {
- if (event instanceof EntityDamageByEntityEvent)
- {
- EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
- if (e.getDamager() instanceof Snowball)
- {
- Snowball b = (Snowball) e.getDamager();
- Player attacker = (Player) b.getShooter();
- Entity v = event.getEntity();
- if (!isPaintBallPlayer(attacker))
- return;
- String end = "a " + v.getType().toString().toLowerCase();
- ChatColor prefix = ChatColor.GOLD;
- if (v instanceof Player)
- {
- Player victim = (Player) v;
- end = victim.getName();
- prefix = ChatColor.GREEN;
- if (!isPaintBallPlayer(victim))
- {
- attacker.sendMessage(ChatColor.YELLOW + end
- + " is not a paintball player!");
- return;
- }
- else if (areDifferentTeams(attacker, victim))
- {
- moveToSpawn(victim, isAxis(victim));
- victim.sendMessage(ChatColor.RED
- + "You were killed by " + attacker.getName());
- Score score = getPlayerScore(attacker);
- score.setScore(score.getScore() + 1);
- updateTeamScores(isAxis(attacker));
- }
- else
- {
- attacker.sendMessage(ChatColor.RED
- + "Friendly Fire! You hit " + end);
- victim.setHealth(victim.getMaxHealth());
- victim.sendMessage(ChatColor.AQUA
- + "Friendly Fire! You were hit by "
- + attacker.getName());
- return;
- }
- }
- else
- {
- ((Damageable) v).setHealth(0);
- }
- attacker.setFoodLevel(20);
- attacker.sendMessage(prefix + "You killed " + end);
- }
- }
- }
- // ------------------------------------------------------------------------------------------------------+
- // Functions
- public void setupScoreBoard()
- {
- manager = Bukkit.getScoreboardManager();
- axisBoard = manager.getNewScoreboard();
- alliesBoard = manager.getNewScoreboard();
- axisTeam = axisBoard.registerNewTeam("axis");
- alliesTeam = alliesBoard.registerNewTeam("allies");
- alliesTeam.setDisplayName(ChatColor.GOLD + "GOLD");
- axisTeam.setDisplayName(ChatColor.WHITE + "WHITE");
- axisObj = axisBoard.registerNewObjective("WHITE", "dummy");
- axisObj.setDisplaySlot(DisplaySlot.SIDEBAR);
- axisObj.setDisplayName(ChatColor.WHITE + "WHITE" + ChatColor.AQUA
- + " Team");
- alliesObj = alliesBoard.registerNewObjective("GOLD", "dummy");
- alliesObj.setDisplaySlot(DisplaySlot.SIDEBAR);
- alliesObj.setDisplayName(ChatColor.GOLD + "GOLD" + ChatColor.AQUA
- + " Team");
- alliesTeam.setCanSeeFriendlyInvisibles(true);
- axisTeam.setCanSeeFriendlyInvisibles(true);
- alliesTeam.setAllowFriendlyFire(false);
- axisTeam.setAllowFriendlyFire(false);
- axisSelf = Bukkit.getOfflinePlayer(ChatColor.GREEN + "Team kills:");
- alliesSelf = Bukkit.getOfflinePlayer(ChatColor.GREEN + "Team kills:");
- axisEnemy = Bukkit.getOfflinePlayer(ChatColor.RED + "Enemy kills:");
- alliesEnemy = Bukkit.getOfflinePlayer(ChatColor.RED + "Enemy kills:");
- axisTeam.addPlayer(axisEnemy);
- axisTeam.addPlayer(axisSelf);
- alliesTeam.addPlayer(alliesEnemy);
- alliesTeam.addPlayer(alliesSelf);
- axisObj.getScore(axisSelf).setScore(0);
- axisObj.getScore(axisEnemy).setScore(0);
- alliesObj.getScore(alliesSelf).setScore(0);
- alliesObj.getScore(alliesEnemy).setScore(0);
- }
- public void winAndRestart()
- {
- if (axisObj.getScore(axisSelf).getScore() >= maxScore)
- {
- for (Player p : axisMap.values())
- {
- p.sendMessage(ChatColor.WHITE + "WHITE" + ChatColor.DARK_GREEN
- + " team has won!");
- moveToSpawn(p, true);
- }
- for (Player p : alliesMap.values())
- {
- p.sendMessage(ChatColor.GOLD + "GOLD" + ChatColor.DARK_RED
- + " team has lost!");
- moveToSpawn(p, false);
- }
- resetScores();
- }
- else if (alliesObj.getScore(alliesSelf).getScore() >= maxScore)
- {
- for (Player p : alliesMap.values())
- {
- p.sendMessage(ChatColor.GOLD + "GOLD" + ChatColor.DARK_GREEN
- + " team has won!");
- moveToSpawn(p, false);
- }
- for (Player p : axisMap.values())
- {
- p.sendMessage(ChatColor.WHITE + "WHITE" + ChatColor.DARK_RED
- + " team has lost!");
- moveToSpawn(p, true);
- }
- resetScores();
- }
- }
- public void resetScores()
- {
- axisObj.getScore(axisSelf).setScore(0);
- axisObj.getScore(axisEnemy).setScore(0);
- alliesObj.getScore(alliesSelf).setScore(0);
- alliesObj.getScore(alliesEnemy).setScore(0);
- for (Player p : playerMap.values())
- {
- try
- {
- getPlayerScore(p).setScore(0);
- }
- catch (Exception e)
- {
- }
- }
- updateBoards();
- }
- public void updateBoards()
- {
- for (Player p : axisMap.values())
- {
- try
- {
- p.setScoreboard(axisBoard);
- }
- catch (Exception e)
- {
- }
- }
- for (Player p : alliesMap.values())
- {
- try
- {
- p.setScoreboard(alliesBoard);
- }
- catch (Exception e)
- {
- }
- }
- }
- public void updateTeamScores(boolean axis)
- {
- if (axis)
- {
- axisObj.getScore(axisSelf).setScore(
- axisObj.getScore(axisSelf).getScore() + 1);
- alliesObj.getScore(alliesEnemy).setScore(
- alliesObj.getScore(alliesEnemy).getScore() + 1);
- }
- else
- {
- axisObj.getScore(axisEnemy).setScore(
- axisObj.getScore(axisEnemy).getScore() + 1);
- alliesObj.getScore(alliesSelf).setScore(
- alliesObj.getScore(alliesSelf).getScore() + 1);
- }
- updateBoards();
- winAndRestart();
- }
- public void moveToSpawn(Player player, boolean axis)
- {
- Location loc = getBestSpawn(axis);
- if (axis)
- {
- if (white_spawns > 0)
- player.teleport(loc);
- else
- player.sendMessage(ChatColor.DARK_RED
- + "Teleporting failed, axis spawn is not set!");
- }
- else
- {
- if (gold_spawns > 0)
- player.teleport(loc);
- else
- player.sendMessage(ChatColor.DARK_RED
- + "Teleporting failed, axis spawn is not set!");
- }
- }
- public void addPlayer(Player player)
- {
- if (playerMap.containsValue(player))
- {
- player.sendMessage(ChatColor.AQUA + "You are already in a team!");
- return;
- }
- boolean axis = false;
- // Allies = GOLD
- // Axis = WHITE
- if (axisMap.size() < alliesMap.size())
- axis = true;
- else if (axisMap.size() > alliesMap.size())
- axis = false;
- else
- {
- int rand = (int) (Math.random()) % 2;
- if (rand == 1)
- axis = true;
- else
- axis = false;
- }
- paintballting = true;
- player.sendMessage(ChatColor.AQUA + "You have joined the "
- + (axis ? ChatColor.WHITE + "WHITE" : ChatColor.GOLD + "GOLD")
- + ChatColor.AQUA + " team.");
- storeInv(player);
- clearInv(player);
- player.setGameMode(GameMode.SURVIVAL);
- if (axis)
- {
- if (alliesMap.containsValue(player))
- alliesMap.remove(player.getEntityId());
- for (Player p : axisMap.values())
- p.sendMessage(ChatColor.WHITE + player.getName()
- + ChatColor.AQUA + " joined your team!");
- for (Player p : alliesMap.values())
- p.sendMessage(ChatColor.WHITE + player.getName()
- + ChatColor.AQUA + " joined the enemy team!");
- axisMap.put(player.getEntityId(), player);
- axisTeam.addPlayer(player);
- getPlayerScore(player).setScore(0);
- player.setScoreboard(axisBoard);
- }
- else
- {
- if (axisMap.containsValue(player))
- axisMap.remove(player.getName());
- for (Player p : alliesMap.values())
- p.sendMessage(ChatColor.GOLD + player.getName()
- + ChatColor.AQUA + " joined your team!");
- for (Player p : axisMap.values())
- p.sendMessage(ChatColor.GOLD + player.getName()
- + ChatColor.AQUA + " joined the enemy team!");
- alliesMap.put(player.getEntityId(), player);
- alliesTeam.addPlayer(player);
- getPlayerScore(player).setScore(0);
- player.setScoreboard(alliesBoard);
- }
- player.setHealth(player.getMaxHealth());
- getPlayerScore(player).setScore(0);
- equipPlayer(player, axis);
- playerMap.put(player.getEntityId(), player);
- locationMap.put(player.getEntityId(), player.getLocation());
- moveToSpawn(player, axis);
- updateBoards();
- player.sendMessage(ChatColor.DARK_RED
- + "Be aware, if you disconnect from the server (or it crashes) during a paintball match, you will lose all your items! It's highly recommended to leave the match and safely store the important items. We are not responsable if you lose your items, nor will we replace them!.");
- }
- public void clearInv(Player player)
- {
- PlayerInventory inv = player.getInventory();
- inv.clear();
- inv.setHelmet(new ItemStack(Material.AIR));
- inv.setChestplate(new ItemStack(Material.AIR));
- inv.setLeggings(new ItemStack(Material.AIR));
- inv.setBoots(new ItemStack(Material.AIR));
- }
- public void storeInv(Player player)
- {
- invContentMap.put(player.getEntityId(), player.getInventory()
- .getContents());
- invArmorMap.put(player.getEntityId(), player.getInventory()
- .getArmorContents());
- }
- public void restoreInv(Player player)
- {
- boolean invcontent = false;
- boolean invarmor = false;
- if (invContentMap.containsKey(player.getEntityId()))
- {
- ItemStack[] content = invContentMap.get(player.getEntityId());
- player.getInventory().setContents(content);
- invcontent = true;
- }
- else
- player.sendMessage("An error occured. Your inventory couldn't get restored!");
- if (invArmorMap.containsKey(player.getEntityId()))
- {
- ItemStack[] armor = invArmorMap.get(player.getEntityId());
- player.getInventory().setArmorContents(armor);
- invarmor = true;
- }
- if (invarmor && invcontent)
- player.sendMessage(ChatColor.AQUA
- + "Your inventory has been restored!");
- else if (invarmor && !invcontent)
- player.sendMessage(ChatColor.YELLOW
- + "Your armor was restored, but your inventory couldn't be restored!");
- else if (!invarmor && invcontent)
- player.sendMessage(ChatColor.YELLOW
- + "Your inventory was restored, but your armor couldn't be restored!");
- else
- player.sendMessage(ChatColor.DARK_RED
- + "Your inventory couldn't be restored!");
- }
- public void equipPlayer(Player player, boolean axis)
- {
- PlayerInventory inv = player.getInventory();
- inv.addItem(new ItemStack(getWeapon(axis)));
- if (axis)
- {
- inv.setHelmet(new ItemStack(Material.IRON_HELMET));
- inv.setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
- inv.setLeggings(new ItemStack(Material.IRON_LEGGINGS));
- inv.setBoots(new ItemStack(Material.IRON_BOOTS));
- }
- else
- {
- inv.setHelmet(new ItemStack(Material.GOLD_HELMET));
- inv.setChestplate(new ItemStack(Material.GOLD_CHESTPLATE));
- inv.setLeggings(new ItemStack(Material.GOLD_LEGGINGS));
- inv.setBoots(new ItemStack(Material.GOLD_BOOTS));
- }
- }
- public void removePlayer(Player player)
- {
- if (playerMap.containsValue(player))
- {
- playerMap.remove(player.getEntityId());
- }
- player.setScoreboard(manager.getNewScoreboard());
- if (locationMap.containsKey(player.getEntityId()))
- {
- player.teleport(locationMap.get(player.getEntityId()));
- locationMap.remove(player.getEntityId());
- }
- try
- {
- axisTeam.removePlayer(player);
- }
- catch (Exception e)
- {
- }
- try
- {
- alliesTeam.removePlayer(player);
- }
- catch (Exception e)
- {
- }
- if (axisMap.containsValue(player))
- {
- axisMap.remove(player.getEntityId());
- player.sendMessage(ChatColor.AQUA + "You have left the "
- + ChatColor.WHITE + "WHITE" + ChatColor.AQUA + " team!");
- clearInv(player);
- restoreInv(player);
- for (Player p : alliesMap.values())
- p.sendMessage(ChatColor.WHITE + player.getName()
- + ChatColor.AQUA + " left the enemy team!");
- for (Player p : axisMap.values())
- p.sendMessage(ChatColor.WHITE + player.getName()
- + ChatColor.AQUA + " left your team!");
- }
- else if (alliesMap.containsValue(player))
- {
- alliesMap.remove(player.getEntityId());
- player.sendMessage(ChatColor.AQUA + "You have left the "
- + ChatColor.GOLD + "GOLD" + ChatColor.AQUA + " team!");
- clearInv(player);
- restoreInv(player);
- for (Player p : alliesMap.values())
- p.sendMessage(ChatColor.GOLD + player.getName()
- + ChatColor.AQUA + " left your team!");
- for (Player p : axisMap.values())
- p.sendMessage(ChatColor.GOLD + player.getName()
- + ChatColor.AQUA + " left the enemy team!");
- }
- else
- player.sendMessage(ChatColor.AQUA
- + "You are not participating in a paintball match!");
- updateBoards();
- if (playerMap.size() == 0)
- {
- paintballting = false;
- resetScores();
- }
- }
- public void forceRemove()
- {
- for (Player p : playerMap.values())
- {
- try
- {
- removePlayer(p);
- }
- catch (Exception e)
- {
- }
- }
- playerMap = new HashMap<Integer, Player>();
- axisMap = new HashMap<Integer, Player>();
- alliesMap = new HashMap<Integer, Player>();
- invContentMap = new HashMap<Integer, ItemStack[]>();
- invArmorMap = new HashMap<Integer, ItemStack[]>();
- locationMap = new HashMap<Integer, Location>();
- setupScoreBoard();
- }
- public void throwProjectile(Player player)
- {
- Location playerLoc = player.getLocation();
- Location loc = playerLoc.add(
- playerLoc
- .getDirection()
- .normalize()
- .multiply(3)
- .toLocation(player.getWorld(), playerLoc.getYaw(),
- playerLoc.getPitch())).add(0, 1D, 0);
- Snowball b = player.getWorld().spawn(loc, Snowball.class);
- Vector velocity = playerLoc.getDirection().normalize().multiply(2);
- b.setShooter(player);
- b.setVelocity(velocity);
- if (isAllies(player))
- {
- b.setFireTicks(1000);
- }
- }
- public void showHelp(Player player)
- {
- String prefix = ChatColor.GOLD + "/paintball ";
- // Join
- player.sendMessage(prefix + "join " + ChatColor.AQUA
- + "Autoassings you either to the " + ChatColor.GOLD + "GOLD"
- + ChatColor.AQUA + " or the " + ChatColor.WHITE + "WHITE"
- + ChatColor.AQUA + " team!");
- // Leave
- player.sendMessage(prefix
- + "leave "
- + ChatColor.AQUA
- + "Leaves current paintball match and brings you to your last location.");
- // Help
- player.sendMessage(prefix + "help " + ChatColor.AQUA
- + "Displays this help page.");
- // Addspawn
- if (player.hasPermission("us.blackpulse.momo.paintball.addSpawn"))
- player.sendMessage(prefix + "addspawn [GOLD/WHITE] "
- + ChatColor.AQUA
- + "Adds your location as a spawn to the team.");
- // Removespawn
- if (player.hasPermission("us.blackpulse.momo.paintball.removeSpawn"))
- player.sendMessage(prefix + "removespawn [GOLD/WHITE] "
- + ChatColor.AQUA + "Removes nearest spawn from the team.");
- // Resetall
- if (player.hasPermission("us.blackpulse.momo.paintball.resetAll"))
- player.sendMessage(prefix + "resetall " + ChatColor.AQUA
- + "Resets the whole paintball plugin (for debugging).");
- }
- public void removeSpawn(Player player, String team)
- {
- boolean axis = false;
- if (team.equalsIgnoreCase("white"))
- {
- axis = true;
- if (white_spawns <= 0)
- {
- player.sendMessage(ChatColor.DARK_RED + "No spawns set!");
- return;
- }
- }
- else if (team.equalsIgnoreCase("gold"))
- {
- axis = false;
- if (gold_spawns <= 0)
- {
- player.sendMessage(ChatColor.DARK_RED + "No spawns set!");
- return;
- }
- }
- else
- {
- player.sendMessage(ChatColor.DARK_RED + "Wrong teamname!");
- return;
- }
- Location[] array = (axis) ? spawnsAxis : spawnsAllies;
- Location[] newarray = new Location[15];
- Location loc = player.getLocation();
- int spawns = (axis) ? white_spawns : gold_spawns;
- int spawn = 0;
- if (spawns > 1)
- {
- double dist = loc.distanceSquared(array[0]);
- for (int i = 0; i < spawns; i++)
- {
- double newdist = loc.distanceSquared(array[i]);
- if (newdist < dist)
- {
- dist = newdist;
- spawn = i;
- }
- }
- int j = 0;
- for (int i = 0; i < spawns; i++)
- {
- if (i != spawn)
- {
- newarray[j] = array[i];
- j++;
- }
- }
- }
- if (axis)
- {
- spawnsAxis = newarray;
- for (int i = 0; i < spawns; i++)
- {
- config.set("spawns.white." + i + ".x", null);
- config.set("spawns.white." + i + ".y", null);
- config.set("spawns.white." + i + ".z", null);
- config.set("spawns.white." + i + ".yaw", null);
- config.set("spawns.white." + i + ".pitch", null);
- config.set("spawns.white." + i + ".world", null);
- config.set("spawns.white." + i, null);
- }
- white_spawns--;
- for (int i = 0; i < white_spawns; i++)
- {
- config.set("spawns.white." + i + ".x", spawnsAxis[i].getX());
- config.set("spawns.white." + i + ".y", spawnsAxis[i].getY());
- config.set("spawns.white." + i + ".z", spawnsAxis[i].getZ());
- config.set("spawns.white." + i + ".yaw", spawnsAxis[i].getYaw());
- config.set("spawns.white." + i + ".pitch",
- spawnsAxis[i].getPitch());
- config.set("spawns.white." + i + ".world", spawnsAxis[i]
- .getWorld().getName());
- }
- config.set("spawns.white.amount", white_spawns);
- }
- else
- {
- spawnsAllies = newarray;
- for (int i = 0; i < spawns; i++)
- {
- config.set("spawns.gold." + i + ".x", null);
- config.set("spawns.gold." + i + ".y", null);
- config.set("spawns.gold." + i + ".z", null);
- config.set("spawns.gold." + i + ".yaw", null);
- config.set("spawns.gold." + i + ".pitch", null);
- config.set("spawns.gold." + i + ".world", null);
- config.set("spawns.gold." + i, null);
- }
- gold_spawns--;
- for (int i = 0; i < gold_spawns; i++)
- {
- config.set("spawns.gold." + i + ".x", spawnsAllies[i].getX());
- config.set("spawns.gold." + i + ".y", spawnsAllies[i].getY());
- config.set("spawns.gold." + i + ".z", spawnsAllies[i].getZ());
- config.set("spawns.gold." + i + ".yaw",
- spawnsAllies[i].getYaw());
- config.set("spawns.gold." + i + ".pitch",
- spawnsAllies[i].getPitch());
- config.set("spawns.gold." + i + ".world", spawnsAllies[i]
- .getWorld().getName());
- }
- config.set("spawns.gold.amount", gold_spawns);
- }
- this.saveConfig();
- String teamn = (axis) ? ChatColor.WHITE + "WHITE" : ChatColor.GOLD
- + "GOLD";
- player.sendMessage(ChatColor.AQUA + "Nearest " + teamn + ChatColor.AQUA
- + " spawn removed!");
- }
- public void setSpawn(Player player, String team)
- {
- Location loc = player.getLocation();
- config = getConfig();
- if (team.equalsIgnoreCase("white"))
- {
- if (white_spawns >= 15)
- {
- player.sendMessage(ChatColor.DARK_RED
- + "Couldn't add"
- + ChatColor.WHITE
- + "WHITE"
- + ChatColor.DARK_RED
- + " spawn! Max amount of spawns (15) for this team reached!");
- return;
- }
- spawnsAxis[white_spawns] = loc;
- config.set("spawns.white." + white_spawns + ".x", loc.getX());
- config.set("spawns.white." + white_spawns + ".y", loc.getY());
- config.set("spawns.white." + white_spawns + ".z", loc.getZ());
- config.set("spawns.white." + white_spawns + ".yaw", loc.getYaw());
- config.set("spawns.white." + white_spawns + ".pitch",
- loc.getPitch());
- config.set("spawns.white." + white_spawns + ".world", loc
- .getWorld().getName());
- white_spawns++;
- config.set("spawns.white.amount", white_spawns);
- player.sendMessage(ChatColor.WHITE + "WHITE" + ChatColor.AQUA
- + " spawn added!");
- }
- else if (team.equalsIgnoreCase("gold"))
- {
- if (gold_spawns >= 15)
- {
- player.sendMessage(ChatColor.DARK_RED
- + "Couldn't add"
- + ChatColor.GOLD
- + "GOLD"
- + ChatColor.DARK_RED
- + " spawn! Max amount of spawns (15) for this team reached!");
- return;
- }
- spawnsAllies[gold_spawns] = loc;
- config.set("spawns.gold." + gold_spawns + ".x", loc.getX());
- config.set("spawns.gold." + gold_spawns + ".y", loc.getY());
- config.set("spawns.gold." + gold_spawns + ".z", loc.getZ());
- config.set("spawns.gold." + gold_spawns + ".yaw", loc.getYaw());
- config.set("spawns.gold." + gold_spawns + ".pitch", loc.getPitch());
- config.set("spawns.gold." + gold_spawns + ".world", loc.getWorld()
- .getName());
- gold_spawns++;
- config.set("spawns.gold.amount", gold_spawns);
- player.sendMessage(ChatColor.GOLD + "GOLD" + ChatColor.AQUA
- + " spawn added!");
- }
- this.saveConfig();
- }
- public void setupFromConfig()
- {
- config = getConfig();
- config.options().copyDefaults(true);
- this.saveConfig();
- maxPlayers = config.getInt("max-players");
- maxScore = config.getInt("max-score");
- gold_spawns = config.getInt("spawns.gold.amount");
- white_spawns = config.getInt("spawns.white.amount");
- Server s = Bukkit.getServer();
- CommandSender cs = s.getConsoleSender();
- for (int i = 0; i < gold_spawns; i++)
- {
- double x = config.getDouble("spawns.gold." + i + ".x");
- double y = config.getDouble("spawns.gold." + i + ".y");
- double z = config.getDouble("spawns.gold." + i + ".z");
- double yaw = config.getDouble("spawns.gold." + i + ".yaw");
- double pitch = config.getDouble("spawns.gold." + i + ".pitch");
- World world = s.getWorld(config.getString("spawns.gold." + i
- + ".world"));
- Location spawn = new Location(world, x, y, z);
- spawn.setPitch((float) pitch);
- spawn.setYaw((float) yaw);
- spawnsAllies[i] = spawn;
- }
- for (int i = 0; i < white_spawns; i++)
- {
- double x = config.getDouble("spawns.white." + i + ".x");
- double y = config.getDouble("spawns.white." + i + ".y");
- double z = config.getDouble("spawns.white." + i + ".z");
- double yaw = config.getDouble("spawns.white." + i + ".yaw");
- double pitch = config.getDouble("spawns.white." + i + ".pitch");
- World world = s.getWorld(config.getString("spawns.white." + i
- + ".world"));
- Location spawn = new Location(world, x, y, z);
- spawn.setPitch((float) pitch);
- spawn.setYaw((float) yaw);
- spawnsAxis[i] = spawn;
- }
- cs.sendMessage("[Paintball] " + ChatColor.AQUA + "Max Score set to "
- + maxScore);
- cs.sendMessage("[Paintball] " + ChatColor.AQUA + "Max Players set to "
- + maxPlayers);
- cs.sendMessage("[Paintball] " + ChatColor.AQUA + "Axis ("
- + ChatColor.WHITE + "WHITE" + ChatColor.AQUA
- + ") spawns loaded: " + white_spawns);
- cs.sendMessage("[Paintball] " + ChatColor.AQUA + "Allies ("
- + ChatColor.GOLD + "GOLD" + ChatColor.AQUA
- + ") spawns loaded: " + gold_spawns);
- }
- // ------------------------------------------------------------------------------------------------------+
- // Return stuff
- public Location getBestSpawn(boolean axis)
- {
- Location best = null;
- double dist = 0;
- double newdist = 0;
- if (axis)
- {
- best = spawnsAxis[0];
- for (int i = 0; i < white_spawns; i++)
- {
- for (Player p : alliesMap.values())
- {
- newdist = spawnsAxis[i].distanceSquared(p.getLocation());
- if (newdist > dist)
- {
- dist = newdist;
- best = spawnsAxis[i];
- }
- }
- }
- }
- else
- {
- best = spawnsAllies[0];
- for (int i = 0; i < gold_spawns; i++)
- {
- for (Player p : axisMap.values())
- {
- newdist = spawnsAllies[i].distanceSquared(p.getLocation());
- if (newdist > dist)
- {
- dist = newdist;
- best = spawnsAllies[i];
- }
- }
- }
- }
- return best;
- }
- public Score getPlayerScore(Player player)
- {
- if (isAxis(player))
- return axisObj.getScore(player);
- else
- return alliesObj.getScore(player);
- }
- public Material getWeapon(boolean axis)
- {
- return axis ? Material.IRON_SPADE : Material.GOLD_SPADE;
- }
- public boolean subCommand(Player player, String[] args)
- {
- String cmd = args[0];
- // CMD: add --------------------+
- if (cmd.equalsIgnoreCase("join"))
- {
- addPlayer(player);
- return true;
- }
- // CMD: stop -------------------+
- if (cmd.equalsIgnoreCase("leave"))
- {
- removePlayer(player);
- return true;
- }
- // CMD: addspawn ---------------+
- if (cmd.equalsIgnoreCase("addspawn"))
- {
- if (player.hasPermission("us.blackpulse.momo.paintball.addSpawn"))
- setSpawn(player, args[1]);
- else
- player.sendMessage(ChatColor.DARK_RED
- + "You don't have the permission to use this command!");
- return true;
- }
- // CMD: removespawn ------------+
- if (cmd.equalsIgnoreCase("removespawn"))
- {
- if (player
- .hasPermission("us.blackpulse.momo.paintball.removeSpawn"))
- removeSpawn(player, args[1]);
- else
- player.sendMessage(ChatColor.DARK_RED
- + "You don't have the permission to use this command!");
- return true;
- }
- // CMD: resetall ---------------+
- if (cmd.equalsIgnoreCase("resetall"))
- {
- if (player.hasPermission("us.blackpulse.momo.paintball.resetAll"))
- {
- forceRemove();
- player.sendMessage(ChatColor.DARK_PURPLE
- + "Paintball has been restetted!");
- }
- else
- player.sendMessage(ChatColor.DARK_RED
- + "You don't have the permission to use this command!");
- return true;
- }
- // CMD: help -------------------+
- if (cmd.equalsIgnoreCase("help"))
- {
- showHelp(player);
- return true;
- }
- player.sendMessage(ChatColor.DARK_RED
- + "Error, wrong subcommand. For help: " + ChatColor.AQUA
- + "/paintball help");
- return false;
- }
- public boolean areDifferentTeams(Player player1, Player player2)
- {
- if (!isPaintBallPlayer(player1) || !isPaintBallPlayer(player2))
- return false;
- if (isAxis(player1) && isAllies(player2))
- return true;
- else if (isAllies(player1) && isAxis(player2))
- return true;
- return false;
- }
- public boolean isAxis(Player player)
- {
- return axisMap.containsValue(player);
- }
- public boolean isAllies(Player player)
- {
- return alliesMap.containsValue(player);
- }
- public boolean isPaintBallPlayer(Player player)
- {
- return playerMap.containsValue(player);
- }
- // ------------------------------------------------------------------------------------------------------+
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement