lishid / OpenInv

Open anyone's inventory as a chest, real-time!
GNU General Public License v3.0
120 stars 97 forks source link

Searchinventory / searchechest for all offline players. #114

Closed ghost closed 5 years ago

ghost commented 5 years ago

This would change these commands from barely used to super useful for finding ALL illegal items! If you think that would be too laggy just use a task timer to loop through all offline players and do it asynchronously.

RoboMWM commented 5 years ago

At that point I'd rather have a tool you can run offline instead.

Jikoo commented 5 years ago

To me this feels like a feature that is made obsolete by a decent item fixer and logger. In my eyes, you're talking 2 basic scenarios:

I'll leave this open for a little while for discussion, I would like to hear what use cases you think this feature has that would not be a waste of your own time.

ghost commented 5 years ago

Atleast add an api to get the inventory/echest of an offline player, it would be extremely useful

Jikoo commented 5 years ago

Already exists.

ghost commented 5 years ago

Ok

On Fri, 25 Oct 2019, 00:01 Adam, notifications@github.com wrote:

Already exists.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lishid/OpenInv/issues/114?email_source=notifications&email_token=AK5UGIBIV6F3RNH2NHI6HI3QQISOBA5CNFSM4JDXWFS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECGV6VI#issuecomment-546135893, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK5UGID6IHFF5E5IWKNLE6LQQISOBANCNFSM4JDXWFSQ .

Jikoo commented 5 years ago

For clarity: Use OpenInv to load a Player from an OfflinePlayer. Use the loaded Player object to obtain a player inventory or ender chest from OpenInv for a user-friendly openable inventory.

If you plan on caching and continuously manipulating a player you must notify OpenInv that your plugin will be in use of it so OpenInv does not read a new object from storage and potentially save over your modifications. Additionally, if you are manipulating any other aspects of the player such as location, OpenInv does not currently cause those aspects to persist if the player logs in before being removed from the cache, so you must manually save after manipulation if the player is not currently online. Various methods also may not work offline - potion and gamemode manipulation used to attempt to send packets, causing issues because an offline player has a null connection.

ghost commented 5 years ago

Ok so im making a plugin that has shared double enderchests between players, could i just get player from offlineplayer and get enderchest? What steps would I need to take to save the data/prevent item duplication? Thank you very much.

Jikoo commented 5 years ago

So you're planning to add a system where 2 27-slot ender chests are opened as a single 54-slot inventory?

You'll need to indicate to OpenInv that you're still using the Player object loaded using IOpenInv#retainPlayer(Player, Plugin). You also need to replace your Player object with the freshly joined Player if they come online while the inventory is open. When you're done with the Player (i.e. when the inventory is closed, assuming neither owner of the dual inventory has it open any more), call IOpenInv#releasePlayer(Player, Plugin) so OpenInv doesn't keep the object cached forever.

Beyond that you may have trouble with conflicts with auto-drop-pickup plugins that support moving items to ender chests, ender chest modifications, things of that nature. Under normal circumstances it's not possible for an ender chest to be manipulated without inventory events firing, but the reason OpenInv takes a version-dependent approach is that there is no event fired when an item is directly added to an inventory by a plugin or command. You could combat this with features like a configurable list of commands that would trigger a refresh of inventories or a scheduler periodically checking contents, but it's hard to guarantee success using only the Bukkit API.

ghost commented 5 years ago

Ok, I think I'm gonna wussy out and store the ender chest contents in a yaml file instead as I am a little concerned with the issues involving players logging in and out etc. For example I remember a bug with openinv where if you viewed a players inventory and they logged out their armor would sometimes be flipped? It was rather strange. The only drawback using yaml for my players would be that both of them cant open the ender chest at once (because it saves when it is closed). Tell me if you think that is the best course of action.

Jikoo commented 5 years ago

Why can't two players view an inventory simultaneously? Just don't re-load it if it's already loaded.

That particular OpenInv bug was due to a mistake I made when adding Java 9+ support, it would have been entirely avoidable with thorough enough testing.

I'm gonna close this because we've now strayed pretty far from the original feature request, but if you want to discuss your idea further here that's fine. I'm also available as Jikoo on Spigot, feel free to ping me from a thread in the plugin development forum.