Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translation related issues #1996

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
import cn.nukkit.entity.item.*;
import cn.nukkit.entity.projectile.EntityArrow;
import cn.nukkit.entity.projectile.EntityThrownTrident;
import cn.nukkit.event.entity.EntityDamageByBlockEvent;
import cn.nukkit.event.entity.EntityDamageByEntityEvent;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.*;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
import cn.nukkit.event.entity.EntityDamageEvent.DamageModifier;
import cn.nukkit.event.entity.ProjectileLaunchEvent;
import cn.nukkit.event.inventory.InventoryCloseEvent;
import cn.nukkit.event.inventory.InventoryPickupArrowEvent;
import cn.nukkit.event.inventory.InventoryPickupItemEvent;
Expand All @@ -32,7 +29,6 @@
import cn.nukkit.form.handler.FormResponseHandler;
import cn.nukkit.form.window.FormWindow;
import cn.nukkit.form.window.FormWindowCustom;
import cn.nukkit.form.window.FormWindowModal;
import cn.nukkit.inventory.*;
import cn.nukkit.inventory.transaction.CraftingTransaction;
import cn.nukkit.inventory.transaction.EnchantTransaction;
Expand Down Expand Up @@ -3908,30 +3904,39 @@ public void kill() {
if (e instanceof Player) {
message = "death.attack.player";
params.add(((Player) e).getDisplayName());
break;
} else if (e instanceof EntityLiving) {
message = "death.attack.mob";
params.add(!Objects.equals(e.getNameTag(), "") ? e.getNameTag() : e.getName());
break;
} else {
params.add("Unknown");
message = "death.attack.generic";
}
} else {
message = "death.attack.generic";
}
break;
case PROJECTILE:
if (cause instanceof EntityDamageByEntityEvent) {
Entity e = ((EntityDamageByEntityEvent) cause).getDamager();
killer = e;
if (e instanceof Player) {
message = "death.attack.arrow";
message = "death.attack.thrown";
params.add(((Player) e).getDisplayName());
} else if (e instanceof EntityLiving) {
message = "death.attack.arrow";
message = "death.attack.thrown";
params.add(!Objects.equals(e.getNameTag(), "") ? e.getNameTag() : e.getName());
break;
} else {
params.add("Unknown");
}
if (message.isEmpty()) {
message = "death.attack.generic";
} else if (cause instanceof EntityDamageByChildEntityEvent) {
Entity entity = ((EntityDamageByChildEntityEvent) cause).getChild();
if (entity instanceof EntityArrow) {
message = "death.attack.arrow";
} else if (entity instanceof EntityThrownTrident) {
message = "death.attack.trident";
}
}
} else {
message = "death.attack.generic";
}
break;
case VOID:
Expand All @@ -3944,11 +3949,9 @@ public void kill() {
}
message = "death.attack.fall";
break;

case SUFFOCATION:
message = "death.attack.inWall";
break;

