Jump to content

[1.10.2] [Solved} Boolean Won't work, 100% confused as to why


Recommended Posts

Posted (edited)

Ok so i have a boolean getting true or false from nbt of a player. When i run print on the boolen it clearly shows true or false but when using it in an if statement it doesnt seem to work. This is the part where im using the boolean - 

            NBTTagCompound data = forgeplayer.getEntityData();
            data.setTag("AdminUtils", new NBTTagCompound());
            NBTTagCompound adminnbt = data.getCompoundTag("AdminUtils");
            adminnbt.setTag("WorldWarnings", new NBTTagCompound());
            NBTTagCompound worldwarnings = adminnbt.getCompoundTag("WorldWarnings");
            Boolean warning = worldwarnings.getBoolean(world);
            if (playerpresent) {
                if (!(worldslist.contains(world))) {
                    if (warning) {
                      System.out.print(String.valueOf(warning);
                      }
                 }
            }

 

Edited by Bennyboy1695
Friend helped me solve it
Posted
2 minutes ago, diesieben07 said:
  • Why are you using getEntityData? It's ugly to work with NBT directly like that. You should use a capability.

Because i just wanted a simple and quick way to store a players true or false on this bit of code. It may be ugly but for my needs it fits.

 

5 minutes ago, diesieben07 said:
  • Why are you using the boxed Boolean type instead of boolean?

I have tried multiple ways of the boolean, still get the issue, this was just the latest way i tried.

 

6 minutes ago, diesieben07 said:
  • What is this playerpresent variable? In general: show more of your code.

The playerpresent just gets whether the player is online. 

 

Here's the full part of that, its using some Sponge methods as its part Sponge and part Forge
 

    public void onBlockPlace(ChangeBlockEvent.Place event) {
        if (AdminUtilsSponge.getInstance().getWorldWarningBoolean()) {
            String world = event.getTargetWorld().getName();
            String worldslist = String.join(", ", AdminUtilsSponge.getInstance().getWorldList());
            Optional<Player> player = event.getCause().first(Player.class);
            Boolean playerpresent = player.isPresent();
            String name = player.get().getName();
            UUID uuid = player.get().getUniqueId();
            EntityPlayer forgeplayer = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(uuid);
            String block = event.getTransactions().get(0).getFinal().getState().getType().getName();
            NBTTagCompound data = forgeplayer.getEntityData();
            data.setTag("AdminUtils", new NBTTagCompound());
            NBTTagCompound adminnbt = data.getCompoundTag("AdminUtils");
            adminnbt.setTag("WorldWarnings", new NBTTagCompound());
            NBTTagCompound worldwarnings = adminnbt.getCompoundTag("WorldWarnings");
            Boolean warning = worldwarnings.getBoolean(world);
            if (playerpresent) {
                if (!(worldslist.contains(world))) {
                    if (warning) {
                        System.out.print(String.valueOf(worldwarnings.getBoolean(world)));
                    }
                }
            }
        }
    }

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.