This commit is contained in:
simibubi 2020-01-05 19:41:44 +01:00
commit 4150fbf9b5
3 changed files with 26 additions and 16 deletions

View file

@ -3,23 +3,25 @@ package com.simibubi.create.foundation.command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.foundation.utility.Lang;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands; import net.minecraft.command.Commands;
import net.minecraft.util.text.StringTextComponent;
public class KillTPSCommand { public class KillTPSCommand {
public static void register(CommandDispatcher<CommandSource> dispatcher) { public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register( dispatcher.register(
Commands.literal("killtps")//todo replace String Components with Translation Components Commands.literal(Lang.translate("command.killTPSCommand"))
.requires(cs -> cs.hasPermissionLevel(2)) .requires(cs -> cs.hasPermissionLevel(2))
.executes(ctx -> { .executes(ctx -> {
//killtps no arguments //killtps no arguments
ctx.getSource().sendFeedback(new StringTextComponent(String.format("[Create]: Server tick is currently slowed by %s ms",Create.lagger.isLagging() ? Create.lagger.getTickTime() : 0)), true); ctx.getSource().sendFeedback(Lang.createTranslationTextComponent("command.killTPSCommand.status.slowed_by.0", Create.lagger.isLagging() ? Create.lagger.getTickTime() : 0), true);
if (Create.lagger.isLagging()) if (Create.lagger.isLagging())
ctx.getSource().sendFeedback(new StringTextComponent("[Create]: use /killtps stop to bring back server tick to regular speed"), true); ctx.getSource().sendFeedback(Lang.createTranslationTextComponent("command.killTPSCommand.status.usage.0"), true);
else else
ctx.getSource().sendFeedback(new StringTextComponent("[Create]: use /killtps start <tickTime> to artificially slow down the server tick"),true); ctx.getSource().sendFeedback(Lang.createTranslationTextComponent("command.killTPSCommand.status.usage.1"),true);
return 1; return 1;
}) })
@ -29,22 +31,22 @@ public class KillTPSCommand {
int tickTime = Create.lagger.getTickTime(); int tickTime = Create.lagger.getTickTime();
if (tickTime > 0){ if (tickTime > 0){
Create.lagger.setLagging(true); Create.lagger.setLagging(true);
ctx.getSource().sendFeedback(new StringTextComponent(String.format("[Create]: Server tick is slowed by %s ms now :)", tickTime)),true); ctx.getSource().sendFeedback((Lang.createTranslationTextComponent("command.killTPSCommand.status.slowed_by.1", tickTime)),true);
ctx.getSource().sendFeedback(new StringTextComponent("[Create]: use /killtps stop to bring back server tick to regular speed"),true); ctx.getSource().sendFeedback(Lang.createTranslationTextComponent("command.killTPSCommand.status.usage.0"),true);
} else { } else {
ctx.getSource().sendFeedback(new StringTextComponent("[Create]: use /killtps start <tickTime> to artificially slow down the server tick"),true); ctx.getSource().sendFeedback(Lang.createTranslationTextComponent("command.killTPSCommand.status.usage.1"),true);
} }
return 1; return 1;
}) })
.then(Commands.argument("tickTime", IntegerArgumentType.integer(1)) .then(Commands.argument(Lang.translate("command.killTPSCommand.argument.tickTime"), IntegerArgumentType.integer(1))
.executes(ctx -> { .executes(ctx -> {
//killtps start tickTime //killtps start tickTime
int tickTime = IntegerArgumentType.getInteger(ctx, "tickTime"); int tickTime = IntegerArgumentType.getInteger(ctx, Lang.translate("command.killTPSCommand.argument.tickTime"));
Create.lagger.setTickTime(tickTime); Create.lagger.setTickTime(tickTime);
Create.lagger.setLagging(true); Create.lagger.setLagging(true);
ctx.getSource().sendFeedback(new StringTextComponent(String.format("[Create]: Server tick is slowed by %s ms now :)", tickTime)),true); ctx.getSource().sendFeedback((Lang.createTranslationTextComponent("command.killTPSCommand.status.slowed_by.1", tickTime)),true);
ctx.getSource().sendFeedback(new StringTextComponent("[Create]: use /killtps stop to bring server tick to regular speed again"),true); ctx.getSource().sendFeedback(Lang.createTranslationTextComponent("command.killTPSCommand.status.usage.0"),true);
return 1; return 1;
}) })
@ -54,7 +56,7 @@ public class KillTPSCommand {
.executes(ctx -> { .executes(ctx -> {
//killtps stop //killtps stop
Create.lagger.setLagging(false); Create.lagger.setLagging(false);
ctx.getSource().sendFeedback(new StringTextComponent("[Create]: Server tick is back to regular speed"), false); ctx.getSource().sendFeedback(Lang.createTranslationTextComponent("command.killTPSCommand.status.slowed_by.2"), false);
return 1; return 1;
}) })

View file

@ -12,15 +12,15 @@ import net.minecraft.util.text.TranslationTextComponent;
public class Lang { public class Lang {
public static String translate(String key, Object... args) { public static String translate(String key, Object... args) {
return getTranslationComponent(key, args).getFormattedText(); return createTranslationTextComponent(key, args).getFormattedText();
} }
private static TranslationTextComponent getTranslationComponent(String key, Object... args) { public static TranslationTextComponent createTranslationTextComponent(String key, Object... args) {
return new TranslationTextComponent(Create.ID + "." + key, args); return new TranslationTextComponent(Create.ID + "." + key, args);
} }
public static void sendStatus(PlayerEntity player, String key, Object... args) { public static void sendStatus(PlayerEntity player, String key, Object... args) {
player.sendStatusMessage(getTranslationComponent(key, args), true); player.sendStatusMessage(createTranslationTextComponent(key, args), true);
} }
public static List<String> translatedOptions(String prefix, String... keys) { public static List<String> translatedOptions(String prefix, String... keys) {

View file

@ -434,6 +434,14 @@
"create.mechanical_mixer.min_ingredients": "Min. Ingredients", "create.mechanical_mixer.min_ingredients": "Min. Ingredients",
"create.command.killTPSCommand": "killtps",
"create.command.killTPSCommand.status.slowed_by.0": "[Create]: Server tick is currently slowed by %s ms",
"create.command.killTPSCommand.status.slowed_by.1": "[Create]: Server tick is slowed by %s ms now :)",
"create.command.killTPSCommand.status.slowed_by.2": "[Create]: Server tick is back to regular speed",
"create.command.killTPSCommand.status.usage.0": "[Create]: use /killtps stop to bring back server tick to regular speed",
"create.command.killTPSCommand.status.usage.1": "[Create]: use /killtps start <tickTime> to artificially slow down the server tick",
"create.command.killTPSCommand.argument.tickTime": "tickTime",
"_comment": "-------------------------] ITEM DESCRIPTIONS [------------------------------------------------", "_comment": "-------------------------] ITEM DESCRIPTIONS [------------------------------------------------",
"item.create.example_item.tooltip": "EXAMPLE ITEM (just a marker that this tooltip exists)", "item.create.example_item.tooltip": "EXAMPLE ITEM (just a marker that this tooltip exists)",