Minecraft Java插件块的位置是相同的,但仍然不起作用

Minecraft Java插件块的位置是相同的,但仍然不起作用,java,minecraft,Java,Minecraft,任何能回答这个问题的人。我正在配置中存储信标位置。当一个信标被破坏时,我会得到正在破坏的块的位置,并检查它是否与我的配置中的相同。我不知道为什么它不工作,我甚至做了p.sendmessage,并将两个值作为消息发送,它们是相同的 第1181行是块中断事件 块中断事件: public HashMap<Integer, Block> beaconStore = new HashMap<>(); // WHEN PLAYER BREAKS BLOCK @EventHandler

任何能回答这个问题的人。我正在配置中存储信标位置。当一个信标被破坏时,我会得到正在破坏的块的位置,并检查它是否与我的配置中的相同。我不知道为什么它不工作,我甚至做了p.sendmessage,并将两个值作为消息发送,它们是相同的

第1181行是块中断事件

块中断事件:

public HashMap<Integer, Block> beaconStore = new HashMap<>();
// WHEN PLAYER BREAKS BLOCK
@EventHandler
public void onBreak(BlockBreakEvent event){
    Player p = event.getPlayer();
    Block block = event.getBlock();

    if (p.getItemInHand().getType() == Material.WOOD_HOE) {
        event.setCancelled(true);

        w = block.getLocation().getWorld().getName();
        x = block.getLocation().getX() + 0.500;
        y = block.getLocation().getY();
        z = block.getLocation().getZ() + 0.500;

        p.sendMessage("§6Saved coordinates for block. (World:" + w + " x:" + x + "," + " y:" + y + "," + " z:" + z + ")");

    }

    if (gameRunning == true) {
        boolean okBreak = false;
        for(Integer integer : BlockReset.keySet()){
              Block bl = BlockReset.get(integer);

              if (bl.equals(block)) {
                  okBreak = true;
              }
              else {

              }
        }

        Location blockLocation = block.getLocation();

        if (block.getType() == Material.BEACON) {
            okBreak = true;

            p.sendMessage(" " + blockLocation);

            World world = block.getWorld();



            double xyellowBeacon1 = getConfig().getDouble("yellowbeacon1.x");
            double yyellowBeacon1 = getConfig().getDouble("yellowbeacon1.y");
            double zyellowBeacon1 = getConfig().getDouble("yellowbeacon1.z");
            Location yellowBeacon1Location = new Location(world, xyellowBeacon1, yyellowBeacon1, zyellowBeacon1);


            double xyellowBeacon2 = getConfig().getDouble("yellowbeacon2.x");
            double yyellowBeacon2 = getConfig().getDouble("yellowbeacon2.y");
            double zyellowBeacon2 = getConfig().getDouble("yellowbeacon2.z");
            Location yellowBeacon2Location = new Location(world, xyellowBeacon2, yyellowBeacon2, zyellowBeacon2);

            double xyellowBeacon3 = getConfig().getDouble("yellowbeacon3.x");
            double yyellowBeacon3 = getConfig().getDouble("yellowbeacon3.y");
            double zyellowBeacon3 = getConfig().getDouble("yellowbeacon3.z");
            Location yellowBeacon3Location = new Location(world, xyellowBeacon3, yyellowBeacon3, zyellowBeacon3);

            double xyellowBeacon4 = getConfig().getDouble("yellowbeacon4.x");
            double yyellowBeacon4 = getConfig().getDouble("yellowbeacon4.y");
            double zyellowBeacon4 = getConfig().getDouble("yellowbeacon4.z");
            Location yellowBeacon4Location = new Location(world, xyellowBeacon4, yyellowBeacon4, zyellowBeacon4);

            if (blockLocation == yellowBeacon1Location) {
                yellowbcount--;
            }
            if (blockLocation == yellowBeacon2Location) {
                yellowbcount--;
            }
            if (blockLocation == yellowBeacon3Location) {
                yellowbcount--;
            }
            if (blockLocation == yellowBeacon4Location) {
                yellowbcount--;
            }



            double xblueBeacon1 = getConfig().getDouble("bluebeacon1.x");
            double yblueBeacon1 = getConfig().getDouble("bluebeacon1.y");
            double zblueBeacon1 = getConfig().getDouble("bluebeacon1.z");
            Location blueBeacon1Location = new Location(world, xblueBeacon1, yblueBeacon1, zblueBeacon1);

            double xblueBeacon2 = getConfig().getDouble("bluebeacon2.x");
            double yblueBeacon2 = getConfig().getDouble("bluebeacon2.y");
            double zblueBeacon2 = getConfig().getDouble("bluebeacon2.z");
            Location blueBeacon2Location = new Location(world, xblueBeacon2, yblueBeacon2, zblueBeacon2);

            double xblueBeacon3 = getConfig().getDouble("bluebeacon3.x");
            double yblueBeacon3 = getConfig().getDouble("bluebeacon3.y");
            double zblueBeacon3 = getConfig().getDouble("bluebeacon3.z");
            Location blueBeacon3Location = new Location(world, xblueBeacon3, yblueBeacon3, zblueBeacon3);

            double xblueBeacon4 = getConfig().getDouble("bluebeacon4.x");
            double yblueBeacon4 = getConfig().getDouble("bluebeacon4.y");
            double zblueBeacon4 = getConfig().getDouble("bluebeacon4.z");
            Location blueBeacon4Location = new Location(world, xblueBeacon4, yblueBeacon4, zblueBeacon4);

            if (blockLocation == blueBeacon1Location) {
                bluebcount--;
            }
            if (blockLocation == blueBeacon2Location) {
                bluebcount--;
            }
            if (blockLocation == blueBeacon3Location) {
                bluebcount--;
            }
            if (blockLocation == blueBeacon4Location) {
                bluebcount--;
            }



            double xgreenBeacon1 = getConfig().getDouble("greenbeacon1.x");
            double ygreenBeacon1 = getConfig().getDouble("greenbeacon1.y");
            double zgreenBeacon1 = getConfig().getDouble("greenbeacon1.z");
            Location greenBeacon1Location = new Location(world, xgreenBeacon1, ygreenBeacon1, zgreenBeacon1);

            double xgreenBeacon2 = getConfig().getDouble("greenbeacon2.x");
            double ygreenBeacon2 = getConfig().getDouble("greenbeacon2.y");
            double zgreenBeacon2 = getConfig().getDouble("greenbeacon2.z");
            Location greenBeacon2Location = new Location(world, xgreenBeacon2, ygreenBeacon2, zgreenBeacon2);

            double xgreenBeacon3 = getConfig().getDouble("greenbeacon3.x");
            double ygreenBeacon3 = getConfig().getDouble("greenbeacon3.y");
            double zgreenBeacon3 = getConfig().getDouble("greenbeacon3.z");
            Location greenBeacon3Location = new Location(world, xgreenBeacon3, ygreenBeacon3, zgreenBeacon3);

            double xgreenBeacon4 = getConfig().getDouble("greenbeacon4.x");
            double ygreenBeacon4 = getConfig().getDouble("greenbeacon4.y");
            double zgreenBeacon4 = getConfig().getDouble("greenbeacon4.z");
            Location greenBeacon4Location = new Location(world, xgreenBeacon4, ygreenBeacon4, zgreenBeacon4);

            if (blockLocation == greenBeacon1Location) {
                greenbcount--;
            }
            if (blockLocation == greenBeacon2Location) {
                greenbcount--;
            }
            if (blockLocation == greenBeacon3Location) {
                greenbcount--;
            }
            if (blockLocation == greenBeacon4Location) {
                greenbcount--;
            }



            double xredBeacon1 = getConfig().getDouble("redbeacon1.x");
            double yredBeacon1 = getConfig().getDouble("redbeacon1.y");
            double zredBeacon1 = getConfig().getDouble("redbeacon1.z");
            Location redBeacon1Location = new Location(world, xredBeacon1, yredBeacon1, zredBeacon1);
            p.sendMessage(" " + redBeacon1Location);

            double xredBeacon2 = getConfig().getDouble("redbeacon2.x");
            double yredBeacon2 = getConfig().getDouble("redbeacon2.y");
            double zredBeacon2 = getConfig().getDouble("redbeacon2.z");
            Location redBeacon2Location = new Location(world, xredBeacon2, yredBeacon2, zredBeacon2);

            double xredBeacon3 = getConfig().getDouble("redbeacon3.x");
            double yredBeacon3 = getConfig().getDouble("redbeacon3.y");
            double zredBeacon3 = getConfig().getDouble("redbeacon3.z");
            Location redBeacon3Location = new Location(world, xredBeacon3, yredBeacon3, zredBeacon3);

            double xredBeacon4 = getConfig().getDouble("redbeacon4.x");
            double yredBeacon4 = getConfig().getDouble("redbeacon4.y");
            double zredBeacon4 = getConfig().getDouble("redbeacon4.z");
            Location redBeacon4Location = new Location(world, xredBeacon4, yredBeacon4, zredBeacon4);

            if (blockLocation == redBeacon1Location) {
                redbcount--;
                p.sendMessage("Okay!");
            }
            if (blockLocation == redBeacon2Location) {
                redbcount--;
            }
            if (blockLocation == redBeacon3Location) {
                redbcount--;
            }
            if (blockLocation == redBeacon4Location) {
                redbcount--;
            }
        }

        if (okBreak == true) {
            event.setCancelled(false);
        }
        else {
            event.setCancelled(true);
            p.sendMessage("§9§lPillars " + dot + " §7You can only break blocks placed by a player!");
        }
    }
}
^^我对每个灯塔都这么做


我希望您理解我的问题。

可能不是您遇到的问题的原因,但是在比较
位置
类实例时,请使用
等于
方法,而不是
=
,因为当您使用相同的方法创建一个比较位置时,它们肯定不是相同的实例

与您的问题没有很大关系,但是稍微重构一下您的代码。如果您必须复制粘贴某些内容,它会标记为可以提取为方法的内容。因此,创建一个带有签名的方法
Location-getLocation(World-World,String-beaconprefix)
,该方法从配置中获取块位置并创建它,显著减少了代码长度

private Location getLocation(World world, String beaconPrefix) {
  double x = getConfig().getDouble(beaconPrefix + ".x");
  double y = getConfig().getDouble(beaconPrefix + ".y");
  double z = getConfig().getDouble(beaconPrefix + ".z");
  return new Location(world, x, y, z);
}

可能不是您遇到的问题的原因,但在比较
位置
类实例时,请使用
等于
方法,而不是
=
,因为在相同方法中创建一个比较位置时,它们肯定不是相同的实例

与您的问题没有很大关系,但是稍微重构一下您的代码。如果您必须复制粘贴某些内容,它会标记为可以提取为方法的内容。因此,创建一个带有签名的方法
Location-getLocation(World-World,String-beaconprefix)
,该方法从配置中获取块位置并创建它,显著减少了代码长度

private Location getLocation(World world, String beaconPrefix) {
  double x = getConfig().getDouble(beaconPrefix + ".x");
  double y = getConfig().getDouble(beaconPrefix + ".y");
  double z = getConfig().getDouble(beaconPrefix + ".z");
  return new Location(world, x, y, z);
}

为什么要将块位置(整数)存储/使用为双精度?为什么不使用整数呢?此外,如果您使用的Minecraft版本为1.10或更高版本,
BlockPos
是一个存在的东西,并且将正确地等同。我将所有内容都存储为双倍,以便可以根据需要更准确地更改它们。我使用了1.8.8+我已经解决了这个问题,正如我所评论的,你什么时候需要知道一个位于
X=15.2389074293874
的块,而不是
X=15
?为什么要存储/使用块位置(整数)作为双精度?为什么不使用整数呢?此外,如果您使用的Minecraft版本为1.10或更高版本,
BlockPos
是一个存在的东西,并且将正确地等同。我将所有内容都存储为双倍,以便可以根据需要更准确地更改它们。我使用了1.8.8+我已经解决了这个问题,正如我所评论的,你什么时候需要知道
X=15.2389074293874而不是
X=15