completions = new ArrayList<>();
+ completions.add("menu");
+
+ if (sender.hasPermission("customstats.reload")) {
+ completions.add("reload");
+ }
+ return completions;
+ }
+}
diff --git a/src/main/java/me/stats/CustomStats/bStats/Metrics.java b/src/main/java/me/gamersclub/customstats/bStats/Metrics.java
similarity index 99%
rename from src/main/java/me/stats/CustomStats/bStats/Metrics.java
rename to src/main/java/me/gamersclub/customstats/bStats/Metrics.java
index 99067e9..56916f1 100644
--- a/src/main/java/me/stats/CustomStats/bStats/Metrics.java
+++ b/src/main/java/me/gamersclub/customstats/bStats/Metrics.java
@@ -1,4 +1,4 @@
-package me.stats.CustomStats.bStats;
+package me.gamersclub.customstats.bStats;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@@ -29,7 +29,7 @@
/**
* bStats collects some data for plugin authors.
*
- * Check out https://bStats.org/ to learn more about bStats!
+ * Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics {
@@ -730,4 +730,4 @@ protected JsonObject getChartData() throws Exception {
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/gamersclub/customstats/menus/StatForm.java b/src/main/java/me/gamersclub/customstats/menus/StatForm.java
new file mode 100644
index 0000000..04d9ca6
--- /dev/null
+++ b/src/main/java/me/gamersclub/customstats/menus/StatForm.java
@@ -0,0 +1,37 @@
+package me.gamersclub.customstats.menus;
+
+import me.gamersclub.customstats.util.PlaceholderManager;
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.geysermc.cumulus.component.LabelComponent;
+import org.geysermc.cumulus.form.CustomForm;
+import org.geysermc.floodgate.api.FloodgateApi;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
+
+public class StatForm {
+ @SuppressWarnings("CanBeFinal")
+ private CustomForm.Builder statForm = CustomForm.builder();
+
+ public StatForm(@NotNull JavaPlugin plugin, @NotNull PlaceholderManager pManager, @NotNull Player player) {
+ String title = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("stats.stat-form.title")));
+ List content = Objects.requireNonNull(plugin.getConfig().getStringList("stats.stat-form.content"));
+
+ statForm.component(LabelComponent.of(title));
+
+ for (String message : content) {
+ message = pManager.placeholderReplacer(player, message);
+ statForm.component(LabelComponent.of(ChatColor.translateAlternateColorCodes('&', message)));
+ }
+
+ statForm.build();
+ }
+
+ public void sendStatForm(@NotNull UUID uuid) {
+ FloodgateApi.getInstance().getPlayer(uuid).sendForm(statForm);
+ }
+}
diff --git a/src/main/java/me/gamersclub/customstats/util/PlaceholderManager.java b/src/main/java/me/gamersclub/customstats/util/PlaceholderManager.java
new file mode 100644
index 0000000..bda5367
--- /dev/null
+++ b/src/main/java/me/gamersclub/customstats/util/PlaceholderManager.java
@@ -0,0 +1,37 @@
+package me.gamersclub.customstats.util;
+
+import me.clip.placeholderapi.PlaceholderAPI;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class PlaceholderManager {
+ static JavaPlugin plugin;
+ @SuppressWarnings("CanBeFinal")
+ boolean papiInstalled;
+
+ public PlaceholderManager(JavaPlugin plugin) {
+ this.plugin = plugin;
+ this.papiInstalled = plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI");
+ }
+
+ public String placeholderReplacer(Player player, String message) {
+ //handle our own placeholders first
+ message = message.replaceAll("%totalplayers%",totalPlayers()+"");
+ message = message.replaceAll("%onlineplayers",onlinePlayers()+"");
+
+ //handle PlaceholderAPI placeholders after our own
+ if (papiInstalled) {
+ message = PlaceholderAPI.setPlaceholders(player, message);
+ }
+
+ return message;
+ }
+
+ public int totalPlayers() {
+ return plugin.getServer().getOfflinePlayers().length;
+ }
+
+ public int onlinePlayers() {
+ return plugin.getServer().getOnlinePlayers().size();
+ }
+}
diff --git a/src/main/java/me/stats/CustomStats/UpdateChecker.java b/src/main/java/me/gamersclub/customstats/util/UpdateChecker.java
similarity index 85%
rename from src/main/java/me/stats/CustomStats/UpdateChecker.java
rename to src/main/java/me/gamersclub/customstats/util/UpdateChecker.java
index 126c273..08f3a60 100644
--- a/src/main/java/me/stats/CustomStats/UpdateChecker.java
+++ b/src/main/java/me/gamersclub/customstats/util/UpdateChecker.java
@@ -1,4 +1,4 @@
-package me.stats.CustomStats;
+package me.gamersclub.customstats.util;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
@@ -23,7 +23,7 @@ public void getVersion(final Consumer consumer) {
consumer.accept(scanner.next());
}
} catch (IOException exception) {
- this.plugin.getLogger().info("Cannot check for updates: " + exception.getMessage());
+ this.plugin.getLogger().warning("Cannot check for updates: " + exception.getMessage());
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/stats/CustomStats/CustomStats.java b/src/main/java/me/stats/CustomStats/CustomStats.java
deleted file mode 100644
index b098ff2..0000000
--- a/src/main/java/me/stats/CustomStats/CustomStats.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package me.stats.CustomStats;
-
-import me.stats.CustomStats.bStats.Metrics;
-import org.bukkit.plugin.java.JavaPlugin;
-
-import java.util.HashMap;
-import java.util.Objects;
-import java.util.UUID;
-import java.util.logging.Logger;
-
-public class CustomStats extends JavaPlugin {
- HashMap opengui = new HashMap<>();
- private Logger console;
- public void onEnable() {
- Objects.requireNonNull(getCommand("stats")).setExecutor(new StatsCommand(this));
- getServer().getPluginManager().registerEvents(new GuiListener(this), this);
- console = getLogger();
- console.info("Loading config.");
- saveDefaultConfig();
- console.info("Config loaded!");
- new Metrics(this, 10123);
- console.info("Checking for a newer version.");
- new UpdateChecker(this, 88300).getVersion(version -> {
- if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
- console.info("You are up to date! (v1.2.1)");
- } else {
- console.info("There is a new update available. Download it at https://www.spigotmc.org/resources/customstats.88300/!");
- }
- });
- console.info("Successfully started!");
- }
-}
diff --git a/src/main/java/me/stats/CustomStats/GuiListener.java b/src/main/java/me/stats/CustomStats/GuiListener.java
deleted file mode 100644
index b6f811a..0000000
--- a/src/main/java/me/stats/CustomStats/GuiListener.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package me.stats.CustomStats;
-
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.inventory.InventoryClickEvent;
-import org.bukkit.event.inventory.InventoryCloseEvent;
-
-public class GuiListener implements Listener {
- CustomStats customStats;
- public GuiListener(CustomStats customStats) {
- this.customStats = customStats;
- }
- @EventHandler
- public void clickevent(InventoryClickEvent e){
- if (customStats.opengui.get(e.getWhoClicked().getUniqueId()).equals(1)){
- e.setCancelled(true);
- }
- }
- @EventHandler
- public void onInventoryClose(InventoryCloseEvent e){
- customStats.opengui.put(e.getPlayer().getUniqueId(), 0);
- }
-}
diff --git a/src/main/java/me/stats/CustomStats/StatsCommand.java b/src/main/java/me/stats/CustomStats/StatsCommand.java
deleted file mode 100644
index feb2ea7..0000000
--- a/src/main/java/me/stats/CustomStats/StatsCommand.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package me.stats.CustomStats;
-
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.Material;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.TabExecutor;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.ItemMeta;
-import java.util.ArrayList;
-import java.util.List;
-
-public class StatsCommand implements CommandExecutor, TabExecutor {
- CustomStats customStats;
- public StatsCommand(CustomStats customStats) {
- this.customStats = customStats;
- }
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
- if (sender instanceof Player) {
- Player p = (Player) sender;
- if (args.length == 1){
- if (args[0].equals("reload")){
- // Checks for permission
- if (p.hasPermission("customstats.reload")){
- customStats.reloadConfig();
- customStats.saveConfig();
- customStats.getConfig();
- p.sendMessage(ChatColor.GREEN+"Configuration reloaded!");
- }
- else {
- p.sendMessage(ChatColor.RED+"Usage: /stats");
- }
- }
- else if (args[0].equals("gui")){
- Inventory gui = Bukkit.createInventory(p, 9, ChatColor.translateAlternateColorCodes('&', customStats.getConfig().getString("statsgui.title")));
- for (int i = 1; i < 10; i++){
- if (customStats.getConfig().contains("statsgui.item"+i)){
- List statsgui = customStats.getConfig().getStringList("statsgui.item"+i);
- ItemStack item = new ItemStack(Material.valueOf(statsgui.get(0).toUpperCase()), 1);
- if (item.getType() != Material.AIR){
- ItemMeta meta = item.getItemMeta();
- meta.setDisplayName(ChatColor.translateAlternateColorCodes('&',statsgui.get(1)));
- item.setItemMeta(meta);
- }
- gui.setItem(i-1, item);
- }
- else{
- gui.clear(i-1);
- i++;
- }
- }
- p.openInventory(gui);
- customStats.opengui.put(p.getUniqueId(), 1);
- }
- else {
- p.sendMessage(ChatColor.RED+"Usage: /stats");
- }
- }
- if (args.length>1){
- p.sendMessage(ChatColor.RED+"Usage: /stats");
- }
- else if (args.length == 0){
- List statcommand = customStats.getConfig().getStringList("statscommand");
- //color code is &
- for (int i = 0; i onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
- return new ArrayList<>();
- }
-}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 9332c30..b0981f7 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -1,24 +1,62 @@
-# FORMAT FOR GUI ITEMS:
-# item(1-9):
-# - (Item type)
-# - '(display name)'
-# Max 9 slots, must be in order. Set item type to air to leave blank.
-#
-statscommand:
- - '&a-----------------------------------------------------'
- - '&6This server was created on February 1, 2021.'
- - '&6The world is 12.34GB in size.'
- - '&6Over 1,234 players have joined since.'
- - '&a-----------------------------------------------------'
-statsgui:
- title:
- - '&3Server Stats GUI&0'
- item1:
- - book
- - '&6This server was created on February 1, 2021.'
- item2:
- - grass_block
- - '&6The world is 12.34GB in size.'
- item3:
- - player_head
- - '&6Over 1,234 players have joined since.'
+# CustomStats v2.0.0
+# More detailed information on how to edit the configuration can be found on the wiki:
+# https://7man7lmyt.github.io/CustomStats/
+
+
+
+# New with v2.0.0: Placeholders
+
+# The plugin supports PlaceholderAPI placeholders, as well as its own built in ones.
+# Note: Placeholders that require a player will not work in the /stats command.
+# Built in placeholders:
+# %totalplayers% - How many unique players have joined the server
+# %onlineplayers% - How many players are currently online.
+
+stats:
+ stat-command:
+ - "&a-----------------------------------------------------"
+ - "&6This server was created on July 30, 2022."
+ - "&6The world is 12.34GB in size."
+ - "&6%totalplayers% unique players have joined since."
+ - "&a-----------------------------------------------------"
+
+ # Customize the menu sent to Minecraft: Java Edition clients.
+ stat-menu:
+ # Format for adding more items to the GUI:
+ # (0-53):
+ # - (Item type)
+ # - "(display name)"
+ # - "(item lore)"
+ # - "(more item lore)"
+
+ # Maximum inventory slots are limited by 'menu-size'.
+ # The items are not required to be in order.
+ # Either set the item type to air or remove the slot to leave blank.
+ # Slot #0 is an exception, you have to set it to air if you wish to set nothing in the slot.
+
+ # Must be a multiple of 9.
+ menu-size: 9
+
+ title: "&3Server Stats Menu"
+ items:
+ 0:
+ - book
+ - "&6This server was created on July 30, 2022."
+ - "&6The world is 12.34GB in size."
+ - "&6%totalplayers% unique players have joined since."
+
+ # Customize the form sent to Minecraft: Bedrock Edition clients. (Will only work if you have GeyserMC + Floodgate!)
+ stat-form:
+ # Format for adding more lines to the form:
+ # content:
+ # - "&6This text is gold!"
+ # - "&lThis text is bold!"
+ # - "&0R&1a&2i&3n&4b&5o&6w &7C&8o&9l&ao&br&cs&d!&e!&f!
+
+ title: "&3Server Stats Menu"
+ content:
+ - "&a--------------------------------"
+ - "&6This server was created on July 30, 2022."
+ - "&6The world is 12.34GB in size."
+ - "&6%totalplayers% unique players have joined since."
+ - "&a--------------------------------"
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 4272ef8..77a311d 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,10 +1,18 @@
name: CustomStats
-version: 1.2.1
-main: me.stats.CustomStats.CustomStats
+version: 2.0.0
+main: me.gamersclub.customstats.CustomStats
author: 7man7LMYT
website: https://discord.gg/Z5MyDwp
description: An anarchy server oriented plugin that adds /stats.
+
+permissions:
+ customstats.reload:
+ default: op
+softdepend:
+ - floodgate
+ - PlaceholderAPI
api-version: 1.13
+
commands:
stats:
description: Command to give information about the server.