Search in sources :

Example 26 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.

the class DeliveryRequestResolver method onRequestCancelled.

@Nullable
@Override
public IRequest<?> onRequestCancelled(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
    if (!manager.getColony().getWorld().isRemote) {
        final Colony colony = (Colony) manager.getColony();
        final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(c -> c.getJob() instanceof JobDeliveryman && ((JobDeliveryman) c.getJob()).getTaskQueue().contains(request.getToken())).findFirst().orElse(null);
        if (freeDeliveryMan == null) {
            MineColonies.getLogger().error("Parent cancellation failed! Unknown request: " + request.getToken());
        } else {
            final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
            job.onTaskDeletion(request.getToken());
        }
    }
    return null;
}
Also used : JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.

the class CitizenInfoCommand method executeSpecializedCode.

@Override
public void executeSpecializedCode(@NotNull final MinecraftServer server, final ICommandSender sender, final Colony colony, final int citizenId) {
    final CitizenData citizenData = colony.getCitizenManager().getCitizen(citizenId);
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizenData.getId(), citizenData.getName())));
    final Optional<EntityCitizen> optionalEntityCitizen = citizenData.getCitizenEntity();
    if (!optionalEntityCitizen.isPresent()) {
        sender.sendMessage(new TextComponentTranslation(CITIZEN_NOT_LOADED));
        return;
    }
    final EntityCitizen entityCitizen = optionalEntityCitizen.get();
    final BlockPos citizenPosition = entityCitizen.getPosition();
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_POSITION, citizenPosition.getX(), citizenPosition.getY(), citizenPosition.getZ())));
    final BlockPos homePosition = entityCitizen.getHomePosition();
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_HOME_POSITION, homePosition.getX(), homePosition.getY(), homePosition.getZ())));
    if (entityCitizen.getWorkBuilding() == null) {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_WORK_POSITION_NULL)));
    } else {
        final BlockPos workingPosition = entityCitizen.getWorkBuilding().getLocation();
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_WORK_POSITION, workingPosition.getX(), workingPosition.getY(), workingPosition.getZ())));
    }
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_HEALTH, entityCitizen.getHealth(), entityCitizen.getMaxHealth())));
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_LEVEL_AND_AGE, entityCitizen.getLevel(), entityCitizen.getGrowingAge(), citizenData.getLevel())));
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_SKILLS, citizenData.getCharisma(), citizenData.getDexterity(), citizenData.getEndurance(), citizenData.getIntelligence(), citizenData.getStrength())));
    if (entityCitizen.getColonyJob() == null) {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_JOB_NULL)));
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_NO_ACTIVITY)));
    } else if (entityCitizen.getWorkBuilding() != null) {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_JOB, entityCitizen.getWorkBuilding().getJobName())));
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESIRED_ACTIVITY, entityCitizen.getDesiredActivity(), entityCitizen.getColonyJob().getNameTagDescription())));
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 28 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.

the class RespawnCitizenCommand method executeSpecializedCode.

@Override
public void executeSpecializedCode(@NotNull final MinecraftServer server, final ICommandSender sender, final Colony colony, final int citizenId) {
    final CitizenData citizenData = colony.getCitizenManager().getCitizen(citizenId);
    final Optional<EntityCitizen> optionalEntityCitizen = citizenData.getCitizenEntity();
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizenData.getId(), citizenData.getName())));
    if (!optionalEntityCitizen.isPresent()) {
        citizenData.updateCitizenEntityIfNecessary();
    }
    final EntityCitizen entityCitizen = citizenData.getCitizenEntity().get();
    final BlockPos position = entityCitizen.getPosition();
    sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
    sender.sendMessage(new TextComponentString(REMOVED_MESSAGE));
    Log.getLogger().info("client? " + sender.getEntityWorld().isRemote);
    server.addScheduledTask(entityCitizen::setDead);
}
Also used : CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 29 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData 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);
}
Also used : PlayerList(net.minecraft.server.management.PlayerList) ICitizenManager(com.minecolonies.coremod.colony.managers.ICitizenManager) ArrayList(java.util.ArrayList) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) MinecraftServer(net.minecraft.server.MinecraftServer) Before(org.junit.Before)

Aggregations

CitizenData (com.minecolonies.coremod.colony.CitizenData)29 BlockPos (net.minecraft.util.math.BlockPos)15 Colony (com.minecolonies.coremod.colony.Colony)14 NotNull (org.jetbrains.annotations.NotNull)9 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)7 Nullable (org.jetbrains.annotations.Nullable)7 TextComponentString (net.minecraft.util.text.TextComponentString)6 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)4 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)4 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)3 MineColonies (com.minecolonies.coremod.MineColonies)3 JobDeliveryman (com.minecolonies.coremod.colony.jobs.JobDeliveryman)3 ItemStack (net.minecraft.item.ItemStack)3 Lists (com.google.common.collect.Lists)2 TypeToken (com.google.common.reflect.TypeToken)2 IColony (com.minecolonies.api.colony.IColony)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)2 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)2 IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)2