Skip to content

Commit

Permalink
[i18n] Add more messages (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0methean authored and mastercoms committed Sep 30, 2018
1 parent 256061c commit a77682b
Show file tree
Hide file tree
Showing 31 changed files with 218 additions and 113 deletions.
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NonNls;

public class BuiltinMaterialValueManager implements MaterialValueManager {

Expand All @@ -24,12 +25,14 @@ public BuiltinMaterialValueManager() {
YamlConfiguration builtinValues = YamlConfiguration.loadConfiguration(new InputStreamReader(
getClass().getClassLoader().getResourceAsStream("builtin/materialValues.yml")));

defaultValue = new BuiltinValueCollection(builtinValues.getConfigurationSection("default"));
defaultValue = new BuiltinValueCollection(
builtinValues.getConfigurationSection("default")); // NON-NLS
registerBuiltins(builtinValues);
}

private void registerBuiltins(ConfigurationSection mainSection) {
ConfigurationSection valuesSection = mainSection.getConfigurationSection("values");
ConfigurationSection valuesSection
= mainSection.getConfigurationSection("values"); // NON-NLS
Set<String> materials = valuesSection.getKeys(false);
for (String strMaterial : materials) {
Material material = Material.matchMaterial(strMaterial);
Expand Down Expand Up @@ -60,7 +63,7 @@ private final class BuiltinValueCollection implements ValueCollection {
this.section = section;
}

private Object get(String name) {
private Object get(@NonNls String name) {
Object got = section.get(name);
if (got == null && this != defaultValue) {
return defaultValue.get(name);
Expand Down
32 changes: 15 additions & 17 deletions src/main/java/net/glowstone/block/blocktype/BlockChest.java
Expand Up @@ -2,13 +2,13 @@

import java.util.ArrayList;
import java.util.Collection;
import net.glowstone.GlowServer;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.BlockEntity;
import net.glowstone.block.entity.ChestEntity;
import net.glowstone.chunk.GlowChunk;
import net.glowstone.entity.GlowPlayer;
import net.glowstone.i18n.ConsoleMessages;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -51,8 +51,7 @@ private static BlockFace getFacingDirection(BlockFace myFacing, BlockFace otherF
case WEST:
return yaw > 90 && yaw < 270 ? BlockFace.SOUTH : BlockFace.NORTH;
default:
GlowServer.logger
.warning("Can only handle N/O/S/W BlockFaces, getting face: " + connection);
ConsoleMessages.Warn.Block.Chest.FACING.log(connection);
return BlockFace.NORTH;
}
}
Expand All @@ -75,21 +74,23 @@ public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face,
BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);

Collection<BlockFace> attachedChests = searchChests(chestBlock);
if (attachedChests.isEmpty()) {
chest.setFacingDirection(normalFacing);
state.setData(chest);
return;
} else if (attachedChests.size() > 1) {
GlowServer.logger.warning("Chest placed near two other chests!");
return;
switch (attachedChests.size()) {
case 0:
chest.setFacingDirection(normalFacing);
state.setData(chest);
return;
case 1:
break;
default:
ConsoleMessages.Warn.Block.Chest.TRIPLE_MIDDLE.log();
return;
}

BlockFace otherPart = attachedChests.iterator().next();

GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);

if (getAttachedChest(otherPartBlock) != null) {
GlowServer.logger.warning("Chest placed near already attached chest!");
ConsoleMessages.Warn.Block.Chest.TRIPLE_END.log();
return;
}

Expand Down Expand Up @@ -126,8 +127,7 @@ public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face,
return true;
}

GlowServer.logger
.warning("Calling blockInteract on BlockChest, but BlockState is " + state);
ConsoleMessages.Warn.Block.Chest.INTERACT_WRONG_CLASS.log(state);

return false;
}
Expand Down Expand Up @@ -171,9 +171,7 @@ public BlockFace getAttachedChest(GlowBlock me) {
return null;
}
if (attachedChests.size() > 1) {
GlowServer.logger.warning(
"Chest may only have one near other chest. Found '" + attachedChests + "' near "
+ me);
ConsoleMessages.Warn.Block.Chest.TRIPLE_ALREADY.log(attachedChests, me);
return null;
}

Expand Down
Expand Up @@ -2,8 +2,8 @@

import java.util.Arrays;
import java.util.Collection;
import net.glowstone.GlowServer;
import net.glowstone.block.GlowBlock;
import net.glowstone.i18n.ConsoleMessages;
import net.glowstone.inventory.ToolType;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand All @@ -21,8 +21,7 @@ private ItemStack getDrops(GlowBlock block) {
case PURPUR_DOUBLE_SLAB:
return new ItemStack(Material.PURPUR_SLAB, 2);
default:
GlowServer.logger.warning("BlockDoubleSlab got wrong material: "
+ block.getType());
ConsoleMessages.Warn.Block.DoubleSlab.WRONG_MATERIAL.log(block.getType());
return new ItemStack(Material.STEP, 2);
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/net/glowstone/block/blocktype/BlockType.java
Expand Up @@ -6,7 +6,6 @@
import java.util.List;
import lombok.Getter;
import net.glowstone.EventFactory;
import net.glowstone.GlowServer;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.ItemTable;
Expand All @@ -15,9 +14,10 @@
import net.glowstone.chunk.GlowChunk;
import net.glowstone.entity.GlowPlayer;
import net.glowstone.entity.physics.BlockBoundingBox;
import net.glowstone.i18n.ConsoleMessages;
import net.glowstone.i18n.GlowstoneMessages;
import net.glowstone.util.SoundInfo;
import net.glowstone.util.SoundUtil;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -319,10 +319,9 @@ public final void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFac
target.getRelative(face.getOppositeFace()).getType()).getMaterial();

// prevent building above the height limit
if (target.getLocation().getY() >= target.getWorld().getMaxHeight()) {
player.sendMessage(
ChatColor.RED + "The height limit for this world is " + target.getWorld()
.getMaxHeight() + " blocks");
final int maxHeight = target.getWorld().getMaxHeight();
if (target.getLocation().getY() >= maxHeight) {
GlowstoneMessages.Block.MAX_HEIGHT.send(player, maxHeight);
return;
}

Expand Down Expand Up @@ -445,9 +444,8 @@ public void leftClickBlock(GlowPlayer player, GlowBlock block, ItemStack holding
* @param data The actual MaterialData found.
*/
protected void warnMaterialData(Class<?> clazz, MaterialData data) {
GlowServer.logger.warning(
"Wrong MaterialData for " + getMaterial() + " (" + getClass().getSimpleName()
+ "): expected " + clazz.getSimpleName() + ", got " + data);
ConsoleMessages.Warn.Block.WRONG_MATERIAL_DATA.log(
getMaterial(), getClass().getSimpleName(), clazz.getSimpleName(), data);
}

public void onRedstoneUpdate(GlowBlock block) {
Expand Down
22 changes: 7 additions & 15 deletions src/main/java/net/glowstone/chunk/ChunkManager.java
Expand Up @@ -10,16 +10,15 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
import lombok.Getter;
import net.glowstone.EventFactory;
import net.glowstone.GlowServer;
import net.glowstone.GlowWorld;
import net.glowstone.chunk.GlowChunk.Key;
import net.glowstone.constants.GlowBiome;
import net.glowstone.generator.GlowChunkData;
import net.glowstone.generator.GlowChunkGenerator;
import net.glowstone.generator.biomegrid.MapLayer;
import net.glowstone.i18n.ConsoleMessages;
import net.glowstone.io.ChunkIoService;
import org.bukkit.Material;
import org.bukkit.block.Biome;
Expand Down Expand Up @@ -154,9 +153,7 @@ public boolean loadChunk(GlowChunk chunk, boolean generate) {
return true;
}
} catch (IOException e) {
GlowServer.logger.log(Level.SEVERE,
"Error while loading chunk (" + chunk.getX() + "," + chunk.getZ() + ")",
e);
ConsoleMessages.Error.Chunk.LOAD_FAILED.log(e, chunk.getX(), chunk.getZ());
// an error in chunk reading may have left the chunk in an invalid state
// (i.e. double initialization errors), so it's forcibly unloaded here
chunk.unload(false, false);
Expand All @@ -171,9 +168,7 @@ public boolean loadChunk(GlowChunk chunk, boolean generate) {
try {
generateChunk(chunk, chunk.getX(), chunk.getZ());
} catch (Throwable ex) {
GlowServer.logger.log(Level.SEVERE,
"Error while generating chunk (" + chunk.getX() + "," + chunk.getZ() + ")",
ex);
ConsoleMessages.Error.Chunk.GEN_FAILED.log(ex, chunk.getX(), chunk.getZ());
return false;
}

Expand All @@ -197,8 +192,7 @@ public void unloadOldChunks() {
Entry<Key, GlowChunk> entry = chunksEntryIter.next();
if (!lockSet.contains(entry.getKey())) {
if (!entry.getValue().unload(true, true)) {
GlowServer.logger.warning(
"Failed to unload chunk " + world.getName() + ":" + entry.getKey());
ConsoleMessages.Warn.Chunk.UNLOAD_FAILED.log(world.getName(), entry.getKey());
}
}
if (!entry.getValue().isLoaded()) {
Expand Down Expand Up @@ -257,8 +251,7 @@ public void forcePopulation(int x, int z) {
try {
populateChunk(x, z, true);
} catch (Throwable ex) {
GlowServer.logger.log(Level.SEVERE,
"Error while populating chunk (" + x + "," + z + ")", ex);
ConsoleMessages.Error.Chunk.POP_FAILED.log(ex, x, z);
}
}

Expand Down Expand Up @@ -386,8 +379,7 @@ public boolean forceRegeneration(int x, int z) {
generateChunk(chunk, x, z);
populateChunk(x, z, false); // should this be forced?
} catch (Throwable ex) {
GlowServer.logger.log(Level.SEVERE,
"Error while regenerating chunk (" + x + "," + z + ")", ex);
ConsoleMessages.Error.Chunk.REGEN_FAILED.log(ex, chunk.getX(), chunk.getZ());
return false;
}
return true;
Expand All @@ -414,7 +406,7 @@ public boolean performSave(GlowChunk chunk) {
service.write(chunk);
return true;
} catch (IOException ex) {
GlowServer.logger.log(Level.SEVERE, "Error while saving " + chunk, ex);
ConsoleMessages.Error.Chunk.SAVE_FAILED.log(ex, chunk);
return false;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/glowstone/command/CommandUtils.java
Expand Up @@ -82,6 +82,7 @@ public static String prettyPrint(Entity[] entities) {
* @param strings one or more strings
* @return a list of the strings, formatted like "a, b and c"
*/
// FIXME: Replace with the function from the Unicode CLDR that handles almost any language
public static String prettyPrint(String[] strings) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < strings.length; i++) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/glowstone/entity/EntityManager.java
Expand Up @@ -13,7 +13,6 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import net.glowstone.EventFactory;
import net.glowstone.chunk.GlowChunk;
import net.glowstone.entity.physics.BoundingBox;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/glowstone/entity/meta/ClientSettings.java
Expand Up @@ -9,7 +9,8 @@
@Data
public class ClientSettings {

public static final ClientSettings DEFAULT = new ClientSettings("en_US", 8, 0, true, 127, 0);
public static final ClientSettings DEFAULT
= new ClientSettings("en_US", 8, 0, true, 127, 0); // NON-NLS

public static final int CHAT_ENABLED = 0;
public static final int CHAT_COMMANDS_ONLY = 1;
Expand Down
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import lombok.Getter;
import lombok.Setter;

import net.glowstone.EventFactory;
import net.glowstone.entity.meta.MetadataIndex;
import org.bukkit.Location;
Expand Down
@@ -1,7 +1,6 @@
package net.glowstone.entity.projectile;

import java.util.concurrent.ThreadLocalRandom;

import net.glowstone.EventFactory;
import net.glowstone.entity.objects.GlowExperienceOrb;
import net.glowstone.net.message.play.entity.SpawnObjectMessage;
Expand Down

0 comments on commit a77682b

Please sign in to comment.