case LAVA:
Block block = this.level.getBlock(new Vector3(this.x, this.y - 1, this.z));
if (block.getId() == Block.MAGMA) {
Expand All @@ -3957,19 +3960,15 @@ public void kill() {
}
message = "death.attack.lava";
break;

case FIRE:
message = "death.attack.onFire";
break;

case FIRE_TICK:
message = "death.attack.inFire";
break;

case DROWNING:
message = "death.attack.drown";
break;

case CONTACT:
if (cause instanceof EntityDamageByBlockEvent) {
int id = ((EntityDamageByBlockEvent) cause).getDamager().getId();
Expand All @@ -3978,9 +3977,10 @@ public void kill() {
} else if (id == Block.ANVIL) {
message = "death.attack.anvil";
}
} else {
message = "death.attack.generic";
}
break;

case BLOCK_EXPLOSION:
case ENTITY_EXPLOSION:
if (cause instanceof EntityDamageByEntityEvent) {
Expand All @@ -3992,7 +3992,8 @@ public void kill() {
} else if (e instanceof EntityLiving) {
message = "death.attack.explosion.player";
params.add(!Objects.equals(e.getNameTag(), "") ? e.getNameTag() : e.getName());
break;
} else if (e instanceof EntityFirework) {
message = "death.attack.fireworks";
} else {
message = "death.attack.explosion";
}
Expand All @@ -4009,6 +4010,23 @@ public void kill() {
case HUNGER:
message = "death.attack.starve";
break;
case THORNS:
if (cause instanceof EntityDamageByEntityEvent) {
Entity e = ((EntityDamageByEntityEvent) cause).getDamager();
killer = e;
if (e instanceof Player) {
message = "death.attack.thorns";
params.add(((Player) e).getDisplayName());
} else if (e instanceof EntityLiving) {
message = "death.attack.thorns";
params.add(!Objects.equals(e.getNameTag(), "") ? e.getNameTag() : e.getName());
} else {
message = "death.attack.generic";
}
} else {
message = "death.attack.generic";
}
break;
default:
message = "death.attack.generic";
break;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/command/defaults/BanCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class BanCommand extends VanillaCommand {

public BanCommand(String name) {
super(name, "%nukkit.command.ban.player.description", "%commands.ban.usage");
super(name, "%nukkit.command.ban.player.description", "%nukkit.command.ban.usage");
this.setPermission("nukkit.command.ban.player");
this.commandParameters.clear();
this.commandParameters.put("default",
Expand Down Expand Up @@ -54,7 +54,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
player.kick(PlayerKickEvent.Reason.NAME_BANNED, (reason.length() > 0) ? "Banned by admin. Reason: " + reason : "Banned by admin");
}

Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.ban.success", player != null ? player.getName() : name));
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.ban.success", player != null ? player.getName() : name));

return true;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/cn/nukkit/command/defaults/BanIpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.nbt.NBTIO;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.utils.TextFormat;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -25,7 +26,7 @@
public class BanIpCommand extends VanillaCommand {

public BanIpCommand(String name) {
super(name, "%nukkit.command.ban.ip.description", "%commands.banip.usage");
super(name, "%nukkit.command.ban.ip.description", "%nukkit.command.banip.usage");
this.setPermission("nukkit.command.ban.ip");
this.setAliases(new String[]{"banip"});
this.commandParameters.clear();
Expand Down Expand Up @@ -89,7 +90,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)

Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success", value));
} else {
sender.sendMessage(new TranslationContainer("commands.banip.invalid"));
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.banip.invalid"));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class BanListCommand extends VanillaCommand {
public BanListCommand(String name) {
super(name, "%nukkit.command.banlist.description", "%commands.banlist.usage");
super(name, "%nukkit.command.banlist.description", "%nukkit.command.banlist.usage");
this.setPermission("nukkit.command.ban.list");
this.commandParameters.clear();
this.commandParameters.put("default", new CommandParameter[]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onRun() {
b.append("os.arch: '").append(System.getProperty("os.arch")).append("'\n");
b.append("os.name: '").append(System.getProperty("os.name")).append("'\n");
b.append("os.version: '").append(System.getProperty("os.version")).append("'\n\n");
b.append("\n# Create a ticket: https://github.com/NukkitX/Nukkit/issues/new");
b.append("\n# Create a ticket: https://github.com/CloudburstMC/Nukkit/issues/new");
String link = HastebinUtility.upload(b.toString());
sender.sendMessage(link);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cn.nukkit.command.data.CommandParamType;
import cn.nukkit.command.data.CommandParameter;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.utils.TextFormat;

/**
* Created on 2015/11/12 by xtypr.
Expand All @@ -14,7 +15,7 @@
public class DefaultGamemodeCommand extends VanillaCommand {

public DefaultGamemodeCommand(String name) {
super(name, "%nukkit.command.defaultgamemode.description", "%commands.defaultgamemode.usage");
super(name, "%nukkit.command.defaultgamemode.description", "%nukkit.command.defaultgamemode.usage");
this.setPermission("nukkit.command.defaultgamemode");
this.commandParameters.clear();
this.commandParameters.put("default", new CommandParameter[]{
Expand All @@ -31,15 +32,15 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
return true;
}
if (args.length == 0) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", new String[]{this.usageMessage}));
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
int gameMode = Server.getGamemodeFromString(args[0]);
if (gameMode != -1) {
sender.getServer().setPropertyInt("gamemode", gameMode);
sender.sendMessage(new TranslationContainer("commands.defaultgamemode.success", new String[]{Server.getGamemodeString(gameMode)}));
sender.sendMessage(new TranslationContainer("commands.defaultgamemode.success", Server.getGamemodeString(gameMode)));
} else {
sender.sendMessage("Unknown game mode"); //
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.gamemode.fail.invalid", args[0]));
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/command/defaults/DeopCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class DeopCommand extends VanillaCommand {
public DeopCommand(String name) {
super(name, "%nukkit.command.deop.description", "%commands.deop.description");
super(name, "%nukkit.command.deop.description", "%nukkit.command.deop.usage");
this.setPermission("nukkit.command.op.take");
this.commandParameters.put("default", new CommandParameter[]{
CommandParameter.newType("player", CommandParamType.TARGET)
Expand All @@ -42,7 +42,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
((Player) player).sendMessage(new TranslationContainer(TextFormat.GRAY + "%commands.deop.message"));
}

Command.broadcastCommandMessage(sender, new TranslationContainer("commands.deop.success", new String[]{player.getName()}));
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.deop.success", player.getName()));

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class DifficultyCommand extends VanillaCommand {

public DifficultyCommand(String name) {
super(name, "%nukkit.command.difficulty.description", "%commands.difficulty.usage");
super(name, "%nukkit.command.difficulty.description", "%nukkit.command.difficulty.usage");
this.setPermission("nukkit.command.difficulty");
this.commandParameters.clear();
this.commandParameters.put("default", new CommandParameter[]{
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/cn/nukkit/command/defaults/EffectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
public class EffectCommand extends Command {
public EffectCommand(String name) {
super(name, "%nukkit.command.effect.description", "%commands.effect.usage");
super(name, "%nukkit.command.effect.description", "%nukkit.command.effect.usage");
this.setPermission("nukkit.command.effect");
this.commandParameters.clear();

Expand Down Expand Up @@ -65,7 +65,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
for (Effect effect : player.getEffects().values()) {
player.removeEffect(effect.getId());
}
sender.sendMessage(new TranslationContainer("commands.effect.success.removed.all", player.getDisplayName()));
sender.sendMessage(new TranslationContainer("commands.effect.success.removed.all", player.getName()));
return true;
}
Effect effect;
Expand All @@ -75,11 +75,11 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
try {
effect = Effect.getEffectByName(args[1]);
} catch (Exception e) {
sender.sendMessage(new TranslationContainer("commands.effect.notFound", args[1]));
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.effect.notFound", args[1]));
return true;
}
}
int duration = 300;
int duration = 600;
int amplification = 0;
if (args.length >= 3) {
try {
Expand Down Expand Up @@ -111,18 +111,18 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
if (duration == 0) {
if (!player.hasEffect(effect.getId())) {
if (player.getEffects().size() == 0) {
sender.sendMessage(new TranslationContainer("commands.effect.failure.notActive.all", player.getDisplayName()));
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.effect.failure.notActive.all", player.getName()));
} else {
sender.sendMessage(new TranslationContainer("commands.effect.failure.notActive", effect.getName(), player.getDisplayName()));
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.effect.failure.notActive", effect.getName(), player.getName()));
}
return true;
}
player.removeEffect(effect.getId());
sender.sendMessage(new TranslationContainer("commands.effect.success.removed", effect.getName(), player.getDisplayName()));
sender.sendMessage(new TranslationContainer("commands.effect.success.removed", effect.getName(), player.getName()));
} else {
effect.setDuration(duration).setAmplifier(amplification);
player.addEffect(effect);
Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.effect.success", effect.getName(), String.valueOf(effect.getAmplifier()), player.getDisplayName(), String.valueOf(effect.getDuration() / 20)));
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.effect.success", effect.getName(), String.valueOf(effect.getAmplifier()), player.getName(), String.valueOf(effect.getDuration() / 20)));
}
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cn/nukkit/command/defaults/EnchantCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class EnchantCommand extends VanillaCommand {

public EnchantCommand(String name) {
super(name, "%nukkit.command.enchant.description", "%commands.enchant.usage");
super(name, "%nukkit.command.enchant.description", "%nukkit.command.enchant.usage");
this.setPermission("nukkit.command.enchant");
this.commandParameters.clear();
this.commandParameters.put("default", new CommandParameter[]{
Expand Down Expand Up @@ -62,18 +62,18 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
}
Enchantment enchantment = Enchantment.getEnchantment(enchantId);
if (enchantment == null) {
sender.sendMessage(new TranslationContainer("commands.enchant.notFound", String.valueOf(enchantId)));
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.enchant.notFound", String.valueOf(enchantId)));
return true;
}
enchantment.setLevel(enchantLevel);
Item item = player.getInventory().getItemInHand();
if (item.getId() <= 0) {
sender.sendMessage(new TranslationContainer("commands.enchant.noItem"));
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.enchant.noItem", player.getName()));
return true;
}
item.addEnchantment(enchantment);
player.getInventory().setItemInHand(item);
Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.enchant.success"));
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.enchant.success", player.getName()));
return true;
}

Expand Down
Loading