Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package net.labymod.addons.customnametags;

import java.util.function.Supplier;
import net.labymod.addons.customnametags.legacy.CustomNameTagsLegacyConverter;
import net.labymod.addons.customnametags.listener.ChatReceiveListener;
import net.labymod.addons.customnametags.listener.NameTagBackgroundRenderListener;
import net.labymod.addons.customnametags.listener.PlayerNameTagRenderListener;
import net.labymod.api.Laby;
import net.labymod.api.addon.LabyAddon;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.TextComponent;
Expand Down Expand Up @@ -49,6 +51,8 @@ protected void enable() {
this.registerListener(new NameTagBackgroundRenderListener(this));
this.registerListener(new PlayerNameTagRenderListener(this));

this.registerLegacyConverter(new CustomNameTagsLegacyConverter(this));

if (this.wasLoadedInRuntime()) {
this.reloadTabList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.labymod.addons.customnametags.legacy;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.labymod.addons.customnametags.CustomNameTag;
import net.labymod.addons.customnametags.CustomNameTags;
import net.labymod.addons.customnametags.CustomNameTagsConfiguration;
import net.labymod.api.configuration.converter.LegacyConverter;
import java.util.Map.Entry;

public class CustomNameTagsLegacyConverter extends LegacyConverter<JsonObject> {

private final CustomNameTags addon;

public CustomNameTagsLegacyConverter(CustomNameTags addon) {
super("tags.json", JsonObject.class);

this.addon = addon;
}

@Override
protected void convert(JsonObject jsonObject) {
CustomNameTagsConfiguration configuration = this.addon.configuration();

JsonObject labymodSettings =
this.fromJson(LEGACY_PATH.resolve("LabyMod-3.json"), JsonObject.class);

configuration.enabled().set(
labymodSettings != null
&& labymodSettings.has("tags")
&& labymodSettings.get("tags").getAsBoolean()
);

for (Entry<String, JsonElement> entry : jsonObject.get("tags").getAsJsonObject().entrySet()) {
CustomNameTag tag = CustomNameTag.create(
true,
entry.getValue().getAsString(),
true
);

configuration.getCustomTags().put(entry.getKey(), tag);
}

this.addon.saveConfiguration();
}

@Override
public boolean hasStuffToConvert() {
return this.getValue() != null
&& this.getValue().has("tags")
&& this.getValue().getAsJsonObject("tags").size() != 0;
}
}