Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.Camer047;
- import java.util.ArrayList;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.Chest;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- public class DefenceClass extends JavaPlugin {
- @Override
- public void onEnable() {
- new ListenerClass(this);
- this.getConfig().addDefault("timer", 5);
- this.getConfig().addDefault("Chest1X", 0);
- this.getConfig().addDefault("Chest1Y", 0);
- this.getConfig().addDefault("Chest1Z", 0);
- this.getConfig().addDefault("Chest2X", 0);
- this.getConfig().addDefault("Chest2Y", 0);
- this.getConfig().addDefault("Chest2Z", 0);
- this.getConfig().addDefault("Chest3X", 0);
- this.getConfig().addDefault("Chest3Y", 0);
- this.getConfig().addDefault("Chest3Z", 0);
- this.getConfig().options().copyDefaults(true);
- //////////
- //ITEMS///
- //////////
- //Declare Variable "Chest Item"
- ItemStack chestItem1 = new ItemStack(Material.DIAMOND_SWORD, 1);
- ItemMeta meta = chestItem1.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item One!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.BLUE + "Diamond Sword");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem1.setItemMeta(meta);
- //Declare Variable "Chest Item"
- ItemStack chestItem1 = new ItemStack(Material.WEB, 1);
- ItemMeta meta = chestItem1.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item ZERO D:!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem1.setItemMeta(meta);
- }
- @Override
- public void onDisable() {
- saveConfig();
- }
- public int time = getConfig().getInt("timer");
- public int chestnumber = 0;
- public boolean onCommand(CommandSender sender, Command cmd, String label,
- String[] args) {
- final Player player = (Player) sender;
- final World world = player.getWorld();
- if (cmd.getName().equalsIgnoreCase("timer")) {
- player.sendMessage("DEFENCE");
- player.sendMessage("By Camer047");
- if (args.length == 1 && args[0].equalsIgnoreCase("start")) {
- this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- public void run() {
- if (time != -1) {
- if (time != 0) {
- Bukkit.getServer().broadcastMessage("" + time);
- time --;
- } else {
- //TEMP
- //Create Random function
- Random random = new Random();
- int spawncords = 4;
- final int spawncordsfinal = random.nextInt(spawncords);
- time = getConfig().getInt("timer");
- int chestcontents = 4;
- final int chestcontentsf = random.nextInt(chestcontents);
- if (spawncordsfinal == 0) {
- chestnumber = 0;
- inv.addItem(chestItem1);
- }}
- if (spawncordsfinal == 1) {
- chestnumber = 1;
- //Set as block: Chest
- Block block = world.getBlockAt(getConfig().getInt("Chest1X"), getConfig().getInt("Chest1Y"), getConfig().getInt("Chest1Z"));
- block.setType(Material.CHEST);
- Chest chest = (Chest) block.getState();
- if (block.getState() instanceof Chest) {
- Inventory inv = chest.getInventory();
- if (chestcontentsf == 1) {
- //Declare Variable "Chest Item"
- ItemStack chestItem1 = new ItemStack(Material.DIAMOND_SWORD, 1);
- ItemMeta meta = chestItem1.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item One!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem1.setItemMeta(meta);
- inv.addItem(chestItem1);
- }
- if (chestcontentsf == 2) {
- //Declare Variable "Chest Item2"
- ItemStack chestItem2 = new ItemStack(Material.IRON_AXE, 1);
- ItemMeta meta = chestItem2.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test item two!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Iron A$$");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem2.setItemMeta(meta);
- inv.addItem(chestItem2);
- }
- if (chestcontentsf == 3) {
- //Declare Variable "Chest Item 3"
- ItemStack chestItem3 = new ItemStack(Material.IRON_SWORD, 1);
- ItemMeta meta = chestItem3.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Chest three!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Mystery Item o_0");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem3.setItemMeta(meta);
- inv.addItem(chestItem3);
- }
- }}
- if (spawncordsfinal == 2) {
- chestnumber = 2;
- //Set as block: Chest
- Block block = world.getBlockAt(getConfig().getInt("Chest2X"), getConfig().getInt("Chest2Y"), getConfig().getInt("Chest2Z"));
- block.setType(Material.CHEST);
- Chest chest = (Chest) block.getState();
- if (block.getState() instanceof Chest) {
- Inventory inv = chest.getInventory();
- if (chestcontentsf == 1) {
- //Declare Variable "Chest Item"
- ItemStack chestItem1 = new ItemStack(Material.DIAMOND_SWORD, 1);
- ItemMeta meta = chestItem1.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item One!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem1.setItemMeta(meta);
- inv.addItem(chestItem1);
- }
- if (chestcontentsf == 2) {
- //Declare Variable "Chest Item2"
- ItemStack chestItem2 = new ItemStack(Material.IRON_AXE, 1);
- ItemMeta meta = chestItem2.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test item two!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Iron A$$");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem2.setItemMeta(meta);
- inv.addItem(chestItem2);
- }
- if (chestcontentsf == 3) {
- //Declare Variable "Chest Item 3"
- ItemStack chestItem3 = new ItemStack(Material.IRON_SWORD, 1);
- ItemMeta meta = chestItem3.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Chest three!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Mystery Item o_0");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem3.setItemMeta(meta);
- inv.addItem(chestItem3);
- }
- }}
- if (spawncordsfinal == 3) {
- chestnumber = 3;
- //Set as block: Chest
- Block block = world.getBlockAt(getConfig().getInt("Chest3X"), getConfig().getInt("Chest3Y"), getConfig().getInt("Chest3Z"));
- block.setType(Material.CHEST);
- Chest chest = (Chest) block.getState();
- if (block.getState() instanceof Chest) {
- Inventory inv = chest.getInventory();
- if (chestcontentsf == 1) {
- //Declare Variable "Chest Item"
- ItemStack chestItem1 = new ItemStack(Material.DIAMOND_SWORD, 1);
- ItemMeta meta = chestItem1.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item One!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem1.setItemMeta(meta);
- inv.addItem(chestItem1);
- }
- if (chestcontentsf == 2) {
- //Declare Variable "Chest Item2"
- ItemStack chestItem2 = new ItemStack(Material.IRON_AXE, 1);
- ItemMeta meta = chestItem2.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test item two!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Iron A$$");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem2.setItemMeta(meta);
- inv.addItem(chestItem2);
- }
- if (chestcontentsf == 3) {
- //Declare Variable "Chest Item 3"
- ItemStack chestItem3 = new ItemStack(Material.IRON_SWORD, 1);
- ItemMeta meta = chestItem3.getItemMeta();
- //Set Item Name
- meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Chest three!");
- //Set the item lore
- ArrayList <String> lore = new ArrayList <String>();
- lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "sexy stick yo");
- lore.add(ChatColor.WHITE + "Atleast this one works :/");
- meta.setLore(lore);
- chestItem3.setItemMeta(meta);
- inv.addItem(chestItem3);
- }
- }
- }
- Bukkit.broadcastMessage("Chest " + chestnumber + " Spawned"); }
- }
- }
- }, 0, 20L);
- }
- }
- return true; }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement