There is a Error in onplayerinteract event plugin. when i right click stone, error in bukkit.

Discussion in 'Plugin Development' started by majalllan, Jan 10, 2021.

  1. Offline

    majalllan

    @EventHandler
    public void PlayerInteract(PlayerInteractEvent event) {
    ItemStack item = event.getItem();
    Action action = event.getAction();
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    if (item == null) {
    return;

    }

    if (action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)) {
    if(item.getType().equals((Material.BOOK))) {
    SGUI.StatusGUI(player);
    //SGUI.SoloModeGUI(player);
    }
    else if(block.getType().equals((Material.SPRUCE_FENCE_GATE))) {
    if(GameStart.multitimemanage == 1 && GameStart.generator1 >= 0 && GameStart.generator1 < 10) {
    GameStart.generator1 = (float) (GameStart.generator1 + 0.25);
    player.playSound(player.getEyeLocation(), Sound.BLOCK_ANVIL_USE, 1, 2);
    player.sendMessage("발전기 수리율 : " + GameStart.generator1 + "% / 10 %" );

    }else if(GameStart.generator1 == 10) {
    GameStart.generator += 1;
    Bukkit.broadcastMessage("발전기 1개가 수리 완료되었습니다. ");
    Bukkit.broadcastMessage("[총 발전기 수리 현황] " + GameStart.generator +" / 4");
    GameStart.generator(player);
    GameStart.generator1 = -1;


    }
    }
    else if(block.getType().equals((Material.FENCE_GATE))) {
    if(GameStart.multitimemanage == 1 && GameStart.generator2 >= 0 && GameStart.generator2 < 10) {
    GameStart.generator2 = (float) (GameStart.generator2 + 0.25);
    player.playSound(player.getEyeLocation(), Sound.BLOCK_ANVIL_USE, 1, 2);
    player.sendMessage("발전기 수리율 : " + GameStart.generator2 + "% / 10 %" );
    }
    else if(GameStart.generator2 == 10) {
    GameStart.generator += 1;
    Bukkit.broadcastMessage("발전기 1개가 수리 완료되었습니다. ");
    Bukkit.broadcastMessage("[총 발전기 수리 현황] " + GameStart.generator +" / 4");
    GameStart.generator(player);

    GameStart.generator2 = -1;

    }
    }
    else if(block.getType().equals((Material.DARK_OAK_FENCE_GATE))) {
    if(GameStart.multitimemanage == 1 && GameStart.generator3 >= 0 && GameStart.generator3 < 10) {
    GameStart.generator3 = (float) (GameStart.generator3 + 0.25);
    player.playSound(player.getEyeLocation(), Sound.BLOCK_ANVIL_USE, 1, 2);
    player.sendMessage("발전기 수리율 : " + GameStart.generator3 + "% / 10 %" );
    }else if(GameStart.generator3 == 10) {
    GameStart.generator += 1;
    Bukkit.broadcastMessage("발전기 1개가 수리 완료되었습니다. ");
    Bukkit.broadcastMessage("[총 발전기 수리 현황] " + GameStart.generator +" / 4");
    GameStart.generator(player);

    GameStart.generator3 = -1;

    }
    }
    else if(block.getType().equals((Material.ACACIA_FENCE_GATE))) {
    if(GameStart.multitimemanage == 1 && GameStart.generator4 >= 0 && GameStart.generator4 < 10) {
    GameStart.generator4 = (float) (GameStart.generator4 + 0.25);
    player.playSound(player.getEyeLocation(), Sound.BLOCK_ANVIL_USE, 1, 2);
    player.sendMessage("발전기 수리율 : " + GameStart.generator4 + "% / 10 %" );
    }else if(GameStart.generator4 == 10) {
    GameStart.generator += 1;
    Bukkit.broadcastMessage("발전기 1개가 수리 완료되었습니다. ");
    Bukkit.broadcastMessage("[총 발전기 수리 현황] " + GameStart.generator +" / 4");
    GameStart.generator(player);

    GameStart.generator4 = -1;

    }
    }
    else if(block.getType().equals((Material.WOODEN_DOOR))) {
    if(GameStart.Jail[0] == -1 && GameStart.multitimemanage == 1 && GameStart.jail1 < 10) {
    GameStart.jail1 += 0.1;
    player.sendMessage(GameStart.jail1 + "% / 10 %");
    }else if(GameStart.jail1 == 10) {
    GameStart.Jail[0] = 0;
    Bukkit.broadcastMessage("감옥에 갇힌 도둑이 탈옥하였습니다.!");
    if(new Location(player.getWorld(), 233.3, 12, 110.6).getBlock().getType().equals((Material.REDSTONE_BLOCK))) {
    new Location(player.getWorld(), 233.3, 12, 110.6).getBlock().setType(Material.AIR);
    new Location(player.getWorld(), 232.3, 10, 110.6).getBlock().setType(Material.REDSTONE_BLOCK);

    return;
    }

    }
    }
    else if(block.getType().equals((Material.BIRCH_DOOR))) {
    if(GameStart.Jail[1] == -1 && GameStart.multitimemanage == 1 && GameStart.jail2 < 10) {
    GameStart.jail2 += 0.1;
    player.sendMessage(GameStart.jail2 + "% / 10 %");
    }else if(GameStart.jail2 == 10) {
    GameStart.Jail[1] = 0;
    Bukkit.broadcastMessage("감옥에 갇힌 도둑이 탈옥하였습니다.!");
    if(new Location(player.getWorld(), 233.3, 12, 116.6).getBlock().getType().equals((Material.REDSTONE_BLOCK))) {
    new Location(player.getWorld(), 233.3, 12, 116.6).getBlock().setType(Material.AIR);
    new Location(player.getWorld(), 232.3, 10, 116.6).getBlock().setType(Material.REDSTONE_BLOCK);

    return;
    }

    }
    }
    else if(block.getType().equals((Material.SPRUCE_DOOR))) {
    if(GameStart.Jail[2] == -1 && GameStart.multitimemanage == 1 && GameStart.jail3 < 10) {
    GameStart.jail3 += 0.1;
    player.sendMessage(GameStart.jail3 + "% / 10 %");
    }else if(GameStart.jail3 == 10) {
    GameStart.Jail[2] = 0;
    Bukkit.broadcastMessage("감옥에 갇힌 도둑이 탈옥하였습니다.!");
    if(new Location(player.getWorld(), 233.3, 12, 122.6).getBlock().getType().equals((Material.REDSTONE_BLOCK))) {
    new Location(player.getWorld(), 233.3, 12, 122.6).getBlock().setType(Material.AIR);
    new Location(player.getWorld(), 232.3, 10, 122.6).getBlock().setType(Material.REDSTONE_BLOCK);

    return;
    }

    }
    }else if(block.getType().equals((Material.JUNGLE_DOOR))) {
    if(GameStart.Jail[3] == -1 && GameStart.multitimemanage == 1 && GameStart.jail4 < 10) {
    GameStart.jail4 += 0.1;
    player.sendMessage(GameStart.jail4 + "% / 10 %");
    }else if(GameStart.jail3 == 10) {
    GameStart.Jail[3] = 0;
    Bukkit.broadcastMessage("감옥에 갇힌 도둑이 탈옥하였습니다.!");
    if(new Location(player.getWorld(), 233.3, 12, 128.6).getBlock().getType().equals((Material.REDSTONE_BLOCK))) {
    new Location(player.getWorld(), 233.3, 12, 128.6).getBlock().setType(Material.AIR);
    new Location(player.getWorld(), 232.3, 10, 128.6).getBlock().setType(Material.REDSTONE_BLOCK);

    return;
    }

    }
    }else {
    return;
    }








    }else {
    return;
    }



    }
     
  2. Offline

    marcelo.mb

    Please beautify your code (write it also into a code section) and let us know the console error.[fire]
     
  3. Offline

    Kars

    Please
    1. format your code
    2. show the error message
     
  4. Offline

    Strahan

    +1 for post us the error. Also you really should refactor that code. Any time you find yourself basically copy and pasting blocks of code with superficial differences, it means you're likely doing something wrong / inefficient. Abstraction is your friend :)
     

Share This Page