more explicit logging

This commit is contained in:
2024-10-23 11:52:22 +02:00
parent 325a997f8f
commit e693ad141f
2 changed files with 15 additions and 5 deletions
@@ -16,23 +16,28 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.logging.Logger;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public class EnchantioBootstrap implements PluginBootstrap { public class EnchantioBootstrap implements PluginBootstrap {
private final Logger logger = Logger.getLogger("enchantio");
@Override @Override
public void bootstrap(@NotNull BootstrapContext context) { public void bootstrap(@NotNull BootstrapContext context) {
EnchantioConfig config; EnchantioConfig config;
try { try {
config = new EnchantioConfig(context.getDataDirectory()); config = new EnchantioConfig(context.getDataDirectory(), logger);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Set<EnchantioEnchant> enchantioEnchants = config.enchants; Set<EnchantioEnchant> enchantioEnchants = config.enchants;
logger.info("Registering supported item tags");
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM).newHandler((event) -> { context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM).newHandler((event) -> {
for (EnchantioEnchant enchant : enchantioEnchants) { for (EnchantioEnchant enchant : enchantioEnchants) {
logger.info("Registering item tag " + enchant.getTagForSupportedItems().key());
event.registrar().addToTag( event.registrar().addToTag(
ItemTypeTagKeys.create(enchant.getTagForSupportedItems().key()), ItemTypeTagKeys.create(enchant.getTagForSupportedItems().key()),
enchant.getSupportedItems() enchant.getSupportedItems()
@@ -42,6 +47,7 @@ public class EnchantioBootstrap implements PluginBootstrap {
context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.freeze().newHandler(event -> { context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.freeze().newHandler(event -> {
for (EnchantioEnchant enchant : enchantioEnchants) { for (EnchantioEnchant enchant : enchantioEnchants) {
logger.info("Registering enchantment " + enchant.getKey());
event.registry().register(TypedKey.create(RegistryKey.ENCHANTMENT, enchant.getKey()), enchantment -> { event.registry().register(TypedKey.create(RegistryKey.ENCHANTMENT, enchant.getKey()), enchantment -> {
enchantment.description(enchant.getDescription()); enchantment.description(enchant.getDescription());
enchantment.anvilCost(enchant.getAnvilCost()); enchantment.anvilCost(enchant.getAnvilCost());
@@ -59,6 +65,7 @@ public class EnchantioBootstrap implements PluginBootstrap {
Set<TagEntry<Enchantment>> enchantTags = new HashSet<>(enchantioEnchants.size()); Set<TagEntry<Enchantment>> enchantTags = new HashSet<>(enchantioEnchants.size());
for (EnchantioEnchant enchant : enchantioEnchants) { for (EnchantioEnchant enchant : enchantioEnchants) {
if (!enchant.canGetFromEnchantingTable()) continue; if (!enchant.canGetFromEnchantingTable()) continue;
logger.info("Registering enchantment " + enchant.getKey() + " to enchanting table possibilities");
enchantTags.add(enchant.getTagEntry()); enchantTags.add(enchant.getTagEntry());
} }
event.registrar().addToTag(EnchantmentTagKeys.IN_ENCHANTING_TABLE, enchantTags); event.registrar().addToTag(EnchantmentTagKeys.IN_ENCHANTING_TABLE, enchantTags);
@@ -22,13 +22,16 @@ import java.nio.file.Path;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Logger;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public class EnchantioConfig { public class EnchantioConfig {
public final Set<EnchantioEnchant> enchants = new HashSet<>(); public final Set<EnchantioEnchant> enchants = new HashSet<>();
private final Logger logger;
protected EnchantioConfig(Path filePath) throws IOException { protected EnchantioConfig(Path filePath, Logger logger) throws IOException {
this.logger = logger;
File file = filePath.toFile(); File file = filePath.toFile();
if (!file.exists()) { if (!file.exists()) {
@@ -152,7 +155,7 @@ public class EnchantioConfig {
if (itemTag.startsWith("#")) { if (itemTag.startsWith("#")) {
itemTag = itemTag.substring(1); itemTag = itemTag.substring(1);
} else { } else {
System.out.println("Only item tags are supported for now, item tags need to begin with #"); logger.warning("Only item tags are supported for now, item tags need to begin with #");
continue; continue;
} }
try { try {
@@ -161,7 +164,7 @@ public class EnchantioConfig {
TagEntry<ItemType> tagEntry = TagEntry.tagEntry(tagKey); TagEntry<ItemType> tagEntry = TagEntry.tagEntry(tagKey);
supportedItemTags.add(tagEntry); supportedItemTags.add(tagEntry);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.out.println("Failed to create tag entry for " + itemTag); logger.warning("Failed to create tag entry for " + itemTag);
} }
} }
return supportedItemTags; return supportedItemTags;