Help - Multiple Classes

Discussion in 'Plugin Development' started by Charliechumbuck, Apr 21, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Charliechumbuck

    Whenever I run my plugin, it says I have an error because one of the subclasses is not connected to the main class correctly! Here's my code: (Help is appreciated, if you didn't already know that :))

    Main Class:

    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    public class Main extends JavaPlugin implements Listener {
    Logger mypluginlogger = Bukkit.getLogger();

    //add houses in the lobby that costs gems as an incentive to play games,
    //and have the players buy their building materials to do so. Each
    //player can only have one plot of land to do so.

    int sx=1812;
    int sy=21;
    int sz=-1242;

    Player player;

    public void onEnable(){
    getServer().getPluginManager().registerEvents(this,this);

    @SuppressWarnings("unused")
    PluginManager pm = getServer().getPluginManager();
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e){
    Player p = e.getPlayer();
    e.setJoinMessage(ChatColor.LIGHT_PURPLE+"Hey, "+ChatColor.GREEN+p.getName()+ChatColor.LIGHT_PURPLE+" has joined the server!");
    p.sendMessage(ChatColor.AQUA+"Welcome to the server, "+p.getName());
    p.teleport(new Location(p.getWorld(),sx,sy,sz));
    p.setGameMode(GameMode.ADVENTURE);
    p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 5, 255));
    p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 5, 255));
    p.getInventory().clear();
    }

    public void onDisable(){

    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
    PlayerInventory pi = player.getInventory();
    if(sender instanceof Player){
    if(cmd.getLabel().equalsIgnoreCase("digdug")){
    @SuppressWarnings("unused")
    DigDug digdug = new DigDug(player);
    return true;
    }
    if(cmd.getLabel().equalsIgnoreCase("lobby")){
    player.teleport(new Location(player.getWorld(),sx,sy,sz));
    pi.clear();
    player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 255, 255));
    player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 255, 255));
    return true;
    }
    }

    return false;
    }
    }

    ==================================================
    Sub Class:

    import java.util.Random;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.DyeColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.CreatureSpawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class DigDug implements Listener{

    Main plugin;
    int gems;
    int roundnum;
    Player player;
    int round;
    double x = 1807.5;
    int y = 36;
    int z = -1708;

    public DigDug(Player player){
    super();
    this.player = player;
    player.sendMessage(ChatColor.GREEN+"Welcome to Dig Dug!");
    this.plugin = (Main) Bukkit.getServer().getPluginManager().getPlugin("YourPluginNameHere");
    DigDugStart(player);
    }

    @SuppressWarnings("deprecation")
    public void DigDugStart(Player player){
    PlayerInventory pi = player.getInventory();
    gems = 0;
    ItemStack pick = new ItemStack(Material.IRON_PICKAXE,1);
    pick.addUnsafeEnchantment(Enchantment.DURABILITY, 9001);
    pick.addUnsafeEnchantment(Enchantment.DIG_SPEED, 7);
    ItemMeta pickmeta = pick.getItemMeta();
    pickmeta.setDisplayName(ChatColor.GREEN+""+ChatColor.BOLD+"Dig Dug Pickaxe!");
    pick.setItemMeta(pickmeta);
    ItemStack bombs = new ItemStack(Material.TNT,3);
    ItemMeta bombmeta = bombs.getItemMeta();
    bombmeta.setDisplayName(ChatColor.BLUE+""+ChatColor.BOLD+"BOMBS!");
    bombs.setItemMeta(bombmeta);
    pi.setItem(0,pick);
    pi.setItem(1,bombs);
    player.updateInventory();
    player.teleport(new Location(player.getWorld(),x,y,z));
    player.setAllowFlight(true);
    player.setFlySpeed((float) .05);
    player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION,3,1000000));
    player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION,3,1000000));
    round = 0;
    NextRound(player);
    }

    @SuppressWarnings("deprecation")
    public void NextRound(Player player){
    round = round + 1;
    player.sendMessage(ChatColor.BLUE+"Are you ready for round "+ChatColor.LIGHT_PURPLE+round+ChatColor.BLUE+"?");
    for(int bx=1807;bx<1835;bx++){
    for(int by = 35;by>28;by--){
    int bz = -1708;
    Location yellowclay = new Location(player.getWorld(),bx,by,bz);
    yellowclay.getBlock().setType(Material.STAINED_CLAY);
    yellowclay.getBlock().setData(DyeColor.YELLOW.getData());
    }
    }
    for(int bx=1807;bx<1835;bx++){
    for(int by = 28;by>21;by--){
    int bz = -1708;
    Location yellowclay = new Location(player.getWorld(),bx,by,bz);
    yellowclay.getBlock().setType(Material.STAINED_CLAY);
    yellowclay.getBlock().setData(DyeColor.ORANGE.getData());
    }
    }
    for(int bx=1807;bx<1835;bx++){
    for(int by = 21;by>14;by--){
    int bz = -1708;
    Location yellowclay = new Location(player.getWorld(),bx,by,bz);
    yellowclay.getBlock().setType(Material.STAINED_CLAY);
    yellowclay.getBlock().setData(DyeColor.RED.getData());
    }
    }
    for(int bx=1807;bx<1835;bx++){
    for(int by = 14;by>7;by--){
    int bz = -1708;
    Location yellowclay = new Location(player.getWorld(),bx,by,bz);
    yellowclay.getBlock().setType(Material.STAINED_CLAY);
    yellowclay.getBlock().setData(DyeColor.BROWN.getData());
    }
    }
    player.teleport(new Location(player.getWorld(),x,y,z));
    Random randx = new Random();
    Random randy = new Random();
    double mx = 1822.5;
    double my = 36;
    double mz = -1707.5;
    switch(this.round){
    case 1:
    gems = 5;
    for(int randstr=0;randstr<5;randstr++){
    int randnumx = 1+randx.nextInt(27);
    int randnumy = 1+randy.nextInt(27);
    Location blockloc = new Location(player.getWorld(),x+randnumx,y-randnumy+1,z);
    blockloc.getBlock().setType(Material.EMERALD_BLOCK);
    }
    Location mobloc = new Location(player.getWorld(),mx,my,mz);
    Entity ent = player.getWorld().spawnEntity(mobloc,EntityType.ZOMBIE);
    ((LivingEntity) ent).setCustomName(ChatColor.RED+""+ChatColor.BOLD+"Evil Miner");
    ((LivingEntity) ent).setCustomNameVisible(true);
    break;
    case 2:
    gems = 7;
    for(int randstr=0;randstr<7;randstr++){
    int randnumx = 1+randx.nextInt(27);
    int randnumy = 1+randy.nextInt(27);
    Location blockloc = new Location(player.getWorld(),x+randnumx,y-randnumy+1,z);
    blockloc.getBlock().setType(Material.EMERALD_BLOCK);
    }
    break;
    case 3:
    gems = 9;
    for(int randstr=0;randstr<9;randstr++){
    int randnumx = 1+randx.nextInt(27);
    int randnumy = 1+randy.nextInt(27);
    Location blockloc = new Location(player.getWorld(),x+randnumx,y-randnumy+1,z);
    blockloc.getBlock().setType(Material.EMERALD_BLOCK);
    }
    break;
    case 4:
    gems = 11;
    for(int randstr=0;randstr<11;randstr++){
    int randnumx = 1+randx.nextInt(27);
    int randnumy = 1+randy.nextInt(27);
    Location blockloc = new Location(player.getWorld(),x+randnumx,y-randnumy+1,z);
    blockloc.getBlock().setType(Material.EMERALD_BLOCK);
    }
    break;
    }
    }

    public void RoundFinish(Player player){
    player.sendMessage(ChatColor.GREEN+"Great job! Round "+ChatColor.GOLD+round+ChatColor.GREEN+" is finished!");
    NextRound(player);
    }

    @EventHandler
    public void spawnEnemies(CreatureSpawnEvent e){
    }

    @EventHandler
    public void onBlockPlace(BlockPlaceEvent e){
    if(e.getBlock().getType()==Material.TNT){
    Location location = e.getBlock().getLocation();
    int tx = e.getBlock().getX();
    int ty = e.getBlock().getY();
    int tz = e.getBlock().getZ();
    Location blockloc1 = new Location(e.getBlock().getWorld(),tx,ty+1,tz);
    Location blockloc2 = new Location(e.getBlock().getWorld(),tx,ty-1,tz);
    Location blockloc3 = new Location(e.getBlock().getWorld(),tx+1,ty,tz);
    Location blockloc4 = new Location(e.getBlock().getWorld(),tx-1,ty,tz);
    Location blockloc5 = new Location(e.getBlock().getWorld(),tx-1,ty-1,tz);
    Location blockloc6 = new Location(e.getBlock().getWorld(),tx+1,ty+1,tz);
    Location blockloc7 = new Location(e.getBlock().getWorld(),tx-1,ty+1,tz);
    Location blockloc8 = new Location(e.getBlock().getWorld(),tx+1,ty-1,tz);
    Block blockloctnt1 = blockloc1.getBlock();
    Block blockloctnt2 = blockloc2.getBlock();
    Block blockloctnt3 = blockloc3.getBlock();
    if(blockloctnt1.getType()!=Material.WOOL){
    blockloc1.getBlock().setType(Material.AIR);
    }
    if(blockloctnt2.getType()!=Material.GLASS){
    blockloc2.getBlock().setType(Material.AIR);
    }
    if(blockloctnt3.getType()!=Material.GLASS){
    blockloc3.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()-1,location.getY(),location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc4.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()-1,location.getY()-1,location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc5.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()+1,location.getY()+1,location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc6.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()-1,location.getY()+1,location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc7.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()+1,location.getY()-1,location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc8.getBlock().setType(Material.AIR);
    }

    if(new Location(location.getWorld(),location.getX(),location.getY(),location.getZ()).getBlock().getType()!=Material.GLASS){
    location.getBlock().setType(Material.AIR);
    }
    }
    }

    @SuppressWarnings("deprecation")
    @EventHandler
    public void onBlockBreak(BlockBreakEvent events,Entity e){
    Block broken = events.getBlock();
    Player player = events.getPlayer();
    if(player.getGameMode()!=GameMode.CREATIVE){
    if(broken.getType()==Material.STAINED_CLAY&&broken.getData()==(DyeColor.YELLOW.getData())){
    events.setCancelled(false);
    }else if(broken.getType()==Material.STAINED_CLAY&&broken.getData()==(DyeColor.ORANGE.getData())){
    events.setCancelled(false);
    }else if(broken.getType()==Material.STAINED_CLAY&&broken.getData()==(DyeColor.RED.getData())){
    events.setCancelled(false);
    }else if(broken.getType()==Material.STAINED_CLAY&&broken.getData()==(DyeColor.BROWN.getData())){
    events.setCancelled(false);
    }else if(broken.getType()==Material.EMERALD_BLOCK){
    events.setCancelled(false);
    gems = gems - 1;
    player.sendMessage(ChatColor.AQUA+"There are only "+ChatColor.GOLD+gems+" gems left!");
    if(gems == 0){
    RoundFinish(player);
    }
    }else{
    events.setCancelled(true);
    }
    }
    }
    }


    And, yes, I did have packages.
     
  2. Offline

    MrInspector

    You're not registering the listener of your other class. ;)
     
  3. Offline

    Charliechumbuck

    Explain how to do so and what you mean?
    (I may not reply until tomorrow)
     
  4. Offline

    Maurdekye

    Charliechumbuck Please use the built in 'code' formatting for posting code. And to answer your question, you have to replace this;
    Code:java
    1. getServer().getPluginManager().registerEvents(this,this);

    with this;
    Code:java
    1. getServer().getPluginManager().registerEvents(new DigDug(), this);
     
    Charliechumbuck likes this.
  5. Offline

    Charliechumbuck

    Maurdekye
    I tried that and it works! For the most part...but the problem is that the blockbreakevent isn't working!
     
  6. Offline

    Rocoty

    Charliechumbuck please get the terms right. A subclass is a class that extends another class. We say that it is a subclass of that other class. What you have there is a regular separate standalone class.

    (One may argue that it is a subclass of Object. But hey, that applies to all classes.)
     
  7. Offline

    Charliechumbuck

    Okay, let me say it this way: The DigDug class is supposed to be called on by the main class when the player puts in a command, and I will do that for all the other mini-games that I'll add. However, I still don't know how to fix the block breaking problem! Can you help me Rocoty?

    Update: none of the other events work either :mad:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  8. Offline

    TGRHavoc

    Charliechumbuck
    Have you registered the other events?:
    Code:java
    1. getServer().getPluginManager().registerEvents(new ClassName(), this);
     
  9. Offline

    Maurdekye

    Charliechumbuck Could you at least repost your code / edit your original post to include the proper formatting? It's really hard to read it and help you as it is.
     
  10. Offline

    Charliechumbuck

    Maurdekye

    Here's meh codin' again (still got teh sutherrn acceant :)):

    Main Class:

    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    public class Main extends JavaPlugin implements Listener {
    Logger mypluginlogger = Bukkit.getLogger();

    //add houses in the lobby that costs gems as an incentive to play games,
    //and have the players buy their building materials to do so. Each
    //player can only have one plot of land to do so.

    int sx=1812;
    int sy=21;
    int sz=-1242;

    Player player;

    public void onEnable(){
    getServer().getPluginManager().registerEvents(new DigDug(player), this);

    @SuppressWarnings("unused")
    PluginManager pm = getServer().getPluginManager();
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e){
    Player p = e.getPlayer();
    e.setJoinMessage(ChatColor.LIGHT_PURPLE+"Hey, "+ChatColor.GREEN+p.getName()+ChatColor.LIGHT_PURPLE+" has joined the server!");
    p.sendMessage(ChatColor.AQUA+"Welcome to the server, "+p.getName());
    p.teleport(new Location(p.getWorld(),sx,sy,sz));
    p.setGameMode(GameMode.ADVENTURE);
    p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 5, 255));
    p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 5, 255));
    p.getInventory().clear();
    }

    public void onDisable(){

    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
    PlayerInventory pi = player.getInventory();
    if(sender instanceof Player){
    if(cmd.getLabel().equalsIgnoreCase("digdug")){
    @SuppressWarnings("unused")
    DigDug digdug = new DigDug(player);
    return true;
    }
    if(cmd.getLabel().equalsIgnoreCase("lobby")){
    player.teleport(new Location(player.getWorld(),sx,sy,sz));
    pi.clear();
    player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 255, 255));
    player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 255, 255));
    return true;
    }
    }

    return false;
    }
    }

    =====================================================================================

    DigDug Class:

    import java.util.Random;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.DyeColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.CreatureSpawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class DigDug implements Listener{

    Main plugin;
    int gems;
    int roundnum;
    Player player;
    int round;
    double x = 1807.5;
    int y = 36;
    int z = -1708;

    public DigDug(Player player){
    super();
    this.player = player;
    player.sendMessage(ChatColor.GREEN+"Welcome to Dig Dug!");
    this.plugin = (Main) Bukkit.getServer().getPluginManager().getPlugin("YourPluginNameHere");
    DigDugStart(player);
    }

    @SuppressWarnings("deprecation")
    public void DigDugStart(Player player){
    PlayerInventory pi = player.getInventory();
    gems = 0;
    ItemStack pick = new ItemStack(Material.IRON_PICKAXE,1);
    pick.addUnsafeEnchantment(Enchantment.DURABILITY, 9001);
    pick.addUnsafeEnchantment(Enchantment.DIG_SPEED, 7);
    ItemMeta pickmeta = pick.getItemMeta();
    pickmeta.setDisplayName(ChatColor.GREEN+""+ChatColor.BOLD+"Dig Dug Pickaxe!");
    pick.setItemMeta(pickmeta);
    ItemStack bombs = new ItemStack(Material.TNT,3);
    ItemMeta bombmeta = bombs.getItemMeta();
    bombmeta.setDisplayName(ChatColor.BLUE+""+ChatColor.BOLD+"BOMBS!");
    bombs.setItemMeta(bombmeta);
    pi.setItem(0,pick);
    pi.setItem(1,bombs);
    player.updateInventory();
    player.teleport(new Location(player.getWorld(),x,y,z));
    player.setAllowFlight(true);
    player.setFlySpeed((float) .05);
    player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION,3,1000000));
    player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION,3,1000000));
    round = 0;
    NextRound(player);
    }

    @SuppressWarnings("deprecation")
    public void NextRound(Player player){
    round = round + 1;
    player.sendMessage(ChatColor.BLUE+"Are you ready for round "+ChatColor.LIGHT_PURPLE+round+ChatColor.BLUE+"?");
    for(int bx=1807;bx<1835;bx++){
    for(int by = 35;by>28;by--){
    int bz = -1708;
    Location yellowclay = new Location(player.getWorld(),bx,by,bz);
    yellowclay.getBlock().setType(Material.STAINED_CLAY);
    yellowclay.getBlock().setData(DyeColor.YELLOW.getData());
    }
    }
    for(int bx=1807;bx<1835;bx++){
    for(int by = 28;by>21;by--){
    int bz = -1708;
    Location yellowclay = new Location(player.getWorld(),bx,by,bz);
    yellowclay.getBlock().setType(Material.STAINED_CLAY);
    yellowclay.getBlock().setData(DyeColor.ORANGE.getData());
    }
    }
    for(int bx=1807;bx<1835;bx++){
    for(int by = 21;by>14;by--){
    int bz = -1708;
    Location yellowclay = new Location(player.getWorld(),bx,by,bz);
    yellowclay.getBlock().setType(Material.STAINED_CLAY);
    yellowclay.getBlock().setData(DyeColor.RED.getData());
    }
    }
    for(int bx=1807;bx<1835;bx++){
    for(int by = 14;by>7;by--){
    int bz = -1708;
    Location yellowclay = new Location(player.getWorld(),bx,by,bz);
    yellowclay.getBlock().setType(Material.STAINED_CLAY);
    yellowclay.getBlock().setData(DyeColor.BROWN.getData());
    }
    }
    player.teleport(new Location(player.getWorld(),x,y,z));
    Random randx = new Random();
    Random randy = new Random();
    double mx = 1822.5;
    double my = 36;
    double mz = -1707.5;
    switch(this.round){
    case 1:
    gems = 5;
    for(int randstr=0;randstr<5;randstr++){
    int randnumx = 1+randx.nextInt(27);
    int randnumy = 1+randy.nextInt(27);
    Location blockloc = new Location(player.getWorld(),x+randnumx,y-randnumy+1,z);
    blockloc.getBlock().setType(Material.EMERALD_BLOCK);
    }
    Location mobloc = new Location(player.getWorld(),mx,my,mz);
    Entity ent = player.getWorld().spawnEntity(mobloc,EntityType.ZOMBIE);
    ((LivingEntity) ent).setCustomName(ChatColor.RED+""+ChatColor.BOLD+"Evil Miner");
    ((LivingEntity) ent).setCustomNameVisible(true);
    break;
    case 2:
    gems = 7;
    for(int randstr=0;randstr<7;randstr++){
    int randnumx = 1+randx.nextInt(27);
    int randnumy = 1+randy.nextInt(27);
    Location blockloc = new Location(player.getWorld(),x+randnumx,y-randnumy+1,z);
    blockloc.getBlock().setType(Material.EMERALD_BLOCK);
    }
    break;
    case 3:
    gems = 9;
    for(int randstr=0;randstr<9;randstr++){
    int randnumx = 1+randx.nextInt(27);
    int randnumy = 1+randy.nextInt(27);
    Location blockloc = new Location(player.getWorld(),x+randnumx,y-randnumy+1,z);
    blockloc.getBlock().setType(Material.EMERALD_BLOCK);
    }
    break;
    case 4:
    gems = 11;
    for(int randstr=0;randstr<11;randstr++){
    int randnumx = 1+randx.nextInt(27);
    int randnumy = 1+randy.nextInt(27);
    Location blockloc = new Location(player.getWorld(),x+randnumx,y-randnumy+1,z);
    blockloc.getBlock().setType(Material.EMERALD_BLOCK);
    }
    break;
    }
    }

    public void RoundFinish(Player player){
    player.sendMessage(ChatColor.GREEN+"Great job! Round "+ChatColor.GOLD+round+ChatColor.GREEN+" is finished!");
    NextRound(player);
    }

    @EventHandler
    public void spawnEnemies(CreatureSpawnEvent e){
    }

    @EventHandler(priority=EventPriority.HIGHEST)
    public void onBlockPlace(BlockPlaceEvent e){
    if(e.getBlock().getType()==Material.TNT){
    Location location = e.getBlock().getLocation();
    int tx = e.getBlock().getX();
    int ty = e.getBlock().getY();
    int tz = e.getBlock().getZ();
    Location blockloc1 = new Location(e.getBlock().getWorld(),tx,ty+1,tz);
    Location blockloc2 = new Location(e.getBlock().getWorld(),tx,ty-1,tz);
    Location blockloc3 = new Location(e.getBlock().getWorld(),tx+1,ty,tz);
    Location blockloc4 = new Location(e.getBlock().getWorld(),tx-1,ty,tz);
    Location blockloc5 = new Location(e.getBlock().getWorld(),tx-1,ty-1,tz);
    Location blockloc6 = new Location(e.getBlock().getWorld(),tx+1,ty+1,tz);
    Location blockloc7 = new Location(e.getBlock().getWorld(),tx-1,ty+1,tz);
    Location blockloc8 = new Location(e.getBlock().getWorld(),tx+1,ty-1,tz);
    Block blockloctnt1 = blockloc1.getBlock();
    Block blockloctnt2 = blockloc2.getBlock();
    Block blockloctnt3 = blockloc3.getBlock();
    if(blockloctnt1.getType()!=Material.WOOL){
    blockloc1.getBlock().setType(Material.AIR);
    }
    if(blockloctnt2.getType()!=Material.GLASS){
    blockloc2.getBlock().setType(Material.AIR);
    }
    if(blockloctnt3.getType()!=Material.GLASS){
    blockloc3.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()-1,location.getY(),location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc4.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()-1,location.getY()-1,location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc5.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()+1,location.getY()+1,location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc6.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()-1,location.getY()+1,location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc7.getBlock().setType(Material.AIR);
    }
    if(new Location(location.getWorld(),location.getX()+1,location.getY()-1,location.getZ()).getBlock().getType()!=Material.GLASS){
    blockloc8.getBlock().setType(Material.AIR);
    }

    if(new Location(location.getWorld(),location.getX(),location.getY(),location.getZ()).getBlock().getType()!=Material.GLASS){
    location.getBlock().setType(Material.AIR);
    }
    }
    }

    @SuppressWarnings("deprecation")
    @EventHandler(priority=EventPriority.HIGHEST)
    public void onBlockBreak(BlockBreakEvent events){
    Block broken = events.getBlock();
    Player player = events.getPlayer();
    if(player.getGameMode()!=GameMode.CREATIVE){
    if(broken.getType()==Material.STAINED_CLAY&&broken.getData()==(DyeColor.YELLOW.getData())){
    events.setCancelled(false);
    }else if(broken.getType()==Material.STAINED_CLAY&&broken.getData()==(DyeColor.ORANGE.getData())){
    events.setCancelled(false);
    }else if(broken.getType()==Material.STAINED_CLAY&&broken.getData()==(DyeColor.RED.getData())){
    events.setCancelled(false);
    }else if(broken.getType()==Material.STAINED_CLAY&&broken.getData()==(DyeColor.BROWN.getData())){
    events.setCancelled(false);
    }else if(broken.getType()==Material.EMERALD_BLOCK){
    events.setCancelled(false);
    gems = gems - 1;
    player.sendMessage(ChatColor.AQUA+"There are only "+ChatColor.GOLD+gems+" gems left!");
    if(gems == 0){
    RoundFinish(player);
    }
    }else{
    events.setCancelled(true);
    }
    }
    }
    }
     
  11. Offline

    Konkz

    Please use the code tags, it's the { } # icon which is third from the end above text editor.
     
  12. Offline

    Charliechumbuck

    Oh. Can you help me still?
     
Thread Status:
Not open for further replies.

Share This Page