mirror of
https://github.com/itHotL/PlayerStats.git
synced 2024-11-26 12:36:16 +01:00
Finished up tab-complete improvements, added "examples" at start of command (#72, #91), changed version number to 1.6
This commit is contained in:
parent
ec13ec51b8
commit
aa8f31c6fb
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.gmail.artemis-the-gr8</groupId>
|
<groupId>com.gmail.artemis-the-gr8</groupId>
|
||||||
<artifactId>PlayerStats</artifactId>
|
<artifactId>PlayerStats</artifactId>
|
||||||
<version>1.5</version>
|
<version>1.6</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -7,13 +7,17 @@ import com.gmail.artemis.the.gr8.playerstats.commands.TabCompleter;
|
|||||||
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
||||||
import com.gmail.artemis.the.gr8.playerstats.listeners.JoinListener;
|
import com.gmail.artemis.the.gr8.playerstats.listeners.JoinListener;
|
||||||
import com.gmail.artemis.the.gr8.playerstats.msg.MessageWriter;
|
import com.gmail.artemis.the.gr8.playerstats.msg.MessageWriter;
|
||||||
|
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
public class Main extends JavaPlugin {
|
||||||
|
|
||||||
private static BukkitAudiences adventure;
|
private static BukkitAudiences adventure;
|
||||||
|
@ -41,33 +41,30 @@ public class TabCompleter implements org.bukkit.command.TabCompleter {
|
|||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
List<String> tabSuggestions = new ArrayList<>();
|
List<String> tabSuggestions = new ArrayList<>();
|
||||||
|
|
||||||
//after typing "stat", suggest a list of viable statistics
|
|
||||||
if (args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
String currentArg = args[args.length -1];
|
String currentArg = args[args.length -1];
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) { //after typing "stat", suggest a list of viable statistics
|
||||||
tabSuggestions = getTabSuggestions(EnumHandler.getStatNames(), args[0]);
|
tabSuggestions = getFirstArgSuggestions(args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//after checking if args[0] is a viable statistic, suggest substatistic OR commandOptions
|
else { //after checking if args[0] is a viable statistic, suggest substatistic OR commandOptions
|
||||||
else {
|
|
||||||
String previousArg = args[args.length -2];
|
String previousArg = args[args.length -2];
|
||||||
|
|
||||||
if (EnumHandler.isStatistic(previousArg)) {
|
if (EnumHandler.isStatistic(previousArg)) {
|
||||||
Statistic stat = EnumHandler.getStatEnum(previousArg);
|
Statistic stat = EnumHandler.getStatEnum(previousArg);
|
||||||
|
|
||||||
if (stat != null) {
|
if (stat != null) {
|
||||||
tabSuggestions = getTabSuggestions(getRelevantList(stat), currentArg);
|
tabSuggestions = getTabSuggestions(getRelevantList(stat), currentArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if previous arg = "player", suggest playerNames
|
//if previous arg = "player"
|
||||||
else if (previousArg.equalsIgnoreCase("player")) {
|
else if (previousArg.equalsIgnoreCase("player")) {
|
||||||
//if args.length-3 is kill_entity or entity_killed_by
|
|
||||||
if (args.length >= 3 && EnumHandler.isEntityStatistic(args[args.length-3])) {
|
if (args.length >= 3 && EnumHandler.isEntityStatistic(args[args.length-3])) {
|
||||||
tabSuggestions = commandOptions;
|
tabSuggestions = commandOptions; //if arg before "player" was entity-stat, suggest commandOptions
|
||||||
}
|
}
|
||||||
else {
|
else { //otherwise "player" is target-flag: suggest playerNames
|
||||||
tabSuggestions = getTabSuggestions(offlinePlayerHandler.getOfflinePlayerNames(), currentArg);
|
tabSuggestions = getTabSuggestions(offlinePlayerHandler.getOfflinePlayerNames(), currentArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,6 +78,13 @@ public class TabCompleter implements org.bukkit.command.TabCompleter {
|
|||||||
return tabSuggestions;
|
return tabSuggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> getFirstArgSuggestions(String currentArg) {
|
||||||
|
List<String> suggestions = EnumHandler.getStatNames();
|
||||||
|
suggestions.add("examples");
|
||||||
|
suggestions.add("help");
|
||||||
|
return getTabSuggestions(suggestions, currentArg);
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> getTabSuggestions(List<String> completeList, String currentArg) {
|
private List<String> getTabSuggestions(List<String> completeList, String currentArg) {
|
||||||
return completeList.stream()
|
return completeList.stream()
|
||||||
.filter(item -> item.toLowerCase().contains(currentArg.toLowerCase()))
|
.filter(item -> item.toLowerCase().contains(currentArg.toLowerCase()))
|
||||||
@ -95,14 +99,12 @@ public class TabCompleter implements org.bukkit.command.TabCompleter {
|
|||||||
case ITEM -> {
|
case ITEM -> {
|
||||||
if (stat == Statistic.BREAK_ITEM) {
|
if (stat == Statistic.BREAK_ITEM) {
|
||||||
return tabCompleteHelper.getItemBrokenSuggestions();
|
return tabCompleteHelper.getItemBrokenSuggestions();
|
||||||
} else if (stat == Statistic.CRAFT_ITEM) {
|
|
||||||
return tabCompleteHelper.getAllItemNames(); //TODO fix
|
|
||||||
} else {
|
} else {
|
||||||
return tabCompleteHelper.getAllItemNames();
|
return tabCompleteHelper.getAllItemNames();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ENTITY -> {
|
case ENTITY -> {
|
||||||
return tabCompleteHelper.getEntityKilledSuggestions();
|
return tabCompleteHelper.getEntitySuggestions();
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
return commandOptions;
|
return commandOptions;
|
||||||
|
@ -11,7 +11,7 @@ import java.util.stream.Collectors;
|
|||||||
public final class TabCompleteHelper {
|
public final class TabCompleteHelper {
|
||||||
|
|
||||||
private static List<String> itemBrokenSuggestions;
|
private static List<String> itemBrokenSuggestions;
|
||||||
private static List<String> entityKilledSuggestions;
|
private static List<String> entitySuggestions;
|
||||||
|
|
||||||
public TabCompleteHelper() {
|
public TabCompleteHelper() {
|
||||||
prepareLists();
|
prepareLists();
|
||||||
@ -29,12 +29,13 @@ public final class TabCompleteHelper {
|
|||||||
return EnumHandler.getBlockNames();
|
return EnumHandler.getBlockNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getEntityKilledSuggestions() {
|
public List<String> getEntitySuggestions() {
|
||||||
return entityKilledSuggestions;
|
return entitySuggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void prepareLists() {
|
private static void prepareLists() {
|
||||||
|
//breaking an item means running its durability negative
|
||||||
itemBrokenSuggestions = Arrays.stream(Material.values())
|
itemBrokenSuggestions = Arrays.stream(Material.values())
|
||||||
.parallel()
|
.parallel()
|
||||||
.filter(Material::isItem)
|
.filter(Material::isItem)
|
||||||
@ -43,7 +44,8 @@ public final class TabCompleteHelper {
|
|||||||
.map(String::toLowerCase)
|
.map(String::toLowerCase)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
entityKilledSuggestions = Arrays.stream(EntityType.values())
|
//the only statistics dealing with entities are killed_entity and entity_killed_by
|
||||||
|
entitySuggestions = Arrays.stream(EntityType.values())
|
||||||
.parallel()
|
.parallel()
|
||||||
.filter(EntityType::isAlive)
|
.filter(EntityType::isAlive)
|
||||||
.map(EntityType::toString)
|
.map(EntityType::toString)
|
||||||
|
@ -13,7 +13,7 @@ import java.io.File;
|
|||||||
public class ConfigHandler {
|
public class ConfigHandler {
|
||||||
|
|
||||||
private static Main plugin;
|
private static Main plugin;
|
||||||
private static double configVersion;
|
private static int configVersion;
|
||||||
|
|
||||||
private File configFile;
|
private File configFile;
|
||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
@ -35,7 +35,7 @@ public class ConfigHandler {
|
|||||||
<p>PlayerStats 1.3: "config-version" is 3. </P>
|
<p>PlayerStats 1.3: "config-version" is 3. </P>
|
||||||
<p>PlayerStats 1.4: "config-version" is 4.</p>*/
|
<p>PlayerStats 1.4: "config-version" is 4.</p>*/
|
||||||
private void checkConfigVersion() {
|
private void checkConfigVersion() {
|
||||||
if (!config.contains("config-version") || config.getDouble("config-version") != configVersion) {
|
if (!config.contains("config-version") || config.getInt("config-version") != configVersion) {
|
||||||
new ConfigUpdateHandler(plugin, configFile, configVersion);
|
new ConfigUpdateHandler(plugin, configFile, configVersion);
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import com.tchristofferson.configupdater.ConfigUpdater;
|
|||||||
public class ConfigUpdateHandler {
|
public class ConfigUpdateHandler {
|
||||||
|
|
||||||
/** Add new key-value pairs to the config without losing comments, using <a href="https://github.com/tchristofferson/Config-Updater">tchristofferson's Config-Updater</a> */
|
/** Add new key-value pairs to the config without losing comments, using <a href="https://github.com/tchristofferson/Config-Updater">tchristofferson's Config-Updater</a> */
|
||||||
public ConfigUpdateHandler(Main plugin, File configFile, double configVersion) {
|
public ConfigUpdateHandler(Main plugin, File configFile, int configVersion) {
|
||||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
|
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
|
||||||
updateTopListDefault(configuration);
|
updateTopListDefault(configuration);
|
||||||
updateDefaultColors(configuration);
|
updateDefaultColors(configuration);
|
||||||
|
@ -16,4 +16,4 @@ public final class FontUtils {
|
|||||||
return (int) Math.round((130.0 - (MinecraftFont.Font.getWidth(displayText) * 1.5))/2);
|
return (int) Math.round((130.0 - (MinecraftFont.Font.getWidth(displayText) * 1.5))/2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -70,13 +70,13 @@ public class StatThread extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Target selection = request.getSelection();
|
|
||||||
long lastCalc = ThreadManager.getLastRecordedCalcTime();
|
long lastCalc = ThreadManager.getLastRecordedCalcTime();
|
||||||
if (lastCalc > 2000) {
|
if (lastCalc > 2000) {
|
||||||
adventure.sender(request.getCommandSender()).sendMessage(
|
adventure.sender(request.getCommandSender()).sendMessage(
|
||||||
messageWriter.waitAMoment(lastCalc > 20000, request.isBukkitConsoleSender()));
|
messageWriter.waitAMoment(lastCalc > 20000, request.isBukkitConsoleSender()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Target selection = request.getSelection();
|
||||||
TextComponent statResult;
|
TextComponent statResult;
|
||||||
try {
|
try {
|
||||||
statResult = switch (selection) {
|
statResult = switch (selection) {
|
||||||
|
@ -12,6 +12,11 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/** This class deals with Bukkit Enumerators. It holds private lists of all
|
||||||
|
block-, item-, entity- and statistic-names, and has one big list of all
|
||||||
|
possible sub-statistic-entries (block/item/entity). It can give the names
|
||||||
|
of all aforementioned enums, check if something is a valid enum constant,
|
||||||
|
and turn a name into its corresponding enum constant. */
|
||||||
public final class EnumHandler {
|
public final class EnumHandler {
|
||||||
|
|
||||||
private final static List<String> blockNames;
|
private final static List<String> blockNames;
|
||||||
@ -50,11 +55,22 @@ public final class EnumHandler {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns all block-names in lowercase */
|
||||||
|
public static List<String> getBlockNames() {
|
||||||
|
return blockNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns all item-names in lowercase*/
|
||||||
public static List<String> getItemNames() {
|
public static List<String> getItemNames() {
|
||||||
return itemNames;
|
return itemNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns corresponding item enum constant for an itemName
|
/** Returns all statistic-names in lowercase */
|
||||||
|
public static List<String> getStatNames() {
|
||||||
|
return statNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the corresponding Material enum constant for an itemName
|
||||||
@param itemName String, case-insensitive
|
@param itemName String, case-insensitive
|
||||||
@return Material enum constant, uppercase */
|
@return Material enum constant, uppercase */
|
||||||
public static @Nullable Material getItemEnum(String itemName) {
|
public static @Nullable Material getItemEnum(String itemName) {
|
||||||
@ -64,12 +80,7 @@ public final class EnumHandler {
|
|||||||
return (item != null && item.isItem()) ? item : null;
|
return (item != null && item.isItem()) ? item : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns all entitytype names in lowercase */
|
/** Returns the corresponding EntityType enum constant for an entityName
|
||||||
public static List<String> getEntityNames() {
|
|
||||||
return entityNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns corresponding EntityType enum constant for an entityName
|
|
||||||
@param entityName String, case-insensitive
|
@param entityName String, case-insensitive
|
||||||
@return EntityType enum constant, uppercase */
|
@return EntityType enum constant, uppercase */
|
||||||
public static @Nullable EntityType getEntityEnum(String entityName) {
|
public static @Nullable EntityType getEntityEnum(String entityName) {
|
||||||
@ -81,12 +92,7 @@ public final class EnumHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns all block names in lowercase */
|
/** Returns the corresponding Material enum constant for a materialName
|
||||||
public static List<String> getBlockNames() {
|
|
||||||
return blockNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns corresponding block enum constant for a materialName
|
|
||||||
@param materialName String, case-insensitive
|
@param materialName String, case-insensitive
|
||||||
@return Material enum constant, uppercase */
|
@return Material enum constant, uppercase */
|
||||||
public static @Nullable Material getBlockEnum(String materialName) {
|
public static @Nullable Material getBlockEnum(String materialName) {
|
||||||
@ -96,6 +102,17 @@ public final class EnumHandler {
|
|||||||
return (block != null && block.isBlock()) ? block : null;
|
return (block != null && block.isBlock()) ? block : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the statistic enum constant, or null if that failed.
|
||||||
|
@param statName String, case-insensitive */
|
||||||
|
public static @Nullable Statistic getStatEnum(@NotNull String statName) {
|
||||||
|
try {
|
||||||
|
return Statistic.valueOf(statName.toUpperCase());
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Checks if string is a valid statistic
|
/** Checks if string is a valid statistic
|
||||||
@param statName String, case-insensitive */
|
@param statName String, case-insensitive */
|
||||||
public static boolean isStatistic(@NotNull String statName) {
|
public static boolean isStatistic(@NotNull String statName) {
|
||||||
@ -108,20 +125,10 @@ public final class EnumHandler {
|
|||||||
statName.equalsIgnoreCase(Statistic.KILL_ENTITY.toString());
|
statName.equalsIgnoreCase(Statistic.KILL_ENTITY.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the names of all general statistics in lowercase */
|
/** Checks if this statistic is a subStatEntry, meaning it is a block, item or entity
|
||||||
public static List<String> getStatNames() {
|
@param statName String, case-insensitive*/
|
||||||
return statNames;
|
public static boolean isSubStatEntry(@NotNull String statName) {
|
||||||
}
|
return subStatNames.contains(statName.toLowerCase());
|
||||||
|
|
||||||
/** Returns the statistic enum constant, or null if that failed.
|
|
||||||
@param statName String, case-insensitive */
|
|
||||||
public static @Nullable Statistic getStatEnum(@NotNull String statName) {
|
|
||||||
try {
|
|
||||||
return Statistic.valueOf(statName.toUpperCase());
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns "block", "entity", "item", or "sub-statistic" if the provided Type is null. */
|
/** Returns "block", "entity", "item", or "sub-statistic" if the provided Type is null. */
|
||||||
@ -135,10 +142,4 @@ public final class EnumHandler {
|
|||||||
}
|
}
|
||||||
return subStat;
|
return subStat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks if this statistic is a subStatEntry, meaning it is a block, item or entity
|
|
||||||
@param statName String, case-insensitive*/
|
|
||||||
public static boolean isSubStatEntry(@NotNull String statName) {
|
|
||||||
return subStatNames.contains(statName.toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
# ------------------------------------------------------------------------------------------------------ #
|
# ------------------------------------------------------------------------------------------------------ #
|
||||||
# PlayerStats Configuration #
|
# PlayerStats Configuration #
|
||||||
# ------------------------------------------------------------------------------------------------------ #
|
# ------------------------------------------------------------------------------------------------------ #
|
||||||
config-version: 5
|
config-version: 6
|
||||||
|
|
||||||
|
|
||||||
# # ------------------------------- # #
|
# # ------------------------------- # #
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
main: com.gmail.artemis.the.gr8.playerstats.Main
|
main: com.gmail.artemis.the.gr8.playerstats.Main
|
||||||
name: PlayerStats
|
name: PlayerStats
|
||||||
version: 1.5
|
version: 1.6
|
||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
description: adds commands to view player statistics in chat
|
description: adds commands to view player statistics in chat
|
||||||
author: Artemis_the_gr8
|
author: Artemis_the_gr8
|
||||||
|
Loading…
Reference in New Issue
Block a user