mirror of
https://github.com/itHotL/PlayerStats.git
synced 2024-11-22 11:55:17 +01:00
Added filter for EntityType::isAlive
This commit is contained in:
parent
87e3d30eb1
commit
776862d396
@ -5,8 +5,10 @@ import com.gmail.artemis.the.gr8.playerstats.commands.StatCommand;
|
||||
import com.gmail.artemis.the.gr8.playerstats.commands.TabCompleter;
|
||||
import com.gmail.artemis.the.gr8.playerstats.commands.cmdutils.TabCompleteHelper;
|
||||
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.DebugLevel;
|
||||
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.utils.MyLogger;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@ -39,6 +41,7 @@ public class Main extends JavaPlugin {
|
||||
//initialize the threadManager
|
||||
ThreadManager threadManager = new ThreadManager(adventure(), config, messageWriter, this);
|
||||
TabCompleteHelper tab = new TabCompleteHelper();
|
||||
Bukkit.getLogger().info(tab.getEntityKilledSuggestions().toString());
|
||||
|
||||
//register all commands and the tabCompleter
|
||||
PluginCommand statcmd = this.getCommand("statistic");
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.commands;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.commands.cmdutils.TabCompleteHelper;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||
import org.bukkit.Statistic;
|
||||
@ -14,6 +15,7 @@ import java.util.stream.Collectors;
|
||||
public class TabCompleter implements org.bukkit.command.TabCompleter {
|
||||
|
||||
private final List<String> commandOptions;
|
||||
private final TabCompleteHelper tabCompleteHelper;
|
||||
|
||||
//TODO add "example" to the list
|
||||
public TabCompleter() {
|
||||
@ -22,6 +24,8 @@ public class TabCompleter implements org.bukkit.command.TabCompleter {
|
||||
commandOptions.add("player");
|
||||
commandOptions.add("server");
|
||||
commandOptions.add("me");
|
||||
|
||||
tabCompleteHelper = new TabCompleteHelper();
|
||||
}
|
||||
|
||||
//args[0] = statistic (length = 1)
|
||||
@ -49,18 +53,13 @@ public class TabCompleter implements org.bukkit.command.TabCompleter {
|
||||
Statistic stat = EnumHandler.getStatEnum(previousArg);
|
||||
|
||||
if (stat != null) {
|
||||
tabSuggestions = switch (stat.getType()) {
|
||||
case UNTYPED -> commandOptions;
|
||||
case BLOCK -> getTabSuggestions(EnumHandler.getBlockNames(), currentArg);
|
||||
case ITEM -> getTabSuggestions(EnumHandler.getItemNames(), currentArg);
|
||||
case ENTITY -> getTabSuggestions(EnumHandler.getEntityNames(), currentArg);
|
||||
};
|
||||
tabSuggestions = getTabSuggestions(getRelevantList(stat), currentArg);
|
||||
}
|
||||
}
|
||||
|
||||
//if previous arg = "player", suggest playerNames
|
||||
else if (previousArg.equalsIgnoreCase("player")) {
|
||||
if (args.length >= 3 && EnumHandler.getEntitySubStatNames().contains(args[args.length-3].toLowerCase())) {
|
||||
if (args.length >= 3 && EnumHandler.getEntityTypeStatNames().contains(args[args.length-3].toLowerCase())) {
|
||||
tabSuggestions = commandOptions;
|
||||
}
|
||||
else {
|
||||
@ -82,4 +81,27 @@ public class TabCompleter implements org.bukkit.command.TabCompleter {
|
||||
.filter(item -> item.toLowerCase().contains(currentArg.toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<String> getRelevantList(Statistic stat) {
|
||||
switch (stat.getType()) {
|
||||
case BLOCK -> {
|
||||
return tabCompleteHelper.getAllBlockNames();
|
||||
}
|
||||
case ITEM -> {
|
||||
if (stat == Statistic.BREAK_ITEM) {
|
||||
return tabCompleteHelper.getItemBrokenSuggestions();
|
||||
} else if (stat == Statistic.CRAFT_ITEM) {
|
||||
return tabCompleteHelper.getAllItemNames(); //TODO fix
|
||||
} else {
|
||||
return tabCompleteHelper.getAllItemNames();
|
||||
}
|
||||
}
|
||||
case ENTITY -> {
|
||||
return tabCompleteHelper.getEntityKilledSuggestions();
|
||||
}
|
||||
default -> {
|
||||
return commandOptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,28 +2,53 @@ package com.gmail.artemis.the.gr8.playerstats.commands.cmdutils;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TabCompleteHelper {
|
||||
|
||||
private List<String> itemBrokenSuggestions;
|
||||
private List<String> entityKilledSuggestions;
|
||||
|
||||
public TabCompleteHelper() {
|
||||
prepareLists();
|
||||
}
|
||||
|
||||
private void prepareLists() {
|
||||
itemBrokenSuggestions = EnumHandler.getItems()
|
||||
.parallelStream()
|
||||
.filter(item -> item.getMaxDurability() != 0)
|
||||
.map(Material::toString)
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
public List<String> getAllItemNames() {
|
||||
return EnumHandler.getItemNames();
|
||||
}
|
||||
|
||||
public List<String> getItemBrokenSuggestions() {
|
||||
return itemBrokenSuggestions;
|
||||
}
|
||||
|
||||
public List<String> getAllBlockNames() {
|
||||
return EnumHandler.getBlockNames();
|
||||
}
|
||||
|
||||
public List<String> getEntityKilledSuggestions() {
|
||||
return entityKilledSuggestions;
|
||||
}
|
||||
|
||||
|
||||
private void prepareLists() {
|
||||
itemBrokenSuggestions = Arrays.stream(Material.values())
|
||||
.parallel()
|
||||
.filter(Material::isItem)
|
||||
.filter(item -> item.getMaxDurability() != 0)
|
||||
.map(Material::toString)
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
entityKilledSuggestions = Arrays.stream(EntityType.values())
|
||||
.parallel()
|
||||
.filter(EntityType::isAlive)
|
||||
.filter(entityType -> entityType != EntityType.ARMOR_STAND)
|
||||
.map(EntityType::toString)
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -95,48 +95,34 @@ public enum Unit {
|
||||
}
|
||||
|
||||
public double getSeconds() {
|
||||
switch (this) {
|
||||
case DAY -> {
|
||||
return 86400;
|
||||
}
|
||||
case HOUR -> {
|
||||
return 3600;
|
||||
}
|
||||
case MINUTE -> {
|
||||
return 60;
|
||||
}
|
||||
case SECOND -> {
|
||||
return 1;
|
||||
}
|
||||
case TICK -> {
|
||||
return 1 / 20.0;
|
||||
}
|
||||
default -> {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return switch (this) {
|
||||
case DAY -> 86400;
|
||||
case HOUR -> 3600;
|
||||
case MINUTE -> 60;
|
||||
case SECOND -> 1;
|
||||
case TICK -> 1 / 20.0;
|
||||
default -> -1;
|
||||
};
|
||||
}
|
||||
|
||||
/** Returns the Unit corresponding to the given String. This String does NOT need to
|
||||
match exactly (it can be "day" or "days", for example), and is case-insensitive.
|
||||
@param unitName an approximation of the name belonging to the desired Unit, case-insensitive */
|
||||
public static @NotNull Unit fromString(@NotNull String unitName) {
|
||||
Unit unit;
|
||||
switch (unitName.toLowerCase()) {
|
||||
case "cm" -> unit = Unit.CM;
|
||||
case "m", "block", "blocks" -> unit = Unit.BLOCK;
|
||||
case "mile", "miles" -> unit = Unit.MILE;
|
||||
case "km" -> unit = Unit.KM;
|
||||
case "hp" -> unit = Unit.HP;
|
||||
case "heart", "hearts" -> unit = Unit.HEART;
|
||||
case "day", "days" -> unit = Unit.DAY;
|
||||
case "hour", "hours" -> unit = Unit.HOUR;
|
||||
case "minute", "minutes", "min" -> unit = Unit.MINUTE;
|
||||
case "second", "seconds", "sec" -> unit = Unit.SECOND;
|
||||
case "tick", "ticks" -> unit = Unit.TICK;
|
||||
default -> unit = Unit.NUMBER;
|
||||
}
|
||||
return unit;
|
||||
return switch (unitName.toLowerCase()) {
|
||||
case "cm" -> Unit.CM;
|
||||
case "m", "block", "blocks" -> Unit.BLOCK;
|
||||
case "mile", "miles" -> Unit.MILE;
|
||||
case "km" -> Unit.KM;
|
||||
case "hp" -> Unit.HP;
|
||||
case "heart", "hearts" -> Unit.HEART;
|
||||
case "day", "days" -> Unit.DAY;
|
||||
case "hour", "hours" -> Unit.HOUR;
|
||||
case "minute", "minutes", "min" -> Unit.MINUTE;
|
||||
case "second", "seconds", "sec" -> Unit.SECOND;
|
||||
case "tick", "ticks" -> Unit.TICK;
|
||||
default -> Unit.NUMBER;
|
||||
};
|
||||
}
|
||||
|
||||
/** Returns the Unit.Type of this Statistic, which can be Untyped, Distance, Damage, or Time.
|
||||
|
@ -23,17 +23,11 @@ public class NumberFormatter {
|
||||
|
||||
public String format(long number, Unit statUnit, Unit smallTimeUnit) {
|
||||
if (smallTimeUnit == null) {
|
||||
switch (statUnit.getType()) {
|
||||
case DISTANCE -> {
|
||||
return formatDistance(number, statUnit);
|
||||
}
|
||||
case DAMAGE -> {
|
||||
return formatDamage(number, statUnit);
|
||||
}
|
||||
default -> {
|
||||
return format.format(number);
|
||||
}
|
||||
}
|
||||
return switch (statUnit.getType()) {
|
||||
case DISTANCE -> formatDistance(number, statUnit);
|
||||
case DAMAGE -> formatDamage(number, statUnit);
|
||||
default -> format.format(number);
|
||||
};
|
||||
} else {
|
||||
return formatTime(number, statUnit, smallTimeUnit);
|
||||
}
|
||||
|
@ -17,9 +17,8 @@ public class EnumHandler {
|
||||
private final static List<String> blockNames;
|
||||
private final static List<String> entityNames;
|
||||
private final static List<String> itemNames;
|
||||
private final static List<Material> items;
|
||||
private final static List<String> statNames;
|
||||
private final static List<String> entitySubStatNames;
|
||||
private final static List<String> entityTypeStatNames;
|
||||
private final static List<String> subStatNames;
|
||||
|
||||
static {
|
||||
@ -41,8 +40,9 @@ public class EnumHandler {
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
items = Arrays.stream(Material.values())
|
||||
.filter(Material::isItem)
|
||||
subStatNames = Stream.of(blockNames, entityNames, itemNames)
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
statNames = Arrays.stream(Statistic.values())
|
||||
@ -50,25 +50,16 @@ public class EnumHandler {
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
entitySubStatNames = Arrays.stream(Statistic.values())
|
||||
entityTypeStatNames = Arrays.stream(Statistic.values())
|
||||
.filter(statistic -> statistic.getType().equals(Statistic.Type.ENTITY))
|
||||
.map(Statistic::toString)
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
subStatNames = Stream.of(blockNames, entityNames, itemNames)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private EnumHandler() {
|
||||
}
|
||||
|
||||
/** Returns all item names in lowercase */
|
||||
public static List<Material> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public static List<String> getItemNames() {
|
||||
return itemNames;
|
||||
}
|
||||
@ -144,7 +135,7 @@ public class EnumHandler {
|
||||
}
|
||||
|
||||
/** Returns all statistics that have type entities, in lowercase */
|
||||
public static List<String> getEntitySubStatNames() {
|
||||
return entitySubStatNames;
|
||||
public static List<String> getEntityTypeStatNames() {
|
||||
return entityTypeStatNames;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user