From 29a55f914b6a8e17f0c644fb13e4af3c074b7b1f Mon Sep 17 00:00:00 2001 From: thatsIch Date: Mon, 10 Aug 2015 13:34:31 +0200 Subject: [PATCH] Fixes #1786: Locale critical code now uses the english local for transmission. Fixes Turkish Problem. Applied English Locale where localization is not expected as in internal recipe handling and IMC handling, basically which interacts with public API where we either require to enforce the incoming text with regex ([a-z0-9]) or just expect proper usage of the API, but with just using upper cases in recipe files it would break in Turkish Locale like ALIAS another option would have been to use `equalsIgnoreCase` in some cases, but not all applicable --- .../api/features/IRecipeHandlerRegistry.java | 18 +++++++++++---- src/main/java/appeng/core/IMCHandler.java | 17 ++++++++------ src/main/java/appeng/core/RecipeLoader.java | 1 - .../appeng/core/api/imc/IMCP2PAttunement.java | 5 ++-- .../registries/RecipeHandlerRegistry.java | 23 +++++++++++++++---- .../parts/automation/PartSharedItemBus.java | 2 +- .../java/appeng/recipes/RecipeHandler.java | 12 +++++----- 7 files changed, 52 insertions(+), 26 deletions(-) diff --git a/src/api/java/appeng/api/features/IRecipeHandlerRegistry.java b/src/api/java/appeng/api/features/IRecipeHandlerRegistry.java index ef50b809..a208cbf3 100644 --- a/src/api/java/appeng/api/features/IRecipeHandlerRegistry.java +++ b/src/api/java/appeng/api/features/IRecipeHandlerRegistry.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2013 AlgorithmX2 + * Copyright (c) 2013 - 2015 AlgorithmX2 * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -24,11 +24,19 @@ package appeng.api.features; +import javax.annotation.Nullable; + import appeng.api.recipes.ICraftHandler; import appeng.api.recipes.IRecipeHandler; import appeng.api.recipes.ISubItemResolver; +/** + * @author AlgorithmX2 + * @author thatsIch + * @version rv3 - 10.08.2015 + * @since rv0 + */ public interface IRecipeHandlerRegistry { @@ -37,7 +45,7 @@ public interface IRecipeHandlerRegistry * * MUST BE CALLED IN PRE-INIT * - * @param name name of crafthandler + * @param name name of crafthandler * @param handler class of crafthandler */ void addNewCraftHandler( String name, Class handler ); @@ -56,6 +64,7 @@ public interface IRecipeHandlerRegistry * * @return A recipe handler by name, returns null on failure. */ + @Nullable ICraftHandler getCraftHandlerFor( String name ); /** @@ -67,9 +76,10 @@ public interface IRecipeHandlerRegistry * resolve sub items by name. * * @param nameSpace namespace of item - * @param itemName full name of item + * @param itemName full name of item * - * @return ResolverResult or ResolverResultSet + * @return ResolverResult or ResolverResultSet or null if could not resolve */ + @Nullable Object resolveItem( String nameSpace, String itemName ); } diff --git a/src/main/java/appeng/core/IMCHandler.java b/src/main/java/appeng/core/IMCHandler.java index 4a517109..7c6ad0a2 100644 --- a/src/main/java/appeng/core/IMCHandler.java +++ b/src/main/java/appeng/core/IMCHandler.java @@ -20,6 +20,7 @@ package appeng.core; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import net.minecraftforge.fml.common.event.FMLInterModComms; @@ -34,6 +35,10 @@ import appeng.core.api.imc.IMCSpatial; /** * Handles the delegation of the corresponding IMC messages to the suitable IMC processors + * + * @author thatsIch + * @version rv3 - 10.08.2015 + * @since rv1 */ public class IMCHandler { @@ -42,8 +47,7 @@ public class IMCHandler /** * Contains the processors, * - * is mutable, - * but write access only by the constructor + * is mutable, but write access only by the constructor */ private final Map processors; @@ -61,13 +65,12 @@ public class IMCHandler for( TunnelType type : TunnelType.values() ) { - this.processors.put( "add-p2p-attunement-" + type.name().replace( '_', '-' ).toLowerCase(), new IMCP2PAttunement() ); + this.processors.put( "add-p2p-attunement-" + type.name().replace( '_', '-' ).toLowerCase( Locale.ENGLISH ), new IMCP2PAttunement() ); } } /** - * Tries to find every message matching the internal IMC keys. - * When found the corresponding handler will process the attached message. + * Tries to find every message matching the internal IMC keys. When found the corresponding handler will process the attached message. * * @param event Event carrying the identifier and message for the handlers */ @@ -79,7 +82,7 @@ public class IMCHandler try { - IIMCProcessor handler = this.processors.get( key ); + final IIMCProcessor handler = this.processors.get( key ); if( handler != null ) { handler.process( message ); @@ -89,7 +92,7 @@ public class IMCHandler throw new IllegalStateException( "Invalid IMC Called: " + key ); } } - catch( Throwable t ) + catch( Exception t ) { AELog.warning( "Problem detected when processing IMC " + key + " from " + message.getSender() ); AELog.error( t ); diff --git a/src/main/java/appeng/core/RecipeLoader.java b/src/main/java/appeng/core/RecipeLoader.java index 8e39692a..b4933602 100644 --- a/src/main/java/appeng/core/RecipeLoader.java +++ b/src/main/java/appeng/core/RecipeLoader.java @@ -22,7 +22,6 @@ package appeng.core; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; - import javax.annotation.Nonnull; import org.apache.commons.io.FileUtils; diff --git a/src/main/java/appeng/core/api/imc/IMCP2PAttunement.java b/src/main/java/appeng/core/api/imc/IMCP2PAttunement.java index dd27a244..fb3bd3e4 100644 --- a/src/main/java/appeng/core/api/imc/IMCP2PAttunement.java +++ b/src/main/java/appeng/core/api/imc/IMCP2PAttunement.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved. * * Applied Energistics 2 is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -31,6 +31,7 @@ package appeng.core.api.imc; import java.util.Arrays; +import java.util.Locale; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage; @@ -45,7 +46,7 @@ public class IMCP2PAttunement implements IIMCProcessor @Override public void process( IMCMessage m ) { - String key = m.key.substring( "add-p2p-attunement-".length() ).replace( '-', '_' ).toUpperCase(); + String key = m.key.substring( "add-p2p-attunement-".length() ).replace( '-', '_' ).toUpperCase( Locale.ENGLISH ); TunnelType type = TunnelType.valueOf( key ); diff --git a/src/main/java/appeng/core/features/registries/RecipeHandlerRegistry.java b/src/main/java/appeng/core/features/registries/RecipeHandlerRegistry.java index f30ee7be..24d0f961 100644 --- a/src/main/java/appeng/core/features/registries/RecipeHandlerRegistry.java +++ b/src/main/java/appeng/core/features/registries/RecipeHandlerRegistry.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved. * * Applied Energistics 2 is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -19,8 +19,12 @@ package appeng.core.features.registries; +import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; +import java.util.Locale; +import java.util.Map; +import javax.annotation.Nullable; import appeng.api.features.IRecipeHandlerRegistry; import appeng.api.recipes.ICraftHandler; @@ -30,16 +34,21 @@ import appeng.core.AELog; import appeng.recipes.RecipeHandler; +/** + * @author AlgorithmX2 + * @author thatsIch + * @version rv3 - 10.08.2015 + * @since rv0 + */ public class RecipeHandlerRegistry implements IRecipeHandlerRegistry { - - final HashMap> handlers = new HashMap>(); - final LinkedList resolvers = new LinkedList(); + private final Map> handlers = new HashMap>( 20 ); + private final Collection resolvers = new LinkedList(); @Override public void addNewCraftHandler( String name, Class handler ) { - this.handlers.put( name.toLowerCase(), handler ); + this.handlers.put( name.toLowerCase( Locale.ENGLISH ), handler ); } @Override @@ -48,6 +57,7 @@ public class RecipeHandlerRegistry implements IRecipeHandlerRegistry this.resolvers.add( sir ); } + @Nullable @Override public ICraftHandler getCraftHandlerFor( String name ) { @@ -64,7 +74,9 @@ public class RecipeHandlerRegistry implements IRecipeHandlerRegistry { AELog.severe( "Error Caused when trying to construct " + clz.getName() ); AELog.error( e ); + this.handlers.put( name, null ); // clear it.. + return null; } } @@ -75,6 +87,7 @@ public class RecipeHandlerRegistry implements IRecipeHandlerRegistry return new RecipeHandler(); } + @Nullable @Override public Object resolveItem( String nameSpace, String itemName ) { diff --git a/src/main/java/appeng/parts/automation/PartSharedItemBus.java b/src/main/java/appeng/parts/automation/PartSharedItemBus.java index 99e5ad39..16313d24 100644 --- a/src/main/java/appeng/parts/automation/PartSharedItemBus.java +++ b/src/main/java/appeng/parts/automation/PartSharedItemBus.java @@ -155,7 +155,7 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid protected boolean canDoBusWork() { final TileEntity self = this.getHost().getTile(); - final BlockPos selfPos = self.getPos().offset( this.side.getFacing() ) + final BlockPos selfPos = self.getPos().offset( this.side.getFacing() ); final int xCoordinate = selfPos.getX(); final int zCoordinate = selfPos.getZ(); diff --git a/src/main/java/appeng/recipes/RecipeHandler.java b/src/main/java/appeng/recipes/RecipeHandler.java index f59f4742..e74a3585 100644 --- a/src/main/java/appeng/recipes/RecipeHandler.java +++ b/src/main/java/appeng/recipes/RecipeHandler.java @@ -26,11 +26,11 @@ import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; - import javax.annotation.Nonnull; import com.google.common.base.Optional; @@ -71,7 +71,7 @@ import com.google.common.collect.HashMultimap; /** * @author AlgorithmX2 * @author thatsIch - * @version rv2 + * @version rv3 - 10.08.2015 * @since rv0 */ public class RecipeHandler implements IRecipeHandler @@ -451,7 +451,7 @@ public class RecipeHandler implements IRecipeHandler try { - Ingredient i = new Ingredient( this, s, 1 ); + IIngredient i = new Ingredient( this, s, 1 ); for( ItemStack is : i.getItemStackSet() ) { @@ -551,7 +551,7 @@ public class RecipeHandler implements IRecipeHandler int split = this.tokens.indexOf( "->" ); if( split != -1 ) { - String operation = this.tokens.remove( 0 ).toLowerCase(); + final String operation = this.tokens.remove( 0 ).toLowerCase( Locale.ENGLISH ); if( operation.equals( "alias" ) ) { @@ -688,7 +688,7 @@ public class RecipeHandler implements IRecipeHandler this.tokens.clear(); } - private List> parseLines( List subList ) throws RecipeError + private List> parseLines( Iterable subList ) throws RecipeError { List> out = new LinkedList>(); List cList = new LinkedList(); @@ -763,7 +763,7 @@ public class RecipeHandler implements IRecipeHandler } } - private boolean isNumber( String v ) + private boolean isNumber( CharSequence v ) { if( v.length() <= 0 ) {