reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
+107 -140
View File
@@ -19,16 +19,6 @@
package appeng.me.cache;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import com.google.common.base.Preconditions;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
@@ -40,163 +30,140 @@ import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.security.ISecurityProvider;
import appeng.core.worlddata.WorldData;
import appeng.me.GridNode;
import com.google.common.base.Preconditions;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
public class SecurityCache implements ISecurityGrid
{
public class SecurityCache implements ISecurityGrid {
private final IGrid myGrid;
private final List<ISecurityProvider> securityProvider = new ArrayList<>();
private final HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms = new HashMap<>();
private long securityKey = -1;
private final IGrid myGrid;
private final List<ISecurityProvider> securityProvider = new ArrayList<>();
private final HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms = new HashMap<>();
private long securityKey = -1;
public SecurityCache( final IGrid g )
{
this.myGrid = g;
}
public SecurityCache(final IGrid g) {
this.myGrid = g;
}
@MENetworkEventSubscribe
public void updatePermissions( final MENetworkSecurityChange ev )
{
this.playerPerms.clear();
if( this.securityProvider.isEmpty() )
{
return;
}
@MENetworkEventSubscribe
public void updatePermissions(final MENetworkSecurityChange ev) {
this.playerPerms.clear();
if (this.securityProvider.isEmpty()) {
return;
}
this.securityProvider.get( 0 ).readPermissions( this.playerPerms );
}
this.securityProvider.get(0).readPermissions(this.playerPerms);
}
public long getSecurityKey()
{
return this.securityKey;
}
public long getSecurityKey() {
return this.securityKey;
}
@Override
public void onUpdateTick()
{
@Override
public void onUpdateTick() {
}
}
@Override
public void removeNode( final IGridNode gridNode, final IGridHost machine )
{
if( machine instanceof ISecurityProvider )
{
this.securityProvider.remove( machine );
this.updateSecurityKey();
}
}
@Override
public void removeNode(final IGridNode gridNode, final IGridHost machine) {
if (machine instanceof ISecurityProvider) {
this.securityProvider.remove(machine);
this.updateSecurityKey();
}
}
private void updateSecurityKey()
{
final long lastCode = this.securityKey;
private void updateSecurityKey() {
final long lastCode = this.securityKey;
if( this.securityProvider.size() == 1 )
{
this.securityKey = this.securityProvider.get( 0 ).getSecurityKey();
}
else
{
this.securityKey = -1;
}
if (this.securityProvider.size() == 1) {
this.securityKey = this.securityProvider.get(0).getSecurityKey();
} else {
this.securityKey = -1;
}
if( lastCode != this.securityKey )
{
this.getGrid().postEvent( new MENetworkSecurityChange() );
for( final IGridNode n : this.getGrid().getNodes() )
{
( (GridNode) n ).setLastSecurityKey( this.securityKey );
}
}
}
if (lastCode != this.securityKey) {
this.getGrid().postEvent(new MENetworkSecurityChange());
for (final IGridNode n : this.getGrid().getNodes()) {
((GridNode) n).setLastSecurityKey(this.securityKey);
}
}
}
@Override
public void addNode( final IGridNode gridNode, final IGridHost machine )
{
if( machine instanceof ISecurityProvider )
{
this.securityProvider.add( (ISecurityProvider) machine );
this.updateSecurityKey();
}
else
{
( (GridNode) gridNode ).setLastSecurityKey( this.securityKey );
}
}
@Override
public void addNode(final IGridNode gridNode, final IGridHost machine) {
if (machine instanceof ISecurityProvider) {
this.securityProvider.add((ISecurityProvider) machine);
this.updateSecurityKey();
} else {
((GridNode) gridNode).setLastSecurityKey(this.securityKey);
}
}
@Override
public void onSplit( final IGridStorage destinationStorage )
{
@Override
public void onSplit(final IGridStorage destinationStorage) {
}
}
@Override
public void onJoin( final IGridStorage sourceStorage )
{
@Override
public void onJoin(final IGridStorage sourceStorage) {
}
}
@Override
public void populateGridStorage( final IGridStorage destinationStorage )
{
@Override
public void populateGridStorage(final IGridStorage destinationStorage) {
}
}
@Override
public boolean isAvailable()
{
return this.securityProvider.size() == 1 && this.securityProvider.get( 0 ).isSecurityEnabled();
}
@Override
public boolean isAvailable() {
return this.securityProvider.size() == 1 && this.securityProvider.get(0).isSecurityEnabled();
}
@Override
public boolean hasPermission( final EntityPlayer player, final SecurityPermissions perm )
{
Preconditions.checkNotNull( player );
Preconditions.checkNotNull( perm );
@Override
public boolean hasPermission(final EntityPlayer player, final SecurityPermissions perm) {
Preconditions.checkNotNull(player);
Preconditions.checkNotNull(perm);
final GameProfile profile = player.getGameProfile();
final int playerID = WorldData.instance().playerData().getPlayerID( profile );
final GameProfile profile = player.getGameProfile();
final int playerID = WorldData.instance().playerData().getPlayerID(profile);
return this.hasPermission( playerID, perm );
}
return this.hasPermission(playerID, perm);
}
@Override
public boolean hasPermission( final int playerID, final SecurityPermissions perm )
{
if( this.isAvailable() )
{
final EnumSet<SecurityPermissions> perms = this.playerPerms.get( playerID );
@Override
public boolean hasPermission(final int playerID, final SecurityPermissions perm) {
if (this.isAvailable()) {
final EnumSet<SecurityPermissions> perms = this.playerPerms.get(playerID);
if( perms == null )
{
if( playerID == -1 ) // no default?
{
return false;
}
else
{
return this.hasPermission( -1, perm );
}
}
if (perms == null) {
if (playerID == -1) // no default?
{
return false;
} else {
return this.hasPermission(-1, perm);
}
}
return perms.contains( perm );
}
return true;
}
return perms.contains(perm);
}
return true;
}
@Override
public int getOwner()
{
if( this.isAvailable() )
{
return this.securityProvider.get( 0 ).getOwner();
}
return -1;
}
@Override
public int getOwner() {
if (this.isAvailable()) {
return this.securityProvider.get(0).getOwner();
}
return -1;
}
public IGrid getGrid()
{
return this.myGrid;
}
public IGrid getGrid() {
return this.myGrid;
}
}