Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.projoosh.dev;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.projoosh.dev.game.Game;
- import com.projoosh.dev.game.GameManager;
- import com.projoosh.dev.game.GameState;
- public class TournamentPVP extends JavaPlugin {
- //Create instance
- public static TournamentPVP INSTANCE;
- FileConfiguration config = this.getConfig();
- //When Plugin is Enabled
- @Override
- public void onEnable() {
- INSTANCE = this;
- saveDefaultConfig();
- GameManager.INSTANCE.init();
- }
- //When Plugin is Disabled
- @Override
- public void onDisable() {
- INSTANCE = null;
- for (Player player : Bukkit.getOnlinePlayers()) {
- player.kickPlayer(ChatColor.RED + "GG! " + ChatColor.GOLD + "The lobby has restarted!");
- }
- }
- public List<String> peopleVoted = new ArrayList<String>();
- //Game Settings
- int minPlayers = this.getConfig().getInt("Game.Min-Players", 3);
- int killPoints = this.getConfig().getInt("Game.Points-Kill", 75);
- int deathPoints = this.getConfig().getInt("Game.Points-Death", 100);
- int startPoints = this.getConfig().getInt("Game.Points-Start", 600);
- public HashMap<String, Integer> mapVotes = new HashMap<String, Integer>();
- //Player spawning Functions, Locations, Variables and Commands
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
- //Make sure command sender is player
- if(!(sender instanceof Player)){
- sender.sendMessage(ChatColor.RED + "You need to be a player to do commands.");
- return false;
- }
- //Define the sender as a player
- Player player = (Player) sender;
- //Add Arena Command
- if(command.getName().equalsIgnoreCase("addarena")){
- if(player.hasPermission("tournament.addarena")){
- if(args.length == 1){
- String name = args[0];
- config.set("Arenas." + name + ".Spawns.mWorld", null);
- TournamentPVP.INSTANCE.saveConfig();
- player.sendMessage(ChatColor.RED + "The arena " + ChatColor.GOLD + name + ChatColor.RED + " was added");
- return false;
- }else{
- player.sendMessage(ChatColor.RED + "Usage: /addarena <name>");
- return false;
- }
- }else{
- player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
- return false;
- }
- }
- //Delete Arena Command
- if(command.getName().equalsIgnoreCase("delarena")){
- if(player.hasPermission("tournament.delarena")){
- if(args.length == 1){
- String name = args[0];
- if (!config.isSet("Arenas." + name)){
- sender.sendMessage(ChatColor.RED + "That arena " + ChatColor.GOLD + name + ChatColor.RED + " does not exist");
- return false;
- }
- config.set("Arenas." + name, null);
- sender.sendMessage(ChatColor.RED + "The arena " + ChatColor.GOLD + name + ChatColor.RED + " was removed");
- return false;
- }else{
- player.sendMessage(ChatColor.RED + "Usage: /delarena <name>");
- return false;
- }
- }else{
- player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
- return false;
- }
- }
- //Set Lobby Command
- if(command.getName().equalsIgnoreCase("setlobbyspawn")){
- if(player.hasPermission("tournament.setlobby")){
- Location location = player.getLocation();
- config.set("Settings.LobbySpawn.X", Integer.valueOf(location.getBlockX()));
- config.set("Settings.LobbySpawn.Y", Integer.valueOf(location.getBlockY()));
- config.set("Settings.LobbySpawn.Z", Integer.valueOf(location.getBlockZ()));
- config.set("Settings.LobbySpawn.World", location.getWorld().getName());
- player.sendMessage(ChatColor.RED + "The lobby spawn has been set.");
- return false;
- }else{
- player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
- return false;
- }
- }
- //Add Spawn Command
- if(command.getName().equalsIgnoreCase("addspawn")){
- if(player.hasPermission("tournament.addspawn")){
- if(args.length == 2){
- Location location = player.getLocation();
- String arena = args[0];
- String name = args[1];
- if (!config.isSet("Arenas." + arena)){
- sender.sendMessage(ChatColor.RED + "The arena " + ChatColor.GOLD + arena + ChatColor.RED + " does not exist");
- return false;
- }
- config.set("Arenas." + arena + ".Spawns." + name + ".X", Integer.valueOf(location.getBlockX()));
- config.set("Arenas." + arena + ".Spawns." + name + ".Y", Integer.valueOf(location.getBlockY()));
- config.set("Arenas." + arena + ".Spawns." + name + ".Z", Integer.valueOf(location.getBlockZ()));
- config.set("Arenas." + arena + ".Spawns." + name + ".World", location.getWorld().getName());
- player.sendMessage(ChatColor.RED + "The spawn point " + ChatColor.GOLD + name + ChatColor.RED + " was added for the arena " + ChatColor.GOLD + arena);
- return false;
- }else{
- player.sendMessage(ChatColor.RED + "Usage: /addspawn <arena> <number>");
- return false;
- }
- }else{
- player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
- return false;
- }
- }
- //Delete spawn command
- if(command.getName().equalsIgnoreCase("delspawn")){
- if(player.hasPermission("tournament.delspawn")){
- if(args.length == 2){
- String arena = args[0];
- String name = args[1];
- if (!config.isSet("Arenas." + arena)){
- sender.sendMessage(ChatColor.RED + "The arena " + ChatColor.GOLD + arena + ChatColor.RED + " does not exist");
- return false;
- }
- if (!config.isSet("Arenas." + arena + ".Spawns." + name)){
- sender.sendMessage(ChatColor.RED + "The spawn point " + ChatColor.GOLD + name + ChatColor.RED + " does not exist in the arena " + ChatColor.GOLD + arena);
- return false;
- }
- config.set("Arenas." + arena + ".Spawns." + name, null);
- sender.sendMessage(ChatColor.RED + "The spawn point " + ChatColor.GOLD + name + ChatColor.RED + " was removed in arena " + ChatColor.GOLD + arena);
- return false;
- }else{
- player.sendMessage(ChatColor.RED + "Usage: /delspawn <arena> <number>");
- return false;
- }
- }else{
- player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
- return false;
- }
- }
- //Server info
- PluginDescriptionFile pdf = this.getDescription(); //Gets plugin.yml
- pdf.getVersion(); //Gets the version
- //Plugin Information Command
- if(command.getName().equalsIgnoreCase("config")){
- if(player.hasPermission("tournament.config")){
- player.sendMessage(ChatColor.GOLD + "-" + ChatColor.GOLD + "------ " + ChatColor.RED + "Information" + ChatColor.GOLD + " ------" + ChatColor.GOLD + "-");
- player.sendMessage(ChatColor.GOLD + "Name: " + ChatColor.RED + "TournamentPVP");
- player.sendMessage(ChatColor.GOLD + "Creator: " + ChatColor.RED + "JooshYT");
- player.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.RED + pdf.getVersion());
- player.sendMessage(ChatColor.GOLD + "Min Players: " + ChatColor.RED + minPlayers );
- player.sendMessage(ChatColor.GOLD + "Start Points: " + ChatColor.RED + startPoints );
- player.sendMessage(ChatColor.GOLD + "Kill Points: " + ChatColor.RED + killPoints );
- player.sendMessage(ChatColor.GOLD + "Death Points: " + ChatColor.RED + deathPoints );
- player.sendMessage(ChatColor.GOLD + "-" + ChatColor.GOLD + "-----------------------" + ChatColor.GOLD + "-");
- }else{
- player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
- return false;
- }
- }
- //Vote Command
- if(command.getName().equalsIgnoreCase("vote")){
- for(String key : getConfig().getConfigurationSection("Arenas").getKeys(false)) {
- if(mapVotes.get(key) == null){
- mapVotes.put(key, 0);
- }
- }
- if(player.hasPermission("tournament.vote")){
- if(Game.getState() == GameState.VOTING){
- if(args.length == 1){
- //Get the state from the class Game
- String arenaPicked = args[0];
- if(this.getConfig().isSet("Arenas." + arenaPicked)){
- for(String key : getConfig().getConfigurationSection("Arenas").getKeys(false)) {
- if(mapVotes.get(key) == null){
- mapVotes.put(key, 0);
- }
- }
- if(inList(player)){
- player.sendMessage(ChatColor.RED + "Sorry, you have already voted.");
- return false;
- }
- if(mapVotes.get(arenaPicked) != null){
- player.sendMessage(ChatColor.RED + "You have voted for the map: " + ChatColor.GOLD + arenaPicked + ChatColor.RED + ".");
- mapVotes.put(arenaPicked, mapVotes.get(arenaPicked)+1);
- peopleVoted.add(player.getName());
- return false;
- }
- }else{
- player.sendMessage(ChatColor.RED + "Sorry, that map is not found. Please vote again.");
- }
- }else{
- player.sendMessage(ChatColor.GOLD + "-" + ChatColor.GOLD + "----- " + ChatColor.RED + "/vote <name>" + ChatColor.GOLD + " -----" + ChatColor.GOLD + "-");
- for(String key : getConfig().getConfigurationSection("Arenas").getKeys(false)) {
- player.sendMessage(ChatColor.GOLD + "- " + ChatColor.RED + key + ChatColor.RED + " - " + mapVotes.get(key) + " Vote(s)");
- }
- player.sendMessage(ChatColor.GOLD + "-" + ChatColor.GOLD + "----------------------" + ChatColor.GOLD + "-");
- }
- }else{
- player.sendMessage(ChatColor.RED + "You are not allowed to vote now.");
- return false;
- }
- }else{
- player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
- return false;
- }
- }
- //End
- return false;
- }
- public boolean inList(Player player) {
- return peopleVoted.contains(player.getName());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement