当前位置: 首页 > 知识库问答 >
问题:

我的世界Java插件-块位置是相同的,但它仍然不工作

宗政元青
2023-03-14

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

https://pastebin.com/Kd4eZyJc第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!");
        }
    }
}

在命令中设置信标位置:

if (args[0].equalsIgnoreCase("yellowbeacon1")) {
    getConfig().set("yellowbeacon1.world", w);
    getConfig().set("yellowbeacon1.x", x - 0.5);
    getConfig().set("yellowbeacon1.y", y);
    getConfig().set("yellowbeacon1.z", z - 0.5);
    saveConfig();

    p.sendMessage("§9§lPillars " + dot + " §7Successfully set §eyellow §5beacon1!");
}

^^我对每个灯塔都这么做。

共有1个答案

宗沛
2023-03-14

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

与您的问题没有太大关系,但是稍微重构一下您的代码。如果你必须复制粘贴一些东西,它会标记为你可以提取的东西作为方法。因此,创建带有签名的方法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插口插件的帮助。 这是布局(或构建路径,如果你想这样称呼它) 这是主文件的代码(main.java) 下面是listeners.java的代码(在监听器包中) 然后这里是yml文件 此外,如果版本错误,下面是我将其上传到服务器时的样子。 org.bukkit.plugin。InvalidDescriptionException:插件无效。yml在org.bukkit.pl

  • 我想知道是否有一种方法可以使插件具有当用户在我的网站上执行操作时触发的事件。我想这样做来制作一个定制商店,因为我不喜欢 Enjin 或 Buycraft,因为它们不是很可定制。

  • 问题内容: 我正在使用Linux Mint Cinnamon14。我将和环境变量设置如下: 然后,我做了适当的更改。 当我执行命令以检查活动的Java版本时,它将显示默认的Java版本(已安装open- jdk)。如何用我下载的默认文件覆盖默认的open-jdk? 更新: 说/ usr / bin / java 说“权限被拒绝” (然后要求输入密码)说找不到命令 但是,并表明它是正确的目录。 问题

  • 我试图用when(requestHeadersSpec.header(notNull(),notNull())来模拟头部。然后返回(requestHeadersSpec);,或者类似的,但我不工作,有人有想法吗? ..... }

  • 我正在编码我的第一个《我的世界》mod,我可以让我的项目加载纹理。我对编码《我的世界》mod很不熟悉,我有点困惑。以下是基本项目的代码: 这是实际项目的代码:

  • 我该怎么办?我的地雷船不会在日食中发射!以下是坠机报告: 我很确定我试图制作的mod不是一个错误。我甚至尝试在没有mod的情况下启动。它仍然不起作用。无论如何,这是我的mod代码: