Replaced dynamic regular expressions with compiled pattern

This commit is contained in:
thatsIch
2015-03-26 11:33:08 +01:00
parent dff3364eb5
commit 58db877006
5 changed files with 35 additions and 15 deletions
+10 -5
View File
@@ -20,6 +20,7 @@ package appeng.core.sync;
import java.lang.reflect.Constructor;
import java.util.regex.Pattern;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -190,6 +191,8 @@ public enum GuiBridge implements IGuiHandler
GUI_CRAFTING_STATUS(ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT);
private static final Pattern PATTERN_PRE_CONTAINER = Pattern.compile( ".Container", Pattern.LITERAL );
private static final Pattern PATTERN_POST_CONTAINER = Pattern.compile( "container." );
private final Class Tile;
private Class Gui;
private final Class Container;
@@ -210,13 +213,15 @@ public enum GuiBridge implements IGuiHandler
{
if ( Platform.isClient() )
{
String start = this.Container.getName();
String GuiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
if ( start.equals( GuiClass ) )
final String start = this.Container.getName();
final String guiClassPostReplaced = PATTERN_POST_CONTAINER.matcher( start ).replaceFirst( "client.gui." );
final String guiClassPreReplaced = PATTERN_PRE_CONTAINER.matcher( guiClassPostReplaced ).replaceAll( ".Gui" );
if ( start.equals( guiClassPreReplaced ) )
throw new RuntimeException( "Unable to find gui class" );
this.Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), GuiClass );
this.Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), guiClassPreReplaced );
if ( this.Gui == null )
throw new RuntimeException( "Cannot Load class: " + GuiClass );
throw new RuntimeException( "Cannot Load class: " + guiClassPreReplaced );
}
}