Solved Get structure a player is in

  • After careful consideration and due to limited usage, we’ve made the decision to discontinue the PaperMC forums. Moving forward, we recommend using Hangar for plugin uploads, and for all other community discussions and support, please join us on Discord.

NickCloudAT

New member
Mar 28, 2025
2
0
1
Hey,

I'm currently making a plugin in where I need to check in which structure a player is in.. Currently I have smth like this:

Java:
                for(final Player p : Bukkit.getOnlinePlayers()){
                    final ArrayList<String> foundStructures = new ArrayList<>();

                    for(final GeneratedStructure generatedStructure : p.getChunk().getStructures()){
                        if(!generatedStructure.getBoundingBox().contains(p.getLocation().toVector()) || hasSeenStructure(p.getUniqueId(), generatedStructure))continue;

                        String structureString = generatedStructure.getStructure().getStructureType().key().asMinimalString().toUpperCase();

                        foundStructures.add(structureString);
                        //setHasSeenStructure(p.getUniqueId(), generatedStructure);
                        p.sendMessage(structureString);
                    }

                    final PlayerProfile playerProfile = WCChallenges.getPlayerHandler().getPlayerProfile(p.getUniqueId());

                    if(foundStructures.isEmpty() || playerProfile == null)continue;

                    for(final BaseChallenge baseChallenge : playerProfile.getChallengesByType(ChallengeType.FIND_STRUCTURE)){
                        if(!(baseChallenge instanceof FindStructureChallenge findStructureChallenge))continue;

                        foundStructures.forEach(findStructureChallenge::playerFoundStructure);
                    }
                }

The Problem; Some structures just return a structuretype of "jigsaw" which is, of course, not very helpful.. I need to know exactly if a player eg. is in a bastion. I already studied the javadocs and now my head hurts because of structures.. Anyone know how I can get the exact structure name?

Thanks!
 

NickCloudAT

New member
Mar 28, 2025
2
0
1
Well, found a way:

String structureString = Objects.requireNonNull(RegistryAccess.registryAccess().getRegistry(RegistryKey.STRUCTURE).getKey(generatedStructure.getStructure())).asMinimalString();