-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introuced the PluginTranslationResolver, which allows to register mul…
…tiple plugins; added support for ExcellentEnchants; bumped artifact-version
- Loading branch information
1 parent
875ddcd
commit 8e69d15
Showing
7 changed files
with
111 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...a/me/blvckbytes/item_predicate_parser/translation/resolver/ExcellentEnchantsResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.blvckbytes.item_predicate_parser.translation.resolver; | ||
|
||
import me.blvckbytes.item_predicate_parser.translation.keyed.LangKeyed; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.Nullable; | ||
import su.nightexpress.excellentenchants.registry.EnchantRegistry; | ||
|
||
public class ExcellentEnchantsResolver extends TranslationResolver { | ||
|
||
public ExcellentEnchantsResolver(Plugin loadedPlugin) { | ||
super(loadedPlugin); | ||
} | ||
|
||
@Override | ||
public @Nullable String resolve(LangKeyed<?> langKeyed) { | ||
if (!(langKeyed.getWrapped() instanceof Enchantment enchantment)) | ||
return null; | ||
|
||
var customEnchantment = EnchantRegistry.getByKey(enchantment.getKey()); | ||
|
||
if (customEnchantment == null) | ||
return null; | ||
|
||
return sanitize(customEnchantment.getDisplayName()); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...a/me/blvckbytes/item_predicate_parser/translation/resolver/PluginTranslationResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package me.blvckbytes.item_predicate_parser.translation.resolver; | ||
|
||
import me.blvckbytes.item_predicate_parser.translation.keyed.LangKeyed; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
|
||
public class PluginTranslationResolver extends TranslationResolver { | ||
|
||
private static final String ECO_ENCHANTS_RESOLVER_PATH = "me/blvckbytes/item_predicate_parser/translation/resolver/EcoEnchantsResolver"; | ||
private static final String EXCELLENT_ENCHANTS_RESOLVER_PATH = "me/blvckbytes/item_predicate_parser/translation/resolver/ExcellentEnchantsResolver"; | ||
|
||
private final List<TranslationResolver> resolvers; | ||
|
||
public PluginTranslationResolver(Plugin plugin) throws Exception { | ||
super(plugin); | ||
|
||
this.resolvers = new ArrayList<>(); | ||
|
||
Plugin loadedPlugin; | ||
|
||
if ((loadedPlugin = Bukkit.getPluginManager().getPlugin("EcoEnchants")) != null) { | ||
resolvers.add(loadResolver(ECO_ENCHANTS_RESOLVER_PATH, loadedPlugin)); | ||
plugin.getLogger().log(Level.INFO, "Loaded resolver for EcoEnchants"); | ||
} | ||
|
||
if ((loadedPlugin = Bukkit.getPluginManager().getPlugin("ExcellentEnchants")) != null) { | ||
resolvers.add(loadResolver(EXCELLENT_ENCHANTS_RESOLVER_PATH, loadedPlugin)); | ||
plugin.getLogger().log(Level.INFO, "Loaded resolver for ExcellentEnchants"); | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable String resolve(LangKeyed<?> langKeyed) { | ||
String result; | ||
|
||
for (var resolver : resolvers) { | ||
if ((result = resolver.resolve(langKeyed)) != null) | ||
return result; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static TranslationResolver loadResolver(String path, Plugin loadedPlugin) throws Exception { | ||
return (TranslationResolver) Class | ||
.forName(path.replace('/', '.')) | ||
.getConstructor(Plugin.class) | ||
.newInstance(loadedPlugin); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...in/java/me/blvckbytes/item_predicate_parser/translation/resolver/TranslationResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters