Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.blackouts.games;
- import java.io.ByteArrayOutputStream;
- import java.io.DataOutputStream;
- import java.io.File;
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Color;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.Sound;
- import org.bukkit.World;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.inventory.meta.LeatherArmorMeta;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.plugin.messaging.Messenger;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.scheduler.BukkitScheduler;
- 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;
- public class Main extends JavaPlugin
- {
- Language handler = new Language(this);
- public Location lobbyLocation;
- private Logger log = Logger.getLogger("Minecraft");
- boolean ok = false;
- boolean inGame = false;
- boolean GameFinish = false;
- String prefix = "[" + ChatColor.RED + "TheTowers" + ChatColor.RESET + "] ";
- String motd;
- ScoreboardManager manager;
- Scoreboard board;
- Team blue;
- Team red;
- Objective kills;
- Objective health;
- Objective points;
- Objective playerpoints;
- Score bluePlayers;
- Score redPlayers;
- Score bluePoints;
- Score redPoints;
- public void onEnable()
- {
- this.manager = getServer().getScoreboardManager();
- this.board = this.manager.getNewScoreboard();
- this.blue = this.board.registerNewTeam("blue");
- this.red = this.board.registerNewTeam("red");
- this.kills = this.board.registerNewObjective("Kills", "playerKillCount");
- this.health = this.board.registerNewObjective("health", "health");
- this.points = this.board.registerNewObjective("Points", "dummy");
- this.playerpoints = this.board.registerNewObjective("PlayerPoints", "dummy");
- this.points.setDisplaySlot(DisplaySlot.SIDEBAR);
- this.points.setDisplayName(ChatColor.GREEN + this.handler.getCaption("PointsScoreboard"));
- this.health.setDisplaySlot(DisplaySlot.BELOW_NAME);
- this.health.setDisplayName(ChatColor.RED + "❤");
- this.playerpoints.setDisplaySlot(DisplaySlot.PLAYER_LIST);
- this.bluePoints = this.points.getScore(Bukkit.getOfflinePlayer(ChatColor.BLUE + this.handler.getCaption("bluePoints") + " : "));
- this.redPoints = this.points.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + this.handler.getCaption("redPoints") + " : "));
- this.bluePoints.setScore(0);
- this.redPoints.setScore(0);
- for (Player online : Bukkit.getOnlinePlayers()) {
- Score score = this.points.getScore(online);
- score.setScore(0);
- }
- this.blue.setAllowFriendlyFire(false);
- this.red.setAllowFriendlyFire(false);
- getServer().getPluginManager().registerEvents(new Events(this), this);
- getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
- this.motd = ("&a" + this.handler.getCaption("MotdPending"));
- BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
- scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
- public void run() {
- if ((Bukkit.getOnlinePlayers().length >= 2) && (!Main.this.inGame) && (!Main.this.ok))
- {
- Main.this.ok = true;
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.AQUA + Main.this.handler.getCaption("EnoughPlayers"));
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.AQUA + Main.this.handler.getCaption("GameMinutes"));
- Main.this.timer(Main.this.getConfig().getInt("sec"));
- }
- }
- }
- , 0L, 20L);
- }
- public void onLoad()
- {
- try {
- File worldContainer = getServer().getWorldContainer();
- File worldFolder = new File(worldContainer, "world");
- deleteWorlds("world");
- FileUtils.copyFolder(new File(worldContainer, "towers"), worldFolder);
- getLogger().info("Worl deleted successful !");
- }
- catch (Throwable $ex)
- {
- try {
- throw
- $ex;
- } catch (Throwable e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public void timer(int sec) { BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
- scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
- int seco;
- public void run() {
- if (this.seco >= 0) {
- for (Player p : Bukkit.getOnlinePlayers())
- {
- p.setLevel(this.seco);
- }
- }
- if (this.seco == 60)
- {
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.AQUA + this.seco + " " + Main.this.handler.getCaption("SecondBeforeGame"));
- }
- if (this.seco == 30)
- {
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.AQUA + this.seco + " " + Main.this.handler.getCaption("SecondBeforeGame"));
- }
- if ((this.seco < 5) && (!Main.this.inGame))
- {
- if (this.seco == 0)
- {
- for (Player p : Bukkit.getOnlinePlayers())
- {
- p.playSound(p.getLocation(), Sound.LEVEL_UP, 100.0F, 1.0F);
- }
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.AQUA + Main.this.handler.getCaption("StartsGame"));
- Main.this.startGame();
- }
- return;
- }
- else
- {
- if ((this.seco > -1) && (this.seco != 1)) {
- for (Player p : Bukkit.getOnlinePlayers())
- {
- p.playSound(p.getLocation(), Sound.CLICK, 100.0F, 1.0F);
- }
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.AQUA + this.seco + " " + Main.this.handler.getCaption("SecondBeforeGame"));
- }
- if (this.seco == 1)
- {
- for (Player p : Bukkit.getOnlinePlayers())
- {
- p.playSound(p.getLocation(), Sound.CLICK, 100.0F, 1.0F);
- }
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.AQUA + this.seco + " " + Main.this.handler.getCaption("SecondBeforeGame"));
- }
- }
- this.seco -= 1;
- }
- }
- , 0L, 20L);
- }
- public void startGame()
- {
- Bukkit.getWorld("world").setTime(20000L);
- this.inGame = true;
- this.motd = ("&c" + this.handler.getCaption("MotdInGame"));
- for (Player p : Bukkit.getOnlinePlayers())
- {
- p.setGameMode(GameMode.SURVIVAL);
- p.getInventory().clear();
- p.updateInventory();
- if ((!this.blue.hasPlayer(p)) && (!this.red.hasPlayer(p)))
- {
- if (this.blue.getSize() < this.red.getSize())
- {
- this.blue.addPlayer(p);
- p.teleport(new Location(p.getWorld(), getConfig().getInt("spawnblue.x"), getConfig().getInt("spawnblue.y"), getConfig().getInt("spawnblue.z")));
- respawnPlayer(p);
- p.setBedSpawnLocation(new Location(p.getWorld(), getConfig().getInt("spawnblue.x"), getConfig().getInt("spawnblue.y"), getConfig().getInt("spawnblue.z")));
- } else {
- this.red.addPlayer(p);
- p.teleport(new Location(p.getWorld(), getConfig().getInt("spawnred.x"), getConfig().getInt("spawnred.y"), getConfig().getInt("spawnred.z")));
- respawnPlayer(p);
- p.setBedSpawnLocation(new Location(p.getWorld(), getConfig().getInt("spawnred.x"), getConfig().getInt("spawnred.y"), getConfig().getInt("spawnred.z")));
- }
- }
- if ((this.blue.hasPlayer(p)) && (!this.red.hasPlayer(p)))
- {
- p.teleport(new Location(p.getWorld(), getConfig().getInt("spawnblue.x"), getConfig().getInt("spawnblue.y"), getConfig().getInt("spawnblue.z")));
- respawnPlayer(p);
- p.setBedSpawnLocation(new Location(p.getWorld(), getConfig().getInt("spawnblue.x"), getConfig().getInt("spawnblue.y"), getConfig().getInt("spawnblue.z")));
- }
- if ((this.red.hasPlayer(p)) && (!this.blue.hasPlayer(p)))
- {
- p.teleport(new Location(p.getWorld(), getConfig().getInt("spawnred.x"), getConfig().getInt("spawnred.y"), getConfig().getInt("spawnred.z")));
- respawnPlayer(p);
- p.setBedSpawnLocation(new Location(p.getWorld(), getConfig().getInt("spawnred.x"), getConfig().getInt("spawnred.y"), getConfig().getInt("spawnred.z")));
- }
- }
- BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
- scheduler.scheduleSyncRepeatingTask(this, new Runnable()
- {
- public void run() {
- if ((Main.this.redPoints.getScore() >= 10) && (Main.this.inGame) && (!Main.this.GameFinish))
- {
- Main.this.GameFinish = true;
- for (final Player p : Bukkit.getOnlinePlayers())
- {
- p.setAllowFlight(true);
- p.setFlying(true);
- p.playSound(p.getLocation(), Sound.WITHER_DEATH, 100.0F, 1.0F);
- p.sendMessage(Main.this.prefix + ChatColor.RED + Main.this.handler.getCaption("RedWin"));
- Main.this.motd = ("&c" + Main.this.handler.getCaption("Win"));
- if (Main.this.getConfig().getString("BungeeCord.returnserver").equalsIgnoreCase("none"))
- new BukkitRunnable()
- {
- public void run() {
- p.kickPlayer(Main.this.handler.getCaption("Win"));
- }
- }
- .runTaskLater(Main.this, 100L);
- else {
- new BukkitRunnable()
- {
- public void run() {
- Main.this.backToLobby(p);
- }
- }
- .runTaskLater(Main.this, 200L);
- }
- }
- new BukkitRunnable()
- {
- public void run() {
- Bukkit.shutdown();
- }
- }
- .runTaskLater(Main.this, 300L);
- } else if ((Main.this.bluePoints.getScore() >= 10) && (Main.this.inGame) && (!Main.this.GameFinish))
- {
- Main.this.GameFinish = true;
- for (final Player p : Bukkit.getOnlinePlayers())
- {
- p.setAllowFlight(true);
- p.setFlying(true);
- p.playSound(p.getLocation(), Sound.WITHER_DEATH, 100.0F, 1.0F);
- Main.this.motd = ("&9" + Main.this.handler.getCaption("Win"));
- p.sendMessage(Main.this.prefix + ChatColor.BLUE + Main.this.handler.getCaption("BlueWin"));
- if (Main.this.getConfig().getString("BungeeCord.returnserver").equalsIgnoreCase("none"))
- new BukkitRunnable()
- {
- public void run() {
- p.kickPlayer(Main.this.handler.getCaption("Win"));
- }
- }
- .runTaskLater(Main.this, 100L);
- else {
- new BukkitRunnable()
- {
- public void run() {
- Main.this.backToLobby(p);
- }
- }
- .runTaskLater(Main.this, 200L);
- }
- new BukkitRunnable()
- {
- public void run() {
- Bukkit.shutdown();
- }
- }
- .runTaskLater(Main.this, 200L);
- }
- }
- if (Main.this.blue.getSize() == 0) {
- Main.this.GameFinish = true;
- Main.this.motd = ("&c" + Main.this.handler.getCaption("Win"));
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.RED + Main.this.handler.getCaption("RedWin"));
- for (final Player p : Bukkit.getOnlinePlayers()) {
- p.setAllowFlight(true);
- p.setFlying(true);
- p.playSound(p.getLocation(), Sound.WITHER_DEATH, 100.0F, 1.0F);
- if (Main.this.getConfig().getString("BungeeCord.returnserver").equalsIgnoreCase("none"))
- new BukkitRunnable()
- {
- public void run() {
- p.kickPlayer(Main.this.handler.getCaption("Win"));
- }
- }
- .runTaskLater(Main.this, 100L);
- else {
- new BukkitRunnable()
- {
- public void run() {
- Main.this.backToLobby(p);
- }
- }
- .runTaskLater(Main.this, 100L);
- }
- }
- new BukkitRunnable()
- {
- public void run() {
- Bukkit.shutdown();
- }
- }
- .runTaskLater(Main.this, 200L);
- }
- if (Main.this.red.getSize() == 0) {
- Main.this.GameFinish = true;
- Main.this.motd = ("&9" + Main.this.handler.getCaption("Win"));
- Bukkit.broadcastMessage(Main.this.prefix + ChatColor.RED + Main.this.handler.getCaption("BlueWin"));
- for (final Player p : Bukkit.getOnlinePlayers()) {
- p.setAllowFlight(true);
- p.setFlying(true);
- p.playSound(p.getLocation(), Sound.WITHER_DEATH, 100.0F, 1.0F);
- if (Main.this.getConfig().getString("BungeeCord.returnserver").equalsIgnoreCase("none"))
- new BukkitRunnable()
- {
- public void run() {
- p.kickPlayer(Main.this.handler.getCaption("Win"));
- }
- }
- .runTaskLater(Main.this, 100L);
- else {
- new BukkitRunnable()
- {
- public void run() {
- Main.this.backToLobby(p);
- }
- }
- .runTaskLater(Main.this, 100L);
- }
- }
- new BukkitRunnable()
- {
- public void run() {
- Bukkit.shutdown();
- }
- }
- .runTaskLater(Main.this, 200L);
- }
- }
- }
- , 0L, 20L);
- }
- public void backToLobby(Player p) {
- ByteArrayOutputStream b = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream(b);
- try
- {
- out.writeUTF("Connect");
- out.writeUTF(getConfig().getString("BungeeCord.returnserver"));
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
- }
- public ItemStack createItem(ItemStack item, String name, String[] lore) {
- ItemMeta im = item.getItemMeta();
- im.setDisplayName(name);
- im.setLore(Arrays.asList(lore));
- item.setItemMeta(im);
- return item;
- }
- private boolean delete(File file) {
- if (file.isDirectory()) {
- for (File subfile : file.listFiles())
- if (!delete(subfile))
- return false;
- }
- return file.delete();
- }
- public void deleteWorlds(String worldName) {
- File target = new File(getServer().getWorldContainer(), worldName);
- if (!target.exists()) {
- this.log.info("Could not load world \"" + worldName + "\" with a random seed: no such world " + "exists in the server directory!");
- return;
- }
- if ((target.isDirectory()) &&
- (!delete(target)))
- this.log.info("Failed to delete world \"" + worldName + "\", perhaps the folder is locked?");
- }
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (command.getName().equalsIgnoreCase("towers")) {
- if (!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "You have to be a player.");
- return true;
- }
- Player player = (Player)sender;
- if (args.length == 0) {
- player.sendMessage(ChatColor.YELLOW + "Plugin Towers v" + getDescription().getVersion() + " by Dragoh.");
- } else {
- String sub = args[0];
- if (sub.equalsIgnoreCase("help")) {
- player.sendMessage(ChatColor.GREEN + "Rush Help :");
- player.sendMessage("/towers setlobby" + ChatColor.YELLOW + " - Set the lobby");
- player.sendMessage("/towers setspawn [color]" + ChatColor.YELLOW + " - Set the spawn of team [color]");
- player.sendMessage("/towers setpol [color]" + ChatColor.YELLOW + " - Set the pool of team [color]");
- player.sendMessage("/towers setreturnserver [server]" + ChatColor.YELLOW + " - Set BungeeCord returnserver");
- } else if (sub.equalsIgnoreCase("setreturnserver")) {
- if (args[1] != null) {
- getConfig().set("BungeeCord.returnserver", args[1]);
- saveConfig();
- player.sendMessage(this.prefix + ChatColor.RED + "You defined successfully the server of return"); } else {
- player.sendMessage(this.prefix + ChatColor.RED + "You have to inform an argument");
- } } else if (sub.equalsIgnoreCase("setlobby")) {
- this.lobbyLocation = player.getLocation();
- player.sendMessage(ChatColor.GREEN + "You have defined the lobby successfully.");
- getConfig().set("lobby.x", Double.valueOf(player.getLocation().getX()));
- getConfig().set("lobby.y", Double.valueOf(player.getLocation().getY()));
- getConfig().set("lobby.z", Double.valueOf(player.getLocation().getZ()));
- saveConfig();
- } else if (sub.equalsIgnoreCase("setspawn")) {
- if ((!args[1].equalsIgnoreCase("red")) && (!args[1].equalsIgnoreCase("blue"))) {
- player.sendMessage(ChatColor.RED + "The color " + ChatColor.DARK_RED + args[1] + ChatColor.RED + " does not exist.");
- } else {
- player.sendMessage(ChatColor.GREEN + "You have successfully defined the spawn of the " + args[1] + "team");
- getConfig().set("spawn" + args[1] + ".x", Double.valueOf(player.getLocation().getX()));
- getConfig().set("spawn" + args[1] + ".y", Double.valueOf(player.getLocation().getY()));
- getConfig().set("spawn" + args[1] + ".z", Double.valueOf(player.getLocation().getZ()));
- saveConfig();
- }
- } else if (sub.equalsIgnoreCase("setpool")) {
- if ((!args[1].equalsIgnoreCase("red")) && (!args[1].equalsIgnoreCase("blue"))) {
- player.sendMessage(ChatColor.RED + "The color " + ChatColor.DARK_RED + args[1] + ChatColor.RED + " does not exist.");
- } else {
- player.sendMessage(ChatColor.GREEN + "You have successfully defined the pool of the " + args[1] + "team");
- getConfig().set("pool" + args[1] + ".x", Double.valueOf(player.getLocation().getX()));
- getConfig().set("pool" + args[1] + ".y", Double.valueOf(player.getLocation().getY()));
- getConfig().set("pool" + args[1] + ".z", Double.valueOf(player.getLocation().getZ()));
- saveConfig();
- }
- } else {
- sender.sendMessage(ChatColor.RED + "Bad arguments or nonexistent command. Use " + ChatColor.DARK_RED + "/towers help" + ChatColor.RED + ".");
- }
- return true;
- }
- }
- return false;
- }
- public void respawnPlayer(Player p) {
- ItemStack helmet = new ItemStack(Material.LEATHER_HELMET, 1);
- ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
- ItemStack leggings = new ItemStack(Material.LEATHER_LEGGINGS, 1);
- ItemStack boots = new ItemStack(Material.LEATHER_BOOTS, 1);
- LeatherArmorMeta hm = (LeatherArmorMeta)helmet.getItemMeta();
- LeatherArmorMeta cp = (LeatherArmorMeta)chestplate.getItemMeta();
- LeatherArmorMeta lg = (LeatherArmorMeta)leggings.getItemMeta();
- LeatherArmorMeta bt = (LeatherArmorMeta)boots.getItemMeta();
- if (this.blue.hasPlayer(p)) {
- hm.setColor(Color.fromRGB(255));
- cp.setColor(Color.fromRGB(255));
- lg.setColor(Color.fromRGB(255));
- bt.setColor(Color.fromRGB(255));
- helmet.setItemMeta(hm);
- chestplate.setItemMeta(cp);
- leggings.setItemMeta(lg);
- boots.setItemMeta(bt);
- p.getInventory().setHelmet(helmet);
- p.getInventory().setChestplate(chestplate);
- p.getInventory().setLeggings(leggings);
- p.getInventory().setBoots(boots);
- }
- if (this.red.hasPlayer(p)) {
- hm.setColor(Color.fromRGB(16711680));
- cp.setColor(Color.fromRGB(16711680));
- lg.setColor(Color.fromRGB(16711680));
- bt.setColor(Color.fromRGB(16711680));
- helmet.setItemMeta(hm);
- chestplate.setItemMeta(cp);
- leggings.setItemMeta(lg);
- boots.setItemMeta(bt);
- p.getInventory().setHelmet(helmet);
- p.getInventory().setChestplate(chestplate);
- p.getInventory().setLeggings(leggings);
- p.getInventory().setBoots(boots);
- }
- p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.BAKED_POTATO, 16) });
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 300, 2));
- p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 300, 4));
- p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 140, 2));
- p.updateInventory();
- }
- public void CheckTeam(Player p) {
- if (this.blue.hasPlayer(p)) {
- this.blue.removePlayer(p);
- }
- if (this.red.hasPlayer(p))
- this.red.removePlayer(p);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement