PluginBugs / Issues-ItemsAdder

Repository used to keep track of issues of my plugin ItemsAdder
https://itemsadder.devs.beer
52 stars 21 forks source link

Water bag loses durability when using it to mine blocks. #1373

Closed astro-angelfish closed 2 years ago

astro-angelfish commented 2 years ago

Terms

Discord tag (optional)

No response

What happened?

It seems that the plugin didn't listen to org.bukkit.event.player.PlayerItemDamageEvent and canceled it. It causes the water bag and other item has durability can be broken when using it to mine blocks.

Steps to reproduce the issue

  1. Mine blocks with water bag or other things has durability.

Server version

Checking version, please wait... This server is running Paper version git-Paper-77 (MC: 1.18.1) (Implementing API version 1.18.1-R0.1-SNAPSHOT) (Git: 5ad1d9a)\nYou are 20 version(s) behind\nDownload the new version at: https://papermc.io/downloads\nPrevious version: git-Paper-"8c189d0" (MC: 1.18.1)

ItemsAdder Version

ItemsAdder version 2.5.0-beta Customized Minecraft without client mods! Website: devs.beer Author: LoneDev

ProtocolLib Version

ProtocolLib version 4.8.0-SNAPSHOT-b539 Provides read/write access to the Minecraft protocol. Authors: dmulloy2 and comphenix

LoneLibs Version

LoneLibs version 1.0.16b Collection of libs used by my plugins Authors: LoneDev and others

LightAPI Version (optional)

This server is not running any plugin by that name. Use /plugins to get a list of plugins.

LibsDisguises Version (optional)

This server is not running any plugin by that name. Use /plugins to get a list of plugins.

FULL server log

Well the server has sensitive information and seems not to be related to the bug so we cannot provide the server log.

Error (optional)

No response

ItemsAdder config.yml

metrics: true
update-checker: true
disable-plugin-loading-messages_DONT_ASK_ME_FOR_SUPPORT_IF_YOU_SET_TRUE__THANKS: false
resource-pack:
  hosting:
    no-host:
      enabled: false
    auto-external-host:
      enabled: true
    self-host:
      enabled: false
      server-ip: 127.0.0.1
      pack-port: 8163
    external-host:
      enabled: false
      url: ''
      skip-url-file-type-check___DONT_ASK_HELP_IF_SET_TRUE: false
  apply-on-join: true
  kick-player-on-decline: false
  kick-player-on-fail: false
  delay-ticks: 1
  notify-other-plugins-interfering: true
  title:
    enabled: true
  protect-player:
    black-screen: true
    hide-hud: true
    cancel-movement: true
    lock-player: true
  command:
    usage-cooldown-seconds: 60
  custom-font:
    enabled: false
    name: ipaexg.ttf
    shift: '[0,0]'
    size: 11.0
    oversample: 2.0
  thin-font:
    enabled: false
  zip:
    protect-file-from-unzip:
      enabled: true
      extreme: true
    compress-png-files: true
    compress-json-files: true
    overwrite-vanilla-models: false
    overwrite-vanilla-lang-json: false
    generate-custom-armors-textures:
      _: 'Available values: VANILLA_1_17 or OPTIFINE'
      enabled: true
      mode: VANILLA_1_17
    fix_transparent_noteblocks__disable-for-more-performance: false
    ignore-files-ext:
    - db
    - yml
    - xcf
    - html
  items:
    CustomModelData-starting-value:
      ALL: 10000
      DIAMOND: 11000
config_files:
  lang: zh_cn
  dictionaries-lang: zh_cn
  extract-default-items: true
  extract-default-resources: true
blocks:
  light-api: true
  fix-glitched-blocks:
    enabled: true
    only-new-chunks: false
    search-also-in-these-biomes:
      enabled: false
      biomes:
      - BEACH
      - BIRCH_FOREST
      - BIRCH_FOREST_HILLS
      - FOREST
      - MOUNTAINS
      - MOUNTAIN_EDGE
      - GRAVELLY_MOUNTAINS
      - PLAINS
      - RIVER
  cancel-break-wrong-tool:
    enabled: true
    send-actionbar: true
  campfire:
    unlit-on-place: true
    allow-any-item: true
  disable-REAL: false
  disable-REAL_TRANSPARENT: false
  disable-REAL_NOTE: false
  disable-REAL_WIRE: true
  disable-FIRE: false
items:
  fix-show-attack-and-damage-as-lore: true
  give_death_location_maps: true
  hide-custom-durability-lore: false
liquids:
  enabled: true
huds:
  enabled: true
mobs:
  disable-MOB-behaviour__DISABLE_AT_YOUR_OWN_RISK: false
font_images:
  chat:
    enabled: true
    doublecheck-permission__disable-for-more-performance: false
    add-hover-suggestion: true
  command:
    enabled: true
    commandblocks: true
    excluded:
    - home
    - sethome
    - tpa
  sign:
    enabled: true
  book:
    enabled: true
  anvil:
    enabled: true
  inventory-title:
    enabled: true
  tab-header-footer:
    enabled: true
  vault-prefix-suffix:
    enabled: true
    update-every-ticks: 1200
  scoreboard-teams:
    enabled: false
    update-every-ticks: 3600
  player-display-name:
    enabled: true
    update-every-ticks: 1200
  replace-in-customitems-name-and-lore: true
effects:
  hide-scoreboard-numbers: false
  text-effects:
    enabled: true
    replace-in-customitems-name-and-lore: true
    chat:
      enabled: true
    sign:
      enabled: true
    book:
      enabled: true
    anvil:
      enabled: true
    tab-header-footer:
      enabled: true
entities:
  max-furniture-vehicles-per-chunk: 30
  allow-removing-old-furnitures_2_3_11: false
recipes:
  hide-vanilla-unrecognized-recipe-errors: true
  custom-recipes:
    unlock:
      all-on-join: false
      on-pickup:
        any: false
        ingredients: true
  remove-vanilla-recipes:
    enabled: true
    list:
      DIAMOND_SWORD: false
      IRON_INGOT: false
debug:
  items:
    log-files-loading: false
    log-items-loading: false
    log-items-loading-disabled: false
    log-font-images-loading: false
    log-huds-loading: false
    log-attribute-modifiers-loading: false
    log-warnings: false
    log-loots-loading: false
    log-loots-loading-disabled: false
    log-armors-loading: false
  recipes:
    log-recipes-loading: false
    log-recipes-loading-disabled: false
    log-recipes-removed-vanilla: false
  resource-pack:
    log-extract-default-resources: false
    log-not-extract-default-resources-already-exist: false
  blocks:
    log-save: false
    log-save-on-unload: false
    log-mined-unknown-blocks: true
  worlds-populators:
    log-loading: false
    log-loading-disabled: false
    log-loading-no-populators: false
    log-loading-no-world: true
    log-generation: false
  trees-populators:
    log-loading: false
    log-loading-disabled: false
    log-loading-no-populators: false
    log-loading-no-world: true
    log-generation: false
  surface-decorators:
    log-loading: false
    log-loading-disabled: false
    log-loading-no-decorators: false
    log-loading-no-world: true
    log-generation: false
  player-stats:
    log-save: false
  performance:
    loading-ms: true
  huds:
    log-triggers: false
  other:
    log-dictionaries-loading: false
    log-liquids-loading: false
    log-minecraft_lang_overwrite-loading: false
  categories:
    log-total-loaded: true
    log-single-loaded: false
    log-single-loaded-overwrite: false
    log-single-skip: false

Problematic items yml configuration file (optional)

No response

Other files, you can drag and drop them here to upload. (optional)

No response

Screenshots/Videos (you can drag and drop files or paste links)

No response

LoneDev6 commented 2 years ago

I need to add a new custom property:

    durability:
      max_custom_durability: 1324
      on_block_break: false ## <---- true by default

Right now I cannot know if a sword is used as a consumable item or if it's actually a sword.

astro-angelfish commented 2 years ago

I need to add a new custom property:

    durability:
      max_custom_durability: 1324
      on_block_break: false ## <---- true by default

Right now I cannot know if a sword is used as a consumable item or if it's actually a sword.

I think there's a listener in the plugin marked the PlayerItemDamageEvent as not cancelled wrongly so that the fixer listener of PlayerItemDamageEvent that should fix this issue not applied. So make the listener's priority lower could fix it. But this maybe not a good solution. A good solution is repair the code where would cause the issue.

And I suggest you to process items with org.bukkit.persistence.PersistentDataContainer instead of checking the id of it. And getting the id of item should use the same way to avoid checking wrongly when the name or lore of the item changes.

var CAN_DAMAGE = new NamespacedKey(pluginInstance, "can_damage");
ItemStack stack = new ItemStack(Material.TOTEM_OF_UNDYING);
var meta = stack.getItemMeta();
var container = meta.getPersistentDataContainer();
// put value
container.set(CAN_DAMAGE, PersistentDataType.INTEGER, 0);
// get value
container.get(CAN_DAMAGE, PersistentDataType.INTEGER);

Anyway, I did NOT decompile any of your code or any reverse emgerring not only because the ToS but also because it is unnecessary. All the suggestions above are based on the behavior of the plugin.

~If you meet any problem that unable to resolve, The OrangeMC Team could offer the technical help for free XD.~

LoneDev6 commented 2 years ago

This is exactly what I said before.

Right now I cannot know if a sword is used as a consumable item or if it's actually a sword.

We need a new property to make IA know if an item can get its durability decreased on block break or on attack. In this case two properties would be better I think, for example

    durability:
      max_custom_durability: 1324
      reduce_on_block_break: false ## <---- true by default
      reduce_on_attack: false ## <---- true by default

Do you think it's a good idea to fix this problem?