use of com.minecolonies.coremod.colony.managers.ICitizenManager in project minecolonies by Minecolonies.
the class CitizenData method generateName.
/**
* Generates a random name from a set of names.
*
* @param rand Random object.
* @return Name of the citizen.
*/
private String generateName(@NotNull final Random rand) {
String citizenName;
String firstName;
String middleInitial;
String lastName;
if (female) {
firstName = getRandomElement(rand, Configurations.names.femaleFirstNames);
} else {
firstName = getRandomElement(rand, Configurations.names.maleFirstNames);
}
middleInitial = String.valueOf(getRandomLetter(rand));
lastName = getRandomElement(rand, Configurations.names.lastNames);
if (Configurations.names.useMiddleInitial) {
citizenName = String.format("%s %s. %s", firstName, middleInitial, lastName);
} else {
citizenName = String.format("%s %s", firstName, lastName);
}
// Check whether there's already a citizen with this name
final ICitizenManager manager = this.getColony().getCitizenManager();
for (int i = 1; i <= this.getColony().getCitizenManager().getMaxCitizens(); i++) {
final CitizenData citizen = manager.getCitizen(i);
if (citizen != null && citizen.getName().equals(citizenName)) {
// Oops - recurse this function and try again
citizenName = generateName(rand);
}
}
return citizenName;
}
use of com.minecolonies.coremod.colony.managers.ICitizenManager in project minecolonies by Minecolonies.
the class CommandEntryPointTest method setUp.
@Before
public void setUp() {
final Colony colony1 = mock(Colony.class);
when(colony1.getID()).thenReturn(1);
final Colony colony2 = mock(Colony.class);
when(colony2.getID()).thenReturn(2);
@SuppressWarnings("unchecked") final List<Colony> colonyList = Arrays.asList(new Colony[] { colony1, colony2 });
final ICitizenManager citizenManager1 = mock(ICitizenManager.class);
when(colony1.getCitizenManager()).thenReturn(citizenManager1);
final ICitizenManager citizenManager2 = mock(ICitizenManager.class);
when(colony2.getCitizenManager()).thenReturn(citizenManager2);
final List<CitizenData> citizenDataList1 = new ArrayList<>();
when(citizenManager1.getCitizens()).thenReturn(citizenDataList1);
final CitizenData citizenJohnSSmith = mock(CitizenData.class);
when(citizenJohnSSmith.getId()).thenReturn(1);
when(citizenJohnSSmith.getName()).thenReturn("John S. Smith");
citizenDataList1.add(citizenJohnSSmith);
when(citizenManager1.getCitizen(1)).thenReturn(citizenJohnSSmith);
final CitizenData citizenJohnSJones = mock(CitizenData.class);
when(citizenJohnSJones.getId()).thenReturn(4);
when(citizenJohnSJones.getName()).thenReturn("John S. Jones");
citizenDataList1.add(citizenJohnSJones);
when(citizenManager1.getCitizen(4)).thenReturn(citizenJohnSJones);
final CitizenData citizenJohnAJones = mock(CitizenData.class);
when(citizenJohnAJones.getId()).thenReturn(2);
when(citizenJohnAJones.getName()).thenReturn("John A. Jones");
citizenDataList1.add(citizenJohnAJones);
when(citizenManager1.getCitizen(2)).thenReturn(citizenJohnAJones);
final CitizenData citizenJennaQBar = mock(CitizenData.class);
when(citizenJennaQBar.getId()).thenReturn(3);
when(citizenJennaQBar.getName()).thenReturn("Jenna Q. Bar");
citizenDataList1.add(citizenJennaQBar);
when(citizenManager1.getCitizen(3)).thenReturn(citizenJennaQBar);
PowerMockito.mockStatic(ColonyManager.class);
BDDMockito.given(ColonyManager.getColonies()).willReturn(colonyList);
BDDMockito.given(ColonyManager.getColony(1)).willReturn(colony1);
BDDMockito.given(ColonyManager.getColony(2)).willReturn(colony2);
PowerMockito.mockStatic(PermissionAPI.class);
BDDMockito.given(PermissionAPI.hasPermission(any(), any())).willReturn(true);
final EntityPlayerMP playerBob = mock(EntityPlayerMP.class);
when(playerBob.getName()).thenReturn("Bob");
final EntityPlayerMP playerSally = mock(EntityPlayerMP.class);
when(playerSally.getName()).thenReturn("Sally");
final PlayerList serverPlayerList = mock(PlayerList.class);
when(serverPlayerList.getPlayerByUsername("Bob")).thenReturn(playerBob);
when(serverPlayerList.getPlayerByUsername("Sally")).thenReturn(playerSally);
server = mock(MinecraftServer.class);
when(server.getOnlinePlayerNames()).thenReturn(new String[] { "Bob", "Sally" });
when(server.getPlayerList()).thenReturn(serverPlayerList);
sender = mock(MinecraftServer.class);
instance = new CommandEntryPointNew();
pos = new BlockPos(1, 2, 3);
}
Aggregations