2014-11-23 13:16:50 +01:00
/ *
* This file is part of Applied Energistics 2 .
2015-05-28 20:01:21 +02:00
* Copyright ( c ) 2013 - 2015 , AlgorithmX2 , All rights reserved .
2014-11-23 13:16:50 +01:00
*
* 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>.
* /
2015-05-28 20:01:21 +02:00
package appeng.core.worlddata ;
2014-11-23 13:16:50 +01:00
import java.util.HashMap ;
import java.util.Map ;
import java.util.UUID ;
import net.minecraftforge.common.config.ConfigCategory ;
import net.minecraftforge.common.config.Property ;
2015-05-28 20:01:21 +02:00
import appeng.core.AELog ;
2014-11-23 13:16:50 +01:00
import appeng.util.UUIDMatcher ;
/ * *
* Initializes a map of ID to UUID from the player list in the settings . cfg
* /
2015-05-28 20:01:21 +02:00
class PlayerMappingsInitializer
2014-11-23 13:16:50 +01:00
{
/ * *
* Internal immutable mapping
* /
private final Map < Integer , UUID > playerMappings ;
/ * *
* Creates the initializer for the player mappings .
* The map will be filled upon construction
* and will only be filled with valid entries .
* If an invalid entry is found , an warning is printed ,
* mostly due to migration problems from 1 . 7 . 2 to 1 . 7 . 10
* where the UUIDs were introduced .
*
* @param playerList the category for the player list , generally extracted using the " players " tag
* /
2015-09-30 14:24:40 +02:00
PlayerMappingsInitializer ( final ConfigCategory playerList )
2014-11-23 13:16:50 +01:00
{
// Matcher for UUIDs
final UUIDMatcher matcher = new UUIDMatcher ( ) ;
// Initial capacity for mappings
final int capacity = playerList . size ( ) ;
// Mappings for the IDs is a regular HashMap
2015-09-29 15:47:55 +02:00
this . playerMappings = new HashMap < > ( capacity ) ;
2014-11-23 13:16:50 +01:00
// Iterates through every pair of UUID to ID
2015-09-30 14:24:40 +02:00
for ( final Map . Entry < String , Property > entry : playerList . getValues ( ) . entrySet ( ) )
2014-11-23 13:16:50 +01:00
{
final String maybeUUID = entry . getKey ( ) ;
final int id = entry . getValue ( ) . getInt ( ) ;
2015-04-03 08:54:31 +02:00
if ( matcher . isUUID ( maybeUUID ) )
2014-11-23 13:16:50 +01:00
{
2015-05-28 20:01:21 +02:00
final UUID uuidString = UUID . fromString ( maybeUUID ) ;
2014-11-23 13:16:50 +01:00
2015-05-28 20:01:21 +02:00
this . playerMappings . put ( id , uuidString ) ;
2014-11-23 13:16:50 +01:00
}
else
{
2015-11-22 15:54:29 +01:00
AELog . warn ( " The configuration for players contained an outdated entry instead an expected UUID " + maybeUUID + " for the player " + id + " . Please clean this up. " ) ;
2014-11-23 13:16:50 +01:00
}
}
}
/ * *
* Getter
*
* @return Immutable map of the players mappings of their ID to their UUID
* /
public Map < Integer , UUID > getPlayerMappings ( )
{
return this . playerMappings ;
}
}