Skip to content

Commit

Permalink
style: plugin hook message at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
RealRONiN committed Oct 24, 2022
1 parent d9c6a7f commit 4269dd3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 20 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>in.arcadelabs</groupId>
<artifactId>LabAide</artifactId>
<version>2.2</version>
<version>2.3</version>
<packaging>jar</packaging>

<name>LabAide</name>
Expand Down Expand Up @@ -144,7 +144,7 @@
<dependency>
<groupId>dev.dejvokep</groupId>
<artifactId>boosted-yaml</artifactId>
<version>1.2</version>
<version>1.3</version>
</dependency>
</dependencies>
</project>
</project>
20 changes: 3 additions & 17 deletions src/main/java/in/arcadelabs/labaide/LabAide.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import lombok.SneakyThrows;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -41,6 +40,7 @@ public class LabAide extends JavaPlugin {
private final MiniMessage miniMessage = MiniMessage.builder().build();
private final List<Plugin> dependants = new ArrayList<>();
private BStats metrics;
private LabAideHooked hooked;

public static Logger Logger() {
return logger;
Expand All @@ -55,31 +55,17 @@ public void onEnable() {
MiniMessage.miniMessage().deserialize(
"<b><color:#f58066>⌬</color></b> "),
null, null);
hooked = new LabAideHooked(logger);
logger.log(Logger.Level.INFO, MiniMessage.miniMessage().deserialize(
"<b><gradient:#e01e37:#f58c67>" +
"LabAide </gradient><color:#f89999><gradient:#f58c67:#f10f5d>up and functional!" +
"</gradient></b>"));

final List<Plugin> serverPlugins = List.of(Bukkit.getPluginManager().getPlugins());
for (final Plugin plugin : serverPlugins) {
if (plugin.getDescription().getDepend().contains("LabAide")
|| plugin.getDescription().getSoftDepend().contains("LabAide")) dependants.add(plugin);
}
if (!dependants.isEmpty()) {
final String pluralOrNot = dependants.size() > 1 ?
"Hooked into " + dependants.size() + " plugins.\n Dependants: "
+ dependants.toString().substring(1, dependants.toString().length() - 1) :
"Hooked into " + dependants.get(0);
logger.log(Logger.Level.INFO, MiniMessage.miniMessage().deserialize(
"<b><gradient:#e01e37:#f58c67>" + pluralOrNot + "</gradient></b>"));
} else logger.log(Logger.Level.INFO, MiniMessage.miniMessage().deserialize(
"<b><gradient:#e01e37:#f58c67>No <st>plugins</st>partners wanna hook with me," +
" guess you and me are same afterall.</gradient></b>"));
}

@Override
public void onDisable() {
logger.log(Logger.Level.INFO, MiniMessage.miniMessage().deserialize(
"<b><gradient:#f58c67:#f10f5d>Adios...</gradient></b>"));
}
}
}
70 changes: 70 additions & 0 deletions src/main/java/in/arcadelabs/labaide/LabAideHooked.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* LabAide - Common utility library for our products.
* Copyright (C) 2022 ArcadeLabs Production.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package in.arcadelabs.labaide;

import in.arcadelabs.labaide.logger.Logger;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

import java.util.ArrayList;
import java.util.List;

public class LabAideHooked {

private final List<Plugin> dependants = new ArrayList<>();

public LabAideHooked(final Logger logger) {

final Plugin[] serverPlugins = Bukkit.getPluginManager().getPlugins();
for (final Plugin plugin : serverPlugins) {
if (plugin.isEnabled()) {
if (plugin.getDescription().getDepend().contains("LabAide")
|| plugin.getDescription().getSoftDepend().contains("LabAide")) dependants.add(plugin);
}
}
if (!dependants.isEmpty()) {
final String pluralOrNot = dependants.size() > 1 ?
"Hooked into " + dependants.size() + " plugins.\n Dependants: "
+ getPluginList() :
"Hooked into " + dependants.get(0);
logger.log(Logger.Level.INFO, MiniMessage.miniMessage().deserialize(
"<b><gradient:#e01e37:#f58c67>" + pluralOrNot + "</gradient></b>"));
} else logger.log(Logger.Level.INFO, MiniMessage.miniMessage().deserialize(
"<b><gradient:#e01e37:#f58c67>No <st>one</st> plugins wanna hook with me," +
" guess you and me are same afterall.</gradient></b>"));
}

private String getPluginList() {
StringBuilder pluginList = new StringBuilder();
Plugin[] plugins = Bukkit.getPluginManager().getPlugins();

for (Plugin plugin : plugins) {
if (pluginList.length() > 0) {
pluginList.append("<color:#007f5f>");
pluginList.append(", ");
}
if (plugin.isEnabled()) {
if (plugin.getDescription().getDepend().contains("LabAide")
|| plugin.getDescription().getSoftDepend().contains("LabAide")) dependants.add(plugin);
}
}
return pluginList.toString();
}
}

0 comments on commit 4269dd3

Please sign in to comment.