Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.shoukaseikyo.minenion;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.util.config.Configuration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Event;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Minenion extends JavaPlugin
- {
- // Class attributes
- public ArrayList<Player> playerList = new ArrayList<Player>();
- public int gameStartTime = 0;
- public HashMap<Player,Integer> playerDie = new HashMap<Player,Integer>();
- public HashMap<Integer, Player> playerOnTower = new HashMap<Integer, Player>();
- public HashMap<Player, Integer> playerTeam = new HashMap<Player, Integer>();
- public HashMap<Player, Integer> playerExperience = new HashMap<Player, Integer>();
- public HashMap<Integer, Integer> teamControlledTower = new HashMap<Integer, Integer>();
- public HashMap<Integer, Integer> playerTowerTime = new HashMap<Integer, Integer>();
- public HashMap<Integer, Integer> playerScore = new HashMap<Integer, Integer>();
- //Player Money
- public HashMap<Player, Integer> playersaccount = new HashMap<Player, Integer>();
- // Player Class
- public HashMap<Player, String> playersclass = new HashMap<Player, String>();
- public HashMap<Player, Integer> playerclasslevel = new HashMap<Player, Integer>();
- public HashMap<Player, Boolean> playerclassskill = new HashMap<Player, Boolean>();
- // Player Effects
- public HashMap<Player, String> playerseffects = new HashMap<Player, String>();
- // FINAL GAME SCORE
- public HashMap<Player, Integer> PlayerKills = new HashMap<Player, Integer>();
- public HashMap<Player, Integer> PlayerDeath = new HashMap<Player, Integer>();
- public HashMap<Player, Integer> PlayerCapturedTowers = new HashMap<Player, Integer>();
- public HashMap<Player, Integer> PlayerDamageInflict = new HashMap<Player, Integer>();
- public HashMap<Player, Integer> PlayerDamage = new HashMap<Player, Integer>();
- public HashMap<Player, Integer> PlayerTimeOnPlate = new HashMap<Player, Integer>();
- public HashMap<Integer, Integer> TeamCapturedTowers = new HashMap<Integer, Integer>();
- public int[] shopblocks = new int[4];
- public Location[] towerLocations = new Location[5];
- public Location blueTeamLocation;
- public Location purpleTeamLocation;
- public boolean start = false;
- public boolean check = false;
- public boolean logging = true;
- public boolean light = false;
- public boolean multiverse = false;
- public int taskId;
- Logger log = Logger.getLogger("Minecraft");
- // Constants
- public static final int BLUE_TEAM = 1;
- public static final int PURPLE_TEAM = 2;
- /*
- * Enable the plugin
- */
- public void onEnable()
- {
- // initialize plugin
- log.info("[MINENION] Plugin enabled");
- PluginManager pluginManager = getServer().getPluginManager();
- // Desactivate the loggin system
- if(getConfig().getString("logging") != null && getConfig().getString("logging").toLowerCase().equals("false"))
- {
- log.info("LOGGING");
- logging = false;
- }
- // Lightweight activation
- if(getConfig().getString("lightweight") != null && getConfig().getString("lightweight").toLowerCase().equals("true"))
- {
- log.info("LIGHTWEIGHT");
- light = true;
- }
- // register entity and player listener
- MinenionEntityListener entityListener = new MinenionEntityListener(this);
- MinenionPlayerListener playerListener = new MinenionPlayerListener(this);
- // register events
- pluginManager.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Event.Priority.Normal, this);
- pluginManager.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this);
- pluginManager.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Normal, this);
- pluginManager.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this);
- //
- loadPointsPos();
- }
- /*
- * Disable the plugin
- */
- public void onDisable()
- {
- log.info("[MINENION] Plugin disabled");
- }
- /*
- * Log system management
- * @param input : text to write to the plug-in log file
- */
- public void mineLog(String input)
- {
- // initialize file
- File file = new File(this.getDataFolder(), "MatchLog.txt");
- BufferedWriter bwriter = null;
- FileWriter fwriter = null;
- try
- {
- // write in file
- file.createNewFile();
- fwriter = new FileWriter(file, true);
- bwriter = new BufferedWriter(fwriter);
- bwriter.write(input);
- bwriter.newLine();
- bwriter.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- /*
- * Schedule the minenion thread
- */
- public void setupGame()
- {
- @SuppressWarnings("unused")
- int taskId;
- // initialize minenion thread task
- MinenionThread minenionThread = new MinenionThread(this);
- // register the thread to the bukkit scheduler
- taskId = getServer().getScheduler().scheduleSyncRepeatingTask(this, minenionThread, 20L, 20L);
- }
- /*
- * Management of plate near tower, capture and neutralize
- */
- public void checkPlate()
- {
- // loop on towers
- for(int i = 1; i <= 5; i++)
- {
- // if player not on the plate tower
- if(playerOnTower.get(i) == null)
- {
- playerTowerTime.put(i, 0);
- ColorTower(i, 0, false);
- }
- else
- {
- // if player is on the plate tower, add tower to player
- Player onPlatePlayer = playerOnTower.get(i);
- int team = playerTeam.get(onPlatePlayer);
- playerTowerTime.get(i);
- // tower controlled by the team
- if(teamControlledTower.get(i) == team)
- {
- // the player defend the tower
- if(isStillOn(onPlatePlayer, i))
- {
- if(logging == true) mineLog(gameStartTime + " - " + onPlatePlayer.getName() + " : defending the tower #" +i + ".");
- ColorTower(i, team, false);
- addTimeOnPlate(onPlatePlayer);
- }
- else
- {
- // the player leave the tower
- if(logging == true) mineLog(gameStartTime + " - " + onPlatePlayer.getName() + " : has leave the tower #" +i + ".");
- playerOnTower.put(i, null);
- ColorTower(i, 0, false);
- }
- }
- else
- {
- // tower not controlled by the team
- if(isStillOn(onPlatePlayer, i))
- {
- // player capture the tower
- if(logging == true) mineLog(gameStartTime + " - " + onPlatePlayer.getName() + " : capturing the tower #" +i + ". " + playerTowerTime.get(i) + "/4");
- ColorTower(i, team, false);
- int time = playerTowerTime.get(i);
- // tower neutralization
- if(time == 4 && teamControlledTower.get(i) != 0)
- {
- if(logging == true) mineLog(gameStartTime + " - The tower #" + i + " has been neutralise by " + onPlatePlayer.getName());
- // add control tower and time
- playerTowerTime.put(i, 0);
- teamControlledTower.put(i, 0);
- }
- else if(time < 4)
- {
- // increment tower control time
- playerTowerTime.put(i, (time+1));
- addTimeOnPlate(onPlatePlayer);
- }
- else
- {
- // get player and team
- int teamOfPlayer = playerTeam.get(onPlatePlayer);
- ChatColor Color;
- String teamTitle;
- if(teamOfPlayer == BLUE_TEAM)
- {
- teamTitle = "blue";
- Color = ChatColor.BLUE;
- }
- else
- {
- teamTitle = "purple";
- Color = ChatColor.DARK_PURPLE;
- }
- if(logging == true) mineLog(gameStartTime + " - The tower #" + i + " has been captured by " + onPlatePlayer.getName() + " in the " + teamTitle + "team");
- error(onPlatePlayer, Color + "The tower #"+ i + " has been captured by " + onPlatePlayer.getName(), true);
- addcaptured(onPlatePlayer);
- // player control the tower
- ColorTower(i, teamOfPlayer, true);
- teamControlledTower.put(i, teamOfPlayer);
- playerTowerTime.put(i, 0);
- }
- }
- else
- {
- if(logging == true) mineLog(gameStartTime + " - " + onPlatePlayer.getName() + " : has leave the tower #" +i + ".");
- // player leave the tower
- playerOnTower.put(i, null);
- playerTowerTime.put(i, 0);
- teamControlledTower.put(i, 0);
- ColorTower(i, 0, false);
- }
- }
- }
- }
- }
- /*
- * Loading the game setup from config.yml plug-in file
- */
- public void loadPointsPos()
- {
- // Checking if the file exists
- if(new File(this.getDataFolder(), "config.yml").exists() == false)
- {
- log.info("The config file don't exist in /plugins/Minenion/. The plugin will be disable.");
- this.setEnabled(false);
- }
- else if(getConfig().getString("towers.one") == null ||
- getConfig().getString("towers.two") == null ||
- getConfig().getString("towers.three") == null ||
- getConfig().getString("towers.four") == null ||
- getConfig().getString("towers.five") == null ||
- getConfig().getString("world") == null ||
- getConfig().getString("spawn.blue") == null ||
- getConfig().getString("spawn.purple") == null ||
- getConfig().getString("shop.skill") == null ||
- getConfig().getString("shop.weapon") == null)
- {
- // one or more parameter is missed
- log.info("The coordinates are empty in /plugins/Minenion/config.yml. The plugin will be disable.");
- this.setEnabled(false);
- }
- else
- {
- boolean worldLoaded = false;
- // Verification if Multiverse is installed
- if(multiverse == true)
- {
- // Checking if the world is loaded in Bukkit
- for(World w: Bukkit.getServer().getWorlds())
- {
- if(w.getName().equals(getConfig().getString("world")))
- {
- worldLoaded = true;
- multiverse = false;
- break;
- }
- }
- }
- else if(new File("plugins\\Multiverse-Core", "config.yml").exists())
- {
- multiverse = true;
- }
- else
- {
- // Checking if the world is loaded in Bukkit
- for(World w: Bukkit.getServer().getWorlds())
- {
- if(w.getName().equals(getConfig().getString("world")))
- {
- worldLoaded = true;
- break;
- }
- }
- }
- if(multiverse == true)
- {
- log.info("[MINENION] Do a \"/mn multiverse\" to load the coordinates.");
- return;
- }
- // The world isn't loaded
- if(worldLoaded == false)
- {
- log.info("[MINENION] The world " + getConfig().getString("world") + " isn't loaded. The plugin will be disable.");
- log.info("[MINENION] Note, if you use Multiverse, load the world in its setting before installing this plugin.");
- this.setEnabled(false);
- return;
- }
- // loading the world
- String WORLD = getConfig().getString("world");
- // loading the position of towers and spawns
- String[][] POS = {(getConfig().getString("towers.one")).split("/"),
- (getConfig().getString("towers.two")).split("/"),
- (getConfig().getString("towers.three")).split("/"),
- (getConfig().getString("towers.four")).split("/"),
- (getConfig().getString("towers.five")).split("/")};
- // loading the start point of teams
- String[] B = (getConfig().getString("spawn.blue")).split("/");
- String[] P = (getConfig().getString("spawn.purple")).split("/");
- // Generation of towers locations
- for(int i = 0; i <= 4; i++)
- {
- towerLocations[i] = new Location(Bukkit.getServer().getWorld(WORLD),
- Double.valueOf(POS[i][0]),
- Double.valueOf(POS[i][1]),
- Double.valueOf(POS[i][2]));
- }
- // Generation of teams locations
- blueTeamLocation = new Location(Bukkit.getServer().getWorld(WORLD),
- Double.valueOf(B[0]),
- Double.valueOf(B[1]),
- Double.valueOf(B[2]));
- purpleTeamLocation = new Location(Bukkit.getServer().getWorld(WORLD),
- Double.valueOf(P[0]),
- Double.valueOf(P[1]),
- Double.valueOf(P[2]));
- // Initialization of control tower
- for(int i = 1; i <= 5; i++)
- {
- playerOnTower.put(i, null);
- teamControlledTower.put(i, 0);
- playerTowerTime.put(i, 0);
- ColorTower(i, 0, true);
- ColorTower(i, 0, false);
- }
- // Initialization of the shop's blocks
- shopblocks[0] = Integer.valueOf(getConfig().getString("shop.weapon").split("/")[0]);
- shopblocks[1] = Integer.valueOf(getConfig().getString("shop.skill").split("/")[0]);
- shopblocks[2] = 0;
- shopblocks[3] = 0;
- // Check if there is damage on blocks
- if(Integer.valueOf(getConfig().getString("shop.weapon").split("/")[1]) != 0)
- {
- shopblocks[2] = Integer.valueOf(getConfig().getString("shop.weapon").split("/")[1]);
- }
- if(Integer.valueOf(getConfig().getString("shop.skill").split("/")[1]) != 0)
- {
- shopblocks[3] = Integer.valueOf(getConfig().getString("shop.skill").split("/")[1]);
- }
- // Initialization the teams scores
- playerScore.put(BLUE_TEAM, 500);
- playerScore.put(PURPLE_TEAM, 500);
- }
- }
- /*
- * Change the color of a tower
- * @param tower : the number of the tower
- * @param team : the color of team who control the tower
- */
- public void ColorTower(int tower, int team, boolean cube)
- {
- int material = 0;
- int height = 17;
- int maxheight = 0;
- byte color = (byte)0x0;
- Block block;
- // Set color for the team
- if(team == BLUE_TEAM)
- {
- color = (byte)0xB;
- material = 35;
- }
- if(team == PURPLE_TEAM)
- {
- color = (byte)0x2;
- material = 35;
- }
- // if the tower is only controlled
- if(cube == true)
- {
- // set height to 13
- material = 35;
- height = 13;
- maxheight = 2;
- }
- // Get coordinates of towers
- World world = towerLocations[0].getWorld();
- int xPosTower = (int) (towerLocations[tower-1].getX()+1);
- int yPosTower = (int) (towerLocations[tower-1].getY()+height);
- int zPosTower = (int) (towerLocations[tower-1].getZ()+1);
- // Apply color to the tower
- for(int x = xPosTower; x >= (xPosTower-2); x--)
- {
- for(int y = yPosTower; y <= (yPosTower+maxheight); y++)
- {
- for(int z = zPosTower; z >= (zPosTower-2); z--)
- {
- block = world.getBlockAt(x, y, z);
- block.setTypeIdAndData(material, color, false);
- }
- }
- }
- }
- /*
- * Reset experience of a player
- * @param player : the player how to reset experience
- */
- public void resetExperience(Player player)
- {
- // reset the player experience
- player.setLevel(0);
- player.setExp(0);
- player.setTotalExperience(0);
- player.giveExp(playerExperience.get(player));
- }
- /*
- * Management of game/team score
- */
- public void scoreManagement()
- {
- String[] controledTowerScore = towerControledScore().split("/");
- int blueScore = Integer.valueOf(controledTowerScore[0]);
- int purpleScore = Integer.valueOf(controledTowerScore[1]);
- if(blueScore > purpleScore)
- {
- // if blue team had more controlled tower than purple team
- int actualControlPower = playerScore.get(2);
- int scoreGap = blueScore - purpleScore;
- // in function of controlled tower score gap, remove score points to player
- if(scoreGap == 1)
- {
- playerScore.put(2, (playerScore.get(2) - 1));
- }
- else if(scoreGap == 2)
- {
- playerScore.put(2, (playerScore.get(2) - 2));
- }
- else if(scoreGap == 3)
- {
- playerScore.put(2, (playerScore.get(2) - 3));
- }
- else if(scoreGap == 4)
- {
- playerScore.put(2, (playerScore.get(2) - 5));
- }
- else if(scoreGap == 5)
- {
- playerScore.put(2, (playerScore.get(2) - 10));
- }
- // send to console the new power balance
- int newControlPower = playerScore.get(2);
- int lostControlPower = actualControlPower - newControlPower;
- if(logging == true) mineLog(gameStartTime + " - The purple Nexus losted " + lostControlPower + "HP, " + newControlPower + "/500");
- }
- else if (blueScore < purpleScore)
- {
- // if purple team had more controlled tower than blue team
- int actualControlPower = playerScore.get(1);
- int scoreGap = purpleScore - blueScore;
- // in function of controlled tower score gap, remove score points to player
- if(scoreGap == 1)
- {
- playerScore.put(1, (playerScore.get(1) - 1));
- }
- if(scoreGap == 2)
- {
- playerScore.put(1, (playerScore.get(1) - 2));
- }
- if(scoreGap == 3)
- {
- playerScore.put(1, (playerScore.get(1) - 3));
- }
- if(scoreGap == 4)
- {
- playerScore.put(1, (playerScore.get(1) - 5));
- }
- if(scoreGap == 5)
- {
- playerScore.put(1, (playerScore.get(1) - 10));
- }
- // send to console the new power balance
- int newControlPower = playerScore.get(1);
- int lostControlPower = actualControlPower - newControlPower;
- if(logging == true) mineLog(gameStartTime + " - The blue Nexus losted " + lostControlPower + "HP, " + newControlPower + "/500");
- }
- // lost game for blue team
- if(playerScore.get(1) <= 0)
- {
- start = false;
- // loop for player list
- for(Player player : playerList)
- {
- if(playerTeam.get(player) == 1)
- {
- // kicking and messaging the players
- player.kickPlayer("You lost !");
- if(logging == true) mineLog(gameStartTime + " - The blue Nexus has been destroyed ! The blue team lost.");
- if(logging == true) mineLog(gameStartTime + " - The game has stopped at : " + getDateTime());
- if(logging == true) mineLog("-------------------------");
- // Generating score file
- if(logging == true) GenerateScore();
- // unregister the minenion thread task
- getServer().getScheduler().cancelTask(taskId);
- }
- }
- }
- // lost fame for purple team
- if(playerScore.get(2) <= 0)
- {
- start = false;
- // loop for player list
- for(Player player : playerList)
- {
- if(playerTeam.get(player) == 2)
- {
- // kicking and messaging the players
- player.kickPlayer("You lost !");
- if(logging == true) mineLog(gameStartTime + " - The purple Nexus has been destroyed ! The purple team lost.");
- if(logging == true) mineLog(gameStartTime + " - The game has stopped at : " + getDateTime());
- if(logging == true) mineLog("-------------------------");
- // Generating score file
- if(logging == true) GenerateScore();
- // unregister the minenion thread task
- getServer().getScheduler().cancelTask(taskId);
- }
- }
- }
- }
- /*
- * Publish error message to the console player or broadcast
- * @param player : the name of the player how receive the message
- * @param message : the message to send
- * @param broadcast : true for broadcast all players, false for the player only
- */
- public void error(Player player, String message, boolean broadcast)
- {
- if(! broadcast)
- {
- // message to player
- player.sendMessage(message);
- }
- else
- {
- // message to broadcast
- getServer().broadcastMessage(message);
- }
- }
- /*
- * Setup all the players to start the game
- */
- public void setupPlayers()
- {
- // setup team towers captured to 0
- TeamCapturedTowers.put(BLUE_TEAM, 0);
- TeamCapturedTowers.put(PURPLE_TEAM, 0);
- // class attributes
- ItemStack itemStack;
- String classOfPlayer;
- // loop for all players
- for(Player player : playerList)
- {
- // initialize player characteristics to play
- player.setGameMode(GameMode.SURVIVAL);
- player.setHealth(20);
- player.setFoodLevel(20);
- if(light == false)
- {
- createaccount(player);
- player.setLevel(0);
- player.setExp(0);
- player.getInventory().clear();
- player.setTotalExperience(0);
- playerExperience.put(player, 0);
- PlayerKills.put(player, 0);
- PlayerDeath.put(player, 0);
- PlayerDamageInflict.put(player, 0);
- PlayerDamage.put(player, 0);
- PlayerTimeOnPlate.put(player, 0);
- PlayerCapturedTowers.put(player, 0);
- // get inventory and class of player
- Inventory playerInventory = player.getInventory();
- classOfPlayer = getClass(player);
- // ARCHER
- if(classOfPlayer.equals("archer"))
- {
- // create an arrows stack (64 pieces) and put it to player inventory (at position 9)
- itemStack = new ItemStack(262, 64);
- playerInventory.setItem(9, itemStack);
- // create a bow stack (one piece) and put it to player inventory (at position 0)
- itemStack = new ItemStack(261, 1);
- playerInventory.setItem(0, itemStack);
- }
- // SWORDMAN
- if(classOfPlayer.equals("swordsman"))
- {
- // create a diamond sword stack (one piece) and put it to player inventory (at position 0)
- itemStack = new ItemStack(276, 1);
- playerInventory.setItem(0, itemStack);
- }
- // TANK
- if(classOfPlayer.equals("tank"))
- {
- // create a wood stick stack (one piece) and put it to player inventory (at position 0)
- itemStack = new ItemStack(280, 1);
- playerInventory.setItem(0, itemStack);
- }
- // UCKER
- if(classOfPlayer.equals("ucker"))
- {
- // create a diamond axe stack (one piece) and put it to player inventory (at position 0)
- itemStack = new ItemStack(279, 1);
- playerInventory.setItem(0, itemStack);
- }
- }
- // move player to blue team start point
- if(playerTeam.get(player) == BLUE_TEAM)
- {
- player.teleport(blueTeamLocation);
- if(logging == true) mineLog(gameStartTime + " - " + player.getName() + "is in BLUE team.");
- }
- // move player to blue team start point
- if(playerTeam.get(player) == PURPLE_TEAM)
- {
- player.teleport(purpleTeamLocation);
- if(logging == true) mineLog(gameStartTime + " - " + player.getName() + "is in PURPLE team.");
- }
- }
- // reset game time
- gameStartTime = 0;
- }
- /*
- * Determine the number of tower where player is
- * @param playerLocation : the location of player
- * @return i : the tower number
- */
- public int inWhichZone(Location playerLocation)
- {
- double X = playerLocation.getX();
- double Y = playerLocation.getY();
- double Z = playerLocation.getZ();
- // loop the towers
- for(int i = 1; i <= 5; i++)
- {
- // check if around the tower
- if(X >= (towerLocations[i-1].getX()-7)
- && X <= (towerLocations[i-1].getX()+7)
- && Y >= (towerLocations[i-1].getY())
- && Y <= (towerLocations[i-1].getY()+3)
- && Z >= (towerLocations[i-1].getZ()-7)
- && Z <= (towerLocations[i-1].getZ()+7))
- {
- // Return tower number
- return (i);
- }
- }
- // No towers near player
- return 0;
- }
- /*
- * Count player in a team
- * @param teamNumber : the number of the team (1 for blue, 2 for purple)
- * @return playerCount : the count of player for the chosen team
- */
- public int countPlayerTeam(int teamNumber)
- {
- int playerCount = 0;
- // loop players list
- for(Player player : playerList)
- {
- // cumulate amount of players for the chosen team
- if(playerTeam.get(player) == teamNumber)
- {
- playerCount++;
- }
- }
- return playerCount;
- }
- /*
- * Calculate the controlled tower for blue/purple team
- * @return : score of controlled tower (blue score / purple score)
- */
- public String towerControledScore()
- {
- int blueControledTower = 0;
- int purpleControledTower = 0;
- int controled = 0;
- String towerScore;
- // loop for towers
- for(int i = 1; i <= 5; i++)
- {
- controled = teamControlledTower.get(i);
- if(controled == 1)
- {
- // tower controlled by blue team
- blueControledTower++;
- }
- if(controled == 2)
- {
- // tower controlled by purple team
- purpleControledTower++;
- }
- }
- // generate the score
- towerScore = blueControledTower+"/"+purpleControledTower;
- return towerScore;
- }
- /*
- * Get the date/time
- * @return date : the current date/time
- */
- private String getDateTime()
- {
- // generate current date/time
- DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
- Date date = new Date();
- return dateFormat.format(date);
- }
- /*
- * Get the byte from int
- * @argument damage : int to get byte from
- * @return damage2byte : byte
- */
- public byte damage2byte(int damage)
- {
- byte data = (byte)0x0;
- if(damage == 0)
- {
- return data;
- }
- if(damage == 1) data = (byte)0x1;
- if(damage == 2) data = (byte)0x2;
- if(damage == 3) data = (byte)0x3;
- if(damage == 4) data = (byte)0x4;
- if(damage == 5) data = (byte)0x5;
- if(damage == 6) data = (byte)0x6;
- if(damage == 7) data = (byte)0x7;
- if(damage == 8) data = (byte)0x8;
- if(damage == 9) data = (byte)0x9;
- if(damage == 10) data = (byte)0xA;
- if(damage == 11) data = (byte)0xB;
- if(damage == 12) data = (byte)0xC;
- if(damage == 13) data = (byte)0xD;
- if(damage == 14) data = (byte)0xE;
- if(damage == 15) data = (byte)0xF;
- return data;
- }
- /*
- * Check if the player is in a tower zone, on a pressure plate
- * @param player : the player to check
- * @param tower : the number of the tower
- * @return stillOn : true if the player still on
- */
- public boolean isStillOn(Player player, int tower)
- {
- // check if player is in a tower zone, on a pressure plate (id=70)
- if(player.getLocation().getBlock().getTypeId() == 70 && inWhichZone(player.getLocation()) == tower)
- {
- // the player still on
- return true;
- }
- // player is off
- return false;
- }
- /*
- * Check if a player is online
- * @param player : the player to check if online
- * @return isOnline : true if the player is online
- */
- public boolean isOnline(String Player)
- {
- if (getServer().getPlayer(Player) == null)
- {
- // player offline
- return false;
- }
- else
- {
- // player online
- return true;
- }
- }
- // CASH MANAGEMENT
- /*
- * withdraw an amount from the player account
- * @param player : the player who to remove money
- * @param amount : the amount of money
- * @return withdraw : true if the transaction is working
- */
- public void withdraw(Player player, int amount)
- {
- if(hasaccount(player))
- {
- if(canafford(player, amount))
- {
- playersaccount.put(player, (playersaccount.get(player) - amount));
- }
- }
- }
- /*
- * Give an amount to the player account
- * @param player : the player who to add money
- * @param amount : the amount of money
- */
- public void give(Player player, int amount)
- {
- if(hasaccount(player))
- {
- playersaccount.put(player, (playersaccount.get(player) + amount));
- }
- }
- /*
- * if the player can afford the price
- * @param player : the player who can afford
- * @param amount : the amount of money
- * @return canafford : true if the player can buy
- */
- public boolean canafford(Player player, int amount)
- {
- if(hasaccount(player))
- {
- if(has(player) >= amount)
- {
- return true;
- }
- return false;
- }
- return false;
- }
- /*
- * Create a account for the player
- * @param player : the player who need an account
- */
- public void createaccount(Player player)
- {
- playersaccount.put(player, 0);
- }
- /*
- * Check if the player has an account
- * @param player : the player who has an account
- * @return hasaccount : true if the player has an account
- */
- public boolean hasaccount(Player player)
- {
- if(playersaccount.containsKey(player))
- {
- return true;
- }
- return false;
- }
- /*
- * Return the money in the player account
- * @param player : the player who has how much
- * @return has : the money the player has
- */
- public int has(Player player)
- {
- if(hasaccount(player))
- {
- return playersaccount.get(player);
- }
- return 0;
- }
- // CLASSES MANAGEMENT
- /*
- * get if the player have the ability to use his skill
- * @argument player : the player to test
- * @return getSkill : true if the player has the ability
- */
- public boolean getSkill(Player player)
- {
- return playerclassskill.get(player);
- }
- /*
- * set the player ability to use his skill to true
- * @argument player : player to give skill
- */
- public void setSkillTrue(Player player)
- {
- playerclassskill.put(player, true);
- }
- /*
- * set the class level of the player
- * @argument player : player to set level
- * @argument level : the level to set
- */
- public void setLevel(Player player, int level)
- {
- playerclasslevel.put(player, level);
- }
- /*
- * get the class level of the player
- * @argument player : the player class level to get
- */
- public int getLevel(Player player)
- {
- return playerclasslevel.get(player);
- }
- /*
- * get the stats of the class with the player
- * @argument player : the player who need stats
- * @argument classe : the class the player have
- */
- public String stats(Player player)
- {
- String statistics = "0/0";
- String classe = playersclass.get(player);
- int level = player.getLevel();
- int inHand = player.getInventory().getItemInHand().getTypeId();
- int attack = 0;
- int defense = 0;
- if(classe.equals("archer"))
- {
- // calculate attack and defense
- attack = (int) Math.floor(4*Math.log(15*level)+4);
- defense = (int) Math.floor(0.1*level);
- // calculate limits of attack/defense
- if(inHand == 0) attack = 1;
- if(getLevel(player) == 1 && attack > 6) attack = 6;
- if(getLevel(player) == 2 && attack > 12) attack = 12;
- if(attack > 19) attack = 19;
- if(defense > 7) defense = 7;
- }
- if(classe.equals("swordsman"))
- {
- // calculate attack and defense
- attack = (int) Math.floor(0.0019*(level*level)+4);
- defense = (int) Math.floor(0.45*level+2);
- // calculate limits of attack/defense
- if(inHand == 0) attack = 1;
- if(getLevel(player) == 1 && attack > 7) attack = 7;
- if(inHand == 267) attack = 15;
- if(attack > 19) attack = 19;
- if(defense > 12) defense = 12;
- }
- if(classe.equals("ucker"))
- {
- // calculate attack and defense
- attack = (int) Math.floor(0.8*level+5);
- defense = (int) Math.floor(0.8*level);
- // calculate limits of attack/defense
- if(inHand == 0) attack = 1;
- if(attack > 19) attack = 19;
- if(defense > 8) defense = 8;
- }
- if(classe.equals("tank"))
- {
- // calculate attack and defense
- attack = (int) Math.floor(0.1*level+2);
- defense = (int) Math.floor(0.7*level+4);
- // calculate limits of attack/defense
- if(inHand == 0) attack = 1;
- //if(inHand == 272) attack = 3;
- //if(inHand == 267) attack = 7;
- if(attack > 10) attack = 10;
- if(defense > 17) defense = 17;
- }
- // generate statistics
- statistics = attack + "/" + defense;
- return statistics;
- }
- /*
- * remove the class from the player
- * @argument player : the player to retire a class
- */
- public void removeclass(Player player)
- {
- // set to lower case to not get errors
- if(hasclass(player))
- {
- playersclass.remove(player);
- }
- }
- /*
- * Get the player class
- * @argument player
- * @return getClass : class
- */
- public String getClass(Player player)
- {
- if(hasclass(player))
- {
- return playersclass.get(player);
- }
- return null;
- }
- /*
- * set the class to the player
- * @argument player : the player who need a class
- * @argument Class : the given class
- */
- public void setclass(Player player, String Class)
- {
- // set to lower case to not get errors
- String Classe = Class.toLowerCase();
- if(exist(Classe))
- {
- if(!hasclass(player))
- {
- playersclass.put(player, Classe);
- playerclasslevel.put(player, 1);
- playerclassskill.put(player, false);
- }
- }
- }
- /*
- * if the player has a class
- * @argument player : the player to test
- * @return hasclass : true if the player has a class
- */
- public boolean hasclass(Player player)
- {
- if(playersclass.containsKey(player))
- {
- return true;
- }
- return false;
- }
- /*
- * if the class exist
- * @argument Class : Class to test
- * @return exist : true if the class exist
- */
- public boolean exist(String Classe)
- {
- if(Classe.equals("archer") ||
- Classe.equals("swordsman") ||
- Classe.equals("ucker") ||
- Classe.equals("tank"))
- {
- return true;
- }
- return false;
- }
- //EFFECTS MANAGEMENT
- public String getEffect(Player player)
- {
- if(stillEffect(player))
- {
- return playerseffects.get(player).split("/")[0];
- }
- return "none";
- }
- /*
- * if the effect is still effective
- * @argument player : the player who will have the effect
- * @return stillEffect : true if the effect is effective
- */
- public boolean stillEffect(Player player)
- {
- if(hasEffect(player))
- {
- String[] EffectTime = playerseffects.get(player).split("/");
- String Effect = EffectTime[0];
- int time = Integer.valueOf(EffectTime[1]);
- //if the effect is poison
- if(time == 0)
- {
- playerseffects.remove(player);
- return false;
- }
- else
- {
- setEffect(player, Effect, (time-1));
- return true;
- }
- }
- return false;
- }
- /*
- * get if the player has an effect
- * @argument player
- * @return hasEffect : true if the player has an effect
- */
- public boolean hasEffect(Player player)
- {
- if(playerseffects.containsKey(player))
- {
- return true;
- }
- return false;
- }
- /*
- * set the effect to the player
- * @argument player : the player who to set effect
- * @argument effect : the effect to set
- * @argument time : the duration of the effect
- */
- public void setEffect(Player player, String Effect, int time)
- {
- if(playerseffects.containsKey(player) == false || playerseffects.get(player).split("/")[0].equals(Effect))
- {
- playerseffects.put(player, Effect+"/"+time);
- }
- }
- // SHOP MANAGEMENT
- public void buyweapon(Player player)
- {
- if(getLevel(player) != 3)
- {
- int price = ((5000*getLevel(player)) - 2000);
- if(canafford(player, price) == false)
- {
- player.sendMessage(ChatColor.RED + "You can't afford an upgrade to your weapon. " + ChatColor.YELLOW + "(Price : " + price + "$)");
- return;
- }
- withdraw(player, price);
- setLevel(player, (getLevel(player)+1));
- player.sendMessage(ChatColor.YELLOW + "You paid " + price + "$ to upgrade your weapon to level " + getLevel(player) + " !");
- return;
- }
- player.sendMessage(ChatColor.RED + "You can't upgrade your weapon anymore.");
- return;
- }
- public void buyskill(Player player)
- {
- if(getSkill(player) == false)
- {
- int price = 12000;
- if(canafford(player, price) == false)
- {
- player.sendMessage(ChatColor.RED + "You can't afford to buy your skill. " + ChatColor.YELLOW + "(Price : " + price + "$)");
- return;
- }
- withdraw(player, price);
- setSkillTrue(player);
- player.sendMessage(ChatColor.YELLOW + "You paid " + price + "$ to obtain your skill !");
- return;
- }
- player.sendMessage(ChatColor.RED + "There is no other skill to buy.");
- return;
- }
- // FINAL GAME SCORE MANAGEMENT
- /*
- * Add a second to the time passed on plate
- * @argument player : the player to add a second
- */
- public void addTimeOnPlate(Player player)
- {
- if(PlayerTimeOnPlate.containsKey(player) == false)
- {
- PlayerTimeOnPlate.put(player, 1);
- return;
- }
- int TimeOnPlate = PlayerTimeOnPlate.get(player);
- PlayerTimeOnPlate.put(player, (TimeOnPlate + 1));
- }
- /*
- * Add an amount of damage to the player
- * @argument player : the player to add amount of damage
- * @argument damage : the amount of damage received
- */
- public void addDamageReceived(Player player, int damage)
- {
- if(PlayerDamage.containsKey(player) == false)
- {
- PlayerDamage.put(player, damage);
- return;
- }
- int Damage = PlayerDamage.get(player);
- PlayerDamage.put(player, (Damage + damage));
- }
- /*
- * Add an amount of damage to the player
- * @argument player : the player to add amount of damage
- * @argument damage : the amount of damage inflicted
- */
- public void addDamageInflict(Player player, int damage)
- {
- if(PlayerCapturedTowers.containsKey(player) == false)
- {
- PlayerCapturedTowers.put(player, damage);
- return;
- }
- int Damage = PlayerCapturedTowers.get(player);
- PlayerCapturedTowers.put(player, (Damage + damage));
- }
- /*
- * Add a captured tower to the counter of the player
- * @argument player : the player to add a captured tower
- */
- public void addcaptured(Player player)
- {
- if(PlayerCapturedTowers.containsKey(player) == false)
- {
- PlayerCapturedTowers.put(player, 1);
- return;
- }
- int TowerCounter = PlayerCapturedTowers.get(player);
- PlayerCapturedTowers.put(player, (TowerCounter + 1));
- int TEAM = playerTeam.get(player);
- if(TeamCapturedTowers.containsKey(TEAM) == false)
- {
- TeamCapturedTowers.put(TEAM, 1);
- return;
- }
- int TeamTowerCounter = TeamCapturedTowers.get(TEAM);
- TeamCapturedTowers.put(TEAM, (TeamTowerCounter + 1));
- }
- /*
- * Add a death to the counter of the player
- * @argument player : the player to add a death
- */
- public void adddeath(Player player)
- {
- if(PlayerDeath.containsKey(player) == false)
- {
- PlayerDeath.put(player, 1);
- return;
- }
- int DeathCounter = PlayerDeath.get(player);
- PlayerDeath.put(player, (DeathCounter + 1));
- }
- /*
- * Add a kill to the counter of the player
- * @argument player : the player to add a kill
- */
- public void addkill(Player player)
- {
- if(PlayerKills.containsKey(player) == false)
- {
- PlayerKills.put(player, 1);
- return;
- }
- int KillCounter = PlayerKills.get(player);
- PlayerKills.put(player, (KillCounter + 1));
- }
- /*
- * Generate the PlayersScore file when the game is finished
- */
- public void GenerateScore()
- {
- // initialize file
- File file = new File(this.getDataFolder(), "PlayersScore.txt");
- BufferedWriter bwriter = null;
- FileWriter fwriter = null;
- try
- {
- // write in file
- file.createNewFile();
- fwriter = new FileWriter(file, true);
- bwriter = new BufferedWriter(fwriter);
- bwriter.write("------------------------------------------");
- bwriter.newLine();
- bwriter.write("---------------|=TIME : " + gameStartTime + "=|---------------");
- bwriter.newLine();
- bwriter.write("------------------------------------------");
- bwriter.newLine();
- for(Player player : playerList)
- {
- bwriter.write("---Player : " + player.getName());
- bwriter.newLine();
- bwriter.write("------Kills : " + PlayerKills.get(player));
- bwriter.newLine();
- bwriter.write("------Death : " + PlayerDeath.get(player));
- bwriter.newLine();
- bwriter.write("------Towers captured : " + PlayerCapturedTowers.get(player) + "/" + TeamCapturedTowers.get(playerTeam.get(player)) + " towers captured by team");
- bwriter.newLine();
- bwriter.write("------Stats : Level : " + player.getLevel() + " - Inflicted damages : " + PlayerDamageInflict.get(player) + " - Damages received : " + PlayerDamage.get(player) + " - Money Obtained : " + has(player) + " - Total experience : " + player.getTotalExperience());
- bwriter.newLine();
- bwriter.write("------Time passed on towers : " + PlayerTimeOnPlate.get(player) + "/" + gameStartTime);
- bwriter.newLine();
- }
- bwriter.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- /*
- * Management of commands typed by a player in the console
- * @param sender : player how send the command
- * @param command : command send by the player (mn for minenion)
- * @param label : command label
- * @param args : arguments of command
- * @return true if the command is known
- */
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- String cmd = command.getName().toLowerCase();
- // if player send a minenion (mm) command
- if (cmd.equals("mn") && sender instanceof Player)
- {
- if(multiverse == true && args[0].toLowerCase().equals("multiverse"))
- {
- loadPointsPos();
- return true;
- }
- if(multiverse == true && (args.length >= 0))
- {
- error((Player)sender, ChatColor.RED + "Do /mn multiverse to reload the plugin with multiverse", false);
- return true;
- }
- // ***********************
- // HELP command
- // ***********************
- if(args.length == 0 || args[0].toLowerCase().equals("help"))
- {
- // write command help in the console
- error((Player)sender, ChatColor.YELLOW + "Available commands", false);
- if(light == true)
- {
- error((Player)sender, ChatColor.YELLOW + " /mn join <team> : " + ChatColor.WHITE + "Join the game.", false);
- error((Player)sender, ChatColor.YELLOW + " <team> : " + ChatColor.BLUE + "BLUE" + ChatColor.YELLOW + " or " + ChatColor.DARK_PURPLE + "PURPLE", false);
- }
- else
- {
- error((Player)sender, ChatColor.YELLOW + " /mn join <team> <class> : " + ChatColor.WHITE + "Join the game.", false);
- error((Player)sender, ChatColor.YELLOW + " <team> : " + ChatColor.BLUE + "BLUE" + ChatColor.YELLOW + " or " + ChatColor.DARK_PURPLE + "PURPLE", false);
- error((Player)sender, ChatColor.YELLOW + " <class> : " + ChatColor.WHITE + "Archer, Swordsman, Tank, Ucker", false);
- }
- error((Player)sender, ChatColor.YELLOW + " /mn quit : " + ChatColor.WHITE + "Quit the current game.", false);
- error((Player)sender, ChatColor.YELLOW + " /mn start : " + ChatColor.WHITE + "Start the current game.", false);
- // if the player is a server operator, more commands
- if(sender.isOp())
- {
- error((Player)sender, ChatColor.YELLOW + " /mn fstart : " + ChatColor.WHITE + "Force the game to start.", false);
- error((Player)sender, ChatColor.YELLOW + " /mn stp : " + ChatColor.WHITE + "Stop the current game and reset the players list.", false);
- }
- return true;
- }
- // ***********************
- // JOIN command
- // ***********************
- if(args[0].toLowerCase().equals("join"))
- {
- // if game is started
- if(start == false)
- {
- // if the command sender is already in the player list
- if(playerList.contains((Player)sender) == true)
- {
- error((Player) sender, ChatColor.RED + "You already joined the game.", false);
- return true;
- }
- // check if the arguments to join are correct
- if(light == false && (args.length < 3 || !(args[1].toLowerCase().equals("blue") || args[1].toLowerCase().equals("purple")) || !(args[2].toLowerCase().equals("archer") || args[2].toLowerCase().equals("swordsman") || args[2].toLowerCase().equals("tank") || args[2].toLowerCase().equals("ucker"))))
- {
- error((Player)sender, ChatColor.YELLOW + "/mn join <team> <class> : " + ChatColor.WHITE + "Join the game.", false);
- error((Player)sender, ChatColor.YELLOW + " <team> : " + ChatColor.BLUE + "BLUE" + ChatColor.YELLOW + " or " + ChatColor.DARK_PURPLE + "PURPLE", false);
- error((Player)sender, ChatColor.YELLOW + " <class> : " + ChatColor.WHITE + "Archer, Swordsman, Tank, Ucker", false);
- return true;
- }
- if(light == true && (args.length < 2 || !(args[1].toLowerCase().equals("blue") || args[1].toLowerCase().equals("purple"))))
- {
- error((Player)sender, ChatColor.YELLOW + "/mn join <team> <class> : " + ChatColor.WHITE + "Join the game.", false);
- error((Player)sender, ChatColor.YELLOW + " <team> : " + ChatColor.BLUE + "BLUE" + ChatColor.YELLOW + " or " + ChatColor.DARK_PURPLE + "PURPLE", false);
- return true;
- }
- // team selection
- int team = 0;
- if(args[1].toLowerCase().equals("blue"))
- {
- team = BLUE_TEAM;
- }
- if(args[1].toLowerCase().equals("purple"))
- {
- team = PURPLE_TEAM;
- }
- String error;
- // check if still slot in the team
- if(countPlayerTeam(team) < 5)
- {
- // add player in the team
- Player player = (Player)sender;
- playerList.add(player);
- playerTeam.put(player, team);
- error = ChatColor.BLUE + sender.getName() + " has join the " + args[1] + " team !";
- if(light == false)
- {
- // check the class of the player and set it
- if(args[2].toLowerCase().equals("archer"))
- {
- setclass(player, "archer");
- }
- if(args[2].toLowerCase().equals("swordsman"))
- {
- setclass(player, "swordsman");
- }
- if(args[2].toLowerCase().equals("tank"))
- {
- setclass(player, "tank");
- }
- if(args[2].toLowerCase().equals("ucker"))
- {
- setclass(player, "ucker");
- }
- error = ChatColor.BLUE + sender.getName() + " has join the " + args[1] + " team as " + args[2] + " !";
- }
- error((Player)sender, error, true);
- return true;
- }
- // there is no more space in the team
- error((Player)sender, ChatColor.RED + "The Team is full !", false);
- return true;
- }
- // the game has already started
- error((Player)sender, ChatColor.RED + "The game is already started, you can't join now ! =(", false);
- return true;
- }
- // ***********************
- // QUIT command
- // ***********************
- if(args[0].toLowerCase().equals("quit"))
- {
- // if game is started
- if(start == false)
- {
- // remove player from the game
- Player player = (Player)sender;
- // if the command sender is not in the player list
- if(playerList.contains(player))
- {
- playerList.remove(player);
- playerTeam.remove(player);
- error((Player)sender, ChatColor.DARK_PURPLE + sender.getName() + " has quit the game !", true);
- return true;
- }
- else
- {
- error(player, ChatColor.RED + "You aren't listed.", false);
- return true;
- }
- }
- // the game has already started
- error((Player)sender, ChatColor.RED + "The game is already started, you can't quit now ! D=", false);
- return true;
- }
- // ***********************
- // START command
- // ***********************
- if(args[0].toLowerCase().equals("start"))
- {
- // if there is 2 team of 5 players and the game not already started
- if((countPlayerTeam(1) + countPlayerTeam(2)) == 10 && start == false)
- {
- // start game
- start = true;
- if(logging == true) mineLog(gameStartTime + " - The game has started at : " + getDateTime());
- for(int i = 1; i <= 5; i++)
- {
- playerOnTower.put(i, null);
- teamControlledTower.put(i, 0);
- playerTowerTime.put(i, 0);
- ColorTower(i, 0, false);
- ColorTower(i, 0, true);
- }
- playerScore.put(1, 500);
- playerScore.put(2, 500);
- setupPlayers();
- setupGame();
- error((Player)sender, ChatColor.YELLOW + "The game is started !", true);
- return true;
- }
- // the game is already started or incomplete team
- error((Player)sender, ChatColor.RED + "The teams are not complete OR the game is already started!", false);
- return true;
- }
- // ***************************************************
- // FSTART forced start command only for game operator
- // ***************************************************
- if(args[0].toLowerCase().equals("fstart") && sender.isOp() && playerList.contains((Player)sender))
- {
- // if game is started
- if(start == false)
- {
- // start the game
- start = true;
- if(logging == true) mineLog(gameStartTime + " - The game has being forced to start at : " + getDateTime() + " WITH " + countPlayerTeam(BLUE_TEAM) + " blue players AND " + countPlayerTeam(PURPLE_TEAM) + " purple players");
- for(int i = 1; i <= 5; i++)
- {
- playerOnTower.put(i, null);
- teamControlledTower.put(i, 0);
- playerTowerTime.put(i, 0);
- ColorTower(i, 0, false);
- ColorTower(i, 0, true);
- }
- playerScore.put(1, 500);
- playerScore.put(2, 500);
- setupPlayers();
- setupGame();
- error((Player)sender, ChatColor.YELLOW + "The game is started !", true);
- return true;
- }
- // the game is already started
- error((Player)sender, ChatColor.RED + "The game is already started!", false);
- return true;
- }
- // *****************************************
- // CHECK command for testing coordinates
- // *****************************************
- if(args[0].toLowerCase().equals("check"))
- {
- if(check == false)
- {
- check = true;
- return true;
- }
- else
- {
- check = false;
- return true;
- }
- }
- // ************************************
- // STOP command only for game operator
- // ************************************
- if(args[0].toLowerCase().equals("stop") && sender.isOp())
- {
- // if game is started
- if(start == true)
- {
- // generate the final score
- if(logging == true)
- {
- GenerateScore();
- playersclass.clear();
- playerclassskill.clear();
- playerclasslevel.clear();
- }
- // clear players
- playerList.clear();
- playerTeam.clear();
- // remove thread task of minennion
- getServer().getScheduler().cancelTask(taskId);
- // messageing the players
- if(logging == true) mineLog(gameStartTime + " - The game has stopped at : " + getDateTime());
- if(logging == true) mineLog("-------------------------");
- error((Player)sender, ChatColor.RED + "The game has been stop ! =(", true);
- start = false;
- return true;
- }
- // the game is not started
- error((Player)sender, ChatColor.RED + "The game isn't started !", false);
- return true;
- }
- return true;
- }
- // unknown command
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement