Started experimenting with statistics and enums, working on the TabCompleter

This commit is contained in:
Artemis-the-gr8 2022-05-05 02:14:56 +02:00
parent 1dba7092b4
commit 984bab74af
15 changed files with 135 additions and 42 deletions

View File

@ -22,6 +22,13 @@
<version>1.18-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>

View File

@ -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");

View File

@ -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!");
}
}

View File

@ -0,0 +1,4 @@
package com.gmail.artemis.the.gr8.playerstats;
public class StatManager {
}

View File

@ -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;
}
}

View File

@ -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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, String label, String[] args) {
List<String> 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;
}
}

View File

@ -0,0 +1,4 @@
package com.gmail.artemis.the.gr8.playerstats.utils;
public class Fancifier {
}

View File

@ -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) {

View File

@ -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!");
}
}

View File

@ -1,4 +0,0 @@
package com.gmail.artemis.the.gr8.statcount;
public class StatManager {
}

View File

@ -1,4 +0,0 @@
package com.gmail.artemis.the.gr8.statcount.commands;
public class StatCommand {
}

View File

@ -1,4 +0,0 @@
package com.gmail.artemis.the.gr8.statcount.commands;
public class TabCompleter {
}

View File

@ -1,4 +0,0 @@
package com.gmail.artemis.the.gr8.statcount.utils;
public class Fancifier {
}

View File

@ -0,0 +1,2 @@
# PlayerStats Configuration

View File

@ -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