表达式的类型必须是数组类型,但它解析为double

时间:2014-04-08 00:56:35

标签: java minecraft bukkit

当我使用此代码时:

    switch (1.$SwitchMap$org$bukkit$Material[block.getType().ordinal()])

我收到错误:

The type of the expression must be an array type but it resolved to double

我正在编写一个Minecraft Bukkit插件

这是我的整个代码:

package me.TheTrain2000.Smelter;

import java.util.Iterator;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
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.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class Main
  extends JavaPlugin
  implements Listener
{
  private static byte MAGIC_BYTE = 15;

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

  @EventHandler(priority=EventPriority.LOW, ignoreCancelled=true)
  public void onEntityExplode(EntityExplodeEvent event)
  {
    if (event.blockList().isEmpty()) {
      return;
    }
    for (Iterator<Block> i = event.blockList().iterator(); i.hasNext();)
    {
      Block block = (Block)i.next();
      if ((block.getData() == MAGIC_BYTE) && (shouldBreak(block)))
      {
        simulateBreak(block);
        i.remove();
      }
    }
  }

  @EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
  public void onBlockBreak(BlockBreakEvent event)
  {
    Block block = event.getBlock();
    if ((block.getData() == MAGIC_BYTE) && (shouldBreak(block)))
    {
      simulateBreak(block);
      event.setCancelled(true);
    }
  }

  @EventHandler(ignoreCancelled=true)
  public void onBlockPhysics(BlockPhysicsEvent event)
  {
    Block block = event.getBlock();
    Block block1 = block.getRelative(BlockFace.DOWN);
    Block block2 = block1.getRelative(BlockFace.DOWN);

    boolean aboveLava = (block1.getType() == Material.LAVA) || (block1.getType() == Material.STATIONARY_LAVA);
    boolean aboveCoveredLava = (block1.getType() == Material.GLASS) && ((block2.getType() == Material.LAVA) || (block2.getType() == Material.STATIONARY_LAVA));
    if (((aboveLava) || (aboveCoveredLava)) && (nextToPiston(block))) {
      smeltBlock(block);
    }
    if ((block.getData() == MAGIC_BYTE) && (block1.getType() == Material.WATER)) {
      simulateBreak(block);
    }
  }

  private void smeltBlock(Block block)
  {
    int newType = getNewType(block).getId();
    if (newType != 0) {
      block.setTypeIdAndData(newType, MAGIC_BYTE, true);
    }
  }

  private boolean shouldBreak(Block block)
  {
    switch (1.$SwitchMap$org$bukkit$Material[block.getType().ordinal()])
    {
    case 1:
    case 2:
    case 3:
    case 4:
      return true;
    }
    return false;
  }

  private Material getNewType(Block block)
  {
    switch (1.$SwitchMap$org$bukkit$Material[block.getType().ordinal()])
    {
    case 5:
      return Material.STONE;
    case 6:
      return Material.IRON_BLOCK;
    case 7:
      return Material.GOLD_BLOCK;
    case 8:
      return Material.GLASS;
    case 9:
      return Material.BRICK;
    }
    return Material.AIR;
  }

  private void simulateBreak(Block block)
  {
    Material dropItem = getDrop(block);
    if (dropItem == null) {
      return;
    }
    block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(dropItem, 1));
    block.setType(Material.AIR);
  }

  private boolean nextToPiston(Block block)
  {
    return (block.getRelative(BlockFace.EAST).getType() == Material.PISTON_EXTENSION) || (block.getRelative(BlockFace.WEST).getType() == Material.PISTON_EXTENSION) || (block.getRelative(BlockFace.NORTH).getType() == Material.PISTON_EXTENSION) || (block.getRelative(BlockFace.SOUTH).getType() == Material.PISTON_EXTENSION) || (block.getRelative(BlockFace.UP).getType() == Material.PISTON_EXTENSION);
  }

  private Material getDrop(Block block)
  {
    switch (1.$SwitchMap$org$bukkit$Material[block.getType().ordinal()])
    {
    case 2:
      return Material.STONE;
    case 3:
      return Material.IRON_INGOT;
    case 4:
      return Material.GOLD_INGOT;
    case 1:
      return Material.GLASS;
    case 10:
      return Material.BRICK;
    }
    return null;
  }
}

1 个答案:

答案 0 :(得分:0)

此:

switch (1.$SwitchMap$org$bukkit$Material[block.getType().ordinal()])

显然已反编译代码且无效的Java源代码。您需要将其替换为原始调用,可能是:

switch(block.getType())

然后,您需要将所有案例陈述从其序数值转换为它们所代表的枚举。