DecentSoftware-eu / DecentHolograms

A lightweight but powerful hologram plugin with many features and configuration options.
https://www.spigotmc.org/resources/96927/
GNU General Public License v3.0
211 stars 101 forks source link

Removing the default line throws IndexOutOfBoundsException #144

Closed EpicKnarvik97 closed 1 year ago

EpicKnarvik97 commented 1 year ago

Just making sure

Reproduction

  1. Install DecentHolograms
  2. Create a new hologram named test
  3. Run /dh line rem test 1 1
  4. Internal error message is displayed in chat, and a stack trace is shown in the console.

Solution

It seems the problem causes an IndexOutOfBoundsException related to removing the first page. You should probably check that the index is in bounds when removing from the pages array.

Server Version

Paper 1.19.4 550

Client Version

1.20.1

Plugin Version

2.8.3

Log

https://pastebin.com/H5ZkhGYH

Andre601 commented 1 year ago

Well.... what did you do?

EpicKnarvik97 commented 1 year ago

Well.... what did you do?

As specified in reproduction, I created a new hologram and deleted the default line (page 1 line 1). The deletion of the line itself seems to work fine, but for some reason, the plugin wants to remove page 2 (eu.decentsoftware.holograms.api.holograms.Hologram.removePage(Hologram.java:915)) as well, without there being a page 2, which causes java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1.

EpicKnarvik97 commented 1 year ago

Okay, I tested a bit more, and generally, it seems that whenever a page is removed because all lines for that page are removed, the index used for triggering page deletion is 1-indexed instead of 0-indexed. This does not happen when the page is removed directly using /dh page rem.

The check in eu.decentsoftware.holograms.api.holograms.Hologram line 911 in the removePage(int index) { method: if (index < 0 || index > size()) { might be part of the problem, as it should be if (index < 0 || index >= size()) { to not exit bounds. Fixing that should at least prevent the stack trace.

The other problem seems that in LineSubCommand line 642 (hologram.removePage(pageIndex);), the index supplied is the user's 1-indexed input which hasn't been converted to 0-indexed.