Initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>PluginViewer</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Utils</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.crankedpvp.pluginviewer;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.pluginviewer.inventory.PluginViewerInventory;
|
||||
import net.crankedpvp.pluginviewer.listeners.PluginsCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class PluginViewerPlugin extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private PluginViewerInventory pluginViewerInventory;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.pluginViewerInventory = new PluginViewerInventory(this);
|
||||
this.getServer().getScheduler().runTaskLater(this, () -> this.getServer().getPluginManager().registerEvents(new PluginsCommand(this), this), 5 * 20L);
|
||||
}
|
||||
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package net.crankedpvp.pluginviewer.inventory;
|
||||
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
||||
import net.crankedpvp.crankedutils.utils.GuiUtil;
|
||||
import net.crankedpvp.crankedutils.utils.SortUtils;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.pluginviewer.PluginViewerPlugin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PluginViewerInventory {
|
||||
|
||||
private final PaginatedGui pluginViewerInventory;
|
||||
|
||||
public PaginatedGui getUI() {
|
||||
return this.pluginViewerInventory;
|
||||
}
|
||||
|
||||
public PluginViewerInventory(PluginViewerPlugin mainClass) {
|
||||
this.pluginViewerInventory = GuiUtil.setupGui(new PaginatedGui(6, 28, "Plugins"));
|
||||
this.pluginViewerInventory.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
|
||||
List<Plugin> plugins = Arrays.asList(mainClass.getServer().getPluginManager().getPlugins());
|
||||
plugins.sort(Comparator.comparing(Plugin::getName));
|
||||
for(Plugin plugin : plugins) {
|
||||
boolean enabled = plugin.isEnabled();
|
||||
Material material = enabled? Material.SLIME_BALL : Material.FIREBALL;
|
||||
String name = enabled ? "&a&l" + plugin.getName() : "&c&l" + plugin.getName();
|
||||
ItemBuilder itemBuilder = new ItemBuilder(material, name);
|
||||
PluginDescriptionFile pluginDescriptionFile = plugin.getDescription();
|
||||
if(!pluginDescriptionFile.getAuthors().isEmpty()) itemBuilder.addLoreLine(enabled ? "&aAuthor(s): &f" + getStringFromList(pluginDescriptionFile.getAuthors()) : "&cAuthor(s): &f" + getStringFromList(pluginDescriptionFile.getAuthors()));
|
||||
if(pluginDescriptionFile.getVersion() != null) itemBuilder.addLoreLine(enabled ? "&aVersion: &f" + pluginDescriptionFile.getVersion() : "&cVersion: &f" + pluginDescriptionFile.getVersion());
|
||||
if(pluginDescriptionFile.getWebsite() != null) itemBuilder.addLoreLine(enabled ? "&aWebsite: &f" + pluginDescriptionFile.getWebsite() : "&cWebsite: &f" + pluginDescriptionFile.getWebsite());
|
||||
if(pluginDescriptionFile.getDescription() != null) itemBuilder.addLoreLine(enabled ? "&aDescription: &f" + pluginDescriptionFile.getDescription() : "&cDescription: &f" + pluginDescriptionFile.getDescription());
|
||||
|
||||
this.pluginViewerInventory.addItem(new GuiItem(itemBuilder.colorize().build()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getStringFromList(List<String> list) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for(String s : list) {
|
||||
stringBuilder.append(s).append(" ");
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.crankedpvp.pluginviewer.listeners;
|
||||
|
||||
import net.crankedpvp.pluginviewer.PluginViewerPlugin;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class PluginsCommand implements Listener {
|
||||
|
||||
private final PluginViewerPlugin plugin;
|
||||
|
||||
public PluginsCommand(PluginViewerPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cmdPreProcessEvent(PlayerCommandPreprocessEvent event) {
|
||||
if(event.getMessage().equals("/plugins")) {
|
||||
event.setCancelled(true);
|
||||
if(!event.getPlayer().hasPermission("*")) return;
|
||||
if(event.getPlayer().isOp()) this.plugin.getPluginViewerInventory().getUI().open(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
name: CrankedPluginViewer
|
||||
main: net.crankedpvp.pluginviewer.PluginViewerPlugin
|
||||
version: ${git.total.commit.count}.0
|
||||
description: "§fCommit ID: §a${git.commit.id.abbrev}"
|
||||
website: https://crankedpvp.net/
|
||||
depend:
|
||||
- CrankedUtils
|
||||
- CrankedCore
|
||||
softdepend:
|
||||
- zzzzzz
|
||||
Reference in New Issue
Block a user