-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add ability to register custom item transformers. #4871
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
base: 2.x
Are you sure you want to change the base?
Conversation
|
Thanks for your interest in contributing to EssentialsX! As it stands, |
|
It's been a while, just would like to see if this could still be merged as the rework to |
|
Heyo! I recently found a need for this again and wanted to know if this could get merged in quickly. Thanks! |
JRoy
left a comment
There was a problem hiding this 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
|
I've addressed the changes. Should I modify anything else? |
JRoy
left a comment
There was a problem hiding this 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]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo this too pls
| if(thePlugin == null) | ||
| throw new IllegalArgumentException("Plugin cannot be null!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public PluginItemTransformer(Plugin thePlugin){ | |
| public PluginItemTransformer(final Plugin thePlugin) { |
| 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(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public static void unregisterItemTransformer(String key){ | |
| public static void unregisterItemTransformer(final String key) { |
| 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)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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)) { |
|
|
||
| //Contains plugin registered item meta data transformers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| //Contains plugin registered item meta data transformers. |
|
Addressed! |
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
Demonstration:
A demonstration isn't fully applicable to the situation as it's not something that immediately affects anything.