Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suggestion] use json features where applicable? #74

Open
Merith-TK opened this issue May 22, 2023 · 2 comments
Open

[suggestion] use json features where applicable? #74

Merith-TK opened this issue May 22, 2023 · 2 comments

Comments

@Merith-TK
Copy link

Merith-TK commented May 22, 2023

the current default as of latest release as of this message

{
  "// Patches some outgoing server packets": "",
  "main": {
    "// Prevents hitting/chatting with open GUI": "",
    "checkInventoryActions": true,
    "// Prevents headless pistons from destroying blocks that are not piston extensions.": "",
    "preventDestructionByHeadlessPistons": true,
    "// Allows headless pistons to destroy certain blocks when preventing destruction is enabled.": "",
    "// Useful to allow only breaking of bedrock but denying destruction of barriers.": "",
    "allowedDestructibleByHeadlessPistons": [
      "minecraft:piston_head"
    ],
    "// What altitude in the nether should start inflicting void damage (e.g. 128). -1 disables it.": "",
    "inflictNetherRoofDamage": -1
  },
  "items": {
    "survival": {
      "// Whether to enable 'legalising' survival items.": "",
      "// Whether to check whole inventory when connecting / changing dimensions, etc.": "",
      "legaliseWholeInventory": true,
      "// Which items should be cleared when clicked in survival inventory": "",
      "bannedItems": {
        "minecraft:structure_void": "",
        "minecraft:end_portal_frame": "",
        "minecraft:bedrock": "",
        "minecraft:barrier": "",
        "minecraft:repeating_command_block": "",
        "minecraft:command_block": "",
        "minecraft:spawner": "",
        "minecraft:jigsaw": "",
        "minecraft:air": "",
        "minecraft:structure_block": "",
        "minecraft:air": "",
        "minecraft:air": "",
        "minecraft:chain_command_block": ""
      },
      "banSpawnEggs": true,
      "checkEnchants": true,
      "checkPotionLevels": true,
      "checkItemCount": true
    },
    "creative": {
      "// Whether to check whole inventory when connecting / changing dimensions, etc.": "",
      "legaliseWholeInventory": true,
      "// Which NBT shouldn't be cleared": "",
      "// Disallow all NBT tags in creative which aren't in whitelist section.": "",
      "whitelistedNBT": [
        "EntityTag",
        "Enchantments",
        "StoredEnchantments",
        "BlockEntityTag",
        "Damage",
        "Potion",
        "display"
      ],
      "removeCreativeNBTTags": true,
      "checkEnchants": true,
      "checkPotionLevels": true,
      "checkItemCount": true
    }
  },
  "combat": {
    "_comment": "// Combat checks settings.",
    "preventWallHit": true,
    "checkHitDistance": true,
    "checkHitAngle": true
  },
  "packet": {
    "removeTeleportData": true,
    "removeHealthTags": true,
    "// Allows health tags for certain entities.": "",
    "// This maps entity ID to percentage as decimal.": "",
    "allowedHealthTags": {
      "minecraft:iron_golem": 0.25,
      "minecraft:wither": 0.5,
      "minecraft:wolf": 0.0
    },
    "removeEquipmentTags": true,
    "checkPortalHack": true,
    "patchSoundExploits": true,
    "removeDroppedItemInfo": true,
    "patchItemKickExploit": true
  },
  "movement": {
    "patchNoFall": true
  },
  "duplication": {
    "_comment": "// Duplication fixes",
    "// Whether to prevent throwing an error when saving large string data.": "",
    "// This is done by ignoring data after DataOutputStream limit.": "",
    "// Written books can reach that point with hacked clients.": "",
    "patchSaveLimit": true,
    "// Whether to disable gravity block duping.": "",
    "patchGravityBlock": true,
    "// Checks if player is connected before applying damage.": "",
    "// Prevents duplicating inventory if player dies after disconnect.": "",
    "patchDeathDuplication": true
  }
}

proposed json

{
  //Patches some outgoing server packets,
  "main": {
    //Prevents hitting/chatting with open GUI,
    "checkInventoryActions": true,
    //Prevents headless pistons from destroying blocks that are not piston extensions.,
    "preventDestructionByHeadlessPistons": true,
    //Allows headless pistons to destroy certain blocks when preventing destruction is enabled.,
    //Useful to allow only breaking of bedrock but denying destruction of barriers.,
    "allowedDestructibleByHeadlessPistons": [
      "minecraft:piston_head"
    ],
    //What altitude in the nether should start inflicting void damage (e.g. 128). -1 disables it.,
    "inflictNetherRoofDamage": -1
  },
  "items": {
    "survival": {
      //Whether to enable 'legalising' survival items.,
      //Whether to check whole inventory when connecting / changing dimensions, etc.,
      "legaliseWholeInventory": true,
      //Which items should be cleared when clicked in survival inventory,
      "bannedItems": [
        "minecraft:structure_void",
        "minecraft:end_portal_frame",
        "minecraft:bedrock",
        "minecraft:barrier",
        "minecraft:repeating_command_block",
        "minecraft:command_block",
        "minecraft:spawner",
        "minecraft:jigsaw",
        "minecraft:air",
        "minecraft:structure_block",
        "minecraft:air",
        "minecraft:air",
        "minecraft:chain_command_block"
	  ],
      "banSpawnEggs": true,
      "checkEnchants": true,
      "checkPotionLevels": true,
      "checkItemCount": true
    },
    "creative": {
      //Whether to check whole inventory when connecting / changing dimensions, etc.,
      "legaliseWholeInventory": true,
      //Which NBT shouldn't be cleared,
      //Disallow all NBT tags in creative which aren't in whitelist section.,
      "whitelistedNBT": [
        "EntityTag",
        "Enchantments",
        "StoredEnchantments",
        "BlockEntityTag",
        "Damage",
        "Potion",
        "display"
      ],
      "removeCreativeNBTTags": true,
      "checkEnchants": true,
      "checkPotionLevels": true,
      "checkItemCount": true
    }
  },
  "combat": {
    //Combat checks settings.",
    "preventWallHit": true,
    "checkHitDistance": true,
    "checkHitAngle": true
  },
  "packet": {
    "removeTeleportData": true,
    "removeHealthTags": true,
    //Allows health tags for certain entities.,
    //This maps entity ID to percentage as decimal.,
    "allowedHealthTags": {
      "minecraft:iron_golem": 0.25,
      "minecraft:wither": 0.5,
      "minecraft:wolf": 0.0
    },
    "removeEquipmentTags": true,
    "checkPortalHack": true,
    "patchSoundExploits": true,
    "removeDroppedItemInfo": true,
    "patchItemKickExploit": true
  },
  "movement": {
    "patchNoFall": true
  },
  "duplication": {
    //Duplication fixes
    //Whether to prevent throwing an error when saving large string data.,
    //This is done by ignoring data after DataOutputStream limit.,
    //Written books can reach that point with hacked clients.,
    "patchSaveLimit": true,
    //Whether to disable gravity block duping.,
    "patchGravityBlock": true,
    //Checks if player is connected before applying damage.,
    //Prevents duplicating inventory if player dies after disconnect.,
    "patchDeathDuplication": true
  }
}
  1. make comments be actual comments (not json keys)
  • Easier to read
  1. make inventory blacklist actually be an [list] and not an {table}
  • Makes editors not have a heart attack when modified

if you are concerned about reading the config file, what you can do is
(psuedo code)

// open file
for each line do
  line = readLine
  line = (trim whitespace from beginning)
  if line.hasPrefix("//") then
    ignore
  else
    append(jsondata, line) // append line to jsondata
 end
 // parse jsondata as if you are parsing file
@Ampflower
Copy link
Collaborator

A problem is that the JSON library used here, GSON, has no native method for writing comments in JSON since the JSON spec normally doesn't allow those. It can read and ignore comments fine with lenient set tho.

If we want native JSON comments as part of JSON 5, we'll likely want Jankson (likely more favourable with being much more fault tolerant with inputs), so that'd be something to consider on top.

@samolego
Copy link
Owner

Agreed, it'd be beneficial to use json5 supported library instead then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants