aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/re/jag/parquet/commands/Savedata.java123
1 files changed, 66 insertions, 57 deletions
diff --git a/src/main/java/re/jag/parquet/commands/Savedata.java b/src/main/java/re/jag/parquet/commands/Savedata.java
index 86ecf9d..1529018 100644
--- a/src/main/java/re/jag/parquet/commands/Savedata.java
+++ b/src/main/java/re/jag/parquet/commands/Savedata.java
@@ -1,12 +1,13 @@
package re.jag.parquet.commands;
import java.io.File;
-import java.util.UUID;
+import java.util.*;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandSource.suggestMatching;
import static net.minecraft.server.command.CommandManager.argument;
+import com.google.common.collect.Lists;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.arguments.FloatArgumentType;
@@ -16,10 +17,6 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.command.arguments.ObjectiveArgumentType;
-import net.minecraft.command.arguments.ObjectiveCriteriaArgumentType;
-import net.minecraft.entity.EntityType;
-import net.minecraft.item.Item;
-import net.minecraft.scoreboard.ScoreboardCriterion;
import net.minecraft.scoreboard.ScoreboardObjective;
import net.minecraft.scoreboard.ScoreboardPlayerScore;
import net.minecraft.scoreboard.ServerScoreboard;
@@ -31,7 +28,6 @@ import re.jag.parquet.Parquet;
import net.minecraft.stat.ServerStatHandler;
import net.minecraft.stat.Stat;
import net.minecraft.stat.StatType;
-import net.minecraft.block.Block;
public class Savedata {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
@@ -46,23 +42,24 @@ public class Savedata {
then(literal("stats").
then(argument("player", StringArgumentType.word()).
suggests( (c, b) -> suggestMatching(c.getSource().getPlayerNames() , b)).
- then(argument("criteria", ObjectiveCriteriaArgumentType.objectiveCriteria()).
+ then(argument("criteria", StringArgumentType.string()).
+ suggests((c,b) -> suggestMatching(get_stat_list(), b)).
executes((c) -> print_player_stat (
c.getSource(),
StringArgumentType.getString(c, "player"),
- ObjectiveCriteriaArgumentType.getCriteria(c, "criteria")
+ StringArgumentType.getString(c, "criteria")
)).
then(literal("import").then(argument("score", ObjectiveArgumentType.objective()).
executes((c) -> import_stat_to_scoreboard (
c.getSource(),
- StringArgumentType.getString(c, "player"),
- ObjectiveCriteriaArgumentType.getCriteria(c, "criteria"),
+ StringArgumentType.getString(c, "player"),
+ StringArgumentType.getString(c, "criteria"),
ObjectiveArgumentType.getWritableObjective(c, "score"), 1)).
then(argument("multiplier", FloatArgumentType.floatArg()).
executes((c) -> import_stat_to_scoreboard(
c.getSource(),
- StringArgumentType.getString(c, "player"),
- ObjectiveCriteriaArgumentType.getCriteria(c, "criteria"),
+ StringArgumentType.getString(c, "player"),
+ StringArgumentType.getString(c, "criteria"),
ObjectiveArgumentType.getWritableObjective(c, "score"),
FloatArgumentType.getFloat(c, "multiplier"))
)
@@ -78,7 +75,52 @@ public class Savedata {
source.sendFeedback(new LiteralText("Hölp goes here"), false);
return 1;
}
-
+
+ private static int test(ServerCommandSource source, String string) {
+ source.sendFeedback(new LiteralText(string),false);
+ return 1;
+ }
+
+ private static List<String> get_stat_list() {
+ List<String> ret = Lists.newArrayList();
+ Iterator stat_type_iter = Registry.STAT_TYPE.iterator();
+
+ while(stat_type_iter.hasNext()) {
+ StatType<Object> statType = (StatType)stat_type_iter.next();
+ Iterator stat_iter = statType.getRegistry().iterator();
+
+ while(stat_iter.hasNext()) {
+ Object object = stat_iter.next();
+ String stat_name = "\"" + Stat.getName(statType, object) + "\"";
+ ret.add(stat_name);
+ }
+ }
+
+ return ret;
+ }
+
+ private static Stat<?> get_stat_from_string(String argument) {
+
+ int criteria_name_seperator = argument.indexOf(':');
+
+ String registry_name="";
+ String stat_name="";
+
+ if (criteria_name_seperator < 0) {
+ return null;
+ } else {
+ registry_name = argument.substring(0,criteria_name_seperator);
+ stat_name = argument.substring(criteria_name_seperator + 1, argument.length() );
+ }
+
+ StatType<Object> stat_type = (StatType<Object>) Registry.STAT_TYPE.get(Identifier.splitOn(registry_name, '.'));
+ Object stat_obj = stat_type.getRegistry().get(Identifier.splitOn(stat_name, '.'));
+
+ Stat stat = stat_type.getOrCreateStat(stat_obj);
+
+ return stat;
+ }
+
private static int list_local_saves(ServerCommandSource source) {
String uuid_list[] = source.getMinecraftServer().getWorld(DimensionType.OVERWORLD).getSaveHandler().getSavedPlayerIds();
@@ -95,7 +137,7 @@ public class Savedata {
return 1;
}
- private static int import_stat_to_scoreboard(ServerCommandSource source, String player,ScoreboardCriterion stat, ScoreboardObjective objective, float multiplier) {
+ private static int import_stat_to_scoreboard(ServerCommandSource source, String player,String stat, ScoreboardObjective objective, float multiplier) {
int score = get_player_stat(source, player, stat);
if (score < 0)
return 0;
@@ -110,7 +152,7 @@ public class Savedata {
return 1;
}
- public static ServerStatHandler get_player_stat_handler(ServerCommandSource source, String player_name) {
+ private static ServerStatHandler get_player_stat_handler(ServerCommandSource source, String player_name) {
ServerPlayerEntity player = source.getMinecraftServer().getPlayerManager().getPlayer(player_name);
if (player != null) {
return player.getStatHandler();
@@ -135,7 +177,7 @@ public class Savedata {
return new ServerStatHandler(source.getMinecraftServer(), file2);
}
- private static int print_player_stat(ServerCommandSource source, String player, ScoreboardCriterion stat) {
+ private static int print_player_stat(ServerCommandSource source, String player, String stat) {
Integer stat_value = get_player_stat(source, player, stat);
if (stat_value >= 0)
@@ -146,54 +188,21 @@ public class Savedata {
return 0;
}
- private static int get_player_stat(ServerCommandSource source, String player_name, ScoreboardCriterion criteria) {
+ private static int get_player_stat(ServerCommandSource source, String player_name, String stat_name) {
ServerStatHandler stat_handler = get_player_stat_handler(source, player_name);
if (stat_handler == null) {
source.sendError(new LiteralText("Failed to get Statistics for Player " + player_name));
return -1;
}
-
- String criteria_name = criteria.getName();
- int criteria_name_seperator = criteria_name.indexOf(':');
-
- String registry_name="";
- String stat_name="";
-
- if (criteria_name_seperator < 0) {
- source.sendError(new LiteralText("Expected valid registry and stat ID"));
- return -1;
- } else {
- registry_name = criteria_name.substring(0,criteria_name_seperator);
- stat_name = criteria_name.substring(criteria_name_seperator + 1, criteria_name.length() );
- }
-
- StatType<?> stat_type = Registry.STAT_TYPE.get(Identifier.splitOn(registry_name, '.'));
- Object stat_obj = stat_type.getRegistry().get(Identifier.splitOn(stat_name, '.'));
-
- if (stat_obj instanceof Block) {
- @SuppressWarnings("unchecked")
- StatType<Block> stat_type_block = (StatType<Block>) stat_type;
- Stat<Block> stat = stat_type_block.getOrCreateStat((Block) stat_obj);
- return stat_handler.getStat(stat);
- } else if (stat_obj instanceof Item) {
- @SuppressWarnings("unchecked")
- StatType<Item> stat_type_item = (StatType<Item>) stat_type;
- Stat<Item> stat = stat_type_item.getOrCreateStat((Item) stat_obj);
- return stat_handler.getStat(stat);
- } else if (stat_obj instanceof Identifier) {
- @SuppressWarnings("unchecked")
- StatType<Identifier> stat_type_ident = (StatType<Identifier>) stat_type;
- Stat<Identifier> stat = stat_type_ident.getOrCreateStat((Identifier) stat_obj);
- return stat_handler.getStat(stat);
- } else if (stat_obj instanceof EntityType<?>) {
- @SuppressWarnings("unchecked")
- StatType<EntityType<?>> stat_type_ident = (StatType<EntityType<?>>) stat_type;
- Stat<EntityType<?>> stat = stat_type_ident.getOrCreateStat((EntityType<?>) stat_obj);
- return stat_handler.getStat(stat);
- } else {
- source.sendError(new LiteralText("Unknown Object " + stat_obj.getClass().getName()));
+
+ Stat stat = get_stat_from_string(stat_name);
+
+ if (stat == null) {
+ source.sendError(new LiteralText("Invalid stat: " + stat_name));
return -1;
}
+
+ return stat_handler.getStat(stat);
}
}