Work on server data and registries.

This commit is contained in:
Sebastian Hartte
2020-06-05 19:03:29 +02:00
parent 476c310de6
commit c411a800f6
24 changed files with 329 additions and 777 deletions
+12 -51
View File
@@ -19,19 +19,13 @@
package appeng.me;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.CompoundNBT;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridStorage;
import appeng.core.AELog;
import appeng.core.worlddata.WorldData;
import net.minecraft.nbt.CompoundNBT;
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
public class GridStorage implements IGridStorage
@@ -39,49 +33,30 @@ public class GridStorage implements IGridStorage
private final long myID;
private final CompoundNBT data;
private final GridStorageSearch mySearchEntry; // keep myself in the list until I'm
private final WeakHashMap<GridStorage, Boolean> divided = new WeakHashMap<>();
private WeakReference<IGrid> internalGrid = null;
// lost...
/**
* for use with world settings
*
* @param id ID of grid storage
* @param gss grid storage search
*/
public GridStorage( final long id, final GridStorageSearch gss )
public GridStorage( final long id )
{
this.myID = id;
this.mySearchEntry = gss;
this.data = new CompoundNBT();
}
/**
* for use with world settings
*
* @param input array of bytes string
* @param data The Grid data.
* @param id ID of grid storage
* @param gss grid storage search
*/
public GridStorage( final String input, final long id, final GridStorageSearch gss )
public GridStorage( final long id, final CompoundNBT data )
{
this.myID = id;
this.mySearchEntry = gss;
CompoundNBT myTag = null;
try
{
final byte[] byteData = javax.xml.bind.DatatypeConverter.parseBase64Binary( input );
myTag = CompressedStreamTools.readCompressed( new ByteArrayInputStream( byteData ) );
}
catch( final Throwable t )
{
myTag = new CompoundNBT();
}
this.data = myTag;
this.data = data;
}
/**
@@ -90,30 +65,16 @@ public class GridStorage implements IGridStorage
public GridStorage()
{
this.myID = 0;
this.mySearchEntry = null;
this.data = new CompoundNBT();
}
public String getValue()
public void saveState()
{
// FIXME final Grid currentGrid = (Grid) this.getGrid();
// FIXME if( currentGrid != null )
// FIXME {
// FIXME currentGrid.saveState();
// FIXME }
try
final Grid currentGrid = (Grid) this.getGrid();
if( currentGrid != null )
{
final ByteArrayOutputStream out = new ByteArrayOutputStream();
CompressedStreamTools.writeCompressed( this.data, out );
return javax.xml.bind.DatatypeConverter.printBase64Binary( out.toByteArray() );
currentGrid.saveState();
}
catch( final IOException e )
{
AELog.debug( e );
}
return "";
}
public IGrid getGrid()
@@ -1,77 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me;
import java.lang.ref.WeakReference;
public class GridStorageSearch
{
private final long id;
private WeakReference<GridStorage> gridStorage;
/**
* for use with the world settings
*
* @param id ID of grid storage search
*/
public GridStorageSearch( final long id )
{
this.id = id;
}
@Override
public int hashCode()
{
return ( (Long) this.id ).hashCode();
}
@Override
public boolean equals( final Object obj )
{
if( obj == null )
{
return false;
}
if( this.getClass() != obj.getClass() )
{
return false;
}
final GridStorageSearch other = (GridStorageSearch) obj;
if( this.id == other.id )
{
return true;
}
return false;
}
public WeakReference<GridStorage> getGridStorage()
{
return this.gridStorage;
}
public void setGridStorage( final WeakReference<GridStorage> gridStorage )
{
this.gridStorage = gridStorage;
}
}
+1 -1
View File
@@ -156,7 +156,7 @@ public class SecurityCache implements ISecurityGrid
Preconditions.checkNotNull( perm );
final GameProfile profile = player.getGameProfile();
final int playerID = WorldData.instance().playerData().getPlayerID( profile );
final int playerID = WorldData.instance().playerData().getMePlayerId( profile );
return this.hasPermission( playerID, perm );
}
@@ -166,7 +166,7 @@ public class AENetworkProxy implements IGridBlock
else if( this.node != null && this.owner != null )
{
final GameProfile profile = this.owner.getGameProfile();
final int playerID = WorldData.instance().playerData().getPlayerID( profile );
final int playerID = WorldData.instance().playerData().getMePlayerId( profile );
this.node.setPlayerID( playerID );
this.owner = null;