From 984bab74af948d6907c55765207c6f2fa3536eed Mon Sep 17 00:00:00 2001 From: Artemis-the-gr8 Date: Thu, 5 May 2022 02:14:56 +0200 Subject: [PATCH] Started experimenting with statistics and enums, working on the TabCompleter --- pom.xml | 7 +++ .../ConfigHandler.java | 4 +- .../artemis/the/gr8/playerstats/Main.java | 24 +++++++++ .../the/gr8/playerstats/StatManager.java | 4 ++ .../gr8/playerstats/commands/StatCommand.java | 22 +++++++++ .../playerstats/commands/TabCompleter.java | 49 +++++++++++++++++++ .../the/gr8/playerstats/utils/Fancifier.java | 4 ++ .../utils/OfflinePlayerHandler.java} | 6 +-- .../gmail/artemis/the/gr8/statcount/Main.java | 20 -------- .../the/gr8/statcount/StatManager.java | 4 -- .../gr8/statcount/commands/StatCommand.java | 4 -- .../gr8/statcount/commands/TabCompleter.java | 4 -- .../the/gr8/statcount/utils/Fancifier.java | 4 -- src/main/resources/config.yml | 2 + src/main/resources/plugin.yml | 19 ++++++- 15 files changed, 135 insertions(+), 42 deletions(-) rename src/main/java/com/gmail/artemis/the/gr8/{statcount => playerstats}/ConfigHandler.java (91%) create mode 100644 src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java create mode 100644 src/main/java/com/gmail/artemis/the/gr8/playerstats/StatManager.java create mode 100644 src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/StatCommand.java create mode 100644 src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/TabCompleter.java create mode 100644 src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/Fancifier.java rename src/main/java/com/gmail/artemis/the/gr8/{statcount/utils/OfflinePlayerGetter.java => playerstats/utils/OfflinePlayerHandler.java} (87%) delete mode 100644 src/main/java/com/gmail/artemis/the/gr8/statcount/Main.java delete mode 100644 src/main/java/com/gmail/artemis/the/gr8/statcount/StatManager.java delete mode 100644 src/main/java/com/gmail/artemis/the/gr8/statcount/commands/StatCommand.java delete mode 100644 src/main/java/com/gmail/artemis/the/gr8/statcount/commands/TabCompleter.java delete mode 100644 src/main/java/com/gmail/artemis/the/gr8/statcount/utils/Fancifier.java create mode 100644 src/main/resources/config.yml diff --git a/pom.xml b/pom.xml index 52e06bc..3007989 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,13 @@ 1.18-R0.1-SNAPSHOT provided + + + org.jetbrains + annotations + 23.0.0 + compile + diff --git a/src/main/java/com/gmail/artemis/the/gr8/statcount/ConfigHandler.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/ConfigHandler.java similarity index 91% rename from src/main/java/com/gmail/artemis/the/gr8/statcount/ConfigHandler.java rename to src/main/java/com/gmail/artemis/the/gr8/playerstats/ConfigHandler.java index 1a96af8..3dba7e4 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/statcount/ConfigHandler.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/ConfigHandler.java @@ -1,4 +1,4 @@ -package com.gmail.artemis.the.gr8.statcount; +package com.gmail.artemis.the.gr8.playerstats; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -17,7 +17,7 @@ public class ConfigHandler { } //create a config file if none exists yet (from the config.yml in the plugin's resources) - public void saveDefaultConfig() { + private void saveDefaultConfig() { config = plugin.getConfig(); plugin.saveDefaultConfig(); configFile = new File(plugin.getDataFolder(), "config.yml"); diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java new file mode 100644 index 0000000..f5fb71b --- /dev/null +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java @@ -0,0 +1,24 @@ +package com.gmail.artemis.the.gr8.playerstats; + +import com.gmail.artemis.the.gr8.playerstats.commands.StatCommand; +import com.gmail.artemis.the.gr8.playerstats.commands.TabCompleter; +import org.bukkit.plugin.java.JavaPlugin; + +public class Main extends JavaPlugin { + + @Override + public void onEnable() { + + ConfigHandler config = new ConfigHandler(this); + this.getCommand("statistic").setExecutor(new StatCommand()); + this.getCommand("statistic").setTabCompleter(new TabCompleter(this)); + this.getLogger().info("Enabled PlayerStats!"); + } + + @Override + public void onDisable() { + this.getLogger().info("Disabled PlayerStats!"); + } + + +} diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/StatManager.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/StatManager.java new file mode 100644 index 0000000..b103e83 --- /dev/null +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/StatManager.java @@ -0,0 +1,4 @@ +package com.gmail.artemis.the.gr8.playerstats; + +public class StatManager { +} diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/StatCommand.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/StatCommand.java new file mode 100644 index 0000000..5270e6f --- /dev/null +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/StatCommand.java @@ -0,0 +1,22 @@ +package com.gmail.artemis.the.gr8.playerstats.commands; + +import org.bukkit.Statistic; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +public class StatCommand implements CommandExecutor { + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,String label, String[] args) { + + if (label.equalsIgnoreCase("statistic")) { + sender.sendMessage("hello"); + + return true; + } + sender.sendMessage("bye"); + return false; + } +} diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/TabCompleter.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/TabCompleter.java new file mode 100644 index 0000000..3b8c48a --- /dev/null +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/TabCompleter.java @@ -0,0 +1,49 @@ +package com.gmail.artemis.the.gr8.playerstats.commands; + +import com.gmail.artemis.the.gr8.playerstats.Main; +import org.bukkit.Statistic; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class TabCompleter implements org.bukkit.command.TabCompleter { + + private final Main plugin; + public TabCompleter(Main p) { + plugin = p; + } + + @Override + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, String label, String[] args) { + + List allStats = new ArrayList<>(); + int i = 0; + int block = 0; + int entity = 0; + int item = 0; + int untyped = 0; + + if (label.equalsIgnoreCase("statistic")) { + for (Statistic stat : Statistic.values()) { + i++; + if (stat.getType().equals(Statistic.Type.BLOCK)) block++; + if (stat.getType().equals(Statistic.Type.ENTITY)) entity++; + if (stat.getType().equals(Statistic.Type.ITEM)) item++; + if (stat.getType().equals(Statistic.Type.UNTYPED)) untyped++; + + if (args.length == 1 && stat.toString().toLowerCase().startsWith(args[0])) { + allStats.add(stat.toString().toLowerCase()); + } + } + } + plugin.getLogger().info("Total number of statistics: " + i); + plugin.getLogger().info("Block type: " + block); + plugin.getLogger().info("Entity type: " + entity); + plugin.getLogger().info("Item type: " + item); + plugin.getLogger().info("Untyped: " + untyped); + return allStats; + } +} diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/Fancifier.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/Fancifier.java new file mode 100644 index 0000000..14edda7 --- /dev/null +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/Fancifier.java @@ -0,0 +1,4 @@ +package com.gmail.artemis.the.gr8.playerstats.utils; + +public class Fancifier { +} diff --git a/src/main/java/com/gmail/artemis/the/gr8/statcount/utils/OfflinePlayerGetter.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OfflinePlayerHandler.java similarity index 87% rename from src/main/java/com/gmail/artemis/the/gr8/statcount/utils/OfflinePlayerGetter.java rename to src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OfflinePlayerHandler.java index ae2dc77..79adf5b 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/statcount/utils/OfflinePlayerGetter.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OfflinePlayerHandler.java @@ -1,13 +1,13 @@ -package com.gmail.artemis.the.gr8.statcount.utils; +package com.gmail.artemis.the.gr8.playerstats.utils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import java.util.Arrays; -public final class OfflinePlayerGetter { +public final class OfflinePlayerHandler { - private OfflinePlayerGetter() { + private OfflinePlayerHandler() { } public static boolean isOfflinePlayer(String playerName) { diff --git a/src/main/java/com/gmail/artemis/the/gr8/statcount/Main.java b/src/main/java/com/gmail/artemis/the/gr8/statcount/Main.java deleted file mode 100644 index 5036a93..0000000 --- a/src/main/java/com/gmail/artemis/the/gr8/statcount/Main.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gmail.artemis.the.gr8.statcount; - -import org.bukkit.plugin.java.JavaPlugin; - -public class Main extends JavaPlugin { - - @Override - public void onEnable() { - - ConfigHandler config = new ConfigHandler(this); - this.getLogger().info("enabled PlayerStats!"); - } - - @Override - public void onDisable() { - this.getLogger().info("disabled PlayerStats!"); - } - - -} diff --git a/src/main/java/com/gmail/artemis/the/gr8/statcount/StatManager.java b/src/main/java/com/gmail/artemis/the/gr8/statcount/StatManager.java deleted file mode 100644 index 49ad405..0000000 --- a/src/main/java/com/gmail/artemis/the/gr8/statcount/StatManager.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.gmail.artemis.the.gr8.statcount; - -public class StatManager { -} diff --git a/src/main/java/com/gmail/artemis/the/gr8/statcount/commands/StatCommand.java b/src/main/java/com/gmail/artemis/the/gr8/statcount/commands/StatCommand.java deleted file mode 100644 index 5ba610e..0000000 --- a/src/main/java/com/gmail/artemis/the/gr8/statcount/commands/StatCommand.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.gmail.artemis.the.gr8.statcount.commands; - -public class StatCommand { -} diff --git a/src/main/java/com/gmail/artemis/the/gr8/statcount/commands/TabCompleter.java b/src/main/java/com/gmail/artemis/the/gr8/statcount/commands/TabCompleter.java deleted file mode 100644 index ee8d15e..0000000 --- a/src/main/java/com/gmail/artemis/the/gr8/statcount/commands/TabCompleter.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.gmail.artemis.the.gr8.statcount.commands; - -public class TabCompleter { -} diff --git a/src/main/java/com/gmail/artemis/the/gr8/statcount/utils/Fancifier.java b/src/main/java/com/gmail/artemis/the/gr8/statcount/utils/Fancifier.java deleted file mode 100644 index f23606d..0000000 --- a/src/main/java/com/gmail/artemis/the/gr8/statcount/utils/Fancifier.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.gmail.artemis.the.gr8.statcount.utils; - -public class Fancifier { -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..dc4d674 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,2 @@ +# PlayerStats Configuration + diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8e7d733..1aa388e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,4 +4,21 @@ version: 1.0 api-version: 1.18 description: adds commands to view player statistics in chat author: Artemis_the_gr8 - +commands: + statistic: + aliases: + - stat + description: general statistic command + permission: playerstats.stat + statisticreload: + aliases: + - statreload + description: reloads the config + permission: playerstats.admin +permissions: + playerstats.stat: + description: lowest permission level + default: op + playerstats.admin: + description: allows config and scoreboard related things + default: op \ No newline at end of file