use of com.willfp.ecoenchants.enchantments.EcoEnchant in project EcoEnchants by Auxilor.
the class CommandLocaleDownload method onExecute.
@Override
public void onExecute(@NotNull final CommandSender sender, @NotNull final List<String> args) {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-locale"));
return;
}
Paste paste = Paste.getFromHastebin(args.get(0));
if (paste == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-locale"));
return;
}
String contents = paste.getContents();
Config configuration = new TransientConfig(contents, ConfigType.YAML);
for (String key : configuration.getKeys(true)) {
this.getPlugin().getLangYml().set(key, configuration.get(key));
}
try {
this.getPlugin().getLangYml().save();
this.getPlugin().getLangYml().clearCache();
for (EcoEnchant value : EcoEnchants.values()) {
value.getConfig().loadFromLang();
value.getConfig().save();
value.getConfig().clearCache();
}
} catch (IOException e) {
e.printStackTrace();
}
sender.sendMessage(this.getPlugin().getLangYml().getMessage("downloaded-locale"));
}
use of com.willfp.ecoenchants.enchantments.EcoEnchant in project EcoEnchants by Auxilor.
the class EnchantmentUtils method unregister.
/**
* Unregister enchantment with the server.
*
* @param enchantment The enchantment.
*/
public static void unregister(@NotNull final Enchantment enchantment) {
try {
Field byIdField = Enchantment.class.getDeclaredField("byKey");
Field byNameField = Enchantment.class.getDeclaredField("byName");
byIdField.setAccessible(true);
byNameField.setAccessible(true);
Map<NamespacedKey, Enchantment> byKey = (Map<NamespacedKey, Enchantment>) byIdField.get(null);
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
byKey.remove(enchantment.getKey());
byName.remove(enchantment.getName());
if (enchantment instanceof EcoEnchant) {
byName.remove(((EcoEnchant) enchantment).getDisplayName());
}
Map<String, Enchantment> byNameClone = new HashMap<>(byName);
for (Map.Entry<String, Enchantment> entry : byNameClone.entrySet()) {
if (entry.getValue().getKey().equals(enchantment.getKey())) {
byName.remove(entry.getKey());
}
}
Field f = Enchantment.class.getDeclaredField("acceptingNew");
f.setAccessible(true);
f.set(null, true);
f.setAccessible(false);
} catch (NoSuchFieldException | IllegalAccessException ignored) {
}
}
use of com.willfp.ecoenchants.enchantments.EcoEnchant in project EcoEnchants by Auxilor.
the class EnchantmentUtils method registerPlaceholders.
/**
* Register the placeholders for an enchantment.
*
* @param enchantment The enchantment to register placeholders for.
*/
public static void registerPlaceholders(@NotNull final EcoEnchant enchantment) {
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(enchantment.getPlugin(), enchantment.getPermissionName() + "_" + "enabled", player -> String.valueOf(enchantment.isEnabled())));
enchantment.getConfig().getKeys(true).forEach(string -> {
String key = string.replace(".", "_").replace("-", "_");
Object object = enchantment.getConfig().get(string);
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(enchantment.getPlugin(), enchantment.getPermissionName() + "_" + key, player -> StringUtils.internalToString(object)));
});
}
use of com.willfp.ecoenchants.enchantments.EcoEnchant in project EcoEnchants by Auxilor.
the class EcoEnchantsPlugin method handleReloadAdditional.
@Override
public void handleReloadAdditional() {
this.getDisplayModule().update();
for (EcoEnchant enchant : EcoEnchants.values()) {
HandlerList.unregisterAll(enchant);
this.getScheduler().runLater(() -> {
if (enchant.isEnabled()) {
this.getEventManager().registerListener(enchant);
if (enchant instanceof TimedRunnable) {
this.getScheduler().syncRepeating((TimedRunnable) enchant, 5, ((TimedRunnable) enchant).getTime());
}
}
}, 1);
}
this.getScheduler().runTimer(() -> {
for (EcoEnchant enchant : EcoEnchants.values()) {
enchant.clearCachedRequirements();
}
}, 300, 300);
}
use of com.willfp.ecoenchants.enchantments.EcoEnchant in project EcoEnchants by Auxilor.
the class CommandLocaleExport method onExecute.
@Override
public void onExecute(@NotNull final CommandSender sender, @NotNull final List<String> args) {
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(new StringReader(this.getPlugin().getLangYml().toPlaintext()));
for (EcoEnchant enchant : EcoEnchants.values()) {
configuration.set("enchantments." + enchant.getKey().getKey() + ".name", enchant.getConfig().getHandle().getString("name"));
configuration.set("enchantments." + enchant.getKey().getKey() + ".description", enchant.getConfig().getHandle().getString("description"));
}
Paste paste = new Paste(configuration.saveToString());
paste.getHastebinToken(token -> {
if (token.length() > 15) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("export-failed"));
} else {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("link-to-locale").replace("%token%", token));
}
});
}
Aggregations