1
0
mirror of https://github.com/chylex/Better-Sprinting.git synced 2025-04-09 18:15:41 +02:00

Added localization for server-side messages

This commit is contained in:
chylex 2015-12-02 16:03:38 +01:00
parent 7788490867
commit aaa2a372b8
4 changed files with 65 additions and 15 deletions
src/main
java/chylex/bettersprinting/server
resources/assets/bettersprinting/lang

View File

@ -3,6 +3,7 @@ import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import chylex.bettersprinting.BetterSprintingMod;
import chylex.bettersprinting.server.compatibility.OldNotificationPacketReceiver;
@ -33,44 +34,48 @@ public class ServerCommandConfig extends CommandBase{
sendMessage(sender,"/bettersprinting setting <survivalFlyBoost|runInAllDirs> <true|false>");
}
else if (args[0].equalsIgnoreCase("info")){
sendMessage(sender,"You can use the command to either disable/enable the mod, or change specific settings of the mod. These will persist after restarting the server, and will also immediately affect players that are already on the server.");
sendMessageTranslated(sender,"bs.command.info");
}
else if (args[0].equalsIgnoreCase("disablemod")){
if (isValidBool(args,1)){
ServerSettings.disableClientMod = getBool(args,1);
ServerSettings.update(BetterSprintingMod.config);
sendMessage(sender,ServerSettings.disableClientMod ? "Better Sprinting will be automatically disabled when a user joins." : "Better Sprinting is now allowed on the server.");
sendMessageTranslated(sender,ServerSettings.disableClientMod ? "bs.command.disableMod" : "bs.command.enableMod");
PacketPipeline.sendToAll(ServerNetwork.writeDisableMod(ServerSettings.disableClientMod));
if (ServerSettings.disableClientMod)OldNotificationPacketReceiver.kickOldModUsers();
}
else sendMessage(sender,"Invalid syntax, do /bettersprinting for list of commands.");
else sendMessageTranslated(sender,"bs.command.invalidSyntax");
}
else if (args[0].equalsIgnoreCase("setting")){
if (args.length <= 1 || !isValidBool(args,2)){
sendMessage(sender,"Invalid syntax, do /bettersprinting for list of commands.");
sendMessageTranslated(sender,"bs.command.invalidSyntax");
}
else{
if (args[1].equalsIgnoreCase("survivalFlyBoost")){
ServerSettings.enableSurvivalFlyBoost = getBool(args,2);
ServerSettings.update(BetterSprintingMod.config);
sendMessage(sender,"Fly boost is now "+(ServerSettings.enableSurvivalFlyBoost ? "enabled" : "disabled")+" when the player is in survival mode.");
sendMessageTranslated(sender,ServerSettings.enableSurvivalFlyBoost ? "bs.command.enableFlyBoost" : "bs.command.disableFlyBoost");
PacketPipeline.sendToAll(ServerNetwork.writeSettings(ServerSettings.enableSurvivalFlyBoost,ServerSettings.enableAllDirs));
}
else if (args[1].equalsIgnoreCase("runInAllDirs")){
ServerSettings.enableAllDirs = getBool(args,2);
ServerSettings.update(BetterSprintingMod.config);
sendMessage(sender,"Sprinting in all directions is now "+(ServerSettings.enableAllDirs ? "enabled." : "disabled."));
sendMessageTranslated(sender,ServerSettings.enableAllDirs ? "bs.command.enableAllDirs" : "bs.command.disableAllDirs");
PacketPipeline.sendToAll(ServerNetwork.writeSettings(ServerSettings.enableSurvivalFlyBoost,ServerSettings.enableAllDirs));
}
}
}
else sendMessage(sender,"Invalid syntax, do /bettersprinting for list of commands.");
else sendMessageTranslated(sender,"bs.command.invalidSyntax");
}
private void sendMessage(ICommandSender sender, String text){
sender.addChatMessage(new ChatComponentText(text));
}
private void sendMessageTranslated(ICommandSender sender, String translationName){
sender.addChatMessage(new ChatComponentTranslation(translationName));
}
private boolean isValidBool(String[] args, int index){
if (index >= args.length)return false;
return args[index].equalsIgnoreCase("true") || args[index].equalsIgnoreCase("false");

View File

@ -1,11 +1,15 @@
package chylex.bettersprinting.server.compatibility;
import io.netty.buffer.ByteBuf;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.server.S40PacketDisconnect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.util.ChatComponentTranslation;
import chylex.bettersprinting.server.ServerSettings;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@ -27,7 +31,7 @@ public class OldNotificationPacketReceiver{
for(String id:instance.users){
EntityPlayerMP player = manager.func_152612_a(id);
if (player != null)player.playerNetServerHandler.kickPlayerFromServer("The server does not allow Better Sprinting. Newer versions of the mod can be disabled automatically without kicking.");
if (player != null)kickPlayer(player.playerNetServerHandler,"bs.server.kick");
}
instance.users.clear();
@ -48,7 +52,7 @@ public class OldNotificationPacketReceiver{
if (data.readByte() == 4){
NetHandlerPlayServer handler = (NetHandlerPlayServer)e.handler;
if (ServerSettings.disableClientMod)handler.kickPlayerFromServer("The server does not allow Better Sprinting. Newer versions of the mod can be disabled automatically without kicking.");
if (ServerSettings.disableClientMod)kickPlayer(handler,"bs.server.kick");
else users.add(handler.playerEntity.getCommandSenderName());
}
}
@ -57,4 +61,19 @@ public class OldNotificationPacketReceiver{
public void onPlayerDisconnect(PlayerLoggedOutEvent e){
users.remove(e.player.getCommandSenderName());
}
private static void kickPlayer(final NetHandlerPlayServer netHandler, String translationName){
final ChatComponentTranslation msg = new ChatComponentTranslation(translationName);
netHandler.netManager.scheduleOutboundPacket(new S40PacketDisconnect(msg),new GenericFutureListener[]{
new GenericFutureListener(){
@Override
public void operationComplete(Future isBright){
netHandler.netManager.closeChannel(msg);
}
}
});
netHandler.netManager.disableAutoRead();
}
}

View File

@ -1,7 +1,11 @@
# Generic GUI titles
gui.enabled=Enabled
gui.disabled=Disabled
gui.unavailable=Unavailable
# Titles for controls
bs.sprint.hold=Sprint (hold)
bs.sprint.toggle=Sprint (toggle)
bs.sneak.toggle=Sneak (toggle)
@ -12,7 +16,7 @@ bs.runAllDirs=Run in all directions
bs.flyBoost=Flying boost
bs.disableMod=Disable mod functionality
# Use the '#' character for splitting lines
# Tooltips for controls (use the '#' character for splitting lines)
bs.sprint.hold.info=Hold to sprint.
bs.sprint.toggle.info=Press once to start or stop sprinting.
@ -24,15 +28,28 @@ bs.runAllDirs.info=Sprint in all directions.#You cannot use this in multiplayer
bs.flyBoost.info=Hold when flying in creative mode to fly faster.
bs.disableMod.info=Disables all non-vanilla functionality of Better Sprinting.#This option can be used if a server doesn't allow the mod.
# If you need to translate fly speed boost, use the following pattern (from 2x to 8x)
2x=2x
# In-game messages
bs.game.integrity=Integrity verification failed, another mod is conflicting with Better Sprinting. Try installing PlayerAPI to resolve the conflict. Conflicting class: $
bs.game.disabled=The server has requested to disable the mod, the sprinting mechanics are switched to vanilla until you disconnect.
bs.game.reenabled=The server has enabled the mod again, sprinting mechanics are switched to Better Sprinting ones.
# If you need to translate fly speed boost, use the following pattern (from 2x to 8x)
# Server messages (translated on client)
2x=2x
bs.server.kick=The server does not allow Better Sprinting. Newer versions of the mod can be disabled automatically without kicking.
bs.command.invalidSyntax=Invalid syntax, do /bettersprinting for list of commands.
bs.command.info=You can use the command to either disable/enable the mod, or change specific settings of the mod. These will persist after restarting the server, and will also immediately affect players that are already on the server.
bs.command.disableMod=Better Sprinting will be automatically disabled when a user joins.
bs.command.enableMod=Better Sprinting is now allowed on the server.
bs.command.disableFlyBoost=Fly boost is now disabled when the player is in survival mode.
bs.command.enableFlyBoost=Fly boost is now enabled when the player is in survival mode.
bs.command.disableAllDirs=Sprinting in all directions is now disabled.
bs.command.enableAllDirs=Sprinting in all directions is now enabled.
# Configuration

View File

@ -1,7 +1,11 @@
# Generic GUI titles
gui.enabled=Включено
gui.disabled=Отключено
gui.unavailable=Недоступно
# Titles for controls
bs.sprint.hold=Бег (удерживать)
bs.sprint.toggle=Бег (переключить)
bs.sneak.toggle=Присесть (переключить)
@ -12,7 +16,7 @@ bs.runAllDirs=Бег во всех направлениях
bs.flyBoost=Ускорение полёта
bs.disableMod=Отключить модификацию
# Use the '#' character for splitting lines
# Tooltips for controls (use the '#' character for splitting lines)
bs.sprint.hold.info=Удерживайте, чтобы бежать.
bs.sprint.toggle.info=Нажмите, чтобы бежать или остановиться.
@ -24,12 +28,17 @@ bs.runAllDirs.info=Бег во всех направлениях.#Вы не мо
bs.flyBoost.info=Удерживайте во время полёта в творческом режиме, чтобы лететь быстрее.
bs.disableMod.info=Отключает все функции модификации Better Sprinting.#Это опция может быть полезна, если сервер не разрешает использовать этот мод.
# If you need to translate fly speed boost, use the following pattern (from 2x to 8x)
2x=2x
# In-game messages
bs.game.integrity=Проверка целостности провалилась, другая модификация конфликтует с Better Sprinting. Установите PlayerAPI, чтобы устранить конфликт. Конфликтующий класс-файл: $
bs.game.disabled=Сервер отключил эту модификацию, механизм бега изменён на оригинальный.
bs.game.reenabled=Сервер включил эту модификацию, используется механизм бега модификации Better Sprinting.
# If you need to translate fly speed boost, use the following pattern (from 2x to 8x)
# Server messages (translated on client)
# Configuration
2x=2x