chore: 添加翻译
This commit is contained in:
1 parent
cc4a5094c7
commit
e91b2a49a3
5 files changed
+119
-15
No files matched your search
@@ -31,6 +31,12 @@ public class SLSCarpetSettings {
|
||||
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE})
|
||||
public static boolean offlineFakePlayers = false;
|
||||
|
||||
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE})
|
||||
public static boolean canUseHatCommand = false;
|
||||
|
||||
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE})
|
||||
public static boolean canUseSitCommand = false;
|
||||
|
||||
@Rule(categories = {CARPET_ID, PCA, PROTOCOL})
|
||||
public static boolean pcaSyncProtocol = false;
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.github.zly2006.carpetslsaddition;
|
||||
|
||||
import carpet.CarpetExtension;
|
||||
import carpet.CarpetServer;
|
||||
import com.github.zly2006.carpetslsaddition.util.SitEntity;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
@@ -11,6 +13,7 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.Version;
|
||||
import net.minecraft.command.CommandRegistryAccess;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
@@ -20,10 +23,12 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -40,7 +45,7 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
||||
public static final String CARPET_ID = "SLS";
|
||||
|
||||
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
|
||||
static final Gson GSON = new Gson();
|
||||
static final Gson GSON = new GsonBuilder().setLenient().create(); // 使用宽容模式,避免部分开发者在书写JSON时不遵守RFC 4627规范
|
||||
|
||||
public static ServerMain INSTANCE;
|
||||
public static MinecraftServer server;
|
||||
@@ -94,7 +99,7 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
||||
}
|
||||
}
|
||||
GSON.fromJson(jsonFile, JsonObject.class).entrySet().stream()
|
||||
.filter(entry -> entry.getKey().startsWith("carpet.rule."))
|
||||
.filter(entry -> entry.getKey().startsWith("carpet."))
|
||||
.filter(entry -> entry.getValue().isJsonPrimitive())
|
||||
.map(entry -> Map.entry(entry.getKey(), entry.getValue().getAsString()))
|
||||
.forEach(entry -> translation.put(entry.getKey(), entry.getValue()));
|
||||
@@ -106,15 +111,44 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
||||
dispatcher.register(CommandManager.literal("hat")
|
||||
.requires(ServerCommandSource::isExecutedByPlayer)
|
||||
.executes(context -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
assert player != null;
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
ItemStack head = player.getEquippedStack(EquipmentSlot.HEAD);
|
||||
player.equipStack(EquipmentSlot.HEAD, stack);
|
||||
player.getInventory().setStack(player.getInventory().selectedSlot, head);
|
||||
player.currentScreenHandler.syncState();
|
||||
return 1;
|
||||
if(SLSCarpetSettings.canUseHatCommand){
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
assert player != null;
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
ItemStack head = player.getEquippedStack(EquipmentSlot.HEAD);
|
||||
player.equipStack(EquipmentSlot.HEAD, stack);
|
||||
player.getInventory().setStack(player.getInventory().selectedSlot, head);
|
||||
player.currentScreenHandler.syncState();
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
context.getSource().sendMessage(Text.literal("服务器尚未启用本指令!").setStyle(Style.EMPTY.withColor(Formatting.RED)));
|
||||
return 0;
|
||||
}
|
||||
}));
|
||||
|
||||
dispatcher.register(CommandManager.literal("sit")
|
||||
.requires(ServerCommandSource::isExecutedByPlayer)
|
||||
.executes(context -> {
|
||||
if(SLSCarpetSettings.canUseSitCommand){
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
assert player != null;
|
||||
World world = player.getWorld();
|
||||
|
||||
ArmorStandEntity armorStandEntity = new ArmorStandEntity(world, player.getX(), player.getY() - 0.16, player.getZ());
|
||||
((SitEntity) armorStandEntity).setSitEntity(true);
|
||||
world.spawnEntity(armorStandEntity);
|
||||
player.setSneaking(false);
|
||||
player.startRiding(armorStandEntity);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
context.getSource().sendMessage(Text.literal("服务器尚未启用本指令!").setStyle(Style.EMPTY.withColor(Formatting.RED)));
|
||||
return 0;
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public static Identifier createId(String path) {
|
||||
|
||||
Reference in new issue
Block a user