Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kmccmk9.ZombieSiege;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.Properties;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Server;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Creature;
- import org.bukkit.entity.CreatureType;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scoreboard.DisplaySlot;
- import org.bukkit.scoreboard.Objective;
- import org.bukkit.scoreboard.Scoreboard;
- import org.bukkit.scoreboard.ScoreboardManager;
- import org.bukkit.scoreboard.Team;
- @SuppressWarnings({ "deprecation", "deprecation" })
- public class ZombieSiege extends JavaPlugin {
- //Global Variables
- Server server;
- static String mainDirectory = "plugins/ZombieSiege"; //sets the main directory for easy reference
- static File settings = new File(mainDirectory + File.separator + "plugin.settings"); //the file separator is the / sign, this will create a new Zones.dat files in the mainDirectory variable listed above, if no Zones directory exists then it will automatically be made along with the file.
- static Properties settingsproperty = new Properties(); //creates a new properties file
- Location tower1=new Location(null,5.0,5.0,5.0);
- Location tower2=new Location(null,5.0,5.0,5.0);
- Location tower3=new Location(null,5.0,5.0,5.0);
- Location tower4=new Location(null,5.0,5.0,5.0);
- Location tower5=new Location(null,5.0,5.0,5.0);
- double tower1x=5;
- double tower2x=5;
- double tower3x=5;
- double tower4x=5;
- double tower5x=5;
- double tower1y=5;
- double tower2y=5;
- double tower3y=5;
- double tower4y=5;
- double tower5y=5;
- double tower1z=5;
- double tower2z=5;
- double tower3z=5;
- double tower4z=5;
- double tower5z=5;
- Location tower = null;
- Entity chicken;
- double x,y,z;
- double areaRadius = 20; //Or any radius you want
- double minRadius = 10; // This would give me a radius between 500 and 1000
- double t = Math.random() * Math.PI;
- double radius = Math.random()*(areaRadius - minRadius) + minRadius;
- ScoreboardManager manager;
- Team team;
- Objective objective;
- Scoreboard board;
- //Enable
- public void onEnable() {
- server = this.getServer();
- manager = Bukkit.getScoreboardManager();
- board = manager.getNewScoreboard();
- team = board.registerNewTeam("Defenders:");
- objective = board.registerNewObjective("zombies", "totalKillCount");
- objective.setDisplaySlot(DisplaySlot.SIDEBAR);
- objective.setDisplayName("Zombies:");
- PluginDescriptionFile pdfFile = this.getDescription();
- System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
- new File(mainDirectory).mkdir(); //makes the Zones directory/folder in the plugins directory
- if(!settings.exists()){ //Checks to see if the zones file exists, defined above, if it doesn't exist then it will do the following. the ! turns the whole statement around, checking that the file doesn't exist instead of if it exists.
- try { //try catch clause explained below in tutorial
- settings.createNewFile(); //creates the file zones.dat
- FileOutputStream out = new FileOutputStream(settings); //creates a new output steam needed to write to the file
- settingsproperty.put("tower1x", "0"); //put the property ZoneCount with a value of 0 into the properties file, this will show up as ZoneCount=0 in the properties file.
- settingsproperty.put("tower1y", "0");
- settingsproperty.put("tower1z", "0");
- settingsproperty.put("tower2x", "0");
- settingsproperty.put("tower2y", "0");
- settingsproperty.put("tower2z", "0");
- settingsproperty.put("tower3x", "0");
- settingsproperty.put("tower3y", "0");
- settingsproperty.put("tower3z", "0");
- settingsproperty.put("tower4x", "0");
- settingsproperty.put("tower4y", "0");
- settingsproperty.put("tower4z", "0");
- settingsproperty.put("tower5x", "0");
- settingsproperty.put("tower5y", "0");
- settingsproperty.put("tower5z", "0");
- settingsproperty.store(out, "Feel free to edit this config!"); //You need this line! It stores what you just put into the file and adds a comment.
- out.flush(); //Explained below in tutorial
- out.close(); //Closes the output stream as it is not needed anymore.
- } catch (IOException ex) {
- ex.printStackTrace(); //explained below.
- }
- } else {
- settingsLoad();
- }
- }
- //Disable
- public void onDisable() {
- PluginDescriptionFile pdfFile = this.getDescription();
- System.out.println( pdfFile.getName() + " is disabled!" );
- }
- //ReadFile
- public void settingsLoad() {
- try {
- FileInputStream in = new FileInputStream(settings);
- settingsproperty.load(in);
- tower1x = Double.valueOf(settingsproperty.getProperty("tower1x"));
- tower2x = Double.valueOf(settingsproperty.getProperty("tower2x"));
- tower3x = Double.valueOf(settingsproperty.getProperty("tower3x"));
- tower4x = Double.valueOf(settingsproperty.getProperty("tower4x"));
- tower5x = Double.valueOf(settingsproperty.getProperty("tower5x"));
- tower1y = Double.valueOf(settingsproperty.getProperty("tower1y"));
- tower2y = Double.valueOf(settingsproperty.getProperty("tower2y"));
- tower3y = Double.valueOf(settingsproperty.getProperty("tower3y"));
- tower4y = Double.valueOf(settingsproperty.getProperty("tower4y"));
- tower5y = Double.valueOf(settingsproperty.getProperty("tower5y"));
- tower1z = Double.valueOf(settingsproperty.getProperty("tower1z"));
- tower2z = Double.valueOf(settingsproperty.getProperty("tower2z"));
- tower3z = Double.valueOf(settingsproperty.getProperty("tower3z"));
- tower4z = Double.valueOf(settingsproperty.getProperty("tower4z"));
- tower5z = Double.valueOf(settingsproperty.getProperty("tower5z"));
- tower1.setX(tower1x);
- tower1.setY(tower1y);
- tower1.setZ(tower1z);
- tower2.setX(tower2x);
- tower2.setY(tower2y);
- tower2.setZ(tower2z);
- tower3.setX(tower3x);
- tower3.setY(tower3y);
- tower3.setZ(tower3z);
- tower4.setX(tower4x);
- tower4.setY(tower4y);
- tower4.setZ(tower4z);
- tower5.setX(tower5x);
- tower5.setY(tower5y);
- tower5.setZ(tower5z);
- in.close();
- } catch (IOException ex)
- {
- ex.printStackTrace();
- }
- }
- public boolean onCommand(final CommandSender sender, Command command, String commandLabel, String[] args) {
- Player player = (Player) sender;
- if (commandLabel.equalsIgnoreCase("zs")) {
- if (args.length == 0) {
- sender.sendMessage(ChatColor.BLUE + "ZombieSiege Help:\n----------------\n1. /zs start - Starts the siege!\n2. /zs stop - Stops teh siege.\n3. /zs set1 - Sets block you are looking at as tower 1 location.\n4. /zs set2 - Sets block you are looking at as tower 2 location.\n5. /zs set3 - Sets the block you are looking at as tower 3 location.\n6. /zs set4 - Sets the block you are looking at as tower 4.\n7. /zs set5 - Sets the block you are looking at as tower 5.");
- }
- else if (args.length == 1) {
- if (args[0].equalsIgnoreCase("set1")) {
- Block b = player.getTargetBlock(null,200);
- tower1.setX(b.getX());
- tower1.setY(b.getY());
- tower1.setZ(b.getZ());
- settingsproperty.setProperty("tower1x", String.valueOf(b.getX()));
- settingsproperty.setProperty("tower1y", String.valueOf(b.getY()));
- settingsproperty.setProperty("tower1z", String.valueOf(b.getZ()));
- player.sendMessage("Tower 1 has been set.");
- }
- else if (args[0].equalsIgnoreCase("join")) {
- team.addPlayer(player);
- team.setPrefix("ZS-");
- team.setAllowFriendlyFire(false);
- player.setScoreboard(board);
- player.sendMessage(ChatColor.YELLOW + "You have been adde to the team!");
- }
- else if (args[0].equalsIgnoreCase("set2")) {
- Block b = player.getTargetBlock(null,200);
- tower2.setX(b.getX());
- tower2.setY(b.getY());
- tower2.setZ(b.getZ());
- settingsproperty.setProperty("tower2x", String.valueOf(b.getX()));
- settingsproperty.setProperty("tower2y", String.valueOf(b.getY()));
- settingsproperty.setProperty("tower2z", String.valueOf(b.getZ()));
- player.sendMessage("Tower 2 has been set.");
- }
- else if (args[0].equalsIgnoreCase("set3")) {
- Block b = player.getTargetBlock(null,200);
- tower3.setX(b.getX());
- tower3.setY(b.getY());
- tower3.setZ(b.getZ());
- settingsproperty.setProperty("tower3x", String.valueOf(b.getX()));
- settingsproperty.setProperty("tower3y", String.valueOf(b.getY()));
- settingsproperty.setProperty("tower3z", String.valueOf(b.getZ()));
- player.sendMessage("Tower 3 has been set.");
- }
- else if (args[0].equalsIgnoreCase("set4")) {
- Block b = player.getTargetBlock(null,200);
- tower4.setX(b.getX());
- tower4.setY(b.getY());
- tower4.setZ(b.getZ());
- settingsproperty.setProperty("tower4x", String.valueOf(b.getX()));
- settingsproperty.setProperty("tower4y", String.valueOf(b.getY()));
- settingsproperty.setProperty("tower4z", String.valueOf(b.getZ()));
- player.sendMessage("Tower 4 has been set.");
- }
- else if (args[0].equalsIgnoreCase("set5")) {
- Block b = player.getTargetBlock(null,200);
- tower5.setX(b.getX());
- tower5.setY(b.getY());
- tower5.setZ(b.getZ());
- settingsproperty.setProperty("tower5x", String.valueOf(b.getX()));
- settingsproperty.setProperty("tower5y", String.valueOf(b.getY()));
- settingsproperty.setProperty("tower5z", String.valueOf(b.getZ()));
- player.sendMessage("Tower 5 has been set.");
- }
- else if (args[0].equalsIgnoreCase("start")) {
- for(Player online : Bukkit.getOnlinePlayers()){
- board.resetScores(online);
- }
- server.broadcastMessage("ZombieSiege will be starting!");
- //Generate Random Number
- Random rn = new Random();
- int i = rn.nextInt(5) + 1;
- server.broadcastMessage(ChatColor.YELLOW + "They are attacking tower #" + i);
- //Spawn mobs
- areaRadius = 15; //Or any radius you want
- minRadius = 10; // This would give me a radius between 500 and 1000
- t = Math.random() * Math.PI;
- radius = Math.random()*(areaRadius - minRadius) + minRadius;
- x = Math.cos(t) * radius;
- y = Math.sin(t) * radius;
- z = Math.cos(t) * radius;
- switch (i) {
- case 1: tower = tower1.clone();
- break;
- case 2: tower = tower2.clone();
- break;
- case 3: tower = tower3.clone();
- break;
- case 4: tower = tower4.clone();
- break;
- case 5: tower = tower5.clone();
- break;
- default: server.broadcastMessage("Something went wrong!");
- break;
- }
- final World world = player.getWorld();
- chicken = world.spawnEntity(tower, EntityType.CHICKEN);
- entityListener eListener = new entityListener(server, chicken);
- Bukkit.getServer().getPluginManager().registerEvents(eListener , this);
- server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- public void run() {
- Location to = tower;
- to.add(x, y, z); // Its just a matter of adding the x, y and z
- int i = 0;
- while (i <= 4) {
- Entity zombie = world.spawnEntity(to, EntityType.PIG_ZOMBIE);
- ((Creature) zombie).setTarget((LivingEntity) chicken);
- areaRadius = 15; //Or any radius you want
- minRadius = 10; // This would give me a radius between 500 and 1000
- t = Math.random() * Math.PI;
- radius = Math.random()*(areaRadius - minRadius) + minRadius;
- x = Math.cos(t) * radius;
- y = Math.sin(t) * radius;
- z = Math.cos(t) * radius;
- i++;
- }
- }
- }, 5 * 20L);
- }
- else
- player.sendMessage(ChatColor.RED + "Arguments mismatch. Use the /zs command to see all options");
- }
- else
- sender.sendMessage(ChatColor.RED + "Arguments mismatch. Use the /zs command to see all options");
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement