Skip to content

Conversation

@Golfing7
Copy link

@Golfing7 Golfing7 commented Mar 24, 2022

Information

This PR closes Nothing.

Details

Proposed feature:
A system to allow plugin developers to add custom item transformers to metadata on items. Would be useful for plugins seeking to add custom item templates that could be dynamic or have special data on the item.

Environments tested:

OS: Windows 10

Java version: 1.8.0_281

  • Most recent Paper version (1.XX.Y, git-Paper-BUILD)
  • CraftBukkit/Spigot/Paper 1.12.2
  • [ x ] CraftBukkit 1.8.8

Demonstration:

A demonstration isn't fully applicable to the situation as it's not something that immediately affects anything.

@mdcfe
Copy link
Member

mdcfe commented Mar 24, 2022

Thanks for your interest in contributing to EssentialsX!

As it stands, MetaItemStack has been long in need of a major overhaul which I've been working on in a private branch. Part of this rework would overlap with the functionality added in this PR, so I will need some time to consider whether it would make sense to merge this PR at this stage.

@pop4959 pop4959 added type: enhancement Features and feature requests. module: main Issues or PRs for the main Essentials module labels May 21, 2022
@Golfing7
Copy link
Author

It's been a while, just would like to see if this could still be merged as the rework to MetaItemStack appears to have not come yet. Thanks!

@Golfing7
Copy link
Author

Golfing7 commented Nov 5, 2025

Heyo! I recently found a need for this again and wanted to know if this could get merged in quickly. Thanks!

Copy link
Member

@JRoy JRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit + fix the formatting issues + fix the merge conflicts

@Golfing7
Copy link
Author

I've addressed the changes. Should I modify anything else?

Copy link
Member

@JRoy JRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some final codestyle nits

private static final Pattern STRICTINVALIDCHARS = Pattern.compile("[^a-z0-9]");
@SuppressWarnings("CheckStyle")
private static final Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]");
private static final Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r -~\u0085\u00A0-\uD7FF\uE000-\uFFFC]");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo this too pls

Comment on lines 10 to 11
if(thePlugin == null)
throw new IllegalArgumentException("Plugin cannot be null!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(thePlugin == null)
throw new IllegalArgumentException("Plugin cannot be null!");
if (thePlugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}

public abstract class PluginItemTransformer {
private final Plugin plugin;

public PluginItemTransformer(Plugin thePlugin){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public PluginItemTransformer(Plugin thePlugin){
public PluginItemTransformer(final Plugin thePlugin) {

Comment on lines 399 to 412
private void transformItem(String key, String data){
final PluginItemTransformer transformer = itemTransformers.get(key);

//Ignore, the plugin is disabled.
if(!transformer.getPlugin().isEnabled())
return;

try{
stack = transformer.apply(data, stack);
}catch(Throwable thr){
Bukkit.getLogger().severe(String.format("[Essentials] - Error applying data \"%s\" to itemstack! Plugin: %s, Key: %s", data, transformer.getPlugin().getName(), key));
thr.printStackTrace();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void transformItem(String key, String data){
final PluginItemTransformer transformer = itemTransformers.get(key);
//Ignore, the plugin is disabled.
if(!transformer.getPlugin().isEnabled())
return;
try{
stack = transformer.apply(data, stack);
}catch(Throwable thr){
Bukkit.getLogger().severe(String.format("[Essentials] - Error applying data \"%s\" to itemstack! Plugin: %s, Key: %s", data, transformer.getPlugin().getName(), key));
thr.printStackTrace();
}
}
private void transformItem(final String key, final String data){
final PluginItemTransformer transformer = itemTransformers.get(key);
//Ignore, the plugin is disabled.
if (!transformer.getPlugin().isEnabled()) {
return;
}
try {
stack = transformer.apply(data, stack);
} catch(final Throwable thr) {
Bukkit.getLogger().severe(String.format("[Essentials] - Error applying data \"%s\" to itemstack! Plugin: %s, Key: %s", data, transformer.getPlugin().getName(), key));
thr.printStackTrace();
}
}

* Unregisters a certain item transformer under key "key".
* @param key the transformer key.
*/
public static void unregisterItemTransformer(String key){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static void unregisterItemTransformer(String key){
public static void unregisterItemTransformer(final String key) {

Comment on lines 97 to 99
public static void registerItemTransformer(String key, PluginItemTransformer itemTransformer){
//Warn people if they're trying to register over top of someone else.
if(itemTransformers.containsKey(key)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static void registerItemTransformer(String key, PluginItemTransformer itemTransformer){
//Warn people if they're trying to register over top of someone else.
if(itemTransformers.containsKey(key)){
public static void registerItemTransformer(final String key, final PluginItemTransformer itemTransformer) {
//Warn people if they're trying to register over top of someone else.
if (itemTransformers.containsKey(key)) {

Comment on lines 58 to 59

//Contains plugin registered item meta data transformers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//Contains plugin registered item meta data transformers.

@Golfing7
Copy link
Author

Addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: main Issues or PRs for the main Essentials module type: enhancement Features and feature requests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants