Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.container.guisync;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.EnumSet;
|
||||
@@ -31,17 +32,17 @@ import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketProgressBar;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
|
||||
|
||||
public class SyncData
|
||||
{
|
||||
|
||||
private Object clientVersion;
|
||||
|
||||
private final AEBaseContainer source;
|
||||
private final Field field;
|
||||
|
||||
private final int channel;
|
||||
private Object clientVersion;
|
||||
|
||||
public SyncData(AEBaseContainer container, Field field, GuiSync annotation) {
|
||||
public SyncData( AEBaseContainer container, Field field, GuiSync annotation )
|
||||
{
|
||||
this.clientVersion = null;
|
||||
this.source = container;
|
||||
this.field = field;
|
||||
@@ -53,129 +54,48 @@ public class SyncData
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
public void tick(ICrafting c)
|
||||
public void tick( ICrafting c )
|
||||
{
|
||||
try
|
||||
{
|
||||
Object val = this.field.get( this.source );
|
||||
if ( val != null && this.clientVersion == null )
|
||||
if( val != null && this.clientVersion == null )
|
||||
this.send( c, val );
|
||||
else if ( !val.equals( this.clientVersion ) )
|
||||
else if( !val.equals( this.clientVersion ) )
|
||||
this.send( c, val );
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
catch( IllegalAccessException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch (IOException e)
|
||||
catch( IOException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
|
||||
public void update(Object val)
|
||||
private void send( ICrafting o, Object val ) throws IOException
|
||||
{
|
||||
try
|
||||
if( val instanceof String )
|
||||
{
|
||||
Object oldValue = this.field.get( this.source );
|
||||
if ( val instanceof String )
|
||||
this.updateString( oldValue, (String) val );
|
||||
else
|
||||
this.updateValue( oldValue, (Long) val );
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateString(Object oldValue, String val)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.field.set( this.source, val );
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
|
||||
private void updateValue(Object oldValue, long val)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( this.field.getType().isEnum() )
|
||||
{
|
||||
EnumSet<? extends Enum> valList = EnumSet.allOf( (Class<? extends Enum>) this.field.getType() );
|
||||
for (Enum e : valList)
|
||||
{
|
||||
if ( e.ordinal() == val )
|
||||
{
|
||||
this.field.set( this.source, e );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( this.field.getType().equals( int.class ) )
|
||||
this.field.set( this.source, (int) val );
|
||||
else if ( this.field.getType().equals( long.class ) )
|
||||
this.field.set( this.source, val );
|
||||
else if ( this.field.getType().equals( boolean.class ) )
|
||||
this.field.set( this.source, val == 1 );
|
||||
else if ( this.field.getType().equals( Integer.class ) )
|
||||
this.field.set( this.source, (int) val );
|
||||
else if ( this.field.getType().equals( Long.class ) )
|
||||
this.field.set( this.source, val );
|
||||
else if ( this.field.getType().equals( Boolean.class ) )
|
||||
this.field.set( this.source, val == 1 );
|
||||
}
|
||||
|
||||
this.source.onUpdate( this.field.getName(), oldValue, this.field.get( this.source ) );
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
|
||||
private void send(ICrafting o, Object val) throws IOException
|
||||
{
|
||||
if ( val instanceof String )
|
||||
{
|
||||
if ( o instanceof EntityPlayerMP )
|
||||
if( o instanceof EntityPlayerMP )
|
||||
NetworkHandler.instance.sendTo( new PacketValueConfig( "SyncDat." + this.channel, (String) val ), (EntityPlayerMP) o );
|
||||
}
|
||||
else if ( this.field.getType().isEnum() )
|
||||
else if( this.field.getType().isEnum() )
|
||||
{
|
||||
o.sendProgressBarUpdate( this.source, this.channel, ((Enum) val).ordinal() );
|
||||
o.sendProgressBarUpdate( this.source, this.channel, ( (Enum) val ).ordinal() );
|
||||
}
|
||||
else if ( val instanceof Long || val.getClass() == long.class )
|
||||
else if( val instanceof Long || val.getClass() == long.class )
|
||||
{
|
||||
NetworkHandler.instance.sendTo( new PacketProgressBar( this.channel, (Long) val ), (EntityPlayerMP) o );
|
||||
}
|
||||
else if ( val instanceof Boolean || val.getClass() == boolean.class )
|
||||
else if( val instanceof Boolean || val.getClass() == boolean.class )
|
||||
{
|
||||
o.sendProgressBarUpdate( this.source, this.channel, ((Boolean) val) ? 1 : 0 );
|
||||
o.sendProgressBarUpdate( this.source, this.channel, ( (Boolean) val ) ? 1 : 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -184,4 +104,84 @@ public class SyncData
|
||||
|
||||
this.clientVersion = val;
|
||||
}
|
||||
|
||||
public void update( Object val )
|
||||
{
|
||||
try
|
||||
{
|
||||
Object oldValue = this.field.get( this.source );
|
||||
if( val instanceof String )
|
||||
this.updateString( oldValue, (String) val );
|
||||
else
|
||||
this.updateValue( oldValue, (Long) val );
|
||||
}
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch( IllegalAccessException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
|
||||
private void updateString( Object oldValue, String val )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.field.set( this.source, val );
|
||||
}
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch( IllegalAccessException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
|
||||
private void updateValue( Object oldValue, long val )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( this.field.getType().isEnum() )
|
||||
{
|
||||
EnumSet<? extends Enum> valList = EnumSet.allOf( (Class<? extends Enum>) this.field.getType() );
|
||||
for( Enum e : valList )
|
||||
{
|
||||
if( e.ordinal() == val )
|
||||
{
|
||||
this.field.set( this.source, e );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( this.field.getType().equals( int.class ) )
|
||||
this.field.set( this.source, (int) val );
|
||||
else if( this.field.getType().equals( long.class ) )
|
||||
this.field.set( this.source, val );
|
||||
else if( this.field.getType().equals( boolean.class ) )
|
||||
this.field.set( this.source, val == 1 );
|
||||
else if( this.field.getType().equals( Integer.class ) )
|
||||
this.field.set( this.source, (int) val );
|
||||
else if( this.field.getType().equals( Long.class ) )
|
||||
this.field.set( this.source, val );
|
||||
else if( this.field.getType().equals( Boolean.class ) )
|
||||
this.field.set( this.source, val == 1 );
|
||||
}
|
||||
|
||||
this.source.onUpdate( this.field.getName(), oldValue, this.field.get( this.source ) );
|
||||
}
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch( IllegalAccessException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user