add messageComponent that takes a component parameter

This commit is contained in:
Taah 2022-05-07 17:34:41 -07:00
parent 884a4ed1ec
commit 5e1475dfb5

View File

@ -71,21 +71,18 @@ public class PlexUtils implements PlexBase
if (Plex.get().getStorageType() == StorageType.MARIADB) if (Plex.get().getStorageType() == StorageType.MARIADB)
{ {
PlexLog.log("Successfully enabled MySQL!"); PlexLog.log("Successfully enabled MySQL!");
} } else if (Plex.get().getStorageType() == StorageType.SQLITE)
else if (Plex.get().getStorageType() == StorageType.SQLITE)
{ {
PlexLog.log("Successfully enabled SQLite!"); PlexLog.log("Successfully enabled SQLite!");
} }
} } catch (SQLException e)
catch (SQLException e)
{ {
if (Plex.get().getMongoConnection().getDatastore() != null) if (Plex.get().getMongoConnection().getDatastore() != null)
{ {
PlexLog.log("Successfully enabled MongoDB!"); PlexLog.log("Successfully enabled MongoDB!");
} }
} }
} } else
else
{ {
if (Plex.get().getMongoConnection().getDatastore() != null) if (Plex.get().getMongoConnection().getDatastore() != null)
{ {
@ -145,6 +142,17 @@ public class PlexUtils implements PlexBase
return MINI_MESSAGE.deserialize(messageString(entry, objects)); return MINI_MESSAGE.deserialize(messageString(entry, objects));
} }
public static Component messageComponent(String entry, Component... objects)
{
Component component = MINI_MESSAGE.deserialize(messageString(entry));
for (int i = 0; i < objects.length; i++)
{
int finalI = i;
component = component.replaceText(builder -> builder.matchLiteral("{" + finalI + "}").replacement(objects[finalI]).build());
}
return component;
}
public static String messageString(String entry, Object... objects) public static String messageString(String entry, Object... objects)
{ {
String f = plugin.messages.getString(entry); String f = plugin.messages.getString(entry);
@ -165,8 +173,7 @@ public class PlexUtils implements PlexBase
try try
{ {
return ((TextComponent) component).content(); return ((TextComponent) component).content();
} } catch (Exception e)
catch (Exception e)
{ {
PlexLog.warn("Unable to get text of component", e.getLocalizedMessage()); PlexLog.warn("Unable to get text of component", e.getLocalizedMessage());
return ""; return "";
@ -185,8 +192,7 @@ public class PlexUtils implements PlexBase
} }
return builder.toString(); return builder.toString();
} } catch (Exception e)
catch (Exception e)
{ {
PlexLog.warn("Unable to get text of components", e.getLocalizedMessage()); PlexLog.warn("Unable to get text of components", e.getLocalizedMessage());
return ""; return "";